three.js 787 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '72dev' };
  6. // browserify support
  7. if ( typeof module === 'object' ) {
  8. module.exports = THREE;
  9. }
  10. // polyfills
  11. if ( Math.sign === undefined ) {
  12. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  13. Math.sign = function ( x ) {
  14. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : +x;
  15. };
  16. }
  17. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  18. // Missing in IE9-11.
  19. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  20. Object.defineProperty( Function.prototype, 'name', {
  21. get: function () {
  22. return this.toString().match(/^\s*function\s*(\S*)\s*\(/)[1];
  23. }
  24. } );
  25. }
  26. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  27. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  28. // GL STATE CONSTANTS
  29. THREE.CullFaceNone = 0;
  30. THREE.CullFaceBack = 1;
  31. THREE.CullFaceFront = 2;
  32. THREE.CullFaceFrontBack = 3;
  33. THREE.FrontFaceDirectionCW = 0;
  34. THREE.FrontFaceDirectionCCW = 1;
  35. // SHADOWING TYPES
  36. THREE.BasicShadowMap = 0;
  37. THREE.PCFShadowMap = 1;
  38. THREE.PCFSoftShadowMap = 2;
  39. // MATERIAL CONSTANTS
  40. // side
  41. THREE.FrontSide = 0;
  42. THREE.BackSide = 1;
  43. THREE.DoubleSide = 2;
  44. // shading
  45. THREE.NoShading = 0;
  46. THREE.FlatShading = 1;
  47. THREE.SmoothShading = 2;
  48. // colors
  49. THREE.NoColors = 0;
  50. THREE.FaceColors = 1;
  51. THREE.VertexColors = 2;
  52. // blending modes
  53. THREE.NoBlending = 0;
  54. THREE.NormalBlending = 1;
  55. THREE.AdditiveBlending = 2;
  56. THREE.SubtractiveBlending = 3;
  57. THREE.MultiplyBlending = 4;
  58. THREE.CustomBlending = 5;
  59. // custom blending equations
  60. // (numbers start from 100 not to clash with other
  61. // mappings to OpenGL constants defined in Texture.js)
  62. THREE.AddEquation = 100;
  63. THREE.SubtractEquation = 101;
  64. THREE.ReverseSubtractEquation = 102;
  65. THREE.MinEquation = 103;
  66. THREE.MaxEquation = 104;
  67. // custom blending destination factors
  68. THREE.ZeroFactor = 200;
  69. THREE.OneFactor = 201;
  70. THREE.SrcColorFactor = 202;
  71. THREE.OneMinusSrcColorFactor = 203;
  72. THREE.SrcAlphaFactor = 204;
  73. THREE.OneMinusSrcAlphaFactor = 205;
  74. THREE.DstAlphaFactor = 206;
  75. THREE.OneMinusDstAlphaFactor = 207;
  76. // custom blending source factors
  77. //THREE.ZeroFactor = 200;
  78. //THREE.OneFactor = 201;
  79. //THREE.SrcAlphaFactor = 204;
  80. //THREE.OneMinusSrcAlphaFactor = 205;
  81. //THREE.DstAlphaFactor = 206;
  82. //THREE.OneMinusDstAlphaFactor = 207;
  83. THREE.DstColorFactor = 208;
  84. THREE.OneMinusDstColorFactor = 209;
  85. THREE.SrcAlphaSaturateFactor = 210;
  86. // depth modes
  87. THREE.NeverDepth = 0;
  88. THREE.AlwaysDepth = 1;
  89. THREE.LessDepth = 2;
  90. THREE.LessEqualDepth = 3;
  91. THREE.EqualDepth = 4;
  92. THREE.GreaterEqualDepth = 5;
  93. THREE.GreaterDepth = 6;
  94. THREE.NotEqualDepth = 7;
  95. // TEXTURE CONSTANTS
  96. THREE.MultiplyOperation = 0;
  97. THREE.MixOperation = 1;
  98. THREE.AddOperation = 2;
  99. // Mapping modes
  100. THREE.UVMapping = 300;
  101. THREE.CubeReflectionMapping = 301;
  102. THREE.CubeRefractionMapping = 302;
  103. THREE.EquirectangularReflectionMapping = 303;
  104. THREE.EquirectangularRefractionMapping = 304;
  105. THREE.SphericalReflectionMapping = 305;
  106. // Wrapping modes
  107. THREE.RepeatWrapping = 1000;
  108. THREE.ClampToEdgeWrapping = 1001;
  109. THREE.MirroredRepeatWrapping = 1002;
  110. // Filters
  111. THREE.NearestFilter = 1003;
  112. THREE.NearestMipMapNearestFilter = 1004;
  113. THREE.NearestMipMapLinearFilter = 1005;
  114. THREE.LinearFilter = 1006;
  115. THREE.LinearMipMapNearestFilter = 1007;
  116. THREE.LinearMipMapLinearFilter = 1008;
  117. // Data types
  118. THREE.UnsignedByteType = 1009;
  119. THREE.ByteType = 1010;
  120. THREE.ShortType = 1011;
  121. THREE.UnsignedShortType = 1012;
  122. THREE.IntType = 1013;
  123. THREE.UnsignedIntType = 1014;
  124. THREE.FloatType = 1015;
  125. THREE.HalfFloatType = 1025;
  126. // Pixel types
  127. //THREE.UnsignedByteType = 1009;
  128. THREE.UnsignedShort4444Type = 1016;
  129. THREE.UnsignedShort5551Type = 1017;
  130. THREE.UnsignedShort565Type = 1018;
  131. // Pixel formats
  132. THREE.AlphaFormat = 1019;
  133. THREE.RGBFormat = 1020;
  134. THREE.RGBAFormat = 1021;
  135. THREE.LuminanceFormat = 1022;
  136. THREE.LuminanceAlphaFormat = 1023;
  137. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  138. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  139. // DDS / ST3C Compressed texture formats
  140. THREE.RGB_S3TC_DXT1_Format = 2001;
  141. THREE.RGBA_S3TC_DXT1_Format = 2002;
  142. THREE.RGBA_S3TC_DXT3_Format = 2003;
  143. THREE.RGBA_S3TC_DXT5_Format = 2004;
  144. // PVRTC compressed texture formats
  145. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  146. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  147. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  148. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  149. // DEPRECATED
  150. THREE.Projector = function () {
  151. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  152. this.projectVector = function ( vector, camera ) {
  153. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  154. vector.project( camera );
  155. };
  156. this.unprojectVector = function ( vector, camera ) {
  157. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  158. vector.unproject( camera );
  159. };
  160. this.pickingRay = function ( vector, camera ) {
  161. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  162. };
  163. };
  164. THREE.CanvasRenderer = function () {
  165. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  166. this.domElement = document.createElement( 'canvas' );
  167. this.clear = function () {};
  168. this.render = function () {};
  169. this.setClearColor = function () {};
  170. this.setSize = function () {};
  171. };
  172. // File:src/math/Color.js
  173. /**
  174. * @author mrdoob / http://mrdoob.com/
  175. */
  176. THREE.Color = function ( color ) {
  177. if ( arguments.length === 3 ) {
  178. return this.setRGB( arguments[ 0 ], arguments[ 1 ], arguments[ 2 ] );
  179. }
  180. return this.set( color )
  181. };
  182. THREE.Color.prototype = {
  183. constructor: THREE.Color,
  184. r: 1, g: 1, b: 1,
  185. set: function ( value ) {
  186. if ( value instanceof THREE.Color ) {
  187. this.copy( value );
  188. } else if ( typeof value === 'number' ) {
  189. this.setHex( value );
  190. } else if ( typeof value === 'string' ) {
  191. this.setStyle( value );
  192. }
  193. return this;
  194. },
  195. setHex: function ( hex ) {
  196. hex = Math.floor( hex );
  197. this.r = ( hex >> 16 & 255 ) / 255;
  198. this.g = ( hex >> 8 & 255 ) / 255;
  199. this.b = ( hex & 255 ) / 255;
  200. return this;
  201. },
  202. setRGB: function ( r, g, b ) {
  203. this.r = r;
  204. this.g = g;
  205. this.b = b;
  206. return this;
  207. },
  208. setHSL: function () {
  209. function hue2rgb ( p, q, t ) {
  210. if ( t < 0 ) t += 1;
  211. if ( t > 1 ) t -= 1;
  212. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  213. if ( t < 1 / 2 ) return q;
  214. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  215. return p;
  216. };
  217. return function ( h, s, l ) {
  218. // h,s,l ranges are in 0.0 - 1.0
  219. h = THREE.Math.euclideanModulo( h, 1 );
  220. s = THREE.Math.clamp( s, 0, 1 );
  221. l = THREE.Math.clamp( l, 0, 1 );
  222. if ( s === 0 ) {
  223. this.r = this.g = this.b = l;
  224. } else {
  225. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  226. var q = ( 2 * l ) - p;
  227. this.r = hue2rgb( q, p, h + 1 / 3 );
  228. this.g = hue2rgb( q, p, h );
  229. this.b = hue2rgb( q, p, h - 1 / 3 );
  230. }
  231. return this;
  232. };
  233. }(),
  234. setStyle: function ( style ) {
  235. // rgb(255,0,0)
  236. if ( /^rgb\((\d+), ?(\d+), ?(\d+)\)$/i.test( style ) ) {
  237. var color = /^rgb\((\d+), ?(\d+), ?(\d+)\)$/i.exec( style );
  238. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  239. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  240. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  241. return this;
  242. }
  243. // rgb(100%,0%,0%)
  244. if ( /^rgb\((\d+)\%, ?(\d+)\%, ?(\d+)\%\)$/i.test( style ) ) {
  245. var color = /^rgb\((\d+)\%, ?(\d+)\%, ?(\d+)\%\)$/i.exec( style );
  246. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  247. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  248. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  249. return this;
  250. }
  251. // #ff0000
  252. if ( /^\#([0-9a-f]{6})$/i.test( style ) ) {
  253. var color = /^\#([0-9a-f]{6})$/i.exec( style );
  254. this.setHex( parseInt( color[ 1 ], 16 ) );
  255. return this;
  256. }
  257. // #f00
  258. if ( /^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.test( style ) ) {
  259. var color = /^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec( style );
  260. this.setHex( parseInt( color[ 1 ] + color[ 1 ] + color[ 2 ] + color[ 2 ] + color[ 3 ] + color[ 3 ], 16 ) );
  261. return this;
  262. }
  263. // red
  264. if ( /^(\w+)$/i.test( style ) ) {
  265. this.setHex( THREE.ColorKeywords[ style ] );
  266. return this;
  267. }
  268. },
  269. copy: function ( color ) {
  270. this.r = color.r;
  271. this.g = color.g;
  272. this.b = color.b;
  273. return this;
  274. },
  275. copyGammaToLinear: function ( color, gammaFactor ) {
  276. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  277. this.r = Math.pow( color.r, gammaFactor );
  278. this.g = Math.pow( color.g, gammaFactor );
  279. this.b = Math.pow( color.b, gammaFactor );
  280. return this;
  281. },
  282. copyLinearToGamma: function ( color, gammaFactor ) {
  283. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  284. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  285. this.r = Math.pow( color.r, safeInverse );
  286. this.g = Math.pow( color.g, safeInverse );
  287. this.b = Math.pow( color.b, safeInverse );
  288. return this;
  289. },
  290. convertGammaToLinear: function () {
  291. var r = this.r, g = this.g, b = this.b;
  292. this.r = r * r;
  293. this.g = g * g;
  294. this.b = b * b;
  295. return this;
  296. },
  297. convertLinearToGamma: function () {
  298. this.r = Math.sqrt( this.r );
  299. this.g = Math.sqrt( this.g );
  300. this.b = Math.sqrt( this.b );
  301. return this;
  302. },
  303. getHex: function () {
  304. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  305. },
  306. getHexString: function () {
  307. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  308. },
  309. getHSL: function ( optionalTarget ) {
  310. // h,s,l ranges are in 0.0 - 1.0
  311. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  312. var r = this.r, g = this.g, b = this.b;
  313. var max = Math.max( r, g, b );
  314. var min = Math.min( r, g, b );
  315. var hue, saturation;
  316. var lightness = ( min + max ) / 2.0;
  317. if ( min === max ) {
  318. hue = 0;
  319. saturation = 0;
  320. } else {
  321. var delta = max - min;
  322. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  323. switch ( max ) {
  324. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  325. case g: hue = ( b - r ) / delta + 2; break;
  326. case b: hue = ( r - g ) / delta + 4; break;
  327. }
  328. hue /= 6;
  329. }
  330. hsl.h = hue;
  331. hsl.s = saturation;
  332. hsl.l = lightness;
  333. return hsl;
  334. },
  335. getStyle: function () {
  336. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  337. },
  338. offsetHSL: function ( h, s, l ) {
  339. var hsl = this.getHSL();
  340. hsl.h += h; hsl.s += s; hsl.l += l;
  341. this.setHSL( hsl.h, hsl.s, hsl.l );
  342. return this;
  343. },
  344. add: function ( color ) {
  345. this.r += color.r;
  346. this.g += color.g;
  347. this.b += color.b;
  348. return this;
  349. },
  350. addColors: function ( color1, color2 ) {
  351. this.r = color1.r + color2.r;
  352. this.g = color1.g + color2.g;
  353. this.b = color1.b + color2.b;
  354. return this;
  355. },
  356. addScalar: function ( s ) {
  357. this.r += s;
  358. this.g += s;
  359. this.b += s;
  360. return this;
  361. },
  362. multiply: function ( color ) {
  363. this.r *= color.r;
  364. this.g *= color.g;
  365. this.b *= color.b;
  366. return this;
  367. },
  368. multiplyScalar: function ( s ) {
  369. this.r *= s;
  370. this.g *= s;
  371. this.b *= s;
  372. return this;
  373. },
  374. lerp: function ( color, alpha ) {
  375. this.r += ( color.r - this.r ) * alpha;
  376. this.g += ( color.g - this.g ) * alpha;
  377. this.b += ( color.b - this.b ) * alpha;
  378. return this;
  379. },
  380. equals: function ( c ) {
  381. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  382. },
  383. fromArray: function ( array ) {
  384. this.r = array[ 0 ];
  385. this.g = array[ 1 ];
  386. this.b = array[ 2 ];
  387. return this;
  388. },
  389. toArray: function ( array, offset ) {
  390. if ( array === undefined ) array = [];
  391. if ( offset === undefined ) offset = 0;
  392. array[ offset ] = this.r;
  393. array[ offset + 1 ] = this.g;
  394. array[ offset + 2 ] = this.b;
  395. return array;
  396. },
  397. clone: function () {
  398. return new THREE.Color().setRGB( this.r, this.g, this.b );
  399. }
  400. };
  401. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  402. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  403. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  404. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  405. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  406. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  407. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  408. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  409. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  410. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  411. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  412. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  413. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  414. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  415. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  416. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  417. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  418. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  419. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  420. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  421. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  422. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  423. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  424. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  425. // File:src/math/Quaternion.js
  426. /**
  427. * @author mikael emtinger / http://gomo.se/
  428. * @author alteredq / http://alteredqualia.com/
  429. * @author WestLangley / http://github.com/WestLangley
  430. * @author bhouston / http://exocortex.com
  431. */
  432. THREE.Quaternion = function ( x, y, z, w ) {
  433. this._x = x || 0;
  434. this._y = y || 0;
  435. this._z = z || 0;
  436. this._w = ( w !== undefined ) ? w : 1;
  437. };
  438. THREE.Quaternion.prototype = {
  439. constructor: THREE.Quaternion,
  440. _x: 0,_y: 0, _z: 0, _w: 0,
  441. get x () {
  442. return this._x;
  443. },
  444. set x ( value ) {
  445. this._x = value;
  446. this.onChangeCallback();
  447. },
  448. get y () {
  449. return this._y;
  450. },
  451. set y ( value ) {
  452. this._y = value;
  453. this.onChangeCallback();
  454. },
  455. get z () {
  456. return this._z;
  457. },
  458. set z ( value ) {
  459. this._z = value;
  460. this.onChangeCallback();
  461. },
  462. get w () {
  463. return this._w;
  464. },
  465. set w ( value ) {
  466. this._w = value;
  467. this.onChangeCallback();
  468. },
  469. set: function ( x, y, z, w ) {
  470. this._x = x;
  471. this._y = y;
  472. this._z = z;
  473. this._w = w;
  474. this.onChangeCallback();
  475. return this;
  476. },
  477. copy: function ( quaternion ) {
  478. this._x = quaternion.x;
  479. this._y = quaternion.y;
  480. this._z = quaternion.z;
  481. this._w = quaternion.w;
  482. this.onChangeCallback();
  483. return this;
  484. },
  485. setFromEuler: function ( euler, update ) {
  486. if ( euler instanceof THREE.Euler === false ) {
  487. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  488. }
  489. // http://www.mathworks.com/matlabcentral/fileexchange/
  490. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  491. // content/SpinCalc.m
  492. var c1 = Math.cos( euler._x / 2 );
  493. var c2 = Math.cos( euler._y / 2 );
  494. var c3 = Math.cos( euler._z / 2 );
  495. var s1 = Math.sin( euler._x / 2 );
  496. var s2 = Math.sin( euler._y / 2 );
  497. var s3 = Math.sin( euler._z / 2 );
  498. if ( euler.order === 'XYZ' ) {
  499. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  500. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  501. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  502. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  503. } else if ( euler.order === 'YXZ' ) {
  504. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  505. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  506. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  507. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  508. } else if ( euler.order === 'ZXY' ) {
  509. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  510. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  511. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  512. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  513. } else if ( euler.order === 'ZYX' ) {
  514. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  515. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  516. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  517. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  518. } else if ( euler.order === 'YZX' ) {
  519. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  520. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  521. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  522. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  523. } else if ( euler.order === 'XZY' ) {
  524. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  525. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  526. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  527. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  528. }
  529. if ( update !== false ) this.onChangeCallback();
  530. return this;
  531. },
  532. setFromAxisAngle: function ( axis, angle ) {
  533. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  534. // assumes axis is normalized
  535. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  536. this._x = axis.x * s;
  537. this._y = axis.y * s;
  538. this._z = axis.z * s;
  539. this._w = Math.cos( halfAngle );
  540. this.onChangeCallback();
  541. return this;
  542. },
  543. setFromRotationMatrix: function ( m ) {
  544. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  545. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  546. var te = m.elements,
  547. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  548. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  549. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  550. trace = m11 + m22 + m33,
  551. s;
  552. if ( trace > 0 ) {
  553. s = 0.5 / Math.sqrt( trace + 1.0 );
  554. this._w = 0.25 / s;
  555. this._x = ( m32 - m23 ) * s;
  556. this._y = ( m13 - m31 ) * s;
  557. this._z = ( m21 - m12 ) * s;
  558. } else if ( m11 > m22 && m11 > m33 ) {
  559. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  560. this._w = ( m32 - m23 ) / s;
  561. this._x = 0.25 * s;
  562. this._y = ( m12 + m21 ) / s;
  563. this._z = ( m13 + m31 ) / s;
  564. } else if ( m22 > m33 ) {
  565. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  566. this._w = ( m13 - m31 ) / s;
  567. this._x = ( m12 + m21 ) / s;
  568. this._y = 0.25 * s;
  569. this._z = ( m23 + m32 ) / s;
  570. } else {
  571. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  572. this._w = ( m21 - m12 ) / s;
  573. this._x = ( m13 + m31 ) / s;
  574. this._y = ( m23 + m32 ) / s;
  575. this._z = 0.25 * s;
  576. }
  577. this.onChangeCallback();
  578. return this;
  579. },
  580. setFromUnitVectors: function () {
  581. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  582. // assumes direction vectors vFrom and vTo are normalized
  583. var v1, r;
  584. var EPS = 0.000001;
  585. return function ( vFrom, vTo ) {
  586. if ( v1 === undefined ) v1 = new THREE.Vector3();
  587. r = vFrom.dot( vTo ) + 1;
  588. if ( r < EPS ) {
  589. r = 0;
  590. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  591. v1.set( - vFrom.y, vFrom.x, 0 );
  592. } else {
  593. v1.set( 0, - vFrom.z, vFrom.y );
  594. }
  595. } else {
  596. v1.crossVectors( vFrom, vTo );
  597. }
  598. this._x = v1.x;
  599. this._y = v1.y;
  600. this._z = v1.z;
  601. this._w = r;
  602. this.normalize();
  603. return this;
  604. }
  605. }(),
  606. inverse: function () {
  607. this.conjugate().normalize();
  608. return this;
  609. },
  610. conjugate: function () {
  611. this._x *= - 1;
  612. this._y *= - 1;
  613. this._z *= - 1;
  614. this.onChangeCallback();
  615. return this;
  616. },
  617. dot: function ( v ) {
  618. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  619. },
  620. lengthSq: function () {
  621. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  622. },
  623. length: function () {
  624. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  625. },
  626. normalize: function () {
  627. var l = this.length();
  628. if ( l === 0 ) {
  629. this._x = 0;
  630. this._y = 0;
  631. this._z = 0;
  632. this._w = 1;
  633. } else {
  634. l = 1 / l;
  635. this._x = this._x * l;
  636. this._y = this._y * l;
  637. this._z = this._z * l;
  638. this._w = this._w * l;
  639. }
  640. this.onChangeCallback();
  641. return this;
  642. },
  643. multiply: function ( q, p ) {
  644. if ( p !== undefined ) {
  645. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  646. return this.multiplyQuaternions( q, p );
  647. }
  648. return this.multiplyQuaternions( this, q );
  649. },
  650. multiplyQuaternions: function ( a, b ) {
  651. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  652. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  653. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  654. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  655. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  656. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  657. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  658. this.onChangeCallback();
  659. return this;
  660. },
  661. multiplyVector3: function ( vector ) {
  662. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  663. return vector.applyQuaternion( this );
  664. },
  665. slerp: function ( qb, t ) {
  666. if ( t === 0 ) return this;
  667. if ( t === 1 ) return this.copy( qb );
  668. var x = this._x, y = this._y, z = this._z, w = this._w;
  669. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  670. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  671. if ( cosHalfTheta < 0 ) {
  672. this._w = - qb._w;
  673. this._x = - qb._x;
  674. this._y = - qb._y;
  675. this._z = - qb._z;
  676. cosHalfTheta = - cosHalfTheta;
  677. } else {
  678. this.copy( qb );
  679. }
  680. if ( cosHalfTheta >= 1.0 ) {
  681. this._w = w;
  682. this._x = x;
  683. this._y = y;
  684. this._z = z;
  685. return this;
  686. }
  687. var halfTheta = Math.acos( cosHalfTheta );
  688. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  689. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  690. this._w = 0.5 * ( w + this._w );
  691. this._x = 0.5 * ( x + this._x );
  692. this._y = 0.5 * ( y + this._y );
  693. this._z = 0.5 * ( z + this._z );
  694. return this;
  695. }
  696. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  697. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  698. this._w = ( w * ratioA + this._w * ratioB );
  699. this._x = ( x * ratioA + this._x * ratioB );
  700. this._y = ( y * ratioA + this._y * ratioB );
  701. this._z = ( z * ratioA + this._z * ratioB );
  702. this.onChangeCallback();
  703. return this;
  704. },
  705. equals: function ( quaternion ) {
  706. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  707. },
  708. fromArray: function ( array, offset ) {
  709. if ( offset === undefined ) offset = 0;
  710. this._x = array[ offset ];
  711. this._y = array[ offset + 1 ];
  712. this._z = array[ offset + 2 ];
  713. this._w = array[ offset + 3 ];
  714. this.onChangeCallback();
  715. return this;
  716. },
  717. toArray: function ( array, offset ) {
  718. if ( array === undefined ) array = [];
  719. if ( offset === undefined ) offset = 0;
  720. array[ offset ] = this._x;
  721. array[ offset + 1 ] = this._y;
  722. array[ offset + 2 ] = this._z;
  723. array[ offset + 3 ] = this._w;
  724. return array;
  725. },
  726. onChange: function ( callback ) {
  727. this.onChangeCallback = callback;
  728. return this;
  729. },
  730. onChangeCallback: function () {},
  731. clone: function () {
  732. return new THREE.Quaternion( this._x, this._y, this._z, this._w );
  733. }
  734. };
  735. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  736. return qm.copy( qa ).slerp( qb, t );
  737. };
  738. // File:src/math/Vector2.js
  739. /**
  740. * @author mrdoob / http://mrdoob.com/
  741. * @author philogb / http://blog.thejit.org/
  742. * @author egraether / http://egraether.com/
  743. * @author zz85 / http://www.lab4games.net/zz85/blog
  744. */
  745. THREE.Vector2 = function ( x, y ) {
  746. this.x = x || 0;
  747. this.y = y || 0;
  748. };
  749. THREE.Vector2.prototype = {
  750. constructor: THREE.Vector2,
  751. set: function ( x, y ) {
  752. this.x = x;
  753. this.y = y;
  754. return this;
  755. },
  756. setX: function ( x ) {
  757. this.x = x;
  758. return this;
  759. },
  760. setY: function ( y ) {
  761. this.y = y;
  762. return this;
  763. },
  764. setComponent: function ( index, value ) {
  765. switch ( index ) {
  766. case 0: this.x = value; break;
  767. case 1: this.y = value; break;
  768. default: throw new Error( 'index is out of range: ' + index );
  769. }
  770. },
  771. getComponent: function ( index ) {
  772. switch ( index ) {
  773. case 0: return this.x;
  774. case 1: return this.y;
  775. default: throw new Error( 'index is out of range: ' + index );
  776. }
  777. },
  778. copy: function ( v ) {
  779. this.x = v.x;
  780. this.y = v.y;
  781. return this;
  782. },
  783. add: function ( v, w ) {
  784. if ( w !== undefined ) {
  785. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  786. return this.addVectors( v, w );
  787. }
  788. this.x += v.x;
  789. this.y += v.y;
  790. return this;
  791. },
  792. addScalar: function ( s ) {
  793. this.x += s;
  794. this.y += s;
  795. return this;
  796. },
  797. addVectors: function ( a, b ) {
  798. this.x = a.x + b.x;
  799. this.y = a.y + b.y;
  800. return this;
  801. },
  802. sub: function ( v, w ) {
  803. if ( w !== undefined ) {
  804. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  805. return this.subVectors( v, w );
  806. }
  807. this.x -= v.x;
  808. this.y -= v.y;
  809. return this;
  810. },
  811. subScalar: function ( s ) {
  812. this.x -= s;
  813. this.y -= s;
  814. return this;
  815. },
  816. subVectors: function ( a, b ) {
  817. this.x = a.x - b.x;
  818. this.y = a.y - b.y;
  819. return this;
  820. },
  821. multiply: function ( v ) {
  822. this.x *= v.x;
  823. this.y *= v.y;
  824. return this;
  825. },
  826. multiplyScalar: function ( s ) {
  827. this.x *= s;
  828. this.y *= s;
  829. return this;
  830. },
  831. divide: function ( v ) {
  832. this.x /= v.x;
  833. this.y /= v.y;
  834. return this;
  835. },
  836. divideScalar: function ( scalar ) {
  837. if ( scalar !== 0 ) {
  838. var invScalar = 1 / scalar;
  839. this.x *= invScalar;
  840. this.y *= invScalar;
  841. } else {
  842. this.x = 0;
  843. this.y = 0;
  844. }
  845. return this;
  846. },
  847. min: function ( v ) {
  848. if ( this.x > v.x ) {
  849. this.x = v.x;
  850. }
  851. if ( this.y > v.y ) {
  852. this.y = v.y;
  853. }
  854. return this;
  855. },
  856. max: function ( v ) {
  857. if ( this.x < v.x ) {
  858. this.x = v.x;
  859. }
  860. if ( this.y < v.y ) {
  861. this.y = v.y;
  862. }
  863. return this;
  864. },
  865. clamp: function ( min, max ) {
  866. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  867. if ( this.x < min.x ) {
  868. this.x = min.x;
  869. } else if ( this.x > max.x ) {
  870. this.x = max.x;
  871. }
  872. if ( this.y < min.y ) {
  873. this.y = min.y;
  874. } else if ( this.y > max.y ) {
  875. this.y = max.y;
  876. }
  877. return this;
  878. },
  879. clampScalar: ( function () {
  880. var min, max;
  881. return function ( minVal, maxVal ) {
  882. if ( min === undefined ) {
  883. min = new THREE.Vector2();
  884. max = new THREE.Vector2();
  885. }
  886. min.set( minVal, minVal );
  887. max.set( maxVal, maxVal );
  888. return this.clamp( min, max );
  889. };
  890. } )(),
  891. floor: function () {
  892. this.x = Math.floor( this.x );
  893. this.y = Math.floor( this.y );
  894. return this;
  895. },
  896. ceil: function () {
  897. this.x = Math.ceil( this.x );
  898. this.y = Math.ceil( this.y );
  899. return this;
  900. },
  901. round: function () {
  902. this.x = Math.round( this.x );
  903. this.y = Math.round( this.y );
  904. return this;
  905. },
  906. roundToZero: function () {
  907. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  908. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  909. return this;
  910. },
  911. negate: function () {
  912. this.x = - this.x;
  913. this.y = - this.y;
  914. return this;
  915. },
  916. dot: function ( v ) {
  917. return this.x * v.x + this.y * v.y;
  918. },
  919. lengthSq: function () {
  920. return this.x * this.x + this.y * this.y;
  921. },
  922. length: function () {
  923. return Math.sqrt( this.x * this.x + this.y * this.y );
  924. },
  925. lengthManhattan: function() {
  926. return Math.abs( this.x ) + Math.abs( this.y );
  927. },
  928. normalize: function () {
  929. return this.divideScalar( this.length() );
  930. },
  931. distanceTo: function ( v ) {
  932. return Math.sqrt( this.distanceToSquared( v ) );
  933. },
  934. distanceToSquared: function ( v ) {
  935. var dx = this.x - v.x, dy = this.y - v.y;
  936. return dx * dx + dy * dy;
  937. },
  938. setLength: function ( l ) {
  939. var oldLength = this.length();
  940. if ( oldLength !== 0 && l !== oldLength ) {
  941. this.multiplyScalar( l / oldLength );
  942. }
  943. return this;
  944. },
  945. lerp: function ( v, alpha ) {
  946. this.x += ( v.x - this.x ) * alpha;
  947. this.y += ( v.y - this.y ) * alpha;
  948. return this;
  949. },
  950. lerpVectors: function ( v1, v2, alpha ) {
  951. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  952. return this;
  953. },
  954. equals: function ( v ) {
  955. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  956. },
  957. fromArray: function ( array, offset ) {
  958. if ( offset === undefined ) offset = 0;
  959. this.x = array[ offset ];
  960. this.y = array[ offset + 1 ];
  961. return this;
  962. },
  963. toArray: function ( array, offset ) {
  964. if ( array === undefined ) array = [];
  965. if ( offset === undefined ) offset = 0;
  966. array[ offset ] = this.x;
  967. array[ offset + 1 ] = this.y;
  968. return array;
  969. },
  970. fromAttribute: function ( attribute, index, offset ) {
  971. if ( offset === undefined ) offset = 0;
  972. index = index * attribute.itemSize + offset;
  973. this.x = attribute.array[ index ];
  974. this.y = attribute.array[ index + 1 ];
  975. return this;
  976. },
  977. clone: function () {
  978. return new THREE.Vector2( this.x, this.y );
  979. }
  980. };
  981. // File:src/math/Vector3.js
  982. /**
  983. * @author mrdoob / http://mrdoob.com/
  984. * @author *kile / http://kile.stravaganza.org/
  985. * @author philogb / http://blog.thejit.org/
  986. * @author mikael emtinger / http://gomo.se/
  987. * @author egraether / http://egraether.com/
  988. * @author WestLangley / http://github.com/WestLangley
  989. */
  990. THREE.Vector3 = function ( x, y, z ) {
  991. this.x = x || 0;
  992. this.y = y || 0;
  993. this.z = z || 0;
  994. };
  995. THREE.Vector3.prototype = {
  996. constructor: THREE.Vector3,
  997. set: function ( x, y, z ) {
  998. this.x = x;
  999. this.y = y;
  1000. this.z = z;
  1001. return this;
  1002. },
  1003. setX: function ( x ) {
  1004. this.x = x;
  1005. return this;
  1006. },
  1007. setY: function ( y ) {
  1008. this.y = y;
  1009. return this;
  1010. },
  1011. setZ: function ( z ) {
  1012. this.z = z;
  1013. return this;
  1014. },
  1015. setComponent: function ( index, value ) {
  1016. switch ( index ) {
  1017. case 0: this.x = value; break;
  1018. case 1: this.y = value; break;
  1019. case 2: this.z = value; break;
  1020. default: throw new Error( 'index is out of range: ' + index );
  1021. }
  1022. },
  1023. getComponent: function ( index ) {
  1024. switch ( index ) {
  1025. case 0: return this.x;
  1026. case 1: return this.y;
  1027. case 2: return this.z;
  1028. default: throw new Error( 'index is out of range: ' + index );
  1029. }
  1030. },
  1031. copy: function ( v ) {
  1032. this.x = v.x;
  1033. this.y = v.y;
  1034. this.z = v.z;
  1035. return this;
  1036. },
  1037. add: function ( v, w ) {
  1038. if ( w !== undefined ) {
  1039. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1040. return this.addVectors( v, w );
  1041. }
  1042. this.x += v.x;
  1043. this.y += v.y;
  1044. this.z += v.z;
  1045. return this;
  1046. },
  1047. addScalar: function ( s ) {
  1048. this.x += s;
  1049. this.y += s;
  1050. this.z += s;
  1051. return this;
  1052. },
  1053. addVectors: function ( a, b ) {
  1054. this.x = a.x + b.x;
  1055. this.y = a.y + b.y;
  1056. this.z = a.z + b.z;
  1057. return this;
  1058. },
  1059. sub: function ( v, w ) {
  1060. if ( w !== undefined ) {
  1061. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1062. return this.subVectors( v, w );
  1063. }
  1064. this.x -= v.x;
  1065. this.y -= v.y;
  1066. this.z -= v.z;
  1067. return this;
  1068. },
  1069. subScalar: function ( s ) {
  1070. this.x -= s;
  1071. this.y -= s;
  1072. this.z -= s;
  1073. return this;
  1074. },
  1075. subVectors: function ( a, b ) {
  1076. this.x = a.x - b.x;
  1077. this.y = a.y - b.y;
  1078. this.z = a.z - b.z;
  1079. return this;
  1080. },
  1081. multiply: function ( v, w ) {
  1082. if ( w !== undefined ) {
  1083. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1084. return this.multiplyVectors( v, w );
  1085. }
  1086. this.x *= v.x;
  1087. this.y *= v.y;
  1088. this.z *= v.z;
  1089. return this;
  1090. },
  1091. multiplyScalar: function ( scalar ) {
  1092. this.x *= scalar;
  1093. this.y *= scalar;
  1094. this.z *= scalar;
  1095. return this;
  1096. },
  1097. multiplyVectors: function ( a, b ) {
  1098. this.x = a.x * b.x;
  1099. this.y = a.y * b.y;
  1100. this.z = a.z * b.z;
  1101. return this;
  1102. },
  1103. applyEuler: function () {
  1104. var quaternion;
  1105. return function ( euler ) {
  1106. if ( euler instanceof THREE.Euler === false ) {
  1107. console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  1108. }
  1109. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1110. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1111. return this;
  1112. };
  1113. }(),
  1114. applyAxisAngle: function () {
  1115. var quaternion;
  1116. return function ( axis, angle ) {
  1117. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1118. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1119. return this;
  1120. };
  1121. }(),
  1122. applyMatrix3: function ( m ) {
  1123. var x = this.x;
  1124. var y = this.y;
  1125. var z = this.z;
  1126. var e = m.elements;
  1127. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1128. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1129. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1130. return this;
  1131. },
  1132. applyMatrix4: function ( m ) {
  1133. // input: THREE.Matrix4 affine matrix
  1134. var x = this.x, y = this.y, z = this.z;
  1135. var e = m.elements;
  1136. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1137. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1138. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1139. return this;
  1140. },
  1141. applyProjection: function ( m ) {
  1142. // input: THREE.Matrix4 projection matrix
  1143. var x = this.x, y = this.y, z = this.z;
  1144. var e = m.elements;
  1145. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1146. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1147. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1148. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1149. return this;
  1150. },
  1151. applyQuaternion: function ( q ) {
  1152. var x = this.x;
  1153. var y = this.y;
  1154. var z = this.z;
  1155. var qx = q.x;
  1156. var qy = q.y;
  1157. var qz = q.z;
  1158. var qw = q.w;
  1159. // calculate quat * vector
  1160. var ix = qw * x + qy * z - qz * y;
  1161. var iy = qw * y + qz * x - qx * z;
  1162. var iz = qw * z + qx * y - qy * x;
  1163. var iw = - qx * x - qy * y - qz * z;
  1164. // calculate result * inverse quat
  1165. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1166. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1167. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1168. return this;
  1169. },
  1170. project: function () {
  1171. var matrix;
  1172. return function ( camera ) {
  1173. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1174. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1175. return this.applyProjection( matrix );
  1176. };
  1177. }(),
  1178. unproject: function () {
  1179. var matrix;
  1180. return function ( camera ) {
  1181. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1182. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1183. return this.applyProjection( matrix );
  1184. };
  1185. }(),
  1186. transformDirection: function ( m ) {
  1187. // input: THREE.Matrix4 affine matrix
  1188. // vector interpreted as a direction
  1189. var x = this.x, y = this.y, z = this.z;
  1190. var e = m.elements;
  1191. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1192. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1193. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1194. this.normalize();
  1195. return this;
  1196. },
  1197. divide: function ( v ) {
  1198. this.x /= v.x;
  1199. this.y /= v.y;
  1200. this.z /= v.z;
  1201. return this;
  1202. },
  1203. divideScalar: function ( scalar ) {
  1204. if ( scalar !== 0 ) {
  1205. var invScalar = 1 / scalar;
  1206. this.x *= invScalar;
  1207. this.y *= invScalar;
  1208. this.z *= invScalar;
  1209. } else {
  1210. this.x = 0;
  1211. this.y = 0;
  1212. this.z = 0;
  1213. }
  1214. return this;
  1215. },
  1216. min: function ( v ) {
  1217. if ( this.x > v.x ) {
  1218. this.x = v.x;
  1219. }
  1220. if ( this.y > v.y ) {
  1221. this.y = v.y;
  1222. }
  1223. if ( this.z > v.z ) {
  1224. this.z = v.z;
  1225. }
  1226. return this;
  1227. },
  1228. max: function ( v ) {
  1229. if ( this.x < v.x ) {
  1230. this.x = v.x;
  1231. }
  1232. if ( this.y < v.y ) {
  1233. this.y = v.y;
  1234. }
  1235. if ( this.z < v.z ) {
  1236. this.z = v.z;
  1237. }
  1238. return this;
  1239. },
  1240. clamp: function ( min, max ) {
  1241. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1242. if ( this.x < min.x ) {
  1243. this.x = min.x;
  1244. } else if ( this.x > max.x ) {
  1245. this.x = max.x;
  1246. }
  1247. if ( this.y < min.y ) {
  1248. this.y = min.y;
  1249. } else if ( this.y > max.y ) {
  1250. this.y = max.y;
  1251. }
  1252. if ( this.z < min.z ) {
  1253. this.z = min.z;
  1254. } else if ( this.z > max.z ) {
  1255. this.z = max.z;
  1256. }
  1257. return this;
  1258. },
  1259. clampScalar: ( function () {
  1260. var min, max;
  1261. return function ( minVal, maxVal ) {
  1262. if ( min === undefined ) {
  1263. min = new THREE.Vector3();
  1264. max = new THREE.Vector3();
  1265. }
  1266. min.set( minVal, minVal, minVal );
  1267. max.set( maxVal, maxVal, maxVal );
  1268. return this.clamp( min, max );
  1269. };
  1270. } )(),
  1271. floor: function () {
  1272. this.x = Math.floor( this.x );
  1273. this.y = Math.floor( this.y );
  1274. this.z = Math.floor( this.z );
  1275. return this;
  1276. },
  1277. ceil: function () {
  1278. this.x = Math.ceil( this.x );
  1279. this.y = Math.ceil( this.y );
  1280. this.z = Math.ceil( this.z );
  1281. return this;
  1282. },
  1283. round: function () {
  1284. this.x = Math.round( this.x );
  1285. this.y = Math.round( this.y );
  1286. this.z = Math.round( this.z );
  1287. return this;
  1288. },
  1289. roundToZero: function () {
  1290. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1291. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1292. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1293. return this;
  1294. },
  1295. negate: function () {
  1296. this.x = - this.x;
  1297. this.y = - this.y;
  1298. this.z = - this.z;
  1299. return this;
  1300. },
  1301. dot: function ( v ) {
  1302. return this.x * v.x + this.y * v.y + this.z * v.z;
  1303. },
  1304. lengthSq: function () {
  1305. return this.x * this.x + this.y * this.y + this.z * this.z;
  1306. },
  1307. length: function () {
  1308. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1309. },
  1310. lengthManhattan: function () {
  1311. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1312. },
  1313. normalize: function () {
  1314. return this.divideScalar( this.length() );
  1315. },
  1316. setLength: function ( l ) {
  1317. var oldLength = this.length();
  1318. if ( oldLength !== 0 && l !== oldLength ) {
  1319. this.multiplyScalar( l / oldLength );
  1320. }
  1321. return this;
  1322. },
  1323. lerp: function ( v, alpha ) {
  1324. this.x += ( v.x - this.x ) * alpha;
  1325. this.y += ( v.y - this.y ) * alpha;
  1326. this.z += ( v.z - this.z ) * alpha;
  1327. return this;
  1328. },
  1329. lerpVectors: function ( v1, v2, alpha ) {
  1330. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1331. return this;
  1332. },
  1333. cross: function ( v, w ) {
  1334. if ( w !== undefined ) {
  1335. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1336. return this.crossVectors( v, w );
  1337. }
  1338. var x = this.x, y = this.y, z = this.z;
  1339. this.x = y * v.z - z * v.y;
  1340. this.y = z * v.x - x * v.z;
  1341. this.z = x * v.y - y * v.x;
  1342. return this;
  1343. },
  1344. crossVectors: function ( a, b ) {
  1345. var ax = a.x, ay = a.y, az = a.z;
  1346. var bx = b.x, by = b.y, bz = b.z;
  1347. this.x = ay * bz - az * by;
  1348. this.y = az * bx - ax * bz;
  1349. this.z = ax * by - ay * bx;
  1350. return this;
  1351. },
  1352. projectOnVector: function () {
  1353. var v1, dot;
  1354. return function ( vector ) {
  1355. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1356. v1.copy( vector ).normalize();
  1357. dot = this.dot( v1 );
  1358. return this.copy( v1 ).multiplyScalar( dot );
  1359. };
  1360. }(),
  1361. projectOnPlane: function () {
  1362. var v1;
  1363. return function ( planeNormal ) {
  1364. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1365. v1.copy( this ).projectOnVector( planeNormal );
  1366. return this.sub( v1 );
  1367. }
  1368. }(),
  1369. reflect: function () {
  1370. // reflect incident vector off plane orthogonal to normal
  1371. // normal is assumed to have unit length
  1372. var v1;
  1373. return function ( normal ) {
  1374. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1375. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1376. }
  1377. }(),
  1378. angleTo: function ( v ) {
  1379. var theta = this.dot( v ) / ( this.length() * v.length() );
  1380. // clamp, to handle numerical problems
  1381. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1382. },
  1383. distanceTo: function ( v ) {
  1384. return Math.sqrt( this.distanceToSquared( v ) );
  1385. },
  1386. distanceToSquared: function ( v ) {
  1387. var dx = this.x - v.x;
  1388. var dy = this.y - v.y;
  1389. var dz = this.z - v.z;
  1390. return dx * dx + dy * dy + dz * dz;
  1391. },
  1392. setEulerFromRotationMatrix: function ( m, order ) {
  1393. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  1394. },
  1395. setEulerFromQuaternion: function ( q, order ) {
  1396. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  1397. },
  1398. getPositionFromMatrix: function ( m ) {
  1399. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  1400. return this.setFromMatrixPosition( m );
  1401. },
  1402. getScaleFromMatrix: function ( m ) {
  1403. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  1404. return this.setFromMatrixScale( m );
  1405. },
  1406. getColumnFromMatrix: function ( index, matrix ) {
  1407. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  1408. return this.setFromMatrixColumn( index, matrix );
  1409. },
  1410. setFromMatrixPosition: function ( m ) {
  1411. this.x = m.elements[ 12 ];
  1412. this.y = m.elements[ 13 ];
  1413. this.z = m.elements[ 14 ];
  1414. return this;
  1415. },
  1416. setFromMatrixScale: function ( m ) {
  1417. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1418. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1419. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1420. this.x = sx;
  1421. this.y = sy;
  1422. this.z = sz;
  1423. return this;
  1424. },
  1425. setFromMatrixColumn: function ( index, matrix ) {
  1426. var offset = index * 4;
  1427. var me = matrix.elements;
  1428. this.x = me[ offset ];
  1429. this.y = me[ offset + 1 ];
  1430. this.z = me[ offset + 2 ];
  1431. return this;
  1432. },
  1433. equals: function ( v ) {
  1434. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1435. },
  1436. fromArray: function ( array, offset ) {
  1437. if ( offset === undefined ) offset = 0;
  1438. this.x = array[ offset ];
  1439. this.y = array[ offset + 1 ];
  1440. this.z = array[ offset + 2 ];
  1441. return this;
  1442. },
  1443. toArray: function ( array, offset ) {
  1444. if ( array === undefined ) array = [];
  1445. if ( offset === undefined ) offset = 0;
  1446. array[ offset ] = this.x;
  1447. array[ offset + 1 ] = this.y;
  1448. array[ offset + 2 ] = this.z;
  1449. return array;
  1450. },
  1451. fromAttribute: function ( attribute, index, offset ) {
  1452. if ( offset === undefined ) offset = 0;
  1453. index = index * attribute.itemSize + offset;
  1454. this.x = attribute.array[ index ];
  1455. this.y = attribute.array[ index + 1 ];
  1456. this.z = attribute.array[ index + 2 ];
  1457. return this;
  1458. },
  1459. clone: function () {
  1460. return new THREE.Vector3( this.x, this.y, this.z );
  1461. }
  1462. };
  1463. // File:src/math/Vector4.js
  1464. /**
  1465. * @author supereggbert / http://www.paulbrunt.co.uk/
  1466. * @author philogb / http://blog.thejit.org/
  1467. * @author mikael emtinger / http://gomo.se/
  1468. * @author egraether / http://egraether.com/
  1469. * @author WestLangley / http://github.com/WestLangley
  1470. */
  1471. THREE.Vector4 = function ( x, y, z, w ) {
  1472. this.x = x || 0;
  1473. this.y = y || 0;
  1474. this.z = z || 0;
  1475. this.w = ( w !== undefined ) ? w : 1;
  1476. };
  1477. THREE.Vector4.prototype = {
  1478. constructor: THREE.Vector4,
  1479. set: function ( x, y, z, w ) {
  1480. this.x = x;
  1481. this.y = y;
  1482. this.z = z;
  1483. this.w = w;
  1484. return this;
  1485. },
  1486. setX: function ( x ) {
  1487. this.x = x;
  1488. return this;
  1489. },
  1490. setY: function ( y ) {
  1491. this.y = y;
  1492. return this;
  1493. },
  1494. setZ: function ( z ) {
  1495. this.z = z;
  1496. return this;
  1497. },
  1498. setW: function ( w ) {
  1499. this.w = w;
  1500. return this;
  1501. },
  1502. setComponent: function ( index, value ) {
  1503. switch ( index ) {
  1504. case 0: this.x = value; break;
  1505. case 1: this.y = value; break;
  1506. case 2: this.z = value; break;
  1507. case 3: this.w = value; break;
  1508. default: throw new Error( 'index is out of range: ' + index );
  1509. }
  1510. },
  1511. getComponent: function ( index ) {
  1512. switch ( index ) {
  1513. case 0: return this.x;
  1514. case 1: return this.y;
  1515. case 2: return this.z;
  1516. case 3: return this.w;
  1517. default: throw new Error( 'index is out of range: ' + index );
  1518. }
  1519. },
  1520. copy: function ( v ) {
  1521. this.x = v.x;
  1522. this.y = v.y;
  1523. this.z = v.z;
  1524. this.w = ( v.w !== undefined ) ? v.w : 1;
  1525. return this;
  1526. },
  1527. add: function ( v, w ) {
  1528. if ( w !== undefined ) {
  1529. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1530. return this.addVectors( v, w );
  1531. }
  1532. this.x += v.x;
  1533. this.y += v.y;
  1534. this.z += v.z;
  1535. this.w += v.w;
  1536. return this;
  1537. },
  1538. addScalar: function ( s ) {
  1539. this.x += s;
  1540. this.y += s;
  1541. this.z += s;
  1542. this.w += s;
  1543. return this;
  1544. },
  1545. addVectors: function ( a, b ) {
  1546. this.x = a.x + b.x;
  1547. this.y = a.y + b.y;
  1548. this.z = a.z + b.z;
  1549. this.w = a.w + b.w;
  1550. return this;
  1551. },
  1552. sub: function ( v, w ) {
  1553. if ( w !== undefined ) {
  1554. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1555. return this.subVectors( v, w );
  1556. }
  1557. this.x -= v.x;
  1558. this.y -= v.y;
  1559. this.z -= v.z;
  1560. this.w -= v.w;
  1561. return this;
  1562. },
  1563. subScalar: function ( s ) {
  1564. this.x -= s;
  1565. this.y -= s;
  1566. this.z -= s;
  1567. this.w -= s;
  1568. return this;
  1569. },
  1570. subVectors: function ( a, b ) {
  1571. this.x = a.x - b.x;
  1572. this.y = a.y - b.y;
  1573. this.z = a.z - b.z;
  1574. this.w = a.w - b.w;
  1575. return this;
  1576. },
  1577. multiplyScalar: function ( scalar ) {
  1578. this.x *= scalar;
  1579. this.y *= scalar;
  1580. this.z *= scalar;
  1581. this.w *= scalar;
  1582. return this;
  1583. },
  1584. applyMatrix4: function ( m ) {
  1585. var x = this.x;
  1586. var y = this.y;
  1587. var z = this.z;
  1588. var w = this.w;
  1589. var e = m.elements;
  1590. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1591. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1592. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1593. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1594. return this;
  1595. },
  1596. divideScalar: function ( scalar ) {
  1597. if ( scalar !== 0 ) {
  1598. var invScalar = 1 / scalar;
  1599. this.x *= invScalar;
  1600. this.y *= invScalar;
  1601. this.z *= invScalar;
  1602. this.w *= invScalar;
  1603. } else {
  1604. this.x = 0;
  1605. this.y = 0;
  1606. this.z = 0;
  1607. this.w = 1;
  1608. }
  1609. return this;
  1610. },
  1611. setAxisAngleFromQuaternion: function ( q ) {
  1612. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1613. // q is assumed to be normalized
  1614. this.w = 2 * Math.acos( q.w );
  1615. var s = Math.sqrt( 1 - q.w * q.w );
  1616. if ( s < 0.0001 ) {
  1617. this.x = 1;
  1618. this.y = 0;
  1619. this.z = 0;
  1620. } else {
  1621. this.x = q.x / s;
  1622. this.y = q.y / s;
  1623. this.z = q.z / s;
  1624. }
  1625. return this;
  1626. },
  1627. setAxisAngleFromRotationMatrix: function ( m ) {
  1628. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1629. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1630. var angle, x, y, z, // variables for result
  1631. epsilon = 0.01, // margin to allow for rounding errors
  1632. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1633. te = m.elements,
  1634. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1635. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1636. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1637. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1638. && ( Math.abs( m13 - m31 ) < epsilon )
  1639. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1640. // singularity found
  1641. // first check for identity matrix which must have +1 for all terms
  1642. // in leading diagonal and zero in other terms
  1643. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1644. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1645. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1646. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1647. // this singularity is identity matrix so angle = 0
  1648. this.set( 1, 0, 0, 0 );
  1649. return this; // zero angle, arbitrary axis
  1650. }
  1651. // otherwise this singularity is angle = 180
  1652. angle = Math.PI;
  1653. var xx = ( m11 + 1 ) / 2;
  1654. var yy = ( m22 + 1 ) / 2;
  1655. var zz = ( m33 + 1 ) / 2;
  1656. var xy = ( m12 + m21 ) / 4;
  1657. var xz = ( m13 + m31 ) / 4;
  1658. var yz = ( m23 + m32 ) / 4;
  1659. if ( ( xx > yy ) && ( xx > zz ) ) { // m11 is the largest diagonal term
  1660. if ( xx < epsilon ) {
  1661. x = 0;
  1662. y = 0.707106781;
  1663. z = 0.707106781;
  1664. } else {
  1665. x = Math.sqrt( xx );
  1666. y = xy / x;
  1667. z = xz / x;
  1668. }
  1669. } else if ( yy > zz ) { // m22 is the largest diagonal term
  1670. if ( yy < epsilon ) {
  1671. x = 0.707106781;
  1672. y = 0;
  1673. z = 0.707106781;
  1674. } else {
  1675. y = Math.sqrt( yy );
  1676. x = xy / y;
  1677. z = yz / y;
  1678. }
  1679. } else { // m33 is the largest diagonal term so base result on this
  1680. if ( zz < epsilon ) {
  1681. x = 0.707106781;
  1682. y = 0.707106781;
  1683. z = 0;
  1684. } else {
  1685. z = Math.sqrt( zz );
  1686. x = xz / z;
  1687. y = yz / z;
  1688. }
  1689. }
  1690. this.set( x, y, z, angle );
  1691. return this; // return 180 deg rotation
  1692. }
  1693. // as we have reached here there are no singularities so we can handle normally
  1694. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1695. + ( m13 - m31 ) * ( m13 - m31 )
  1696. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1697. if ( Math.abs( s ) < 0.001 ) s = 1;
  1698. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1699. // caught by singularity test above, but I've left it in just in case
  1700. this.x = ( m32 - m23 ) / s;
  1701. this.y = ( m13 - m31 ) / s;
  1702. this.z = ( m21 - m12 ) / s;
  1703. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1704. return this;
  1705. },
  1706. min: function ( v ) {
  1707. if ( this.x > v.x ) {
  1708. this.x = v.x;
  1709. }
  1710. if ( this.y > v.y ) {
  1711. this.y = v.y;
  1712. }
  1713. if ( this.z > v.z ) {
  1714. this.z = v.z;
  1715. }
  1716. if ( this.w > v.w ) {
  1717. this.w = v.w;
  1718. }
  1719. return this;
  1720. },
  1721. max: function ( v ) {
  1722. if ( this.x < v.x ) {
  1723. this.x = v.x;
  1724. }
  1725. if ( this.y < v.y ) {
  1726. this.y = v.y;
  1727. }
  1728. if ( this.z < v.z ) {
  1729. this.z = v.z;
  1730. }
  1731. if ( this.w < v.w ) {
  1732. this.w = v.w;
  1733. }
  1734. return this;
  1735. },
  1736. clamp: function ( min, max ) {
  1737. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1738. if ( this.x < min.x ) {
  1739. this.x = min.x;
  1740. } else if ( this.x > max.x ) {
  1741. this.x = max.x;
  1742. }
  1743. if ( this.y < min.y ) {
  1744. this.y = min.y;
  1745. } else if ( this.y > max.y ) {
  1746. this.y = max.y;
  1747. }
  1748. if ( this.z < min.z ) {
  1749. this.z = min.z;
  1750. } else if ( this.z > max.z ) {
  1751. this.z = max.z;
  1752. }
  1753. if ( this.w < min.w ) {
  1754. this.w = min.w;
  1755. } else if ( this.w > max.w ) {
  1756. this.w = max.w;
  1757. }
  1758. return this;
  1759. },
  1760. clampScalar: ( function () {
  1761. var min, max;
  1762. return function ( minVal, maxVal ) {
  1763. if ( min === undefined ) {
  1764. min = new THREE.Vector4();
  1765. max = new THREE.Vector4();
  1766. }
  1767. min.set( minVal, minVal, minVal, minVal );
  1768. max.set( maxVal, maxVal, maxVal, maxVal );
  1769. return this.clamp( min, max );
  1770. };
  1771. } )(),
  1772. floor: function () {
  1773. this.x = Math.floor( this.x );
  1774. this.y = Math.floor( this.y );
  1775. this.z = Math.floor( this.z );
  1776. this.w = Math.floor( this.w );
  1777. return this;
  1778. },
  1779. ceil: function () {
  1780. this.x = Math.ceil( this.x );
  1781. this.y = Math.ceil( this.y );
  1782. this.z = Math.ceil( this.z );
  1783. this.w = Math.ceil( this.w );
  1784. return this;
  1785. },
  1786. round: function () {
  1787. this.x = Math.round( this.x );
  1788. this.y = Math.round( this.y );
  1789. this.z = Math.round( this.z );
  1790. this.w = Math.round( this.w );
  1791. return this;
  1792. },
  1793. roundToZero: function () {
  1794. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1795. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1796. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1797. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1798. return this;
  1799. },
  1800. negate: function () {
  1801. this.x = - this.x;
  1802. this.y = - this.y;
  1803. this.z = - this.z;
  1804. this.w = - this.w;
  1805. return this;
  1806. },
  1807. dot: function ( v ) {
  1808. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1809. },
  1810. lengthSq: function () {
  1811. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1812. },
  1813. length: function () {
  1814. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1815. },
  1816. lengthManhattan: function () {
  1817. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1818. },
  1819. normalize: function () {
  1820. return this.divideScalar( this.length() );
  1821. },
  1822. setLength: function ( l ) {
  1823. var oldLength = this.length();
  1824. if ( oldLength !== 0 && l !== oldLength ) {
  1825. this.multiplyScalar( l / oldLength );
  1826. }
  1827. return this;
  1828. },
  1829. lerp: function ( v, alpha ) {
  1830. this.x += ( v.x - this.x ) * alpha;
  1831. this.y += ( v.y - this.y ) * alpha;
  1832. this.z += ( v.z - this.z ) * alpha;
  1833. this.w += ( v.w - this.w ) * alpha;
  1834. return this;
  1835. },
  1836. lerpVectors: function ( v1, v2, alpha ) {
  1837. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1838. return this;
  1839. },
  1840. equals: function ( v ) {
  1841. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1842. },
  1843. fromArray: function ( array, offset ) {
  1844. if ( offset === undefined ) offset = 0;
  1845. this.x = array[ offset ];
  1846. this.y = array[ offset + 1 ];
  1847. this.z = array[ offset + 2 ];
  1848. this.w = array[ offset + 3 ];
  1849. return this;
  1850. },
  1851. toArray: function ( array, offset ) {
  1852. if ( array === undefined ) array = [];
  1853. if ( offset === undefined ) offset = 0;
  1854. array[ offset ] = this.x;
  1855. array[ offset + 1 ] = this.y;
  1856. array[ offset + 2 ] = this.z;
  1857. array[ offset + 3 ] = this.w;
  1858. return array;
  1859. },
  1860. fromAttribute: function ( attribute, index, offset ) {
  1861. if ( offset === undefined ) offset = 0;
  1862. index = index * attribute.itemSize + offset;
  1863. this.x = attribute.array[ index ];
  1864. this.y = attribute.array[ index + 1 ];
  1865. this.z = attribute.array[ index + 2 ];
  1866. this.w = attribute.array[ index + 3 ];
  1867. return this;
  1868. },
  1869. clone: function () {
  1870. return new THREE.Vector4( this.x, this.y, this.z, this.w );
  1871. }
  1872. };
  1873. // File:src/math/Euler.js
  1874. /**
  1875. * @author mrdoob / http://mrdoob.com/
  1876. * @author WestLangley / http://github.com/WestLangley
  1877. * @author bhouston / http://exocortex.com
  1878. */
  1879. THREE.Euler = function ( x, y, z, order ) {
  1880. this._x = x || 0;
  1881. this._y = y || 0;
  1882. this._z = z || 0;
  1883. this._order = order || THREE.Euler.DefaultOrder;
  1884. };
  1885. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1886. THREE.Euler.DefaultOrder = 'XYZ';
  1887. THREE.Euler.prototype = {
  1888. constructor: THREE.Euler,
  1889. _x: 0, _y: 0, _z: 0, _order: THREE.Euler.DefaultOrder,
  1890. get x () {
  1891. return this._x;
  1892. },
  1893. set x ( value ) {
  1894. this._x = value;
  1895. this.onChangeCallback();
  1896. },
  1897. get y () {
  1898. return this._y;
  1899. },
  1900. set y ( value ) {
  1901. this._y = value;
  1902. this.onChangeCallback();
  1903. },
  1904. get z () {
  1905. return this._z;
  1906. },
  1907. set z ( value ) {
  1908. this._z = value;
  1909. this.onChangeCallback();
  1910. },
  1911. get order () {
  1912. return this._order;
  1913. },
  1914. set order ( value ) {
  1915. this._order = value;
  1916. this.onChangeCallback();
  1917. },
  1918. set: function ( x, y, z, order ) {
  1919. this._x = x;
  1920. this._y = y;
  1921. this._z = z;
  1922. this._order = order || this._order;
  1923. this.onChangeCallback();
  1924. return this;
  1925. },
  1926. copy: function ( euler ) {
  1927. this._x = euler._x;
  1928. this._y = euler._y;
  1929. this._z = euler._z;
  1930. this._order = euler._order;
  1931. this.onChangeCallback();
  1932. return this;
  1933. },
  1934. setFromRotationMatrix: function ( m, order, update ) {
  1935. var clamp = THREE.Math.clamp;
  1936. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1937. var te = m.elements;
  1938. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  1939. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  1940. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1941. order = order || this._order;
  1942. if ( order === 'XYZ' ) {
  1943. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  1944. if ( Math.abs( m13 ) < 0.99999 ) {
  1945. this._x = Math.atan2( - m23, m33 );
  1946. this._z = Math.atan2( - m12, m11 );
  1947. } else {
  1948. this._x = Math.atan2( m32, m22 );
  1949. this._z = 0;
  1950. }
  1951. } else if ( order === 'YXZ' ) {
  1952. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  1953. if ( Math.abs( m23 ) < 0.99999 ) {
  1954. this._y = Math.atan2( m13, m33 );
  1955. this._z = Math.atan2( m21, m22 );
  1956. } else {
  1957. this._y = Math.atan2( - m31, m11 );
  1958. this._z = 0;
  1959. }
  1960. } else if ( order === 'ZXY' ) {
  1961. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  1962. if ( Math.abs( m32 ) < 0.99999 ) {
  1963. this._y = Math.atan2( - m31, m33 );
  1964. this._z = Math.atan2( - m12, m22 );
  1965. } else {
  1966. this._y = 0;
  1967. this._z = Math.atan2( m21, m11 );
  1968. }
  1969. } else if ( order === 'ZYX' ) {
  1970. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  1971. if ( Math.abs( m31 ) < 0.99999 ) {
  1972. this._x = Math.atan2( m32, m33 );
  1973. this._z = Math.atan2( m21, m11 );
  1974. } else {
  1975. this._x = 0;
  1976. this._z = Math.atan2( - m12, m22 );
  1977. }
  1978. } else if ( order === 'YZX' ) {
  1979. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  1980. if ( Math.abs( m21 ) < 0.99999 ) {
  1981. this._x = Math.atan2( - m23, m22 );
  1982. this._y = Math.atan2( - m31, m11 );
  1983. } else {
  1984. this._x = 0;
  1985. this._y = Math.atan2( m13, m33 );
  1986. }
  1987. } else if ( order === 'XZY' ) {
  1988. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  1989. if ( Math.abs( m12 ) < 0.99999 ) {
  1990. this._x = Math.atan2( m32, m22 );
  1991. this._y = Math.atan2( m13, m11 );
  1992. } else {
  1993. this._x = Math.atan2( - m23, m33 );
  1994. this._y = 0;
  1995. }
  1996. } else {
  1997. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  1998. }
  1999. this._order = order;
  2000. if ( update !== false ) this.onChangeCallback();
  2001. return this;
  2002. },
  2003. setFromQuaternion: function () {
  2004. var matrix;
  2005. return function ( q, order, update ) {
  2006. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2007. matrix.makeRotationFromQuaternion( q );
  2008. this.setFromRotationMatrix( matrix, order, update );
  2009. return this;
  2010. };
  2011. }(),
  2012. setFromVector3: function ( v, order ) {
  2013. return this.set( v.x, v.y, v.z, order || this._order );
  2014. },
  2015. reorder: function () {
  2016. // WARNING: this discards revolution information -bhouston
  2017. var q = new THREE.Quaternion();
  2018. return function ( newOrder ) {
  2019. q.setFromEuler( this );
  2020. this.setFromQuaternion( q, newOrder );
  2021. };
  2022. }(),
  2023. equals: function ( euler ) {
  2024. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2025. },
  2026. fromArray: function ( array ) {
  2027. this._x = array[ 0 ];
  2028. this._y = array[ 1 ];
  2029. this._z = array[ 2 ];
  2030. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2031. this.onChangeCallback();
  2032. return this;
  2033. },
  2034. toArray: function ( array, offset ) {
  2035. if ( array === undefined ) array = [];
  2036. if ( offset === undefined ) offset = 0;
  2037. array[ offset ] = this._x;
  2038. array[ offset + 1 ] = this._y;
  2039. array[ offset + 2 ] = this._z;
  2040. array[ offset + 3 ] = this._order;
  2041. return array;
  2042. },
  2043. toVector3: function ( optionalResult ) {
  2044. if ( optionalResult ) {
  2045. return optionalResult.set( this._x, this._y, this._z );
  2046. } else {
  2047. return new THREE.Vector3( this._x, this._y, this._z );
  2048. }
  2049. },
  2050. onChange: function ( callback ) {
  2051. this.onChangeCallback = callback;
  2052. return this;
  2053. },
  2054. onChangeCallback: function () {},
  2055. clone: function () {
  2056. return new THREE.Euler( this._x, this._y, this._z, this._order );
  2057. }
  2058. };
  2059. // File:src/math/Line3.js
  2060. /**
  2061. * @author bhouston / http://exocortex.com
  2062. */
  2063. THREE.Line3 = function ( start, end ) {
  2064. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2065. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2066. };
  2067. THREE.Line3.prototype = {
  2068. constructor: THREE.Line3,
  2069. set: function ( start, end ) {
  2070. this.start.copy( start );
  2071. this.end.copy( end );
  2072. return this;
  2073. },
  2074. copy: function ( line ) {
  2075. this.start.copy( line.start );
  2076. this.end.copy( line.end );
  2077. return this;
  2078. },
  2079. center: function ( optionalTarget ) {
  2080. var result = optionalTarget || new THREE.Vector3();
  2081. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2082. },
  2083. delta: function ( optionalTarget ) {
  2084. var result = optionalTarget || new THREE.Vector3();
  2085. return result.subVectors( this.end, this.start );
  2086. },
  2087. distanceSq: function () {
  2088. return this.start.distanceToSquared( this.end );
  2089. },
  2090. distance: function () {
  2091. return this.start.distanceTo( this.end );
  2092. },
  2093. at: function ( t, optionalTarget ) {
  2094. var result = optionalTarget || new THREE.Vector3();
  2095. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2096. },
  2097. closestPointToPointParameter: function () {
  2098. var startP = new THREE.Vector3();
  2099. var startEnd = new THREE.Vector3();
  2100. return function ( point, clampToLine ) {
  2101. startP.subVectors( point, this.start );
  2102. startEnd.subVectors( this.end, this.start );
  2103. var startEnd2 = startEnd.dot( startEnd );
  2104. var startEnd_startP = startEnd.dot( startP );
  2105. var t = startEnd_startP / startEnd2;
  2106. if ( clampToLine ) {
  2107. t = THREE.Math.clamp( t, 0, 1 );
  2108. }
  2109. return t;
  2110. };
  2111. }(),
  2112. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2113. var t = this.closestPointToPointParameter( point, clampToLine );
  2114. var result = optionalTarget || new THREE.Vector3();
  2115. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2116. },
  2117. applyMatrix4: function ( matrix ) {
  2118. this.start.applyMatrix4( matrix );
  2119. this.end.applyMatrix4( matrix );
  2120. return this;
  2121. },
  2122. equals: function ( line ) {
  2123. return line.start.equals( this.start ) && line.end.equals( this.end );
  2124. },
  2125. clone: function () {
  2126. return new THREE.Line3().copy( this );
  2127. }
  2128. };
  2129. // File:src/math/Box2.js
  2130. /**
  2131. * @author bhouston / http://exocortex.com
  2132. */
  2133. THREE.Box2 = function ( min, max ) {
  2134. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  2135. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2136. };
  2137. THREE.Box2.prototype = {
  2138. constructor: THREE.Box2,
  2139. set: function ( min, max ) {
  2140. this.min.copy( min );
  2141. this.max.copy( max );
  2142. return this;
  2143. },
  2144. setFromPoints: function ( points ) {
  2145. this.makeEmpty();
  2146. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2147. this.expandByPoint( points[ i ] )
  2148. }
  2149. return this;
  2150. },
  2151. setFromCenterAndSize: function () {
  2152. var v1 = new THREE.Vector2();
  2153. return function ( center, size ) {
  2154. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2155. this.min.copy( center ).sub( halfSize );
  2156. this.max.copy( center ).add( halfSize );
  2157. return this;
  2158. };
  2159. }(),
  2160. copy: function ( box ) {
  2161. this.min.copy( box.min );
  2162. this.max.copy( box.max );
  2163. return this;
  2164. },
  2165. makeEmpty: function () {
  2166. this.min.x = this.min.y = Infinity;
  2167. this.max.x = this.max.y = - Infinity;
  2168. return this;
  2169. },
  2170. empty: function () {
  2171. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2172. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2173. },
  2174. center: function ( optionalTarget ) {
  2175. var result = optionalTarget || new THREE.Vector2();
  2176. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2177. },
  2178. size: function ( optionalTarget ) {
  2179. var result = optionalTarget || new THREE.Vector2();
  2180. return result.subVectors( this.max, this.min );
  2181. },
  2182. expandByPoint: function ( point ) {
  2183. this.min.min( point );
  2184. this.max.max( point );
  2185. return this;
  2186. },
  2187. expandByVector: function ( vector ) {
  2188. this.min.sub( vector );
  2189. this.max.add( vector );
  2190. return this;
  2191. },
  2192. expandByScalar: function ( scalar ) {
  2193. this.min.addScalar( - scalar );
  2194. this.max.addScalar( scalar );
  2195. return this;
  2196. },
  2197. containsPoint: function ( point ) {
  2198. if ( point.x < this.min.x || point.x > this.max.x ||
  2199. point.y < this.min.y || point.y > this.max.y ) {
  2200. return false;
  2201. }
  2202. return true;
  2203. },
  2204. containsBox: function ( box ) {
  2205. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2206. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2207. return true;
  2208. }
  2209. return false;
  2210. },
  2211. getParameter: function ( point, optionalTarget ) {
  2212. // This can potentially have a divide by zero if the box
  2213. // has a size dimension of 0.
  2214. var result = optionalTarget || new THREE.Vector2();
  2215. return result.set(
  2216. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2217. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2218. );
  2219. },
  2220. isIntersectionBox: function ( box ) {
  2221. // using 6 splitting planes to rule out intersections.
  2222. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2223. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2224. return false;
  2225. }
  2226. return true;
  2227. },
  2228. clampPoint: function ( point, optionalTarget ) {
  2229. var result = optionalTarget || new THREE.Vector2();
  2230. return result.copy( point ).clamp( this.min, this.max );
  2231. },
  2232. distanceToPoint: function () {
  2233. var v1 = new THREE.Vector2();
  2234. return function ( point ) {
  2235. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2236. return clampedPoint.sub( point ).length();
  2237. };
  2238. }(),
  2239. intersect: function ( box ) {
  2240. this.min.max( box.min );
  2241. this.max.min( box.max );
  2242. return this;
  2243. },
  2244. union: function ( box ) {
  2245. this.min.min( box.min );
  2246. this.max.max( box.max );
  2247. return this;
  2248. },
  2249. translate: function ( offset ) {
  2250. this.min.add( offset );
  2251. this.max.add( offset );
  2252. return this;
  2253. },
  2254. equals: function ( box ) {
  2255. return box.min.equals( this.min ) && box.max.equals( this.max );
  2256. },
  2257. clone: function () {
  2258. return new THREE.Box2().copy( this );
  2259. }
  2260. };
  2261. // File:src/math/Box3.js
  2262. /**
  2263. * @author bhouston / http://exocortex.com
  2264. * @author WestLangley / http://github.com/WestLangley
  2265. */
  2266. THREE.Box3 = function ( min, max ) {
  2267. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2268. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2269. };
  2270. THREE.Box3.prototype = {
  2271. constructor: THREE.Box3,
  2272. set: function ( min, max ) {
  2273. this.min.copy( min );
  2274. this.max.copy( max );
  2275. return this;
  2276. },
  2277. setFromPoints: function ( points ) {
  2278. this.makeEmpty();
  2279. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2280. this.expandByPoint( points[ i ] );
  2281. }
  2282. return this;
  2283. },
  2284. setFromCenterAndSize: function () {
  2285. var v1 = new THREE.Vector3();
  2286. return function ( center, size ) {
  2287. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2288. this.min.copy( center ).sub( halfSize );
  2289. this.max.copy( center ).add( halfSize );
  2290. return this;
  2291. };
  2292. }(),
  2293. setFromObject: function () {
  2294. // Computes the world-axis-aligned bounding box of an object (including its children),
  2295. // accounting for both the object's, and children's, world transforms
  2296. var v1 = new THREE.Vector3();
  2297. return function ( object ) {
  2298. var scope = this;
  2299. object.updateMatrixWorld( true );
  2300. this.makeEmpty();
  2301. object.traverse( function ( node ) {
  2302. var geometry = node.geometry;
  2303. if ( geometry !== undefined ) {
  2304. if ( geometry instanceof THREE.Geometry ) {
  2305. var vertices = geometry.vertices;
  2306. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2307. v1.copy( vertices[ i ] );
  2308. v1.applyMatrix4( node.matrixWorld );
  2309. scope.expandByPoint( v1 );
  2310. }
  2311. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2312. var positions = geometry.attributes[ 'position' ].array;
  2313. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2314. v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
  2315. v1.applyMatrix4( node.matrixWorld );
  2316. scope.expandByPoint( v1 );
  2317. }
  2318. }
  2319. }
  2320. } );
  2321. return this;
  2322. };
  2323. }(),
  2324. copy: function ( box ) {
  2325. this.min.copy( box.min );
  2326. this.max.copy( box.max );
  2327. return this;
  2328. },
  2329. makeEmpty: function () {
  2330. this.min.x = this.min.y = this.min.z = Infinity;
  2331. this.max.x = this.max.y = this.max.z = - Infinity;
  2332. return this;
  2333. },
  2334. empty: function () {
  2335. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2336. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2337. },
  2338. center: function ( optionalTarget ) {
  2339. var result = optionalTarget || new THREE.Vector3();
  2340. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2341. },
  2342. size: function ( optionalTarget ) {
  2343. var result = optionalTarget || new THREE.Vector3();
  2344. return result.subVectors( this.max, this.min );
  2345. },
  2346. expandByPoint: function ( point ) {
  2347. this.min.min( point );
  2348. this.max.max( point );
  2349. return this;
  2350. },
  2351. expandByVector: function ( vector ) {
  2352. this.min.sub( vector );
  2353. this.max.add( vector );
  2354. return this;
  2355. },
  2356. expandByScalar: function ( scalar ) {
  2357. this.min.addScalar( - scalar );
  2358. this.max.addScalar( scalar );
  2359. return this;
  2360. },
  2361. containsPoint: function ( point ) {
  2362. if ( point.x < this.min.x || point.x > this.max.x ||
  2363. point.y < this.min.y || point.y > this.max.y ||
  2364. point.z < this.min.z || point.z > this.max.z ) {
  2365. return false;
  2366. }
  2367. return true;
  2368. },
  2369. containsBox: function ( box ) {
  2370. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2371. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2372. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2373. return true;
  2374. }
  2375. return false;
  2376. },
  2377. getParameter: function ( point, optionalTarget ) {
  2378. // This can potentially have a divide by zero if the box
  2379. // has a size dimension of 0.
  2380. var result = optionalTarget || new THREE.Vector3();
  2381. return result.set(
  2382. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2383. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2384. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2385. );
  2386. },
  2387. isIntersectionBox: function ( box ) {
  2388. // using 6 splitting planes to rule out intersections.
  2389. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2390. box.max.y < this.min.y || box.min.y > this.max.y ||
  2391. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2392. return false;
  2393. }
  2394. return true;
  2395. },
  2396. clampPoint: function ( point, optionalTarget ) {
  2397. var result = optionalTarget || new THREE.Vector3();
  2398. return result.copy( point ).clamp( this.min, this.max );
  2399. },
  2400. distanceToPoint: function () {
  2401. var v1 = new THREE.Vector3();
  2402. return function ( point ) {
  2403. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2404. return clampedPoint.sub( point ).length();
  2405. };
  2406. }(),
  2407. getBoundingSphere: function () {
  2408. var v1 = new THREE.Vector3();
  2409. return function ( optionalTarget ) {
  2410. var result = optionalTarget || new THREE.Sphere();
  2411. result.center = this.center();
  2412. result.radius = this.size( v1 ).length() * 0.5;
  2413. return result;
  2414. };
  2415. }(),
  2416. intersect: function ( box ) {
  2417. this.min.max( box.min );
  2418. this.max.min( box.max );
  2419. return this;
  2420. },
  2421. union: function ( box ) {
  2422. this.min.min( box.min );
  2423. this.max.max( box.max );
  2424. return this;
  2425. },
  2426. applyMatrix4: function () {
  2427. var points = [
  2428. new THREE.Vector3(),
  2429. new THREE.Vector3(),
  2430. new THREE.Vector3(),
  2431. new THREE.Vector3(),
  2432. new THREE.Vector3(),
  2433. new THREE.Vector3(),
  2434. new THREE.Vector3(),
  2435. new THREE.Vector3()
  2436. ];
  2437. return function ( matrix ) {
  2438. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2439. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2440. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2441. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2442. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2443. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2444. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2445. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2446. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2447. this.makeEmpty();
  2448. this.setFromPoints( points );
  2449. return this;
  2450. };
  2451. }(),
  2452. translate: function ( offset ) {
  2453. this.min.add( offset );
  2454. this.max.add( offset );
  2455. return this;
  2456. },
  2457. equals: function ( box ) {
  2458. return box.min.equals( this.min ) && box.max.equals( this.max );
  2459. },
  2460. clone: function () {
  2461. return new THREE.Box3().copy( this );
  2462. }
  2463. };
  2464. // File:src/math/Matrix3.js
  2465. /**
  2466. * @author alteredq / http://alteredqualia.com/
  2467. * @author WestLangley / http://github.com/WestLangley
  2468. * @author bhouston / http://exocortex.com
  2469. */
  2470. THREE.Matrix3 = function () {
  2471. this.elements = new Float32Array( [
  2472. 1, 0, 0,
  2473. 0, 1, 0,
  2474. 0, 0, 1
  2475. ] );
  2476. if ( arguments.length > 0 ) {
  2477. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2478. }
  2479. };
  2480. THREE.Matrix3.prototype = {
  2481. constructor: THREE.Matrix3,
  2482. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2483. var te = this.elements;
  2484. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2485. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2486. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2487. return this;
  2488. },
  2489. identity: function () {
  2490. this.set(
  2491. 1, 0, 0,
  2492. 0, 1, 0,
  2493. 0, 0, 1
  2494. );
  2495. return this;
  2496. },
  2497. copy: function ( m ) {
  2498. var me = m.elements;
  2499. this.set(
  2500. me[ 0 ], me[ 3 ], me[ 6 ],
  2501. me[ 1 ], me[ 4 ], me[ 7 ],
  2502. me[ 2 ], me[ 5 ], me[ 8 ]
  2503. );
  2504. return this;
  2505. },
  2506. multiplyVector3: function ( vector ) {
  2507. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  2508. return vector.applyMatrix3( this );
  2509. },
  2510. multiplyVector3Array: function ( a ) {
  2511. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2512. return this.applyToVector3Array( a );
  2513. },
  2514. applyToVector3Array: function () {
  2515. var v1;
  2516. return function ( array, offset, length ) {
  2517. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2518. if ( offset === undefined ) offset = 0;
  2519. if ( length === undefined ) length = array.length;
  2520. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2521. v1.fromArray( array, j );
  2522. v1.applyMatrix3( this );
  2523. v1.toArray( array, j );
  2524. }
  2525. return array;
  2526. };
  2527. }(),
  2528. applyToBuffer: function () {
  2529. var v1;
  2530. return function applyToBuffer( buffer, offset, length ) {
  2531. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2532. if ( offset === undefined ) offset = 0;
  2533. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2534. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2535. v1.x = buffer.getX( j );
  2536. v1.y = buffer.getY( j );
  2537. v1.z = buffer.getZ( j );
  2538. v1.applyMatrix3( this );
  2539. buffer.setXYZ( v1.x, v1.y, v1.z );
  2540. }
  2541. return buffer;
  2542. };
  2543. }(),
  2544. multiplyScalar: function ( s ) {
  2545. var te = this.elements;
  2546. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2547. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2548. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2549. return this;
  2550. },
  2551. determinant: function () {
  2552. var te = this.elements;
  2553. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2554. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2555. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2556. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2557. },
  2558. getInverse: function ( matrix, throwOnInvertible ) {
  2559. // input: THREE.Matrix4
  2560. // ( based on http://code.google.com/p/webgl-mjs/ )
  2561. var me = matrix.elements;
  2562. var te = this.elements;
  2563. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2564. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2565. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2566. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2567. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2568. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2569. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2570. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2571. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2572. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2573. // no inverse
  2574. if ( det === 0 ) {
  2575. var msg = "Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2576. if ( throwOnInvertible || false ) {
  2577. throw new Error( msg );
  2578. } else {
  2579. console.warn( msg );
  2580. }
  2581. this.identity();
  2582. return this;
  2583. }
  2584. this.multiplyScalar( 1.0 / det );
  2585. return this;
  2586. },
  2587. transpose: function () {
  2588. var tmp, m = this.elements;
  2589. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2590. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2591. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2592. return this;
  2593. },
  2594. flattenToArrayOffset: function ( array, offset ) {
  2595. var te = this.elements;
  2596. array[ offset ] = te[ 0 ];
  2597. array[ offset + 1 ] = te[ 1 ];
  2598. array[ offset + 2 ] = te[ 2 ];
  2599. array[ offset + 3 ] = te[ 3 ];
  2600. array[ offset + 4 ] = te[ 4 ];
  2601. array[ offset + 5 ] = te[ 5 ];
  2602. array[ offset + 6 ] = te[ 6 ];
  2603. array[ offset + 7 ] = te[ 7 ];
  2604. array[ offset + 8 ] = te[ 8 ];
  2605. return array;
  2606. },
  2607. getNormalMatrix: function ( m ) {
  2608. // input: THREE.Matrix4
  2609. this.getInverse( m ).transpose();
  2610. return this;
  2611. },
  2612. transposeIntoArray: function ( r ) {
  2613. var m = this.elements;
  2614. r[ 0 ] = m[ 0 ];
  2615. r[ 1 ] = m[ 3 ];
  2616. r[ 2 ] = m[ 6 ];
  2617. r[ 3 ] = m[ 1 ];
  2618. r[ 4 ] = m[ 4 ];
  2619. r[ 5 ] = m[ 7 ];
  2620. r[ 6 ] = m[ 2 ];
  2621. r[ 7 ] = m[ 5 ];
  2622. r[ 8 ] = m[ 8 ];
  2623. return this;
  2624. },
  2625. fromArray: function ( array ) {
  2626. this.elements.set( array );
  2627. return this;
  2628. },
  2629. toArray: function () {
  2630. var te = this.elements;
  2631. return [
  2632. te[ 0 ], te[ 1 ], te[ 2 ],
  2633. te[ 3 ], te[ 4 ], te[ 5 ],
  2634. te[ 6 ], te[ 7 ], te[ 8 ]
  2635. ];
  2636. },
  2637. clone: function () {
  2638. return new THREE.Matrix3().fromArray( this.elements );
  2639. }
  2640. };
  2641. // File:src/math/Matrix4.js
  2642. /**
  2643. * @author mrdoob / http://mrdoob.com/
  2644. * @author supereggbert / http://www.paulbrunt.co.uk/
  2645. * @author philogb / http://blog.thejit.org/
  2646. * @author jordi_ros / http://plattsoft.com
  2647. * @author D1plo1d / http://github.com/D1plo1d
  2648. * @author alteredq / http://alteredqualia.com/
  2649. * @author mikael emtinger / http://gomo.se/
  2650. * @author timknip / http://www.floorplanner.com/
  2651. * @author bhouston / http://exocortex.com
  2652. * @author WestLangley / http://github.com/WestLangley
  2653. */
  2654. THREE.Matrix4 = function () {
  2655. this.elements = new Float32Array( [
  2656. 1, 0, 0, 0,
  2657. 0, 1, 0, 0,
  2658. 0, 0, 1, 0,
  2659. 0, 0, 0, 1
  2660. ] );
  2661. if ( arguments.length > 0 ) {
  2662. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2663. }
  2664. };
  2665. THREE.Matrix4.prototype = {
  2666. constructor: THREE.Matrix4,
  2667. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2668. var te = this.elements;
  2669. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2670. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2671. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2672. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2673. return this;
  2674. },
  2675. identity: function () {
  2676. this.set(
  2677. 1, 0, 0, 0,
  2678. 0, 1, 0, 0,
  2679. 0, 0, 1, 0,
  2680. 0, 0, 0, 1
  2681. );
  2682. return this;
  2683. },
  2684. copy: function ( m ) {
  2685. this.elements.set( m.elements );
  2686. return this;
  2687. },
  2688. extractPosition: function ( m ) {
  2689. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  2690. return this.copyPosition( m );
  2691. },
  2692. copyPosition: function ( m ) {
  2693. var te = this.elements;
  2694. var me = m.elements;
  2695. te[ 12 ] = me[ 12 ];
  2696. te[ 13 ] = me[ 13 ];
  2697. te[ 14 ] = me[ 14 ];
  2698. return this;
  2699. },
  2700. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2701. var te = this.elements;
  2702. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2703. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2704. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2705. return this;
  2706. },
  2707. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2708. this.set(
  2709. xAxis.x, yAxis.x, zAxis.x, 0,
  2710. xAxis.y, yAxis.y, zAxis.y, 0,
  2711. xAxis.z, yAxis.z, zAxis.z, 0,
  2712. 0, 0, 0, 1
  2713. );
  2714. return this;
  2715. },
  2716. extractRotation: function () {
  2717. var v1;
  2718. return function ( m ) {
  2719. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2720. var te = this.elements;
  2721. var me = m.elements;
  2722. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2723. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2724. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2725. te[ 0 ] = me[ 0 ] * scaleX;
  2726. te[ 1 ] = me[ 1 ] * scaleX;
  2727. te[ 2 ] = me[ 2 ] * scaleX;
  2728. te[ 4 ] = me[ 4 ] * scaleY;
  2729. te[ 5 ] = me[ 5 ] * scaleY;
  2730. te[ 6 ] = me[ 6 ] * scaleY;
  2731. te[ 8 ] = me[ 8 ] * scaleZ;
  2732. te[ 9 ] = me[ 9 ] * scaleZ;
  2733. te[ 10 ] = me[ 10 ] * scaleZ;
  2734. return this;
  2735. };
  2736. }(),
  2737. makeRotationFromEuler: function ( euler ) {
  2738. if ( euler instanceof THREE.Euler === false ) {
  2739. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2740. }
  2741. var te = this.elements;
  2742. var x = euler.x, y = euler.y, z = euler.z;
  2743. var a = Math.cos( x ), b = Math.sin( x );
  2744. var c = Math.cos( y ), d = Math.sin( y );
  2745. var e = Math.cos( z ), f = Math.sin( z );
  2746. if ( euler.order === 'XYZ' ) {
  2747. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2748. te[ 0 ] = c * e;
  2749. te[ 4 ] = - c * f;
  2750. te[ 8 ] = d;
  2751. te[ 1 ] = af + be * d;
  2752. te[ 5 ] = ae - bf * d;
  2753. te[ 9 ] = - b * c;
  2754. te[ 2 ] = bf - ae * d;
  2755. te[ 6 ] = be + af * d;
  2756. te[ 10 ] = a * c;
  2757. } else if ( euler.order === 'YXZ' ) {
  2758. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2759. te[ 0 ] = ce + df * b;
  2760. te[ 4 ] = de * b - cf;
  2761. te[ 8 ] = a * d;
  2762. te[ 1 ] = a * f;
  2763. te[ 5 ] = a * e;
  2764. te[ 9 ] = - b;
  2765. te[ 2 ] = cf * b - de;
  2766. te[ 6 ] = df + ce * b;
  2767. te[ 10 ] = a * c;
  2768. } else if ( euler.order === 'ZXY' ) {
  2769. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2770. te[ 0 ] = ce - df * b;
  2771. te[ 4 ] = - a * f;
  2772. te[ 8 ] = de + cf * b;
  2773. te[ 1 ] = cf + de * b;
  2774. te[ 5 ] = a * e;
  2775. te[ 9 ] = df - ce * b;
  2776. te[ 2 ] = - a * d;
  2777. te[ 6 ] = b;
  2778. te[ 10 ] = a * c;
  2779. } else if ( euler.order === 'ZYX' ) {
  2780. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2781. te[ 0 ] = c * e;
  2782. te[ 4 ] = be * d - af;
  2783. te[ 8 ] = ae * d + bf;
  2784. te[ 1 ] = c * f;
  2785. te[ 5 ] = bf * d + ae;
  2786. te[ 9 ] = af * d - be;
  2787. te[ 2 ] = - d;
  2788. te[ 6 ] = b * c;
  2789. te[ 10 ] = a * c;
  2790. } else if ( euler.order === 'YZX' ) {
  2791. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2792. te[ 0 ] = c * e;
  2793. te[ 4 ] = bd - ac * f;
  2794. te[ 8 ] = bc * f + ad;
  2795. te[ 1 ] = f;
  2796. te[ 5 ] = a * e;
  2797. te[ 9 ] = - b * e;
  2798. te[ 2 ] = - d * e;
  2799. te[ 6 ] = ad * f + bc;
  2800. te[ 10 ] = ac - bd * f;
  2801. } else if ( euler.order === 'XZY' ) {
  2802. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2803. te[ 0 ] = c * e;
  2804. te[ 4 ] = - f;
  2805. te[ 8 ] = d * e;
  2806. te[ 1 ] = ac * f + bd;
  2807. te[ 5 ] = a * e;
  2808. te[ 9 ] = ad * f - bc;
  2809. te[ 2 ] = bc * f - ad;
  2810. te[ 6 ] = b * e;
  2811. te[ 10 ] = bd * f + ac;
  2812. }
  2813. // last column
  2814. te[ 3 ] = 0;
  2815. te[ 7 ] = 0;
  2816. te[ 11 ] = 0;
  2817. // bottom row
  2818. te[ 12 ] = 0;
  2819. te[ 13 ] = 0;
  2820. te[ 14 ] = 0;
  2821. te[ 15 ] = 1;
  2822. return this;
  2823. },
  2824. setRotationFromQuaternion: function ( q ) {
  2825. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  2826. return this.makeRotationFromQuaternion( q );
  2827. },
  2828. makeRotationFromQuaternion: function ( q ) {
  2829. var te = this.elements;
  2830. var x = q.x, y = q.y, z = q.z, w = q.w;
  2831. var x2 = x + x, y2 = y + y, z2 = z + z;
  2832. var xx = x * x2, xy = x * y2, xz = x * z2;
  2833. var yy = y * y2, yz = y * z2, zz = z * z2;
  2834. var wx = w * x2, wy = w * y2, wz = w * z2;
  2835. te[ 0 ] = 1 - ( yy + zz );
  2836. te[ 4 ] = xy - wz;
  2837. te[ 8 ] = xz + wy;
  2838. te[ 1 ] = xy + wz;
  2839. te[ 5 ] = 1 - ( xx + zz );
  2840. te[ 9 ] = yz - wx;
  2841. te[ 2 ] = xz - wy;
  2842. te[ 6 ] = yz + wx;
  2843. te[ 10 ] = 1 - ( xx + yy );
  2844. // last column
  2845. te[ 3 ] = 0;
  2846. te[ 7 ] = 0;
  2847. te[ 11 ] = 0;
  2848. // bottom row
  2849. te[ 12 ] = 0;
  2850. te[ 13 ] = 0;
  2851. te[ 14 ] = 0;
  2852. te[ 15 ] = 1;
  2853. return this;
  2854. },
  2855. lookAt: function () {
  2856. var x, y, z;
  2857. return function ( eye, target, up ) {
  2858. if ( x === undefined ) x = new THREE.Vector3();
  2859. if ( y === undefined ) y = new THREE.Vector3();
  2860. if ( z === undefined ) z = new THREE.Vector3();
  2861. var te = this.elements;
  2862. z.subVectors( eye, target ).normalize();
  2863. if ( z.length() === 0 ) {
  2864. z.z = 1;
  2865. }
  2866. x.crossVectors( up, z ).normalize();
  2867. if ( x.length() === 0 ) {
  2868. z.x += 0.0001;
  2869. x.crossVectors( up, z ).normalize();
  2870. }
  2871. y.crossVectors( z, x );
  2872. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2873. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2874. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2875. return this;
  2876. };
  2877. }(),
  2878. multiply: function ( m, n ) {
  2879. if ( n !== undefined ) {
  2880. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2881. return this.multiplyMatrices( m, n );
  2882. }
  2883. return this.multiplyMatrices( this, m );
  2884. },
  2885. multiplyMatrices: function ( a, b ) {
  2886. var ae = a.elements;
  2887. var be = b.elements;
  2888. var te = this.elements;
  2889. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2890. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2891. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2892. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2893. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2894. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2895. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2896. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2897. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2898. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2899. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2900. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2901. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2902. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2903. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2904. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2905. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2906. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2907. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2908. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2909. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2910. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2911. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2912. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2913. return this;
  2914. },
  2915. multiplyToArray: function ( a, b, r ) {
  2916. var te = this.elements;
  2917. this.multiplyMatrices( a, b );
  2918. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  2919. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  2920. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  2921. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  2922. return this;
  2923. },
  2924. multiplyScalar: function ( s ) {
  2925. var te = this.elements;
  2926. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2927. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2928. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2929. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2930. return this;
  2931. },
  2932. multiplyVector3: function ( vector ) {
  2933. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  2934. return vector.applyProjection( this );
  2935. },
  2936. multiplyVector4: function ( vector ) {
  2937. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  2938. return vector.applyMatrix4( this );
  2939. },
  2940. multiplyVector3Array: function ( a ) {
  2941. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2942. return this.applyToVector3Array( a );
  2943. },
  2944. applyToVector3Array: function () {
  2945. var v1;
  2946. return function ( array, offset, length ) {
  2947. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2948. if ( offset === undefined ) offset = 0;
  2949. if ( length === undefined ) length = array.length;
  2950. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2951. v1.fromArray( array, j );
  2952. v1.applyMatrix4( this );
  2953. v1.toArray( array, j );
  2954. }
  2955. return array;
  2956. };
  2957. }(),
  2958. applyToBuffer: function () {
  2959. var v1;
  2960. return function applyToBuffer( buffer, offset, length ) {
  2961. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2962. if ( offset === undefined ) offset = 0;
  2963. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2964. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2965. v1.x = buffer.getX( j );
  2966. v1.y = buffer.getY( j );
  2967. v1.z = buffer.getZ( j );
  2968. v1.applyMatrix4( this );
  2969. buffer.setXYZ( v1.x, v1.y, v1.z );
  2970. }
  2971. return buffer;
  2972. };
  2973. }(),
  2974. rotateAxis: function ( v ) {
  2975. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  2976. v.transformDirection( this );
  2977. },
  2978. crossVector: function ( vector ) {
  2979. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  2980. return vector.applyMatrix4( this );
  2981. },
  2982. determinant: function () {
  2983. var te = this.elements;
  2984. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  2985. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  2986. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  2987. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  2988. //TODO: make this more efficient
  2989. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  2990. return (
  2991. n41 * (
  2992. + n14 * n23 * n32
  2993. - n13 * n24 * n32
  2994. - n14 * n22 * n33
  2995. + n12 * n24 * n33
  2996. + n13 * n22 * n34
  2997. - n12 * n23 * n34
  2998. ) +
  2999. n42 * (
  3000. + n11 * n23 * n34
  3001. - n11 * n24 * n33
  3002. + n14 * n21 * n33
  3003. - n13 * n21 * n34
  3004. + n13 * n24 * n31
  3005. - n14 * n23 * n31
  3006. ) +
  3007. n43 * (
  3008. + n11 * n24 * n32
  3009. - n11 * n22 * n34
  3010. - n14 * n21 * n32
  3011. + n12 * n21 * n34
  3012. + n14 * n22 * n31
  3013. - n12 * n24 * n31
  3014. ) +
  3015. n44 * (
  3016. - n13 * n22 * n31
  3017. - n11 * n23 * n32
  3018. + n11 * n22 * n33
  3019. + n13 * n21 * n32
  3020. - n12 * n21 * n33
  3021. + n12 * n23 * n31
  3022. )
  3023. );
  3024. },
  3025. transpose: function () {
  3026. var te = this.elements;
  3027. var tmp;
  3028. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3029. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3030. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3031. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3032. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3033. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3034. return this;
  3035. },
  3036. flattenToArrayOffset: function ( array, offset ) {
  3037. var te = this.elements;
  3038. array[ offset ] = te[ 0 ];
  3039. array[ offset + 1 ] = te[ 1 ];
  3040. array[ offset + 2 ] = te[ 2 ];
  3041. array[ offset + 3 ] = te[ 3 ];
  3042. array[ offset + 4 ] = te[ 4 ];
  3043. array[ offset + 5 ] = te[ 5 ];
  3044. array[ offset + 6 ] = te[ 6 ];
  3045. array[ offset + 7 ] = te[ 7 ];
  3046. array[ offset + 8 ] = te[ 8 ];
  3047. array[ offset + 9 ] = te[ 9 ];
  3048. array[ offset + 10 ] = te[ 10 ];
  3049. array[ offset + 11 ] = te[ 11 ];
  3050. array[ offset + 12 ] = te[ 12 ];
  3051. array[ offset + 13 ] = te[ 13 ];
  3052. array[ offset + 14 ] = te[ 14 ];
  3053. array[ offset + 15 ] = te[ 15 ];
  3054. return array;
  3055. },
  3056. getPosition: function () {
  3057. var v1;
  3058. return function () {
  3059. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3060. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3061. var te = this.elements;
  3062. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3063. };
  3064. }(),
  3065. setPosition: function ( v ) {
  3066. var te = this.elements;
  3067. te[ 12 ] = v.x;
  3068. te[ 13 ] = v.y;
  3069. te[ 14 ] = v.z;
  3070. return this;
  3071. },
  3072. getInverse: function ( m, throwOnInvertible ) {
  3073. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3074. var te = this.elements;
  3075. var me = m.elements;
  3076. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3077. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3078. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3079. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3080. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3081. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3082. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3083. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3084. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3085. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3086. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3087. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3088. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3089. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3090. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3091. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3092. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3093. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3094. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3095. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3096. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3097. if ( det === 0 ) {
  3098. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3099. if ( throwOnInvertible || false ) {
  3100. throw new Error( msg );
  3101. } else {
  3102. console.warn( msg );
  3103. }
  3104. this.identity();
  3105. return this;
  3106. }
  3107. this.multiplyScalar( 1 / det );
  3108. return this;
  3109. },
  3110. translate: function ( v ) {
  3111. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  3112. },
  3113. rotateX: function ( angle ) {
  3114. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  3115. },
  3116. rotateY: function ( angle ) {
  3117. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  3118. },
  3119. rotateZ: function ( angle ) {
  3120. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  3121. },
  3122. rotateByAxis: function ( axis, angle ) {
  3123. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  3124. },
  3125. scale: function ( v ) {
  3126. var te = this.elements;
  3127. var x = v.x, y = v.y, z = v.z;
  3128. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3129. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3130. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3131. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3132. return this;
  3133. },
  3134. getMaxScaleOnAxis: function () {
  3135. var te = this.elements;
  3136. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3137. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3138. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3139. return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
  3140. },
  3141. makeTranslation: function ( x, y, z ) {
  3142. this.set(
  3143. 1, 0, 0, x,
  3144. 0, 1, 0, y,
  3145. 0, 0, 1, z,
  3146. 0, 0, 0, 1
  3147. );
  3148. return this;
  3149. },
  3150. makeRotationX: function ( theta ) {
  3151. var c = Math.cos( theta ), s = Math.sin( theta );
  3152. this.set(
  3153. 1, 0, 0, 0,
  3154. 0, c, - s, 0,
  3155. 0, s, c, 0,
  3156. 0, 0, 0, 1
  3157. );
  3158. return this;
  3159. },
  3160. makeRotationY: function ( theta ) {
  3161. var c = Math.cos( theta ), s = Math.sin( theta );
  3162. this.set(
  3163. c, 0, s, 0,
  3164. 0, 1, 0, 0,
  3165. - s, 0, c, 0,
  3166. 0, 0, 0, 1
  3167. );
  3168. return this;
  3169. },
  3170. makeRotationZ: function ( theta ) {
  3171. var c = Math.cos( theta ), s = Math.sin( theta );
  3172. this.set(
  3173. c, - s, 0, 0,
  3174. s, c, 0, 0,
  3175. 0, 0, 1, 0,
  3176. 0, 0, 0, 1
  3177. );
  3178. return this;
  3179. },
  3180. makeRotationAxis: function ( axis, angle ) {
  3181. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3182. var c = Math.cos( angle );
  3183. var s = Math.sin( angle );
  3184. var t = 1 - c;
  3185. var x = axis.x, y = axis.y, z = axis.z;
  3186. var tx = t * x, ty = t * y;
  3187. this.set(
  3188. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3189. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3190. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3191. 0, 0, 0, 1
  3192. );
  3193. return this;
  3194. },
  3195. makeScale: function ( x, y, z ) {
  3196. this.set(
  3197. x, 0, 0, 0,
  3198. 0, y, 0, 0,
  3199. 0, 0, z, 0,
  3200. 0, 0, 0, 1
  3201. );
  3202. return this;
  3203. },
  3204. compose: function ( position, quaternion, scale ) {
  3205. this.makeRotationFromQuaternion( quaternion );
  3206. this.scale( scale );
  3207. this.setPosition( position );
  3208. return this;
  3209. },
  3210. decompose: function () {
  3211. var vector, matrix;
  3212. return function ( position, quaternion, scale ) {
  3213. if ( vector === undefined ) vector = new THREE.Vector3();
  3214. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3215. var te = this.elements;
  3216. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3217. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3218. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3219. // if determine is negative, we need to invert one scale
  3220. var det = this.determinant();
  3221. if ( det < 0 ) {
  3222. sx = - sx;
  3223. }
  3224. position.x = te[ 12 ];
  3225. position.y = te[ 13 ];
  3226. position.z = te[ 14 ];
  3227. // scale the rotation part
  3228. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3229. var invSX = 1 / sx;
  3230. var invSY = 1 / sy;
  3231. var invSZ = 1 / sz;
  3232. matrix.elements[ 0 ] *= invSX;
  3233. matrix.elements[ 1 ] *= invSX;
  3234. matrix.elements[ 2 ] *= invSX;
  3235. matrix.elements[ 4 ] *= invSY;
  3236. matrix.elements[ 5 ] *= invSY;
  3237. matrix.elements[ 6 ] *= invSY;
  3238. matrix.elements[ 8 ] *= invSZ;
  3239. matrix.elements[ 9 ] *= invSZ;
  3240. matrix.elements[ 10 ] *= invSZ;
  3241. quaternion.setFromRotationMatrix( matrix );
  3242. scale.x = sx;
  3243. scale.y = sy;
  3244. scale.z = sz;
  3245. return this;
  3246. };
  3247. }(),
  3248. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3249. var te = this.elements;
  3250. var x = 2 * near / ( right - left );
  3251. var y = 2 * near / ( top - bottom );
  3252. var a = ( right + left ) / ( right - left );
  3253. var b = ( top + bottom ) / ( top - bottom );
  3254. var c = - ( far + near ) / ( far - near );
  3255. var d = - 2 * far * near / ( far - near );
  3256. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3257. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3258. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3259. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3260. return this;
  3261. },
  3262. makePerspective: function ( fov, aspect, near, far ) {
  3263. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3264. var ymin = - ymax;
  3265. var xmin = ymin * aspect;
  3266. var xmax = ymax * aspect;
  3267. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3268. },
  3269. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3270. var te = this.elements;
  3271. var w = right - left;
  3272. var h = top - bottom;
  3273. var p = far - near;
  3274. var x = ( right + left ) / w;
  3275. var y = ( top + bottom ) / h;
  3276. var z = ( far + near ) / p;
  3277. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3278. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3279. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3280. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3281. return this;
  3282. },
  3283. fromArray: function ( array ) {
  3284. this.elements.set( array );
  3285. return this;
  3286. },
  3287. toArray: function () {
  3288. var te = this.elements;
  3289. return [
  3290. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3291. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3292. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3293. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3294. ];
  3295. },
  3296. clone: function () {
  3297. return new THREE.Matrix4().fromArray( this.elements );
  3298. }
  3299. };
  3300. // File:src/math/Ray.js
  3301. /**
  3302. * @author bhouston / http://exocortex.com
  3303. */
  3304. THREE.Ray = function ( origin, direction ) {
  3305. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3306. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3307. };
  3308. THREE.Ray.prototype = {
  3309. constructor: THREE.Ray,
  3310. set: function ( origin, direction ) {
  3311. this.origin.copy( origin );
  3312. this.direction.copy( direction );
  3313. return this;
  3314. },
  3315. copy: function ( ray ) {
  3316. this.origin.copy( ray.origin );
  3317. this.direction.copy( ray.direction );
  3318. return this;
  3319. },
  3320. at: function ( t, optionalTarget ) {
  3321. var result = optionalTarget || new THREE.Vector3();
  3322. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3323. },
  3324. recast: function () {
  3325. var v1 = new THREE.Vector3();
  3326. return function ( t ) {
  3327. this.origin.copy( this.at( t, v1 ) );
  3328. return this;
  3329. };
  3330. }(),
  3331. closestPointToPoint: function ( point, optionalTarget ) {
  3332. var result = optionalTarget || new THREE.Vector3();
  3333. result.subVectors( point, this.origin );
  3334. var directionDistance = result.dot( this.direction );
  3335. if ( directionDistance < 0 ) {
  3336. return result.copy( this.origin );
  3337. }
  3338. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3339. },
  3340. distanceToPoint: function ( point ) {
  3341. return Math.sqrt( this.distanceSqToPoint( point ) );
  3342. },
  3343. distanceSqToPoint: function () {
  3344. var v1 = new THREE.Vector3();
  3345. return function ( point ) {
  3346. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3347. // point behind the ray
  3348. if ( directionDistance < 0 ) {
  3349. return this.origin.distanceToSquared( point );
  3350. }
  3351. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3352. return v1.distanceToSquared( point );
  3353. };
  3354. }(),
  3355. distanceSqToSegment: function () {
  3356. var segCenter = new THREE.Vector3();
  3357. var segDir = new THREE.Vector3();
  3358. var diff = new THREE.Vector3();
  3359. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3360. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3361. // It returns the min distance between the ray and the segment
  3362. // defined by v0 and v1
  3363. // It can also set two optional targets :
  3364. // - The closest point on the ray
  3365. // - The closest point on the segment
  3366. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3367. segDir.copy( v1 ).sub( v0 ).normalize();
  3368. diff.copy( this.origin ).sub( segCenter );
  3369. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3370. var a01 = - this.direction.dot( segDir );
  3371. var b0 = diff.dot( this.direction );
  3372. var b1 = - diff.dot( segDir );
  3373. var c = diff.lengthSq();
  3374. var det = Math.abs( 1 - a01 * a01 );
  3375. var s0, s1, sqrDist, extDet;
  3376. if ( det > 0 ) {
  3377. // The ray and segment are not parallel.
  3378. s0 = a01 * b1 - b0;
  3379. s1 = a01 * b0 - b1;
  3380. extDet = segExtent * det;
  3381. if ( s0 >= 0 ) {
  3382. if ( s1 >= - extDet ) {
  3383. if ( s1 <= extDet ) {
  3384. // region 0
  3385. // Minimum at interior points of ray and segment.
  3386. var invDet = 1 / det;
  3387. s0 *= invDet;
  3388. s1 *= invDet;
  3389. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3390. } else {
  3391. // region 1
  3392. s1 = segExtent;
  3393. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3394. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3395. }
  3396. } else {
  3397. // region 5
  3398. s1 = - segExtent;
  3399. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3400. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3401. }
  3402. } else {
  3403. if ( s1 <= - extDet ) {
  3404. // region 4
  3405. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3406. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3407. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3408. } else if ( s1 <= extDet ) {
  3409. // region 3
  3410. s0 = 0;
  3411. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3412. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3413. } else {
  3414. // region 2
  3415. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3416. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3417. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3418. }
  3419. }
  3420. } else {
  3421. // Ray and segment are parallel.
  3422. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3423. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3424. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3425. }
  3426. if ( optionalPointOnRay ) {
  3427. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3428. }
  3429. if ( optionalPointOnSegment ) {
  3430. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3431. }
  3432. return sqrDist;
  3433. };
  3434. }(),
  3435. isIntersectionSphere: function ( sphere ) {
  3436. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3437. },
  3438. intersectSphere: function () {
  3439. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3440. var v1 = new THREE.Vector3();
  3441. return function ( sphere, optionalTarget ) {
  3442. v1.subVectors( sphere.center, this.origin );
  3443. var tca = v1.dot( this.direction );
  3444. var d2 = v1.dot( v1 ) - tca * tca;
  3445. var radius2 = sphere.radius * sphere.radius;
  3446. if ( d2 > radius2 ) return null;
  3447. var thc = Math.sqrt( radius2 - d2 );
  3448. // t0 = first intersect point - entrance on front of sphere
  3449. var t0 = tca - thc;
  3450. // t1 = second intersect point - exit point on back of sphere
  3451. var t1 = tca + thc;
  3452. // test to see if both t0 and t1 are behind the ray - if so, return null
  3453. if ( t0 < 0 && t1 < 0 ) return null;
  3454. // test to see if t0 is behind the ray:
  3455. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3456. // in order to always return an intersect point that is in front of the ray.
  3457. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3458. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3459. return this.at( t0, optionalTarget );
  3460. }
  3461. }(),
  3462. isIntersectionPlane: function ( plane ) {
  3463. // check if the ray lies on the plane first
  3464. var distToPoint = plane.distanceToPoint( this.origin );
  3465. if ( distToPoint === 0 ) {
  3466. return true;
  3467. }
  3468. var denominator = plane.normal.dot( this.direction );
  3469. if ( denominator * distToPoint < 0 ) {
  3470. return true;
  3471. }
  3472. // ray origin is behind the plane (and is pointing behind it)
  3473. return false;
  3474. },
  3475. distanceToPlane: function ( plane ) {
  3476. var denominator = plane.normal.dot( this.direction );
  3477. if ( denominator === 0 ) {
  3478. // line is coplanar, return origin
  3479. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3480. return 0;
  3481. }
  3482. // Null is preferable to undefined since undefined means.... it is undefined
  3483. return null;
  3484. }
  3485. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3486. // Return if the ray never intersects the plane
  3487. return t >= 0 ? t : null;
  3488. },
  3489. intersectPlane: function ( plane, optionalTarget ) {
  3490. var t = this.distanceToPlane( plane );
  3491. if ( t === null ) {
  3492. return null;
  3493. }
  3494. return this.at( t, optionalTarget );
  3495. },
  3496. isIntersectionBox: function () {
  3497. var v = new THREE.Vector3();
  3498. return function ( box ) {
  3499. return this.intersectBox( box, v ) !== null;
  3500. };
  3501. }(),
  3502. intersectBox: function ( box, optionalTarget ) {
  3503. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3504. var tmin,tmax,tymin,tymax,tzmin,tzmax;
  3505. var invdirx = 1 / this.direction.x,
  3506. invdiry = 1 / this.direction.y,
  3507. invdirz = 1 / this.direction.z;
  3508. var origin = this.origin;
  3509. if ( invdirx >= 0 ) {
  3510. tmin = ( box.min.x - origin.x ) * invdirx;
  3511. tmax = ( box.max.x - origin.x ) * invdirx;
  3512. } else {
  3513. tmin = ( box.max.x - origin.x ) * invdirx;
  3514. tmax = ( box.min.x - origin.x ) * invdirx;
  3515. }
  3516. if ( invdiry >= 0 ) {
  3517. tymin = ( box.min.y - origin.y ) * invdiry;
  3518. tymax = ( box.max.y - origin.y ) * invdiry;
  3519. } else {
  3520. tymin = ( box.max.y - origin.y ) * invdiry;
  3521. tymax = ( box.min.y - origin.y ) * invdiry;
  3522. }
  3523. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3524. // These lines also handle the case where tmin or tmax is NaN
  3525. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3526. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3527. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3528. if ( invdirz >= 0 ) {
  3529. tzmin = ( box.min.z - origin.z ) * invdirz;
  3530. tzmax = ( box.max.z - origin.z ) * invdirz;
  3531. } else {
  3532. tzmin = ( box.max.z - origin.z ) * invdirz;
  3533. tzmax = ( box.min.z - origin.z ) * invdirz;
  3534. }
  3535. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3536. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3537. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3538. //return point closest to the ray (positive side)
  3539. if ( tmax < 0 ) return null;
  3540. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3541. },
  3542. intersectTriangle: function () {
  3543. // Compute the offset origin, edges, and normal.
  3544. var diff = new THREE.Vector3();
  3545. var edge1 = new THREE.Vector3();
  3546. var edge2 = new THREE.Vector3();
  3547. var normal = new THREE.Vector3();
  3548. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3549. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3550. edge1.subVectors( b, a );
  3551. edge2.subVectors( c, a );
  3552. normal.crossVectors( edge1, edge2 );
  3553. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3554. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3555. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3556. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3557. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3558. var DdN = this.direction.dot( normal );
  3559. var sign;
  3560. if ( DdN > 0 ) {
  3561. if ( backfaceCulling ) return null;
  3562. sign = 1;
  3563. } else if ( DdN < 0 ) {
  3564. sign = - 1;
  3565. DdN = - DdN;
  3566. } else {
  3567. return null;
  3568. }
  3569. diff.subVectors( this.origin, a );
  3570. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3571. // b1 < 0, no intersection
  3572. if ( DdQxE2 < 0 ) {
  3573. return null;
  3574. }
  3575. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3576. // b2 < 0, no intersection
  3577. if ( DdE1xQ < 0 ) {
  3578. return null;
  3579. }
  3580. // b1+b2 > 1, no intersection
  3581. if ( DdQxE2 + DdE1xQ > DdN ) {
  3582. return null;
  3583. }
  3584. // Line intersects triangle, check if ray does.
  3585. var QdN = - sign * diff.dot( normal );
  3586. // t < 0, no intersection
  3587. if ( QdN < 0 ) {
  3588. return null;
  3589. }
  3590. // Ray intersects triangle.
  3591. return this.at( QdN / DdN, optionalTarget );
  3592. };
  3593. }(),
  3594. applyMatrix4: function ( matrix4 ) {
  3595. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3596. this.origin.applyMatrix4( matrix4 );
  3597. this.direction.sub( this.origin );
  3598. this.direction.normalize();
  3599. return this;
  3600. },
  3601. equals: function ( ray ) {
  3602. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3603. },
  3604. clone: function () {
  3605. return new THREE.Ray().copy( this );
  3606. }
  3607. };
  3608. // File:src/math/Sphere.js
  3609. /**
  3610. * @author bhouston / http://exocortex.com
  3611. * @author mrdoob / http://mrdoob.com/
  3612. */
  3613. THREE.Sphere = function ( center, radius ) {
  3614. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3615. this.radius = ( radius !== undefined ) ? radius : 0;
  3616. };
  3617. THREE.Sphere.prototype = {
  3618. constructor: THREE.Sphere,
  3619. set: function ( center, radius ) {
  3620. this.center.copy( center );
  3621. this.radius = radius;
  3622. return this;
  3623. },
  3624. setFromPoints: function () {
  3625. var box = new THREE.Box3();
  3626. return function ( points, optionalCenter ) {
  3627. var center = this.center;
  3628. if ( optionalCenter !== undefined ) {
  3629. center.copy( optionalCenter );
  3630. } else {
  3631. box.setFromPoints( points ).center( center );
  3632. }
  3633. var maxRadiusSq = 0;
  3634. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3635. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3636. }
  3637. this.radius = Math.sqrt( maxRadiusSq );
  3638. return this;
  3639. };
  3640. }(),
  3641. copy: function ( sphere ) {
  3642. this.center.copy( sphere.center );
  3643. this.radius = sphere.radius;
  3644. return this;
  3645. },
  3646. empty: function () {
  3647. return ( this.radius <= 0 );
  3648. },
  3649. containsPoint: function ( point ) {
  3650. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3651. },
  3652. distanceToPoint: function ( point ) {
  3653. return ( point.distanceTo( this.center ) - this.radius );
  3654. },
  3655. intersectsSphere: function ( sphere ) {
  3656. var radiusSum = this.radius + sphere.radius;
  3657. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3658. },
  3659. clampPoint: function ( point, optionalTarget ) {
  3660. var deltaLengthSq = this.center.distanceToSquared( point );
  3661. var result = optionalTarget || new THREE.Vector3();
  3662. result.copy( point );
  3663. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3664. result.sub( this.center ).normalize();
  3665. result.multiplyScalar( this.radius ).add( this.center );
  3666. }
  3667. return result;
  3668. },
  3669. getBoundingBox: function ( optionalTarget ) {
  3670. var box = optionalTarget || new THREE.Box3();
  3671. box.set( this.center, this.center );
  3672. box.expandByScalar( this.radius );
  3673. return box;
  3674. },
  3675. applyMatrix4: function ( matrix ) {
  3676. this.center.applyMatrix4( matrix );
  3677. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3678. return this;
  3679. },
  3680. translate: function ( offset ) {
  3681. this.center.add( offset );
  3682. return this;
  3683. },
  3684. equals: function ( sphere ) {
  3685. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3686. },
  3687. clone: function () {
  3688. return new THREE.Sphere().copy( this );
  3689. }
  3690. };
  3691. // File:src/math/Frustum.js
  3692. /**
  3693. * @author mrdoob / http://mrdoob.com/
  3694. * @author alteredq / http://alteredqualia.com/
  3695. * @author bhouston / http://exocortex.com
  3696. */
  3697. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3698. this.planes = [
  3699. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3700. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3701. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3702. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3703. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3704. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3705. ];
  3706. };
  3707. THREE.Frustum.prototype = {
  3708. constructor: THREE.Frustum,
  3709. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3710. var planes = this.planes;
  3711. planes[ 0 ].copy( p0 );
  3712. planes[ 1 ].copy( p1 );
  3713. planes[ 2 ].copy( p2 );
  3714. planes[ 3 ].copy( p3 );
  3715. planes[ 4 ].copy( p4 );
  3716. planes[ 5 ].copy( p5 );
  3717. return this;
  3718. },
  3719. copy: function ( frustum ) {
  3720. var planes = this.planes;
  3721. for ( var i = 0; i < 6; i ++ ) {
  3722. planes[ i ].copy( frustum.planes[ i ] );
  3723. }
  3724. return this;
  3725. },
  3726. setFromMatrix: function ( m ) {
  3727. var planes = this.planes;
  3728. var me = m.elements;
  3729. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3730. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3731. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3732. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3733. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3734. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3735. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3736. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3737. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3738. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3739. return this;
  3740. },
  3741. intersectsObject: function () {
  3742. var sphere = new THREE.Sphere();
  3743. return function ( object ) {
  3744. var geometry = object.geometry;
  3745. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3746. sphere.copy( geometry.boundingSphere );
  3747. sphere.applyMatrix4( object.matrixWorld );
  3748. return this.intersectsSphere( sphere );
  3749. };
  3750. }(),
  3751. intersectsSphere: function ( sphere ) {
  3752. var planes = this.planes;
  3753. var center = sphere.center;
  3754. var negRadius = - sphere.radius;
  3755. for ( var i = 0; i < 6; i ++ ) {
  3756. var distance = planes[ i ].distanceToPoint( center );
  3757. if ( distance < negRadius ) {
  3758. return false;
  3759. }
  3760. }
  3761. return true;
  3762. },
  3763. intersectsBox: function () {
  3764. var p1 = new THREE.Vector3(),
  3765. p2 = new THREE.Vector3();
  3766. return function ( box ) {
  3767. var planes = this.planes;
  3768. for ( var i = 0; i < 6 ; i ++ ) {
  3769. var plane = planes[ i ];
  3770. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3771. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3772. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3773. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3774. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3775. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3776. var d1 = plane.distanceToPoint( p1 );
  3777. var d2 = plane.distanceToPoint( p2 );
  3778. // if both outside plane, no intersection
  3779. if ( d1 < 0 && d2 < 0 ) {
  3780. return false;
  3781. }
  3782. }
  3783. return true;
  3784. };
  3785. }(),
  3786. containsPoint: function ( point ) {
  3787. var planes = this.planes;
  3788. for ( var i = 0; i < 6; i ++ ) {
  3789. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3790. return false;
  3791. }
  3792. }
  3793. return true;
  3794. },
  3795. clone: function () {
  3796. return new THREE.Frustum().copy( this );
  3797. }
  3798. };
  3799. // File:src/math/Plane.js
  3800. /**
  3801. * @author bhouston / http://exocortex.com
  3802. */
  3803. THREE.Plane = function ( normal, constant ) {
  3804. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3805. this.constant = ( constant !== undefined ) ? constant : 0;
  3806. };
  3807. THREE.Plane.prototype = {
  3808. constructor: THREE.Plane,
  3809. set: function ( normal, constant ) {
  3810. this.normal.copy( normal );
  3811. this.constant = constant;
  3812. return this;
  3813. },
  3814. setComponents: function ( x, y, z, w ) {
  3815. this.normal.set( x, y, z );
  3816. this.constant = w;
  3817. return this;
  3818. },
  3819. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3820. this.normal.copy( normal );
  3821. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3822. return this;
  3823. },
  3824. setFromCoplanarPoints: function () {
  3825. var v1 = new THREE.Vector3();
  3826. var v2 = new THREE.Vector3();
  3827. return function ( a, b, c ) {
  3828. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3829. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3830. this.setFromNormalAndCoplanarPoint( normal, a );
  3831. return this;
  3832. };
  3833. }(),
  3834. copy: function ( plane ) {
  3835. this.normal.copy( plane.normal );
  3836. this.constant = plane.constant;
  3837. return this;
  3838. },
  3839. normalize: function () {
  3840. // Note: will lead to a divide by zero if the plane is invalid.
  3841. var inverseNormalLength = 1.0 / this.normal.length();
  3842. this.normal.multiplyScalar( inverseNormalLength );
  3843. this.constant *= inverseNormalLength;
  3844. return this;
  3845. },
  3846. negate: function () {
  3847. this.constant *= - 1;
  3848. this.normal.negate();
  3849. return this;
  3850. },
  3851. distanceToPoint: function ( point ) {
  3852. return this.normal.dot( point ) + this.constant;
  3853. },
  3854. distanceToSphere: function ( sphere ) {
  3855. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3856. },
  3857. projectPoint: function ( point, optionalTarget ) {
  3858. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3859. },
  3860. orthoPoint: function ( point, optionalTarget ) {
  3861. var perpendicularMagnitude = this.distanceToPoint( point );
  3862. var result = optionalTarget || new THREE.Vector3();
  3863. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3864. },
  3865. isIntersectionLine: function ( line ) {
  3866. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3867. var startSign = this.distanceToPoint( line.start );
  3868. var endSign = this.distanceToPoint( line.end );
  3869. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3870. },
  3871. intersectLine: function () {
  3872. var v1 = new THREE.Vector3();
  3873. return function ( line, optionalTarget ) {
  3874. var result = optionalTarget || new THREE.Vector3();
  3875. var direction = line.delta( v1 );
  3876. var denominator = this.normal.dot( direction );
  3877. if ( denominator === 0 ) {
  3878. // line is coplanar, return origin
  3879. if ( this.distanceToPoint( line.start ) === 0 ) {
  3880. return result.copy( line.start );
  3881. }
  3882. // Unsure if this is the correct method to handle this case.
  3883. return undefined;
  3884. }
  3885. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3886. if ( t < 0 || t > 1 ) {
  3887. return undefined;
  3888. }
  3889. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  3890. };
  3891. }(),
  3892. coplanarPoint: function ( optionalTarget ) {
  3893. var result = optionalTarget || new THREE.Vector3();
  3894. return result.copy( this.normal ).multiplyScalar( - this.constant );
  3895. },
  3896. applyMatrix4: function () {
  3897. var v1 = new THREE.Vector3();
  3898. var v2 = new THREE.Vector3();
  3899. var m1 = new THREE.Matrix3();
  3900. return function ( matrix, optionalNormalMatrix ) {
  3901. // compute new normal based on theory here:
  3902. // http://www.songho.ca/opengl/gl_normaltransform.html
  3903. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  3904. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  3905. var newCoplanarPoint = this.coplanarPoint( v2 );
  3906. newCoplanarPoint.applyMatrix4( matrix );
  3907. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  3908. return this;
  3909. };
  3910. }(),
  3911. translate: function ( offset ) {
  3912. this.constant = this.constant - offset.dot( this.normal );
  3913. return this;
  3914. },
  3915. equals: function ( plane ) {
  3916. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  3917. },
  3918. clone: function () {
  3919. return new THREE.Plane().copy( this );
  3920. }
  3921. };
  3922. // File:src/math/Math.js
  3923. /**
  3924. * @author alteredq / http://alteredqualia.com/
  3925. * @author mrdoob / http://mrdoob.com/
  3926. */
  3927. THREE.Math = {
  3928. generateUUID: function () {
  3929. // http://www.broofa.com/Tools/Math.uuid.htm
  3930. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  3931. var uuid = new Array( 36 );
  3932. var rnd = 0, r;
  3933. return function () {
  3934. for ( var i = 0; i < 36; i ++ ) {
  3935. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  3936. uuid[ i ] = '-';
  3937. } else if ( i === 14 ) {
  3938. uuid[ i ] = '4';
  3939. } else {
  3940. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  3941. r = rnd & 0xf;
  3942. rnd = rnd >> 4;
  3943. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  3944. }
  3945. }
  3946. return uuid.join( '' );
  3947. };
  3948. }(),
  3949. // Clamp value to range <a, b>
  3950. clamp: function ( x, a, b ) {
  3951. return ( x < a ) ? a : ( ( x > b ) ? b : x );
  3952. },
  3953. // Clamp value to range <a, inf)
  3954. clampBottom: function ( x, a ) {
  3955. return x < a ? a : x;
  3956. },
  3957. // compute euclidian modulo of m % n
  3958. // https://en.wikipedia.org/wiki/Modulo_operation
  3959. euclideanModulo: function ( n, m ) {
  3960. return ( ( n % m ) + m ) % m;
  3961. },
  3962. // Linear mapping from range <a1, a2> to range <b1, b2>
  3963. mapLinear: function ( x, a1, a2, b1, b2 ) {
  3964. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  3965. },
  3966. // http://en.wikipedia.org/wiki/Smoothstep
  3967. smoothstep: function ( x, min, max ) {
  3968. if ( x <= min ) return 0;
  3969. if ( x >= max ) return 1;
  3970. x = ( x - min ) / ( max - min );
  3971. return x * x * ( 3 - 2 * x );
  3972. },
  3973. smootherstep: function ( x, min, max ) {
  3974. if ( x <= min ) return 0;
  3975. if ( x >= max ) return 1;
  3976. x = ( x - min ) / ( max - min );
  3977. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  3978. },
  3979. // Random float from <0, 1> with 16 bits of randomness
  3980. // (standard Math.random() creates repetitive patterns when applied over larger space)
  3981. random16: function () {
  3982. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  3983. },
  3984. // Random integer from <low, high> interval
  3985. randInt: function ( low, high ) {
  3986. return Math.floor( this.randFloat( low, high ) );
  3987. },
  3988. // Random float from <low, high> interval
  3989. randFloat: function ( low, high ) {
  3990. return low + Math.random() * ( high - low );
  3991. },
  3992. // Random float from <-range/2, range/2> interval
  3993. randFloatSpread: function ( range ) {
  3994. return range * ( 0.5 - Math.random() );
  3995. },
  3996. degToRad: function () {
  3997. var degreeToRadiansFactor = Math.PI / 180;
  3998. return function ( degrees ) {
  3999. return degrees * degreeToRadiansFactor;
  4000. };
  4001. }(),
  4002. radToDeg: function () {
  4003. var radianToDegreesFactor = 180 / Math.PI;
  4004. return function ( radians ) {
  4005. return radians * radianToDegreesFactor;
  4006. };
  4007. }(),
  4008. isPowerOfTwo: function ( value ) {
  4009. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4010. },
  4011. nextPowerOfTwo: function ( value ) {
  4012. value --;
  4013. value |= value >> 1;
  4014. value |= value >> 2;
  4015. value |= value >> 4;
  4016. value |= value >> 8;
  4017. value |= value >> 16;
  4018. value ++;
  4019. return value;
  4020. }
  4021. };
  4022. // File:src/math/Spline.js
  4023. /**
  4024. * Spline from Tween.js, slightly optimized (and trashed)
  4025. * http://sole.github.com/tween.js/examples/05_spline.html
  4026. *
  4027. * @author mrdoob / http://mrdoob.com/
  4028. * @author alteredq / http://alteredqualia.com/
  4029. */
  4030. THREE.Spline = function ( points ) {
  4031. this.points = points;
  4032. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4033. point, intPoint, weight, w2, w3,
  4034. pa, pb, pc, pd;
  4035. this.initFromArray = function ( a ) {
  4036. this.points = [];
  4037. for ( var i = 0; i < a.length; i ++ ) {
  4038. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4039. }
  4040. };
  4041. this.getPoint = function ( k ) {
  4042. point = ( this.points.length - 1 ) * k;
  4043. intPoint = Math.floor( point );
  4044. weight = point - intPoint;
  4045. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4046. c[ 1 ] = intPoint;
  4047. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4048. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4049. pa = this.points[ c[ 0 ] ];
  4050. pb = this.points[ c[ 1 ] ];
  4051. pc = this.points[ c[ 2 ] ];
  4052. pd = this.points[ c[ 3 ] ];
  4053. w2 = weight * weight;
  4054. w3 = weight * w2;
  4055. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4056. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4057. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4058. return v3;
  4059. };
  4060. this.getControlPointsArray = function () {
  4061. var i, p, l = this.points.length,
  4062. coords = [];
  4063. for ( i = 0; i < l; i ++ ) {
  4064. p = this.points[ i ];
  4065. coords[ i ] = [ p.x, p.y, p.z ];
  4066. }
  4067. return coords;
  4068. };
  4069. // approximate length by summing linear segments
  4070. this.getLength = function ( nSubDivisions ) {
  4071. var i, index, nSamples, position,
  4072. point = 0, intPoint = 0, oldIntPoint = 0,
  4073. oldPosition = new THREE.Vector3(),
  4074. tmpVec = new THREE.Vector3(),
  4075. chunkLengths = [],
  4076. totalLength = 0;
  4077. // first point has 0 length
  4078. chunkLengths[ 0 ] = 0;
  4079. if ( ! nSubDivisions ) nSubDivisions = 100;
  4080. nSamples = this.points.length * nSubDivisions;
  4081. oldPosition.copy( this.points[ 0 ] );
  4082. for ( i = 1; i < nSamples; i ++ ) {
  4083. index = i / nSamples;
  4084. position = this.getPoint( index );
  4085. tmpVec.copy( position );
  4086. totalLength += tmpVec.distanceTo( oldPosition );
  4087. oldPosition.copy( position );
  4088. point = ( this.points.length - 1 ) * index;
  4089. intPoint = Math.floor( point );
  4090. if ( intPoint !== oldIntPoint ) {
  4091. chunkLengths[ intPoint ] = totalLength;
  4092. oldIntPoint = intPoint;
  4093. }
  4094. }
  4095. // last point ends with total length
  4096. chunkLengths[ chunkLengths.length ] = totalLength;
  4097. return { chunks: chunkLengths, total: totalLength };
  4098. };
  4099. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4100. var i, j,
  4101. index, indexCurrent, indexNext,
  4102. realDistance,
  4103. sampling, position,
  4104. newpoints = [],
  4105. tmpVec = new THREE.Vector3(),
  4106. sl = this.getLength();
  4107. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4108. for ( i = 1; i < this.points.length; i ++ ) {
  4109. //tmpVec.copy( this.points[ i - 1 ] );
  4110. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4111. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4112. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4113. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4114. indexNext = i / ( this.points.length - 1 );
  4115. for ( j = 1; j < sampling - 1; j ++ ) {
  4116. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4117. position = this.getPoint( index );
  4118. newpoints.push( tmpVec.copy( position ).clone() );
  4119. }
  4120. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4121. }
  4122. this.points = newpoints;
  4123. };
  4124. // Catmull-Rom
  4125. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4126. var v0 = ( p2 - p0 ) * 0.5,
  4127. v1 = ( p3 - p1 ) * 0.5;
  4128. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4129. }
  4130. };
  4131. // File:src/math/Triangle.js
  4132. /**
  4133. * @author bhouston / http://exocortex.com
  4134. * @author mrdoob / http://mrdoob.com/
  4135. */
  4136. THREE.Triangle = function ( a, b, c ) {
  4137. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4138. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4139. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4140. };
  4141. THREE.Triangle.normal = function () {
  4142. var v0 = new THREE.Vector3();
  4143. return function ( a, b, c, optionalTarget ) {
  4144. var result = optionalTarget || new THREE.Vector3();
  4145. result.subVectors( c, b );
  4146. v0.subVectors( a, b );
  4147. result.cross( v0 );
  4148. var resultLengthSq = result.lengthSq();
  4149. if ( resultLengthSq > 0 ) {
  4150. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4151. }
  4152. return result.set( 0, 0, 0 );
  4153. };
  4154. }();
  4155. // static/instance method to calculate barycentric coordinates
  4156. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4157. THREE.Triangle.barycoordFromPoint = function () {
  4158. var v0 = new THREE.Vector3();
  4159. var v1 = new THREE.Vector3();
  4160. var v2 = new THREE.Vector3();
  4161. return function ( point, a, b, c, optionalTarget ) {
  4162. v0.subVectors( c, a );
  4163. v1.subVectors( b, a );
  4164. v2.subVectors( point, a );
  4165. var dot00 = v0.dot( v0 );
  4166. var dot01 = v0.dot( v1 );
  4167. var dot02 = v0.dot( v2 );
  4168. var dot11 = v1.dot( v1 );
  4169. var dot12 = v1.dot( v2 );
  4170. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4171. var result = optionalTarget || new THREE.Vector3();
  4172. // collinear or singular triangle
  4173. if ( denom === 0 ) {
  4174. // arbitrary location outside of triangle?
  4175. // not sure if this is the best idea, maybe should be returning undefined
  4176. return result.set( - 2, - 1, - 1 );
  4177. }
  4178. var invDenom = 1 / denom;
  4179. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4180. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4181. // barycentric coordinates must always sum to 1
  4182. return result.set( 1 - u - v, v, u );
  4183. };
  4184. }();
  4185. THREE.Triangle.containsPoint = function () {
  4186. var v1 = new THREE.Vector3();
  4187. return function ( point, a, b, c ) {
  4188. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4189. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4190. };
  4191. }();
  4192. THREE.Triangle.prototype = {
  4193. constructor: THREE.Triangle,
  4194. set: function ( a, b, c ) {
  4195. this.a.copy( a );
  4196. this.b.copy( b );
  4197. this.c.copy( c );
  4198. return this;
  4199. },
  4200. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4201. this.a.copy( points[ i0 ] );
  4202. this.b.copy( points[ i1 ] );
  4203. this.c.copy( points[ i2 ] );
  4204. return this;
  4205. },
  4206. copy: function ( triangle ) {
  4207. this.a.copy( triangle.a );
  4208. this.b.copy( triangle.b );
  4209. this.c.copy( triangle.c );
  4210. return this;
  4211. },
  4212. area: function () {
  4213. var v0 = new THREE.Vector3();
  4214. var v1 = new THREE.Vector3();
  4215. return function () {
  4216. v0.subVectors( this.c, this.b );
  4217. v1.subVectors( this.a, this.b );
  4218. return v0.cross( v1 ).length() * 0.5;
  4219. };
  4220. }(),
  4221. midpoint: function ( optionalTarget ) {
  4222. var result = optionalTarget || new THREE.Vector3();
  4223. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4224. },
  4225. normal: function ( optionalTarget ) {
  4226. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4227. },
  4228. plane: function ( optionalTarget ) {
  4229. var result = optionalTarget || new THREE.Plane();
  4230. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4231. },
  4232. barycoordFromPoint: function ( point, optionalTarget ) {
  4233. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4234. },
  4235. containsPoint: function ( point ) {
  4236. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4237. },
  4238. equals: function ( triangle ) {
  4239. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4240. },
  4241. clone: function () {
  4242. return new THREE.Triangle().copy( this );
  4243. }
  4244. };
  4245. // File:src/core/Clock.js
  4246. /**
  4247. * @author alteredq / http://alteredqualia.com/
  4248. */
  4249. THREE.Clock = function ( autoStart ) {
  4250. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4251. this.startTime = 0;
  4252. this.oldTime = 0;
  4253. this.elapsedTime = 0;
  4254. this.running = false;
  4255. };
  4256. THREE.Clock.prototype = {
  4257. constructor: THREE.Clock,
  4258. start: function () {
  4259. this.startTime = self.performance !== undefined && self.performance.now !== undefined
  4260. ? self.performance.now()
  4261. : Date.now();
  4262. this.oldTime = this.startTime;
  4263. this.running = true;
  4264. },
  4265. stop: function () {
  4266. this.getElapsedTime();
  4267. this.running = false;
  4268. },
  4269. getElapsedTime: function () {
  4270. this.getDelta();
  4271. return this.elapsedTime;
  4272. },
  4273. getDelta: function () {
  4274. var diff = 0;
  4275. if ( this.autoStart && ! this.running ) {
  4276. this.start();
  4277. }
  4278. if ( this.running ) {
  4279. var newTime = self.performance !== undefined && self.performance.now !== undefined
  4280. ? self.performance.now()
  4281. : Date.now();
  4282. diff = 0.001 * ( newTime - this.oldTime );
  4283. this.oldTime = newTime;
  4284. this.elapsedTime += diff;
  4285. }
  4286. return diff;
  4287. }
  4288. };
  4289. // File:src/core/EventDispatcher.js
  4290. /**
  4291. * https://github.com/mrdoob/eventdispatcher.js/
  4292. */
  4293. THREE.EventDispatcher = function () {};
  4294. THREE.EventDispatcher.prototype = {
  4295. constructor: THREE.EventDispatcher,
  4296. apply: function ( object ) {
  4297. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4298. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4299. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4300. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4301. },
  4302. addEventListener: function ( type, listener ) {
  4303. if ( this._listeners === undefined ) this._listeners = {};
  4304. var listeners = this._listeners;
  4305. if ( listeners[ type ] === undefined ) {
  4306. listeners[ type ] = [];
  4307. }
  4308. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4309. listeners[ type ].push( listener );
  4310. }
  4311. },
  4312. hasEventListener: function ( type, listener ) {
  4313. if ( this._listeners === undefined ) return false;
  4314. var listeners = this._listeners;
  4315. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4316. return true;
  4317. }
  4318. return false;
  4319. },
  4320. removeEventListener: function ( type, listener ) {
  4321. if ( this._listeners === undefined ) return;
  4322. var listeners = this._listeners;
  4323. var listenerArray = listeners[ type ];
  4324. if ( listenerArray !== undefined ) {
  4325. var index = listenerArray.indexOf( listener );
  4326. if ( index !== - 1 ) {
  4327. listenerArray.splice( index, 1 );
  4328. }
  4329. }
  4330. },
  4331. dispatchEvent: function ( event ) {
  4332. if ( this._listeners === undefined ) return;
  4333. var listeners = this._listeners;
  4334. var listenerArray = listeners[ event.type ];
  4335. if ( listenerArray !== undefined ) {
  4336. event.target = this;
  4337. var array = [];
  4338. var length = listenerArray.length;
  4339. for ( var i = 0; i < length; i ++ ) {
  4340. array[ i ] = listenerArray[ i ];
  4341. }
  4342. for ( var i = 0; i < length; i ++ ) {
  4343. array[ i ].call( this, event );
  4344. }
  4345. }
  4346. }
  4347. };
  4348. // File:src/core/Raycaster.js
  4349. /**
  4350. * @author mrdoob / http://mrdoob.com/
  4351. * @author bhouston / http://exocortex.com/
  4352. * @author stephomi / http://stephaneginier.com/
  4353. */
  4354. ( function ( THREE ) {
  4355. THREE.Raycaster = function ( origin, direction, near, far ) {
  4356. this.ray = new THREE.Ray( origin, direction );
  4357. // direction is assumed to be normalized (for accurate distance calculations)
  4358. this.near = near || 0;
  4359. this.far = far || Infinity;
  4360. this.params = {
  4361. Sprite: {},
  4362. Mesh: {},
  4363. PointCloud: { threshold: 1 },
  4364. LOD: {},
  4365. Line: {}
  4366. };
  4367. };
  4368. var descSort = function ( a, b ) {
  4369. return a.distance - b.distance;
  4370. };
  4371. var intersectObject = function ( object, raycaster, intersects, recursive ) {
  4372. if ( object.visible === false ) return;
  4373. object.raycast( raycaster, intersects );
  4374. if ( recursive === true ) {
  4375. var children = object.children;
  4376. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4377. intersectObject( children[ i ], raycaster, intersects, true );
  4378. }
  4379. }
  4380. };
  4381. //
  4382. THREE.Raycaster.prototype = {
  4383. constructor: THREE.Raycaster,
  4384. linePrecision: 1,
  4385. set: function ( origin, direction ) {
  4386. // direction is assumed to be normalized (for accurate distance calculations)
  4387. this.ray.set( origin, direction );
  4388. },
  4389. setFromCamera: function ( coords, camera ) {
  4390. if ( camera instanceof THREE.PerspectiveCamera ) {
  4391. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4392. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4393. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4394. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4395. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4396. } else {
  4397. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4398. }
  4399. },
  4400. intersectObject: function ( object, recursive ) {
  4401. var intersects = [];
  4402. intersectObject( object, this, intersects, recursive );
  4403. intersects.sort( descSort );
  4404. return intersects;
  4405. },
  4406. intersectObjects: function ( objects, recursive ) {
  4407. var intersects = [];
  4408. if ( Array.isArray( objects ) === false ) {
  4409. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4410. return intersects;
  4411. }
  4412. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4413. intersectObject( objects[ i ], this, intersects, recursive );
  4414. }
  4415. intersects.sort( descSort );
  4416. return intersects;
  4417. }
  4418. };
  4419. }( THREE ) );
  4420. // File:src/core/Object3D.js
  4421. /**
  4422. * @author mrdoob / http://mrdoob.com/
  4423. * @author mikael emtinger / http://gomo.se/
  4424. * @author alteredq / http://alteredqualia.com/
  4425. * @author WestLangley / http://github.com/WestLangley
  4426. * @author elephantatwork / www.elephantatwork.ch
  4427. */
  4428. THREE.Object3D = function () {
  4429. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4430. this.uuid = THREE.Math.generateUUID();
  4431. this.name = '';
  4432. this.type = 'Object3D';
  4433. this.parent = undefined;
  4434. this.children = [];
  4435. this.up = THREE.Object3D.DefaultUp.clone();
  4436. var position = new THREE.Vector3();
  4437. var rotation = new THREE.Euler();
  4438. var quaternion = new THREE.Quaternion();
  4439. var scale = new THREE.Vector3( 1, 1, 1 );
  4440. var onRotationChange = function () {
  4441. quaternion.setFromEuler( rotation, false );
  4442. };
  4443. var onQuaternionChange = function () {
  4444. rotation.setFromQuaternion( quaternion, undefined, false );
  4445. };
  4446. rotation.onChange( onRotationChange );
  4447. quaternion.onChange( onQuaternionChange );
  4448. Object.defineProperties( this, {
  4449. position: {
  4450. enumerable: true,
  4451. value: position
  4452. },
  4453. rotation: {
  4454. enumerable: true,
  4455. value: rotation
  4456. },
  4457. quaternion: {
  4458. enumerable: true,
  4459. value: quaternion
  4460. },
  4461. scale: {
  4462. enumerable: true,
  4463. value: scale
  4464. }
  4465. } );
  4466. this.rotationAutoUpdate = true;
  4467. this.matrix = new THREE.Matrix4();
  4468. this.matrixWorld = new THREE.Matrix4();
  4469. this.matrixAutoUpdate = true;
  4470. this.matrixWorldNeedsUpdate = false;
  4471. this.visible = true;
  4472. this.castShadow = false;
  4473. this.receiveShadow = false;
  4474. this.frustumCulled = true;
  4475. this.renderOrder = 0;
  4476. this.userData = {};
  4477. };
  4478. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4479. THREE.Object3D.prototype = {
  4480. constructor: THREE.Object3D,
  4481. get eulerOrder () {
  4482. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4483. return this.rotation.order;
  4484. },
  4485. set eulerOrder ( value ) {
  4486. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4487. this.rotation.order = value;
  4488. },
  4489. get useQuaternion () {
  4490. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4491. },
  4492. set useQuaternion ( value ) {
  4493. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4494. },
  4495. set renderDepth ( value ) {
  4496. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  4497. },
  4498. applyMatrix: function ( matrix ) {
  4499. this.matrix.multiplyMatrices( matrix, this.matrix );
  4500. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4501. },
  4502. setRotationFromAxisAngle: function ( axis, angle ) {
  4503. // assumes axis is normalized
  4504. this.quaternion.setFromAxisAngle( axis, angle );
  4505. },
  4506. setRotationFromEuler: function ( euler ) {
  4507. this.quaternion.setFromEuler( euler, true );
  4508. },
  4509. setRotationFromMatrix: function ( m ) {
  4510. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4511. this.quaternion.setFromRotationMatrix( m );
  4512. },
  4513. setRotationFromQuaternion: function ( q ) {
  4514. // assumes q is normalized
  4515. this.quaternion.copy( q );
  4516. },
  4517. rotateOnAxis: function () {
  4518. // rotate object on axis in object space
  4519. // axis is assumed to be normalized
  4520. var q1 = new THREE.Quaternion();
  4521. return function ( axis, angle ) {
  4522. q1.setFromAxisAngle( axis, angle );
  4523. this.quaternion.multiply( q1 );
  4524. return this;
  4525. }
  4526. }(),
  4527. rotateX: function () {
  4528. var v1 = new THREE.Vector3( 1, 0, 0 );
  4529. return function ( angle ) {
  4530. return this.rotateOnAxis( v1, angle );
  4531. };
  4532. }(),
  4533. rotateY: function () {
  4534. var v1 = new THREE.Vector3( 0, 1, 0 );
  4535. return function ( angle ) {
  4536. return this.rotateOnAxis( v1, angle );
  4537. };
  4538. }(),
  4539. rotateZ: function () {
  4540. var v1 = new THREE.Vector3( 0, 0, 1 );
  4541. return function ( angle ) {
  4542. return this.rotateOnAxis( v1, angle );
  4543. };
  4544. }(),
  4545. translateOnAxis: function () {
  4546. // translate object by distance along axis in object space
  4547. // axis is assumed to be normalized
  4548. var v1 = new THREE.Vector3();
  4549. return function ( axis, distance ) {
  4550. v1.copy( axis ).applyQuaternion( this.quaternion );
  4551. this.position.add( v1.multiplyScalar( distance ) );
  4552. return this;
  4553. }
  4554. }(),
  4555. translate: function ( distance, axis ) {
  4556. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  4557. return this.translateOnAxis( axis, distance );
  4558. },
  4559. translateX: function () {
  4560. var v1 = new THREE.Vector3( 1, 0, 0 );
  4561. return function ( distance ) {
  4562. return this.translateOnAxis( v1, distance );
  4563. };
  4564. }(),
  4565. translateY: function () {
  4566. var v1 = new THREE.Vector3( 0, 1, 0 );
  4567. return function ( distance ) {
  4568. return this.translateOnAxis( v1, distance );
  4569. };
  4570. }(),
  4571. translateZ: function () {
  4572. var v1 = new THREE.Vector3( 0, 0, 1 );
  4573. return function ( distance ) {
  4574. return this.translateOnAxis( v1, distance );
  4575. };
  4576. }(),
  4577. localToWorld: function ( vector ) {
  4578. return vector.applyMatrix4( this.matrixWorld );
  4579. },
  4580. worldToLocal: function () {
  4581. var m1 = new THREE.Matrix4();
  4582. return function ( vector ) {
  4583. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  4584. };
  4585. }(),
  4586. lookAt: function () {
  4587. // This routine does not support objects with rotated and/or translated parent(s)
  4588. var m1 = new THREE.Matrix4();
  4589. return function ( vector ) {
  4590. m1.lookAt( vector, this.position, this.up );
  4591. this.quaternion.setFromRotationMatrix( m1 );
  4592. };
  4593. }(),
  4594. add: function ( object ) {
  4595. if ( arguments.length > 1 ) {
  4596. for ( var i = 0; i < arguments.length; i ++ ) {
  4597. this.add( arguments[ i ] );
  4598. }
  4599. return this;
  4600. }
  4601. if ( object === this ) {
  4602. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  4603. return this;
  4604. }
  4605. if ( object instanceof THREE.Object3D ) {
  4606. if ( object.parent !== undefined ) {
  4607. object.parent.remove( object );
  4608. }
  4609. object.parent = this;
  4610. object.dispatchEvent( { type: 'added' } );
  4611. this.children.push( object );
  4612. } else {
  4613. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  4614. }
  4615. return this;
  4616. },
  4617. remove: function ( object ) {
  4618. if ( arguments.length > 1 ) {
  4619. for ( var i = 0; i < arguments.length; i ++ ) {
  4620. this.remove( arguments[ i ] );
  4621. }
  4622. }
  4623. var index = this.children.indexOf( object );
  4624. if ( index !== - 1 ) {
  4625. object.parent = undefined;
  4626. object.dispatchEvent( { type: 'removed' } );
  4627. this.children.splice( index, 1 );
  4628. }
  4629. },
  4630. getChildByName: function ( name ) {
  4631. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  4632. return this.getObjectByName( name );
  4633. },
  4634. getObjectById: function ( id ) {
  4635. return this.getObjectByProperty( 'id', id );
  4636. },
  4637. getObjectByName: function ( name ) {
  4638. return this.getObjectByProperty( 'name', name );
  4639. },
  4640. getObjectByProperty: function ( name, value ) {
  4641. if ( this[ name ] === value ) return this;
  4642. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4643. var child = this.children[ i ];
  4644. var object = child.getObjectByProperty( name, value );
  4645. if ( object !== undefined ) {
  4646. return object;
  4647. }
  4648. }
  4649. return undefined;
  4650. },
  4651. getWorldPosition: function ( optionalTarget ) {
  4652. var result = optionalTarget || new THREE.Vector3();
  4653. this.updateMatrixWorld( true );
  4654. return result.setFromMatrixPosition( this.matrixWorld );
  4655. },
  4656. getWorldQuaternion: function () {
  4657. var position = new THREE.Vector3();
  4658. var scale = new THREE.Vector3();
  4659. return function ( optionalTarget ) {
  4660. var result = optionalTarget || new THREE.Quaternion();
  4661. this.updateMatrixWorld( true );
  4662. this.matrixWorld.decompose( position, result, scale );
  4663. return result;
  4664. }
  4665. }(),
  4666. getWorldRotation: function () {
  4667. var quaternion = new THREE.Quaternion();
  4668. return function ( optionalTarget ) {
  4669. var result = optionalTarget || new THREE.Euler();
  4670. this.getWorldQuaternion( quaternion );
  4671. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  4672. }
  4673. }(),
  4674. getWorldScale: function () {
  4675. var position = new THREE.Vector3();
  4676. var quaternion = new THREE.Quaternion();
  4677. return function ( optionalTarget ) {
  4678. var result = optionalTarget || new THREE.Vector3();
  4679. this.updateMatrixWorld( true );
  4680. this.matrixWorld.decompose( position, quaternion, result );
  4681. return result;
  4682. }
  4683. }(),
  4684. getWorldDirection: function () {
  4685. var quaternion = new THREE.Quaternion();
  4686. return function ( optionalTarget ) {
  4687. var result = optionalTarget || new THREE.Vector3();
  4688. this.getWorldQuaternion( quaternion );
  4689. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  4690. }
  4691. }(),
  4692. raycast: function () {},
  4693. traverse: function ( callback ) {
  4694. callback( this );
  4695. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4696. this.children[ i ].traverse( callback );
  4697. }
  4698. },
  4699. traverseVisible: function ( callback ) {
  4700. if ( this.visible === false ) return;
  4701. callback( this );
  4702. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4703. this.children[ i ].traverseVisible( callback );
  4704. }
  4705. },
  4706. traverseAncestors: function ( callback ) {
  4707. if ( this.parent ) {
  4708. callback( this.parent );
  4709. this.parent.traverseAncestors( callback );
  4710. }
  4711. },
  4712. updateMatrix: function () {
  4713. this.matrix.compose( this.position, this.quaternion, this.scale );
  4714. this.matrixWorldNeedsUpdate = true;
  4715. },
  4716. updateMatrixWorld: function ( force ) {
  4717. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  4718. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  4719. if ( this.parent === undefined ) {
  4720. this.matrixWorld.copy( this.matrix );
  4721. } else {
  4722. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4723. }
  4724. this.matrixWorldNeedsUpdate = false;
  4725. force = true;
  4726. }
  4727. // update children
  4728. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4729. this.children[ i ].updateMatrixWorld( force );
  4730. }
  4731. },
  4732. toJSON: function ( meta ) {
  4733. var isRootObject = ( meta === undefined );
  4734. var data = {};
  4735. // meta is a hash used to collect geometries, materials.
  4736. // not providing it implies that this is the root object
  4737. // being serialized.
  4738. if ( isRootObject ) {
  4739. // initialize meta obj
  4740. meta = {
  4741. geometries: {},
  4742. materials: {},
  4743. textures: {},
  4744. images: {}
  4745. };
  4746. data.metadata = {
  4747. version: 4.4,
  4748. type: 'Object',
  4749. generator: 'Object3D.toJSON'
  4750. };
  4751. }
  4752. // standard Object3D serialization
  4753. data.uuid = this.uuid;
  4754. data.type = this.type;
  4755. if ( this.name !== '' ) data.name = this.name;
  4756. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  4757. if ( this.visible !== true ) data.visible = this.visible;
  4758. data.matrix = this.matrix.toArray();
  4759. if ( this.children.length > 0 ) {
  4760. data.children = [];
  4761. for ( var i = 0; i < this.children.length; i ++ ) {
  4762. data.children.push( this.children[ i ].toJSON( meta ).object );
  4763. }
  4764. }
  4765. var output = {};
  4766. if ( isRootObject ) {
  4767. var geometries = extractFromCache( meta.geometries );
  4768. var materials = extractFromCache( meta.materials );
  4769. var textures = extractFromCache( meta.textures );
  4770. var images = extractFromCache( meta.images );
  4771. if ( geometries.length > 0 ) output.geometries = geometries;
  4772. if ( materials.length > 0 ) output.materials = materials;
  4773. if ( textures.length > 0 ) output.textures = textures;
  4774. if ( images.length > 0 ) output.images = images;
  4775. }
  4776. output.object = data;
  4777. return output;
  4778. // extract data from the cache hash
  4779. // remove metadata on each item
  4780. // and return as array
  4781. function extractFromCache ( cache ) {
  4782. var values = [];
  4783. for ( var key in cache ) {
  4784. var data = cache[ key ];
  4785. delete data.metadata;
  4786. values.push( data );
  4787. }
  4788. return values;
  4789. }
  4790. },
  4791. clone: function ( object, recursive ) {
  4792. if ( object === undefined ) object = new THREE.Object3D();
  4793. if ( recursive === undefined ) recursive = true;
  4794. object.name = this.name;
  4795. object.up.copy( this.up );
  4796. object.position.copy( this.position );
  4797. object.quaternion.copy( this.quaternion );
  4798. object.scale.copy( this.scale );
  4799. object.rotationAutoUpdate = this.rotationAutoUpdate;
  4800. object.matrix.copy( this.matrix );
  4801. object.matrixWorld.copy( this.matrixWorld );
  4802. object.matrixAutoUpdate = this.matrixAutoUpdate;
  4803. object.matrixWorldNeedsUpdate = this.matrixWorldNeedsUpdate;
  4804. object.visible = this.visible;
  4805. object.castShadow = this.castShadow;
  4806. object.receiveShadow = this.receiveShadow;
  4807. object.frustumCulled = this.frustumCulled;
  4808. object.renderOrder = this.renderOrder;
  4809. object.userData = JSON.parse( JSON.stringify( this.userData ) );
  4810. if ( recursive === true ) {
  4811. for ( var i = 0; i < this.children.length; i ++ ) {
  4812. var child = this.children[ i ];
  4813. object.add( child.clone() );
  4814. }
  4815. }
  4816. return object;
  4817. }
  4818. };
  4819. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  4820. THREE.Object3DIdCount = 0;
  4821. // File:src/core/Face3.js
  4822. /**
  4823. * @author mrdoob / http://mrdoob.com/
  4824. * @author alteredq / http://alteredqualia.com/
  4825. */
  4826. THREE.Face3 = function ( a, b, c, normal, color ) {
  4827. this.a = a;
  4828. this.b = b;
  4829. this.c = c;
  4830. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  4831. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4832. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  4833. this.vertexColors = Array.isArray( color ) ? color : [];
  4834. this.vertexTangents = [];
  4835. };
  4836. THREE.Face3.prototype = {
  4837. constructor: THREE.Face3,
  4838. clone: function () {
  4839. var face = new THREE.Face3( this.a, this.b, this.c );
  4840. face.normal.copy( this.normal );
  4841. face.color.copy( this.color );
  4842. for ( var i = 0, il = this.vertexNormals.length; i < il; i ++ ) {
  4843. face.vertexNormals[ i ] = this.vertexNormals[ i ].clone();
  4844. }
  4845. for ( var i = 0, il = this.vertexColors.length; i < il; i ++ ) {
  4846. face.vertexColors[ i ] = this.vertexColors[ i ].clone();
  4847. }
  4848. for ( var i = 0, il = this.vertexTangents.length; i < il; i ++ ) {
  4849. face.vertexTangents[ i ] = this.vertexTangents[ i ].clone();
  4850. }
  4851. return face;
  4852. }
  4853. };
  4854. // File:src/core/Face4.js
  4855. /**
  4856. * @author mrdoob / http://mrdoob.com/
  4857. */
  4858. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  4859. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  4860. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  4861. };
  4862. // File:src/core/BufferAttribute.js
  4863. /**
  4864. * @author mrdoob / http://mrdoob.com/
  4865. */
  4866. THREE.BufferAttribute = function ( array, itemSize ) {
  4867. this.uuid = THREE.Math.generateUUID();
  4868. this.array = array;
  4869. this.itemSize = itemSize;
  4870. this.needsUpdate = false;
  4871. };
  4872. THREE.BufferAttribute.prototype = {
  4873. constructor: THREE.BufferAttribute,
  4874. get length () {
  4875. console.warn( 'THREE.BufferAttribute: .length has been renamed to .count.' );
  4876. return this.count;
  4877. },
  4878. get count() {
  4879. return this.array.length / this.itemSize;
  4880. },
  4881. copyAt: function ( index1, attribute, index2 ) {
  4882. index1 *= this.itemSize;
  4883. index2 *= attribute.itemSize;
  4884. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  4885. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  4886. }
  4887. return this;
  4888. },
  4889. copyArray: function ( array ) {
  4890. this.array.set( array );
  4891. return this;
  4892. },
  4893. copyColorsArray: function ( colors ) {
  4894. var array = this.array, offset = 0;
  4895. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  4896. var color = colors[ i ];
  4897. if ( color === undefined ) {
  4898. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  4899. color = new THREE.Color();
  4900. }
  4901. array[ offset ++ ] = color.r;
  4902. array[ offset ++ ] = color.g;
  4903. array[ offset ++ ] = color.b;
  4904. }
  4905. return this;
  4906. },
  4907. copyIndicesArray: function ( indices ) {
  4908. var array = this.array, offset = 0;
  4909. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  4910. var index = indices[ i ];
  4911. array[ offset ++ ] = index.a;
  4912. array[ offset ++ ] = index.b;
  4913. array[ offset ++ ] = index.c;
  4914. }
  4915. return this;
  4916. },
  4917. copyVector2sArray: function ( vectors ) {
  4918. var array = this.array, offset = 0;
  4919. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  4920. var vector = vectors[ i ];
  4921. if ( vector === undefined ) {
  4922. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  4923. vector = new THREE.Vector2();
  4924. }
  4925. array[ offset ++ ] = vector.x;
  4926. array[ offset ++ ] = vector.y;
  4927. }
  4928. return this;
  4929. },
  4930. copyVector3sArray: function ( vectors ) {
  4931. var array = this.array, offset = 0;
  4932. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  4933. var vector = vectors[ i ];
  4934. if ( vector === undefined ) {
  4935. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  4936. vector = new THREE.Vector3();
  4937. }
  4938. array[ offset ++ ] = vector.x;
  4939. array[ offset ++ ] = vector.y;
  4940. array[ offset ++ ] = vector.z;
  4941. }
  4942. return this;
  4943. },
  4944. copyVector4sArray: function ( vectors ) {
  4945. var array = this.array, offset = 0;
  4946. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  4947. var vector = vectors[ i ];
  4948. if ( vector === undefined ) {
  4949. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  4950. vector = new THREE.Vector4();
  4951. }
  4952. array[ offset ++ ] = vector.x;
  4953. array[ offset ++ ] = vector.y;
  4954. array[ offset ++ ] = vector.z;
  4955. array[ offset ++ ] = vector.w;
  4956. }
  4957. return this;
  4958. },
  4959. set: function ( value, offset ) {
  4960. if ( offset === undefined ) offset = 0;
  4961. this.array.set( value, offset );
  4962. return this;
  4963. },
  4964. getX: function ( index ) {
  4965. return this.array[ index * this.itemSize ];
  4966. },
  4967. setX: function ( index, x ) {
  4968. this.array[ index * this.itemSize ] = x;
  4969. return this;
  4970. },
  4971. getY: function ( index ) {
  4972. return this.array[ index * this.itemSize + 1 ];
  4973. },
  4974. setY: function ( index, y ) {
  4975. this.array[ index * this.itemSize + 1 ] = y;
  4976. return this;
  4977. },
  4978. getZ: function ( index ) {
  4979. return this.array[ index * this.itemSize + 2 ];
  4980. },
  4981. setZ: function ( index, z ) {
  4982. this.array[ index * this.itemSize + 2 ] = z;
  4983. return this;
  4984. },
  4985. getW: function ( index ) {
  4986. return this.array[ index * this.itemSize + 3 ];
  4987. },
  4988. setW: function ( index, w ) {
  4989. this.array[ index * this.itemSize + 3 ] = w;
  4990. return this;
  4991. },
  4992. setXY: function ( index, x, y ) {
  4993. index *= this.itemSize;
  4994. this.array[ index + 0 ] = x;
  4995. this.array[ index + 1 ] = y;
  4996. return this;
  4997. },
  4998. setXYZ: function ( index, x, y, z ) {
  4999. index *= this.itemSize;
  5000. this.array[ index + 0 ] = x;
  5001. this.array[ index + 1 ] = y;
  5002. this.array[ index + 2 ] = z;
  5003. return this;
  5004. },
  5005. setXYZW: function ( index, x, y, z, w ) {
  5006. index *= this.itemSize;
  5007. this.array[ index + 0 ] = x;
  5008. this.array[ index + 1 ] = y;
  5009. this.array[ index + 2 ] = z;
  5010. this.array[ index + 3 ] = w;
  5011. return this;
  5012. },
  5013. clone: function () {
  5014. return new THREE.BufferAttribute( new this.array.constructor( this.array ), this.itemSize );
  5015. }
  5016. };
  5017. //
  5018. THREE.Int8Attribute = function ( array, itemSize ) {
  5019. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5020. };
  5021. THREE.Uint8Attribute = function ( array, itemSize ) {
  5022. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5023. };
  5024. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5025. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5026. };
  5027. THREE.Int16Attribute = function ( array, itemSize ) {
  5028. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5029. };
  5030. THREE.Uint16Attribute = function ( array, itemSize ) {
  5031. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5032. };
  5033. THREE.Int32Attribute = function ( array, itemSize ) {
  5034. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5035. };
  5036. THREE.Uint32Attribute = function ( array, itemSize ) {
  5037. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5038. };
  5039. THREE.Float32Attribute = function ( array, itemSize ) {
  5040. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5041. };
  5042. THREE.Float64Attribute = function ( array, itemSize ) {
  5043. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5044. };
  5045. // File:src/core/DynamicBufferAttribute.js
  5046. /**
  5047. * @author benaadams / https://twitter.com/ben_a_adams
  5048. * @author mrdoob / http://mrdoob.com/
  5049. */
  5050. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5051. THREE.BufferAttribute.call( this, array, itemSize );
  5052. this.updateRange = { offset: 0, count: -1 };
  5053. };
  5054. THREE.DynamicBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5055. THREE.DynamicBufferAttribute.prototype.constructor = THREE.DynamicBufferAttribute;
  5056. THREE.DynamicBufferAttribute.prototype.clone = function () {
  5057. return new THREE.DynamicBufferAttribute( new this.array.constructor( this.array ), this.itemSize );
  5058. };
  5059. // File:src/core/InstancedBufferAttribute.js
  5060. /**
  5061. * @author benaadams / https://twitter.com/ben_a_adams
  5062. */
  5063. THREE.InstancedBufferAttribute = function (array, itemSize, meshPerAttribute, dynamic) {
  5064. THREE.DynamicBufferAttribute.call( this, array, itemSize );
  5065. this.dynamic = dynamic || false;
  5066. this.meshPerAttribute = meshPerAttribute || 1;
  5067. };
  5068. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.DynamicBufferAttribute.prototype );
  5069. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5070. THREE.InstancedBufferAttribute.prototype.clone = function () {
  5071. return new THREE.InstancedBufferAttribute( new this.array.constructor( this.array ), this.itemSize, this.meshPerAttribute, this.dynamic );
  5072. };
  5073. // File:src/core/InterleavedBuffer.js
  5074. /**
  5075. * @author benaadams / https://twitter.com/ben_a_adams
  5076. */
  5077. THREE.InterleavedBuffer = function ( array, stride, dynamic ) {
  5078. this.uuid = THREE.Math.generateUUID();
  5079. this.array = array;
  5080. this.stride = stride;
  5081. this.needsUpdate = false;
  5082. this.dynamic = dynamic || false;
  5083. this.updateRange = { offset: 0, count: -1 };
  5084. };
  5085. THREE.InterleavedBuffer.prototype = {
  5086. constructor: THREE.InterleavedBuffer,
  5087. get length () {
  5088. return this.array.length;
  5089. },
  5090. copyAt: function ( index1, attribute, index2 ) {
  5091. index1 *= this.stride;
  5092. index2 *= attribute.stride;
  5093. for ( var i = 0, l = this.stride; i < l; i++ ) {
  5094. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5095. }
  5096. return this;
  5097. },
  5098. set: function ( value, offset ) {
  5099. if ( offset === undefined ) offset = 0;
  5100. this.array.set( value, offset );
  5101. return this;
  5102. },
  5103. clone: function () {
  5104. return new THREE.InterleavedBuffer( new this.array.constructor( this.array ), this.stride, this.dynamic );
  5105. }
  5106. };
  5107. // File:src/core/InstancedInterleavedBuffer.js
  5108. /**
  5109. * @author benaadams / https://twitter.com/ben_a_adams
  5110. */
  5111. THREE.InstancedInterleavedBuffer = function ( array, stride, dynamic, meshPerAttribute ) {
  5112. THREE.InterleavedBuffer.call( this, array, stride, dynamic );
  5113. this.meshPerAttribute = meshPerAttribute || 1;
  5114. };
  5115. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5116. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5117. THREE.InstancedInterleavedBuffer.prototype.clone = function () {
  5118. return new THREE.InstancedInterleavedBuffer( new this.array.constructor( this.array ), this.stride, this.dynamic, this.meshPerAttribute );
  5119. };
  5120. // File:src/core/InterleavedBufferAttribute.js
  5121. /**
  5122. * @author benaadams / https://twitter.com/ben_a_adams
  5123. */
  5124. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5125. this.uuid = THREE.Math.generateUUID();
  5126. this.data = interleavedBuffer;
  5127. this.itemSize = itemSize;
  5128. this.offset = offset;
  5129. };
  5130. THREE.InterleavedBufferAttribute.prototype = {
  5131. constructor: THREE.InterleavedBufferAttribute,
  5132. get length() {
  5133. console.warn( 'THREE.InterleavedBufferAttribute: .length has been renamed to .count.' );
  5134. return this.count;
  5135. },
  5136. get count() {
  5137. return this.data.array.length / this.data.stride;
  5138. },
  5139. setX: function ( index, x ) {
  5140. this.data.array[ index * this.data.stride + this.offset ] = x;
  5141. return this;
  5142. },
  5143. setY: function ( index, y ) {
  5144. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5145. return this;
  5146. },
  5147. setZ: function ( index, z ) {
  5148. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5149. return this;
  5150. },
  5151. setW: function ( index, w ) {
  5152. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5153. return this;
  5154. },
  5155. getX: function ( index ) {
  5156. return this.data.array[ index * this.data.stride + this.offset ];
  5157. },
  5158. getY: function ( index ) {
  5159. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5160. },
  5161. getZ: function ( index ) {
  5162. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5163. },
  5164. getW: function ( index ) {
  5165. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5166. },
  5167. setXY: function ( index, x, y ) {
  5168. index = index * this.data.stride + this.offset;
  5169. this.data.array[ index + 0 ] = x;
  5170. this.data.array[ index + 1 ] = y;
  5171. return this;
  5172. },
  5173. setXYZ: function ( index, x, y, z ) {
  5174. index = index * this.data.stride + this.offset;
  5175. this.data.array[ index + 0 ] = x;
  5176. this.data.array[ index + 1 ] = y;
  5177. this.data.array[ index + 2 ] = z;
  5178. return this;
  5179. },
  5180. setXYZW: function ( index, x, y, z, w ) {
  5181. index = index * this.data.stride + this.offset;
  5182. this.data.array[ index + 0 ] = x;
  5183. this.data.array[ index + 1 ] = y;
  5184. this.data.array[ index + 2 ] = z;
  5185. this.data.array[ index + 3 ] = w;
  5186. return this;
  5187. }
  5188. };
  5189. // File:src/core/Geometry.js
  5190. /**
  5191. * @author mrdoob / http://mrdoob.com/
  5192. * @author kile / http://kile.stravaganza.org/
  5193. * @author alteredq / http://alteredqualia.com/
  5194. * @author mikael emtinger / http://gomo.se/
  5195. * @author zz85 / http://www.lab4games.net/zz85/blog
  5196. * @author bhouston / http://exocortex.com
  5197. */
  5198. THREE.Geometry = function () {
  5199. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5200. this.uuid = THREE.Math.generateUUID();
  5201. this.name = '';
  5202. this.type = 'Geometry';
  5203. this.vertices = [];
  5204. this.colors = [];
  5205. this.faces = [];
  5206. this.faceVertexUvs = [ [] ];
  5207. this.morphTargets = [];
  5208. this.morphColors = [];
  5209. this.morphNormals = [];
  5210. this.skinWeights = [];
  5211. this.skinIndices = [];
  5212. this.lineDistances = [];
  5213. this.boundingBox = null;
  5214. this.boundingSphere = null;
  5215. this.hasTangents = false;
  5216. // update flags
  5217. this.verticesNeedUpdate = false;
  5218. this.elementsNeedUpdate = false;
  5219. this.uvsNeedUpdate = false;
  5220. this.normalsNeedUpdate = false;
  5221. this.tangentsNeedUpdate = false;
  5222. this.colorsNeedUpdate = false;
  5223. this.lineDistancesNeedUpdate = false;
  5224. };
  5225. THREE.Geometry.prototype = {
  5226. constructor: THREE.Geometry,
  5227. applyMatrix: function ( matrix ) {
  5228. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5229. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5230. var vertex = this.vertices[ i ];
  5231. vertex.applyMatrix4( matrix );
  5232. }
  5233. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5234. var face = this.faces[ i ];
  5235. face.normal.applyMatrix3( normalMatrix ).normalize();
  5236. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5237. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5238. }
  5239. }
  5240. if ( this.boundingBox !== null ) {
  5241. this.computeBoundingBox();
  5242. }
  5243. if ( this.boundingSphere !== null ) {
  5244. this.computeBoundingSphere();
  5245. }
  5246. this.verticesNeedUpdate = true;
  5247. this.normalsNeedUpdate = true;
  5248. },
  5249. fromBufferGeometry: function ( geometry ) {
  5250. var scope = this;
  5251. var attributes = geometry.attributes;
  5252. var vertices = attributes.position.array;
  5253. var indices = attributes.index !== undefined ? attributes.index.array : undefined;
  5254. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5255. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5256. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5257. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5258. var tangents = attributes.tangent !== undefined ? attributes.tangent.array : undefined;
  5259. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5260. if ( tangents !== undefined ) this.hasTangents = true;
  5261. var tempNormals = [];
  5262. var tempUVs = [];
  5263. var tempUVs2 = [];
  5264. var tempTangents = [];
  5265. for ( var i = 0, j = 0, k = 0; i < vertices.length; i += 3, j += 2, k += 4 ) {
  5266. scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  5267. if ( normals !== undefined ) {
  5268. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5269. }
  5270. if ( colors !== undefined ) {
  5271. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5272. }
  5273. if ( uvs !== undefined ) {
  5274. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5275. }
  5276. if ( uvs2 !== undefined ) {
  5277. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5278. }
  5279. if ( tangents !== undefined ) {
  5280. tempTangents.push( new THREE.Vector4( tangents[ k ], tangents[ k + 1 ], tangents[ k + 2 ], tangents[ k + 3 ] ) );
  5281. }
  5282. }
  5283. var addFace = function ( a, b, c ) {
  5284. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5285. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5286. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5287. scope.faces.push( face );
  5288. if ( uvs !== undefined ) {
  5289. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5290. }
  5291. if ( uvs2 !== undefined ) {
  5292. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5293. }
  5294. if ( tangents !== undefined ) {
  5295. face.vertexTangents.push( tempTangents[ a ].clone(), tempTangents[ b ].clone(), tempTangents[ c ].clone() );
  5296. }
  5297. };
  5298. if ( indices !== undefined ) {
  5299. var drawcalls = geometry.drawcalls;
  5300. if ( drawcalls.length > 0 ) {
  5301. for ( var i = 0; i < drawcalls.length; i ++ ) {
  5302. var drawcall = drawcalls[ i ];
  5303. var start = drawcall.start;
  5304. var count = drawcall.count;
  5305. var index = drawcall.index;
  5306. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5307. addFace( index + indices[ j ], index + indices[ j + 1 ], index + indices[ j + 2 ] );
  5308. }
  5309. }
  5310. } else {
  5311. for ( var i = 0; i < indices.length; i += 3 ) {
  5312. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5313. }
  5314. }
  5315. } else {
  5316. for ( var i = 0; i < vertices.length / 3; i += 3 ) {
  5317. addFace( i, i + 1, i + 2 );
  5318. }
  5319. }
  5320. this.computeFaceNormals();
  5321. if ( geometry.boundingBox !== null ) {
  5322. this.boundingBox = geometry.boundingBox.clone();
  5323. }
  5324. if ( geometry.boundingSphere !== null ) {
  5325. this.boundingSphere = geometry.boundingSphere.clone();
  5326. }
  5327. return this;
  5328. },
  5329. center: function () {
  5330. this.computeBoundingBox();
  5331. var offset = this.boundingBox.center().negate();
  5332. this.applyMatrix( new THREE.Matrix4().setPosition( offset ) );
  5333. return offset;
  5334. },
  5335. normalize: function () {
  5336. this.computeBoundingSphere();
  5337. var center = this.boundingSphere.center;
  5338. var radius = this.boundingSphere.radius;
  5339. var s = radius === 0 ? 1 : 1.0 / radius;
  5340. var matrix = new THREE.Matrix4();
  5341. matrix.set(
  5342. s, 0, 0, -s * center.x,
  5343. 0, s, 0, -s * center.y,
  5344. 0, 0, s, -s * center.z,
  5345. 0, 0, 0, 1
  5346. );
  5347. this.applyMatrix( matrix );
  5348. return this;
  5349. },
  5350. computeFaceNormals: function () {
  5351. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5352. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5353. var face = this.faces[ f ];
  5354. var vA = this.vertices[ face.a ];
  5355. var vB = this.vertices[ face.b ];
  5356. var vC = this.vertices[ face.c ];
  5357. cb.subVectors( vC, vB );
  5358. ab.subVectors( vA, vB );
  5359. cb.cross( ab );
  5360. cb.normalize();
  5361. face.normal.copy( cb );
  5362. }
  5363. },
  5364. computeVertexNormals: function ( areaWeighted ) {
  5365. var v, vl, f, fl, face, vertices;
  5366. vertices = new Array( this.vertices.length );
  5367. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5368. vertices[ v ] = new THREE.Vector3();
  5369. }
  5370. if ( areaWeighted ) {
  5371. // vertex normals weighted by triangle areas
  5372. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5373. var vA, vB, vC;
  5374. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5375. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5376. face = this.faces[ f ];
  5377. vA = this.vertices[ face.a ];
  5378. vB = this.vertices[ face.b ];
  5379. vC = this.vertices[ face.c ];
  5380. cb.subVectors( vC, vB );
  5381. ab.subVectors( vA, vB );
  5382. cb.cross( ab );
  5383. vertices[ face.a ].add( cb );
  5384. vertices[ face.b ].add( cb );
  5385. vertices[ face.c ].add( cb );
  5386. }
  5387. } else {
  5388. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5389. face = this.faces[ f ];
  5390. vertices[ face.a ].add( face.normal );
  5391. vertices[ face.b ].add( face.normal );
  5392. vertices[ face.c ].add( face.normal );
  5393. }
  5394. }
  5395. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5396. vertices[ v ].normalize();
  5397. }
  5398. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5399. face = this.faces[ f ];
  5400. var vertexNormals = face.vertexNormals;
  5401. if ( vertexNormals.length === 3 ) {
  5402. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5403. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5404. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5405. } else {
  5406. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5407. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5408. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5409. }
  5410. }
  5411. },
  5412. computeMorphNormals: function () {
  5413. var i, il, f, fl, face;
  5414. // save original normals
  5415. // - create temp variables on first access
  5416. // otherwise just copy (for faster repeated calls)
  5417. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5418. face = this.faces[ f ];
  5419. if ( ! face.__originalFaceNormal ) {
  5420. face.__originalFaceNormal = face.normal.clone();
  5421. } else {
  5422. face.__originalFaceNormal.copy( face.normal );
  5423. }
  5424. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5425. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5426. if ( ! face.__originalVertexNormals[ i ] ) {
  5427. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5428. } else {
  5429. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5430. }
  5431. }
  5432. }
  5433. // use temp geometry to compute face and vertex normals for each morph
  5434. var tmpGeo = new THREE.Geometry();
  5435. tmpGeo.faces = this.faces;
  5436. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5437. // create on first access
  5438. if ( ! this.morphNormals[ i ] ) {
  5439. this.morphNormals[ i ] = {};
  5440. this.morphNormals[ i ].faceNormals = [];
  5441. this.morphNormals[ i ].vertexNormals = [];
  5442. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5443. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5444. var faceNormal, vertexNormals;
  5445. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5446. faceNormal = new THREE.Vector3();
  5447. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5448. dstNormalsFace.push( faceNormal );
  5449. dstNormalsVertex.push( vertexNormals );
  5450. }
  5451. }
  5452. var morphNormals = this.morphNormals[ i ];
  5453. // set vertices to morph target
  5454. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5455. // compute morph normals
  5456. tmpGeo.computeFaceNormals();
  5457. tmpGeo.computeVertexNormals();
  5458. // store morph normals
  5459. var faceNormal, vertexNormals;
  5460. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5461. face = this.faces[ f ];
  5462. faceNormal = morphNormals.faceNormals[ f ];
  5463. vertexNormals = morphNormals.vertexNormals[ f ];
  5464. faceNormal.copy( face.normal );
  5465. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5466. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5467. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5468. }
  5469. }
  5470. // restore original normals
  5471. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5472. face = this.faces[ f ];
  5473. face.normal = face.__originalFaceNormal;
  5474. face.vertexNormals = face.__originalVertexNormals;
  5475. }
  5476. },
  5477. computeTangents: function () {
  5478. // based on http://www.terathon.com/code/tangent.html
  5479. // tangents go to vertices
  5480. var f, fl, v, vl, i, vertexIndex,
  5481. face, uv, vA, vB, vC, uvA, uvB, uvC,
  5482. x1, x2, y1, y2, z1, z2,
  5483. s1, s2, t1, t2, r, t, test,
  5484. tan1 = [], tan2 = [],
  5485. sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
  5486. tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(),
  5487. n = new THREE.Vector3(), w;
  5488. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5489. tan1[ v ] = new THREE.Vector3();
  5490. tan2[ v ] = new THREE.Vector3();
  5491. }
  5492. function handleTriangle( context, a, b, c, ua, ub, uc ) {
  5493. vA = context.vertices[ a ];
  5494. vB = context.vertices[ b ];
  5495. vC = context.vertices[ c ];
  5496. uvA = uv[ ua ];
  5497. uvB = uv[ ub ];
  5498. uvC = uv[ uc ];
  5499. x1 = vB.x - vA.x;
  5500. x2 = vC.x - vA.x;
  5501. y1 = vB.y - vA.y;
  5502. y2 = vC.y - vA.y;
  5503. z1 = vB.z - vA.z;
  5504. z2 = vC.z - vA.z;
  5505. s1 = uvB.x - uvA.x;
  5506. s2 = uvC.x - uvA.x;
  5507. t1 = uvB.y - uvA.y;
  5508. t2 = uvC.y - uvA.y;
  5509. r = 1.0 / ( s1 * t2 - s2 * t1 );
  5510. sdir.set( ( t2 * x1 - t1 * x2 ) * r,
  5511. ( t2 * y1 - t1 * y2 ) * r,
  5512. ( t2 * z1 - t1 * z2 ) * r );
  5513. tdir.set( ( s1 * x2 - s2 * x1 ) * r,
  5514. ( s1 * y2 - s2 * y1 ) * r,
  5515. ( s1 * z2 - s2 * z1 ) * r );
  5516. tan1[ a ].add( sdir );
  5517. tan1[ b ].add( sdir );
  5518. tan1[ c ].add( sdir );
  5519. tan2[ a ].add( tdir );
  5520. tan2[ b ].add( tdir );
  5521. tan2[ c ].add( tdir );
  5522. }
  5523. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5524. face = this.faces[ f ];
  5525. uv = this.faceVertexUvs[ 0 ][ f ]; // use UV layer 0 for tangents
  5526. handleTriangle( this, face.a, face.b, face.c, 0, 1, 2 );
  5527. }
  5528. var faceIndex = [ 'a', 'b', 'c', 'd' ];
  5529. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5530. face = this.faces[ f ];
  5531. for ( i = 0; i < Math.min( face.vertexNormals.length, 3 ); i ++ ) {
  5532. n.copy( face.vertexNormals[ i ] );
  5533. vertexIndex = face[ faceIndex[ i ] ];
  5534. t = tan1[ vertexIndex ];
  5535. // Gram-Schmidt orthogonalize
  5536. tmp.copy( t );
  5537. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  5538. // Calculate handedness
  5539. tmp2.crossVectors( face.vertexNormals[ i ], t );
  5540. test = tmp2.dot( tan2[ vertexIndex ] );
  5541. w = ( test < 0.0 ) ? - 1.0 : 1.0;
  5542. face.vertexTangents[ i ] = new THREE.Vector4( tmp.x, tmp.y, tmp.z, w );
  5543. }
  5544. }
  5545. this.hasTangents = true;
  5546. },
  5547. computeLineDistances: function () {
  5548. var d = 0;
  5549. var vertices = this.vertices;
  5550. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5551. if ( i > 0 ) {
  5552. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  5553. }
  5554. this.lineDistances[ i ] = d;
  5555. }
  5556. },
  5557. computeBoundingBox: function () {
  5558. if ( this.boundingBox === null ) {
  5559. this.boundingBox = new THREE.Box3();
  5560. }
  5561. this.boundingBox.setFromPoints( this.vertices );
  5562. },
  5563. computeBoundingSphere: function () {
  5564. if ( this.boundingSphere === null ) {
  5565. this.boundingSphere = new THREE.Sphere();
  5566. }
  5567. this.boundingSphere.setFromPoints( this.vertices );
  5568. },
  5569. merge: function ( geometry, matrix ) {
  5570. if ( geometry instanceof THREE.Geometry === false ) {
  5571. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5572. return;
  5573. }
  5574. var normalMatrix,
  5575. vertexOffset = this.vertices.length,
  5576. vertices1 = this.vertices,
  5577. vertices2 = geometry.vertices,
  5578. faces1 = this.faces,
  5579. faces2 = geometry.faces,
  5580. uvs1 = this.faceVertexUvs[ 0 ],
  5581. uvs2 = geometry.faceVertexUvs[ 0 ];
  5582. if ( matrix !== undefined ) {
  5583. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5584. }
  5585. // vertices
  5586. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5587. var vertex = vertices2[ i ];
  5588. var vertexCopy = vertex.clone();
  5589. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5590. vertices1.push( vertexCopy );
  5591. }
  5592. // faces
  5593. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5594. var face = faces2[ i ], faceCopy, normal, color,
  5595. faceVertexNormals = face.vertexNormals,
  5596. faceVertexColors = face.vertexColors;
  5597. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5598. faceCopy.normal.copy( face.normal );
  5599. if ( normalMatrix !== undefined ) {
  5600. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5601. }
  5602. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5603. normal = faceVertexNormals[ j ].clone();
  5604. if ( normalMatrix !== undefined ) {
  5605. normal.applyMatrix3( normalMatrix ).normalize();
  5606. }
  5607. faceCopy.vertexNormals.push( normal );
  5608. }
  5609. faceCopy.color.copy( face.color );
  5610. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5611. color = faceVertexColors[ j ];
  5612. faceCopy.vertexColors.push( color.clone() );
  5613. }
  5614. faces1.push( faceCopy );
  5615. }
  5616. // uvs
  5617. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5618. var uv = uvs2[ i ], uvCopy = [];
  5619. if ( uv === undefined ) {
  5620. continue;
  5621. }
  5622. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5623. uvCopy.push( uv[ j ].clone() );
  5624. }
  5625. uvs1.push( uvCopy );
  5626. }
  5627. },
  5628. mergeMesh: function ( mesh ) {
  5629. if ( mesh instanceof THREE.Mesh === false ) {
  5630. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5631. return;
  5632. }
  5633. mesh.matrixAutoUpdate && mesh.updateMatrix();
  5634. this.merge( mesh.geometry, mesh.matrix );
  5635. },
  5636. /*
  5637. * Checks for duplicate vertices with hashmap.
  5638. * Duplicated vertices are removed
  5639. * and faces' vertices are updated.
  5640. */
  5641. mergeVertices: function () {
  5642. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5643. var unique = [], changes = [];
  5644. var v, key;
  5645. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5646. var precision = Math.pow( 10, precisionPoints );
  5647. var i, il, face;
  5648. var indices, j, jl;
  5649. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5650. v = this.vertices[ i ];
  5651. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5652. if ( verticesMap[ key ] === undefined ) {
  5653. verticesMap[ key ] = i;
  5654. unique.push( this.vertices[ i ] );
  5655. changes[ i ] = unique.length - 1;
  5656. } else {
  5657. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5658. changes[ i ] = changes[ verticesMap[ key ] ];
  5659. }
  5660. }
  5661. // if faces are completely degenerate after merging vertices, we
  5662. // have to remove them from the geometry.
  5663. var faceIndicesToRemove = [];
  5664. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5665. face = this.faces[ i ];
  5666. face.a = changes[ face.a ];
  5667. face.b = changes[ face.b ];
  5668. face.c = changes[ face.c ];
  5669. indices = [ face.a, face.b, face.c ];
  5670. var dupIndex = - 1;
  5671. // if any duplicate vertices are found in a Face3
  5672. // we have to remove the face as nothing can be saved
  5673. for ( var n = 0; n < 3; n ++ ) {
  5674. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5675. dupIndex = n;
  5676. faceIndicesToRemove.push( i );
  5677. break;
  5678. }
  5679. }
  5680. }
  5681. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5682. var idx = faceIndicesToRemove[ i ];
  5683. this.faces.splice( idx, 1 );
  5684. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5685. this.faceVertexUvs[ j ].splice( idx, 1 );
  5686. }
  5687. }
  5688. // Use unique set of vertices
  5689. var diff = this.vertices.length - unique.length;
  5690. this.vertices = unique;
  5691. return diff;
  5692. },
  5693. toJSON: function () {
  5694. var data = {
  5695. metadata: {
  5696. version: 4.4,
  5697. type: 'Geometry',
  5698. generator: 'Geometry.toJSON'
  5699. }
  5700. };
  5701. // standard Geometry serialization
  5702. data.uuid = this.uuid;
  5703. data.type = this.type;
  5704. if ( this.name !== '' ) data.name = this.name;
  5705. if ( this.parameters !== undefined ) {
  5706. var parameters = this.parameters;
  5707. for ( var key in parameters ) {
  5708. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5709. }
  5710. return data;
  5711. }
  5712. var vertices = [];
  5713. for ( var i = 0; i < this.vertices.length; i ++ ) {
  5714. var vertex = this.vertices[ i ];
  5715. vertices.push( vertex.x, vertex.y, vertex.z );
  5716. }
  5717. var faces = [];
  5718. var normals = [];
  5719. var normalsHash = {};
  5720. var colors = [];
  5721. var colorsHash = {};
  5722. var uvs = [];
  5723. var uvsHash = {};
  5724. for ( var i = 0; i < this.faces.length; i ++ ) {
  5725. var face = this.faces[ i ];
  5726. var hasMaterial = false; // face.materialIndex !== undefined;
  5727. var hasFaceUv = false; // deprecated
  5728. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  5729. var hasFaceNormal = face.normal.length() > 0;
  5730. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  5731. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  5732. var hasFaceVertexColor = face.vertexColors.length > 0;
  5733. var faceType = 0;
  5734. faceType = setBit( faceType, 0, 0 );
  5735. faceType = setBit( faceType, 1, hasMaterial );
  5736. faceType = setBit( faceType, 2, hasFaceUv );
  5737. faceType = setBit( faceType, 3, hasFaceVertexUv );
  5738. faceType = setBit( faceType, 4, hasFaceNormal );
  5739. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  5740. faceType = setBit( faceType, 6, hasFaceColor );
  5741. faceType = setBit( faceType, 7, hasFaceVertexColor );
  5742. faces.push( faceType );
  5743. faces.push( face.a, face.b, face.c );
  5744. if ( hasFaceVertexUv ) {
  5745. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  5746. faces.push(
  5747. getUvIndex( faceVertexUvs[ 0 ] ),
  5748. getUvIndex( faceVertexUvs[ 1 ] ),
  5749. getUvIndex( faceVertexUvs[ 2 ] )
  5750. );
  5751. }
  5752. if ( hasFaceNormal ) {
  5753. faces.push( getNormalIndex( face.normal ) );
  5754. }
  5755. if ( hasFaceVertexNormal ) {
  5756. var vertexNormals = face.vertexNormals;
  5757. faces.push(
  5758. getNormalIndex( vertexNormals[ 0 ] ),
  5759. getNormalIndex( vertexNormals[ 1 ] ),
  5760. getNormalIndex( vertexNormals[ 2 ] )
  5761. );
  5762. }
  5763. if ( hasFaceColor ) {
  5764. faces.push( getColorIndex( face.color ) );
  5765. }
  5766. if ( hasFaceVertexColor ) {
  5767. var vertexColors = face.vertexColors;
  5768. faces.push(
  5769. getColorIndex( vertexColors[ 0 ] ),
  5770. getColorIndex( vertexColors[ 1 ] ),
  5771. getColorIndex( vertexColors[ 2 ] )
  5772. );
  5773. }
  5774. }
  5775. function setBit( value, position, enabled ) {
  5776. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position) );
  5777. }
  5778. function getNormalIndex( normal ) {
  5779. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  5780. if ( normalsHash[ hash ] !== undefined ) {
  5781. return normalsHash[ hash ];
  5782. }
  5783. normalsHash[ hash ] = normals.length / 3;
  5784. normals.push( normal.x, normal.y, normal.z );
  5785. return normalsHash[ hash ];
  5786. }
  5787. function getColorIndex( color ) {
  5788. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  5789. if ( colorsHash[ hash ] !== undefined ) {
  5790. return colorsHash[ hash ];
  5791. }
  5792. colorsHash[ hash ] = colors.length;
  5793. colors.push( color.getHex() );
  5794. return colorsHash[ hash ];
  5795. }
  5796. function getUvIndex( uv ) {
  5797. var hash = uv.x.toString() + uv.y.toString();
  5798. if ( uvsHash[ hash ] !== undefined ) {
  5799. return uvsHash[ hash ];
  5800. }
  5801. uvsHash[ hash ] = uvs.length / 2;
  5802. uvs.push( uv.x, uv.y );
  5803. return uvsHash[ hash ];
  5804. }
  5805. data.data = {};
  5806. data.data.vertices = vertices;
  5807. data.data.normals = normals;
  5808. if ( colors.length > 0 ) data.data.colors = colors;
  5809. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  5810. data.data.faces = faces;
  5811. return data;
  5812. },
  5813. clone: function () {
  5814. var geometry = new THREE.Geometry();
  5815. var vertices = this.vertices;
  5816. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5817. geometry.vertices.push( vertices[ i ].clone() );
  5818. }
  5819. var faces = this.faces;
  5820. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  5821. geometry.faces.push( faces[ i ].clone() );
  5822. }
  5823. for ( var i = 0, il = this.faceVertexUvs.length; i < il; i ++ ) {
  5824. var faceVertexUvs = this.faceVertexUvs[ i ];
  5825. if ( geometry.faceVertexUvs[ i ] === undefined ) {
  5826. geometry.faceVertexUvs[ i ] = [];
  5827. }
  5828. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  5829. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  5830. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  5831. var uv = uvs[ k ];
  5832. uvsCopy.push( uv.clone() );
  5833. }
  5834. geometry.faceVertexUvs[ i ].push( uvsCopy );
  5835. }
  5836. }
  5837. return geometry;
  5838. },
  5839. dispose: function () {
  5840. this.dispatchEvent( { type: 'dispose' } );
  5841. },
  5842. // Backwards compatibility
  5843. set groupsNeedUpdate ( value ) {
  5844. if ( value === true ) this.dispose();
  5845. }
  5846. };
  5847. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  5848. THREE.GeometryIdCount = 0;
  5849. // File:src/core/DirectGeometry.js
  5850. /**
  5851. * @author mrdoob / http://mrdoob.com/
  5852. */
  5853. THREE.DirectGeometry = function () {
  5854. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5855. this.uuid = THREE.Math.generateUUID();
  5856. this.name = '';
  5857. this.type = 'DirectGeometry';
  5858. this.indices = [];
  5859. this.vertices = [];
  5860. this.colors = [];
  5861. this.normals = [];
  5862. this.colors = [];
  5863. this.uvs = [];
  5864. this.uvs2 = [];
  5865. this.tangents = [];
  5866. this.morphTargets = [];
  5867. this.morphColors = [];
  5868. this.morphNormals = [];
  5869. this.skinWeights = [];
  5870. this.skinIndices = [];
  5871. // this.lineDistances = [];
  5872. this.boundingBox = null;
  5873. this.boundingSphere = null;
  5874. // update flags
  5875. this.verticesNeedUpdate = false;
  5876. this.normalsNeedUpdate = false;
  5877. this.colorsNeedUpdate = false;
  5878. this.uvsNeedUpdate = false;
  5879. this.tangentsNeedUpdate = false;
  5880. };
  5881. THREE.DirectGeometry.prototype = {
  5882. constructor: THREE.DirectGeometry,
  5883. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  5884. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  5885. computeFaceNormals: function () {
  5886. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  5887. return this;
  5888. },
  5889. computeVertexNormals: function () {
  5890. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  5891. return this;
  5892. },
  5893. computeTangents: function () {
  5894. console.warn( 'THREE.DirectGeometry: computeTangents() is not a method of this type of geometry.' );
  5895. return this;
  5896. },
  5897. fromGeometry: function ( geometry ) {
  5898. var faces = geometry.faces;
  5899. var vertices = geometry.vertices;
  5900. var faceVertexUvs = geometry.faceVertexUvs;
  5901. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  5902. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  5903. var hasTangents = geometry.hasTangents;
  5904. // morphs
  5905. var morphTargets = geometry.morphTargets;
  5906. var morphTargetsLength = morphTargets.length;
  5907. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  5908. this.morphTargets[ i ] = [];
  5909. }
  5910. var morphNormals = geometry.morphNormals;
  5911. var morphNormalsLength = morphNormals.length;
  5912. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  5913. this.morphNormals[ i ] = [];
  5914. }
  5915. var morphColors = geometry.morphColors;
  5916. var morphColorsLength = morphColors.length;
  5917. for ( var i = 0; i < morphColorsLength; i ++ ) {
  5918. this.morphColors[ i ] = [];
  5919. }
  5920. // skins
  5921. var skinIndices = geometry.skinIndices;
  5922. var skinWeights = geometry.skinWeights;
  5923. var hasSkinIndices = skinIndices.length === vertices.length;
  5924. var hasSkinWeights = skinWeights.length === vertices.length;
  5925. //
  5926. for ( var i = 0; i < faces.length; i ++ ) {
  5927. var face = faces[ i ];
  5928. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  5929. var vertexNormals = face.vertexNormals;
  5930. if ( vertexNormals.length === 3 ) {
  5931. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  5932. } else {
  5933. var normal = face.normal;
  5934. this.normals.push( normal, normal, normal );
  5935. }
  5936. var vertexColors = face.vertexColors;
  5937. if ( vertexColors.length === 3 ) {
  5938. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  5939. } else {
  5940. var color = face.color;
  5941. this.colors.push( color, color, color );
  5942. }
  5943. if ( hasFaceVertexUv === true ) {
  5944. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  5945. if ( vertexUvs !== undefined ) {
  5946. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5947. } else {
  5948. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  5949. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  5950. }
  5951. }
  5952. if ( hasFaceVertexUv2 === true ) {
  5953. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  5954. if ( vertexUvs !== undefined ) {
  5955. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5956. } else {
  5957. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  5958. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  5959. }
  5960. }
  5961. if ( hasTangents === true ) {
  5962. var vertexTangents = face.vertexTangents;
  5963. if ( vertexTangents.length === 3 ) {
  5964. this.tangents.push( vertexTangents[ 0 ], vertexTangents[ 1 ], vertexTangents[ 2 ] );
  5965. } else {
  5966. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined tangents ', i );
  5967. this.tangents.push( new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4() );
  5968. }
  5969. }
  5970. // morphs
  5971. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  5972. var morphTarget = morphTargets[ j ].vertices;
  5973. this.morphTargets[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  5974. }
  5975. /*
  5976. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  5977. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  5978. this.morphNormals[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  5979. }
  5980. for ( var j = 0; j < morphColorsLength; j ++ ) {
  5981. var morphColor = morphColors[ j ].colors;
  5982. this.morphColors[ j ].push( morphColor[ face.a ], morphColor[ face.b ], morphColor[ face.c ] );
  5983. }
  5984. */
  5985. // skins
  5986. if ( hasSkinIndices ) {
  5987. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  5988. }
  5989. if ( hasSkinWeights ) {
  5990. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  5991. }
  5992. }
  5993. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  5994. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  5995. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  5996. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  5997. this.tangentsNeedUpdate = geometry.tangentsNeedUpdate;
  5998. return this;
  5999. },
  6000. dispose: function () {
  6001. this.dispatchEvent( { type: 'dispose' } );
  6002. }
  6003. };
  6004. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6005. // File:src/core/BufferGeometry.js
  6006. /**
  6007. * @author alteredq / http://alteredqualia.com/
  6008. * @author mrdoob / http://mrdoob.com/
  6009. */
  6010. THREE.BufferGeometry = function () {
  6011. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6012. this.uuid = THREE.Math.generateUUID();
  6013. this.name = '';
  6014. this.type = 'BufferGeometry';
  6015. this.attributes = {};
  6016. this.morphAttributes = [];
  6017. this.drawcalls = [];
  6018. this.offsets = this.drawcalls; // backwards compatibility
  6019. this.boundingBox = null;
  6020. this.boundingSphere = null;
  6021. };
  6022. THREE.BufferGeometry.prototype = {
  6023. constructor: THREE.BufferGeometry,
  6024. addAttribute: function ( name, attribute ) {
  6025. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6026. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6027. this.attributes[ name ] = { array: arguments[ 1 ], itemSize: arguments[ 2 ] };
  6028. return;
  6029. }
  6030. this.attributes[ name ] = attribute;
  6031. },
  6032. getAttribute: function ( name ) {
  6033. return this.attributes[ name ];
  6034. },
  6035. addDrawCall: function ( start, count, indexOffset ) {
  6036. this.drawcalls.push( {
  6037. start: start,
  6038. count: count,
  6039. index: indexOffset !== undefined ? indexOffset : 0
  6040. } );
  6041. },
  6042. applyMatrix: function ( matrix ) {
  6043. var position = this.attributes.position;
  6044. if ( position !== undefined ) {
  6045. matrix.applyToVector3Array( position.array );
  6046. position.needsUpdate = true;
  6047. }
  6048. var normal = this.attributes.normal;
  6049. if ( normal !== undefined ) {
  6050. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6051. normalMatrix.applyToVector3Array( normal.array );
  6052. normal.needsUpdate = true;
  6053. }
  6054. if ( this.boundingBox !== null ) {
  6055. this.computeBoundingBox();
  6056. }
  6057. if ( this.boundingSphere !== null ) {
  6058. this.computeBoundingSphere();
  6059. }
  6060. },
  6061. copy: function ( geometry ) {
  6062. var attributes = geometry.attributes;
  6063. var offsets = geometry.offsets;
  6064. for ( var name in attributes ) {
  6065. var attribute = attributes[ name ];
  6066. this.addAttribute( name, attribute.clone() );
  6067. }
  6068. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  6069. var offset = offsets[ i ];
  6070. this.offsets.push( {
  6071. start: offset.start,
  6072. index: offset.index,
  6073. count: offset.count
  6074. } );
  6075. }
  6076. return this;
  6077. },
  6078. center: function () {
  6079. this.computeBoundingBox();
  6080. var offset = this.boundingBox.center().negate();
  6081. this.applyMatrix( new THREE.Matrix4().setPosition( offset ) );
  6082. return offset;
  6083. },
  6084. setFromObject: function ( object ) {
  6085. console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6086. var geometry = object.geometry;
  6087. var material = object.material;
  6088. if ( object instanceof THREE.PointCloud || object instanceof THREE.Line ) {
  6089. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6090. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6091. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6092. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6093. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6094. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6095. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6096. }
  6097. if ( geometry.boundingSphere !== null ) {
  6098. this.boundingSphere = geometry.boundingSphere.clone();
  6099. }
  6100. if ( geometry.boundingBox !== null ) {
  6101. this.boundingBox = geometry.boundingBox.clone();
  6102. }
  6103. } else if ( object instanceof THREE.Mesh ) {
  6104. if ( geometry instanceof THREE.Geometry ) {
  6105. this.fromGeometry( geometry );
  6106. }
  6107. }
  6108. return this;
  6109. },
  6110. updateFromObject: function ( object ) {
  6111. var geometry = object.geometry;
  6112. if ( object instanceof THREE.Mesh ) {
  6113. var direct = geometry.__directGeometry;
  6114. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6115. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6116. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6117. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6118. direct.tangentsNeedUpdate = geometry.tangentsNeedUpdate;
  6119. geometry.verticesNeedUpdate = false;
  6120. geometry.normalsNeedUpdate = false;
  6121. geometry.colorsNeedUpdate = false;
  6122. geometry.uvsNeedUpdate = false;
  6123. geometry.tangentsNeedUpdate = false;
  6124. geometry = direct;
  6125. }
  6126. if ( geometry.verticesNeedUpdate === true ) {
  6127. var attribute = this.attributes.position;
  6128. if ( attribute !== undefined ) {
  6129. attribute.copyVector3sArray( geometry.vertices );
  6130. attribute.needsUpdate = true;
  6131. }
  6132. geometry.verticesNeedUpdate = false;
  6133. }
  6134. if ( geometry.normalsNeedUpdate === true ) {
  6135. var attribute = this.attributes.normal;
  6136. if ( attribute !== undefined ) {
  6137. attribute.copyVector3sArray( geometry.normals );
  6138. attribute.needsUpdate = true;
  6139. }
  6140. geometry.normalsNeedUpdate = false;
  6141. }
  6142. if ( geometry.colorsNeedUpdate === true ) {
  6143. var attribute = this.attributes.color;
  6144. if ( attribute !== undefined ) {
  6145. attribute.copyColorsArray( geometry.colors );
  6146. attribute.needsUpdate = true;
  6147. }
  6148. geometry.colorsNeedUpdate = false;
  6149. }
  6150. if ( geometry.tangentsNeedUpdate === true ) {
  6151. var attribute = this.attributes.tangent;
  6152. if ( attribute !== undefined ) {
  6153. attribute.copyVector4sArray( geometry.tangents );
  6154. attribute.needsUpdate = true;
  6155. }
  6156. geometry.tangentsNeedUpdate = false;
  6157. }
  6158. if ( geometry.lineDistancesNeedUpdate ) {
  6159. var attribute = this.attributes.lineDistance;
  6160. if ( attribute !== undefined ) {
  6161. attribute.copyArray( geometry.lineDistances );
  6162. attribute.needsUpdate = true;
  6163. }
  6164. geometry.lineDistancesNeedUpdate = false;
  6165. }
  6166. return this;
  6167. },
  6168. fromGeometry: function ( geometry ) {
  6169. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6170. return this.fromDirectGeometry( geometry.__directGeometry );
  6171. },
  6172. fromDirectGeometry: function ( geometry ) {
  6173. var positions = new Float32Array( geometry.vertices.length * 3 );
  6174. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6175. if ( geometry.normals.length > 0 ) {
  6176. var normals = new Float32Array( geometry.normals.length * 3 );
  6177. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6178. }
  6179. if ( geometry.colors.length > 0 ) {
  6180. var colors = new Float32Array( geometry.colors.length * 3 );
  6181. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6182. }
  6183. if ( geometry.uvs.length > 0 ) {
  6184. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6185. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6186. }
  6187. if ( geometry.uvs2.length > 0 ) {
  6188. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6189. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6190. }
  6191. if ( geometry.tangents.length > 0 ) {
  6192. var tangents = new Float32Array( geometry.tangents.length * 4 );
  6193. this.addAttribute( 'tangent', new THREE.BufferAttribute( tangents, 4 ).copyVector4sArray( geometry.tangents ) );
  6194. }
  6195. if ( geometry.indices.length > 0 ) {
  6196. var indices = new Uint16Array( geometry.indices.length * 3 );
  6197. this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6198. }
  6199. // morphs
  6200. if ( geometry.morphTargets.length > 0 ) {
  6201. var morphTargets = geometry.morphTargets;
  6202. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6203. var morphTarget = morphTargets[ i ];
  6204. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6205. this.morphAttributes.push( attribute.copyVector3sArray( morphTarget ) );
  6206. }
  6207. // TODO normals, colors
  6208. }
  6209. // skinning
  6210. if ( geometry.skinIndices.length > 0 ) {
  6211. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6212. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6213. }
  6214. if ( geometry.skinWeights.length > 0 ) {
  6215. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6216. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6217. }
  6218. //
  6219. if ( geometry.boundingSphere !== null ) {
  6220. this.boundingSphere = geometry.boundingSphere.clone();
  6221. }
  6222. if ( geometry.boundingBox !== null ) {
  6223. this.boundingBox = geometry.boundingBox.clone();
  6224. }
  6225. return this;
  6226. },
  6227. computeBoundingBox: function () {
  6228. var vector = new THREE.Vector3();
  6229. return function () {
  6230. if ( this.boundingBox === null ) {
  6231. this.boundingBox = new THREE.Box3();
  6232. }
  6233. var positions = this.attributes.position.array;
  6234. if ( positions ) {
  6235. var bb = this.boundingBox;
  6236. bb.makeEmpty();
  6237. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6238. vector.fromArray( positions, i );
  6239. bb.expandByPoint( vector );
  6240. }
  6241. }
  6242. if ( positions === undefined || positions.length === 0 ) {
  6243. this.boundingBox.min.set( 0, 0, 0 );
  6244. this.boundingBox.max.set( 0, 0, 0 );
  6245. }
  6246. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6247. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6248. }
  6249. };
  6250. }(),
  6251. computeBoundingSphere: function () {
  6252. var box = new THREE.Box3();
  6253. var vector = new THREE.Vector3();
  6254. return function () {
  6255. if ( this.boundingSphere === null ) {
  6256. this.boundingSphere = new THREE.Sphere();
  6257. }
  6258. var positions = this.attributes.position.array;
  6259. if ( positions ) {
  6260. box.makeEmpty();
  6261. var center = this.boundingSphere.center;
  6262. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6263. vector.fromArray( positions, i );
  6264. box.expandByPoint( vector );
  6265. }
  6266. box.center( center );
  6267. // hoping to find a boundingSphere with a radius smaller than the
  6268. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6269. var maxRadiusSq = 0;
  6270. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6271. vector.fromArray( positions, i );
  6272. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6273. }
  6274. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6275. if ( isNaN( this.boundingSphere.radius ) ) {
  6276. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6277. }
  6278. }
  6279. };
  6280. }(),
  6281. computeFaceNormals: function () {
  6282. // backwards compatibility
  6283. },
  6284. computeVertexNormals: function () {
  6285. var attributes = this.attributes;
  6286. if ( attributes.position ) {
  6287. var positions = attributes.position.array;
  6288. if ( attributes.normal === undefined ) {
  6289. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6290. } else {
  6291. // reset existing normals to zero
  6292. var normals = attributes.normal.array;
  6293. for ( var i = 0, il = normals.length; i < il; i ++ ) {
  6294. normals[ i ] = 0;
  6295. }
  6296. }
  6297. var normals = attributes.normal.array;
  6298. var vA, vB, vC,
  6299. pA = new THREE.Vector3(),
  6300. pB = new THREE.Vector3(),
  6301. pC = new THREE.Vector3(),
  6302. cb = new THREE.Vector3(),
  6303. ab = new THREE.Vector3();
  6304. // indexed elements
  6305. if ( attributes.index ) {
  6306. var indices = attributes.index.array;
  6307. var offsets = ( this.offsets.length > 0 ? this.offsets : [ { start: 0, count: indices.length, index: 0 } ] );
  6308. for ( var j = 0, jl = offsets.length; j < jl; ++ j ) {
  6309. var start = offsets[ j ].start;
  6310. var count = offsets[ j ].count;
  6311. var index = offsets[ j ].index;
  6312. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6313. vA = ( index + indices[ i ] ) * 3;
  6314. vB = ( index + indices[ i + 1 ] ) * 3;
  6315. vC = ( index + indices[ i + 2 ] ) * 3;
  6316. pA.fromArray( positions, vA );
  6317. pB.fromArray( positions, vB );
  6318. pC.fromArray( positions, vC );
  6319. cb.subVectors( pC, pB );
  6320. ab.subVectors( pA, pB );
  6321. cb.cross( ab );
  6322. normals[ vA ] += cb.x;
  6323. normals[ vA + 1 ] += cb.y;
  6324. normals[ vA + 2 ] += cb.z;
  6325. normals[ vB ] += cb.x;
  6326. normals[ vB + 1 ] += cb.y;
  6327. normals[ vB + 2 ] += cb.z;
  6328. normals[ vC ] += cb.x;
  6329. normals[ vC + 1 ] += cb.y;
  6330. normals[ vC + 2 ] += cb.z;
  6331. }
  6332. }
  6333. } else {
  6334. // non-indexed elements (unconnected triangle soup)
  6335. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6336. pA.fromArray( positions, i );
  6337. pB.fromArray( positions, i + 3 );
  6338. pC.fromArray( positions, i + 6 );
  6339. cb.subVectors( pC, pB );
  6340. ab.subVectors( pA, pB );
  6341. cb.cross( ab );
  6342. normals[ i ] = cb.x;
  6343. normals[ i + 1 ] = cb.y;
  6344. normals[ i + 2 ] = cb.z;
  6345. normals[ i + 3 ] = cb.x;
  6346. normals[ i + 4 ] = cb.y;
  6347. normals[ i + 5 ] = cb.z;
  6348. normals[ i + 6 ] = cb.x;
  6349. normals[ i + 7 ] = cb.y;
  6350. normals[ i + 8 ] = cb.z;
  6351. }
  6352. }
  6353. this.normalizeNormals();
  6354. attributes.normal.needsUpdate = true;
  6355. }
  6356. },
  6357. computeTangents: function () {
  6358. // based on http://www.terathon.com/code/tangent.html
  6359. // (per vertex tangents)
  6360. if ( this.attributes.index === undefined ||
  6361. this.attributes.position === undefined ||
  6362. this.attributes.normal === undefined ||
  6363. this.attributes.uv === undefined ) {
  6364. console.warn( 'THREE.BufferGeometry: Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()' );
  6365. return;
  6366. }
  6367. var indices = this.attributes.index.array;
  6368. var positions = this.attributes.position.array;
  6369. var normals = this.attributes.normal.array;
  6370. var uvs = this.attributes.uv.array;
  6371. var nVertices = positions.length / 3;
  6372. if ( this.attributes.tangent === undefined ) {
  6373. this.addAttribute( 'tangent', new THREE.BufferAttribute( new Float32Array( 4 * nVertices ), 4 ) );
  6374. }
  6375. var tangents = this.attributes.tangent.array;
  6376. var tan1 = [], tan2 = [];
  6377. for ( var k = 0; k < nVertices; k ++ ) {
  6378. tan1[ k ] = new THREE.Vector3();
  6379. tan2[ k ] = new THREE.Vector3();
  6380. }
  6381. var vA = new THREE.Vector3(),
  6382. vB = new THREE.Vector3(),
  6383. vC = new THREE.Vector3(),
  6384. uvA = new THREE.Vector2(),
  6385. uvB = new THREE.Vector2(),
  6386. uvC = new THREE.Vector2(),
  6387. x1, x2, y1, y2, z1, z2,
  6388. s1, s2, t1, t2, r;
  6389. var sdir = new THREE.Vector3(), tdir = new THREE.Vector3();
  6390. function handleTriangle( a, b, c ) {
  6391. vA.fromArray( positions, a * 3 );
  6392. vB.fromArray( positions, b * 3 );
  6393. vC.fromArray( positions, c * 3 );
  6394. uvA.fromArray( uvs, a * 2 );
  6395. uvB.fromArray( uvs, b * 2 );
  6396. uvC.fromArray( uvs, c * 2 );
  6397. x1 = vB.x - vA.x;
  6398. x2 = vC.x - vA.x;
  6399. y1 = vB.y - vA.y;
  6400. y2 = vC.y - vA.y;
  6401. z1 = vB.z - vA.z;
  6402. z2 = vC.z - vA.z;
  6403. s1 = uvB.x - uvA.x;
  6404. s2 = uvC.x - uvA.x;
  6405. t1 = uvB.y - uvA.y;
  6406. t2 = uvC.y - uvA.y;
  6407. r = 1.0 / ( s1 * t2 - s2 * t1 );
  6408. sdir.set(
  6409. ( t2 * x1 - t1 * x2 ) * r,
  6410. ( t2 * y1 - t1 * y2 ) * r,
  6411. ( t2 * z1 - t1 * z2 ) * r
  6412. );
  6413. tdir.set(
  6414. ( s1 * x2 - s2 * x1 ) * r,
  6415. ( s1 * y2 - s2 * y1 ) * r,
  6416. ( s1 * z2 - s2 * z1 ) * r
  6417. );
  6418. tan1[ a ].add( sdir );
  6419. tan1[ b ].add( sdir );
  6420. tan1[ c ].add( sdir );
  6421. tan2[ a ].add( tdir );
  6422. tan2[ b ].add( tdir );
  6423. tan2[ c ].add( tdir );
  6424. }
  6425. var i, il;
  6426. var j, jl;
  6427. var iA, iB, iC;
  6428. if ( this.drawcalls.length === 0 ) {
  6429. this.addDrawCall( 0, indices.length, 0 );
  6430. }
  6431. var drawcalls = this.drawcalls;
  6432. for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
  6433. var start = drawcalls[ j ].start;
  6434. var count = drawcalls[ j ].count;
  6435. var index = drawcalls[ j ].index;
  6436. for ( i = start, il = start + count; i < il; i += 3 ) {
  6437. iA = index + indices[ i ];
  6438. iB = index + indices[ i + 1 ];
  6439. iC = index + indices[ i + 2 ];
  6440. handleTriangle( iA, iB, iC );
  6441. }
  6442. }
  6443. var tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3();
  6444. var n = new THREE.Vector3(), n2 = new THREE.Vector3();
  6445. var w, t, test;
  6446. function handleVertex( v ) {
  6447. n.fromArray( normals, v * 3 );
  6448. n2.copy( n );
  6449. t = tan1[ v ];
  6450. // Gram-Schmidt orthogonalize
  6451. tmp.copy( t );
  6452. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  6453. // Calculate handedness
  6454. tmp2.crossVectors( n2, t );
  6455. test = tmp2.dot( tan2[ v ] );
  6456. w = ( test < 0.0 ) ? - 1.0 : 1.0;
  6457. tangents[ v * 4 ] = tmp.x;
  6458. tangents[ v * 4 + 1 ] = tmp.y;
  6459. tangents[ v * 4 + 2 ] = tmp.z;
  6460. tangents[ v * 4 + 3 ] = w;
  6461. }
  6462. for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
  6463. var start = drawcalls[ j ].start;
  6464. var count = drawcalls[ j ].count;
  6465. var index = drawcalls[ j ].index;
  6466. for ( i = start, il = start + count; i < il; i += 3 ) {
  6467. iA = index + indices[ i ];
  6468. iB = index + indices[ i + 1 ];
  6469. iC = index + indices[ i + 2 ];
  6470. handleVertex( iA );
  6471. handleVertex( iB );
  6472. handleVertex( iC );
  6473. }
  6474. }
  6475. },
  6476. /*
  6477. Compute the draw offset for large models by chunking the index buffer into chunks of 65k addressable vertices.
  6478. This method will effectively rewrite the index buffer and remap all attributes to match the new indices.
  6479. WARNING: This method will also expand the vertex count to prevent sprawled triangles across draw offsets.
  6480. size - Defaults to 65535 or 4294967296 if extension OES_element_index_uint supported, but allows for larger or smaller chunks.
  6481. */
  6482. computeOffsets: function ( size ) {
  6483. if ( size === undefined ) size = THREE.BufferGeometry.MaxIndex;
  6484. var indices = this.attributes.index.array;
  6485. var vertices = this.attributes.position.array;
  6486. var facesCount = ( indices.length / 3 );
  6487. var UintArray = ( ( vertices.length / 3 ) > 65535 && THREE.BufferGeometry.MaxIndex > 65535 ) ? Uint32Array : Uint16Array;
  6488. /*
  6489. console.log("Computing buffers in offsets of "+size+" -> indices:"+indices.length+" vertices:"+vertices.length);
  6490. console.log("Faces to process: "+(indices.length/3));
  6491. console.log("Reordering "+verticesCount+" vertices.");
  6492. */
  6493. var sortedIndices = new UintArray( indices.length );
  6494. var indexPtr = 0;
  6495. var vertexPtr = 0;
  6496. var offsets = [ { start:0, count:0, index:0 } ];
  6497. var offset = offsets[ 0 ];
  6498. var duplicatedVertices = 0;
  6499. var newVerticeMaps = 0;
  6500. var faceVertices = new Int32Array( 6 );
  6501. var vertexMap = new Int32Array( vertices.length );
  6502. var revVertexMap = new Int32Array( vertices.length );
  6503. for ( var j = 0; j < vertices.length; j ++ ) { vertexMap[ j ] = - 1; revVertexMap[ j ] = - 1; }
  6504. /*
  6505. Traverse every face and reorder vertices in the proper offsets of 65k.
  6506. We can have more than 'size' entries in the index buffer per offset, but only reference 'size' values.
  6507. */
  6508. for ( var findex = 0; findex < facesCount; findex ++ ) {
  6509. newVerticeMaps = 0;
  6510. for ( var vo = 0; vo < 3; vo ++ ) {
  6511. var vid = indices[ findex * 3 + vo ];
  6512. if ( vertexMap[ vid ] === - 1 ) {
  6513. //Unmapped vertex
  6514. faceVertices[ vo * 2 ] = vid;
  6515. faceVertices[ vo * 2 + 1 ] = - 1;
  6516. newVerticeMaps ++;
  6517. } else if ( vertexMap[ vid ] < offset.index ) {
  6518. //Reused vertices from previous block (duplicate)
  6519. faceVertices[ vo * 2 ] = vid;
  6520. faceVertices[ vo * 2 + 1 ] = - 1;
  6521. duplicatedVertices ++;
  6522. } else {
  6523. //Reused vertex in the current block
  6524. faceVertices[ vo * 2 ] = vid;
  6525. faceVertices[ vo * 2 + 1 ] = vertexMap[ vid ];
  6526. }
  6527. }
  6528. var faceMax = vertexPtr + newVerticeMaps;
  6529. if ( faceMax > ( offset.index + size ) ) {
  6530. var new_offset = { start:indexPtr, count:0, index:vertexPtr };
  6531. offsets.push( new_offset );
  6532. offset = new_offset;
  6533. //Re-evaluate reused vertices in light of new offset.
  6534. for ( var v = 0; v < 6; v += 2 ) {
  6535. var new_vid = faceVertices[ v + 1 ];
  6536. if ( new_vid > - 1 && new_vid < offset.index )
  6537. faceVertices[ v + 1 ] = - 1;
  6538. }
  6539. }
  6540. //Reindex the face.
  6541. for ( var v = 0; v < 6; v += 2 ) {
  6542. var vid = faceVertices[ v ];
  6543. var new_vid = faceVertices[ v + 1 ];
  6544. if ( new_vid === - 1 )
  6545. new_vid = vertexPtr ++;
  6546. vertexMap[ vid ] = new_vid;
  6547. revVertexMap[ new_vid ] = vid;
  6548. sortedIndices[ indexPtr ++ ] = new_vid - offset.index; //XXX overflows at 16bit
  6549. offset.count ++;
  6550. }
  6551. }
  6552. /* Move all attribute values to map to the new computed indices , also expand the vertex stack to match our new vertexPtr. */
  6553. this.reorderBuffers( sortedIndices, revVertexMap, vertexPtr );
  6554. this.offsets = offsets; // TODO: Deprecate
  6555. this.drawcalls = offsets;
  6556. /*
  6557. var orderTime = Date.now();
  6558. console.log("Reorder time: "+(orderTime-s)+"ms");
  6559. console.log("Duplicated "+duplicatedVertices+" vertices.");
  6560. console.log("Compute Buffers time: "+(Date.now()-s)+"ms");
  6561. console.log("Draw offsets: "+offsets.length);
  6562. */
  6563. return offsets;
  6564. },
  6565. merge: function ( geometry, offset ) {
  6566. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6567. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6568. return;
  6569. }
  6570. if ( offset === undefined ) offset = 0;
  6571. var attributes = this.attributes;
  6572. for ( var key in attributes ) {
  6573. if ( geometry.attributes[ key ] === undefined ) continue;
  6574. var attribute1 = attributes[ key ];
  6575. var attributeArray1 = attribute1.array;
  6576. var attribute2 = geometry.attributes[ key ];
  6577. var attributeArray2 = attribute2.array;
  6578. var attributeSize = attribute2.itemSize;
  6579. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6580. attributeArray1[ j ] = attributeArray2[ i ];
  6581. }
  6582. }
  6583. return this;
  6584. },
  6585. normalizeNormals: function () {
  6586. var normals = this.attributes.normal.array;
  6587. var x, y, z, n;
  6588. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6589. x = normals[ i ];
  6590. y = normals[ i + 1 ];
  6591. z = normals[ i + 2 ];
  6592. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6593. normals[ i ] *= n;
  6594. normals[ i + 1 ] *= n;
  6595. normals[ i + 2 ] *= n;
  6596. }
  6597. },
  6598. /*
  6599. reoderBuffers:
  6600. Reorder attributes based on a new indexBuffer and indexMap.
  6601. indexBuffer - Uint16Array of the new ordered indices.
  6602. indexMap - Int32Array where the position is the new vertex ID and the value the old vertex ID for each vertex.
  6603. vertexCount - Amount of total vertices considered in this reordering (in case you want to grow the vertex stack).
  6604. */
  6605. reorderBuffers: function ( indexBuffer, indexMap, vertexCount ) {
  6606. /* Create a copy of all attributes for reordering. */
  6607. var sortedAttributes = {};
  6608. for ( var attr in this.attributes ) {
  6609. if ( attr === 'index' )
  6610. continue;
  6611. var sourceArray = this.attributes[ attr ].array;
  6612. sortedAttributes[ attr ] = new sourceArray.constructor( this.attributes[ attr ].itemSize * vertexCount );
  6613. }
  6614. /* Move attribute positions based on the new index map */
  6615. for ( var new_vid = 0; new_vid < vertexCount; new_vid ++ ) {
  6616. var vid = indexMap[ new_vid ];
  6617. for ( var attr in this.attributes ) {
  6618. if ( attr === 'index' )
  6619. continue;
  6620. var attrArray = this.attributes[ attr ].array;
  6621. var attrSize = this.attributes[ attr ].itemSize;
  6622. var sortedAttr = sortedAttributes[ attr ];
  6623. for ( var k = 0; k < attrSize; k ++ )
  6624. sortedAttr[ new_vid * attrSize + k ] = attrArray[ vid * attrSize + k ];
  6625. }
  6626. }
  6627. /* Carry the new sorted buffers locally */
  6628. this.attributes[ 'index' ].array = indexBuffer;
  6629. for ( var attr in this.attributes ) {
  6630. if ( attr === 'index' )
  6631. continue;
  6632. this.attributes[ attr ].array = sortedAttributes[ attr ];
  6633. this.attributes[ attr ].numItems = this.attributes[ attr ].itemSize * vertexCount;
  6634. }
  6635. },
  6636. toJSON: function () {
  6637. var data = {
  6638. metadata: {
  6639. version: 4.4,
  6640. type: 'BufferGeometry',
  6641. generator: 'BufferGeometry.toJSON'
  6642. }
  6643. };
  6644. // standard BufferGeometry serialization
  6645. data.uuid = this.uuid;
  6646. data.type = this.type;
  6647. if ( this.name !== '' ) data.name = this.name;
  6648. if ( this.parameters !== undefined ) {
  6649. var parameters = this.parameters;
  6650. for ( var key in parameters ) {
  6651. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6652. }
  6653. return data;
  6654. }
  6655. data.data = { attributes: {} };
  6656. var attributes = this.attributes;
  6657. var offsets = this.offsets;
  6658. var boundingSphere = this.boundingSphere;
  6659. for ( var key in attributes ) {
  6660. var attribute = attributes[ key ];
  6661. var array = Array.prototype.slice.call( attribute.array );
  6662. data.data.attributes[ key ] = {
  6663. itemSize: attribute.itemSize,
  6664. type: attribute.array.constructor.name,
  6665. array: array
  6666. }
  6667. }
  6668. if ( offsets.length > 0 ) {
  6669. data.data.offsets = JSON.parse( JSON.stringify( offsets ) );
  6670. }
  6671. if ( boundingSphere !== null ) {
  6672. data.data.boundingSphere = {
  6673. center: boundingSphere.center.toArray(),
  6674. radius: boundingSphere.radius
  6675. }
  6676. }
  6677. return data;
  6678. },
  6679. clone: function () {
  6680. var geometry = new THREE.BufferGeometry();
  6681. for ( var attr in this.attributes ) {
  6682. var sourceAttr = this.attributes[ attr ];
  6683. geometry.addAttribute( attr, sourceAttr.clone() );
  6684. }
  6685. for ( var i = 0, il = this.offsets.length; i < il; i ++ ) {
  6686. var offset = this.offsets[ i ];
  6687. geometry.offsets.push( {
  6688. start: offset.start,
  6689. index: offset.index,
  6690. count: offset.count
  6691. } );
  6692. }
  6693. return geometry;
  6694. },
  6695. dispose: function () {
  6696. this.dispatchEvent( { type: 'dispose' } );
  6697. }
  6698. };
  6699. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  6700. THREE.BufferGeometry.MaxIndex = 65535;
  6701. // File:src/core/InstancedBufferGeometry.js
  6702. /**
  6703. * @author benaadams / https://twitter.com/ben_a_adams
  6704. */
  6705. THREE.InstancedBufferGeometry = function () {
  6706. THREE.BufferGeometry.call( this );
  6707. this.type = 'InstancedBufferGeometry';
  6708. this.maxInstancedCount = undefined;
  6709. };
  6710. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  6711. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  6712. THREE.InstancedBufferGeometry.prototype.addDrawCall = function ( start, count, indexOffset, instances ) {
  6713. this.drawcalls.push( {
  6714. start: start,
  6715. count: count,
  6716. index: indexOffset !== undefined ? indexOffset : 0,
  6717. instances: instances
  6718. } );
  6719. },
  6720. THREE.InstancedBufferGeometry.prototype.clone = function () {
  6721. var geometry = new THREE.InstancedBufferGeometry();
  6722. for ( var attr in this.attributes ) {
  6723. var sourceAttr = this.attributes[attr];
  6724. geometry.addAttribute( attr, sourceAttr.clone() );
  6725. }
  6726. for ( var i = 0, il = this.offsets.length; i < il; i++ ) {
  6727. var offset = this.offsets[i];
  6728. geometry.offsets.push( {
  6729. start: offset.start,
  6730. index: offset.index,
  6731. count: offset.count,
  6732. instances: offset.instances
  6733. } );
  6734. }
  6735. return geometry;
  6736. };
  6737. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  6738. // File:src/cameras/Camera.js
  6739. /**
  6740. * @author mrdoob / http://mrdoob.com/
  6741. * @author mikael emtinger / http://gomo.se/
  6742. * @author WestLangley / http://github.com/WestLangley
  6743. */
  6744. THREE.Camera = function () {
  6745. THREE.Object3D.call( this );
  6746. this.type = 'Camera';
  6747. this.matrixWorldInverse = new THREE.Matrix4();
  6748. this.projectionMatrix = new THREE.Matrix4();
  6749. };
  6750. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  6751. THREE.Camera.prototype.constructor = THREE.Camera;
  6752. THREE.Camera.prototype.getWorldDirection = function () {
  6753. var quaternion = new THREE.Quaternion();
  6754. return function ( optionalTarget ) {
  6755. var result = optionalTarget || new THREE.Vector3();
  6756. this.getWorldQuaternion( quaternion );
  6757. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  6758. };
  6759. }();
  6760. THREE.Camera.prototype.lookAt = function () {
  6761. // This routine does not support cameras with rotated and/or translated parent(s)
  6762. var m1 = new THREE.Matrix4();
  6763. return function ( vector ) {
  6764. m1.lookAt( this.position, vector, this.up );
  6765. this.quaternion.setFromRotationMatrix( m1 );
  6766. };
  6767. }();
  6768. THREE.Camera.prototype.clone = function ( camera ) {
  6769. if ( camera === undefined ) camera = new THREE.Camera();
  6770. THREE.Object3D.prototype.clone.call( this, camera );
  6771. camera.matrixWorldInverse.copy( this.matrixWorldInverse );
  6772. camera.projectionMatrix.copy( this.projectionMatrix );
  6773. return camera;
  6774. };
  6775. // File:src/cameras/CubeCamera.js
  6776. /**
  6777. * Camera for rendering cube maps
  6778. * - renders scene into axis-aligned cube
  6779. *
  6780. * @author alteredq / http://alteredqualia.com/
  6781. */
  6782. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  6783. THREE.Object3D.call( this );
  6784. this.type = 'CubeCamera';
  6785. var fov = 90, aspect = 1;
  6786. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6787. cameraPX.up.set( 0, - 1, 0 );
  6788. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  6789. this.add( cameraPX );
  6790. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6791. cameraNX.up.set( 0, - 1, 0 );
  6792. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  6793. this.add( cameraNX );
  6794. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6795. cameraPY.up.set( 0, 0, 1 );
  6796. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  6797. this.add( cameraPY );
  6798. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6799. cameraNY.up.set( 0, 0, - 1 );
  6800. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  6801. this.add( cameraNY );
  6802. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6803. cameraPZ.up.set( 0, - 1, 0 );
  6804. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  6805. this.add( cameraPZ );
  6806. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6807. cameraNZ.up.set( 0, - 1, 0 );
  6808. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  6809. this.add( cameraNZ );
  6810. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  6811. this.updateCubeMap = function ( renderer, scene ) {
  6812. if ( this.parent === undefined ) this.updateMatrixWorld();
  6813. var renderTarget = this.renderTarget;
  6814. var generateMipmaps = renderTarget.generateMipmaps;
  6815. renderTarget.generateMipmaps = false;
  6816. renderTarget.activeCubeFace = 0;
  6817. renderer.render( scene, cameraPX, renderTarget );
  6818. renderTarget.activeCubeFace = 1;
  6819. renderer.render( scene, cameraNX, renderTarget );
  6820. renderTarget.activeCubeFace = 2;
  6821. renderer.render( scene, cameraPY, renderTarget );
  6822. renderTarget.activeCubeFace = 3;
  6823. renderer.render( scene, cameraNY, renderTarget );
  6824. renderTarget.activeCubeFace = 4;
  6825. renderer.render( scene, cameraPZ, renderTarget );
  6826. renderTarget.generateMipmaps = generateMipmaps;
  6827. renderTarget.activeCubeFace = 5;
  6828. renderer.render( scene, cameraNZ, renderTarget );
  6829. renderer.setRenderTarget( null );
  6830. };
  6831. };
  6832. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  6833. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  6834. // File:src/cameras/OrthographicCamera.js
  6835. /**
  6836. * @author alteredq / http://alteredqualia.com/
  6837. */
  6838. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  6839. THREE.Camera.call( this );
  6840. this.type = 'OrthographicCamera';
  6841. this.zoom = 1;
  6842. this.left = left;
  6843. this.right = right;
  6844. this.top = top;
  6845. this.bottom = bottom;
  6846. this.near = ( near !== undefined ) ? near : 0.1;
  6847. this.far = ( far !== undefined ) ? far : 2000;
  6848. this.updateProjectionMatrix();
  6849. };
  6850. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  6851. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  6852. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  6853. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  6854. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  6855. var cx = ( this.right + this.left ) / 2;
  6856. var cy = ( this.top + this.bottom ) / 2;
  6857. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  6858. };
  6859. THREE.OrthographicCamera.prototype.clone = function () {
  6860. var camera = new THREE.OrthographicCamera();
  6861. THREE.Camera.prototype.clone.call( this, camera );
  6862. camera.zoom = this.zoom;
  6863. camera.left = this.left;
  6864. camera.right = this.right;
  6865. camera.top = this.top;
  6866. camera.bottom = this.bottom;
  6867. camera.near = this.near;
  6868. camera.far = this.far;
  6869. return camera;
  6870. };
  6871. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  6872. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  6873. data.object.zoom = this.zoom;
  6874. data.object.left = this.left;
  6875. data.object.right = this.right;
  6876. data.object.top = this.top;
  6877. data.object.bottom = this.bottom;
  6878. data.object.near = this.near;
  6879. data.object.far = this.far;
  6880. return data;
  6881. };
  6882. // File:src/cameras/PerspectiveCamera.js
  6883. /**
  6884. * @author mrdoob / http://mrdoob.com/
  6885. * @author greggman / http://games.greggman.com/
  6886. * @author zz85 / http://www.lab4games.net/zz85/blog
  6887. */
  6888. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  6889. THREE.Camera.call( this );
  6890. this.type = 'PerspectiveCamera';
  6891. this.zoom = 1;
  6892. this.fov = fov !== undefined ? fov : 50;
  6893. this.aspect = aspect !== undefined ? aspect : 1;
  6894. this.near = near !== undefined ? near : 0.1;
  6895. this.far = far !== undefined ? far : 2000;
  6896. this.updateProjectionMatrix();
  6897. };
  6898. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  6899. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  6900. /**
  6901. * Uses Focal Length (in mm) to estimate and set FOV
  6902. * 35mm (full-frame) camera is used if frame size is not specified;
  6903. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  6904. */
  6905. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  6906. if ( frameHeight === undefined ) frameHeight = 24;
  6907. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  6908. this.updateProjectionMatrix();
  6909. };
  6910. /**
  6911. * Sets an offset in a larger frustum. This is useful for multi-window or
  6912. * multi-monitor/multi-machine setups.
  6913. *
  6914. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  6915. * the monitors are in grid like this
  6916. *
  6917. * +---+---+---+
  6918. * | A | B | C |
  6919. * +---+---+---+
  6920. * | D | E | F |
  6921. * +---+---+---+
  6922. *
  6923. * then for each monitor you would call it like this
  6924. *
  6925. * var w = 1920;
  6926. * var h = 1080;
  6927. * var fullWidth = w * 3;
  6928. * var fullHeight = h * 2;
  6929. *
  6930. * --A--
  6931. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  6932. * --B--
  6933. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  6934. * --C--
  6935. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  6936. * --D--
  6937. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  6938. * --E--
  6939. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  6940. * --F--
  6941. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  6942. *
  6943. * Note there is no reason monitors have to be the same size or in a grid.
  6944. */
  6945. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  6946. this.fullWidth = fullWidth;
  6947. this.fullHeight = fullHeight;
  6948. this.x = x;
  6949. this.y = y;
  6950. this.width = width;
  6951. this.height = height;
  6952. this.updateProjectionMatrix();
  6953. };
  6954. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  6955. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  6956. if ( this.fullWidth ) {
  6957. var aspect = this.fullWidth / this.fullHeight;
  6958. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  6959. var bottom = - top;
  6960. var left = aspect * bottom;
  6961. var right = aspect * top;
  6962. var width = Math.abs( right - left );
  6963. var height = Math.abs( top - bottom );
  6964. this.projectionMatrix.makeFrustum(
  6965. left + this.x * width / this.fullWidth,
  6966. left + ( this.x + this.width ) * width / this.fullWidth,
  6967. top - ( this.y + this.height ) * height / this.fullHeight,
  6968. top - this.y * height / this.fullHeight,
  6969. this.near,
  6970. this.far
  6971. );
  6972. } else {
  6973. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  6974. }
  6975. };
  6976. THREE.PerspectiveCamera.prototype.clone = function () {
  6977. var camera = new THREE.PerspectiveCamera();
  6978. THREE.Camera.prototype.clone.call( this, camera );
  6979. camera.zoom = this.zoom;
  6980. camera.fov = this.fov;
  6981. camera.aspect = this.aspect;
  6982. camera.near = this.near;
  6983. camera.far = this.far;
  6984. return camera;
  6985. };
  6986. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  6987. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  6988. data.object.zoom = this.zoom;
  6989. data.object.fov = this.fov;
  6990. data.object.aspect = this.aspect;
  6991. data.object.near = this.near;
  6992. data.object.far = this.far;
  6993. return data;
  6994. };
  6995. // File:src/lights/Light.js
  6996. /**
  6997. * @author mrdoob / http://mrdoob.com/
  6998. * @author alteredq / http://alteredqualia.com/
  6999. */
  7000. THREE.Light = function ( color ) {
  7001. THREE.Object3D.call( this );
  7002. this.type = 'Light';
  7003. this.color = new THREE.Color( color );
  7004. };
  7005. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  7006. THREE.Light.prototype.constructor = THREE.Light;
  7007. THREE.Light.prototype.clone = function ( light ) {
  7008. if ( light === undefined ) light = new THREE.Light();
  7009. THREE.Object3D.prototype.clone.call( this, light );
  7010. light.color.copy( this.color );
  7011. return light;
  7012. };
  7013. // File:src/lights/AmbientLight.js
  7014. /**
  7015. * @author mrdoob / http://mrdoob.com/
  7016. */
  7017. THREE.AmbientLight = function ( color ) {
  7018. THREE.Light.call( this, color );
  7019. this.type = 'AmbientLight';
  7020. };
  7021. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  7022. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  7023. THREE.AmbientLight.prototype.clone = function () {
  7024. var light = new THREE.AmbientLight();
  7025. THREE.Light.prototype.clone.call( this, light );
  7026. return light;
  7027. };
  7028. THREE.AmbientLight.prototype.toJSON = function ( meta ) {
  7029. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7030. data.object.color = this.color.getHex();
  7031. return data;
  7032. };
  7033. // File:src/lights/AreaLight.js
  7034. /**
  7035. * @author MPanknin / http://www.redplant.de/
  7036. * @author alteredq / http://alteredqualia.com/
  7037. * @author prafullit
  7038. */
  7039. THREE.AreaLight = function ( color, intensity ) {
  7040. THREE.Light.call( this, color );
  7041. this.type = 'AreaLight';
  7042. this.normal = new THREE.Vector3( 0, - 1, 0 );
  7043. this.right = new THREE.Vector3( 1, 0, 0 );
  7044. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7045. this.width = 1.0;
  7046. this.height = 1.0;
  7047. this.constantAttenuation = 1.5;
  7048. this.linearAttenuation = 0.5;
  7049. this.quadraticAttenuation = 0.1;
  7050. };
  7051. THREE.AreaLight.prototype = Object.create( THREE.Light.prototype );
  7052. THREE.AreaLight.prototype.constructor = THREE.AreaLight;
  7053. THREE.AreaLight.prototype.clone = function () {
  7054. var light = new THREE.AreaLight();
  7055. THREE.Light.prototype.clone.call( this, light );
  7056. light.normal.copy(this.normal);
  7057. light.right.copy(this.right);
  7058. light.intensity = this.intensity;
  7059. light.width = this.width;
  7060. light.height = this.height;
  7061. light.constantAttenuation = this.constantAttenuation;
  7062. light.linearAttenuation = this.linearAttenuation;
  7063. light.quadraticAttenuation = this.quadraticAttenuation
  7064. return light;
  7065. };
  7066. THREE.AreaLight.prototype.toJSON = function ( meta ) {
  7067. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7068. data.object.color = this.color.getHex();
  7069. data.object.intensity = this.intensity;
  7070. return data;
  7071. };
  7072. // File:src/lights/DirectionalLight.js
  7073. /**
  7074. * @author mrdoob / http://mrdoob.com/
  7075. * @author alteredq / http://alteredqualia.com/
  7076. */
  7077. THREE.DirectionalLight = function ( color, intensity ) {
  7078. THREE.Light.call( this, color );
  7079. this.type = 'DirectionalLight';
  7080. this.position.set( 0, 1, 0 );
  7081. this.target = new THREE.Object3D();
  7082. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7083. this.castShadow = false;
  7084. this.onlyShadow = false;
  7085. //
  7086. this.shadowCameraNear = 50;
  7087. this.shadowCameraFar = 5000;
  7088. this.shadowCameraLeft = - 500;
  7089. this.shadowCameraRight = 500;
  7090. this.shadowCameraTop = 500;
  7091. this.shadowCameraBottom = - 500;
  7092. this.shadowCameraVisible = false;
  7093. this.shadowBias = 0;
  7094. this.shadowDarkness = 0.5;
  7095. this.shadowMapWidth = 512;
  7096. this.shadowMapHeight = 512;
  7097. //
  7098. this.shadowCascade = false;
  7099. this.shadowCascadeOffset = new THREE.Vector3( 0, 0, - 1000 );
  7100. this.shadowCascadeCount = 2;
  7101. this.shadowCascadeBias = [ 0, 0, 0 ];
  7102. this.shadowCascadeWidth = [ 512, 512, 512 ];
  7103. this.shadowCascadeHeight = [ 512, 512, 512 ];
  7104. this.shadowCascadeNearZ = [ - 1.000, 0.990, 0.998 ];
  7105. this.shadowCascadeFarZ = [ 0.990, 0.998, 1.000 ];
  7106. this.shadowCascadeArray = [];
  7107. //
  7108. this.shadowMap = null;
  7109. this.shadowMapSize = null;
  7110. this.shadowCamera = null;
  7111. this.shadowMatrix = null;
  7112. };
  7113. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  7114. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  7115. THREE.DirectionalLight.prototype.clone = function () {
  7116. var light = new THREE.DirectionalLight();
  7117. THREE.Light.prototype.clone.call( this, light );
  7118. light.target = this.target.clone();
  7119. light.intensity = this.intensity;
  7120. light.castShadow = this.castShadow;
  7121. light.onlyShadow = this.onlyShadow;
  7122. //
  7123. light.shadowCameraNear = this.shadowCameraNear;
  7124. light.shadowCameraFar = this.shadowCameraFar;
  7125. light.shadowCameraLeft = this.shadowCameraLeft;
  7126. light.shadowCameraRight = this.shadowCameraRight;
  7127. light.shadowCameraTop = this.shadowCameraTop;
  7128. light.shadowCameraBottom = this.shadowCameraBottom;
  7129. light.shadowCameraVisible = this.shadowCameraVisible;
  7130. light.shadowBias = this.shadowBias;
  7131. light.shadowDarkness = this.shadowDarkness;
  7132. light.shadowMapWidth = this.shadowMapWidth;
  7133. light.shadowMapHeight = this.shadowMapHeight;
  7134. //
  7135. light.shadowCascade = this.shadowCascade;
  7136. light.shadowCascadeOffset.copy( this.shadowCascadeOffset );
  7137. light.shadowCascadeCount = this.shadowCascadeCount;
  7138. light.shadowCascadeBias = this.shadowCascadeBias.slice( 0 );
  7139. light.shadowCascadeWidth = this.shadowCascadeWidth.slice( 0 );
  7140. light.shadowCascadeHeight = this.shadowCascadeHeight.slice( 0 );
  7141. light.shadowCascadeNearZ = this.shadowCascadeNearZ.slice( 0 );
  7142. light.shadowCascadeFarZ = this.shadowCascadeFarZ.slice( 0 );
  7143. return light;
  7144. };
  7145. THREE.DirectionalLight.prototype.toJSON = function ( meta ) {
  7146. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7147. data.object.color = this.color.getHex();
  7148. data.object.intensity = this.intensity;
  7149. return data;
  7150. };
  7151. // File:src/lights/HemisphereLight.js
  7152. /**
  7153. * @author alteredq / http://alteredqualia.com/
  7154. */
  7155. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  7156. THREE.Light.call( this, skyColor );
  7157. this.type = 'HemisphereLight';
  7158. this.position.set( 0, 100, 0 );
  7159. this.groundColor = new THREE.Color( groundColor );
  7160. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7161. };
  7162. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  7163. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  7164. THREE.HemisphereLight.prototype.clone = function () {
  7165. var light = new THREE.HemisphereLight();
  7166. THREE.Light.prototype.clone.call( this, light );
  7167. light.groundColor.copy( this.groundColor );
  7168. light.intensity = this.intensity;
  7169. return light;
  7170. };
  7171. THREE.HemisphereLight.prototype.toJSON = function ( meta ) {
  7172. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7173. data.object.color = this.color.getHex();
  7174. data.object.groundColor = this.groundColor.getHex();
  7175. return data;
  7176. };
  7177. // File:src/lights/PointLight.js
  7178. /**
  7179. * @author mrdoob / http://mrdoob.com/
  7180. */
  7181. THREE.PointLight = function ( color, intensity, distance, decay ) {
  7182. THREE.Light.call( this, color );
  7183. this.type = 'PointLight';
  7184. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7185. this.distance = ( distance !== undefined ) ? distance : 0;
  7186. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  7187. };
  7188. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  7189. THREE.PointLight.prototype.constructor = THREE.PointLight;
  7190. THREE.PointLight.prototype.clone = function () {
  7191. var light = new THREE.PointLight();
  7192. THREE.Light.prototype.clone.call( this, light );
  7193. light.intensity = this.intensity;
  7194. light.distance = this.distance;
  7195. light.decay = this.decay;
  7196. return light;
  7197. };
  7198. THREE.PointLight.prototype.toJSON = function ( meta ) {
  7199. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7200. data.object.color = this.color.getHex();
  7201. data.object.intensity = this.intensity;
  7202. data.object.distance = this.distance;
  7203. data.object.decay = this.decay;
  7204. return data;
  7205. };
  7206. // File:src/lights/SpotLight.js
  7207. /**
  7208. * @author alteredq / http://alteredqualia.com/
  7209. */
  7210. THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
  7211. THREE.Light.call( this, color );
  7212. this.type = 'SpotLight';
  7213. this.position.set( 0, 1, 0 );
  7214. this.target = new THREE.Object3D();
  7215. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7216. this.distance = ( distance !== undefined ) ? distance : 0;
  7217. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  7218. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  7219. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  7220. this.castShadow = false;
  7221. this.onlyShadow = false;
  7222. //
  7223. this.shadowCameraNear = 50;
  7224. this.shadowCameraFar = 5000;
  7225. this.shadowCameraFov = 50;
  7226. this.shadowCameraVisible = false;
  7227. this.shadowBias = 0;
  7228. this.shadowDarkness = 0.5;
  7229. this.shadowMapWidth = 512;
  7230. this.shadowMapHeight = 512;
  7231. //
  7232. this.shadowMap = null;
  7233. this.shadowMapSize = null;
  7234. this.shadowCamera = null;
  7235. this.shadowMatrix = null;
  7236. };
  7237. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  7238. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  7239. THREE.SpotLight.prototype.clone = function () {
  7240. var light = new THREE.SpotLight();
  7241. THREE.Light.prototype.clone.call( this, light );
  7242. light.target = this.target.clone();
  7243. light.intensity = this.intensity;
  7244. light.distance = this.distance;
  7245. light.angle = this.angle;
  7246. light.exponent = this.exponent;
  7247. light.decay = this.decay;
  7248. light.castShadow = this.castShadow;
  7249. light.onlyShadow = this.onlyShadow;
  7250. //
  7251. light.shadowCameraNear = this.shadowCameraNear;
  7252. light.shadowCameraFar = this.shadowCameraFar;
  7253. light.shadowCameraFov = this.shadowCameraFov;
  7254. light.shadowCameraVisible = this.shadowCameraVisible;
  7255. light.shadowBias = this.shadowBias;
  7256. light.shadowDarkness = this.shadowDarkness;
  7257. light.shadowMapWidth = this.shadowMapWidth;
  7258. light.shadowMapHeight = this.shadowMapHeight;
  7259. return light;
  7260. };
  7261. THREE.SpotLight.prototype.toJSON = function ( meta ) {
  7262. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7263. data.object.color = this.color.getHex();
  7264. data.object.intensity = this.intensity;
  7265. data.object.distance = this.distance;
  7266. data.object.angle = this.angle;
  7267. data.object.exponent = this.exponent;
  7268. data.object.decay = this.decay;
  7269. return data;
  7270. };
  7271. // File:src/loaders/Cache.js
  7272. /**
  7273. * @author mrdoob / http://mrdoob.com/
  7274. */
  7275. THREE.Cache = {
  7276. files: {},
  7277. add: function ( key, file ) {
  7278. // console.log( 'THREE.Cache', 'Adding key:', key );
  7279. this.files[ key ] = file;
  7280. },
  7281. get: function ( key ) {
  7282. // console.log( 'THREE.Cache', 'Checking key:', key );
  7283. return this.files[ key ];
  7284. },
  7285. remove: function ( key ) {
  7286. delete this.files[ key ];
  7287. },
  7288. clear: function () {
  7289. this.files = {}
  7290. }
  7291. };
  7292. // File:src/loaders/Loader.js
  7293. /**
  7294. * @author alteredq / http://alteredqualia.com/
  7295. */
  7296. THREE.Loader = function ( showStatus ) {
  7297. this.showStatus = showStatus;
  7298. this.statusDomElement = showStatus ? THREE.Loader.prototype.addStatusElement() : null;
  7299. this.imageLoader = new THREE.ImageLoader();
  7300. this.onLoadStart = function () {};
  7301. this.onLoadProgress = function () {};
  7302. this.onLoadComplete = function () {};
  7303. };
  7304. THREE.Loader.prototype = {
  7305. constructor: THREE.Loader,
  7306. crossOrigin: undefined,
  7307. addStatusElement: function () {
  7308. var e = document.createElement( 'div' );
  7309. e.style.position = 'absolute';
  7310. e.style.right = '0px';
  7311. e.style.top = '0px';
  7312. e.style.fontSize = '0.8em';
  7313. e.style.textAlign = 'left';
  7314. e.style.background = 'rgba(0,0,0,0.25)';
  7315. e.style.color = '#fff';
  7316. e.style.width = '120px';
  7317. e.style.padding = '0.5em 0.5em 0.5em 0.5em';
  7318. e.style.zIndex = 1000;
  7319. e.innerHTML = 'Loading ...';
  7320. return e;
  7321. },
  7322. updateProgress: function ( progress ) {
  7323. var message = 'Loaded ';
  7324. if ( progress.total ) {
  7325. message += ( 100 * progress.loaded / progress.total ).toFixed( 0 ) + '%';
  7326. } else {
  7327. message += ( progress.loaded / 1024 ).toFixed( 2 ) + ' KB';
  7328. }
  7329. this.statusDomElement.innerHTML = message;
  7330. },
  7331. extractUrlBase: function ( url ) {
  7332. var parts = url.split( '/' );
  7333. if ( parts.length === 1 ) return './';
  7334. parts.pop();
  7335. return parts.join( '/' ) + '/';
  7336. },
  7337. initMaterials: function ( materials, texturePath ) {
  7338. var array = [];
  7339. for ( var i = 0; i < materials.length; ++ i ) {
  7340. array[ i ] = this.createMaterial( materials[ i ], texturePath );
  7341. }
  7342. return array;
  7343. },
  7344. needsTangents: function ( materials ) {
  7345. for ( var i = 0, il = materials.length; i < il; i ++ ) {
  7346. var m = materials[ i ];
  7347. if ( m instanceof THREE.ShaderMaterial ) return true;
  7348. }
  7349. return false;
  7350. },
  7351. createMaterial: function ( m, texturePath ) {
  7352. var scope = this;
  7353. function nearest_pow2( n ) {
  7354. var l = Math.log( n ) / Math.LN2;
  7355. return Math.pow( 2, Math.round( l ) );
  7356. }
  7357. function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) {
  7358. var fullPath = texturePath + sourceFile;
  7359. var texture;
  7360. var loader = THREE.Loader.Handlers.get( fullPath );
  7361. if ( loader !== null ) {
  7362. texture = loader.load( fullPath );
  7363. } else {
  7364. texture = new THREE.Texture();
  7365. loader = scope.imageLoader;
  7366. loader.crossOrigin = scope.crossOrigin;
  7367. loader.load( fullPath, function ( image ) {
  7368. if ( THREE.Math.isPowerOfTwo( image.width ) === false ||
  7369. THREE.Math.isPowerOfTwo( image.height ) === false ) {
  7370. var width = nearest_pow2( image.width );
  7371. var height = nearest_pow2( image.height );
  7372. var canvas = document.createElement( 'canvas' );
  7373. canvas.width = width;
  7374. canvas.height = height;
  7375. var context = canvas.getContext( '2d' );
  7376. context.drawImage( image, 0, 0, width, height );
  7377. texture.image = canvas;
  7378. } else {
  7379. texture.image = image;
  7380. }
  7381. texture.needsUpdate = true;
  7382. } );
  7383. }
  7384. texture.sourceFile = sourceFile;
  7385. if ( repeat ) {
  7386. texture.repeat.set( repeat[ 0 ], repeat[ 1 ] );
  7387. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  7388. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  7389. }
  7390. if ( offset ) {
  7391. texture.offset.set( offset[ 0 ], offset[ 1 ] );
  7392. }
  7393. if ( wrap ) {
  7394. var wrapMap = {
  7395. 'repeat': THREE.RepeatWrapping,
  7396. 'mirror': THREE.MirroredRepeatWrapping
  7397. };
  7398. if ( wrapMap[ wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ wrap[ 0 ] ];
  7399. if ( wrapMap[ wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ wrap[ 1 ] ];
  7400. }
  7401. if ( anisotropy ) {
  7402. texture.anisotropy = anisotropy;
  7403. }
  7404. where[ name ] = texture;
  7405. }
  7406. function rgb2hex( rgb ) {
  7407. return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
  7408. }
  7409. // defaults
  7410. var mtype = 'MeshLambertMaterial';
  7411. var mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, bumpMap: null, wireframe: false };
  7412. // parameters from model file
  7413. if ( m.shading ) {
  7414. var shading = m.shading.toLowerCase();
  7415. if ( shading === 'phong' ) mtype = 'MeshPhongMaterial';
  7416. else if ( shading === 'basic' ) mtype = 'MeshBasicMaterial';
  7417. }
  7418. if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
  7419. mpars.blending = THREE[ m.blending ];
  7420. }
  7421. if ( m.transparent !== undefined ) {
  7422. mpars.transparent = m.transparent;
  7423. }
  7424. if ( m.opacity !== undefined && m.opacity < 1.0 ) {
  7425. mpars.transparent = true;
  7426. }
  7427. if ( m.depthTest !== undefined ) {
  7428. mpars.depthTest = m.depthTest;
  7429. }
  7430. if ( m.depthWrite !== undefined ) {
  7431. mpars.depthWrite = m.depthWrite;
  7432. }
  7433. if ( m.visible !== undefined ) {
  7434. mpars.visible = m.visible;
  7435. }
  7436. if ( m.flipSided !== undefined ) {
  7437. mpars.side = THREE.BackSide;
  7438. }
  7439. if ( m.doubleSided !== undefined ) {
  7440. mpars.side = THREE.DoubleSide;
  7441. }
  7442. if ( m.wireframe !== undefined ) {
  7443. mpars.wireframe = m.wireframe;
  7444. }
  7445. if ( m.vertexColors !== undefined ) {
  7446. if ( m.vertexColors === 'face' ) {
  7447. mpars.vertexColors = THREE.FaceColors;
  7448. } else if ( m.vertexColors ) {
  7449. mpars.vertexColors = THREE.VertexColors;
  7450. }
  7451. }
  7452. // colors
  7453. if ( m.colorDiffuse ) {
  7454. mpars.color = rgb2hex( m.colorDiffuse );
  7455. } else if ( m.DbgColor ) {
  7456. mpars.color = m.DbgColor;
  7457. }
  7458. if ( m.colorSpecular ) {
  7459. mpars.specular = rgb2hex( m.colorSpecular );
  7460. }
  7461. if ( m.colorEmissive ) {
  7462. mpars.emissive = rgb2hex( m.colorEmissive );
  7463. }
  7464. // modifiers
  7465. if ( m.transparency !== undefined ) {
  7466. console.warn( 'THREE.Loader: transparency has been renamed to opacity' );
  7467. m.opacity = m.transparency;
  7468. }
  7469. if ( m.opacity !== undefined ) {
  7470. mpars.opacity = m.opacity;
  7471. }
  7472. if ( m.specularCoef ) {
  7473. mpars.shininess = m.specularCoef;
  7474. }
  7475. // textures
  7476. if ( m.mapDiffuse && texturePath ) {
  7477. create_texture( mpars, 'map', m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  7478. }
  7479. if ( m.mapLight && texturePath ) {
  7480. create_texture( mpars, 'lightMap', m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  7481. }
  7482. if ( m.mapAO && texturePath ) {
  7483. create_texture( mpars, 'aoMap', m.mapAO, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  7484. }
  7485. if ( m.mapBump && texturePath ) {
  7486. create_texture( mpars, 'bumpMap', m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  7487. }
  7488. if ( m.mapNormal && texturePath ) {
  7489. create_texture( mpars, 'normalMap', m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  7490. }
  7491. if ( m.mapSpecular && texturePath ) {
  7492. create_texture( mpars, 'specularMap', m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  7493. }
  7494. if ( m.mapAlpha && texturePath ) {
  7495. create_texture( mpars, 'alphaMap', m.mapAlpha, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  7496. }
  7497. //
  7498. if ( m.mapBumpScale ) {
  7499. mpars.bumpScale = m.mapBumpScale;
  7500. }
  7501. if ( m.mapNormalFactor ) {
  7502. mpars.normalScale = new THREE.Vector2( m.mapNormalFactor, m.mapNormalFactor );
  7503. }
  7504. var material = new THREE[ mtype ]( mpars );
  7505. if ( m.DbgName !== undefined ) material.name = m.DbgName;
  7506. return material;
  7507. }
  7508. };
  7509. THREE.Loader.Handlers = {
  7510. handlers: [],
  7511. add: function ( regex, loader ) {
  7512. this.handlers.push( regex, loader );
  7513. },
  7514. get: function ( file ) {
  7515. for ( var i = 0, l = this.handlers.length; i < l; i += 2 ) {
  7516. var regex = this.handlers[ i ];
  7517. var loader = this.handlers[ i + 1 ];
  7518. if ( regex.test( file ) ) {
  7519. return loader;
  7520. }
  7521. }
  7522. return null;
  7523. }
  7524. };
  7525. // File:src/loaders/XHRLoader.js
  7526. /**
  7527. * @author mrdoob / http://mrdoob.com/
  7528. */
  7529. THREE.XHRLoader = function ( manager ) {
  7530. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7531. };
  7532. THREE.XHRLoader.prototype = {
  7533. constructor: THREE.XHRLoader,
  7534. load: function ( url, onLoad, onProgress, onError ) {
  7535. var scope = this;
  7536. var cached = THREE.Cache.get( url );
  7537. if ( cached !== undefined ) {
  7538. if ( onLoad ) onLoad( cached );
  7539. return cached;
  7540. }
  7541. var request = new XMLHttpRequest();
  7542. request.open( 'GET', url, true );
  7543. request.addEventListener( 'load', function ( event ) {
  7544. THREE.Cache.add( url, this.response );
  7545. if ( onLoad ) onLoad( this.response );
  7546. scope.manager.itemEnd( url );
  7547. }, false );
  7548. if ( onProgress !== undefined ) {
  7549. request.addEventListener( 'progress', function ( event ) {
  7550. onProgress( event );
  7551. }, false );
  7552. }
  7553. if ( onError !== undefined ) {
  7554. request.addEventListener( 'error', function ( event ) {
  7555. onError( event );
  7556. }, false );
  7557. }
  7558. if ( this.crossOrigin !== undefined ) request.crossOrigin = this.crossOrigin;
  7559. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  7560. request.send( null );
  7561. scope.manager.itemStart( url );
  7562. return request;
  7563. },
  7564. setResponseType: function ( value ) {
  7565. this.responseType = value;
  7566. },
  7567. setCrossOrigin: function ( value ) {
  7568. this.crossOrigin = value;
  7569. }
  7570. };
  7571. // File:src/loaders/ImageLoader.js
  7572. /**
  7573. * @author mrdoob / http://mrdoob.com/
  7574. */
  7575. THREE.ImageLoader = function ( manager ) {
  7576. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7577. };
  7578. THREE.ImageLoader.prototype = {
  7579. constructor: THREE.ImageLoader,
  7580. load: function ( url, onLoad, onProgress, onError ) {
  7581. var scope = this;
  7582. var cached = THREE.Cache.get( url );
  7583. if ( cached !== undefined ) {
  7584. if ( onLoad ) onLoad( cached );
  7585. return cached;
  7586. }
  7587. var image = document.createElement( 'img' );
  7588. image.addEventListener( 'load', function ( event ) {
  7589. THREE.Cache.add( url, this );
  7590. if ( onLoad ) onLoad( this );
  7591. scope.manager.itemEnd( url );
  7592. }, false );
  7593. if ( onProgress !== undefined ) {
  7594. image.addEventListener( 'progress', function ( event ) {
  7595. onProgress( event );
  7596. }, false );
  7597. }
  7598. if ( onError !== undefined ) {
  7599. image.addEventListener( 'error', function ( event ) {
  7600. onError( event );
  7601. }, false );
  7602. }
  7603. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  7604. scope.manager.itemStart( url );
  7605. image.src = url;
  7606. return image;
  7607. },
  7608. setCrossOrigin: function ( value ) {
  7609. this.crossOrigin = value;
  7610. }
  7611. };
  7612. // File:src/loaders/JSONLoader.js
  7613. /**
  7614. * @author mrdoob / http://mrdoob.com/
  7615. * @author alteredq / http://alteredqualia.com/
  7616. */
  7617. THREE.JSONLoader = function ( showStatus ) {
  7618. THREE.Loader.call( this, showStatus );
  7619. this.withCredentials = false;
  7620. };
  7621. THREE.JSONLoader.prototype = Object.create( THREE.Loader.prototype );
  7622. THREE.JSONLoader.prototype.constructor = THREE.JSONLoader;
  7623. THREE.JSONLoader.prototype.load = function ( url, callback, texturePath ) {
  7624. // TODO: unify load API to for easier SceneLoader use
  7625. texturePath = texturePath && ( typeof texturePath === 'string' ) ? texturePath : this.extractUrlBase( url );
  7626. this.onLoadStart();
  7627. this.loadAjaxJSON( this, url, callback, texturePath );
  7628. };
  7629. THREE.JSONLoader.prototype.loadAjaxJSON = function ( context, url, callback, texturePath, callbackProgress ) {
  7630. var xhr = new XMLHttpRequest();
  7631. var length = 0;
  7632. xhr.onreadystatechange = function () {
  7633. if ( xhr.readyState === xhr.DONE ) {
  7634. if ( xhr.status === 200 || xhr.status === 0 ) {
  7635. if ( xhr.responseText ) {
  7636. var json = JSON.parse( xhr.responseText );
  7637. var metadata = json.metadata;
  7638. if ( metadata !== undefined ) {
  7639. if ( metadata.type === 'object' ) {
  7640. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  7641. return;
  7642. }
  7643. if ( metadata.type === 'scene' ) {
  7644. console.error( 'THREE.JSONLoader: ' + url + ' seems to be a Scene. Use THREE.SceneLoader instead.' );
  7645. return;
  7646. }
  7647. }
  7648. var result = context.parse( json, texturePath );
  7649. callback( result.geometry, result.materials );
  7650. } else {
  7651. console.error( 'THREE.JSONLoader: ' + url + ' seems to be unreachable or the file is empty.' );
  7652. }
  7653. // in context of more complex asset initialization
  7654. // do not block on single failed file
  7655. // maybe should go even one more level up
  7656. context.onLoadComplete();
  7657. } else {
  7658. console.error( 'THREE.JSONLoader: Couldn\'t load ' + url + ' (' + xhr.status + ')' );
  7659. }
  7660. } else if ( xhr.readyState === xhr.LOADING ) {
  7661. if ( callbackProgress ) {
  7662. if ( length === 0 ) {
  7663. length = xhr.getResponseHeader( 'Content-Length' );
  7664. }
  7665. callbackProgress( { total: length, loaded: xhr.responseText.length } );
  7666. }
  7667. } else if ( xhr.readyState === xhr.HEADERS_RECEIVED ) {
  7668. if ( callbackProgress !== undefined ) {
  7669. length = xhr.getResponseHeader( 'Content-Length' );
  7670. }
  7671. }
  7672. };
  7673. xhr.open( 'GET', url, true );
  7674. xhr.withCredentials = this.withCredentials;
  7675. xhr.send( null );
  7676. };
  7677. THREE.JSONLoader.prototype.parse = function ( json, texturePath ) {
  7678. var geometry = new THREE.Geometry(),
  7679. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  7680. parseModel( scale );
  7681. parseSkin();
  7682. parseMorphing( scale );
  7683. geometry.computeFaceNormals();
  7684. geometry.computeBoundingSphere();
  7685. function parseModel( scale ) {
  7686. function isBitSet( value, position ) {
  7687. return value & ( 1 << position );
  7688. }
  7689. var i, j, fi,
  7690. offset, zLength,
  7691. colorIndex, normalIndex, uvIndex,
  7692. type,
  7693. isQuad,
  7694. hasMaterial,
  7695. hasFaceVertexUv,
  7696. hasFaceNormal, hasFaceVertexNormal,
  7697. hasFaceColor, hasFaceVertexColor,
  7698. vertex, face, faceA, faceB, hex, normal,
  7699. uvLayer, uv, u, v,
  7700. faces = json.faces,
  7701. vertices = json.vertices,
  7702. normals = json.normals,
  7703. colors = json.colors,
  7704. nUvLayers = 0;
  7705. if ( json.uvs !== undefined ) {
  7706. // disregard empty arrays
  7707. for ( i = 0; i < json.uvs.length; i ++ ) {
  7708. if ( json.uvs[ i ].length ) nUvLayers ++;
  7709. }
  7710. for ( i = 0; i < nUvLayers; i ++ ) {
  7711. geometry.faceVertexUvs[ i ] = [];
  7712. }
  7713. }
  7714. offset = 0;
  7715. zLength = vertices.length;
  7716. while ( offset < zLength ) {
  7717. vertex = new THREE.Vector3();
  7718. vertex.x = vertices[ offset ++ ] * scale;
  7719. vertex.y = vertices[ offset ++ ] * scale;
  7720. vertex.z = vertices[ offset ++ ] * scale;
  7721. geometry.vertices.push( vertex );
  7722. }
  7723. offset = 0;
  7724. zLength = faces.length;
  7725. while ( offset < zLength ) {
  7726. type = faces[ offset ++ ];
  7727. isQuad = isBitSet( type, 0 );
  7728. hasMaterial = isBitSet( type, 1 );
  7729. hasFaceVertexUv = isBitSet( type, 3 );
  7730. hasFaceNormal = isBitSet( type, 4 );
  7731. hasFaceVertexNormal = isBitSet( type, 5 );
  7732. hasFaceColor = isBitSet( type, 6 );
  7733. hasFaceVertexColor = isBitSet( type, 7 );
  7734. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  7735. if ( isQuad ) {
  7736. faceA = new THREE.Face3();
  7737. faceA.a = faces[ offset ];
  7738. faceA.b = faces[ offset + 1 ];
  7739. faceA.c = faces[ offset + 3 ];
  7740. faceB = new THREE.Face3();
  7741. faceB.a = faces[ offset + 1 ];
  7742. faceB.b = faces[ offset + 2 ];
  7743. faceB.c = faces[ offset + 3 ];
  7744. offset += 4;
  7745. if ( hasMaterial ) {
  7746. offset ++;
  7747. }
  7748. // to get face <=> uv index correspondence
  7749. fi = geometry.faces.length;
  7750. if ( hasFaceVertexUv ) {
  7751. for ( i = 0; i < nUvLayers; i ++ ) {
  7752. uvLayer = json.uvs[ i ];
  7753. geometry.faceVertexUvs[ i ][ fi ] = [];
  7754. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  7755. for ( j = 0; j < 4; j ++ ) {
  7756. uvIndex = faces[ offset ++ ];
  7757. u = uvLayer[ uvIndex * 2 ];
  7758. v = uvLayer[ uvIndex * 2 + 1 ];
  7759. uv = new THREE.Vector2( u, v );
  7760. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  7761. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  7762. }
  7763. }
  7764. }
  7765. if ( hasFaceNormal ) {
  7766. normalIndex = faces[ offset ++ ] * 3;
  7767. faceA.normal.set(
  7768. normals[ normalIndex ++ ],
  7769. normals[ normalIndex ++ ],
  7770. normals[ normalIndex ]
  7771. );
  7772. faceB.normal.copy( faceA.normal );
  7773. }
  7774. if ( hasFaceVertexNormal ) {
  7775. for ( i = 0; i < 4; i ++ ) {
  7776. normalIndex = faces[ offset ++ ] * 3;
  7777. normal = new THREE.Vector3(
  7778. normals[ normalIndex ++ ],
  7779. normals[ normalIndex ++ ],
  7780. normals[ normalIndex ]
  7781. );
  7782. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  7783. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  7784. }
  7785. }
  7786. if ( hasFaceColor ) {
  7787. colorIndex = faces[ offset ++ ];
  7788. hex = colors[ colorIndex ];
  7789. faceA.color.setHex( hex );
  7790. faceB.color.setHex( hex );
  7791. }
  7792. if ( hasFaceVertexColor ) {
  7793. for ( i = 0; i < 4; i ++ ) {
  7794. colorIndex = faces[ offset ++ ];
  7795. hex = colors[ colorIndex ];
  7796. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  7797. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  7798. }
  7799. }
  7800. geometry.faces.push( faceA );
  7801. geometry.faces.push( faceB );
  7802. } else {
  7803. face = new THREE.Face3();
  7804. face.a = faces[ offset ++ ];
  7805. face.b = faces[ offset ++ ];
  7806. face.c = faces[ offset ++ ];
  7807. if ( hasMaterial ) {
  7808. offset ++;
  7809. }
  7810. // to get face <=> uv index correspondence
  7811. fi = geometry.faces.length;
  7812. if ( hasFaceVertexUv ) {
  7813. for ( i = 0; i < nUvLayers; i ++ ) {
  7814. uvLayer = json.uvs[ i ];
  7815. geometry.faceVertexUvs[ i ][ fi ] = [];
  7816. for ( j = 0; j < 3; j ++ ) {
  7817. uvIndex = faces[ offset ++ ];
  7818. u = uvLayer[ uvIndex * 2 ];
  7819. v = uvLayer[ uvIndex * 2 + 1 ];
  7820. uv = new THREE.Vector2( u, v );
  7821. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  7822. }
  7823. }
  7824. }
  7825. if ( hasFaceNormal ) {
  7826. normalIndex = faces[ offset ++ ] * 3;
  7827. face.normal.set(
  7828. normals[ normalIndex ++ ],
  7829. normals[ normalIndex ++ ],
  7830. normals[ normalIndex ]
  7831. );
  7832. }
  7833. if ( hasFaceVertexNormal ) {
  7834. for ( i = 0; i < 3; i ++ ) {
  7835. normalIndex = faces[ offset ++ ] * 3;
  7836. normal = new THREE.Vector3(
  7837. normals[ normalIndex ++ ],
  7838. normals[ normalIndex ++ ],
  7839. normals[ normalIndex ]
  7840. );
  7841. face.vertexNormals.push( normal );
  7842. }
  7843. }
  7844. if ( hasFaceColor ) {
  7845. colorIndex = faces[ offset ++ ];
  7846. face.color.setHex( colors[ colorIndex ] );
  7847. }
  7848. if ( hasFaceVertexColor ) {
  7849. for ( i = 0; i < 3; i ++ ) {
  7850. colorIndex = faces[ offset ++ ];
  7851. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  7852. }
  7853. }
  7854. geometry.faces.push( face );
  7855. }
  7856. }
  7857. }
  7858. function parseSkin() {
  7859. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  7860. if ( json.skinWeights ) {
  7861. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  7862. var x = json.skinWeights[ i ];
  7863. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  7864. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  7865. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  7866. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  7867. }
  7868. }
  7869. if ( json.skinIndices ) {
  7870. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  7871. var a = json.skinIndices[ i ];
  7872. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  7873. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  7874. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  7875. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  7876. }
  7877. }
  7878. geometry.bones = json.bones;
  7879. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  7880. console.warn( 'THREE.JSONLoader: When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  7881. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  7882. }
  7883. // could change this to json.animations[0] or remove completely
  7884. geometry.animation = json.animation;
  7885. geometry.animations = json.animations;
  7886. }
  7887. function parseMorphing( scale ) {
  7888. if ( json.morphTargets !== undefined ) {
  7889. var i, l, v, vl, dstVertices, srcVertices;
  7890. for ( i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  7891. geometry.morphTargets[ i ] = {};
  7892. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  7893. geometry.morphTargets[ i ].vertices = [];
  7894. dstVertices = geometry.morphTargets[ i ].vertices;
  7895. srcVertices = json.morphTargets [ i ].vertices;
  7896. for ( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  7897. var vertex = new THREE.Vector3();
  7898. vertex.x = srcVertices[ v ] * scale;
  7899. vertex.y = srcVertices[ v + 1 ] * scale;
  7900. vertex.z = srcVertices[ v + 2 ] * scale;
  7901. dstVertices.push( vertex );
  7902. }
  7903. }
  7904. }
  7905. if ( json.morphColors !== undefined ) {
  7906. var i, l, c, cl, dstColors, srcColors, color;
  7907. for ( i = 0, l = json.morphColors.length; i < l; i ++ ) {
  7908. geometry.morphColors[ i ] = {};
  7909. geometry.morphColors[ i ].name = json.morphColors[ i ].name;
  7910. geometry.morphColors[ i ].colors = [];
  7911. dstColors = geometry.morphColors[ i ].colors;
  7912. srcColors = json.morphColors [ i ].colors;
  7913. for ( c = 0, cl = srcColors.length; c < cl; c += 3 ) {
  7914. color = new THREE.Color( 0xffaa00 );
  7915. color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
  7916. dstColors.push( color );
  7917. }
  7918. }
  7919. }
  7920. }
  7921. if ( json.materials === undefined || json.materials.length === 0 ) {
  7922. return { geometry: geometry };
  7923. } else {
  7924. var materials = this.initMaterials( json.materials, texturePath );
  7925. if ( this.needsTangents( materials ) ) {
  7926. geometry.computeTangents();
  7927. }
  7928. return { geometry: geometry, materials: materials };
  7929. }
  7930. };
  7931. // File:src/loaders/LoadingManager.js
  7932. /**
  7933. * @author mrdoob / http://mrdoob.com/
  7934. */
  7935. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  7936. var scope = this;
  7937. var loaded = 0, total = 0;
  7938. this.onLoad = onLoad;
  7939. this.onProgress = onProgress;
  7940. this.onError = onError;
  7941. this.itemStart = function ( url ) {
  7942. total ++;
  7943. };
  7944. this.itemEnd = function ( url ) {
  7945. loaded ++;
  7946. if ( scope.onProgress !== undefined ) {
  7947. scope.onProgress( url, loaded, total );
  7948. }
  7949. if ( loaded === total && scope.onLoad !== undefined ) {
  7950. scope.onLoad();
  7951. }
  7952. };
  7953. };
  7954. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  7955. // File:src/loaders/BufferGeometryLoader.js
  7956. /**
  7957. * @author mrdoob / http://mrdoob.com/
  7958. */
  7959. THREE.BufferGeometryLoader = function ( manager ) {
  7960. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7961. };
  7962. THREE.BufferGeometryLoader.prototype = {
  7963. constructor: THREE.BufferGeometryLoader,
  7964. load: function ( url, onLoad, onProgress, onError ) {
  7965. var scope = this;
  7966. var loader = new THREE.XHRLoader( scope.manager );
  7967. loader.setCrossOrigin( this.crossOrigin );
  7968. loader.load( url, function ( text ) {
  7969. onLoad( scope.parse( JSON.parse( text ) ) );
  7970. }, onProgress, onError );
  7971. },
  7972. setCrossOrigin: function ( value ) {
  7973. this.crossOrigin = value;
  7974. },
  7975. parse: function ( json ) {
  7976. var geometry = new THREE.BufferGeometry();
  7977. var attributes = json.data.attributes;
  7978. for ( var key in attributes ) {
  7979. var attribute = attributes[ key ];
  7980. var typedArray = new self[ attribute.type ]( attribute.array );
  7981. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  7982. }
  7983. var offsets = json.data.offsets;
  7984. if ( offsets !== undefined ) {
  7985. geometry.offsets = JSON.parse( JSON.stringify( offsets ) );
  7986. }
  7987. var boundingSphere = json.data.boundingSphere;
  7988. if ( boundingSphere !== undefined ) {
  7989. var center = new THREE.Vector3();
  7990. if ( boundingSphere.center !== undefined ) {
  7991. center.fromArray( boundingSphere.center );
  7992. }
  7993. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  7994. }
  7995. return geometry;
  7996. }
  7997. };
  7998. // File:src/loaders/MaterialLoader.js
  7999. /**
  8000. * @author mrdoob / http://mrdoob.com/
  8001. */
  8002. THREE.MaterialLoader = function ( manager ) {
  8003. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8004. };
  8005. THREE.MaterialLoader.prototype = {
  8006. constructor: THREE.MaterialLoader,
  8007. load: function ( url, onLoad, onProgress, onError ) {
  8008. var scope = this;
  8009. var loader = new THREE.XHRLoader( scope.manager );
  8010. loader.setCrossOrigin( this.crossOrigin );
  8011. loader.load( url, function ( text ) {
  8012. onLoad( scope.parse( JSON.parse( text ) ) );
  8013. }, onProgress, onError );
  8014. },
  8015. setCrossOrigin: function ( value ) {
  8016. this.crossOrigin = value;
  8017. },
  8018. parse: function ( json ) {
  8019. var material = new THREE[ json.type ];
  8020. if ( json.color !== undefined ) material.color.setHex( json.color );
  8021. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  8022. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  8023. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  8024. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  8025. if ( json.attributes !== undefined ) material.attributes = json.attributes;
  8026. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  8027. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  8028. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  8029. if ( json.shading !== undefined ) material.shading = json.shading;
  8030. if ( json.blending !== undefined ) material.blending = json.blending;
  8031. if ( json.side !== undefined ) material.side = json.side;
  8032. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  8033. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  8034. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  8035. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  8036. // for PointCloudMaterial
  8037. if ( json.size !== undefined ) material.size = json.size;
  8038. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  8039. if ( json.materials !== undefined ) {
  8040. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  8041. material.materials.push( this.parse( json.materials[ i ] ) );
  8042. }
  8043. }
  8044. return material;
  8045. }
  8046. };
  8047. // File:src/loaders/ObjectLoader.js
  8048. /**
  8049. * @author mrdoob / http://mrdoob.com/
  8050. */
  8051. THREE.ObjectLoader = function ( manager ) {
  8052. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8053. this.texturePath = '';
  8054. };
  8055. THREE.ObjectLoader.prototype = {
  8056. constructor: THREE.ObjectLoader,
  8057. load: function ( url, onLoad, onProgress, onError ) {
  8058. if ( this.texturePath === '' ) {
  8059. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  8060. }
  8061. var scope = this;
  8062. var loader = new THREE.XHRLoader( scope.manager );
  8063. loader.setCrossOrigin( this.crossOrigin );
  8064. loader.load( url, function ( text ) {
  8065. scope.parse( JSON.parse( text ), onLoad );
  8066. }, onProgress, onError );
  8067. },
  8068. setTexturePath: function ( value ) {
  8069. this.texturePath = value;
  8070. },
  8071. setCrossOrigin: function ( value ) {
  8072. this.crossOrigin = value;
  8073. },
  8074. parse: function ( json, onLoad ) {
  8075. var geometries = this.parseGeometries( json.geometries );
  8076. var images = this.parseImages( json.images, function () {
  8077. if ( onLoad !== undefined ) onLoad( object );
  8078. } );
  8079. var textures = this.parseTextures( json.textures, images );
  8080. var materials = this.parseMaterials( json.materials, textures );
  8081. var object = this.parseObject( json.object, geometries, materials );
  8082. if ( json.images === undefined || json.images.length === 0 ) {
  8083. if ( onLoad !== undefined ) onLoad( object );
  8084. }
  8085. return object;
  8086. },
  8087. parseGeometries: function ( json ) {
  8088. var geometries = {};
  8089. if ( json !== undefined ) {
  8090. var geometryLoader = new THREE.JSONLoader();
  8091. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  8092. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8093. var geometry;
  8094. var data = json[ i ];
  8095. switch ( data.type ) {
  8096. case 'PlaneGeometry':
  8097. case 'PlaneBufferGeometry':
  8098. geometry = new THREE[ data.type ](
  8099. data.width,
  8100. data.height,
  8101. data.widthSegments,
  8102. data.heightSegments
  8103. );
  8104. break;
  8105. case 'BoxGeometry':
  8106. case 'CubeGeometry': // backwards compatible
  8107. geometry = new THREE.BoxGeometry(
  8108. data.width,
  8109. data.height,
  8110. data.depth,
  8111. data.widthSegments,
  8112. data.heightSegments,
  8113. data.depthSegments
  8114. );
  8115. break;
  8116. case 'CircleGeometry':
  8117. geometry = new THREE.CircleGeometry(
  8118. data.radius,
  8119. data.segments
  8120. );
  8121. break;
  8122. case 'CylinderGeometry':
  8123. geometry = new THREE.CylinderGeometry(
  8124. data.radiusTop,
  8125. data.radiusBottom,
  8126. data.height,
  8127. data.radialSegments,
  8128. data.heightSegments,
  8129. data.openEnded
  8130. );
  8131. break;
  8132. case 'SphereGeometry':
  8133. geometry = new THREE.SphereGeometry(
  8134. data.radius,
  8135. data.widthSegments,
  8136. data.heightSegments,
  8137. data.phiStart,
  8138. data.phiLength,
  8139. data.thetaStart,
  8140. data.thetaLength
  8141. );
  8142. break;
  8143. case 'IcosahedronGeometry':
  8144. geometry = new THREE.IcosahedronGeometry(
  8145. data.radius,
  8146. data.detail
  8147. );
  8148. break;
  8149. case 'TorusGeometry':
  8150. geometry = new THREE.TorusGeometry(
  8151. data.radius,
  8152. data.tube,
  8153. data.radialSegments,
  8154. data.tubularSegments,
  8155. data.arc
  8156. );
  8157. break;
  8158. case 'TorusKnotGeometry':
  8159. geometry = new THREE.TorusKnotGeometry(
  8160. data.radius,
  8161. data.tube,
  8162. data.radialSegments,
  8163. data.tubularSegments,
  8164. data.p,
  8165. data.q,
  8166. data.heightScale
  8167. );
  8168. break;
  8169. case 'BufferGeometry':
  8170. geometry = bufferGeometryLoader.parse( data );
  8171. break;
  8172. case 'Geometry':
  8173. geometry = geometryLoader.parse( data.data ).geometry;
  8174. break;
  8175. case 'TextGeometry':
  8176. geometry = new THREE.TextGeometry(
  8177. data.text,
  8178. data.data
  8179. );
  8180. break;
  8181. }
  8182. geometry.uuid = data.uuid;
  8183. if ( data.name !== undefined ) geometry.name = data.name;
  8184. geometries[ data.uuid ] = geometry;
  8185. }
  8186. }
  8187. return geometries;
  8188. },
  8189. parseMaterials: function ( json, textures ) {
  8190. var materials = {};
  8191. if ( json !== undefined ) {
  8192. var getTexture = function ( name ) {
  8193. if ( textures[ name ] === undefined ) {
  8194. console.warn( 'THREE.ObjectLoader: Undefined texture', name );
  8195. }
  8196. return textures[ name ];
  8197. };
  8198. var loader = new THREE.MaterialLoader();
  8199. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8200. var data = json[ i ];
  8201. var material = loader.parse( data );
  8202. material.uuid = data.uuid;
  8203. if ( data.depthTest !== undefined ) material.depthTest = data.depthTest;
  8204. if ( data.depthWrite !== undefined ) material.depthWrite = data.depthWrite;
  8205. if ( data.name !== undefined ) material.name = data.name;
  8206. if ( data.map !== undefined ) material.map = getTexture( data.map );
  8207. if ( data.alphaMap !== undefined ) {
  8208. material.alphaMap = getTexture( data.alphaMap );
  8209. material.transparent = true;
  8210. }
  8211. if ( data.bumpMap !== undefined ) material.bumpMap = getTexture( data.bumpMap );
  8212. if ( data.bumpScale !== undefined ) material.bumpScale = data.bumpScale;
  8213. if ( data.normalMap !== undefined ) material.normalMap = getTexture( data.normalMap );
  8214. if ( data.normalScale ) material.normalScale = new THREE.Vector2( data.normalScale, data.normalScale );
  8215. if ( data.specularMap !== undefined ) material.specularMap = getTexture( data.specularMap );
  8216. if ( data.envMap !== undefined ) {
  8217. material.envMap = getTexture( data.envMap );
  8218. material.combine = THREE.MultiplyOperation;
  8219. }
  8220. if ( data.reflectivity ) material.reflectivity = data.reflectivity;
  8221. if ( data.lightMap !== undefined ) material.lightMap = getTexture( data.lightMap );
  8222. if ( data.lightMapIntensity !== undefined ) material.lightMapIntensity = data.lightMapIntensity;
  8223. if ( data.aoMap !== undefined ) material.aoMap = getTexture( data.aoMap );
  8224. if ( data.aoMapIntensity !== undefined ) material.aoMapIntensity = data.aoMapIntensity;
  8225. materials[ data.uuid ] = material;
  8226. }
  8227. }
  8228. return materials;
  8229. },
  8230. parseImages: function ( json, onLoad ) {
  8231. var scope = this;
  8232. var images = {};
  8233. if ( json !== undefined && json.length > 0 ) {
  8234. var manager = new THREE.LoadingManager( onLoad );
  8235. var loader = new THREE.ImageLoader( manager );
  8236. loader.setCrossOrigin( this.crossOrigin );
  8237. var loadImage = function ( url ) {
  8238. scope.manager.itemStart( url );
  8239. return loader.load( url, function () {
  8240. scope.manager.itemEnd( url );
  8241. } );
  8242. };
  8243. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8244. var image = json[ i ];
  8245. images[ image.uuid ] = loadImage( image.url );
  8246. }
  8247. }
  8248. return images;
  8249. },
  8250. parseTextures: function ( json, images ) {
  8251. function parseConstant( value ) {
  8252. if ( typeof( value ) === 'number' ) return value;
  8253. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  8254. return THREE[ value ];
  8255. }
  8256. var textures = {};
  8257. if ( json !== undefined ) {
  8258. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8259. var data = json[ i ];
  8260. if ( data.image === undefined ) {
  8261. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  8262. }
  8263. if ( images[ data.image ] === undefined ) {
  8264. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  8265. }
  8266. var texture = new THREE.Texture( images[ data.image ] );
  8267. texture.needsUpdate = true;
  8268. texture.uuid = data.uuid;
  8269. if ( data.name !== undefined ) texture.name = data.name;
  8270. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  8271. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  8272. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  8273. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  8274. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  8275. if ( Array.isArray( data.wrap ) ) {
  8276. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  8277. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  8278. }
  8279. textures[ data.uuid ] = texture;
  8280. }
  8281. }
  8282. return textures;
  8283. },
  8284. parseObject: function () {
  8285. var matrix = new THREE.Matrix4();
  8286. return function ( data, geometries, materials ) {
  8287. var object;
  8288. var getGeometry = function ( name ) {
  8289. if ( geometries[ name ] === undefined ) {
  8290. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  8291. }
  8292. return geometries[ name ];
  8293. };
  8294. var getMaterial = function ( name ) {
  8295. if ( materials[ name ] === undefined ) {
  8296. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  8297. }
  8298. return materials[ name ];
  8299. };
  8300. switch ( data.type ) {
  8301. case 'Scene':
  8302. object = new THREE.Scene();
  8303. break;
  8304. case 'PerspectiveCamera':
  8305. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  8306. break;
  8307. case 'OrthographicCamera':
  8308. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  8309. break;
  8310. case 'AmbientLight':
  8311. object = new THREE.AmbientLight( data.color );
  8312. break;
  8313. case 'DirectionalLight':
  8314. object = new THREE.DirectionalLight( data.color, data.intensity );
  8315. break;
  8316. case 'PointLight':
  8317. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  8318. break;
  8319. case 'SpotLight':
  8320. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
  8321. break;
  8322. case 'HemisphereLight':
  8323. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  8324. break;
  8325. case 'Mesh':
  8326. object = new THREE.Mesh( getGeometry( data.geometry ), getMaterial( data.material ) );
  8327. break;
  8328. case 'Line':
  8329. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  8330. break;
  8331. case 'PointCloud':
  8332. object = new THREE.PointCloud( getGeometry( data.geometry ), getMaterial( data.material ) );
  8333. break;
  8334. case 'Sprite':
  8335. object = new THREE.Sprite( getMaterial( data.material ) );
  8336. break;
  8337. case 'Group':
  8338. object = new THREE.Group();
  8339. break;
  8340. default:
  8341. object = new THREE.Object3D();
  8342. }
  8343. object.uuid = data.uuid;
  8344. if ( data.name !== undefined ) object.name = data.name;
  8345. if ( data.matrix !== undefined ) {
  8346. matrix.fromArray( data.matrix );
  8347. matrix.decompose( object.position, object.quaternion, object.scale );
  8348. } else {
  8349. if ( data.position !== undefined ) object.position.fromArray( data.position );
  8350. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  8351. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  8352. }
  8353. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  8354. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  8355. if ( data.visible !== undefined ) object.visible = data.visible;
  8356. if ( data.userData !== undefined ) object.userData = data.userData;
  8357. if ( data.children !== undefined ) {
  8358. for ( var child in data.children ) {
  8359. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  8360. }
  8361. }
  8362. return object;
  8363. }
  8364. }()
  8365. };
  8366. // File:src/loaders/TextureLoader.js
  8367. /**
  8368. * @author mrdoob / http://mrdoob.com/
  8369. */
  8370. THREE.TextureLoader = function ( manager ) {
  8371. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8372. };
  8373. THREE.TextureLoader.prototype = {
  8374. constructor: THREE.TextureLoader,
  8375. load: function ( url, onLoad, onProgress, onError ) {
  8376. var scope = this;
  8377. var loader = new THREE.ImageLoader( scope.manager );
  8378. loader.setCrossOrigin( this.crossOrigin );
  8379. loader.load( url, function ( image ) {
  8380. var texture = new THREE.Texture( image );
  8381. texture.needsUpdate = true;
  8382. if ( onLoad !== undefined ) {
  8383. onLoad( texture );
  8384. }
  8385. }, onProgress, onError );
  8386. },
  8387. setCrossOrigin: function ( value ) {
  8388. this.crossOrigin = value;
  8389. }
  8390. };
  8391. // File:src/loaders/BinaryTextureLoader.js
  8392. /**
  8393. * @author Nikos M. / https://github.com/foo123/
  8394. *
  8395. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  8396. */
  8397. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function () {
  8398. // override in sub classes
  8399. this._parser = null;
  8400. };
  8401. THREE.BinaryTextureLoader.prototype = {
  8402. constructor: THREE.BinaryTextureLoader,
  8403. load: function ( url, onLoad, onProgress, onError ) {
  8404. var scope = this;
  8405. var texture = new THREE.DataTexture( );
  8406. var loader = new THREE.XHRLoader();
  8407. loader.setResponseType( 'arraybuffer' );
  8408. loader.load( url, function ( buffer ) {
  8409. var texData = scope._parser( buffer );
  8410. if ( !texData ) return;
  8411. if ( undefined !== texData.image ) {
  8412. texture.image = texData.image;
  8413. } else if ( undefined !== texData.data ) {
  8414. texture.image.width = texData.width;
  8415. texture.image.height = texData.height;
  8416. texture.image.data = texData.data;
  8417. }
  8418. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  8419. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  8420. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  8421. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  8422. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  8423. if ( undefined !== texData.format ) {
  8424. texture.format = texData.format;
  8425. }
  8426. if ( undefined !== texData.type ) {
  8427. texture.type = texData.type;
  8428. }
  8429. if ( undefined !== texData.mipmaps ) {
  8430. texture.mipmaps = texData.mipmaps;
  8431. }
  8432. if ( 1 === texData.mipmapCount ) {
  8433. texture.minFilter = THREE.LinearFilter;
  8434. }
  8435. texture.needsUpdate = true;
  8436. if ( onLoad ) onLoad( texture, texData );
  8437. }, onProgress, onError );
  8438. return texture;
  8439. }
  8440. };
  8441. // File:src/loaders/CompressedTextureLoader.js
  8442. /**
  8443. * @author mrdoob / http://mrdoob.com/
  8444. *
  8445. * Abstract Base class to block based textures loader (dds, pvr, ...)
  8446. */
  8447. THREE.CompressedTextureLoader = function () {
  8448. // override in sub classes
  8449. this._parser = null;
  8450. };
  8451. THREE.CompressedTextureLoader.prototype = {
  8452. constructor: THREE.CompressedTextureLoader,
  8453. load: function ( url, onLoad, onError ) {
  8454. var scope = this;
  8455. var images = [];
  8456. var texture = new THREE.CompressedTexture();
  8457. texture.image = images;
  8458. var loader = new THREE.XHRLoader();
  8459. loader.setResponseType( 'arraybuffer' );
  8460. if ( Array.isArray( url ) ) {
  8461. var loaded = 0;
  8462. var loadTexture = function ( i ) {
  8463. loader.load( url[ i ], function ( buffer ) {
  8464. var texDatas = scope._parser( buffer, true );
  8465. images[ i ] = {
  8466. width: texDatas.width,
  8467. height: texDatas.height,
  8468. format: texDatas.format,
  8469. mipmaps: texDatas.mipmaps
  8470. };
  8471. loaded += 1;
  8472. if ( loaded === 6 ) {
  8473. if (texDatas.mipmapCount === 1)
  8474. texture.minFilter = THREE.LinearFilter;
  8475. texture.format = texDatas.format;
  8476. texture.needsUpdate = true;
  8477. if ( onLoad ) onLoad( texture );
  8478. }
  8479. } );
  8480. };
  8481. for ( var i = 0, il = url.length; i < il; ++ i ) {
  8482. loadTexture( i );
  8483. }
  8484. } else {
  8485. // compressed cubemap texture stored in a single DDS file
  8486. loader.load( url, function ( buffer ) {
  8487. var texDatas = scope._parser( buffer, true );
  8488. if ( texDatas.isCubemap ) {
  8489. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  8490. for ( var f = 0; f < faces; f ++ ) {
  8491. images[ f ] = { mipmaps : [] };
  8492. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  8493. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  8494. images[ f ].format = texDatas.format;
  8495. images[ f ].width = texDatas.width;
  8496. images[ f ].height = texDatas.height;
  8497. }
  8498. }
  8499. } else {
  8500. texture.image.width = texDatas.width;
  8501. texture.image.height = texDatas.height;
  8502. texture.mipmaps = texDatas.mipmaps;
  8503. }
  8504. if ( texDatas.mipmapCount === 1 ) {
  8505. texture.minFilter = THREE.LinearFilter;
  8506. }
  8507. texture.format = texDatas.format;
  8508. texture.needsUpdate = true;
  8509. if ( onLoad ) onLoad( texture );
  8510. } );
  8511. }
  8512. return texture;
  8513. }
  8514. };
  8515. // File:src/materials/Material.js
  8516. /**
  8517. * @author mrdoob / http://mrdoob.com/
  8518. * @author alteredq / http://alteredqualia.com/
  8519. */
  8520. THREE.Material = function () {
  8521. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  8522. this.uuid = THREE.Math.generateUUID();
  8523. this.name = '';
  8524. this.type = 'Material';
  8525. this.side = THREE.FrontSide;
  8526. this.opacity = 1;
  8527. this.transparent = false;
  8528. this.blending = THREE.NormalBlending;
  8529. this.blendSrc = THREE.SrcAlphaFactor;
  8530. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  8531. this.blendEquation = THREE.AddEquation;
  8532. this.blendSrcAlpha = null;
  8533. this.blendDstAlpha = null;
  8534. this.blendEquationAlpha = null;
  8535. this.depthFunc = THREE.LessEqualDepth;
  8536. this.depthTest = true;
  8537. this.depthWrite = true;
  8538. this.colorWrite = true;
  8539. this.polygonOffset = false;
  8540. this.polygonOffsetFactor = 0;
  8541. this.polygonOffsetUnits = 0;
  8542. this.alphaTest = 0;
  8543. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  8544. this.visible = true;
  8545. this._needsUpdate = true;
  8546. };
  8547. THREE.Material.prototype = {
  8548. constructor: THREE.Material,
  8549. get needsUpdate () {
  8550. return this._needsUpdate;
  8551. },
  8552. set needsUpdate ( value ) {
  8553. if ( value === true ) this.update();
  8554. this._needsUpdate = value;
  8555. },
  8556. setValues: function ( values ) {
  8557. if ( values === undefined ) return;
  8558. for ( var key in values ) {
  8559. var newValue = values[ key ];
  8560. if ( newValue === undefined ) {
  8561. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  8562. continue;
  8563. }
  8564. if ( key in this ) {
  8565. var currentValue = this[ key ];
  8566. if ( currentValue instanceof THREE.Color ) {
  8567. currentValue.set( newValue );
  8568. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  8569. currentValue.copy( newValue );
  8570. } else if ( key === 'overdraw' ) {
  8571. // ensure overdraw is backwards-compatible with legacy boolean type
  8572. this[ key ] = Number( newValue );
  8573. } else {
  8574. this[ key ] = newValue;
  8575. }
  8576. }
  8577. }
  8578. },
  8579. toJSON: function ( meta ) {
  8580. var data = {
  8581. metadata: {
  8582. version: 4.4,
  8583. type: 'Material',
  8584. generator: 'Material.toJSON'
  8585. }
  8586. };
  8587. // standard Material serialization
  8588. data.uuid = this.uuid;
  8589. data.type = this.type;
  8590. if ( this.name !== '' ) data.name = this.name;
  8591. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  8592. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  8593. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  8594. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  8595. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  8596. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  8597. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  8598. if ( this.bumpMap instanceof THREE.Texture ) {
  8599. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  8600. data.bumpScale = this.bumpScale;
  8601. }
  8602. if ( this.normalMap instanceof THREE.Texture ) {
  8603. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  8604. data.normalScale = this.normalScale; // Removed for now, causes issue in editor ui.js
  8605. }
  8606. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  8607. if ( this.envMap instanceof THREE.Texture ) {
  8608. data.envMap = this.envMap.toJSON( meta ).uuid;
  8609. data.reflectivity = this.reflectivity; // Scale behind envMap
  8610. }
  8611. if ( this.size !== undefined ) data.size = this.size;
  8612. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  8613. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  8614. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  8615. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  8616. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  8617. if ( this.opacity < 1 ) data.opacity = this.opacity;
  8618. if ( this.transparent === true ) data.transparent = this.transparent;
  8619. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  8620. return data;
  8621. },
  8622. clone: function ( material ) {
  8623. if ( material === undefined ) material = new THREE.Material();
  8624. material.name = this.name;
  8625. material.side = this.side;
  8626. material.opacity = this.opacity;
  8627. material.transparent = this.transparent;
  8628. material.blending = this.blending;
  8629. material.blendSrc = this.blendSrc;
  8630. material.blendDst = this.blendDst;
  8631. material.blendEquation = this.blendEquation;
  8632. material.blendSrcAlpha = this.blendSrcAlpha;
  8633. material.blendDstAlpha = this.blendDstAlpha;
  8634. material.blendEquationAlpha = this.blendEquationAlpha;
  8635. material.depthFunc = this.depthFunc;
  8636. material.depthTest = this.depthTest;
  8637. material.depthWrite = this.depthWrite;
  8638. material.polygonOffset = this.polygonOffset;
  8639. material.polygonOffsetFactor = this.polygonOffsetFactor;
  8640. material.polygonOffsetUnits = this.polygonOffsetUnits;
  8641. material.alphaTest = this.alphaTest;
  8642. material.overdraw = this.overdraw;
  8643. material.visible = this.visible;
  8644. return material;
  8645. },
  8646. update: function () {
  8647. this.dispatchEvent( { type: 'update' } );
  8648. },
  8649. dispose: function () {
  8650. this.dispatchEvent( { type: 'dispose' } );
  8651. }
  8652. };
  8653. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  8654. THREE.MaterialIdCount = 0;
  8655. // File:src/materials/LineBasicMaterial.js
  8656. /**
  8657. * @author mrdoob / http://mrdoob.com/
  8658. * @author alteredq / http://alteredqualia.com/
  8659. *
  8660. * parameters = {
  8661. * color: <hex>,
  8662. * opacity: <float>,
  8663. *
  8664. * blending: THREE.NormalBlending,
  8665. * depthTest: <bool>,
  8666. * depthWrite: <bool>,
  8667. *
  8668. * linewidth: <float>,
  8669. * linecap: "round",
  8670. * linejoin: "round",
  8671. *
  8672. * vertexColors: <bool>
  8673. *
  8674. * fog: <bool>
  8675. * }
  8676. */
  8677. THREE.LineBasicMaterial = function ( parameters ) {
  8678. THREE.Material.call( this );
  8679. this.type = 'LineBasicMaterial';
  8680. this.color = new THREE.Color( 0xffffff );
  8681. this.linewidth = 1;
  8682. this.linecap = 'round';
  8683. this.linejoin = 'round';
  8684. this.vertexColors = THREE.NoColors;
  8685. this.fog = true;
  8686. this.setValues( parameters );
  8687. };
  8688. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  8689. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  8690. THREE.LineBasicMaterial.prototype.clone = function () {
  8691. var material = new THREE.LineBasicMaterial();
  8692. THREE.Material.prototype.clone.call( this, material );
  8693. material.color.copy( this.color );
  8694. material.linewidth = this.linewidth;
  8695. material.linecap = this.linecap;
  8696. material.linejoin = this.linejoin;
  8697. material.vertexColors = this.vertexColors;
  8698. material.fog = this.fog;
  8699. return material;
  8700. };
  8701. // File:src/materials/LineDashedMaterial.js
  8702. /**
  8703. * @author alteredq / http://alteredqualia.com/
  8704. *
  8705. * parameters = {
  8706. * color: <hex>,
  8707. * opacity: <float>,
  8708. *
  8709. * blending: THREE.NormalBlending,
  8710. * depthTest: <bool>,
  8711. * depthWrite: <bool>,
  8712. *
  8713. * linewidth: <float>,
  8714. *
  8715. * scale: <float>,
  8716. * dashSize: <float>,
  8717. * gapSize: <float>,
  8718. *
  8719. * vertexColors: <bool>
  8720. *
  8721. * fog: <bool>
  8722. * }
  8723. */
  8724. THREE.LineDashedMaterial = function ( parameters ) {
  8725. THREE.Material.call( this );
  8726. this.type = 'LineDashedMaterial';
  8727. this.color = new THREE.Color( 0xffffff );
  8728. this.linewidth = 1;
  8729. this.scale = 1;
  8730. this.dashSize = 3;
  8731. this.gapSize = 1;
  8732. this.vertexColors = false;
  8733. this.fog = true;
  8734. this.setValues( parameters );
  8735. };
  8736. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  8737. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  8738. THREE.LineDashedMaterial.prototype.clone = function () {
  8739. var material = new THREE.LineDashedMaterial();
  8740. THREE.Material.prototype.clone.call( this, material );
  8741. material.color.copy( this.color );
  8742. material.linewidth = this.linewidth;
  8743. material.scale = this.scale;
  8744. material.dashSize = this.dashSize;
  8745. material.gapSize = this.gapSize;
  8746. material.vertexColors = this.vertexColors;
  8747. material.fog = this.fog;
  8748. return material;
  8749. };
  8750. // File:src/materials/MeshBasicMaterial.js
  8751. /**
  8752. * @author mrdoob / http://mrdoob.com/
  8753. * @author alteredq / http://alteredqualia.com/
  8754. *
  8755. * parameters = {
  8756. * color: <hex>,
  8757. * opacity: <float>,
  8758. * map: new THREE.Texture( <Image> ),
  8759. *
  8760. * aoMap: new THREE.Texture( <Image> ),
  8761. * aoMapIntensity: <float>
  8762. *
  8763. * specularMap: new THREE.Texture( <Image> ),
  8764. *
  8765. * alphaMap: new THREE.Texture( <Image> ),
  8766. *
  8767. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  8768. * combine: THREE.Multiply,
  8769. * reflectivity: <float>,
  8770. * refractionRatio: <float>,
  8771. *
  8772. * shading: THREE.SmoothShading,
  8773. * blending: THREE.NormalBlending,
  8774. * depthTest: <bool>,
  8775. * depthWrite: <bool>,
  8776. *
  8777. * wireframe: <boolean>,
  8778. * wireframeLinewidth: <float>,
  8779. *
  8780. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  8781. *
  8782. * skinning: <bool>,
  8783. * morphTargets: <bool>,
  8784. *
  8785. * fog: <bool>
  8786. * }
  8787. */
  8788. THREE.MeshBasicMaterial = function ( parameters ) {
  8789. THREE.Material.call( this );
  8790. this.type = 'MeshBasicMaterial';
  8791. this.color = new THREE.Color( 0xffffff ); // emissive
  8792. this.map = null;
  8793. this.aoMap = null;
  8794. this.aoMapIntensity = 1.0;
  8795. this.specularMap = null;
  8796. this.alphaMap = null;
  8797. this.envMap = null;
  8798. this.combine = THREE.MultiplyOperation;
  8799. this.reflectivity = 1;
  8800. this.refractionRatio = 0.98;
  8801. this.fog = true;
  8802. this.shading = THREE.SmoothShading;
  8803. this.wireframe = false;
  8804. this.wireframeLinewidth = 1;
  8805. this.wireframeLinecap = 'round';
  8806. this.wireframeLinejoin = 'round';
  8807. this.vertexColors = THREE.NoColors;
  8808. this.skinning = false;
  8809. this.morphTargets = false;
  8810. this.setValues( parameters );
  8811. };
  8812. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  8813. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  8814. THREE.MeshBasicMaterial.prototype.clone = function () {
  8815. var material = new THREE.MeshBasicMaterial();
  8816. THREE.Material.prototype.clone.call( this, material );
  8817. material.color.copy( this.color );
  8818. material.map = this.map;
  8819. material.aoMap = this.aoMap;
  8820. material.aoMapIntensity = this.aoMapIntensity;
  8821. material.specularMap = this.specularMap;
  8822. material.alphaMap = this.alphaMap;
  8823. material.envMap = this.envMap;
  8824. material.combine = this.combine;
  8825. material.reflectivity = this.reflectivity;
  8826. material.refractionRatio = this.refractionRatio;
  8827. material.fog = this.fog;
  8828. material.shading = this.shading;
  8829. material.wireframe = this.wireframe;
  8830. material.wireframeLinewidth = this.wireframeLinewidth;
  8831. material.wireframeLinecap = this.wireframeLinecap;
  8832. material.wireframeLinejoin = this.wireframeLinejoin;
  8833. material.vertexColors = this.vertexColors;
  8834. material.skinning = this.skinning;
  8835. material.morphTargets = this.morphTargets;
  8836. return material;
  8837. };
  8838. // File:src/materials/MeshLambertMaterial.js
  8839. /**
  8840. * @author mrdoob / http://mrdoob.com/
  8841. * @author alteredq / http://alteredqualia.com/
  8842. *
  8843. * parameters = {
  8844. * color: <hex>,
  8845. * emissive: <hex>,
  8846. * opacity: <float>,
  8847. *
  8848. * map: new THREE.Texture( <Image> ),
  8849. *
  8850. * specularMap: new THREE.Texture( <Image> ),
  8851. *
  8852. * alphaMap: new THREE.Texture( <Image> ),
  8853. *
  8854. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  8855. * combine: THREE.Multiply,
  8856. * reflectivity: <float>,
  8857. * refractionRatio: <float>,
  8858. *
  8859. * shading: THREE.SmoothShading,
  8860. * blending: THREE.NormalBlending,
  8861. * depthTest: <bool>,
  8862. * depthWrite: <bool>,
  8863. *
  8864. * wireframe: <boolean>,
  8865. * wireframeLinewidth: <float>,
  8866. *
  8867. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  8868. *
  8869. * skinning: <bool>,
  8870. * morphTargets: <bool>,
  8871. * morphNormals: <bool>,
  8872. *
  8873. * fog: <bool>
  8874. * }
  8875. */
  8876. THREE.MeshLambertMaterial = function ( parameters ) {
  8877. THREE.Material.call( this );
  8878. this.type = 'MeshLambertMaterial';
  8879. this.color = new THREE.Color( 0xffffff ); // diffuse
  8880. this.emissive = new THREE.Color( 0x000000 );
  8881. this.map = null;
  8882. this.specularMap = null;
  8883. this.alphaMap = null;
  8884. this.envMap = null;
  8885. this.combine = THREE.MultiplyOperation;
  8886. this.reflectivity = 1;
  8887. this.refractionRatio = 0.98;
  8888. this.fog = true;
  8889. this.shading = THREE.SmoothShading;
  8890. this.wireframe = false;
  8891. this.wireframeLinewidth = 1;
  8892. this.wireframeLinecap = 'round';
  8893. this.wireframeLinejoin = 'round';
  8894. this.vertexColors = THREE.NoColors;
  8895. this.skinning = false;
  8896. this.morphTargets = false;
  8897. this.morphNormals = false;
  8898. this.setValues( parameters );
  8899. };
  8900. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  8901. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  8902. THREE.MeshLambertMaterial.prototype.clone = function () {
  8903. var material = new THREE.MeshLambertMaterial();
  8904. THREE.Material.prototype.clone.call( this, material );
  8905. material.color.copy( this.color );
  8906. material.emissive.copy( this.emissive );
  8907. material.map = this.map;
  8908. material.specularMap = this.specularMap;
  8909. material.alphaMap = this.alphaMap;
  8910. material.envMap = this.envMap;
  8911. material.combine = this.combine;
  8912. material.reflectivity = this.reflectivity;
  8913. material.refractionRatio = this.refractionRatio;
  8914. material.fog = this.fog;
  8915. material.shading = this.shading;
  8916. material.wireframe = this.wireframe;
  8917. material.wireframeLinewidth = this.wireframeLinewidth;
  8918. material.wireframeLinecap = this.wireframeLinecap;
  8919. material.wireframeLinejoin = this.wireframeLinejoin;
  8920. material.vertexColors = this.vertexColors;
  8921. material.skinning = this.skinning;
  8922. material.morphTargets = this.morphTargets;
  8923. material.morphNormals = this.morphNormals;
  8924. return material;
  8925. };
  8926. // File:src/materials/MeshPhongMaterial.js
  8927. /**
  8928. * @author mrdoob / http://mrdoob.com/
  8929. * @author alteredq / http://alteredqualia.com/
  8930. *
  8931. * parameters = {
  8932. * color: <hex>,
  8933. * emissive: <hex>,
  8934. * specular: <hex>,
  8935. * shininess: <float>,
  8936. * opacity: <float>,
  8937. *
  8938. * map: new THREE.Texture( <Image> ),
  8939. *
  8940. * lightMap: new THREE.Texture( <Image> ),
  8941. * lightMapIntensity: <float>
  8942. *
  8943. * aoMap: new THREE.Texture( <Image> ),
  8944. * aoMapIntensity: <float>
  8945. *
  8946. * emissiveMap: new THREE.Texture( <Image> ),
  8947. *
  8948. * bumpMap: new THREE.Texture( <Image> ),
  8949. * bumpScale: <float>,
  8950. *
  8951. * normalMap: new THREE.Texture( <Image> ),
  8952. * normalScale: <Vector2>,
  8953. *
  8954. * specularMap: new THREE.Texture( <Image> ),
  8955. *
  8956. * alphaMap: new THREE.Texture( <Image> ),
  8957. *
  8958. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  8959. * combine: THREE.Multiply,
  8960. * reflectivity: <float>,
  8961. * refractionRatio: <float>,
  8962. *
  8963. * shading: THREE.SmoothShading,
  8964. * blending: THREE.NormalBlending,
  8965. * depthTest: <bool>,
  8966. * depthWrite: <bool>,
  8967. *
  8968. * wireframe: <boolean>,
  8969. * wireframeLinewidth: <float>,
  8970. *
  8971. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  8972. *
  8973. * skinning: <bool>,
  8974. * morphTargets: <bool>,
  8975. * morphNormals: <bool>,
  8976. *
  8977. * fog: <bool>
  8978. * }
  8979. */
  8980. THREE.MeshPhongMaterial = function ( parameters ) {
  8981. THREE.Material.call( this );
  8982. this.type = 'MeshPhongMaterial';
  8983. this.color = new THREE.Color( 0xffffff ); // diffuse
  8984. this.emissive = new THREE.Color( 0x000000 );
  8985. this.specular = new THREE.Color( 0x111111 );
  8986. this.shininess = 30;
  8987. this.metal = false;
  8988. this.map = null;
  8989. this.lightMap = null;
  8990. this.lightMapIntensity = 1.0;
  8991. this.aoMap = null;
  8992. this.aoMapIntensity = 1.0;
  8993. this.emissiveMap = null;
  8994. this.bumpMap = null;
  8995. this.bumpScale = 1;
  8996. this.normalMap = null;
  8997. this.normalScale = new THREE.Vector2( 1, 1 );
  8998. this.specularMap = null;
  8999. this.alphaMap = null;
  9000. this.envMap = null;
  9001. this.combine = THREE.MultiplyOperation;
  9002. this.reflectivity = 1;
  9003. this.refractionRatio = 0.98;
  9004. this.fog = true;
  9005. this.shading = THREE.SmoothShading;
  9006. this.wireframe = false;
  9007. this.wireframeLinewidth = 1;
  9008. this.wireframeLinecap = 'round';
  9009. this.wireframeLinejoin = 'round';
  9010. this.vertexColors = THREE.NoColors;
  9011. this.skinning = false;
  9012. this.morphTargets = false;
  9013. this.morphNormals = false;
  9014. this.setValues( parameters );
  9015. };
  9016. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  9017. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  9018. THREE.MeshPhongMaterial.prototype.clone = function () {
  9019. var material = new THREE.MeshPhongMaterial();
  9020. THREE.Material.prototype.clone.call( this, material );
  9021. material.color.copy( this.color );
  9022. material.emissive.copy( this.emissive );
  9023. material.specular.copy( this.specular );
  9024. material.shininess = this.shininess;
  9025. material.metal = this.metal;
  9026. material.map = this.map;
  9027. material.lightMap = this.lightMap;
  9028. material.lightMapIntensity = this.lightMapIntensity;
  9029. material.aoMap = this.aoMap;
  9030. material.aoMapIntensity = this.aoMapIntensity;
  9031. material.emissiveMap = this.emissiveMap;
  9032. material.bumpMap = this.bumpMap;
  9033. material.bumpScale = this.bumpScale;
  9034. material.normalMap = this.normalMap;
  9035. material.normalScale.copy( this.normalScale );
  9036. material.specularMap = this.specularMap;
  9037. material.alphaMap = this.alphaMap;
  9038. material.envMap = this.envMap;
  9039. material.combine = this.combine;
  9040. material.reflectivity = this.reflectivity;
  9041. material.refractionRatio = this.refractionRatio;
  9042. material.fog = this.fog;
  9043. material.shading = this.shading;
  9044. material.wireframe = this.wireframe;
  9045. material.wireframeLinewidth = this.wireframeLinewidth;
  9046. material.wireframeLinecap = this.wireframeLinecap;
  9047. material.wireframeLinejoin = this.wireframeLinejoin;
  9048. material.vertexColors = this.vertexColors;
  9049. material.skinning = this.skinning;
  9050. material.morphTargets = this.morphTargets;
  9051. material.morphNormals = this.morphNormals;
  9052. return material;
  9053. };
  9054. // File:src/materials/MeshDepthMaterial.js
  9055. /**
  9056. * @author mrdoob / http://mrdoob.com/
  9057. * @author alteredq / http://alteredqualia.com/
  9058. *
  9059. * parameters = {
  9060. * opacity: <float>,
  9061. *
  9062. * blending: THREE.NormalBlending,
  9063. * depthTest: <bool>,
  9064. * depthWrite: <bool>,
  9065. *
  9066. * wireframe: <boolean>,
  9067. * wireframeLinewidth: <float>
  9068. * }
  9069. */
  9070. THREE.MeshDepthMaterial = function ( parameters ) {
  9071. THREE.Material.call( this );
  9072. this.type = 'MeshDepthMaterial';
  9073. this.morphTargets = false;
  9074. this.wireframe = false;
  9075. this.wireframeLinewidth = 1;
  9076. this.setValues( parameters );
  9077. };
  9078. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  9079. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  9080. THREE.MeshDepthMaterial.prototype.clone = function () {
  9081. var material = new THREE.MeshDepthMaterial();
  9082. THREE.Material.prototype.clone.call( this, material );
  9083. material.wireframe = this.wireframe;
  9084. material.wireframeLinewidth = this.wireframeLinewidth;
  9085. return material;
  9086. };
  9087. // File:src/materials/MeshNormalMaterial.js
  9088. /**
  9089. * @author mrdoob / http://mrdoob.com/
  9090. *
  9091. * parameters = {
  9092. * opacity: <float>,
  9093. *
  9094. * shading: THREE.FlatShading,
  9095. * blending: THREE.NormalBlending,
  9096. * depthTest: <bool>,
  9097. * depthWrite: <bool>,
  9098. *
  9099. * wireframe: <boolean>,
  9100. * wireframeLinewidth: <float>
  9101. * }
  9102. */
  9103. THREE.MeshNormalMaterial = function ( parameters ) {
  9104. THREE.Material.call( this, parameters );
  9105. this.type = 'MeshNormalMaterial';
  9106. this.wireframe = false;
  9107. this.wireframeLinewidth = 1;
  9108. this.morphTargets = false;
  9109. this.setValues( parameters );
  9110. };
  9111. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  9112. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  9113. THREE.MeshNormalMaterial.prototype.clone = function () {
  9114. var material = new THREE.MeshNormalMaterial();
  9115. THREE.Material.prototype.clone.call( this, material );
  9116. material.wireframe = this.wireframe;
  9117. material.wireframeLinewidth = this.wireframeLinewidth;
  9118. return material;
  9119. };
  9120. // File:src/materials/MeshFaceMaterial.js
  9121. /**
  9122. * @author mrdoob / http://mrdoob.com/
  9123. */
  9124. THREE.MeshFaceMaterial = function ( materials ) {
  9125. this.uuid = THREE.Math.generateUUID();
  9126. this.type = 'MeshFaceMaterial';
  9127. this.materials = materials instanceof Array ? materials : [];
  9128. };
  9129. THREE.MeshFaceMaterial.prototype = {
  9130. constructor: THREE.MeshFaceMaterial,
  9131. toJSON: function () {
  9132. var output = {
  9133. metadata: {
  9134. version: 4.2,
  9135. type: 'material',
  9136. generator: 'MaterialExporter'
  9137. },
  9138. uuid: this.uuid,
  9139. type: this.type,
  9140. materials: []
  9141. };
  9142. for ( var i = 0, l = this.materials.length; i < l; i ++ ) {
  9143. output.materials.push( this.materials[ i ].toJSON() );
  9144. }
  9145. return output;
  9146. },
  9147. clone: function () {
  9148. var material = new THREE.MeshFaceMaterial();
  9149. for ( var i = 0; i < this.materials.length; i ++ ) {
  9150. material.materials.push( this.materials[ i ].clone() );
  9151. }
  9152. return material;
  9153. }
  9154. };
  9155. // File:src/materials/PointCloudMaterial.js
  9156. /**
  9157. * @author mrdoob / http://mrdoob.com/
  9158. * @author alteredq / http://alteredqualia.com/
  9159. *
  9160. * parameters = {
  9161. * color: <hex>,
  9162. * opacity: <float>,
  9163. * map: new THREE.Texture( <Image> ),
  9164. *
  9165. * size: <float>,
  9166. * sizeAttenuation: <bool>,
  9167. *
  9168. * blending: THREE.NormalBlending,
  9169. * depthTest: <bool>,
  9170. * depthWrite: <bool>,
  9171. *
  9172. * vertexColors: <bool>,
  9173. *
  9174. * fog: <bool>
  9175. * }
  9176. */
  9177. THREE.PointCloudMaterial = function ( parameters ) {
  9178. THREE.Material.call( this );
  9179. this.type = 'PointCloudMaterial';
  9180. this.color = new THREE.Color( 0xffffff );
  9181. this.map = null;
  9182. this.size = 1;
  9183. this.sizeAttenuation = true;
  9184. this.vertexColors = THREE.NoColors;
  9185. this.fog = true;
  9186. this.setValues( parameters );
  9187. };
  9188. THREE.PointCloudMaterial.prototype = Object.create( THREE.Material.prototype );
  9189. THREE.PointCloudMaterial.prototype.constructor = THREE.PointCloudMaterial;
  9190. THREE.PointCloudMaterial.prototype.clone = function () {
  9191. var material = new THREE.PointCloudMaterial();
  9192. THREE.Material.prototype.clone.call( this, material );
  9193. material.color.copy( this.color );
  9194. material.map = this.map;
  9195. material.size = this.size;
  9196. material.sizeAttenuation = this.sizeAttenuation;
  9197. material.vertexColors = this.vertexColors;
  9198. material.fog = this.fog;
  9199. return material;
  9200. };
  9201. // backwards compatibility
  9202. THREE.ParticleBasicMaterial = function ( parameters ) {
  9203. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointCloudMaterial.' );
  9204. return new THREE.PointCloudMaterial( parameters );
  9205. };
  9206. THREE.ParticleSystemMaterial = function ( parameters ) {
  9207. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointCloudMaterial.' );
  9208. return new THREE.PointCloudMaterial( parameters );
  9209. };
  9210. // File:src/materials/ShaderMaterial.js
  9211. /**
  9212. * @author alteredq / http://alteredqualia.com/
  9213. *
  9214. * parameters = {
  9215. * defines: { "label" : "value" },
  9216. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  9217. *
  9218. * fragmentShader: <string>,
  9219. * vertexShader: <string>,
  9220. *
  9221. * shading: THREE.SmoothShading,
  9222. * blending: THREE.NormalBlending,
  9223. * depthTest: <bool>,
  9224. * depthWrite: <bool>,
  9225. *
  9226. * wireframe: <boolean>,
  9227. * wireframeLinewidth: <float>,
  9228. *
  9229. * lights: <bool>,
  9230. *
  9231. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9232. *
  9233. * skinning: <bool>,
  9234. * morphTargets: <bool>,
  9235. * morphNormals: <bool>,
  9236. *
  9237. * fog: <bool>
  9238. * }
  9239. */
  9240. THREE.ShaderMaterial = function ( parameters ) {
  9241. THREE.Material.call( this );
  9242. this.type = 'ShaderMaterial';
  9243. this.defines = {};
  9244. this.uniforms = {};
  9245. this.attributes = [];
  9246. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  9247. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  9248. this.shading = THREE.SmoothShading;
  9249. this.linewidth = 1;
  9250. this.wireframe = false;
  9251. this.wireframeLinewidth = 1;
  9252. this.fog = false; // set to use scene fog
  9253. this.lights = false; // set to use scene lights
  9254. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  9255. this.skinning = false; // set to use skinning attribute streams
  9256. this.morphTargets = false; // set to use morph targets
  9257. this.morphNormals = false; // set to use morph normals
  9258. this.derivatives = false; // set to use derivatives
  9259. // When rendered geometry doesn't include these attributes but the material does,
  9260. // use these default values in WebGL. This avoids errors when buffer data is missing.
  9261. this.defaultAttributeValues = {
  9262. 'color': [ 1, 1, 1 ],
  9263. 'uv': [ 0, 0 ],
  9264. 'uv2': [ 0, 0 ]
  9265. };
  9266. this.index0AttributeName = undefined;
  9267. if ( parameters !== undefined ) {
  9268. if ( parameters.attributes !== undefined && Array.isArray( parameters.attributes ) === false ) {
  9269. console.warn( 'THREE.ShaderMaterial: attributes should now be an array of attribute names.' );
  9270. parameters.attributes = Object.keys( parameters.attributes );
  9271. }
  9272. this.setValues( parameters );
  9273. }
  9274. };
  9275. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  9276. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  9277. THREE.ShaderMaterial.prototype.clone = function ( material ) {
  9278. if ( material === undefined ) material = new THREE.ShaderMaterial();
  9279. THREE.Material.prototype.clone.call( this, material );
  9280. material.fragmentShader = this.fragmentShader;
  9281. material.vertexShader = this.vertexShader;
  9282. material.uniforms = THREE.UniformsUtils.clone( this.uniforms );
  9283. material.attributes = this.attributes;
  9284. material.defines = this.defines;
  9285. material.shading = this.shading;
  9286. material.wireframe = this.wireframe;
  9287. material.wireframeLinewidth = this.wireframeLinewidth;
  9288. material.fog = this.fog;
  9289. material.lights = this.lights;
  9290. material.vertexColors = this.vertexColors;
  9291. material.skinning = this.skinning;
  9292. material.morphTargets = this.morphTargets;
  9293. material.morphNormals = this.morphNormals;
  9294. return material;
  9295. };
  9296. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  9297. var data = THREE.Material.prototype.toJSON.call( this, meta );
  9298. data.uniforms = this.uniforms;
  9299. data.attributes = this.attributes;
  9300. data.vertexShader = this.vertexShader;
  9301. data.fragmentShader = this.fragmentShader;
  9302. return data;
  9303. };
  9304. // File:src/materials/RawShaderMaterial.js
  9305. /**
  9306. * @author mrdoob / http://mrdoob.com/
  9307. */
  9308. THREE.RawShaderMaterial = function ( parameters ) {
  9309. THREE.ShaderMaterial.call( this, parameters );
  9310. this.type = 'RawShaderMaterial';
  9311. };
  9312. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  9313. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  9314. THREE.RawShaderMaterial.prototype.clone = function () {
  9315. var material = new THREE.RawShaderMaterial();
  9316. THREE.ShaderMaterial.prototype.clone.call( this, material );
  9317. return material;
  9318. };
  9319. // File:src/materials/SpriteMaterial.js
  9320. /**
  9321. * @author alteredq / http://alteredqualia.com/
  9322. *
  9323. * parameters = {
  9324. * color: <hex>,
  9325. * opacity: <float>,
  9326. * map: new THREE.Texture( <Image> ),
  9327. *
  9328. * blending: THREE.NormalBlending,
  9329. * depthTest: <bool>,
  9330. * depthWrite: <bool>,
  9331. *
  9332. * uvOffset: new THREE.Vector2(),
  9333. * uvScale: new THREE.Vector2(),
  9334. *
  9335. * fog: <bool>
  9336. * }
  9337. */
  9338. THREE.SpriteMaterial = function ( parameters ) {
  9339. THREE.Material.call( this );
  9340. this.type = 'SpriteMaterial';
  9341. this.color = new THREE.Color( 0xffffff );
  9342. this.map = null;
  9343. this.rotation = 0;
  9344. this.fog = false;
  9345. // set parameters
  9346. this.setValues( parameters );
  9347. };
  9348. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  9349. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  9350. THREE.SpriteMaterial.prototype.clone = function () {
  9351. var material = new THREE.SpriteMaterial();
  9352. THREE.Material.prototype.clone.call( this, material );
  9353. material.color.copy( this.color );
  9354. material.map = this.map;
  9355. material.rotation = this.rotation;
  9356. material.fog = this.fog;
  9357. return material;
  9358. };
  9359. // File:src/textures/Texture.js
  9360. /**
  9361. * @author mrdoob / http://mrdoob.com/
  9362. * @author alteredq / http://alteredqualia.com/
  9363. * @author szimek / https://github.com/szimek/
  9364. */
  9365. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9366. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  9367. this.uuid = THREE.Math.generateUUID();
  9368. this.name = '';
  9369. this.sourceFile = '';
  9370. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  9371. this.mipmaps = [];
  9372. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  9373. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  9374. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  9375. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  9376. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  9377. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  9378. this.format = format !== undefined ? format : THREE.RGBAFormat;
  9379. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  9380. this.offset = new THREE.Vector2( 0, 0 );
  9381. this.repeat = new THREE.Vector2( 1, 1 );
  9382. this.generateMipmaps = true;
  9383. this.premultiplyAlpha = false;
  9384. this.flipY = true;
  9385. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  9386. this._needsUpdate = false;
  9387. this.onUpdate = null;
  9388. };
  9389. THREE.Texture.DEFAULT_IMAGE = undefined;
  9390. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  9391. THREE.Texture.prototype = {
  9392. constructor: THREE.Texture,
  9393. get needsUpdate () {
  9394. return this._needsUpdate;
  9395. },
  9396. set needsUpdate ( value ) {
  9397. if ( value === true ) this.update();
  9398. this._needsUpdate = value;
  9399. },
  9400. clone: function ( texture ) {
  9401. if ( texture === undefined ) texture = new THREE.Texture();
  9402. texture.image = this.image;
  9403. texture.mipmaps = this.mipmaps.slice( 0 );
  9404. texture.mapping = this.mapping;
  9405. texture.wrapS = this.wrapS;
  9406. texture.wrapT = this.wrapT;
  9407. texture.magFilter = this.magFilter;
  9408. texture.minFilter = this.minFilter;
  9409. texture.anisotropy = this.anisotropy;
  9410. texture.format = this.format;
  9411. texture.type = this.type;
  9412. texture.offset.copy( this.offset );
  9413. texture.repeat.copy( this.repeat );
  9414. texture.generateMipmaps = this.generateMipmaps;
  9415. texture.premultiplyAlpha = this.premultiplyAlpha;
  9416. texture.flipY = this.flipY;
  9417. texture.unpackAlignment = this.unpackAlignment;
  9418. return texture;
  9419. },
  9420. toJSON: function ( meta ) {
  9421. if ( meta.textures[ this.uuid ] !== undefined ) {
  9422. return meta.textures[ this.uuid ];
  9423. }
  9424. function getDataURL( image ) {
  9425. var canvas;
  9426. if ( image.toDataURL !== undefined ) {
  9427. canvas = image;
  9428. } else {
  9429. canvas = document.createElement( 'canvas' );
  9430. canvas.width = image.width;
  9431. canvas.height = image.height;
  9432. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  9433. }
  9434. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  9435. return canvas.toDataURL( 'image/jpeg', 0.6 );
  9436. } else {
  9437. return canvas.toDataURL( 'image/png' );
  9438. }
  9439. }
  9440. var output = {
  9441. metadata: {
  9442. version: 4.4,
  9443. type: 'Texture',
  9444. generator: 'Texture.toJSON'
  9445. },
  9446. uuid: this.uuid,
  9447. name: this.name,
  9448. mapping: this.mapping,
  9449. repeat: [ this.repeat.x, this.repeat.y ],
  9450. offset: [ this.offset.x, this.offset.y ],
  9451. wrap: [ this.wrapS, this.wrapT ],
  9452. minFilter: this.minFilter,
  9453. magFilter: this.magFilter,
  9454. anisotropy: this.anisotropy
  9455. };
  9456. if ( this.image !== undefined ) {
  9457. // TODO: Move to THREE.Image
  9458. var image = this.image;
  9459. if ( image.uuid === undefined ) {
  9460. image.uuid = THREE.Math.generateUUID(); // UGH
  9461. }
  9462. if ( meta.images[ image.uuid ] === undefined ) {
  9463. meta.images[ image.uuid ] = {
  9464. uuid: image.uuid,
  9465. url: getDataURL( image )
  9466. };
  9467. }
  9468. output.image = image.uuid;
  9469. }
  9470. meta.textures[ this.uuid ] = output;
  9471. return output;
  9472. },
  9473. update: function () {
  9474. this.dispatchEvent( { type: 'update' } );
  9475. },
  9476. dispose: function () {
  9477. this.dispatchEvent( { type: 'dispose' } );
  9478. }
  9479. };
  9480. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  9481. THREE.TextureIdCount = 0;
  9482. // File:src/textures/CubeTexture.js
  9483. /**
  9484. * @author mrdoob / http://mrdoob.com/
  9485. */
  9486. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9487. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  9488. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9489. this.images = images;
  9490. };
  9491. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  9492. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  9493. THREE.CubeTexture.clone = function ( texture ) {
  9494. if ( texture === undefined ) texture = new THREE.CubeTexture();
  9495. THREE.Texture.prototype.clone.call( this, texture );
  9496. texture.images = this.images;
  9497. return texture;
  9498. };
  9499. // File:src/textures/CompressedTexture.js
  9500. /**
  9501. * @author alteredq / http://alteredqualia.com/
  9502. */
  9503. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  9504. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9505. this.image = { width: width, height: height };
  9506. this.mipmaps = mipmaps;
  9507. // no flipping for cube textures
  9508. // (also flipping doesn't work for compressed textures )
  9509. this.flipY = false;
  9510. // can't generate mipmaps for compressed textures
  9511. // mips must be embedded in DDS files
  9512. this.generateMipmaps = false;
  9513. };
  9514. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  9515. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  9516. THREE.CompressedTexture.prototype.clone = function () {
  9517. var texture = new THREE.CompressedTexture();
  9518. THREE.Texture.prototype.clone.call( this, texture );
  9519. return texture;
  9520. };
  9521. // File:src/textures/DataTexture.js
  9522. /**
  9523. * @author alteredq / http://alteredqualia.com/
  9524. */
  9525. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  9526. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9527. this.image = { data: data, width: width, height: height };
  9528. };
  9529. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  9530. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  9531. THREE.DataTexture.prototype.clone = function () {
  9532. var texture = new THREE.DataTexture();
  9533. THREE.Texture.prototype.clone.call( this, texture );
  9534. return texture;
  9535. };
  9536. // File:src/textures/VideoTexture.js
  9537. /**
  9538. * @author mrdoob / http://mrdoob.com/
  9539. */
  9540. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9541. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9542. this.generateMipmaps = false;
  9543. var scope = this;
  9544. var update = function () {
  9545. requestAnimationFrame( update );
  9546. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  9547. scope.needsUpdate = true;
  9548. }
  9549. };
  9550. update();
  9551. };
  9552. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  9553. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  9554. // File:src/objects/Group.js
  9555. /**
  9556. * @author mrdoob / http://mrdoob.com/
  9557. */
  9558. THREE.Group = function () {
  9559. THREE.Object3D.call( this );
  9560. this.type = 'Group';
  9561. };
  9562. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  9563. THREE.Group.prototype.constructor = THREE.Group;
  9564. THREE.Group.prototype.clone = function ( object ) {
  9565. if ( object === undefined ) object = new THREE.Group();
  9566. THREE.Object3D.prototype.clone.call( this, object );
  9567. return object;
  9568. };
  9569. // File:src/objects/PointCloud.js
  9570. /**
  9571. * @author alteredq / http://alteredqualia.com/
  9572. */
  9573. THREE.PointCloud = function ( geometry, material ) {
  9574. THREE.Object3D.call( this );
  9575. this.type = 'PointCloud';
  9576. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9577. this.material = material !== undefined ? material : new THREE.PointCloudMaterial( { color: Math.random() * 0xffffff } );
  9578. };
  9579. THREE.PointCloud.prototype = Object.create( THREE.Object3D.prototype );
  9580. THREE.PointCloud.prototype.constructor = THREE.PointCloud;
  9581. THREE.PointCloud.prototype.raycast = ( function () {
  9582. var inverseMatrix = new THREE.Matrix4();
  9583. var ray = new THREE.Ray();
  9584. return function ( raycaster, intersects ) {
  9585. var object = this;
  9586. var geometry = object.geometry;
  9587. var threshold = raycaster.params.PointCloud.threshold;
  9588. inverseMatrix.getInverse( this.matrixWorld );
  9589. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9590. if ( geometry.boundingBox !== null ) {
  9591. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  9592. return;
  9593. }
  9594. }
  9595. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  9596. var localThresholdSq = localThreshold * localThreshold;
  9597. var position = new THREE.Vector3();
  9598. var testPoint = function ( point, index ) {
  9599. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  9600. if ( rayPointDistanceSq < localThresholdSq ) {
  9601. var intersectPoint = ray.closestPointToPoint( point );
  9602. intersectPoint.applyMatrix4( object.matrixWorld );
  9603. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  9604. if ( distance < raycaster.near || distance > raycaster.far ) return;
  9605. intersects.push( {
  9606. distance: distance,
  9607. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  9608. point: intersectPoint.clone(),
  9609. index: index,
  9610. face: null,
  9611. object: object
  9612. } );
  9613. }
  9614. };
  9615. if ( geometry instanceof THREE.BufferGeometry ) {
  9616. var attributes = geometry.attributes;
  9617. var positions = attributes.position.array;
  9618. if ( attributes.index !== undefined ) {
  9619. var indices = attributes.index.array;
  9620. var offsets = geometry.offsets;
  9621. if ( offsets.length === 0 ) {
  9622. offsets.push( {
  9623. start: 0,
  9624. count: indices.length,
  9625. index: 0
  9626. } );
  9627. }
  9628. for ( var oi = 0, ol = offsets.length; oi < ol; ++ oi ) {
  9629. var offset = offsets[ oi ];
  9630. var start = offset.start;
  9631. var count = offset.count;
  9632. var index = offset.index;
  9633. for ( var i = start, il = start + count; i < il; i ++ ) {
  9634. var a = index + indices[ i ];
  9635. position.fromArray( positions, a * 3 );
  9636. testPoint( position, a );
  9637. }
  9638. }
  9639. } else {
  9640. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  9641. position.fromArray( positions, i * 3 );
  9642. testPoint( position, i );
  9643. }
  9644. }
  9645. } else {
  9646. var vertices = geometry.vertices;
  9647. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  9648. testPoint( vertices[ i ], i );
  9649. }
  9650. }
  9651. };
  9652. }() );
  9653. THREE.PointCloud.prototype.clone = function ( object ) {
  9654. if ( object === undefined ) object = new THREE.PointCloud( this.geometry, this.material );
  9655. THREE.Object3D.prototype.clone.call( this, object );
  9656. return object;
  9657. };
  9658. THREE.PointCloud.prototype.toJSON = function ( meta ) {
  9659. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9660. // only serialize if not in meta geometries cache
  9661. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  9662. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  9663. }
  9664. // only serialize if not in meta materials cache
  9665. if ( meta.materials[ this.material.uuid ] === undefined ) {
  9666. meta.materials[ this.material.uuid ] = this.material.toJSON();
  9667. }
  9668. data.object.geometry = this.geometry.uuid;
  9669. data.object.material = this.material.uuid;
  9670. return data;
  9671. };
  9672. // Backwards compatibility
  9673. THREE.ParticleSystem = function ( geometry, material ) {
  9674. console.warn( 'THREE.ParticleSystem has been renamed to THREE.PointCloud.' );
  9675. return new THREE.PointCloud( geometry, material );
  9676. };
  9677. // File:src/objects/Line.js
  9678. /**
  9679. * @author mrdoob / http://mrdoob.com/
  9680. */
  9681. THREE.Line = function ( geometry, material, mode ) {
  9682. if ( mode === 1 ) {
  9683. console.error( 'THREE.Line: THREE.LinePieces mode has been removed. Use THREE.LineSegments instead.' );
  9684. }
  9685. THREE.Object3D.call( this );
  9686. this.type = 'Line';
  9687. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9688. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  9689. };
  9690. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  9691. THREE.Line.prototype.constructor = THREE.Line;
  9692. THREE.Line.prototype.raycast = ( function () {
  9693. var inverseMatrix = new THREE.Matrix4();
  9694. var ray = new THREE.Ray();
  9695. var sphere = new THREE.Sphere();
  9696. return function ( raycaster, intersects ) {
  9697. var precision = raycaster.linePrecision;
  9698. var precisionSq = precision * precision;
  9699. var geometry = this.geometry;
  9700. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9701. // Checking boundingSphere distance to ray
  9702. sphere.copy( geometry.boundingSphere );
  9703. sphere.applyMatrix4( this.matrixWorld );
  9704. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  9705. return;
  9706. }
  9707. inverseMatrix.getInverse( this.matrixWorld );
  9708. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9709. var vStart = new THREE.Vector3();
  9710. var vEnd = new THREE.Vector3();
  9711. var interSegment = new THREE.Vector3();
  9712. var interRay = new THREE.Vector3();
  9713. var step = this instanceof THREE.LineSegments ? 2 : 1;
  9714. if ( geometry instanceof THREE.BufferGeometry ) {
  9715. var attributes = geometry.attributes;
  9716. if ( attributes.index !== undefined ) {
  9717. var indices = attributes.index.array;
  9718. var positions = attributes.position.array;
  9719. var offsets = geometry.offsets;
  9720. if ( offsets.length === 0 ) {
  9721. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  9722. }
  9723. for ( var oi = 0; oi < offsets.length; oi ++) {
  9724. var start = offsets[ oi ].start;
  9725. var count = offsets[ oi ].count;
  9726. var index = offsets[ oi ].index;
  9727. for ( var i = start; i < start + count - 1; i += step ) {
  9728. var a = index + indices[ i ];
  9729. var b = index + indices[ i + 1 ];
  9730. vStart.fromArray( positions, a * 3 );
  9731. vEnd.fromArray( positions, b * 3 );
  9732. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  9733. if ( distSq > precisionSq ) continue;
  9734. var distance = ray.origin.distanceTo( interRay );
  9735. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9736. intersects.push( {
  9737. distance: distance,
  9738. // What do we want? intersection point on the ray or on the segment??
  9739. // point: raycaster.ray.at( distance ),
  9740. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9741. index: i,
  9742. offsetIndex: oi,
  9743. face: null,
  9744. faceIndex: null,
  9745. object: this
  9746. } );
  9747. }
  9748. }
  9749. } else {
  9750. var positions = attributes.position.array;
  9751. for ( var i = 0; i < positions.length / 3 - 1; i += step ) {
  9752. vStart.fromArray( positions, 3 * i );
  9753. vEnd.fromArray( positions, 3 * i + 3 );
  9754. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  9755. if ( distSq > precisionSq ) continue;
  9756. var distance = ray.origin.distanceTo( interRay );
  9757. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9758. intersects.push( {
  9759. distance: distance,
  9760. // What do we want? intersection point on the ray or on the segment??
  9761. // point: raycaster.ray.at( distance ),
  9762. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9763. index: i,
  9764. face: null,
  9765. faceIndex: null,
  9766. object: this
  9767. } );
  9768. }
  9769. }
  9770. } else if ( geometry instanceof THREE.Geometry ) {
  9771. var vertices = geometry.vertices;
  9772. var nbVertices = vertices.length;
  9773. for ( var i = 0; i < nbVertices - 1; i += step ) {
  9774. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  9775. if ( distSq > precisionSq ) continue;
  9776. var distance = ray.origin.distanceTo( interRay );
  9777. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9778. intersects.push( {
  9779. distance: distance,
  9780. // What do we want? intersection point on the ray or on the segment??
  9781. // point: raycaster.ray.at( distance ),
  9782. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9783. index: i,
  9784. face: null,
  9785. faceIndex: null,
  9786. object: this
  9787. } );
  9788. }
  9789. }
  9790. };
  9791. }() );
  9792. THREE.Line.prototype.clone = function ( object ) {
  9793. if ( object === undefined ) object = new THREE[ this.type ]( this.geometry, this.material );
  9794. THREE.Object3D.prototype.clone.call( this, object );
  9795. return object;
  9796. };
  9797. THREE.Line.prototype.toJSON = function ( meta ) {
  9798. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9799. // only serialize if not in meta geometries cache
  9800. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  9801. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  9802. }
  9803. // only serialize if not in meta materials cache
  9804. if ( meta.materials[ this.material.uuid ] === undefined ) {
  9805. meta.materials[ this.material.uuid ] = this.material.toJSON();
  9806. }
  9807. data.object.geometry = this.geometry.uuid;
  9808. data.object.material = this.material.uuid;
  9809. return data;
  9810. };
  9811. // DEPRECATED
  9812. THREE.LineStrip = 0;
  9813. THREE.LinePieces = 1;
  9814. // File:src/objects/LineSegments.js
  9815. /**
  9816. * @author mrdoob / http://mrdoob.com/
  9817. */
  9818. THREE.LineSegments = function ( geometry, material ) {
  9819. THREE.Line.call( this, geometry, material );
  9820. this.type = 'LineSegments';
  9821. };
  9822. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  9823. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  9824. THREE.LineSegments.prototype.clone = function ( object ) {
  9825. if ( object === undefined ) object = new THREE.LineSegments( this.geometry, this.material );
  9826. THREE.Line.prototype.clone.call( this, object );
  9827. return object;
  9828. };
  9829. // File:src/objects/Mesh.js
  9830. /**
  9831. * @author mrdoob / http://mrdoob.com/
  9832. * @author alteredq / http://alteredqualia.com/
  9833. * @author mikael emtinger / http://gomo.se/
  9834. * @author jonobr1 / http://jonobr1.com/
  9835. */
  9836. THREE.Mesh = function ( geometry, material ) {
  9837. THREE.Object3D.call( this );
  9838. this.type = 'Mesh';
  9839. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9840. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  9841. this.updateMorphTargets();
  9842. };
  9843. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  9844. THREE.Mesh.prototype.constructor = THREE.Mesh;
  9845. THREE.Mesh.prototype.updateMorphTargets = function () {
  9846. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  9847. this.morphTargetBase = - 1;
  9848. this.morphTargetForcedOrder = [];
  9849. this.morphTargetInfluences = [];
  9850. this.morphTargetDictionary = {};
  9851. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  9852. this.morphTargetInfluences.push( 0 );
  9853. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  9854. }
  9855. }
  9856. };
  9857. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  9858. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  9859. return this.morphTargetDictionary[ name ];
  9860. }
  9861. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  9862. return 0;
  9863. };
  9864. THREE.Mesh.prototype.raycast = ( function () {
  9865. var inverseMatrix = new THREE.Matrix4();
  9866. var ray = new THREE.Ray();
  9867. var sphere = new THREE.Sphere();
  9868. var vA = new THREE.Vector3();
  9869. var vB = new THREE.Vector3();
  9870. var vC = new THREE.Vector3();
  9871. return function ( raycaster, intersects ) {
  9872. var geometry = this.geometry;
  9873. var material = this.material;
  9874. if ( material === undefined ) return;
  9875. // Checking boundingSphere distance to ray
  9876. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9877. sphere.copy( geometry.boundingSphere );
  9878. sphere.applyMatrix4( this.matrixWorld );
  9879. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  9880. return;
  9881. }
  9882. // Check boundingBox before continuing
  9883. inverseMatrix.getInverse( this.matrixWorld );
  9884. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9885. if ( geometry.boundingBox !== null ) {
  9886. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  9887. return;
  9888. }
  9889. }
  9890. var a, b, c;
  9891. if ( geometry instanceof THREE.BufferGeometry ) {
  9892. var attributes = geometry.attributes;
  9893. if ( attributes.index !== undefined ) {
  9894. var indices = attributes.index.array;
  9895. var positions = attributes.position.array;
  9896. var offsets = geometry.offsets;
  9897. if ( offsets.length === 0 ) {
  9898. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  9899. }
  9900. for ( var oi = 0, ol = offsets.length; oi < ol; ++ oi ) {
  9901. var start = offsets[ oi ].start;
  9902. var count = offsets[ oi ].count;
  9903. var index = offsets[ oi ].index;
  9904. for ( var i = start, il = start + count; i < il; i += 3 ) {
  9905. a = index + indices[ i ];
  9906. b = index + indices[ i + 1 ];
  9907. c = index + indices[ i + 2 ];
  9908. vA.fromArray( positions, a * 3 );
  9909. vB.fromArray( positions, b * 3 );
  9910. vC.fromArray( positions, c * 3 );
  9911. if ( material.side === THREE.BackSide ) {
  9912. var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
  9913. } else {
  9914. var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
  9915. }
  9916. if ( intersectionPoint === null ) continue;
  9917. intersectionPoint.applyMatrix4( this.matrixWorld );
  9918. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  9919. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9920. intersects.push( {
  9921. distance: distance,
  9922. point: intersectionPoint,
  9923. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  9924. faceIndex: Math.floor( i / 3 ), // triangle number in indices buffer semantics
  9925. object: this
  9926. } );
  9927. }
  9928. }
  9929. } else {
  9930. var positions = attributes.position.array;
  9931. for ( var i = 0, j = 0, il = positions.length; i < il; i += 3, j += 9 ) {
  9932. a = i;
  9933. b = i + 1;
  9934. c = i + 2;
  9935. vA.fromArray( positions, j );
  9936. vB.fromArray( positions, j + 3 );
  9937. vC.fromArray( positions, j + 6 );
  9938. if ( material.side === THREE.BackSide ) {
  9939. var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
  9940. } else {
  9941. var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
  9942. }
  9943. if ( intersectionPoint === null ) continue;
  9944. intersectionPoint.applyMatrix4( this.matrixWorld );
  9945. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  9946. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9947. intersects.push( {
  9948. distance: distance,
  9949. point: intersectionPoint,
  9950. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  9951. index: Math.floor(i/3), // triangle number in positions buffer semantics
  9952. object: this
  9953. } );
  9954. }
  9955. }
  9956. } else if ( geometry instanceof THREE.Geometry ) {
  9957. var isFaceMaterial = material instanceof THREE.MeshFaceMaterial;
  9958. var materials = isFaceMaterial === true ? material.materials : null;
  9959. var vertices = geometry.vertices;
  9960. var faces = geometry.faces;
  9961. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  9962. var face = faces[ f ];
  9963. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  9964. if ( faceMaterial === undefined ) continue;
  9965. a = vertices[ face.a ];
  9966. b = vertices[ face.b ];
  9967. c = vertices[ face.c ];
  9968. if ( faceMaterial.morphTargets === true ) {
  9969. var morphTargets = geometry.morphTargets;
  9970. var morphInfluences = this.morphTargetInfluences;
  9971. vA.set( 0, 0, 0 );
  9972. vB.set( 0, 0, 0 );
  9973. vC.set( 0, 0, 0 );
  9974. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  9975. var influence = morphInfluences[ t ];
  9976. if ( influence === 0 ) continue;
  9977. var targets = morphTargets[ t ].vertices;
  9978. vA.x += ( targets[ face.a ].x - a.x ) * influence;
  9979. vA.y += ( targets[ face.a ].y - a.y ) * influence;
  9980. vA.z += ( targets[ face.a ].z - a.z ) * influence;
  9981. vB.x += ( targets[ face.b ].x - b.x ) * influence;
  9982. vB.y += ( targets[ face.b ].y - b.y ) * influence;
  9983. vB.z += ( targets[ face.b ].z - b.z ) * influence;
  9984. vC.x += ( targets[ face.c ].x - c.x ) * influence;
  9985. vC.y += ( targets[ face.c ].y - c.y ) * influence;
  9986. vC.z += ( targets[ face.c ].z - c.z ) * influence;
  9987. }
  9988. vA.add( a );
  9989. vB.add( b );
  9990. vC.add( c );
  9991. a = vA;
  9992. b = vB;
  9993. c = vC;
  9994. }
  9995. if ( faceMaterial.side === THREE.BackSide ) {
  9996. var intersectionPoint = ray.intersectTriangle( c, b, a, true );
  9997. } else {
  9998. var intersectionPoint = ray.intersectTriangle( a, b, c, faceMaterial.side !== THREE.DoubleSide );
  9999. }
  10000. if ( intersectionPoint === null ) continue;
  10001. intersectionPoint.applyMatrix4( this.matrixWorld );
  10002. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  10003. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10004. intersects.push( {
  10005. distance: distance,
  10006. point: intersectionPoint,
  10007. face: face,
  10008. faceIndex: f,
  10009. object: this
  10010. } );
  10011. }
  10012. }
  10013. };
  10014. }() );
  10015. THREE.Mesh.prototype.clone = function ( object, recursive ) {
  10016. if ( object === undefined ) object = new THREE.Mesh( this.geometry, this.material );
  10017. THREE.Object3D.prototype.clone.call( this, object, recursive );
  10018. return object;
  10019. };
  10020. THREE.Mesh.prototype.toJSON = function ( meta ) {
  10021. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10022. // only serialize if not in meta geometries cache
  10023. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  10024. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  10025. }
  10026. // only serialize if not in meta materials cache
  10027. if ( meta.materials[ this.material.uuid ] === undefined ) {
  10028. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  10029. }
  10030. data.object.geometry = this.geometry.uuid;
  10031. data.object.material = this.material.uuid;
  10032. return data;
  10033. };
  10034. // File:src/objects/Bone.js
  10035. /**
  10036. * @author mikael emtinger / http://gomo.se/
  10037. * @author alteredq / http://alteredqualia.com/
  10038. * @author ikerr / http://verold.com
  10039. */
  10040. THREE.Bone = function ( skin ) {
  10041. THREE.Object3D.call( this );
  10042. this.type = 'Bone';
  10043. this.skin = skin;
  10044. };
  10045. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  10046. THREE.Bone.prototype.constructor = THREE.Bone;
  10047. THREE.Bone.prototype.clone = function ( object ) {
  10048. if ( object === undefined ) object = new THREE.Bone( this.skin );
  10049. THREE.Object3D.prototype.clone.call( this, object );
  10050. object.skin = this.skin;
  10051. return object;
  10052. };
  10053. // File:src/objects/Skeleton.js
  10054. /**
  10055. * @author mikael emtinger / http://gomo.se/
  10056. * @author alteredq / http://alteredqualia.com/
  10057. * @author michael guerrero / http://realitymeltdown.com
  10058. * @author ikerr / http://verold.com
  10059. */
  10060. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  10061. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  10062. this.identityMatrix = new THREE.Matrix4();
  10063. // copy the bone array
  10064. bones = bones || [];
  10065. this.bones = bones.slice( 0 );
  10066. // create a bone texture or an array of floats
  10067. if ( this.useVertexTexture ) {
  10068. // layout (1 matrix = 4 pixels)
  10069. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  10070. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  10071. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  10072. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  10073. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  10074. var size = THREE.Math.nextPowerOfTwo( Math.sqrt( this.bones.length * 4 ) ); // 4 pixels needed for 1 matrix
  10075. this.boneTextureWidth = size;
  10076. this.boneTextureHeight = size;
  10077. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  10078. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  10079. this.boneTexture.minFilter = THREE.NearestFilter;
  10080. this.boneTexture.magFilter = THREE.NearestFilter;
  10081. this.boneTexture.generateMipmaps = false;
  10082. this.boneTexture.flipY = false;
  10083. } else {
  10084. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  10085. }
  10086. // use the supplied bone inverses or calculate the inverses
  10087. if ( boneInverses === undefined ) {
  10088. this.calculateInverses();
  10089. } else {
  10090. if ( this.bones.length === boneInverses.length ) {
  10091. this.boneInverses = boneInverses.slice( 0 );
  10092. } else {
  10093. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  10094. this.boneInverses = [];
  10095. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10096. this.boneInverses.push( new THREE.Matrix4() );
  10097. }
  10098. }
  10099. }
  10100. };
  10101. THREE.Skeleton.prototype.calculateInverses = function () {
  10102. this.boneInverses = [];
  10103. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10104. var inverse = new THREE.Matrix4();
  10105. if ( this.bones[ b ] ) {
  10106. inverse.getInverse( this.bones[ b ].matrixWorld );
  10107. }
  10108. this.boneInverses.push( inverse );
  10109. }
  10110. };
  10111. THREE.Skeleton.prototype.pose = function () {
  10112. var bone;
  10113. // recover the bind-time world matrices
  10114. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10115. bone = this.bones[ b ];
  10116. if ( bone ) {
  10117. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  10118. }
  10119. }
  10120. // compute the local matrices, positions, rotations and scales
  10121. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10122. bone = this.bones[ b ];
  10123. if ( bone ) {
  10124. if ( bone.parent ) {
  10125. bone.matrix.getInverse( bone.parent.matrixWorld );
  10126. bone.matrix.multiply( bone.matrixWorld );
  10127. } else {
  10128. bone.matrix.copy( bone.matrixWorld );
  10129. }
  10130. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  10131. }
  10132. }
  10133. };
  10134. THREE.Skeleton.prototype.update = ( function () {
  10135. var offsetMatrix = new THREE.Matrix4();
  10136. return function () {
  10137. // flatten bone matrices to array
  10138. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10139. // compute the offset between the current and the original transform
  10140. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  10141. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  10142. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  10143. }
  10144. if ( this.useVertexTexture ) {
  10145. this.boneTexture.needsUpdate = true;
  10146. }
  10147. };
  10148. } )();
  10149. THREE.Skeleton.prototype.clone = function () {
  10150. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  10151. };
  10152. // File:src/objects/SkinnedMesh.js
  10153. /**
  10154. * @author mikael emtinger / http://gomo.se/
  10155. * @author alteredq / http://alteredqualia.com/
  10156. * @author ikerr / http://verold.com
  10157. */
  10158. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  10159. THREE.Mesh.call( this, geometry, material );
  10160. this.type = 'SkinnedMesh';
  10161. this.bindMode = "attached";
  10162. this.bindMatrix = new THREE.Matrix4();
  10163. this.bindMatrixInverse = new THREE.Matrix4();
  10164. // init bones
  10165. // TODO: remove bone creation as there is no reason (other than
  10166. // convenience) for THREE.SkinnedMesh to do this.
  10167. var bones = [];
  10168. if ( this.geometry && this.geometry.bones !== undefined ) {
  10169. var bone, gbone, p, q, s;
  10170. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  10171. gbone = this.geometry.bones[ b ];
  10172. p = gbone.pos;
  10173. q = gbone.rotq;
  10174. s = gbone.scl;
  10175. bone = new THREE.Bone( this );
  10176. bones.push( bone );
  10177. bone.name = gbone.name;
  10178. bone.position.set( p[ 0 ], p[ 1 ], p[ 2 ] );
  10179. bone.quaternion.set( q[ 0 ], q[ 1 ], q[ 2 ], q[ 3 ] );
  10180. if ( s !== undefined ) {
  10181. bone.scale.set( s[ 0 ], s[ 1 ], s[ 2 ] );
  10182. } else {
  10183. bone.scale.set( 1, 1, 1 );
  10184. }
  10185. }
  10186. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  10187. gbone = this.geometry.bones[ b ];
  10188. if ( gbone.parent !== - 1 ) {
  10189. bones[ gbone.parent ].add( bones[ b ] );
  10190. } else {
  10191. this.add( bones[ b ] );
  10192. }
  10193. }
  10194. }
  10195. this.normalizeSkinWeights();
  10196. this.updateMatrixWorld( true );
  10197. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ) );
  10198. };
  10199. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  10200. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  10201. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  10202. this.skeleton = skeleton;
  10203. if ( bindMatrix === undefined ) {
  10204. this.updateMatrixWorld( true );
  10205. bindMatrix = this.matrixWorld;
  10206. }
  10207. this.bindMatrix.copy( bindMatrix );
  10208. this.bindMatrixInverse.getInverse( bindMatrix );
  10209. };
  10210. THREE.SkinnedMesh.prototype.pose = function () {
  10211. this.skeleton.pose();
  10212. };
  10213. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  10214. if ( this.geometry instanceof THREE.Geometry ) {
  10215. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  10216. var sw = this.geometry.skinWeights[ i ];
  10217. var scale = 1.0 / sw.lengthManhattan();
  10218. if ( scale !== Infinity ) {
  10219. sw.multiplyScalar( scale );
  10220. } else {
  10221. sw.set( 1 ); // this will be normalized by the shader anyway
  10222. }
  10223. }
  10224. } else {
  10225. // skinning weights assumed to be normalized for THREE.BufferGeometry
  10226. }
  10227. };
  10228. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  10229. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  10230. if ( this.bindMode === "attached" ) {
  10231. this.bindMatrixInverse.getInverse( this.matrixWorld );
  10232. } else if ( this.bindMode === "detached" ) {
  10233. this.bindMatrixInverse.getInverse( this.bindMatrix );
  10234. } else {
  10235. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  10236. }
  10237. };
  10238. THREE.SkinnedMesh.prototype.clone = function( object ) {
  10239. if ( object === undefined ) {
  10240. object = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture );
  10241. }
  10242. THREE.Mesh.prototype.clone.call( this, object );
  10243. return object;
  10244. };
  10245. // File:src/objects/MorphAnimMesh.js
  10246. /**
  10247. * @author alteredq / http://alteredqualia.com/
  10248. */
  10249. THREE.MorphAnimMesh = function ( geometry, material ) {
  10250. THREE.Mesh.call( this, geometry, material );
  10251. this.type = 'MorphAnimMesh';
  10252. // API
  10253. this.duration = 1000; // milliseconds
  10254. this.mirroredLoop = false;
  10255. this.time = 0;
  10256. // internals
  10257. this.lastKeyframe = 0;
  10258. this.currentKeyframe = 0;
  10259. this.direction = 1;
  10260. this.directionBackwards = false;
  10261. this.setFrameRange( 0, this.geometry.morphTargets.length - 1 );
  10262. };
  10263. THREE.MorphAnimMesh.prototype = Object.create( THREE.Mesh.prototype );
  10264. THREE.MorphAnimMesh.prototype.constructor = THREE.MorphAnimMesh;
  10265. THREE.MorphAnimMesh.prototype.setFrameRange = function ( start, end ) {
  10266. this.startKeyframe = start;
  10267. this.endKeyframe = end;
  10268. this.length = this.endKeyframe - this.startKeyframe + 1;
  10269. };
  10270. THREE.MorphAnimMesh.prototype.setDirectionForward = function () {
  10271. this.direction = 1;
  10272. this.directionBackwards = false;
  10273. };
  10274. THREE.MorphAnimMesh.prototype.setDirectionBackward = function () {
  10275. this.direction = - 1;
  10276. this.directionBackwards = true;
  10277. };
  10278. THREE.MorphAnimMesh.prototype.parseAnimations = function () {
  10279. var geometry = this.geometry;
  10280. if ( ! geometry.animations ) geometry.animations = {};
  10281. var firstAnimation, animations = geometry.animations;
  10282. var pattern = /([a-z]+)_?(\d+)/;
  10283. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  10284. var morph = geometry.morphTargets[ i ];
  10285. var parts = morph.name.match( pattern );
  10286. if ( parts && parts.length > 1 ) {
  10287. var label = parts[ 1 ];
  10288. if ( ! animations[ label ] ) animations[ label ] = { start: Infinity, end: - Infinity };
  10289. var animation = animations[ label ];
  10290. if ( i < animation.start ) animation.start = i;
  10291. if ( i > animation.end ) animation.end = i;
  10292. if ( ! firstAnimation ) firstAnimation = label;
  10293. }
  10294. }
  10295. geometry.firstAnimation = firstAnimation;
  10296. };
  10297. THREE.MorphAnimMesh.prototype.setAnimationLabel = function ( label, start, end ) {
  10298. if ( ! this.geometry.animations ) this.geometry.animations = {};
  10299. this.geometry.animations[ label ] = { start: start, end: end };
  10300. };
  10301. THREE.MorphAnimMesh.prototype.playAnimation = function ( label, fps ) {
  10302. var animation = this.geometry.animations[ label ];
  10303. if ( animation ) {
  10304. this.setFrameRange( animation.start, animation.end );
  10305. this.duration = 1000 * ( ( animation.end - animation.start ) / fps );
  10306. this.time = 0;
  10307. } else {
  10308. console.warn( 'THREE.MorphAnimMesh: animation[' + label + '] undefined in .playAnimation()' );
  10309. }
  10310. };
  10311. THREE.MorphAnimMesh.prototype.updateAnimation = function ( delta ) {
  10312. var frameTime = this.duration / this.length;
  10313. this.time += this.direction * delta;
  10314. if ( this.mirroredLoop ) {
  10315. if ( this.time > this.duration || this.time < 0 ) {
  10316. this.direction *= - 1;
  10317. if ( this.time > this.duration ) {
  10318. this.time = this.duration;
  10319. this.directionBackwards = true;
  10320. }
  10321. if ( this.time < 0 ) {
  10322. this.time = 0;
  10323. this.directionBackwards = false;
  10324. }
  10325. }
  10326. } else {
  10327. this.time = this.time % this.duration;
  10328. if ( this.time < 0 ) this.time += this.duration;
  10329. }
  10330. var keyframe = this.startKeyframe + THREE.Math.clamp( Math.floor( this.time / frameTime ), 0, this.length - 1 );
  10331. if ( keyframe !== this.currentKeyframe ) {
  10332. this.morphTargetInfluences[ this.lastKeyframe ] = 0;
  10333. this.morphTargetInfluences[ this.currentKeyframe ] = 1;
  10334. this.morphTargetInfluences[ keyframe ] = 0;
  10335. this.lastKeyframe = this.currentKeyframe;
  10336. this.currentKeyframe = keyframe;
  10337. }
  10338. var mix = ( this.time % frameTime ) / frameTime;
  10339. if ( this.directionBackwards ) {
  10340. mix = 1 - mix;
  10341. }
  10342. this.morphTargetInfluences[ this.currentKeyframe ] = mix;
  10343. this.morphTargetInfluences[ this.lastKeyframe ] = 1 - mix;
  10344. };
  10345. THREE.MorphAnimMesh.prototype.interpolateTargets = function ( a, b, t ) {
  10346. var influences = this.morphTargetInfluences;
  10347. for ( var i = 0, l = influences.length; i < l; i ++ ) {
  10348. influences[ i ] = 0;
  10349. }
  10350. if ( a > -1 ) influences[ a ] = 1 - t;
  10351. if ( b > -1 ) influences[ b ] = t;
  10352. };
  10353. THREE.MorphAnimMesh.prototype.clone = function ( object ) {
  10354. if ( object === undefined ) object = new THREE.MorphAnimMesh( this.geometry, this.material );
  10355. object.duration = this.duration;
  10356. object.mirroredLoop = this.mirroredLoop;
  10357. object.time = this.time;
  10358. object.lastKeyframe = this.lastKeyframe;
  10359. object.currentKeyframe = this.currentKeyframe;
  10360. object.direction = this.direction;
  10361. object.directionBackwards = this.directionBackwards;
  10362. THREE.Mesh.prototype.clone.call( this, object );
  10363. return object;
  10364. };
  10365. // File:src/objects/LOD.js
  10366. /**
  10367. * @author mikael emtinger / http://gomo.se/
  10368. * @author alteredq / http://alteredqualia.com/
  10369. * @author mrdoob / http://mrdoob.com/
  10370. */
  10371. THREE.LOD = function () {
  10372. THREE.Object3D.call( this );
  10373. Object.defineProperties( this, {
  10374. levels: {
  10375. enumerable: true,
  10376. value: []
  10377. },
  10378. objects: {
  10379. get: function () {
  10380. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  10381. return this.levels;
  10382. }
  10383. }
  10384. } );
  10385. };
  10386. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  10387. THREE.LOD.prototype.constructor = THREE.LOD;
  10388. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  10389. if ( distance === undefined ) distance = 0;
  10390. distance = Math.abs( distance );
  10391. var levels = this.levels;
  10392. for ( var l = 0; l < levels.length; l ++ ) {
  10393. if ( distance < levels[ l ].distance ) {
  10394. break;
  10395. }
  10396. }
  10397. levels.splice( l, 0, { distance: distance, object: object } );
  10398. this.add( object );
  10399. };
  10400. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  10401. var levels = this.levels;
  10402. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  10403. if ( distance < levels[ i ].distance ) {
  10404. break;
  10405. }
  10406. }
  10407. return levels[ i - 1 ].object;
  10408. };
  10409. THREE.LOD.prototype.raycast = ( function () {
  10410. var matrixPosition = new THREE.Vector3();
  10411. return function ( raycaster, intersects ) {
  10412. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  10413. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  10414. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  10415. };
  10416. }() );
  10417. THREE.LOD.prototype.update = function () {
  10418. var v1 = new THREE.Vector3();
  10419. var v2 = new THREE.Vector3();
  10420. return function ( camera ) {
  10421. var levels = this.levels;
  10422. if ( levels.length > 1 ) {
  10423. v1.setFromMatrixPosition( camera.matrixWorld );
  10424. v2.setFromMatrixPosition( this.matrixWorld );
  10425. var distance = v1.distanceTo( v2 );
  10426. levels[ 0 ].object.visible = true;
  10427. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  10428. if ( distance >= levels[ i ].distance ) {
  10429. levels[ i - 1 ].object.visible = false;
  10430. levels[ i ].object.visible = true;
  10431. } else {
  10432. break;
  10433. }
  10434. }
  10435. for ( ; i < l; i ++ ) {
  10436. levels[ i ].object.visible = false;
  10437. }
  10438. }
  10439. };
  10440. }();
  10441. THREE.LOD.prototype.clone = function ( object ) {
  10442. if ( object === undefined ) object = new THREE.LOD();
  10443. THREE.Object3D.prototype.clone.call( this, object, false );
  10444. var levels = this.levels;
  10445. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  10446. var level = levels[ i ];
  10447. object.addLevel( level.object.clone(), level.distance );
  10448. }
  10449. return object;
  10450. };
  10451. // File:src/objects/Sprite.js
  10452. /**
  10453. * @author mikael emtinger / http://gomo.se/
  10454. * @author alteredq / http://alteredqualia.com/
  10455. */
  10456. THREE.Sprite = ( function () {
  10457. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  10458. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  10459. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  10460. var geometry = new THREE.BufferGeometry();
  10461. geometry.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
  10462. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  10463. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  10464. return function ( material ) {
  10465. THREE.Object3D.call( this );
  10466. this.type = 'Sprite';
  10467. this.geometry = geometry;
  10468. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  10469. };
  10470. } )();
  10471. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  10472. THREE.Sprite.prototype.constructor = THREE.Sprite;
  10473. THREE.Sprite.prototype.raycast = ( function () {
  10474. var matrixPosition = new THREE.Vector3();
  10475. return function ( raycaster, intersects ) {
  10476. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  10477. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  10478. var guessSizeSq = this.scale.x * this.scale.y;
  10479. if ( distanceSq > guessSizeSq ) {
  10480. return;
  10481. }
  10482. intersects.push( {
  10483. distance: Math.sqrt( distanceSq ),
  10484. point: this.position,
  10485. face: null,
  10486. object: this
  10487. } );
  10488. };
  10489. }() );
  10490. THREE.Sprite.prototype.clone = function ( object ) {
  10491. if ( object === undefined ) object = new THREE.Sprite( this.material );
  10492. THREE.Object3D.prototype.clone.call( this, object );
  10493. return object;
  10494. };
  10495. THREE.Sprite.prototype.toJSON = function ( meta ) {
  10496. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10497. // only serialize if not in meta materials cache
  10498. if ( meta.materials[ this.material.uuid ] === undefined ) {
  10499. meta.materials[ this.material.uuid ] = this.material.toJSON();
  10500. }
  10501. data.object.material = this.material.uuid;
  10502. return data;
  10503. };
  10504. // Backwards compatibility
  10505. THREE.Particle = THREE.Sprite;
  10506. // File:src/objects/LensFlare.js
  10507. /**
  10508. * @author mikael emtinger / http://gomo.se/
  10509. * @author alteredq / http://alteredqualia.com/
  10510. */
  10511. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  10512. THREE.Object3D.call( this );
  10513. this.lensFlares = [];
  10514. this.positionScreen = new THREE.Vector3();
  10515. this.customUpdateCallback = undefined;
  10516. if ( texture !== undefined ) {
  10517. this.add( texture, size, distance, blending, color );
  10518. }
  10519. };
  10520. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  10521. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  10522. /*
  10523. * Add: adds another flare
  10524. */
  10525. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  10526. if ( size === undefined ) size = - 1;
  10527. if ( distance === undefined ) distance = 0;
  10528. if ( opacity === undefined ) opacity = 1;
  10529. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  10530. if ( blending === undefined ) blending = THREE.NormalBlending;
  10531. distance = Math.min( distance, Math.max( 0, distance ) );
  10532. this.lensFlares.push( {
  10533. texture: texture, // THREE.Texture
  10534. size: size, // size in pixels (-1 = use texture.width)
  10535. distance: distance, // distance (0-1) from light source (0=at light source)
  10536. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  10537. scale: 1, // scale
  10538. rotation: 0, // rotation
  10539. opacity: opacity, // opacity
  10540. color: color, // color
  10541. blending: blending // blending
  10542. } );
  10543. };
  10544. /*
  10545. * Update lens flares update positions on all flares based on the screen position
  10546. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  10547. */
  10548. THREE.LensFlare.prototype.updateLensFlares = function () {
  10549. var f, fl = this.lensFlares.length;
  10550. var flare;
  10551. var vecX = - this.positionScreen.x * 2;
  10552. var vecY = - this.positionScreen.y * 2;
  10553. for ( f = 0; f < fl; f ++ ) {
  10554. flare = this.lensFlares[ f ];
  10555. flare.x = this.positionScreen.x + vecX * flare.distance;
  10556. flare.y = this.positionScreen.y + vecY * flare.distance;
  10557. flare.wantedRotation = flare.x * Math.PI * 0.25;
  10558. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  10559. }
  10560. };
  10561. THREE.LensFlare.prototype.clone = function ( object ) {
  10562. if ( object === undefined ) object = new THREE.LensFlare();
  10563. THREE.Object3D.prototype.clone.call( this, object );
  10564. object.positionScreen.copy( this.positionScreen );
  10565. object.customUpdateCallback = this.customUpdateCallback;
  10566. for ( var i = 0, l = this.lensFlares.length; i < l; i ++ ) {
  10567. object.lensFlares.push( this.lensFlares[ i ] );
  10568. }
  10569. return object;
  10570. };
  10571. // File:src/scenes/Scene.js
  10572. /**
  10573. * @author mrdoob / http://mrdoob.com/
  10574. */
  10575. THREE.Scene = function () {
  10576. THREE.Object3D.call( this );
  10577. this.type = 'Scene';
  10578. this.fog = null;
  10579. this.overrideMaterial = null;
  10580. this.autoUpdate = true; // checked by the renderer
  10581. };
  10582. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  10583. THREE.Scene.prototype.constructor = THREE.Scene;
  10584. THREE.Scene.prototype.clone = function ( object ) {
  10585. if ( object === undefined ) object = new THREE.Scene();
  10586. THREE.Object3D.prototype.clone.call( this, object );
  10587. if ( this.fog !== null ) object.fog = this.fog.clone();
  10588. if ( this.overrideMaterial !== null ) object.overrideMaterial = this.overrideMaterial.clone();
  10589. object.autoUpdate = this.autoUpdate;
  10590. object.matrixAutoUpdate = this.matrixAutoUpdate;
  10591. return object;
  10592. };
  10593. // File:src/scenes/Fog.js
  10594. /**
  10595. * @author mrdoob / http://mrdoob.com/
  10596. * @author alteredq / http://alteredqualia.com/
  10597. */
  10598. THREE.Fog = function ( color, near, far ) {
  10599. this.name = '';
  10600. this.color = new THREE.Color( color );
  10601. this.near = ( near !== undefined ) ? near : 1;
  10602. this.far = ( far !== undefined ) ? far : 1000;
  10603. };
  10604. THREE.Fog.prototype.clone = function () {
  10605. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  10606. };
  10607. // File:src/scenes/FogExp2.js
  10608. /**
  10609. * @author mrdoob / http://mrdoob.com/
  10610. * @author alteredq / http://alteredqualia.com/
  10611. */
  10612. THREE.FogExp2 = function ( color, density ) {
  10613. this.name = '';
  10614. this.color = new THREE.Color( color );
  10615. this.density = ( density !== undefined ) ? density : 0.00025;
  10616. };
  10617. THREE.FogExp2.prototype.clone = function () {
  10618. return new THREE.FogExp2( this.color.getHex(), this.density );
  10619. };
  10620. // File:src/renderers/shaders/ShaderChunk.js
  10621. THREE.ShaderChunk = {};
  10622. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  10623. THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n\n#endif\n";
  10624. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  10625. THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n\n uniform sampler2D alphaMap;\n\n#endif\n";
  10626. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  10627. THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n\n if ( diffuseColor.a < ALPHATEST ) discard;\n\n#endif\n";
  10628. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  10629. THREE.ShaderChunk[ 'aomap_fragment'] = "#ifdef USE_AOMAP\n\n totalAmbientLight *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n#endif\n";
  10630. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  10631. THREE.ShaderChunk[ 'aomap_pars_fragment'] = "#ifdef USE_AOMAP\n\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n\n#endif";
  10632. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  10633. 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";
  10634. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  10635. THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n\n diffuseColor.rgb *= vColor;\n\n#endif";
  10636. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  10637. THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif\n";
  10638. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  10639. THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif";
  10640. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  10641. THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n\n vColor.xyz = color.xyz;\n\n#endif";
  10642. // File:src/renderers/shaders/ShaderChunk/common.glsl
  10643. 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 return ( 1.0 - specularColor ) * pow( 1.0 - dotLH, 5.0 ) + 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";
  10644. // File:src/renderers/shaders/ShaderChunk/default_vertex.glsl
  10645. THREE.ShaderChunk[ 'default_vertex'] = "#ifdef USE_SKINNING\n\n vec4 mvPosition = modelViewMatrix * skinned;\n\n#elif defined( USE_MORPHTARGETS )\n\n vec4 mvPosition = modelViewMatrix * vec4( morphed, 1.0 );\n\n#else\n\n vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\n#endif\n\ngl_Position = projectionMatrix * mvPosition;\n";
  10646. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  10647. THREE.ShaderChunk[ 'defaultnormal_vertex'] = "#ifdef USE_SKINNING\n\n vec3 objectNormal = skinnedNormal.xyz;\n\n#elif defined( USE_MORPHNORMALS )\n\n vec3 objectNormal = morphedNormal;\n\n#else\n\n vec3 objectNormal = normal;\n\n#endif\n\n#ifdef FLIP_SIDED\n\n objectNormal = -objectNormal;\n\n#endif\n\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  10648. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  10649. 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";
  10650. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  10651. THREE.ShaderChunk[ 'emissivemap_pars_fragment'] = "#ifdef USE_EMISSIVEMAP\n\n uniform sampler2D emissiveMap;\n\n#endif\n";
  10652. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  10653. 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";
  10654. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  10655. 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";
  10656. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  10657. 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";
  10658. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  10659. THREE.ShaderChunk[ 'envmap_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG )\n\n vec3 worldNormal = transformDirection( objectNormal, modelMatrix );\n\n vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\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";
  10660. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  10661. 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";
  10662. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  10663. 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";
  10664. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  10665. THREE.ShaderChunk[ 'lightmap_fragment'] = "#ifdef USE_LIGHTMAP\n\n totalAmbientLight += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\n#endif\n";
  10666. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  10667. THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n\n#endif";
  10668. // File:src/renderers/shaders/ShaderChunk/lights_lambert_pars_vertex.glsl
  10669. 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";
  10670. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  10671. 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 vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\n vec3 lVector = lPosition.xyz - 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 vec4 lPosition = viewMatrix * vec4( lightPosition, 1.0 );\n vec3 lVector = lPosition.xyz - mvPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], normalize( lightPosition - worldPosition.xyz ) );\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 = transformDirection( directionalLightDirection[ i ], viewMatrix );\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 = transformDirection( hemisphereLightDirection[ i ], viewMatrix );\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";
  10672. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  10673. THREE.ShaderChunk[ 'lights_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\nvec3 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 vec4 lPosition = viewMatrix * vec4( lightPosition, 1.0 );\n vec3 lVector = lPosition.xyz + 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 vec4 lPosition = viewMatrix * vec4( lightPosition, 1.0 );\n vec3 lVector = lPosition.xyz + vViewPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], normalize( lightPosition - vWorldPosition ) );\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 = transformDirection( directionalLightDirection[ i ], viewMatrix );\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#if MAX_HEMI_LIGHTS > 0\n\n for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec3 lightDir = transformDirection( hemisphereLightDirection[ i ], viewMatrix );\n\n // diffuse\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 totalDiffuseLight += lightColor;\n\n // specular (sky term only)\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * max( dotProduct, 0.0 );\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";
  10674. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  10675. 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_BUMPMAP ) || 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";
  10676. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  10677. THREE.ShaderChunk[ 'lights_phong_pars_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n";
  10678. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  10679. THREE.ShaderChunk[ 'lights_phong_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n vWorldPosition = worldPosition.xyz;\n\n#endif";
  10680. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  10681. THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  10682. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  10683. THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n\n#endif";
  10684. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  10685. THREE.ShaderChunk[ 'logdepthbuf_pars_fragment'] = "#ifdef USE_LOGDEPTHBUF\n\n uniform float logDepthBufFC;\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n #extension GL_EXT_frag_depth : enable\n varying float vFragDepth;\n\n #endif\n\n#endif";
  10686. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  10687. 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";
  10688. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  10689. 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";
  10690. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  10691. 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";
  10692. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  10693. THREE.ShaderChunk[ 'map_pars_fragment'] = "#ifdef USE_MAP\n\n uniform sampler2D map;\n\n#endif";
  10694. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  10695. 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";
  10696. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  10697. THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n\n#endif\n";
  10698. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  10699. THREE.ShaderChunk[ 'morphnormal_vertex'] = "#ifdef USE_MORPHNORMALS\n\n vec3 morphedNormal = vec3( 0.0 );\n\n morphedNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n morphedNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n morphedNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n morphedNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n\n morphedNormal += normal;\n\n#endif";
  10700. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  10701. 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";
  10702. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  10703. THREE.ShaderChunk[ 'morphtarget_vertex'] = "#ifdef USE_MORPHTARGETS\n\n vec3 morphed = vec3( 0.0 );\n morphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n morphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n morphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n morphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n\n #ifndef USE_MORPHNORMALS\n\n morphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n morphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n morphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n morphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n\n #endif\n\n morphed += position;\n\n#endif";
  10704. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  10705. 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";
  10706. // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  10707. 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 #ifdef SHADOWMAP_CASCADE\n\n int inFrustumCount = 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 vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\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 // don't shadow pixels outside of light frustum\n // use just first frustum (for cascades)\n // don't shadow pixels behind far plane of light frustum\n\n #ifdef SHADOWMAP_CASCADE\n\n inFrustumCount += int( inFrustum );\n bvec3 frustumTestVec = bvec3( inFrustum, inFrustumCount == 1, shadowCoord.z <= 1.0 );\n\n #else\n\n bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\n #endif\n\n bool frustumTest = all( frustumTestVec );\n\n if ( frustumTest ) {\n\n shadowCoord.z += shadowBias[ i ];\n\n #if defined( SHADOWMAP_TYPE_PCF )\n\n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n\n float shadow = 0.0;\n\n /*\n // nested loops breaks shader compiler / validator on some ATI cards when using OpenGL\n // must enroll loop manually\n\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\n vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );\n\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\n float fDepth = unpackDepth( rgbaDepth );\n\n if ( fDepth < shadowCoord.z )\n shadow += 1.0;\n\n }\n\n shadow /= 9.0;\n\n */\n\n const float shadowDelta = 1.0 / 9.0;\n\n float xPixelOffset = 1.0 / shadowMapSize[ i ].x;\n float yPixelOffset = 1.0 / shadowMapSize[ i ].y;\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 shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );\n\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n\n float shadow = 0.0;\n\n float xPixelOffset = 1.0 / shadowMapSize[ i ].x;\n float yPixelOffset = 1.0 / shadowMapSize[ i ].y;\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 shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );\n\n #else\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 - shadowDarkness[ i ] );\n\n // spot with multiple shadows has the same color as single shadow spot\n\n // shadowColor = min( shadowColor, vec3( shadowDarkness[ i ] ) );\n\n #endif\n\n }\n\n\n #ifdef SHADOWMAP_DEBUG\n\n #ifdef SHADOWMAP_CASCADE\n\n if ( inFrustum && inFrustumCount == 1 ) outgoingLight *= frustumColors[ i ];\n\n #else\n\n if ( inFrustum ) outgoingLight *= frustumColors[ i ];\n\n #endif\n\n #endif\n\n }\n\n outgoingLight = outgoingLight * shadowColor;\n\n#endif\n";
  10708. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  10709. 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#endif";
  10710. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  10711. THREE.ShaderChunk[ 'shadowmap_pars_vertex'] = "#ifdef USE_SHADOWMAP\n\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n uniform mat4 shadowMatrix[ MAX_SHADOWS ];\n\n#endif";
  10712. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  10713. THREE.ShaderChunk[ 'shadowmap_vertex'] = "#ifdef USE_SHADOWMAP\n\n for( int i = 0; i < MAX_SHADOWS; i ++ ) {\n\n vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;\n\n }\n\n#endif";
  10714. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  10715. 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";
  10716. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  10717. 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";
  10718. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  10719. THREE.ShaderChunk[ 'skinning_vertex'] = "#ifdef USE_SKINNING\n\n #ifdef USE_MORPHTARGETS\n\n vec4 skinVertex = bindMatrix * vec4( morphed, 1.0 );\n\n #else\n\n vec4 skinVertex = bindMatrix * vec4( position, 1.0 );\n\n #endif\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";
  10720. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  10721. 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 #ifdef USE_MORPHNORMALS\n\n vec4 skinnedNormal = skinMatrix * vec4( morphedNormal, 0.0 );\n\n #else\n\n vec4 skinnedNormal = skinMatrix * vec4( normal, 0.0 );\n\n #endif\n\n#endif\n";
  10722. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  10723. 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";
  10724. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  10725. THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n\n uniform sampler2D specularMap;\n\n#endif";
  10726. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  10727. THREE.ShaderChunk[ 'uv2_pars_fragment'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n varying vec2 vUv2;\n\n#endif";
  10728. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  10729. THREE.ShaderChunk[ 'uv2_pars_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n attribute vec2 uv2;\n varying vec2 vUv2;\n\n#endif";
  10730. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  10731. THREE.ShaderChunk[ 'uv2_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n vUv2 = uv2;\n\n#endif";
  10732. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  10733. 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";
  10734. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  10735. 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";
  10736. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  10737. 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";
  10738. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  10739. 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 #elif defined( USE_MORPHTARGETS )\n\n vec4 worldPosition = modelMatrix * vec4( morphed, 1.0 );\n\n #else\n\n vec4 worldPosition = modelMatrix * vec4( position, 1.0 );\n\n #endif\n\n#endif\n";
  10740. // File:src/renderers/shaders/UniformsUtils.js
  10741. /**
  10742. * Uniform Utilities
  10743. */
  10744. THREE.UniformsUtils = {
  10745. merge: function ( uniforms ) {
  10746. var merged = {};
  10747. for ( var u = 0; u < uniforms.length; u ++ ) {
  10748. var tmp = this.clone( uniforms[ u ] );
  10749. for ( var p in tmp ) {
  10750. merged[ p ] = tmp[ p ];
  10751. }
  10752. }
  10753. return merged;
  10754. },
  10755. clone: function ( uniforms_src ) {
  10756. var uniforms_dst = {};
  10757. for ( var u in uniforms_src ) {
  10758. uniforms_dst[ u ] = {};
  10759. for ( var p in uniforms_src[ u ] ) {
  10760. var parameter_src = uniforms_src[ u ][ p ];
  10761. if ( parameter_src instanceof THREE.Color ||
  10762. parameter_src instanceof THREE.Vector2 ||
  10763. parameter_src instanceof THREE.Vector3 ||
  10764. parameter_src instanceof THREE.Vector4 ||
  10765. parameter_src instanceof THREE.Matrix3 ||
  10766. parameter_src instanceof THREE.Matrix4 ||
  10767. parameter_src instanceof THREE.Texture ) {
  10768. uniforms_dst[ u ][ p ] = parameter_src.clone();
  10769. } else if ( Array.isArray( parameter_src ) ) {
  10770. uniforms_dst[ u ][ p ] = parameter_src.slice();
  10771. } else {
  10772. uniforms_dst[ u ][ p ] = parameter_src;
  10773. }
  10774. }
  10775. }
  10776. return uniforms_dst;
  10777. }
  10778. };
  10779. // File:src/renderers/shaders/UniformsLib.js
  10780. /**
  10781. * Uniforms library for shared webgl shaders
  10782. */
  10783. THREE.UniformsLib = {
  10784. common: {
  10785. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  10786. "opacity" : { type: "f", value: 1.0 },
  10787. "map" : { type: "t", value: null },
  10788. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  10789. "specularMap" : { type: "t", value: null },
  10790. "alphaMap" : { type: "t", value: null },
  10791. "envMap" : { type: "t", value: null },
  10792. "flipEnvMap" : { type: "f", value: - 1 },
  10793. "reflectivity" : { type: "f", value: 1.0 },
  10794. "refractionRatio" : { type: "f", value: 0.98 }
  10795. },
  10796. aomap: {
  10797. "aoMap" : { type: "t", value: null },
  10798. "aoMapIntensity" : { type: "f", value: 1 },
  10799. },
  10800. lightmap: {
  10801. "lightMap" : { type: "t", value: null },
  10802. "lightMapIntensity" : { type: "f", value: 1 },
  10803. },
  10804. emissivemap: {
  10805. "emissiveMap" : { type: "t", value: null },
  10806. },
  10807. bump: {
  10808. "bumpMap" : { type: "t", value: null },
  10809. "bumpScale" : { type: "f", value: 1 }
  10810. },
  10811. normalmap: {
  10812. "normalMap" : { type: "t", value: null },
  10813. "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  10814. },
  10815. fog : {
  10816. "fogDensity" : { type: "f", value: 0.00025 },
  10817. "fogNear" : { type: "f", value: 1 },
  10818. "fogFar" : { type: "f", value: 2000 },
  10819. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  10820. },
  10821. lights: {
  10822. "ambientLightColor" : { type: "fv", value: [] },
  10823. "directionalLightDirection" : { type: "fv", value: [] },
  10824. "directionalLightColor" : { type: "fv", value: [] },
  10825. "hemisphereLightDirection" : { type: "fv", value: [] },
  10826. "hemisphereLightSkyColor" : { type: "fv", value: [] },
  10827. "hemisphereLightGroundColor" : { type: "fv", value: [] },
  10828. "pointLightColor" : { type: "fv", value: [] },
  10829. "pointLightPosition" : { type: "fv", value: [] },
  10830. "pointLightDistance" : { type: "fv1", value: [] },
  10831. "pointLightDecay" : { type: "fv1", value: [] },
  10832. "spotLightColor" : { type: "fv", value: [] },
  10833. "spotLightPosition" : { type: "fv", value: [] },
  10834. "spotLightDirection" : { type: "fv", value: [] },
  10835. "spotLightDistance" : { type: "fv1", value: [] },
  10836. "spotLightAngleCos" : { type: "fv1", value: [] },
  10837. "spotLightExponent" : { type: "fv1", value: [] },
  10838. "spotLightDecay" : { type: "fv1", value: [] }
  10839. },
  10840. particle: {
  10841. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  10842. "opacity" : { type: "f", value: 1.0 },
  10843. "size" : { type: "f", value: 1.0 },
  10844. "scale" : { type: "f", value: 1.0 },
  10845. "map" : { type: "t", value: null },
  10846. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  10847. "fogDensity" : { type: "f", value: 0.00025 },
  10848. "fogNear" : { type: "f", value: 1 },
  10849. "fogFar" : { type: "f", value: 2000 },
  10850. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  10851. },
  10852. shadowmap: {
  10853. "shadowMap": { type: "tv", value: [] },
  10854. "shadowMapSize": { type: "v2v", value: [] },
  10855. "shadowBias" : { type: "fv1", value: [] },
  10856. "shadowDarkness": { type: "fv1", value: [] },
  10857. "shadowMatrix" : { type: "m4v", value: [] }
  10858. }
  10859. };
  10860. // File:src/renderers/shaders/ShaderLib.js
  10861. /**
  10862. * Webgl Shader Library for three.js
  10863. *
  10864. * @author alteredq / http://alteredqualia.com/
  10865. * @author mrdoob / http://mrdoob.com/
  10866. * @author mikael emtinger / http://gomo.se/
  10867. */
  10868. THREE.ShaderLib = {
  10869. 'basic': {
  10870. uniforms: THREE.UniformsUtils.merge( [
  10871. THREE.UniformsLib[ "common" ],
  10872. THREE.UniformsLib[ "aomap" ],
  10873. THREE.UniformsLib[ "fog" ],
  10874. THREE.UniformsLib[ "shadowmap" ]
  10875. ] ),
  10876. vertexShader: [
  10877. THREE.ShaderChunk[ "common" ],
  10878. THREE.ShaderChunk[ "uv_pars_vertex" ],
  10879. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  10880. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  10881. THREE.ShaderChunk[ "color_pars_vertex" ],
  10882. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  10883. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  10884. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  10885. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  10886. "void main() {",
  10887. THREE.ShaderChunk[ "uv_vertex" ],
  10888. THREE.ShaderChunk[ "uv2_vertex" ],
  10889. THREE.ShaderChunk[ "color_vertex" ],
  10890. THREE.ShaderChunk[ "skinbase_vertex" ],
  10891. " #ifdef USE_ENVMAP",
  10892. THREE.ShaderChunk[ "morphnormal_vertex" ],
  10893. THREE.ShaderChunk[ "skinnormal_vertex" ],
  10894. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  10895. " #endif",
  10896. THREE.ShaderChunk[ "morphtarget_vertex" ],
  10897. THREE.ShaderChunk[ "skinning_vertex" ],
  10898. THREE.ShaderChunk[ "default_vertex" ],
  10899. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  10900. THREE.ShaderChunk[ "worldpos_vertex" ],
  10901. THREE.ShaderChunk[ "envmap_vertex" ],
  10902. THREE.ShaderChunk[ "shadowmap_vertex" ],
  10903. "}"
  10904. ].join("\n"),
  10905. fragmentShader: [
  10906. "uniform vec3 diffuse;",
  10907. "uniform float opacity;",
  10908. THREE.ShaderChunk[ "common" ],
  10909. THREE.ShaderChunk[ "color_pars_fragment" ],
  10910. THREE.ShaderChunk[ "uv_pars_fragment" ],
  10911. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  10912. THREE.ShaderChunk[ "map_pars_fragment" ],
  10913. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  10914. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  10915. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  10916. THREE.ShaderChunk[ "fog_pars_fragment" ],
  10917. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  10918. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  10919. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  10920. "void main() {",
  10921. " vec3 outgoingLight = vec3( 0.0 );",
  10922. " vec4 diffuseColor = vec4( diffuse, opacity );",
  10923. " vec3 totalAmbientLight = vec3( 1.0 );", // hardwired
  10924. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  10925. THREE.ShaderChunk[ "map_fragment" ],
  10926. THREE.ShaderChunk[ "color_fragment" ],
  10927. THREE.ShaderChunk[ "alphamap_fragment" ],
  10928. THREE.ShaderChunk[ "alphatest_fragment" ],
  10929. THREE.ShaderChunk[ "specularmap_fragment" ],
  10930. THREE.ShaderChunk[ "aomap_fragment" ],
  10931. " outgoingLight = diffuseColor.rgb * totalAmbientLight;", // simple shader
  10932. THREE.ShaderChunk[ "envmap_fragment" ],
  10933. THREE.ShaderChunk[ "shadowmap_fragment" ], // TODO: Shadows on an otherwise unlit surface doesn't make sense.
  10934. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  10935. THREE.ShaderChunk[ "fog_fragment" ],
  10936. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  10937. "}"
  10938. ].join("\n")
  10939. },
  10940. 'lambert': {
  10941. uniforms: THREE.UniformsUtils.merge( [
  10942. THREE.UniformsLib[ "common" ],
  10943. THREE.UniformsLib[ "fog" ],
  10944. THREE.UniformsLib[ "lights" ],
  10945. THREE.UniformsLib[ "shadowmap" ],
  10946. {
  10947. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  10948. }
  10949. ] ),
  10950. vertexShader: [
  10951. "#define LAMBERT",
  10952. "varying vec3 vLightFront;",
  10953. "#ifdef DOUBLE_SIDED",
  10954. " varying vec3 vLightBack;",
  10955. "#endif",
  10956. THREE.ShaderChunk[ "common" ],
  10957. THREE.ShaderChunk[ "uv_pars_vertex" ],
  10958. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  10959. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  10960. THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
  10961. THREE.ShaderChunk[ "color_pars_vertex" ],
  10962. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  10963. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  10964. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  10965. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  10966. "void main() {",
  10967. THREE.ShaderChunk[ "uv_vertex" ],
  10968. THREE.ShaderChunk[ "uv2_vertex" ],
  10969. THREE.ShaderChunk[ "color_vertex" ],
  10970. THREE.ShaderChunk[ "morphnormal_vertex" ],
  10971. THREE.ShaderChunk[ "skinbase_vertex" ],
  10972. THREE.ShaderChunk[ "skinnormal_vertex" ],
  10973. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  10974. THREE.ShaderChunk[ "morphtarget_vertex" ],
  10975. THREE.ShaderChunk[ "skinning_vertex" ],
  10976. THREE.ShaderChunk[ "default_vertex" ],
  10977. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  10978. THREE.ShaderChunk[ "worldpos_vertex" ],
  10979. THREE.ShaderChunk[ "envmap_vertex" ],
  10980. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  10981. THREE.ShaderChunk[ "shadowmap_vertex" ],
  10982. "}"
  10983. ].join("\n"),
  10984. fragmentShader: [
  10985. "uniform vec3 diffuse;",
  10986. "uniform vec3 emissive;",
  10987. "uniform float opacity;",
  10988. "varying vec3 vLightFront;",
  10989. "#ifdef DOUBLE_SIDED",
  10990. " varying vec3 vLightBack;",
  10991. "#endif",
  10992. THREE.ShaderChunk[ "common" ],
  10993. THREE.ShaderChunk[ "color_pars_fragment" ],
  10994. THREE.ShaderChunk[ "uv_pars_fragment" ],
  10995. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  10996. THREE.ShaderChunk[ "map_pars_fragment" ],
  10997. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  10998. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  10999. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11000. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11001. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11002. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11003. "void main() {",
  11004. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  11005. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11006. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11007. THREE.ShaderChunk[ "map_fragment" ],
  11008. THREE.ShaderChunk[ "color_fragment" ],
  11009. THREE.ShaderChunk[ "alphamap_fragment" ],
  11010. THREE.ShaderChunk[ "alphatest_fragment" ],
  11011. THREE.ShaderChunk[ "specularmap_fragment" ],
  11012. " #ifdef DOUBLE_SIDED",
  11013. " if ( gl_FrontFacing )",
  11014. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  11015. " else",
  11016. " outgoingLight += diffuseColor.rgb * vLightBack + emissive;",
  11017. " #else",
  11018. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  11019. " #endif",
  11020. THREE.ShaderChunk[ "envmap_fragment" ],
  11021. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11022. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11023. THREE.ShaderChunk[ "fog_fragment" ],
  11024. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11025. "}"
  11026. ].join("\n")
  11027. },
  11028. 'phong': {
  11029. uniforms: THREE.UniformsUtils.merge( [
  11030. THREE.UniformsLib[ "common" ],
  11031. THREE.UniformsLib[ "aomap" ],
  11032. THREE.UniformsLib[ "lightmap" ],
  11033. THREE.UniformsLib[ "emissivemap" ],
  11034. THREE.UniformsLib[ "bump" ],
  11035. THREE.UniformsLib[ "normalmap" ],
  11036. THREE.UniformsLib[ "fog" ],
  11037. THREE.UniformsLib[ "lights" ],
  11038. THREE.UniformsLib[ "shadowmap" ],
  11039. {
  11040. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  11041. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  11042. "shininess": { type: "f", value: 30 }
  11043. }
  11044. ] ),
  11045. vertexShader: [
  11046. "#define PHONG",
  11047. "varying vec3 vViewPosition;",
  11048. "#ifndef FLAT_SHADED",
  11049. " varying vec3 vNormal;",
  11050. "#endif",
  11051. THREE.ShaderChunk[ "common" ],
  11052. THREE.ShaderChunk[ "uv_pars_vertex" ],
  11053. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  11054. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  11055. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  11056. THREE.ShaderChunk[ "color_pars_vertex" ],
  11057. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11058. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11059. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11060. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11061. "void main() {",
  11062. THREE.ShaderChunk[ "uv_vertex" ],
  11063. THREE.ShaderChunk[ "uv2_vertex" ],
  11064. THREE.ShaderChunk[ "color_vertex" ],
  11065. THREE.ShaderChunk[ "morphnormal_vertex" ],
  11066. THREE.ShaderChunk[ "skinbase_vertex" ],
  11067. THREE.ShaderChunk[ "skinnormal_vertex" ],
  11068. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  11069. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  11070. " vNormal = normalize( transformedNormal );",
  11071. "#endif",
  11072. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11073. THREE.ShaderChunk[ "skinning_vertex" ],
  11074. THREE.ShaderChunk[ "default_vertex" ],
  11075. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11076. " vViewPosition = - mvPosition.xyz;",
  11077. THREE.ShaderChunk[ "worldpos_vertex" ],
  11078. THREE.ShaderChunk[ "envmap_vertex" ],
  11079. THREE.ShaderChunk[ "lights_phong_vertex" ],
  11080. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11081. "}"
  11082. ].join("\n"),
  11083. fragmentShader: [
  11084. "#define PHONG",
  11085. "uniform vec3 diffuse;",
  11086. "uniform vec3 emissive;",
  11087. "uniform vec3 specular;",
  11088. "uniform float shininess;",
  11089. "uniform float opacity;",
  11090. THREE.ShaderChunk[ "common" ],
  11091. THREE.ShaderChunk[ "color_pars_fragment" ],
  11092. THREE.ShaderChunk[ "uv_pars_fragment" ],
  11093. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  11094. THREE.ShaderChunk[ "map_pars_fragment" ],
  11095. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  11096. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  11097. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  11098. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  11099. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  11100. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11101. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  11102. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11103. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  11104. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  11105. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11106. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11107. "void main() {",
  11108. " vec3 outgoingLight = vec3( 0.0 );",
  11109. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11110. " vec3 totalAmbientLight = ambientLightColor;",
  11111. " vec3 totalEmissiveLight = emissive;",
  11112. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11113. THREE.ShaderChunk[ "map_fragment" ],
  11114. THREE.ShaderChunk[ "color_fragment" ],
  11115. THREE.ShaderChunk[ "alphamap_fragment" ],
  11116. THREE.ShaderChunk[ "alphatest_fragment" ],
  11117. THREE.ShaderChunk[ "specularmap_fragment" ],
  11118. THREE.ShaderChunk[ "lightmap_fragment" ],
  11119. THREE.ShaderChunk[ "aomap_fragment" ],
  11120. THREE.ShaderChunk[ "emissivemap_fragment" ],
  11121. THREE.ShaderChunk[ "lights_phong_fragment" ],
  11122. THREE.ShaderChunk[ "envmap_fragment" ],
  11123. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11124. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11125. THREE.ShaderChunk[ "fog_fragment" ],
  11126. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11127. "}"
  11128. ].join("\n")
  11129. },
  11130. 'particle_basic': {
  11131. uniforms: THREE.UniformsUtils.merge( [
  11132. THREE.UniformsLib[ "particle" ],
  11133. THREE.UniformsLib[ "shadowmap" ]
  11134. ] ),
  11135. vertexShader: [
  11136. "uniform float size;",
  11137. "uniform float scale;",
  11138. THREE.ShaderChunk[ "common" ],
  11139. THREE.ShaderChunk[ "color_pars_vertex" ],
  11140. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11141. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11142. "void main() {",
  11143. THREE.ShaderChunk[ "color_vertex" ],
  11144. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  11145. " #ifdef USE_SIZEATTENUATION",
  11146. " gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
  11147. " #else",
  11148. " gl_PointSize = size;",
  11149. " #endif",
  11150. " gl_Position = projectionMatrix * mvPosition;",
  11151. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11152. THREE.ShaderChunk[ "worldpos_vertex" ],
  11153. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11154. "}"
  11155. ].join("\n"),
  11156. fragmentShader: [
  11157. "uniform vec3 psColor;",
  11158. "uniform float opacity;",
  11159. THREE.ShaderChunk[ "common" ],
  11160. THREE.ShaderChunk[ "color_pars_fragment" ],
  11161. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  11162. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11163. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11164. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11165. "void main() {",
  11166. " vec3 outgoingLight = vec3( 0.0 );",
  11167. " vec4 diffuseColor = vec4( psColor, opacity );",
  11168. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11169. THREE.ShaderChunk[ "map_particle_fragment" ],
  11170. THREE.ShaderChunk[ "color_fragment" ],
  11171. THREE.ShaderChunk[ "alphatest_fragment" ],
  11172. " outgoingLight = diffuseColor.rgb;", // simple shader
  11173. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11174. THREE.ShaderChunk[ "fog_fragment" ],
  11175. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11176. "}"
  11177. ].join("\n")
  11178. },
  11179. 'dashed': {
  11180. uniforms: THREE.UniformsUtils.merge( [
  11181. THREE.UniformsLib[ "common" ],
  11182. THREE.UniformsLib[ "fog" ],
  11183. {
  11184. "scale" : { type: "f", value: 1 },
  11185. "dashSize" : { type: "f", value: 1 },
  11186. "totalSize": { type: "f", value: 2 }
  11187. }
  11188. ] ),
  11189. vertexShader: [
  11190. "uniform float scale;",
  11191. "attribute float lineDistance;",
  11192. "varying float vLineDistance;",
  11193. THREE.ShaderChunk[ "common" ],
  11194. THREE.ShaderChunk[ "color_pars_vertex" ],
  11195. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11196. "void main() {",
  11197. THREE.ShaderChunk[ "color_vertex" ],
  11198. " vLineDistance = scale * lineDistance;",
  11199. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  11200. " gl_Position = projectionMatrix * mvPosition;",
  11201. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11202. "}"
  11203. ].join("\n"),
  11204. fragmentShader: [
  11205. "uniform vec3 diffuse;",
  11206. "uniform float opacity;",
  11207. "uniform float dashSize;",
  11208. "uniform float totalSize;",
  11209. "varying float vLineDistance;",
  11210. THREE.ShaderChunk[ "common" ],
  11211. THREE.ShaderChunk[ "color_pars_fragment" ],
  11212. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11213. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11214. "void main() {",
  11215. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  11216. " discard;",
  11217. " }",
  11218. " vec3 outgoingLight = vec3( 0.0 );",
  11219. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11220. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11221. THREE.ShaderChunk[ "color_fragment" ],
  11222. " outgoingLight = diffuseColor.rgb;", // simple shader
  11223. THREE.ShaderChunk[ "fog_fragment" ],
  11224. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11225. "}"
  11226. ].join("\n")
  11227. },
  11228. 'depth': {
  11229. uniforms: {
  11230. "mNear": { type: "f", value: 1.0 },
  11231. "mFar" : { type: "f", value: 2000.0 },
  11232. "opacity" : { type: "f", value: 1.0 }
  11233. },
  11234. vertexShader: [
  11235. THREE.ShaderChunk[ "common" ],
  11236. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11237. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11238. "void main() {",
  11239. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11240. THREE.ShaderChunk[ "default_vertex" ],
  11241. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11242. "}"
  11243. ].join("\n"),
  11244. fragmentShader: [
  11245. "uniform float mNear;",
  11246. "uniform float mFar;",
  11247. "uniform float opacity;",
  11248. THREE.ShaderChunk[ "common" ],
  11249. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11250. "void main() {",
  11251. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11252. " #ifdef USE_LOGDEPTHBUF_EXT",
  11253. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  11254. " #else",
  11255. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  11256. " #endif",
  11257. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  11258. " gl_FragColor = vec4( vec3( color ), opacity );",
  11259. "}"
  11260. ].join("\n")
  11261. },
  11262. 'normal': {
  11263. uniforms: {
  11264. "opacity" : { type: "f", value: 1.0 }
  11265. },
  11266. vertexShader: [
  11267. "varying vec3 vNormal;",
  11268. THREE.ShaderChunk[ "common" ],
  11269. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11270. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11271. "void main() {",
  11272. " vNormal = normalize( normalMatrix * normal );",
  11273. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11274. THREE.ShaderChunk[ "default_vertex" ],
  11275. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11276. "}"
  11277. ].join("\n"),
  11278. fragmentShader: [
  11279. "uniform float opacity;",
  11280. "varying vec3 vNormal;",
  11281. THREE.ShaderChunk[ "common" ],
  11282. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11283. "void main() {",
  11284. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  11285. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11286. "}"
  11287. ].join("\n")
  11288. },
  11289. /* -------------------------------------------------------------------------
  11290. // Cube map shader
  11291. ------------------------------------------------------------------------- */
  11292. 'cube': {
  11293. uniforms: { "tCube": { type: "t", value: null },
  11294. "tFlip": { type: "f", value: - 1 } },
  11295. vertexShader: [
  11296. "varying vec3 vWorldPosition;",
  11297. THREE.ShaderChunk[ "common" ],
  11298. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11299. "void main() {",
  11300. " vWorldPosition = transformDirection( position, modelMatrix );",
  11301. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  11302. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11303. "}"
  11304. ].join("\n"),
  11305. fragmentShader: [
  11306. "uniform samplerCube tCube;",
  11307. "uniform float tFlip;",
  11308. "varying vec3 vWorldPosition;",
  11309. THREE.ShaderChunk[ "common" ],
  11310. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11311. "void main() {",
  11312. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  11313. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11314. "}"
  11315. ].join("\n")
  11316. },
  11317. /* -------------------------------------------------------------------------
  11318. // Cube map shader
  11319. ------------------------------------------------------------------------- */
  11320. 'equirect': {
  11321. uniforms: { "tEquirect": { type: "t", value: null },
  11322. "tFlip": { type: "f", value: - 1 } },
  11323. vertexShader: [
  11324. "varying vec3 vWorldPosition;",
  11325. THREE.ShaderChunk[ "common" ],
  11326. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11327. "void main() {",
  11328. " vWorldPosition = transformDirection( position, modelMatrix );",
  11329. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  11330. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11331. "}"
  11332. ].join("\n"),
  11333. fragmentShader: [
  11334. "uniform sampler2D tEquirect;",
  11335. "uniform float tFlip;",
  11336. "varying vec3 vWorldPosition;",
  11337. THREE.ShaderChunk[ "common" ],
  11338. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11339. "void main() {",
  11340. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  11341. "vec3 direction = normalize( vWorldPosition );",
  11342. "vec2 sampleUV;",
  11343. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  11344. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  11345. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  11346. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11347. "}"
  11348. ].join("\n")
  11349. },
  11350. /* Depth encoding into RGBA texture
  11351. *
  11352. * based on SpiderGL shadow map example
  11353. * http://spidergl.org/example.php?id=6
  11354. *
  11355. * originally from
  11356. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  11357. *
  11358. * see also
  11359. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  11360. */
  11361. 'depthRGBA': {
  11362. uniforms: {},
  11363. vertexShader: [
  11364. THREE.ShaderChunk[ "common" ],
  11365. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11366. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11367. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11368. "void main() {",
  11369. THREE.ShaderChunk[ "skinbase_vertex" ],
  11370. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11371. THREE.ShaderChunk[ "skinning_vertex" ],
  11372. THREE.ShaderChunk[ "default_vertex" ],
  11373. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11374. "}"
  11375. ].join("\n"),
  11376. fragmentShader: [
  11377. THREE.ShaderChunk[ "common" ],
  11378. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11379. "vec4 pack_depth( const in float depth ) {",
  11380. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  11381. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  11382. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
  11383. " res -= res.xxyz * bit_mask;",
  11384. " return res;",
  11385. "}",
  11386. "void main() {",
  11387. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11388. " #ifdef USE_LOGDEPTHBUF_EXT",
  11389. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  11390. " #else",
  11391. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  11392. " #endif",
  11393. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  11394. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  11395. //"gl_FragData[ 0 ] = pack_depth( z );",
  11396. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  11397. "}"
  11398. ].join("\n")
  11399. }
  11400. };
  11401. // File:src/renderers/WebGLRenderer.js
  11402. /**
  11403. * @author supereggbert / http://www.paulbrunt.co.uk/
  11404. * @author mrdoob / http://mrdoob.com/
  11405. * @author alteredq / http://alteredqualia.com/
  11406. * @author szimek / https://github.com/szimek/
  11407. */
  11408. THREE.WebGLRenderer = function ( parameters ) {
  11409. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  11410. parameters = parameters || {};
  11411. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  11412. _context = parameters.context !== undefined ? parameters.context : null,
  11413. _width = _canvas.width,
  11414. _height = _canvas.height,
  11415. pixelRatio = 1,
  11416. _precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  11417. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  11418. _depth = parameters.depth !== undefined ? parameters.depth : true,
  11419. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  11420. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  11421. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  11422. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  11423. _logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false,
  11424. _clearColor = new THREE.Color( 0x000000 ),
  11425. _clearAlpha = 0;
  11426. var lights = [];
  11427. var opaqueObjects = [];
  11428. var transparentObjects = [];
  11429. var sprites = [];
  11430. var lensFlares = [];
  11431. // public properties
  11432. this.domElement = _canvas;
  11433. this.context = null;
  11434. // clearing
  11435. this.autoClear = true;
  11436. this.autoClearColor = true;
  11437. this.autoClearDepth = true;
  11438. this.autoClearStencil = true;
  11439. // scene graph
  11440. this.sortObjects = true;
  11441. // physically based shading
  11442. this.gammaFactor = 2.0; // for backwards compatibility
  11443. this.gammaInput = false;
  11444. this.gammaOutput = false;
  11445. // morphs
  11446. this.maxMorphTargets = 8;
  11447. this.maxMorphNormals = 4;
  11448. // flags
  11449. this.autoScaleCubemaps = true;
  11450. // info
  11451. this.info = {
  11452. memory: {
  11453. programs: 0,
  11454. geometries: 0,
  11455. textures: 0
  11456. },
  11457. render: {
  11458. calls: 0,
  11459. vertices: 0,
  11460. faces: 0,
  11461. points: 0
  11462. }
  11463. };
  11464. // internal properties
  11465. var _this = this,
  11466. _programs = [],
  11467. // internal state cache
  11468. _currentProgram = null,
  11469. _currentFramebuffer = null,
  11470. _currentMaterialId = - 1,
  11471. _currentGeometryProgram = '',
  11472. _currentCamera = null,
  11473. _usedTextureUnits = 0,
  11474. _viewportX = 0,
  11475. _viewportY = 0,
  11476. _viewportWidth = _canvas.width,
  11477. _viewportHeight = _canvas.height,
  11478. _currentWidth = 0,
  11479. _currentHeight = 0,
  11480. // frustum
  11481. _frustum = new THREE.Frustum(),
  11482. // camera matrices cache
  11483. _projScreenMatrix = new THREE.Matrix4(),
  11484. _vector3 = new THREE.Vector3(),
  11485. // light arrays cache
  11486. _direction = new THREE.Vector3(),
  11487. _lightsNeedUpdate = true,
  11488. _lights = {
  11489. ambient: [ 0, 0, 0 ],
  11490. directional: { length: 0, colors:[], positions: [] },
  11491. point: { length: 0, colors: [], positions: [], distances: [], decays: [] },
  11492. spot: { length: 0, colors: [], positions: [], distances: [], directions: [], anglesCos: [], exponents: [], decays: [] },
  11493. hemi: { length: 0, skyColors: [], groundColors: [], positions: [] }
  11494. };
  11495. // initialize
  11496. var _gl;
  11497. try {
  11498. var attributes = {
  11499. alpha: _alpha,
  11500. depth: _depth,
  11501. stencil: _stencil,
  11502. antialias: _antialias,
  11503. premultipliedAlpha: _premultipliedAlpha,
  11504. preserveDrawingBuffer: _preserveDrawingBuffer
  11505. };
  11506. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  11507. if ( _gl === null ) {
  11508. if ( _canvas.getContext( 'webgl') !== null ) {
  11509. throw 'Error creating WebGL context with your selected attributes.';
  11510. } else {
  11511. throw 'Error creating WebGL context.';
  11512. }
  11513. }
  11514. _canvas.addEventListener( 'webglcontextlost', function ( event ) {
  11515. event.preventDefault();
  11516. resetGLState();
  11517. setDefaultGLState();
  11518. objects.objects = {};
  11519. properties.clear();
  11520. }, false);
  11521. } catch ( error ) {
  11522. console.error( 'THREE.WebGLRenderer: ' + error );
  11523. }
  11524. var state = new THREE.WebGLState( _gl, paramThreeToGL );
  11525. if ( _gl.getShaderPrecisionFormat === undefined ) {
  11526. _gl.getShaderPrecisionFormat = function () {
  11527. return {
  11528. 'rangeMin': 1,
  11529. 'rangeMax': 1,
  11530. 'precision': 1
  11531. };
  11532. }
  11533. }
  11534. var properties = new THREE.WebGLProperties();
  11535. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  11536. var extensions = new THREE.WebGLExtensions( _gl );
  11537. extensions.get( 'OES_texture_float' );
  11538. extensions.get( 'OES_texture_float_linear' );
  11539. extensions.get( 'OES_texture_half_float' );
  11540. extensions.get( 'OES_texture_half_float_linear' );
  11541. extensions.get( 'OES_standard_derivatives' );
  11542. extensions.get( 'ANGLE_instanced_arrays' );
  11543. if ( extensions.get( 'OES_element_index_uint' ) ) {
  11544. THREE.BufferGeometry.MaxIndex = 4294967296;
  11545. }
  11546. if ( _logarithmicDepthBuffer ) {
  11547. extensions.get( 'EXT_frag_depth' );
  11548. }
  11549. //
  11550. var glClearColor = function ( r, g, b, a ) {
  11551. if ( _premultipliedAlpha === true ) {
  11552. r *= a; g *= a; b *= a;
  11553. }
  11554. _gl.clearColor( r, g, b, a );
  11555. };
  11556. var setDefaultGLState = function () {
  11557. state.init();
  11558. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  11559. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11560. };
  11561. var resetGLState = function () {
  11562. _currentProgram = null;
  11563. _currentCamera = null;
  11564. _currentGeometryProgram = '';
  11565. _currentMaterialId = - 1;
  11566. _lightsNeedUpdate = true;
  11567. state.reset();
  11568. };
  11569. setDefaultGLState();
  11570. this.context = _gl;
  11571. this.extensions = extensions;
  11572. this.state = state;
  11573. // shadow map
  11574. var shadowMap = new THREE.WebGLShadowMap( this, lights, objects );
  11575. this.shadowMap = shadowMap;
  11576. // GPU capabilities
  11577. var _maxTextures = _gl.getParameter( _gl.MAX_TEXTURE_IMAGE_UNITS );
  11578. var _maxVertexTextures = _gl.getParameter( _gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  11579. var _maxTextureSize = _gl.getParameter( _gl.MAX_TEXTURE_SIZE );
  11580. var _maxCubemapSize = _gl.getParameter( _gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  11581. var _supportsVertexTextures = _maxVertexTextures > 0;
  11582. var _supportsBoneTextures = _supportsVertexTextures && extensions.get( 'OES_texture_float' );
  11583. var _supportsInstancedArrays = extensions.get( 'ANGLE_instanced_arrays' );
  11584. //
  11585. var _vertexShaderPrecisionHighpFloat = _gl.getShaderPrecisionFormat( _gl.VERTEX_SHADER, _gl.HIGH_FLOAT );
  11586. var _vertexShaderPrecisionMediumpFloat = _gl.getShaderPrecisionFormat( _gl.VERTEX_SHADER, _gl.MEDIUM_FLOAT );
  11587. var _fragmentShaderPrecisionHighpFloat = _gl.getShaderPrecisionFormat( _gl.FRAGMENT_SHADER, _gl.HIGH_FLOAT );
  11588. var _fragmentShaderPrecisionMediumpFloat = _gl.getShaderPrecisionFormat( _gl.FRAGMENT_SHADER, _gl.MEDIUM_FLOAT );
  11589. var getCompressedTextureFormats = ( function () {
  11590. var array;
  11591. return function () {
  11592. if ( array !== undefined ) {
  11593. return array;
  11594. }
  11595. array = [];
  11596. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) || extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
  11597. var formats = _gl.getParameter( _gl.COMPRESSED_TEXTURE_FORMATS );
  11598. for ( var i = 0; i < formats.length; i ++ ) {
  11599. array.push( formats[ i ] );
  11600. }
  11601. }
  11602. return array;
  11603. };
  11604. } )();
  11605. // clamp precision to maximum available
  11606. var highpAvailable = _vertexShaderPrecisionHighpFloat.precision > 0 && _fragmentShaderPrecisionHighpFloat.precision > 0;
  11607. var mediumpAvailable = _vertexShaderPrecisionMediumpFloat.precision > 0 && _fragmentShaderPrecisionMediumpFloat.precision > 0;
  11608. if ( _precision === 'highp' && ! highpAvailable ) {
  11609. if ( mediumpAvailable ) {
  11610. _precision = 'mediump';
  11611. console.warn( 'THREE.WebGLRenderer: highp not supported, using mediump.' );
  11612. } else {
  11613. _precision = 'lowp';
  11614. console.warn( 'THREE.WebGLRenderer: highp and mediump not supported, using lowp.' );
  11615. }
  11616. }
  11617. if ( _precision === 'mediump' && ! mediumpAvailable ) {
  11618. _precision = 'lowp';
  11619. console.warn( 'THREE.WebGLRenderer: mediump not supported, using lowp.' );
  11620. }
  11621. // Plugins
  11622. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  11623. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  11624. // API
  11625. this.getContext = function () {
  11626. return _gl;
  11627. };
  11628. this.forceContextLoss = function () {
  11629. extensions.get( 'WEBGL_lose_context' ).loseContext();
  11630. };
  11631. this.supportsVertexTextures = function () {
  11632. return _supportsVertexTextures;
  11633. };
  11634. this.supportsInstancedArrays = function () {
  11635. return _supportsInstancedArrays;
  11636. };
  11637. this.supportsFloatTextures = function () {
  11638. return extensions.get( 'OES_texture_float' );
  11639. };
  11640. this.supportsHalfFloatTextures = function () {
  11641. return extensions.get( 'OES_texture_half_float' );
  11642. };
  11643. this.supportsStandardDerivatives = function () {
  11644. return extensions.get( 'OES_standard_derivatives' );
  11645. };
  11646. this.supportsCompressedTextureS3TC = function () {
  11647. return extensions.get( 'WEBGL_compressed_texture_s3tc' );
  11648. };
  11649. this.supportsCompressedTexturePVRTC = function () {
  11650. return extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  11651. };
  11652. this.supportsBlendMinMax = function () {
  11653. return extensions.get( 'EXT_blend_minmax' );
  11654. };
  11655. this.getMaxAnisotropy = ( function () {
  11656. var value;
  11657. return function () {
  11658. if ( value !== undefined ) return value;
  11659. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  11660. if ( extension !== null ) {
  11661. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  11662. } else {
  11663. value = 0;
  11664. }
  11665. return value;
  11666. }
  11667. } )();
  11668. this.getPrecision = function () {
  11669. return _precision;
  11670. };
  11671. this.getPixelRatio = function () {
  11672. return pixelRatio;
  11673. };
  11674. this.setPixelRatio = function ( value ) {
  11675. if ( value !== undefined ) pixelRatio = value;
  11676. };
  11677. this.getSize = function () {
  11678. return {
  11679. width: _width,
  11680. height: _height
  11681. };
  11682. };
  11683. this.setSize = function ( width, height, updateStyle ) {
  11684. _width = width;
  11685. _height = height;
  11686. _canvas.width = width * pixelRatio;
  11687. _canvas.height = height * pixelRatio;
  11688. if ( updateStyle !== false ) {
  11689. _canvas.style.width = width + 'px';
  11690. _canvas.style.height = height + 'px';
  11691. }
  11692. this.setViewport( 0, 0, width, height );
  11693. };
  11694. this.setViewport = function ( x, y, width, height ) {
  11695. _viewportX = x * pixelRatio;
  11696. _viewportY = y * pixelRatio;
  11697. _viewportWidth = width * pixelRatio;
  11698. _viewportHeight = height * pixelRatio;
  11699. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  11700. };
  11701. this.setScissor = function ( x, y, width, height ) {
  11702. _gl.scissor(
  11703. x * pixelRatio,
  11704. y * pixelRatio,
  11705. width * pixelRatio,
  11706. height * pixelRatio
  11707. );
  11708. };
  11709. this.enableScissorTest = function ( enable ) {
  11710. enable ? _gl.enable( _gl.SCISSOR_TEST ) : _gl.disable( _gl.SCISSOR_TEST );
  11711. };
  11712. // Clearing
  11713. this.getClearColor = function () {
  11714. return _clearColor;
  11715. };
  11716. this.setClearColor = function ( color, alpha ) {
  11717. _clearColor.set( color );
  11718. _clearAlpha = alpha !== undefined ? alpha : 1;
  11719. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11720. };
  11721. this.getClearAlpha = function () {
  11722. return _clearAlpha;
  11723. };
  11724. this.setClearAlpha = function ( alpha ) {
  11725. _clearAlpha = alpha;
  11726. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11727. };
  11728. this.clear = function ( color, depth, stencil ) {
  11729. var bits = 0;
  11730. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  11731. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  11732. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  11733. _gl.clear( bits );
  11734. };
  11735. this.clearColor = function () {
  11736. _gl.clear( _gl.COLOR_BUFFER_BIT );
  11737. };
  11738. this.clearDepth = function () {
  11739. _gl.clear( _gl.DEPTH_BUFFER_BIT );
  11740. };
  11741. this.clearStencil = function () {
  11742. _gl.clear( _gl.STENCIL_BUFFER_BIT );
  11743. };
  11744. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  11745. this.setRenderTarget( renderTarget );
  11746. this.clear( color, depth, stencil );
  11747. };
  11748. // Reset
  11749. this.resetGLState = resetGLState;
  11750. // Events
  11751. var onTextureDispose = function ( event ) {
  11752. var texture = event.target;
  11753. texture.removeEventListener( 'dispose', onTextureDispose );
  11754. deallocateTexture( texture );
  11755. _this.info.memory.textures --;
  11756. };
  11757. var onRenderTargetDispose = function ( event ) {
  11758. var renderTarget = event.target;
  11759. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  11760. deallocateRenderTarget( renderTarget );
  11761. _this.info.memory.textures --;
  11762. };
  11763. var onMaterialDispose = function ( event ) {
  11764. var material = event.target;
  11765. material.removeEventListener( 'dispose', onMaterialDispose );
  11766. deallocateMaterial( material );
  11767. };
  11768. // Buffer deallocation
  11769. var deallocateTexture = function ( texture ) {
  11770. var textureProperties = properties.get( texture );
  11771. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  11772. // cube texture
  11773. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  11774. } else {
  11775. // 2D texture
  11776. if ( textureProperties.__webglInit === undefined ) return;
  11777. _gl.deleteTexture( textureProperties.__webglTexture );
  11778. }
  11779. // remove all webgl properties
  11780. properties.delete( texture );
  11781. };
  11782. var deallocateRenderTarget = function ( renderTarget ) {
  11783. var renderTargetProperties = properties.get( renderTarget );
  11784. if ( ! renderTarget || renderTargetProperties.__webglTexture === undefined ) return;
  11785. _gl.deleteTexture( renderTargetProperties.__webglTexture );
  11786. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  11787. for ( var i = 0; i < 6; i ++ ) {
  11788. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  11789. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer[ i ] );
  11790. }
  11791. } else {
  11792. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  11793. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer );
  11794. }
  11795. properties.delete( renderTargetProperties );
  11796. };
  11797. var deallocateMaterial = function ( material ) {
  11798. var program = properties.get( material ).program.program;
  11799. if ( program === undefined ) return;
  11800. material.program = undefined;
  11801. // only deallocate GL program if this was the last use of shared program
  11802. // assumed there is only single copy of any program in the _programs list
  11803. // (that's how it's constructed)
  11804. var i, il, programInfo;
  11805. var deleteProgram = false;
  11806. for ( i = 0, il = _programs.length; i < il; i ++ ) {
  11807. programInfo = _programs[ i ];
  11808. if ( programInfo.program === program ) {
  11809. programInfo.usedTimes --;
  11810. if ( programInfo.usedTimes === 0 ) {
  11811. deleteProgram = true;
  11812. }
  11813. break;
  11814. }
  11815. }
  11816. if ( deleteProgram === true ) {
  11817. // avoid using array.splice, this is costlier than creating new array from scratch
  11818. var newPrograms = [];
  11819. for ( i = 0, il = _programs.length; i < il; i ++ ) {
  11820. programInfo = _programs[ i ];
  11821. if ( programInfo.program !== program ) {
  11822. newPrograms.push( programInfo );
  11823. }
  11824. }
  11825. _programs = newPrograms;
  11826. _gl.deleteProgram( program );
  11827. _this.info.memory.programs --;
  11828. }
  11829. properties.delete( material );
  11830. };
  11831. // Buffer rendering
  11832. this.renderBufferImmediate = function ( object, program, material ) {
  11833. state.initAttributes();
  11834. var objectProperties = properties.get( object );
  11835. if ( object.hasPositions && ! objectProperties.__webglVertexBuffer ) objectProperties.__webglVertexBuffer = _gl.createBuffer();
  11836. if ( object.hasNormals && ! objectProperties.__webglNormalBuffer ) objectProperties.__webglNormalBuffer = _gl.createBuffer();
  11837. if ( object.hasUvs && ! objectProperties.__webglUvBuffer ) objectProperties.__webglUvBuffer = _gl.createBuffer();
  11838. if ( object.hasColors && ! objectProperties.__webglColorBuffer ) objectProperties.__webglColorBuffer = _gl.createBuffer();
  11839. var attributes = program.getAttributes();
  11840. if ( object.hasPositions ) {
  11841. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglVertexBuffer );
  11842. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  11843. state.enableAttribute( attributes.position );
  11844. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  11845. }
  11846. if ( object.hasNormals ) {
  11847. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglNormalBuffer );
  11848. if ( material instanceof THREE.MeshPhongMaterial === false && material.shading === THREE.FlatShading ) {
  11849. var nx, ny, nz,
  11850. nax, nbx, ncx, nay, nby, ncy, naz, nbz, ncz,
  11851. normalArray,
  11852. i, il = object.count * 3;
  11853. for ( i = 0; i < il; i += 9 ) {
  11854. normalArray = object.normalArray;
  11855. nax = normalArray[ i ];
  11856. nay = normalArray[ i + 1 ];
  11857. naz = normalArray[ i + 2 ];
  11858. nbx = normalArray[ i + 3 ];
  11859. nby = normalArray[ i + 4 ];
  11860. nbz = normalArray[ i + 5 ];
  11861. ncx = normalArray[ i + 6 ];
  11862. ncy = normalArray[ i + 7 ];
  11863. ncz = normalArray[ i + 8 ];
  11864. nx = ( nax + nbx + ncx ) / 3;
  11865. ny = ( nay + nby + ncy ) / 3;
  11866. nz = ( naz + nbz + ncz ) / 3;
  11867. normalArray[ i ] = nx;
  11868. normalArray[ i + 1 ] = ny;
  11869. normalArray[ i + 2 ] = nz;
  11870. normalArray[ i + 3 ] = nx;
  11871. normalArray[ i + 4 ] = ny;
  11872. normalArray[ i + 5 ] = nz;
  11873. normalArray[ i + 6 ] = nx;
  11874. normalArray[ i + 7 ] = ny;
  11875. normalArray[ i + 8 ] = nz;
  11876. }
  11877. }
  11878. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  11879. state.enableAttribute( attributes.normal );
  11880. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  11881. }
  11882. if ( object.hasUvs && material.map ) {
  11883. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglUvBuffer );
  11884. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  11885. state.enableAttribute( attributes.uv );
  11886. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  11887. }
  11888. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  11889. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglColorBuffer );
  11890. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  11891. state.enableAttribute( attributes.color );
  11892. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  11893. }
  11894. state.disableUnusedAttributes();
  11895. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  11896. object.count = 0;
  11897. };
  11898. function setupVertexAttributes( material, program, geometry, startIndex ) {
  11899. var extension;
  11900. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  11901. extension = extensions.get( 'ANGLE_instanced_arrays' );
  11902. if ( extension === null ) {
  11903. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  11904. return;
  11905. }
  11906. }
  11907. var geometryAttributes = geometry.attributes;
  11908. var programAttributes = program.getAttributes();
  11909. var materialDefaultAttributeValues = material.defaultAttributeValues;
  11910. for ( var name in programAttributes ) {
  11911. var programAttribute = programAttributes[ name ];
  11912. if ( programAttribute >= 0 ) {
  11913. var geometryAttribute = geometryAttributes[ name ];
  11914. if ( geometryAttribute !== undefined ) {
  11915. var size = geometryAttribute.itemSize;
  11916. state.enableAttribute( programAttribute );
  11917. var buffer = objects.getAttributeBuffer(geometryAttribute);
  11918. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  11919. var data = geometryAttribute.data;
  11920. var stride = data.stride;
  11921. var offset = geometryAttribute.offset;
  11922. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  11923. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  11924. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  11925. if ( extension === null ) {
  11926. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
  11927. return;
  11928. }
  11929. extension.vertexAttribDivisorANGLE( programAttribute, data.meshPerAttribute );
  11930. if ( geometry.maxInstancedCount === undefined ) {
  11931. geometry.maxInstancedCount = data.meshPerAttribute * ( data.array.length / data.stride );
  11932. }
  11933. }
  11934. } else {
  11935. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  11936. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  11937. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  11938. if ( extension === null ) {
  11939. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
  11940. return;
  11941. }
  11942. extension.vertexAttribDivisorANGLE( programAttribute, geometryAttribute.meshPerAttribute );
  11943. if ( geometry.maxInstancedCount === undefined ) {
  11944. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * ( geometryAttribute.array.length / geometryAttribute.itemSize );
  11945. }
  11946. }
  11947. }
  11948. } else if ( materialDefaultAttributeValues !== undefined ) {
  11949. var value = materialDefaultAttributeValues[ name ];
  11950. if ( value !== undefined ) {
  11951. switch ( value.length ) {
  11952. case 2:
  11953. _gl.vertexAttrib2fv( programAttribute, value );
  11954. break;
  11955. case 3:
  11956. _gl.vertexAttrib3fv( programAttribute, value );
  11957. break;
  11958. case 4:
  11959. _gl.vertexAttrib4fv( programAttribute, value );
  11960. break;
  11961. default:
  11962. _gl.vertexAttrib1fv( programAttribute, value );
  11963. }
  11964. }
  11965. }
  11966. }
  11967. }
  11968. state.disableUnusedAttributes();
  11969. }
  11970. this.renderBufferDirect = function ( camera, lights, fog, material, object ) {
  11971. if ( material.visible === false ) return;
  11972. setMaterial( material );
  11973. var geometry = objects.geometries.get( object );
  11974. var program = setProgram( camera, lights, fog, material, object );
  11975. var updateBuffers = false,
  11976. wireframeBit = material.wireframe ? 1 : 0,
  11977. geometryProgram = geometry.id + '_' + program.id + '_' + wireframeBit;
  11978. if ( geometryProgram !== _currentGeometryProgram ) {
  11979. _currentGeometryProgram = geometryProgram;
  11980. updateBuffers = true;
  11981. }
  11982. if ( updateBuffers ) {
  11983. state.initAttributes();
  11984. }
  11985. if ( object instanceof THREE.Mesh ) {
  11986. renderMesh( material, geometry, object, program, updateBuffers );
  11987. } else if ( object instanceof THREE.Line ) {
  11988. renderLine( material, geometry, object, program, updateBuffers );
  11989. } else if ( object instanceof THREE.PointCloud ) {
  11990. renderPointCloud( material, geometry, object, program, updateBuffers );
  11991. }
  11992. };
  11993. function renderMesh( material, geometry, object, program, updateBuffers ) {
  11994. var mode = _gl.TRIANGLES;
  11995. if ( material.wireframe === true ) {
  11996. mode = _gl.LINES;
  11997. state.setLineWidth( material.wireframeLinewidth * pixelRatio );
  11998. }
  11999. var index = geometry.attributes.index;
  12000. if ( index ) {
  12001. // indexed triangles
  12002. var type, size;
  12003. var indexBuffer = objects.getAttributeBuffer(index);
  12004. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12005. type = _gl.UNSIGNED_INT;
  12006. size = 4;
  12007. } else {
  12008. type = _gl.UNSIGNED_SHORT;
  12009. size = 2;
  12010. }
  12011. var offsets = geometry.offsets;
  12012. if ( offsets.length === 0 ) {
  12013. if ( updateBuffers ) {
  12014. setupVertexAttributes( material, program, geometry, 0 );
  12015. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12016. }
  12017. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  12018. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12019. if ( extension === null ) {
  12020. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12021. return;
  12022. }
  12023. extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount ); // Draw the instanced meshes
  12024. } else {
  12025. _gl.drawElements( mode, index.array.length, type, 0 );
  12026. }
  12027. _this.info.render.calls ++;
  12028. _this.info.render.vertices += index.array.length; // not really true, here vertices can be shared
  12029. _this.info.render.faces += index.array.length / 3;
  12030. } else {
  12031. // if there is more than 1 chunk
  12032. // must set attribute pointers to use new offsets for each chunk
  12033. // even if geometry and materials didn't change
  12034. updateBuffers = true;
  12035. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12036. var startIndex = offsets[ i ].index;
  12037. if ( updateBuffers ) {
  12038. setupVertexAttributes( material, program, geometry, startIndex );
  12039. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12040. }
  12041. // render indexed triangles
  12042. if ( geometry instanceof THREE.InstancedBufferGeometry && offsets[i].instances > 0 ) {
  12043. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12044. if ( extension === null ) {
  12045. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12046. return;
  12047. }
  12048. extension.drawElementsInstancedANGLE( mode, offsets[i].count, type, offsets[i].start * size, offsets[i].count, type, offsets[i].instances ); // Draw the instanced meshes
  12049. } else {
  12050. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
  12051. }
  12052. _this.info.render.calls ++;
  12053. _this.info.render.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  12054. _this.info.render.faces += offsets[ i ].count / 3;
  12055. }
  12056. }
  12057. } else {
  12058. // non-indexed triangles
  12059. var offsets = geometry.offsets;
  12060. if ( offsets.length === 0 ) {
  12061. if ( updateBuffers ) {
  12062. setupVertexAttributes( material, program, geometry, 0 );
  12063. }
  12064. var position = geometry.attributes.position;
  12065. // render non-indexed triangles
  12066. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  12067. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12068. if ( extension === null ) {
  12069. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12070. return;
  12071. }
  12072. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  12073. extension.drawArraysInstancedANGLE( mode, 0, position.data.array.length / position.data.stride, geometry.maxInstancedCount ); // Draw the instanced meshes
  12074. } else {
  12075. extension.drawArraysInstancedANGLE( mode, 0, position.array.length / position.itemSize, geometry.maxInstancedCount ); // Draw the instanced meshes
  12076. }
  12077. } else {
  12078. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  12079. _gl.drawArrays( mode, 0, position.data.array.length / position.data.stride );
  12080. } else {
  12081. _gl.drawArrays( mode, 0, position.array.length / position.itemSize );
  12082. }
  12083. }
  12084. _this.info.render.calls++;
  12085. _this.info.render.vertices += position.array.length / position.itemSize;
  12086. _this.info.render.faces += position.array.length / ( 3 * position.itemSize );
  12087. } else {
  12088. // if there is more than 1 chunk
  12089. // must set attribute pointers to use new offsets for each chunk
  12090. // even if geometry and materials didn't change
  12091. if ( updateBuffers ) {
  12092. setupVertexAttributes( material, program, geometry, 0 );
  12093. }
  12094. for ( var i = 0, il = offsets.length; i < il; i++ ) {
  12095. // render non-indexed triangles
  12096. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  12097. console.error( 'THREE.WebGLRenderer.renderMesh: cannot use drawCalls with THREE.InstancedBufferGeometry.' );
  12098. return;
  12099. } else {
  12100. _gl.drawArrays( mode, offsets[ i ].start, offsets[ i ].count );
  12101. }
  12102. _this.info.render.calls++;
  12103. _this.info.render.vertices += offsets[ i ].count;
  12104. _this.info.render.faces += ( offsets[ i ].count ) / 3;
  12105. }
  12106. }
  12107. }
  12108. }
  12109. function renderLine( material, geometry, object, program, updateBuffers ) {
  12110. var mode = object instanceof THREE.LineSegments ? _gl.LINES : _gl.LINE_STRIP;
  12111. // In case user is not using Line*Material by mistake
  12112. var lineWidth = material.linewidth !== undefined ? material.linewidth : 1;
  12113. state.setLineWidth( lineWidth * pixelRatio );
  12114. var index = geometry.attributes.index;
  12115. if ( index ) {
  12116. // indexed lines
  12117. var type, size;
  12118. var indexBuffer = objects.getAttributeBuffer(index);
  12119. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12120. type = _gl.UNSIGNED_INT;
  12121. size = 4;
  12122. } else {
  12123. type = _gl.UNSIGNED_SHORT;
  12124. size = 2;
  12125. }
  12126. var offsets = geometry.offsets;
  12127. if ( offsets.length === 0 ) {
  12128. if ( updateBuffers ) {
  12129. setupVertexAttributes( material, program, geometry, 0 );
  12130. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12131. }
  12132. _gl.drawElements( mode, index.array.length, type, 0 ); // 2 bytes per Uint16Array
  12133. _this.info.render.calls ++;
  12134. _this.info.render.vertices += index.array.length; // not really true, here vertices can be shared
  12135. } else {
  12136. // if there is more than 1 chunk
  12137. // must set attribute pointers to use new offsets for each chunk
  12138. // even if geometry and materials didn't change
  12139. if ( offsets.length > 1 ) updateBuffers = true;
  12140. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12141. var startIndex = offsets[ i ].index;
  12142. if ( updateBuffers ) {
  12143. setupVertexAttributes( material, program, geometry, startIndex );
  12144. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12145. }
  12146. // render indexed lines
  12147. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size ); // 2 bytes per Uint16Array
  12148. _this.info.render.calls ++;
  12149. _this.info.render.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  12150. }
  12151. }
  12152. } else {
  12153. // non-indexed lines
  12154. if ( updateBuffers ) {
  12155. setupVertexAttributes( material, program, geometry, 0 );
  12156. }
  12157. var position = geometry.attributes.position;
  12158. var offsets = geometry.offsets;
  12159. if ( offsets.length === 0 ) {
  12160. _gl.drawArrays( mode, 0, position.array.length / 3 );
  12161. _this.info.render.calls ++;
  12162. _this.info.render.vertices += position.array.length / 3;
  12163. } else {
  12164. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12165. _gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
  12166. _this.info.render.calls ++;
  12167. _this.info.render.vertices += offsets[ i ].count;
  12168. }
  12169. }
  12170. }
  12171. }
  12172. function renderPointCloud( material, geometry, object, program, updateBuffers ) {
  12173. var mode = _gl.POINTS;
  12174. var index = geometry.attributes.index;
  12175. if ( index ) {
  12176. // indexed points
  12177. var type, size;
  12178. var indexBuffer = objects.getAttributeBuffer( index );
  12179. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12180. type = _gl.UNSIGNED_INT;
  12181. size = 4;
  12182. } else {
  12183. type = _gl.UNSIGNED_SHORT;
  12184. size = 2;
  12185. }
  12186. var offsets = geometry.offsets;
  12187. if ( offsets.length === 0 ) {
  12188. if ( updateBuffers ) {
  12189. setupVertexAttributes( material, program, geometry, 0 );
  12190. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12191. }
  12192. _gl.drawElements( mode, index.array.length, type, 0);
  12193. _this.info.render.calls ++;
  12194. _this.info.render.points += index.array.length;
  12195. } else {
  12196. // if there is more than 1 chunk
  12197. // must set attribute pointers to use new offsets for each chunk
  12198. // even if geometry and materials didn't change
  12199. if ( offsets.length > 1 ) updateBuffers = true;
  12200. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12201. var startIndex = offsets[ i ].index;
  12202. if ( updateBuffers ) {
  12203. setupVertexAttributes( material, program, geometry, startIndex );
  12204. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12205. }
  12206. // render indexed points
  12207. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
  12208. _this.info.render.calls ++;
  12209. _this.info.render.points += offsets[ i ].count;
  12210. }
  12211. }
  12212. } else {
  12213. // non-indexed points
  12214. if ( updateBuffers ) {
  12215. setupVertexAttributes( material, program, geometry, 0 );
  12216. }
  12217. var position = geometry.attributes.position;
  12218. var offsets = geometry.offsets;
  12219. if ( offsets.length === 0 ) {
  12220. _gl.drawArrays( mode, 0, position.array.length / 3 );
  12221. _this.info.render.calls ++;
  12222. _this.info.render.points += position.array.length / 3;
  12223. } else {
  12224. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12225. _gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
  12226. _this.info.render.calls ++;
  12227. _this.info.render.points += offsets[ i ].count;
  12228. }
  12229. }
  12230. }
  12231. }
  12232. // Sorting
  12233. function painterSortStable ( a, b ) {
  12234. if ( a.object.renderOrder !== b.object.renderOrder ) {
  12235. return a.object.renderOrder - b.object.renderOrder;
  12236. } else if ( a.object.material.id !== b.object.material.id ) {
  12237. return a.object.material.id - b.object.material.id;
  12238. } else if ( a.z !== b.z ) {
  12239. return a.z - b.z;
  12240. } else {
  12241. return a.id - b.id;
  12242. }
  12243. }
  12244. function reversePainterSortStable ( a, b ) {
  12245. if ( a.object.renderOrder !== b.object.renderOrder ) {
  12246. return a.object.renderOrder - b.object.renderOrder;
  12247. } if ( a.z !== b.z ) {
  12248. return b.z - a.z;
  12249. } else {
  12250. return a.id - b.id;
  12251. }
  12252. }
  12253. // Rendering
  12254. this.render = function ( scene, camera, renderTarget, forceClear ) {
  12255. if ( camera instanceof THREE.Camera === false ) {
  12256. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  12257. return;
  12258. }
  12259. var fog = scene.fog;
  12260. // reset caching for this frame
  12261. _currentGeometryProgram = '';
  12262. _currentMaterialId = - 1;
  12263. _currentCamera = null;
  12264. _lightsNeedUpdate = true;
  12265. // update scene graph
  12266. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  12267. // update camera matrices and frustum
  12268. if ( camera.parent === undefined ) camera.updateMatrixWorld();
  12269. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  12270. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  12271. _frustum.setFromMatrix( _projScreenMatrix );
  12272. lights.length = 0;
  12273. opaqueObjects.length = 0;
  12274. transparentObjects.length = 0;
  12275. sprites.length = 0;
  12276. lensFlares.length = 0;
  12277. projectObject( scene );
  12278. if ( _this.sortObjects === true ) {
  12279. opaqueObjects.sort( painterSortStable );
  12280. transparentObjects.sort( reversePainterSortStable );
  12281. }
  12282. objects.update( opaqueObjects );
  12283. objects.update( transparentObjects );
  12284. //
  12285. shadowMap.render( scene, camera );
  12286. //
  12287. _this.info.render.calls = 0;
  12288. _this.info.render.vertices = 0;
  12289. _this.info.render.faces = 0;
  12290. _this.info.render.points = 0;
  12291. this.setRenderTarget( renderTarget );
  12292. if ( this.autoClear || forceClear ) {
  12293. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  12294. }
  12295. // set matrices for immediate objects
  12296. for ( var i = 0, il = objects.objectsImmediate.length; i < il; i ++ ) {
  12297. var webglObject = objects.objectsImmediate[ i ];
  12298. var object = webglObject.object;
  12299. if ( object.visible === true ) {
  12300. setupMatrices( object, camera );
  12301. var material = object.material;
  12302. if ( material.transparent ) {
  12303. webglObject.transparent = material;
  12304. webglObject.opaque = null;
  12305. } else {
  12306. webglObject.opaque = material;
  12307. webglObject.transparent = null;
  12308. }
  12309. }
  12310. }
  12311. if ( scene.overrideMaterial ) {
  12312. var overrideMaterial = scene.overrideMaterial;
  12313. renderObjects( opaqueObjects, camera, lights, fog, overrideMaterial );
  12314. renderObjects( transparentObjects, camera, lights, fog, overrideMaterial );
  12315. renderObjectsImmediate( objects.objectsImmediate, '', camera, lights, fog, overrideMaterial );
  12316. } else {
  12317. // opaque pass (front-to-back order)
  12318. state.setBlending( THREE.NoBlending );
  12319. renderObjects( opaqueObjects, camera, lights, fog, null );
  12320. renderObjectsImmediate( objects.objectsImmediate, 'opaque', camera, lights, fog, null );
  12321. // transparent pass (back-to-front order)
  12322. renderObjects( transparentObjects, camera, lights, fog, null );
  12323. renderObjectsImmediate( objects.objectsImmediate, 'transparent', camera, lights, fog, null );
  12324. }
  12325. // custom render plugins (post pass)
  12326. spritePlugin.render( scene, camera );
  12327. lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
  12328. // Generate mipmap if we're using any kind of mipmap filtering
  12329. if ( renderTarget && renderTarget.generateMipmaps && renderTarget.minFilter !== THREE.NearestFilter && renderTarget.minFilter !== THREE.LinearFilter ) {
  12330. updateRenderTargetMipmap( renderTarget );
  12331. }
  12332. // Ensure depth buffer writing is enabled so it can be cleared on next render
  12333. state.setDepthTest( true );
  12334. state.setDepthWrite( true );
  12335. state.setColorWrite( true );
  12336. // _gl.finish();
  12337. };
  12338. function projectObject( object ) {
  12339. if ( object.visible === true ) {
  12340. if ( object instanceof THREE.Scene || object instanceof THREE.Group ) {
  12341. // skip
  12342. } else {
  12343. // update Skeleton objects
  12344. if ( object instanceof THREE.SkinnedMesh ) {
  12345. object.skeleton.update();
  12346. }
  12347. objects.init( object );
  12348. if ( object instanceof THREE.Light ) {
  12349. lights.push( object );
  12350. } else if ( object instanceof THREE.Sprite ) {
  12351. sprites.push( object );
  12352. } else if ( object instanceof THREE.LensFlare ) {
  12353. lensFlares.push( object );
  12354. } else {
  12355. var webglObject = objects.objects[ object.id ];
  12356. if ( webglObject && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  12357. var material = object.material;
  12358. if ( properties.get( material ) ) {
  12359. material.program = properties.get( material ).program;
  12360. }
  12361. if ( material.transparent ) {
  12362. transparentObjects.push( webglObject );
  12363. } else {
  12364. opaqueObjects.push( webglObject );
  12365. }
  12366. if ( _this.sortObjects === true ) {
  12367. _vector3.setFromMatrixPosition( object.matrixWorld );
  12368. _vector3.applyProjection( _projScreenMatrix );
  12369. webglObject.z = _vector3.z;
  12370. }
  12371. }
  12372. }
  12373. }
  12374. for ( var i = 0, l = object.children.length; i < l; i ++ ) {
  12375. projectObject( object.children[ i ] );
  12376. }
  12377. }
  12378. }
  12379. function renderObjects( renderList, camera, lights, fog, overrideMaterial ) {
  12380. var material = overrideMaterial;
  12381. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12382. var webglObject = renderList[ i ];
  12383. var object = webglObject.object;
  12384. setupMatrices( object, camera );
  12385. if ( overrideMaterial === null ) material = object.material;
  12386. if ( material instanceof THREE.MeshFaceMaterial ) {
  12387. var materials = material.materials;
  12388. for ( var j = 0, jl = materials.length; j < jl; j ++ ) {
  12389. _this.renderBufferDirect( camera, lights, fog, materials[ j ], object );
  12390. }
  12391. continue;
  12392. }
  12393. _this.renderBufferDirect( camera, lights, fog, material, object );
  12394. }
  12395. }
  12396. function renderObjectsImmediate ( renderList, materialType, camera, lights, fog, overrideMaterial ) {
  12397. var material = overrideMaterial;
  12398. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12399. var webglObject = renderList[ i ];
  12400. var object = webglObject.object;
  12401. if ( object.visible === true ) {
  12402. if ( overrideMaterial === null ) material = webglObject[ materialType ];
  12403. _this.renderImmediateObject( camera, lights, fog, material, object );
  12404. }
  12405. }
  12406. }
  12407. this.renderImmediateObject = function ( camera, lights, fog, material, object ) {
  12408. setMaterial( material );
  12409. var program = setProgram( camera, lights, fog, material, object );
  12410. _currentGeometryProgram = '';
  12411. if ( object.immediateRenderCallback ) {
  12412. object.immediateRenderCallback( program, _gl, _frustum );
  12413. } else {
  12414. object.render( function ( object ) { _this.renderBufferImmediate( object, program, material ); } );
  12415. }
  12416. };
  12417. // Materials
  12418. var shaderIDs = {
  12419. MeshDepthMaterial: 'depth',
  12420. MeshNormalMaterial: 'normal',
  12421. MeshBasicMaterial: 'basic',
  12422. MeshLambertMaterial: 'lambert',
  12423. MeshPhongMaterial: 'phong',
  12424. LineBasicMaterial: 'basic',
  12425. LineDashedMaterial: 'dashed',
  12426. PointCloudMaterial: 'particle_basic'
  12427. };
  12428. function initMaterial( material, lights, fog, object ) {
  12429. var materialProperties = properties.get( material );
  12430. var shaderID = shaderIDs[ material.type ];
  12431. // heuristics to create shader parameters according to lights in the scene
  12432. // (not to blow over maxLights budget)
  12433. var maxLightCount = allocateLights( lights );
  12434. var maxShadows = allocateShadows( lights );
  12435. var maxBones = allocateBones( object );
  12436. var parameters = {
  12437. precision: _precision,
  12438. supportsVertexTextures: _supportsVertexTextures,
  12439. map: !! material.map,
  12440. envMap: !! material.envMap,
  12441. envMapMode: material.envMap && material.envMap.mapping,
  12442. lightMap: !! material.lightMap,
  12443. aoMap: !! material.aoMap,
  12444. emissiveMap: !! material.emissiveMap,
  12445. bumpMap: !! material.bumpMap,
  12446. normalMap: !! material.normalMap,
  12447. specularMap: !! material.specularMap,
  12448. alphaMap: !! material.alphaMap,
  12449. combine: material.combine,
  12450. vertexColors: material.vertexColors,
  12451. fog: fog,
  12452. useFog: material.fog,
  12453. fogExp: fog instanceof THREE.FogExp2,
  12454. flatShading: material.shading === THREE.FlatShading,
  12455. sizeAttenuation: material.sizeAttenuation,
  12456. logarithmicDepthBuffer: _logarithmicDepthBuffer,
  12457. skinning: material.skinning,
  12458. maxBones: maxBones,
  12459. useVertexTexture: _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  12460. morphTargets: material.morphTargets,
  12461. morphNormals: material.morphNormals,
  12462. maxMorphTargets: _this.maxMorphTargets,
  12463. maxMorphNormals: _this.maxMorphNormals,
  12464. maxDirLights: maxLightCount.directional,
  12465. maxPointLights: maxLightCount.point,
  12466. maxSpotLights: maxLightCount.spot,
  12467. maxHemiLights: maxLightCount.hemi,
  12468. maxShadows: maxShadows,
  12469. shadowMapEnabled: shadowMap.enabled && object.receiveShadow && maxShadows > 0,
  12470. shadowMapType: shadowMap.type,
  12471. shadowMapDebug: shadowMap.debug,
  12472. shadowMapCascade: shadowMap.cascade,
  12473. alphaTest: material.alphaTest,
  12474. metal: material.metal,
  12475. doubleSided: material.side === THREE.DoubleSide,
  12476. flipSided: material.side === THREE.BackSide
  12477. };
  12478. // Generate code
  12479. var chunks = [];
  12480. if ( shaderID ) {
  12481. chunks.push( shaderID );
  12482. } else {
  12483. chunks.push( material.fragmentShader );
  12484. chunks.push( material.vertexShader );
  12485. }
  12486. if ( material.defines !== undefined ) {
  12487. for ( var name in material.defines ) {
  12488. chunks.push( name );
  12489. chunks.push( material.defines[ name ] );
  12490. }
  12491. }
  12492. for ( var name in parameters ) {
  12493. chunks.push( name );
  12494. chunks.push( parameters[ name ] );
  12495. }
  12496. var code = chunks.join();
  12497. if ( !materialProperties.program ) {
  12498. // new material
  12499. material.addEventListener( 'dispose', onMaterialDispose );
  12500. } else if ( materialProperties.program.code !== code ) {
  12501. // changed glsl or parameters
  12502. deallocateMaterial( material );
  12503. } else if ( shaderID !== undefined ) {
  12504. // same glsl
  12505. return;
  12506. } else if ( materialProperties.__webglShader.uniforms === material.uniforms ) {
  12507. // same uniforms (container object)
  12508. return;
  12509. }
  12510. if ( shaderID ) {
  12511. var shader = THREE.ShaderLib[ shaderID ];
  12512. materialProperties.__webglShader = {
  12513. name: material.type,
  12514. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  12515. vertexShader: shader.vertexShader,
  12516. fragmentShader: shader.fragmentShader
  12517. }
  12518. } else {
  12519. materialProperties.__webglShader = {
  12520. name: material.type,
  12521. uniforms: material.uniforms,
  12522. vertexShader: material.vertexShader,
  12523. fragmentShader: material.fragmentShader
  12524. }
  12525. }
  12526. var program;
  12527. // Check if code has been already compiled
  12528. for ( var p = 0, pl = _programs.length; p < pl; p ++ ) {
  12529. var programInfo = _programs[ p ];
  12530. if ( programInfo.code === code ) {
  12531. program = programInfo;
  12532. program.usedTimes ++;
  12533. break;
  12534. }
  12535. }
  12536. if ( program === undefined ) {
  12537. material.__webglShader = materialProperties.__webglShader;
  12538. program = new THREE.WebGLProgram( _this, code, material, parameters );
  12539. _programs.push( program );
  12540. _this.info.memory.programs = _programs.length;
  12541. }
  12542. materialProperties.program = program;
  12543. var attributes = program.getAttributes();
  12544. if ( material.morphTargets ) {
  12545. material.numSupportedMorphTargets = 0;
  12546. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  12547. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  12548. material.numSupportedMorphTargets ++;
  12549. }
  12550. }
  12551. }
  12552. if ( material.morphNormals ) {
  12553. material.numSupportedMorphNormals = 0;
  12554. for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
  12555. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  12556. material.numSupportedMorphNormals ++;
  12557. }
  12558. }
  12559. }
  12560. materialProperties.uniformsList = [];
  12561. var uniformLocations = materialProperties.program.getUniforms();
  12562. for ( var u in materialProperties.__webglShader.uniforms ) {
  12563. var location = uniformLocations[ u ];
  12564. if ( location ) {
  12565. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  12566. }
  12567. }
  12568. }
  12569. function setMaterial( material ) {
  12570. setMaterialFaces( material );
  12571. if ( material.transparent === true ) {
  12572. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  12573. } else {
  12574. state.setBlending( THREE.NoBlending );
  12575. }
  12576. state.setDepthFunc( material.depthFunc );
  12577. state.setDepthTest( material.depthTest );
  12578. state.setDepthWrite( material.depthWrite );
  12579. state.setColorWrite( material.colorWrite );
  12580. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12581. }
  12582. function setMaterialFaces( material ) {
  12583. state.setDoubleSided( material.side === THREE.DoubleSide );
  12584. state.setFlipSided( material.side === THREE.BackSide );
  12585. }
  12586. function setProgram( camera, lights, fog, material, object ) {
  12587. _usedTextureUnits = 0;
  12588. var materialProperties = properties.get( material );
  12589. if ( material.needsUpdate || ! materialProperties.program ) {
  12590. initMaterial( material, lights, fog, object );
  12591. material.needsUpdate = false;
  12592. }
  12593. var refreshProgram = false;
  12594. var refreshMaterial = false;
  12595. var refreshLights = false;
  12596. var program = materialProperties.program,
  12597. p_uniforms = program.getUniforms(),
  12598. m_uniforms = materialProperties.__webglShader.uniforms;
  12599. if ( program.id !== _currentProgram ) {
  12600. _gl.useProgram( program.program );
  12601. _currentProgram = program.id;
  12602. refreshProgram = true;
  12603. refreshMaterial = true;
  12604. refreshLights = true;
  12605. }
  12606. if ( material.id !== _currentMaterialId ) {
  12607. if ( _currentMaterialId === -1 ) refreshLights = true;
  12608. _currentMaterialId = material.id;
  12609. refreshMaterial = true;
  12610. }
  12611. if ( refreshProgram || camera !== _currentCamera ) {
  12612. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  12613. if ( _logarithmicDepthBuffer ) {
  12614. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  12615. }
  12616. if ( camera !== _currentCamera ) _currentCamera = camera;
  12617. // load material specific uniforms
  12618. // (shader material also gets them for the sake of genericity)
  12619. if ( material instanceof THREE.ShaderMaterial ||
  12620. material instanceof THREE.MeshPhongMaterial ||
  12621. material.envMap ) {
  12622. if ( p_uniforms.cameraPosition !== null ) {
  12623. _vector3.setFromMatrixPosition( camera.matrixWorld );
  12624. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  12625. }
  12626. }
  12627. if ( material instanceof THREE.MeshPhongMaterial ||
  12628. material instanceof THREE.MeshLambertMaterial ||
  12629. material instanceof THREE.MeshBasicMaterial ||
  12630. material instanceof THREE.ShaderMaterial ||
  12631. material.skinning ) {
  12632. if ( p_uniforms.viewMatrix !== null ) {
  12633. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  12634. }
  12635. }
  12636. }
  12637. // skinning uniforms must be set even if material didn't change
  12638. // auto-setting of texture unit for bone texture must go before other textures
  12639. // not sure why, but otherwise weird things happen
  12640. if ( material.skinning ) {
  12641. if ( object.bindMatrix && p_uniforms.bindMatrix !== null ) {
  12642. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  12643. }
  12644. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== null ) {
  12645. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  12646. }
  12647. if ( _supportsBoneTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  12648. if ( p_uniforms.boneTexture !== null ) {
  12649. var textureUnit = getTextureUnit();
  12650. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  12651. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  12652. }
  12653. if ( p_uniforms.boneTextureWidth !== null ) {
  12654. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  12655. }
  12656. if ( p_uniforms.boneTextureHeight !== null ) {
  12657. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  12658. }
  12659. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  12660. if ( p_uniforms.boneGlobalMatrices !== null ) {
  12661. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  12662. }
  12663. }
  12664. }
  12665. if ( refreshMaterial ) {
  12666. // refresh uniforms common to several materials
  12667. if ( fog && material.fog ) {
  12668. refreshUniformsFog( m_uniforms, fog );
  12669. }
  12670. if ( material instanceof THREE.MeshPhongMaterial ||
  12671. material instanceof THREE.MeshLambertMaterial ||
  12672. material.lights ) {
  12673. if ( _lightsNeedUpdate ) {
  12674. refreshLights = true;
  12675. setupLights( lights );
  12676. _lightsNeedUpdate = false;
  12677. }
  12678. if ( refreshLights ) {
  12679. refreshUniformsLights( m_uniforms, _lights );
  12680. markUniformsLightsNeedsUpdate( m_uniforms, true );
  12681. } else {
  12682. markUniformsLightsNeedsUpdate( m_uniforms, false );
  12683. }
  12684. }
  12685. if ( material instanceof THREE.MeshBasicMaterial ||
  12686. material instanceof THREE.MeshLambertMaterial ||
  12687. material instanceof THREE.MeshPhongMaterial ) {
  12688. refreshUniformsCommon( m_uniforms, material );
  12689. }
  12690. // refresh single material specific uniforms
  12691. if ( material instanceof THREE.LineBasicMaterial ) {
  12692. refreshUniformsLine( m_uniforms, material );
  12693. } else if ( material instanceof THREE.LineDashedMaterial ) {
  12694. refreshUniformsLine( m_uniforms, material );
  12695. refreshUniformsDash( m_uniforms, material );
  12696. } else if ( material instanceof THREE.PointCloudMaterial ) {
  12697. refreshUniformsParticle( m_uniforms, material );
  12698. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  12699. refreshUniformsPhong( m_uniforms, material );
  12700. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  12701. refreshUniformsLambert( m_uniforms, material );
  12702. } else if ( material instanceof THREE.MeshBasicMaterial ) {
  12703. refreshUniformsBasic( m_uniforms, material );
  12704. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  12705. m_uniforms.mNear.value = camera.near;
  12706. m_uniforms.mFar.value = camera.far;
  12707. m_uniforms.opacity.value = material.opacity;
  12708. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  12709. m_uniforms.opacity.value = material.opacity;
  12710. }
  12711. if ( object.receiveShadow && ! material._shadowPass ) {
  12712. refreshUniformsShadow( m_uniforms, lights );
  12713. }
  12714. // load common uniforms
  12715. loadUniformsGeneric( materialProperties.uniformsList );
  12716. }
  12717. loadUniformsMatrices( p_uniforms, object );
  12718. if ( p_uniforms.modelMatrix !== null ) {
  12719. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  12720. }
  12721. return program;
  12722. }
  12723. // Uniforms (refresh uniforms objects)
  12724. function refreshUniformsCommon ( uniforms, material ) {
  12725. uniforms.opacity.value = material.opacity;
  12726. uniforms.diffuse.value = material.color;
  12727. uniforms.map.value = material.map;
  12728. uniforms.specularMap.value = material.specularMap;
  12729. uniforms.alphaMap.value = material.alphaMap;
  12730. if ( material.bumpMap ) {
  12731. uniforms.bumpMap.value = material.bumpMap;
  12732. uniforms.bumpScale.value = material.bumpScale;
  12733. }
  12734. if ( material.normalMap ) {
  12735. uniforms.normalMap.value = material.normalMap;
  12736. uniforms.normalScale.value.copy( material.normalScale );
  12737. }
  12738. // uv repeat and offset setting priorities
  12739. // 1. color map
  12740. // 2. specular map
  12741. // 3. normal map
  12742. // 4. bump map
  12743. // 5. alpha map
  12744. // 6. emissive map
  12745. var uvScaleMap;
  12746. if ( material.map ) {
  12747. uvScaleMap = material.map;
  12748. } else if ( material.specularMap ) {
  12749. uvScaleMap = material.specularMap;
  12750. } else if ( material.normalMap ) {
  12751. uvScaleMap = material.normalMap;
  12752. } else if ( material.bumpMap ) {
  12753. uvScaleMap = material.bumpMap;
  12754. } else if ( material.alphaMap ) {
  12755. uvScaleMap = material.alphaMap;
  12756. } else if ( material.emissiveMap ) {
  12757. uvScaleMap = material.emissiveMap;
  12758. }
  12759. if ( uvScaleMap !== undefined ) {
  12760. var offset = uvScaleMap.offset;
  12761. var repeat = uvScaleMap.repeat;
  12762. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  12763. }
  12764. uniforms.envMap.value = material.envMap;
  12765. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  12766. uniforms.reflectivity.value = material.reflectivity;
  12767. uniforms.refractionRatio.value = material.refractionRatio;
  12768. }
  12769. function refreshUniformsLine ( uniforms, material ) {
  12770. uniforms.diffuse.value = material.color;
  12771. uniforms.opacity.value = material.opacity;
  12772. }
  12773. function refreshUniformsDash ( uniforms, material ) {
  12774. uniforms.dashSize.value = material.dashSize;
  12775. uniforms.totalSize.value = material.dashSize + material.gapSize;
  12776. uniforms.scale.value = material.scale;
  12777. }
  12778. function refreshUniformsParticle ( uniforms, material ) {
  12779. uniforms.psColor.value = material.color;
  12780. uniforms.opacity.value = material.opacity;
  12781. uniforms.size.value = material.size;
  12782. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  12783. uniforms.map.value = material.map;
  12784. if ( material.map !== null ) {
  12785. var offset = material.map.offset;
  12786. var repeat = material.map.repeat;
  12787. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  12788. }
  12789. }
  12790. function refreshUniformsFog ( uniforms, fog ) {
  12791. uniforms.fogColor.value = fog.color;
  12792. if ( fog instanceof THREE.Fog ) {
  12793. uniforms.fogNear.value = fog.near;
  12794. uniforms.fogFar.value = fog.far;
  12795. } else if ( fog instanceof THREE.FogExp2 ) {
  12796. uniforms.fogDensity.value = fog.density;
  12797. }
  12798. }
  12799. function refreshUniformsPhong ( uniforms, material ) {
  12800. uniforms.shininess.value = material.shininess;
  12801. uniforms.emissive.value = material.emissive;
  12802. uniforms.specular.value = material.specular;
  12803. uniforms.lightMap.value = material.lightMap;
  12804. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  12805. uniforms.aoMap.value = material.aoMap;
  12806. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  12807. uniforms.emissiveMap.value = material.emissiveMap;
  12808. }
  12809. function refreshUniformsLambert ( uniforms, material ) {
  12810. uniforms.emissive.value = material.emissive;
  12811. }
  12812. function refreshUniformsBasic ( uniforms, material ) {
  12813. uniforms.aoMap.value = material.aoMap;
  12814. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  12815. }
  12816. function refreshUniformsLights ( uniforms, lights ) {
  12817. uniforms.ambientLightColor.value = lights.ambient;
  12818. uniforms.directionalLightColor.value = lights.directional.colors;
  12819. uniforms.directionalLightDirection.value = lights.directional.positions;
  12820. uniforms.pointLightColor.value = lights.point.colors;
  12821. uniforms.pointLightPosition.value = lights.point.positions;
  12822. uniforms.pointLightDistance.value = lights.point.distances;
  12823. uniforms.pointLightDecay.value = lights.point.decays;
  12824. uniforms.spotLightColor.value = lights.spot.colors;
  12825. uniforms.spotLightPosition.value = lights.spot.positions;
  12826. uniforms.spotLightDistance.value = lights.spot.distances;
  12827. uniforms.spotLightDirection.value = lights.spot.directions;
  12828. uniforms.spotLightAngleCos.value = lights.spot.anglesCos;
  12829. uniforms.spotLightExponent.value = lights.spot.exponents;
  12830. uniforms.spotLightDecay.value = lights.spot.decays;
  12831. uniforms.hemisphereLightSkyColor.value = lights.hemi.skyColors;
  12832. uniforms.hemisphereLightGroundColor.value = lights.hemi.groundColors;
  12833. uniforms.hemisphereLightDirection.value = lights.hemi.positions;
  12834. }
  12835. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  12836. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  12837. uniforms.ambientLightColor.needsUpdate = value;
  12838. uniforms.directionalLightColor.needsUpdate = value;
  12839. uniforms.directionalLightDirection.needsUpdate = value;
  12840. uniforms.pointLightColor.needsUpdate = value;
  12841. uniforms.pointLightPosition.needsUpdate = value;
  12842. uniforms.pointLightDistance.needsUpdate = value;
  12843. uniforms.pointLightDecay.needsUpdate = value;
  12844. uniforms.spotLightColor.needsUpdate = value;
  12845. uniforms.spotLightPosition.needsUpdate = value;
  12846. uniforms.spotLightDistance.needsUpdate = value;
  12847. uniforms.spotLightDirection.needsUpdate = value;
  12848. uniforms.spotLightAngleCos.needsUpdate = value;
  12849. uniforms.spotLightExponent.needsUpdate = value;
  12850. uniforms.spotLightDecay.needsUpdate = value;
  12851. uniforms.hemisphereLightSkyColor.needsUpdate = value;
  12852. uniforms.hemisphereLightGroundColor.needsUpdate = value;
  12853. uniforms.hemisphereLightDirection.needsUpdate = value;
  12854. }
  12855. function refreshUniformsShadow ( uniforms, lights ) {
  12856. if ( uniforms.shadowMatrix ) {
  12857. var j = 0;
  12858. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  12859. var light = lights[ i ];
  12860. if ( ! light.castShadow ) continue;
  12861. if ( light instanceof THREE.SpotLight || ( light instanceof THREE.DirectionalLight && ! light.shadowCascade ) ) {
  12862. uniforms.shadowMap.value[ j ] = light.shadowMap;
  12863. uniforms.shadowMapSize.value[ j ] = light.shadowMapSize;
  12864. uniforms.shadowMatrix.value[ j ] = light.shadowMatrix;
  12865. uniforms.shadowDarkness.value[ j ] = light.shadowDarkness;
  12866. uniforms.shadowBias.value[ j ] = light.shadowBias;
  12867. j ++;
  12868. }
  12869. }
  12870. }
  12871. }
  12872. // Uniforms (load to GPU)
  12873. function loadUniformsMatrices ( uniforms, object ) {
  12874. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object._modelViewMatrix.elements );
  12875. if ( uniforms.normalMatrix ) {
  12876. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object._normalMatrix.elements );
  12877. }
  12878. }
  12879. function getTextureUnit() {
  12880. var textureUnit = _usedTextureUnits;
  12881. if ( textureUnit >= _maxTextures ) {
  12882. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + _maxTextures );
  12883. }
  12884. _usedTextureUnits += 1;
  12885. return textureUnit;
  12886. }
  12887. function loadUniformsGeneric ( uniforms ) {
  12888. var texture, textureUnit, offset;
  12889. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  12890. var uniform = uniforms[ j ][ 0 ];
  12891. // needsUpdate property is not added to all uniforms.
  12892. if ( uniform.needsUpdate === false ) continue;
  12893. var type = uniform.type;
  12894. var value = uniform.value;
  12895. var location = uniforms[ j ][ 1 ];
  12896. switch ( type ) {
  12897. case '1i':
  12898. _gl.uniform1i( location, value );
  12899. break;
  12900. case '1f':
  12901. _gl.uniform1f( location, value );
  12902. break;
  12903. case '2f':
  12904. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  12905. break;
  12906. case '3f':
  12907. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  12908. break;
  12909. case '4f':
  12910. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  12911. break;
  12912. case '1iv':
  12913. _gl.uniform1iv( location, value );
  12914. break;
  12915. case '3iv':
  12916. _gl.uniform3iv( location, value );
  12917. break;
  12918. case '1fv':
  12919. _gl.uniform1fv( location, value );
  12920. break;
  12921. case '2fv':
  12922. _gl.uniform2fv( location, value );
  12923. break;
  12924. case '3fv':
  12925. _gl.uniform3fv( location, value );
  12926. break;
  12927. case '4fv':
  12928. _gl.uniform4fv( location, value );
  12929. break;
  12930. case 'Matrix3fv':
  12931. _gl.uniformMatrix3fv( location, false, value );
  12932. break;
  12933. case 'Matrix4fv':
  12934. _gl.uniformMatrix4fv( location, false, value );
  12935. break;
  12936. //
  12937. case 'i':
  12938. // single integer
  12939. _gl.uniform1i( location, value );
  12940. break;
  12941. case 'f':
  12942. // single float
  12943. _gl.uniform1f( location, value );
  12944. break;
  12945. case 'v2':
  12946. // single THREE.Vector2
  12947. _gl.uniform2f( location, value.x, value.y );
  12948. break;
  12949. case 'v3':
  12950. // single THREE.Vector3
  12951. _gl.uniform3f( location, value.x, value.y, value.z );
  12952. break;
  12953. case 'v4':
  12954. // single THREE.Vector4
  12955. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  12956. break;
  12957. case 'c':
  12958. // single THREE.Color
  12959. _gl.uniform3f( location, value.r, value.g, value.b );
  12960. break;
  12961. case 'iv1':
  12962. // flat array of integers (JS or typed array)
  12963. _gl.uniform1iv( location, value );
  12964. break;
  12965. case 'iv':
  12966. // flat array of integers with 3 x N size (JS or typed array)
  12967. _gl.uniform3iv( location, value );
  12968. break;
  12969. case 'fv1':
  12970. // flat array of floats (JS or typed array)
  12971. _gl.uniform1fv( location, value );
  12972. break;
  12973. case 'fv':
  12974. // flat array of floats with 3 x N size (JS or typed array)
  12975. _gl.uniform3fv( location, value );
  12976. break;
  12977. case 'v2v':
  12978. // array of THREE.Vector2
  12979. if ( uniform._array === undefined ) {
  12980. uniform._array = new Float32Array( 2 * value.length );
  12981. }
  12982. for ( var i = 0, il = value.length; i < il; i ++ ) {
  12983. offset = i * 2;
  12984. uniform._array[ offset + 0 ] = value[ i ].x;
  12985. uniform._array[ offset + 1 ] = value[ i ].y;
  12986. }
  12987. _gl.uniform2fv( location, uniform._array );
  12988. break;
  12989. case 'v3v':
  12990. // array of THREE.Vector3
  12991. if ( uniform._array === undefined ) {
  12992. uniform._array = new Float32Array( 3 * value.length );
  12993. }
  12994. for ( var i = 0, il = value.length; i < il; i ++ ) {
  12995. offset = i * 3;
  12996. uniform._array[ offset + 0 ] = value[ i ].x;
  12997. uniform._array[ offset + 1 ] = value[ i ].y;
  12998. uniform._array[ offset + 2 ] = value[ i ].z;
  12999. }
  13000. _gl.uniform3fv( location, uniform._array );
  13001. break;
  13002. case 'v4v':
  13003. // array of THREE.Vector4
  13004. if ( uniform._array === undefined ) {
  13005. uniform._array = new Float32Array( 4 * value.length );
  13006. }
  13007. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13008. offset = i * 4;
  13009. uniform._array[ offset + 0 ] = value[ i ].x;
  13010. uniform._array[ offset + 1 ] = value[ i ].y;
  13011. uniform._array[ offset + 2 ] = value[ i ].z;
  13012. uniform._array[ offset + 3 ] = value[ i ].w;
  13013. }
  13014. _gl.uniform4fv( location, uniform._array );
  13015. break;
  13016. case 'm3':
  13017. // single THREE.Matrix3
  13018. _gl.uniformMatrix3fv( location, false, value.elements );
  13019. break;
  13020. case 'm3v':
  13021. // array of THREE.Matrix3
  13022. if ( uniform._array === undefined ) {
  13023. uniform._array = new Float32Array( 9 * value.length );
  13024. }
  13025. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13026. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  13027. }
  13028. _gl.uniformMatrix3fv( location, false, uniform._array );
  13029. break;
  13030. case 'm4':
  13031. // single THREE.Matrix4
  13032. _gl.uniformMatrix4fv( location, false, value.elements );
  13033. break;
  13034. case 'm4v':
  13035. // array of THREE.Matrix4
  13036. if ( uniform._array === undefined ) {
  13037. uniform._array = new Float32Array( 16 * value.length );
  13038. }
  13039. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13040. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  13041. }
  13042. _gl.uniformMatrix4fv( location, false, uniform._array );
  13043. break;
  13044. case 't':
  13045. // single THREE.Texture (2d or cube)
  13046. texture = value;
  13047. textureUnit = getTextureUnit();
  13048. _gl.uniform1i( location, textureUnit );
  13049. if ( ! texture ) continue;
  13050. if ( texture instanceof THREE.CubeTexture ||
  13051. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) { // CompressedTexture can have Array in image :/
  13052. setCubeTexture( texture, textureUnit );
  13053. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  13054. setCubeTextureDynamic( texture, textureUnit );
  13055. } else {
  13056. _this.setTexture( texture, textureUnit );
  13057. }
  13058. break;
  13059. case 'tv':
  13060. // array of THREE.Texture (2d)
  13061. if ( uniform._array === undefined ) {
  13062. uniform._array = [];
  13063. }
  13064. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  13065. uniform._array[ i ] = getTextureUnit();
  13066. }
  13067. _gl.uniform1iv( location, uniform._array );
  13068. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  13069. texture = uniform.value[ i ];
  13070. textureUnit = uniform._array[ i ];
  13071. if ( ! texture ) continue;
  13072. _this.setTexture( texture, textureUnit );
  13073. }
  13074. break;
  13075. default:
  13076. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  13077. }
  13078. }
  13079. }
  13080. function setupMatrices ( object, camera ) {
  13081. object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  13082. object._normalMatrix.getNormalMatrix( object._modelViewMatrix );
  13083. }
  13084. function setColorLinear( array, offset, color, intensity ) {
  13085. array[ offset + 0 ] = color.r * intensity;
  13086. array[ offset + 1 ] = color.g * intensity;
  13087. array[ offset + 2 ] = color.b * intensity;
  13088. }
  13089. function setupLights ( lights ) {
  13090. var l, ll, light,
  13091. r = 0, g = 0, b = 0,
  13092. color, skyColor, groundColor,
  13093. intensity,
  13094. distance,
  13095. zlights = _lights,
  13096. dirColors = zlights.directional.colors,
  13097. dirPositions = zlights.directional.positions,
  13098. pointColors = zlights.point.colors,
  13099. pointPositions = zlights.point.positions,
  13100. pointDistances = zlights.point.distances,
  13101. pointDecays = zlights.point.decays,
  13102. spotColors = zlights.spot.colors,
  13103. spotPositions = zlights.spot.positions,
  13104. spotDistances = zlights.spot.distances,
  13105. spotDirections = zlights.spot.directions,
  13106. spotAnglesCos = zlights.spot.anglesCos,
  13107. spotExponents = zlights.spot.exponents,
  13108. spotDecays = zlights.spot.decays,
  13109. hemiSkyColors = zlights.hemi.skyColors,
  13110. hemiGroundColors = zlights.hemi.groundColors,
  13111. hemiPositions = zlights.hemi.positions,
  13112. dirLength = 0,
  13113. pointLength = 0,
  13114. spotLength = 0,
  13115. hemiLength = 0,
  13116. dirCount = 0,
  13117. pointCount = 0,
  13118. spotCount = 0,
  13119. hemiCount = 0,
  13120. dirOffset = 0,
  13121. pointOffset = 0,
  13122. spotOffset = 0,
  13123. hemiOffset = 0;
  13124. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  13125. light = lights[ l ];
  13126. if ( light.onlyShadow ) continue;
  13127. color = light.color;
  13128. intensity = light.intensity;
  13129. distance = light.distance;
  13130. if ( light instanceof THREE.AmbientLight ) {
  13131. if ( ! light.visible ) continue;
  13132. r += color.r;
  13133. g += color.g;
  13134. b += color.b;
  13135. } else if ( light instanceof THREE.DirectionalLight ) {
  13136. dirCount += 1;
  13137. if ( ! light.visible ) continue;
  13138. _direction.setFromMatrixPosition( light.matrixWorld );
  13139. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13140. _direction.sub( _vector3 );
  13141. _direction.normalize();
  13142. dirOffset = dirLength * 3;
  13143. dirPositions[ dirOffset + 0 ] = _direction.x;
  13144. dirPositions[ dirOffset + 1 ] = _direction.y;
  13145. dirPositions[ dirOffset + 2 ] = _direction.z;
  13146. setColorLinear( dirColors, dirOffset, color, intensity );
  13147. dirLength += 1;
  13148. } else if ( light instanceof THREE.PointLight ) {
  13149. pointCount += 1;
  13150. if ( ! light.visible ) continue;
  13151. pointOffset = pointLength * 3;
  13152. setColorLinear( pointColors, pointOffset, color, intensity );
  13153. _vector3.setFromMatrixPosition( light.matrixWorld );
  13154. pointPositions[ pointOffset + 0 ] = _vector3.x;
  13155. pointPositions[ pointOffset + 1 ] = _vector3.y;
  13156. pointPositions[ pointOffset + 2 ] = _vector3.z;
  13157. // distance is 0 if decay is 0, because there is no attenuation at all.
  13158. pointDistances[ pointLength ] = distance;
  13159. pointDecays[ pointLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  13160. pointLength += 1;
  13161. } else if ( light instanceof THREE.SpotLight ) {
  13162. spotCount += 1;
  13163. if ( ! light.visible ) continue;
  13164. spotOffset = spotLength * 3;
  13165. setColorLinear( spotColors, spotOffset, color, intensity );
  13166. _direction.setFromMatrixPosition( light.matrixWorld );
  13167. spotPositions[ spotOffset + 0 ] = _direction.x;
  13168. spotPositions[ spotOffset + 1 ] = _direction.y;
  13169. spotPositions[ spotOffset + 2 ] = _direction.z;
  13170. spotDistances[ spotLength ] = distance;
  13171. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13172. _direction.sub( _vector3 );
  13173. _direction.normalize();
  13174. spotDirections[ spotOffset + 0 ] = _direction.x;
  13175. spotDirections[ spotOffset + 1 ] = _direction.y;
  13176. spotDirections[ spotOffset + 2 ] = _direction.z;
  13177. spotAnglesCos[ spotLength ] = Math.cos( light.angle );
  13178. spotExponents[ spotLength ] = light.exponent;
  13179. spotDecays[ spotLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  13180. spotLength += 1;
  13181. } else if ( light instanceof THREE.HemisphereLight ) {
  13182. hemiCount += 1;
  13183. if ( ! light.visible ) continue;
  13184. _direction.setFromMatrixPosition( light.matrixWorld );
  13185. _direction.normalize();
  13186. hemiOffset = hemiLength * 3;
  13187. hemiPositions[ hemiOffset + 0 ] = _direction.x;
  13188. hemiPositions[ hemiOffset + 1 ] = _direction.y;
  13189. hemiPositions[ hemiOffset + 2 ] = _direction.z;
  13190. skyColor = light.color;
  13191. groundColor = light.groundColor;
  13192. setColorLinear( hemiSkyColors, hemiOffset, skyColor, intensity );
  13193. setColorLinear( hemiGroundColors, hemiOffset, groundColor, intensity );
  13194. hemiLength += 1;
  13195. }
  13196. }
  13197. // null eventual remains from removed lights
  13198. // (this is to avoid if in shader)
  13199. for ( l = dirLength * 3, ll = Math.max( dirColors.length, dirCount * 3 ); l < ll; l ++ ) dirColors[ l ] = 0.0;
  13200. for ( l = pointLength * 3, ll = Math.max( pointColors.length, pointCount * 3 ); l < ll; l ++ ) pointColors[ l ] = 0.0;
  13201. for ( l = spotLength * 3, ll = Math.max( spotColors.length, spotCount * 3 ); l < ll; l ++ ) spotColors[ l ] = 0.0;
  13202. for ( l = hemiLength * 3, ll = Math.max( hemiSkyColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiSkyColors[ l ] = 0.0;
  13203. for ( l = hemiLength * 3, ll = Math.max( hemiGroundColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiGroundColors[ l ] = 0.0;
  13204. zlights.directional.length = dirLength;
  13205. zlights.point.length = pointLength;
  13206. zlights.spot.length = spotLength;
  13207. zlights.hemi.length = hemiLength;
  13208. zlights.ambient[ 0 ] = r;
  13209. zlights.ambient[ 1 ] = g;
  13210. zlights.ambient[ 2 ] = b;
  13211. }
  13212. // GL state setting
  13213. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  13214. if ( cullFace === THREE.CullFaceNone ) {
  13215. _gl.disable( _gl.CULL_FACE );
  13216. } else {
  13217. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  13218. _gl.frontFace( _gl.CW );
  13219. } else {
  13220. _gl.frontFace( _gl.CCW );
  13221. }
  13222. if ( cullFace === THREE.CullFaceBack ) {
  13223. _gl.cullFace( _gl.BACK );
  13224. } else if ( cullFace === THREE.CullFaceFront ) {
  13225. _gl.cullFace( _gl.FRONT );
  13226. } else {
  13227. _gl.cullFace( _gl.FRONT_AND_BACK );
  13228. }
  13229. _gl.enable( _gl.CULL_FACE );
  13230. }
  13231. };
  13232. this.setMaterialFaces = setMaterialFaces;
  13233. // Textures
  13234. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  13235. var extension;
  13236. if ( isImagePowerOfTwo ) {
  13237. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  13238. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  13239. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  13240. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  13241. } else {
  13242. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  13243. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  13244. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  13245. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping. ( ' + texture.sourceFile + ' )' );
  13246. }
  13247. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  13248. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  13249. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  13250. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter. ( ' + texture.sourceFile + ' )' );
  13251. }
  13252. }
  13253. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  13254. if ( extension && texture.type !== THREE.FloatType && texture.type !== THREE.HalfFloatType ) {
  13255. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  13256. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  13257. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  13258. }
  13259. }
  13260. }
  13261. this.uploadTexture = function ( texture, slot ) {
  13262. var textureProperties = properties.get( texture );
  13263. if ( textureProperties.__webglInit === undefined ) {
  13264. textureProperties.__webglInit = true;
  13265. texture.__webglInit = true;
  13266. texture.addEventListener( 'dispose', onTextureDispose );
  13267. textureProperties.__webglTexture = _gl.createTexture();
  13268. _this.info.memory.textures ++;
  13269. }
  13270. state.activeTexture( _gl.TEXTURE0 + slot );
  13271. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  13272. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  13273. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  13274. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  13275. texture.image = clampToMaxSize( texture.image, _maxTextureSize );
  13276. var image = texture.image,
  13277. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  13278. glFormat = paramThreeToGL( texture.format ),
  13279. glType = paramThreeToGL( texture.type );
  13280. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  13281. var mipmap, mipmaps = texture.mipmaps;
  13282. if ( texture instanceof THREE.DataTexture ) {
  13283. // use manually created mipmaps if available
  13284. // if there are no manual mipmaps
  13285. // set 0 level mipmap and then use GL to generate other mipmap levels
  13286. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  13287. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13288. mipmap = mipmaps[ i ];
  13289. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13290. }
  13291. texture.generateMipmaps = false;
  13292. } else {
  13293. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  13294. }
  13295. } else if ( texture instanceof THREE.CompressedTexture ) {
  13296. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13297. mipmap = mipmaps[ i ];
  13298. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  13299. if ( getCompressedTextureFormats().indexOf( glFormat ) > -1 ) {
  13300. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13301. } else {
  13302. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  13303. }
  13304. } else {
  13305. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13306. }
  13307. }
  13308. } else { // regular Texture (image, video, canvas)
  13309. // use manually created mipmaps if available
  13310. // if there are no manual mipmaps
  13311. // set 0 level mipmap and then use GL to generate other mipmap levels
  13312. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  13313. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13314. mipmap = mipmaps[ i ];
  13315. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  13316. }
  13317. texture.generateMipmaps = false;
  13318. } else {
  13319. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  13320. }
  13321. }
  13322. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  13323. texture.needsUpdate = false;
  13324. if ( texture.onUpdate ) texture.onUpdate( texture );
  13325. };
  13326. this.setTexture = function ( texture, slot ) {
  13327. // if the image has been uploaded into a separate renderer, will need to reupload to this renderer
  13328. if ( ( texture.image && texture.image.complete !== false ) && texture.__webglInit === true && properties.get( texture ).__webglInit === undefined ) {
  13329. texture.needsUpdate = true;
  13330. }
  13331. if ( texture.needsUpdate === true ) {
  13332. var image = texture.image;
  13333. if ( image === undefined ) {
  13334. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  13335. return;
  13336. }
  13337. if ( image.complete === false ) {
  13338. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  13339. return;
  13340. }
  13341. _this.uploadTexture( texture, slot );
  13342. return;
  13343. }
  13344. state.activeTexture( _gl.TEXTURE0 + slot );
  13345. state.bindTexture( _gl.TEXTURE_2D, properties.get( texture ).__webglTexture );
  13346. };
  13347. function clampToMaxSize ( image, maxSize ) {
  13348. if ( image.width > maxSize || image.height > maxSize ) {
  13349. // Warning: Scaling through the canvas will only work with images that use
  13350. // premultiplied alpha.
  13351. var scale = maxSize / Math.max( image.width, image.height );
  13352. var canvas = document.createElement( 'canvas' );
  13353. canvas.width = Math.floor( image.width * scale );
  13354. canvas.height = Math.floor( image.height * scale );
  13355. var context = canvas.getContext( '2d' );
  13356. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  13357. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  13358. return canvas;
  13359. }
  13360. return image;
  13361. }
  13362. function setCubeTexture ( texture, slot ) {
  13363. var textureProperties = properties.get( texture );
  13364. if ( texture.image.length === 6 ) {
  13365. if ( texture.needsUpdate ) {
  13366. if ( ! textureProperties.__image__webglTextureCube ) {
  13367. texture.addEventListener( 'dispose', onTextureDispose );
  13368. textureProperties.__image__webglTextureCube = _gl.createTexture();
  13369. _this.info.memory.textures ++;
  13370. }
  13371. state.activeTexture( _gl.TEXTURE0 + slot );
  13372. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  13373. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  13374. var isCompressed = texture instanceof THREE.CompressedTexture;
  13375. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  13376. var cubeImage = [];
  13377. for ( var i = 0; i < 6; i ++ ) {
  13378. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  13379. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], _maxCubemapSize );
  13380. } else {
  13381. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  13382. }
  13383. }
  13384. var image = cubeImage[ 0 ],
  13385. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  13386. glFormat = paramThreeToGL( texture.format ),
  13387. glType = paramThreeToGL( texture.type );
  13388. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  13389. for ( var i = 0; i < 6; i ++ ) {
  13390. if ( ! isCompressed ) {
  13391. if ( isDataTexture ) {
  13392. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  13393. } else {
  13394. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  13395. }
  13396. } else {
  13397. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  13398. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  13399. mipmap = mipmaps[ j ];
  13400. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  13401. if ( getCompressedTextureFormats().indexOf( glFormat ) > -1 ) {
  13402. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13403. } else {
  13404. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  13405. }
  13406. } else {
  13407. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13408. }
  13409. }
  13410. }
  13411. }
  13412. if ( texture.generateMipmaps && isImagePowerOfTwo ) {
  13413. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13414. }
  13415. texture.needsUpdate = false;
  13416. if ( texture.onUpdate ) texture.onUpdate( texture );
  13417. } else {
  13418. state.activeTexture( _gl.TEXTURE0 + slot );
  13419. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  13420. }
  13421. }
  13422. }
  13423. function setCubeTextureDynamic ( texture, slot ) {
  13424. state.activeTexture( _gl.TEXTURE0 + slot );
  13425. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  13426. }
  13427. // Render targets
  13428. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  13429. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13430. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, properties.get( renderTarget ).__webglTexture, 0 );
  13431. }
  13432. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  13433. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  13434. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13435. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  13436. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13437. /* For some reason this is not working. Defaulting to RGBA4.
  13438. } else if ( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13439. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  13440. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13441. */
  13442. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13443. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  13444. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13445. } else {
  13446. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  13447. }
  13448. }
  13449. this.setRenderTarget = function ( renderTarget ) {
  13450. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  13451. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  13452. var renderTargetProperties = properties.get( renderTarget );
  13453. if ( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  13454. if ( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  13455. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13456. renderTargetProperties.__webglTexture = _gl.createTexture();
  13457. _this.info.memory.textures ++;
  13458. // Setup texture, create render and frame buffers
  13459. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height ),
  13460. glFormat = paramThreeToGL( renderTarget.format ),
  13461. glType = paramThreeToGL( renderTarget.type );
  13462. if ( isCube ) {
  13463. renderTargetProperties.__webglFramebuffer = [];
  13464. renderTargetProperties.__webglRenderbuffer = [];
  13465. state.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTargetProperties.__webglTexture );
  13466. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget, isTargetPowerOfTwo );
  13467. for ( var i = 0; i < 6; i ++ ) {
  13468. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13469. renderTargetProperties.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  13470. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13471. setupFrameBuffer( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  13472. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer[ i ], renderTarget );
  13473. }
  13474. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13475. } else {
  13476. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13477. if ( renderTarget.shareDepthFrom ) {
  13478. renderTargetProperties.__webglRenderbuffer = renderTarget.shareDepthFrom.__webglRenderbuffer;
  13479. } else {
  13480. renderTargetProperties.__webglRenderbuffer = _gl.createRenderbuffer();
  13481. }
  13482. state.bindTexture( _gl.TEXTURE_2D, renderTargetProperties.__webglTexture );
  13483. setTextureParameters( _gl.TEXTURE_2D, renderTarget, isTargetPowerOfTwo );
  13484. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13485. setupFrameBuffer( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  13486. if ( renderTarget.shareDepthFrom ) {
  13487. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13488. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  13489. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13490. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  13491. }
  13492. } else {
  13493. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer, renderTarget );
  13494. }
  13495. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  13496. }
  13497. // Release everything
  13498. if ( isCube ) {
  13499. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  13500. } else {
  13501. state.bindTexture( _gl.TEXTURE_2D, null );
  13502. }
  13503. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  13504. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  13505. }
  13506. var framebuffer, width, height, vx, vy;
  13507. if ( renderTarget ) {
  13508. var renderTargetProperties = properties.get( renderTarget );
  13509. if ( isCube ) {
  13510. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  13511. } else {
  13512. framebuffer = renderTargetProperties.__webglFramebuffer;
  13513. }
  13514. width = renderTarget.width;
  13515. height = renderTarget.height;
  13516. vx = 0;
  13517. vy = 0;
  13518. } else {
  13519. framebuffer = null;
  13520. width = _viewportWidth;
  13521. height = _viewportHeight;
  13522. vx = _viewportX;
  13523. vy = _viewportY;
  13524. }
  13525. if ( framebuffer !== _currentFramebuffer ) {
  13526. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13527. _gl.viewport( vx, vy, width, height );
  13528. _currentFramebuffer = framebuffer;
  13529. }
  13530. _currentWidth = width;
  13531. _currentHeight = height;
  13532. };
  13533. this.readRenderTargetPixels = function( renderTarget, x, y, width, height, buffer ) {
  13534. if ( ! ( renderTarget instanceof THREE.WebGLRenderTarget ) ) {
  13535. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  13536. return;
  13537. }
  13538. if ( properties.get( renderTarget ).__webglFramebuffer ) {
  13539. if ( renderTarget.format !== THREE.RGBAFormat ) {
  13540. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA format. readPixels can read only RGBA format.' );
  13541. return;
  13542. }
  13543. var restore = false;
  13544. if ( properties.get( renderTarget ).__webglFramebuffer !== _currentFramebuffer ) {
  13545. _gl.bindFramebuffer( _gl.FRAMEBUFFER, properties.get( renderTarget ).__webglFramebuffer );
  13546. restore = true;
  13547. }
  13548. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  13549. _gl.readPixels( x, y, width, height, _gl.RGBA, _gl.UNSIGNED_BYTE, buffer );
  13550. } else {
  13551. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  13552. }
  13553. if ( restore ) {
  13554. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  13555. }
  13556. }
  13557. };
  13558. function updateRenderTargetMipmap ( renderTarget ) {
  13559. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  13560. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( renderTarget ).__webglTexture );
  13561. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13562. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  13563. } else {
  13564. state.bindTexture( _gl.TEXTURE_2D, properties.get( renderTarget ).__webglTexture );
  13565. _gl.generateMipmap( _gl.TEXTURE_2D );
  13566. state.bindTexture( _gl.TEXTURE_2D, null );
  13567. }
  13568. }
  13569. // Fallback filters for non-power-of-2 textures
  13570. function filterFallback ( f ) {
  13571. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  13572. return _gl.NEAREST;
  13573. }
  13574. return _gl.LINEAR;
  13575. }
  13576. // Map three.js constants to WebGL constants
  13577. function paramThreeToGL ( p ) {
  13578. var extension;
  13579. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  13580. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  13581. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  13582. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  13583. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  13584. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  13585. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  13586. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  13587. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  13588. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  13589. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  13590. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  13591. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  13592. if ( p === THREE.ByteType ) return _gl.BYTE;
  13593. if ( p === THREE.ShortType ) return _gl.SHORT;
  13594. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  13595. if ( p === THREE.IntType ) return _gl.INT;
  13596. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  13597. if ( p === THREE.FloatType ) return _gl.FLOAT;
  13598. extension = extensions.get( 'OES_texture_half_float' );
  13599. if ( extension !== null ) {
  13600. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  13601. }
  13602. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  13603. if ( p === THREE.RGBFormat ) return _gl.RGB;
  13604. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  13605. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  13606. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  13607. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  13608. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  13609. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  13610. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  13611. if ( p === THREE.OneFactor ) return _gl.ONE;
  13612. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  13613. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  13614. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  13615. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  13616. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  13617. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  13618. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  13619. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  13620. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  13621. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13622. if ( extension !== null ) {
  13623. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13624. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13625. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13626. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13627. }
  13628. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13629. if ( extension !== null ) {
  13630. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13631. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13632. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13633. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13634. }
  13635. extension = extensions.get( 'EXT_blend_minmax' );
  13636. if ( extension !== null ) {
  13637. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  13638. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  13639. }
  13640. return 0;
  13641. }
  13642. // Allocations
  13643. function allocateBones ( object ) {
  13644. if ( _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  13645. return 1024;
  13646. } else {
  13647. // default for when object is not specified
  13648. // ( for example when prebuilding shader to be used with multiple objects )
  13649. //
  13650. // - leave some extra space for other uniforms
  13651. // - limit here is ANGLE's 254 max uniform vectors
  13652. // (up to 54 should be safe)
  13653. var nVertexUniforms = _gl.getParameter( _gl.MAX_VERTEX_UNIFORM_VECTORS );
  13654. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  13655. var maxBones = nVertexMatrices;
  13656. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  13657. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  13658. if ( maxBones < object.skeleton.bones.length ) {
  13659. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  13660. }
  13661. }
  13662. return maxBones;
  13663. }
  13664. }
  13665. function allocateLights( lights ) {
  13666. var dirLights = 0;
  13667. var pointLights = 0;
  13668. var spotLights = 0;
  13669. var hemiLights = 0;
  13670. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  13671. var light = lights[ l ];
  13672. if ( light.onlyShadow || light.visible === false ) continue;
  13673. if ( light instanceof THREE.DirectionalLight ) dirLights ++;
  13674. if ( light instanceof THREE.PointLight ) pointLights ++;
  13675. if ( light instanceof THREE.SpotLight ) spotLights ++;
  13676. if ( light instanceof THREE.HemisphereLight ) hemiLights ++;
  13677. }
  13678. return { 'directional': dirLights, 'point': pointLights, 'spot': spotLights, 'hemi': hemiLights };
  13679. }
  13680. function allocateShadows( lights ) {
  13681. var maxShadows = 0;
  13682. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  13683. var light = lights[ l ];
  13684. if ( ! light.castShadow ) continue;
  13685. if ( light instanceof THREE.SpotLight ) maxShadows ++;
  13686. if ( light instanceof THREE.DirectionalLight && ! light.shadowCascade ) maxShadows ++;
  13687. }
  13688. return maxShadows;
  13689. }
  13690. // DEPRECATED
  13691. this.initMaterial = function () {
  13692. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  13693. };
  13694. this.addPrePlugin = function () {
  13695. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  13696. };
  13697. this.addPostPlugin = function () {
  13698. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  13699. };
  13700. this.updateShadowMap = function () {
  13701. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  13702. };
  13703. Object.defineProperties( this, {
  13704. shadowMapEnabled: {
  13705. get: function () {
  13706. return shadowMap.enabled;
  13707. },
  13708. set: function ( value ) {
  13709. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  13710. shadowMap.enabled = value;
  13711. }
  13712. },
  13713. shadowMapType: {
  13714. get: function () {
  13715. return shadowMap.type;
  13716. },
  13717. set: function ( value ) {
  13718. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  13719. shadowMap.type = value;
  13720. }
  13721. },
  13722. shadowMapCullFace: {
  13723. get: function () {
  13724. return shadowMap.cullFace;
  13725. },
  13726. set: function ( value ) {
  13727. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  13728. shadowMap.cullFace = value;
  13729. }
  13730. },
  13731. shadowMapDebug: {
  13732. get: function () {
  13733. return shadowMap.debug;
  13734. },
  13735. set: function ( value ) {
  13736. console.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' );
  13737. shadowMap.debug = value;
  13738. }
  13739. },
  13740. shadowMapCascade: {
  13741. get: function () {
  13742. return shadowMap.cascade;
  13743. },
  13744. set: function ( value ) {
  13745. console.warn( 'THREE.WebGLRenderer: .shadowMapCascade is now .shadowMap.cascade.' );
  13746. shadowMap.cascade = value;
  13747. }
  13748. }
  13749. } );
  13750. };
  13751. // File:src/renderers/WebGLRenderTarget.js
  13752. /**
  13753. * @author szimek / https://github.com/szimek/
  13754. * @author alteredq / http://alteredqualia.com/
  13755. */
  13756. THREE.WebGLRenderTarget = function ( width, height, options ) {
  13757. this.uuid = THREE.Math.generateUUID();
  13758. this.width = width;
  13759. this.height = height;
  13760. options = options || {};
  13761. this.wrapS = options.wrapS !== undefined ? options.wrapS : THREE.ClampToEdgeWrapping;
  13762. this.wrapT = options.wrapT !== undefined ? options.wrapT : THREE.ClampToEdgeWrapping;
  13763. this.magFilter = options.magFilter !== undefined ? options.magFilter : THREE.LinearFilter;
  13764. this.minFilter = options.minFilter !== undefined ? options.minFilter : THREE.LinearMipMapLinearFilter;
  13765. this.anisotropy = options.anisotropy !== undefined ? options.anisotropy : 1;
  13766. this.offset = new THREE.Vector2( 0, 0 );
  13767. this.repeat = new THREE.Vector2( 1, 1 );
  13768. this.format = options.format !== undefined ? options.format : THREE.RGBAFormat;
  13769. this.type = options.type !== undefined ? options.type : THREE.UnsignedByteType;
  13770. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  13771. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  13772. this.generateMipmaps = true;
  13773. this.shareDepthFrom = options.shareDepthFrom !== undefined ? options.shareDepthFrom : null;
  13774. };
  13775. THREE.WebGLRenderTarget.prototype = {
  13776. constructor: THREE.WebGLRenderTarget,
  13777. setSize: function ( width, height ) {
  13778. if ( this.width !== width || this.height !== height ) {
  13779. this.width = width;
  13780. this.height = height;
  13781. this.dispose();
  13782. }
  13783. },
  13784. clone: function () {
  13785. var tmp = new THREE.WebGLRenderTarget( this.width, this.height );
  13786. tmp.wrapS = this.wrapS;
  13787. tmp.wrapT = this.wrapT;
  13788. tmp.magFilter = this.magFilter;
  13789. tmp.minFilter = this.minFilter;
  13790. tmp.anisotropy = this.anisotropy;
  13791. tmp.offset.copy( this.offset );
  13792. tmp.repeat.copy( this.repeat );
  13793. tmp.format = this.format;
  13794. tmp.type = this.type;
  13795. tmp.depthBuffer = this.depthBuffer;
  13796. tmp.stencilBuffer = this.stencilBuffer;
  13797. tmp.generateMipmaps = this.generateMipmaps;
  13798. tmp.shareDepthFrom = this.shareDepthFrom;
  13799. return tmp;
  13800. },
  13801. dispose: function () {
  13802. this.dispatchEvent( { type: 'dispose' } );
  13803. }
  13804. };
  13805. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  13806. // File:src/renderers/WebGLRenderTargetCube.js
  13807. /**
  13808. * @author alteredq / http://alteredqualia.com
  13809. */
  13810. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  13811. THREE.WebGLRenderTarget.call( this, width, height, options );
  13812. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  13813. };
  13814. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  13815. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  13816. // File:src/renderers/webgl/WebGLExtensions.js
  13817. /**
  13818. * @author mrdoob / http://mrdoob.com/
  13819. */
  13820. THREE.WebGLExtensions = function ( gl ) {
  13821. var extensions = {};
  13822. this.get = function ( name ) {
  13823. if ( extensions[ name ] !== undefined ) {
  13824. return extensions[ name ];
  13825. }
  13826. var extension;
  13827. switch ( name ) {
  13828. case 'EXT_texture_filter_anisotropic':
  13829. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  13830. break;
  13831. case 'WEBGL_compressed_texture_s3tc':
  13832. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  13833. break;
  13834. case 'WEBGL_compressed_texture_pvrtc':
  13835. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  13836. break;
  13837. default:
  13838. extension = gl.getExtension( name );
  13839. }
  13840. if ( extension === null ) {
  13841. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  13842. }
  13843. extensions[ name ] = extension;
  13844. return extension;
  13845. };
  13846. };
  13847. // File:src/renderers/webgl/WebGLGeometries.js
  13848. /**
  13849. * @author mrdoob / http://mrdoob.com/
  13850. */
  13851. THREE.WebGLGeometries = function ( gl, info ) {
  13852. var geometries = {};
  13853. this.get = function ( object ) {
  13854. var geometry = object.geometry;
  13855. if ( geometries[ geometry.id ] !== undefined ) {
  13856. return geometries[ geometry.id ];
  13857. }
  13858. geometry.addEventListener( 'dispose', onGeometryDispose );
  13859. if ( geometry instanceof THREE.BufferGeometry ) {
  13860. geometries[ geometry.id ] = geometry;
  13861. } else {
  13862. geometries[ geometry.id ] = new THREE.BufferGeometry().setFromObject( object );
  13863. }
  13864. info.memory.geometries ++;
  13865. return geometries[ geometry.id ];
  13866. };
  13867. function onGeometryDispose( event ) {
  13868. var geometry = event.target;
  13869. var buffergeometry = geometries[ geometry.id ];
  13870. for ( var name in buffergeometry.attributes ) {
  13871. var attribute = buffergeometry.attributes[ name ];
  13872. if ( attribute.buffer !== undefined ) {
  13873. gl.deleteBuffer( attribute.buffer );
  13874. delete attribute.buffer;
  13875. }
  13876. }
  13877. geometry.removeEventListener( 'dispose', onGeometryDispose );
  13878. delete geometries[ geometry.id ];
  13879. info.memory.geometries --;
  13880. }
  13881. };
  13882. // File:src/renderers/webgl/WebGLObjects.js
  13883. /**
  13884. * @author mrdoob / http://mrdoob.com/
  13885. */
  13886. THREE.WebGLObjects = function ( gl, properties, info ) {
  13887. var objects = {};
  13888. var objectsImmediate = [];
  13889. var morphInfluences = new Float32Array( 8 );
  13890. var geometries = new THREE.WebGLGeometries( gl, info );
  13891. //
  13892. function onObjectRemoved( event ) {
  13893. var object = event.target;
  13894. object.traverse( function ( child ) {
  13895. child.removeEventListener( 'remove', onObjectRemoved );
  13896. removeObject( child );
  13897. } );
  13898. }
  13899. function removeObject( object ) {
  13900. if ( object instanceof THREE.Mesh ||
  13901. object instanceof THREE.PointCloud ||
  13902. object instanceof THREE.Line ) {
  13903. delete objects[ object.id ];
  13904. } else if ( object instanceof THREE.ImmediateRenderObject || object.immediateRenderCallback ) {
  13905. removeInstances( objectsImmediate, object );
  13906. }
  13907. delete object._modelViewMatrix;
  13908. delete object._normalMatrix;
  13909. properties.delete( object );
  13910. }
  13911. function removeInstances( objlist, object ) {
  13912. for ( var o = objlist.length - 1; o >= 0; o -- ) {
  13913. if ( objlist[ o ].object === object ) {
  13914. objlist.splice( o, 1 );
  13915. }
  13916. }
  13917. }
  13918. //
  13919. this.objects = objects;
  13920. this.objectsImmediate = objectsImmediate;
  13921. this.geometries = geometries;
  13922. this.init = function ( object ) {
  13923. var objectProperties = properties.get( object );
  13924. if ( objectProperties.__webglInit === undefined ) {
  13925. objectProperties.__webglInit = true;
  13926. object._modelViewMatrix = new THREE.Matrix4();
  13927. object._normalMatrix = new THREE.Matrix3();
  13928. object.addEventListener( 'removed', onObjectRemoved );
  13929. }
  13930. if ( objectProperties.__webglActive === undefined ) {
  13931. objectProperties.__webglActive = true;
  13932. if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.PointCloud ) {
  13933. objects[ object.id ] = {
  13934. id: object.id,
  13935. object: object,
  13936. z: 0
  13937. };
  13938. } else if ( object instanceof THREE.ImmediateRenderObject || object.immediateRenderCallback ) {
  13939. objectsImmediate.push( {
  13940. id: null,
  13941. object: object,
  13942. opaque: null,
  13943. transparent: null,
  13944. z: 0
  13945. } );
  13946. }
  13947. }
  13948. };
  13949. function numericalSort ( a, b ) {
  13950. return b[ 0 ] - a[ 0 ];
  13951. }
  13952. function updateObject( object ) {
  13953. var geometry = geometries.get( object );
  13954. if ( object.geometry.dynamic === true ) {
  13955. geometry.updateFromObject( object );
  13956. }
  13957. // morph targets
  13958. if ( object.morphTargetInfluences !== undefined ) {
  13959. var activeInfluences = [];
  13960. var morphTargetInfluences = object.morphTargetInfluences;
  13961. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  13962. var influence = morphTargetInfluences[ i ];
  13963. activeInfluences.push( [ influence, i ] );
  13964. }
  13965. activeInfluences.sort( numericalSort );
  13966. if ( activeInfluences.length > 8 ) {
  13967. activeInfluences.length = 8;
  13968. }
  13969. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  13970. morphInfluences[ i ] = activeInfluences[ i ][ 0 ];
  13971. var attribute = geometry.morphAttributes[ activeInfluences[ i ][ 1 ] ];
  13972. geometry.addAttribute( 'morphTarget' + i, attribute );
  13973. }
  13974. var material = object.material;
  13975. if ( material.program !== undefined ) {
  13976. var uniforms = material.program.getUniforms();
  13977. if ( uniforms.morphTargetInfluences !== null ) {
  13978. gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  13979. }
  13980. } else {
  13981. console.warn( 'TOFIX: material.program is undefined' );
  13982. }
  13983. }
  13984. //
  13985. var attributes = geometry.attributes;
  13986. for ( var name in attributes ) {
  13987. var attribute = attributes[ name ];
  13988. var bufferType = ( name === 'index' ) ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER;
  13989. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  13990. var attributeProperties = properties.get( data );
  13991. if ( attributeProperties.__webglBuffer === undefined ) {
  13992. attributeProperties.__webglBuffer = gl.createBuffer();
  13993. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  13994. var usage = gl.STATIC_DRAW;
  13995. if ( data instanceof THREE.DynamicBufferAttribute
  13996. || ( data instanceof THREE.InstancedBufferAttribute && data.dynamic === true )
  13997. || ( data instanceof THREE.InterleavedBuffer && data.dynamic === true ) ) {
  13998. usage = gl.DYNAMIC_DRAW;
  13999. }
  14000. gl.bufferData( bufferType, data.array, usage );
  14001. data.needsUpdate = false;
  14002. } else if ( data.needsUpdate === true ) {
  14003. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  14004. if ( data.updateRange === undefined || data.updateRange.count === -1 ) { // Not using update ranges
  14005. gl.bufferSubData( bufferType, 0, data.array );
  14006. } else if ( data.updateRange.count === 0 ) {
  14007. console.error( 'THREE.WebGLRenderer.updateObject: using updateRange for THREE.DynamicBufferAttribute and marked as needsUpdate but count is 0, ensure you are using set methods or updating manually.' );
  14008. } else {
  14009. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  14010. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  14011. data.updateRange.count = 0; // reset range
  14012. }
  14013. data.needsUpdate = false;
  14014. }
  14015. }
  14016. };
  14017. // returns the webgl buffer for a specified attribute
  14018. this.getAttributeBuffer = function ( attribute ) {
  14019. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14020. return properties.get( attribute.data ).__webglBuffer
  14021. }
  14022. return properties.get( attribute ).__webglBuffer;
  14023. }
  14024. this.update = function ( renderList ) {
  14025. for ( var i = 0, ul = renderList.length; i < ul; i++ ) {
  14026. var object = renderList[i].object;
  14027. if ( object.material.visible !== false ) {
  14028. updateObject( object );
  14029. }
  14030. }
  14031. };
  14032. };
  14033. // File:src/renderers/webgl/WebGLProgram.js
  14034. THREE.WebGLProgram = ( function () {
  14035. var programIdCount = 0;
  14036. function generateDefines( defines ) {
  14037. var chunks = [];
  14038. for ( var name in defines ) {
  14039. var value = defines[ name ];
  14040. if ( value === false ) continue;
  14041. chunks.push( '#define ' + name + ' ' + value );
  14042. }
  14043. return chunks.join( '\n' );
  14044. }
  14045. function fetchUniformLocations( gl, program, identifiers ) {
  14046. var uniforms = {};
  14047. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  14048. for ( var i = 0; i < n; i ++ ) {
  14049. var info = gl.getActiveUniform( program , i );
  14050. var name = info.name;
  14051. var location = gl.getUniformLocation( program, name );
  14052. //console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  14053. var suffixPos = name.lastIndexOf( '[0]' );
  14054. if ( suffixPos !== -1 && suffixPos === name.length - 3 ) {
  14055. uniforms[ name.substr( 0, suffixPos ) ] = location;
  14056. }
  14057. uniforms[ name ] = location;
  14058. }
  14059. return uniforms;
  14060. }
  14061. function fetchAttributeLocations( gl, program, identifiers ) {
  14062. var attributes = {};
  14063. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  14064. for ( var i = 0; i < n; i ++ ) {
  14065. var info = gl.getActiveAttrib( program , i );
  14066. var name = info.name;
  14067. //console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name);
  14068. attributes[ name ] = gl.getAttribLocation( program, name );
  14069. }
  14070. return attributes;
  14071. }
  14072. function filterEmptyLine( string ) {
  14073. return string !== '';
  14074. }
  14075. return function ( renderer, code, material, parameters ) {
  14076. var gl = renderer.context;
  14077. var defines = material.defines;
  14078. var uniforms = material.__webglShader.uniforms;
  14079. var attributes = material.attributes;
  14080. var vertexShader = material.__webglShader.vertexShader;
  14081. var fragmentShader = material.__webglShader.fragmentShader;
  14082. var index0AttributeName = material.index0AttributeName;
  14083. /*
  14084. if ( index0AttributeName === undefined && parameters.morphTargets === true ) {
  14085. // programs with morphTargets displace position out of attribute 0
  14086. index0AttributeName = 'position';
  14087. }
  14088. */
  14089. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  14090. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  14091. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  14092. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  14093. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  14094. }
  14095. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  14096. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  14097. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  14098. if ( parameters.envMap ) {
  14099. switch ( material.envMap.mapping ) {
  14100. case THREE.CubeReflectionMapping:
  14101. case THREE.CubeRefractionMapping:
  14102. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  14103. break;
  14104. case THREE.EquirectangularReflectionMapping:
  14105. case THREE.EquirectangularRefractionMapping:
  14106. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  14107. break;
  14108. case THREE.SphericalReflectionMapping:
  14109. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  14110. break;
  14111. }
  14112. switch ( material.envMap.mapping ) {
  14113. case THREE.CubeRefractionMapping:
  14114. case THREE.EquirectangularRefractionMapping:
  14115. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  14116. break;
  14117. }
  14118. switch ( material.combine ) {
  14119. case THREE.MultiplyOperation:
  14120. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  14121. break;
  14122. case THREE.MixOperation:
  14123. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  14124. break;
  14125. case THREE.AddOperation:
  14126. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  14127. break;
  14128. }
  14129. }
  14130. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  14131. // console.log( 'building new program ' );
  14132. //
  14133. var customDefines = generateDefines( defines );
  14134. //
  14135. var program = gl.createProgram();
  14136. var prefixVertex, prefixFragment;
  14137. if ( material instanceof THREE.RawShaderMaterial ) {
  14138. prefixVertex = '';
  14139. prefixFragment = '';
  14140. } else {
  14141. prefixVertex = [
  14142. 'precision ' + parameters.precision + ' float;',
  14143. 'precision ' + parameters.precision + ' int;',
  14144. '#define SHADER_NAME ' + material.__webglShader.name,
  14145. customDefines,
  14146. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  14147. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  14148. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  14149. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  14150. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  14151. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  14152. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  14153. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  14154. '#define MAX_SHADOWS ' + parameters.maxShadows,
  14155. '#define MAX_BONES ' + parameters.maxBones,
  14156. parameters.map ? '#define USE_MAP' : '',
  14157. parameters.envMap ? '#define USE_ENVMAP' : '',
  14158. parameters.envMap ? '#define ' + envMapModeDefine : '',
  14159. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  14160. parameters.aoMap ? '#define USE_AOMAP' : '',
  14161. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  14162. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  14163. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  14164. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  14165. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  14166. parameters.vertexColors ? '#define USE_COLOR' : '',
  14167. parameters.flatShading ? '#define FLAT_SHADED': '',
  14168. parameters.skinning ? '#define USE_SKINNING' : '',
  14169. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  14170. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  14171. parameters.morphNormals ? '#define USE_MORPHNORMALS' : '',
  14172. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  14173. parameters.flipSided ? '#define FLIP_SIDED' : '',
  14174. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  14175. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  14176. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  14177. parameters.shadowMapCascade ? '#define SHADOWMAP_CASCADE' : '',
  14178. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  14179. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  14180. parameters.logarithmicDepthBuffer && renderer.extensions.get('EXT_frag_depth') ? '#define USE_LOGDEPTHBUF_EXT' : '',
  14181. 'uniform mat4 modelMatrix;',
  14182. 'uniform mat4 modelViewMatrix;',
  14183. 'uniform mat4 projectionMatrix;',
  14184. 'uniform mat4 viewMatrix;',
  14185. 'uniform mat3 normalMatrix;',
  14186. 'uniform vec3 cameraPosition;',
  14187. 'attribute vec3 position;',
  14188. 'attribute vec3 normal;',
  14189. 'attribute vec2 uv;',
  14190. '#ifdef USE_COLOR',
  14191. ' attribute vec3 color;',
  14192. '#endif',
  14193. '#ifdef USE_MORPHTARGETS',
  14194. ' attribute vec3 morphTarget0;',
  14195. ' attribute vec3 morphTarget1;',
  14196. ' attribute vec3 morphTarget2;',
  14197. ' attribute vec3 morphTarget3;',
  14198. ' #ifdef USE_MORPHNORMALS',
  14199. ' attribute vec3 morphNormal0;',
  14200. ' attribute vec3 morphNormal1;',
  14201. ' attribute vec3 morphNormal2;',
  14202. ' attribute vec3 morphNormal3;',
  14203. ' #else',
  14204. ' attribute vec3 morphTarget4;',
  14205. ' attribute vec3 morphTarget5;',
  14206. ' attribute vec3 morphTarget6;',
  14207. ' attribute vec3 morphTarget7;',
  14208. ' #endif',
  14209. '#endif',
  14210. '#ifdef USE_SKINNING',
  14211. ' attribute vec4 skinIndex;',
  14212. ' attribute vec4 skinWeight;',
  14213. '#endif',
  14214. '\n'
  14215. ].filter( filterEmptyLine ).join( '\n' );
  14216. prefixFragment = [
  14217. ( parameters.bumpMap || parameters.normalMap || parameters.flatShading || material.derivatives ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  14218. 'precision ' + parameters.precision + ' float;',
  14219. 'precision ' + parameters.precision + ' int;',
  14220. '#define SHADER_NAME ' + material.__webglShader.name,
  14221. customDefines,
  14222. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  14223. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  14224. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  14225. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  14226. '#define MAX_SHADOWS ' + parameters.maxShadows,
  14227. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  14228. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  14229. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  14230. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  14231. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  14232. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  14233. parameters.map ? '#define USE_MAP' : '',
  14234. parameters.envMap ? '#define USE_ENVMAP' : '',
  14235. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  14236. parameters.envMap ? '#define ' + envMapModeDefine : '',
  14237. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  14238. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  14239. parameters.aoMap ? '#define USE_AOMAP' : '',
  14240. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  14241. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  14242. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  14243. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  14244. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  14245. parameters.vertexColors ? '#define USE_COLOR' : '',
  14246. parameters.flatShading ? '#define FLAT_SHADED': '',
  14247. parameters.metal ? '#define METAL' : '',
  14248. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  14249. parameters.flipSided ? '#define FLIP_SIDED' : '',
  14250. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  14251. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  14252. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  14253. parameters.shadowMapCascade ? '#define SHADOWMAP_CASCADE' : '',
  14254. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  14255. parameters.logarithmicDepthBuffer && renderer.extensions.get('EXT_frag_depth') ? '#define USE_LOGDEPTHBUF_EXT' : '',
  14256. 'uniform mat4 viewMatrix;',
  14257. 'uniform vec3 cameraPosition;',
  14258. '\n'
  14259. ].filter( filterEmptyLine ).join( '\n' );
  14260. }
  14261. var vertexGlsl = prefixVertex + vertexShader;
  14262. var fragmentGlsl = prefixFragment + fragmentShader;
  14263. var glVertexShader = new THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  14264. var glFragmentShader = new THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  14265. gl.attachShader( program, glVertexShader );
  14266. gl.attachShader( program, glFragmentShader );
  14267. if ( index0AttributeName !== undefined ) {
  14268. // Force a particular attribute to index 0.
  14269. // because potentially expensive emulation is done by browser if attribute 0 is disabled.
  14270. // And, color, for example is often automatically bound to index 0 so disabling it
  14271. gl.bindAttribLocation( program, 0, index0AttributeName );
  14272. }
  14273. gl.linkProgram( program );
  14274. var programLogInfo = gl.getProgramInfoLog( program );
  14275. var vertexErrorLogInfo = gl.getShaderInfoLog( glVertexShader );
  14276. var fragmentErrorLogInfo = gl.getShaderInfoLog( glFragmentShader );
  14277. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  14278. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLogInfo, vertexErrorLogInfo, fragmentErrorLogInfo );
  14279. }
  14280. if ( programLogInfo !== '' ) {
  14281. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLogInfo );
  14282. }
  14283. // clean up
  14284. gl.deleteShader( glVertexShader );
  14285. gl.deleteShader( glFragmentShader );
  14286. // set up caching for uniform locations
  14287. var getUniforms = function() { return this._cachedUniforms; };
  14288. this.getUniforms = function() {
  14289. // fetch, cache, and next time just use a dumb accessor
  14290. var uniforms = fetchUniformLocations( gl, program );
  14291. this._cachedUniforms = uniforms;
  14292. this.getUniforms = getUniforms;
  14293. return uniforms;
  14294. };
  14295. // set up caching for attribute locations
  14296. var getAttributes = function() { return this._cachedAttributes; };
  14297. this.getAttributes = function() {
  14298. var attributes = fetchAttributeLocations( gl, program );
  14299. this._cachedAttributes = attributes;
  14300. this.getAttributes = getAttributes;
  14301. return attributes;
  14302. };
  14303. // DEPRECATED
  14304. Object.defineProperties( this, {
  14305. uniforms: {
  14306. get: function() {
  14307. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  14308. return this.getUniforms();
  14309. }
  14310. },
  14311. attributes: {
  14312. get: function() {
  14313. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  14314. return this.getAttributes();
  14315. }
  14316. }
  14317. });
  14318. //
  14319. this.id = programIdCount ++;
  14320. this.code = code;
  14321. this.usedTimes = 1;
  14322. this.program = program;
  14323. this.vertexShader = glVertexShader;
  14324. this.fragmentShader = glFragmentShader;
  14325. return this;
  14326. };
  14327. } )();
  14328. // File:src/renderers/webgl/WebGLProperties.js
  14329. /**
  14330. * @author fordacious / fordacious.github.io
  14331. */
  14332. THREE.WebGLProperties = function () {
  14333. var properties = {};
  14334. this.get = function ( object ) {
  14335. if ( properties[ object.uuid ] === undefined ) {
  14336. properties[ object.uuid ] = {};
  14337. }
  14338. return properties[ object.uuid ];
  14339. };
  14340. this.delete = function ( object ) {
  14341. delete properties[ object.uuid ];
  14342. };
  14343. this.clear = function () {
  14344. properties = {};
  14345. };
  14346. };
  14347. // File:src/renderers/webgl/WebGLShader.js
  14348. THREE.WebGLShader = ( function () {
  14349. var addLineNumbers = function ( string ) {
  14350. var lines = string.split( '\n' );
  14351. for ( var i = 0; i < lines.length; i ++ ) {
  14352. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  14353. }
  14354. return lines.join( '\n' );
  14355. };
  14356. return function ( gl, type, string ) {
  14357. var shader = gl.createShader( type );
  14358. gl.shaderSource( shader, string );
  14359. gl.compileShader( shader );
  14360. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  14361. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  14362. }
  14363. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  14364. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  14365. }
  14366. // --enable-privileged-webgl-extension
  14367. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  14368. return shader;
  14369. };
  14370. } )();
  14371. // File:src/renderers/webgl/WebGLShadowMap.js
  14372. /**
  14373. * @author alteredq / http://alteredqualia.com/
  14374. * @author mrdoob / http://mrdoob.com/
  14375. */
  14376. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  14377. var _gl = _renderer.context,
  14378. _state = _renderer.state,
  14379. _frustum = new THREE.Frustum(),
  14380. _projScreenMatrix = new THREE.Matrix4(),
  14381. _min = new THREE.Vector3(),
  14382. _max = new THREE.Vector3(),
  14383. _webglObjects = _objects.objects,
  14384. _webglObjectsImmediate = _objects.objectsImmediate,
  14385. _matrixPosition = new THREE.Vector3(),
  14386. _renderList = [];
  14387. // init
  14388. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  14389. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  14390. var _depthMaterial = new THREE.ShaderMaterial( {
  14391. uniforms: depthUniforms,
  14392. vertexShader: depthShader.vertexShader,
  14393. fragmentShader: depthShader.fragmentShader
  14394. } );
  14395. var _depthMaterialMorph = new THREE.ShaderMaterial( {
  14396. uniforms: depthUniforms,
  14397. vertexShader: depthShader.vertexShader,
  14398. fragmentShader: depthShader.fragmentShader,
  14399. morphTargets: true
  14400. } );
  14401. var _depthMaterialSkin = new THREE.ShaderMaterial( {
  14402. uniforms: depthUniforms,
  14403. vertexShader: depthShader.vertexShader,
  14404. fragmentShader: depthShader.fragmentShader,
  14405. skinning: true
  14406. } );
  14407. var _depthMaterialMorphSkin = new THREE.ShaderMaterial( {
  14408. uniforms: depthUniforms,
  14409. vertexShader: depthShader.vertexShader,
  14410. fragmentShader: depthShader.fragmentShader,
  14411. morphTargets: true,
  14412. skinning: true
  14413. } );
  14414. _depthMaterial._shadowPass = true;
  14415. _depthMaterialMorph._shadowPass = true;
  14416. _depthMaterialSkin._shadowPass = true;
  14417. _depthMaterialMorphSkin._shadowPass = true;
  14418. //
  14419. var scope = this;
  14420. this.enabled = false;
  14421. this.type = THREE.PCFShadowMap;
  14422. this.cullFace = THREE.CullFaceFront;
  14423. this.debug = false;
  14424. this.cascade = false;
  14425. this.render = function ( scene, camera ) {
  14426. if ( scope.enabled === false ) return;
  14427. var i, il, j, jl, n,
  14428. shadowMap, shadowMatrix, shadowCamera,
  14429. webglObject, object, material, light,
  14430. lights = [],
  14431. k = 0,
  14432. fog = null;
  14433. // set GL state for depth map
  14434. _gl.clearColor( 1, 1, 1, 1 );
  14435. _state.setBlend( false );
  14436. _gl.enable( _gl.CULL_FACE );
  14437. _gl.frontFace( _gl.CCW );
  14438. if ( scope.cullFace === THREE.CullFaceFront ) {
  14439. _gl.cullFace( _gl.FRONT );
  14440. } else {
  14441. _gl.cullFace( _gl.BACK );
  14442. }
  14443. _state.setDepthTest( true );
  14444. // preprocess lights
  14445. // - skip lights that are not casting shadows
  14446. // - create virtual lights for cascaded shadow maps
  14447. for ( i = 0, il = _lights.length; i < il; i ++ ) {
  14448. light = _lights[ i ];
  14449. if ( ! light.castShadow ) continue;
  14450. if ( ( light instanceof THREE.DirectionalLight ) && light.shadowCascade ) {
  14451. for ( n = 0; n < light.shadowCascadeCount; n ++ ) {
  14452. var virtualLight;
  14453. if ( ! light.shadowCascadeArray[ n ] ) {
  14454. virtualLight = createVirtualLight( light, n );
  14455. virtualLight.originalCamera = camera;
  14456. var gyro = new THREE.Gyroscope();
  14457. gyro.position.copy( light.shadowCascadeOffset );
  14458. gyro.add( virtualLight );
  14459. gyro.add( virtualLight.target );
  14460. camera.add( gyro );
  14461. light.shadowCascadeArray[ n ] = virtualLight;
  14462. //console.log( "Created virtualLight", virtualLight );
  14463. } else {
  14464. virtualLight = light.shadowCascadeArray[ n ];
  14465. }
  14466. updateVirtualLight( light, n );
  14467. lights[ k ] = virtualLight;
  14468. k ++;
  14469. }
  14470. } else {
  14471. lights[ k ] = light;
  14472. k ++;
  14473. }
  14474. }
  14475. // render depth map
  14476. for ( i = 0, il = lights.length; i < il; i ++ ) {
  14477. light = lights[ i ];
  14478. if ( ! light.shadowMap ) {
  14479. var shadowFilter = THREE.LinearFilter;
  14480. if ( scope.type === THREE.PCFSoftShadowMap ) {
  14481. shadowFilter = THREE.NearestFilter;
  14482. }
  14483. var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
  14484. light.shadowMap = new THREE.WebGLRenderTarget( light.shadowMapWidth, light.shadowMapHeight, pars );
  14485. light.shadowMapSize = new THREE.Vector2( light.shadowMapWidth, light.shadowMapHeight );
  14486. light.shadowMatrix = new THREE.Matrix4();
  14487. }
  14488. if ( ! light.shadowCamera ) {
  14489. if ( light instanceof THREE.SpotLight ) {
  14490. light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, light.shadowMapWidth / light.shadowMapHeight, light.shadowCameraNear, light.shadowCameraFar );
  14491. } else if ( light instanceof THREE.DirectionalLight ) {
  14492. light.shadowCamera = new THREE.OrthographicCamera( light.shadowCameraLeft, light.shadowCameraRight, light.shadowCameraTop, light.shadowCameraBottom, light.shadowCameraNear, light.shadowCameraFar );
  14493. } else {
  14494. console.error( "THREE.ShadowMapPlugin: Unsupported light type for shadow", light );
  14495. continue;
  14496. }
  14497. scene.add( light.shadowCamera );
  14498. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14499. }
  14500. if ( light.shadowCameraVisible && ! light.cameraHelper ) {
  14501. light.cameraHelper = new THREE.CameraHelper( light.shadowCamera );
  14502. scene.add( light.cameraHelper );
  14503. }
  14504. if ( light.isVirtual && virtualLight.originalCamera == camera ) {
  14505. updateShadowCamera( camera, light );
  14506. }
  14507. shadowMap = light.shadowMap;
  14508. shadowMatrix = light.shadowMatrix;
  14509. shadowCamera = light.shadowCamera;
  14510. //
  14511. shadowCamera.position.setFromMatrixPosition( light.matrixWorld );
  14512. _matrixPosition.setFromMatrixPosition( light.target.matrixWorld );
  14513. shadowCamera.lookAt( _matrixPosition );
  14514. shadowCamera.updateMatrixWorld();
  14515. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  14516. //
  14517. if ( light.cameraHelper ) light.cameraHelper.visible = light.shadowCameraVisible;
  14518. if ( light.shadowCameraVisible ) light.cameraHelper.update();
  14519. // compute shadow matrix
  14520. shadowMatrix.set(
  14521. 0.5, 0.0, 0.0, 0.5,
  14522. 0.0, 0.5, 0.0, 0.5,
  14523. 0.0, 0.0, 0.5, 0.5,
  14524. 0.0, 0.0, 0.0, 1.0
  14525. );
  14526. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  14527. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  14528. // update camera matrices and frustum
  14529. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  14530. _frustum.setFromMatrix( _projScreenMatrix );
  14531. // render shadow map
  14532. _renderer.setRenderTarget( shadowMap );
  14533. _renderer.clear();
  14534. // set object matrices & frustum culling
  14535. _renderList.length = 0;
  14536. projectObject( scene, shadowCamera );
  14537. // render regular objects
  14538. var objectMaterial, useMorphing, useSkinning;
  14539. for ( j = 0, jl = _renderList.length; j < jl; j ++ ) {
  14540. webglObject = _renderList[ j ];
  14541. object = webglObject.object;
  14542. // culling is overridden globally for all objects
  14543. // while rendering depth map
  14544. // need to deal with MeshFaceMaterial somehow
  14545. // in that case just use the first of material.materials for now
  14546. // (proper solution would require to break objects by materials
  14547. // similarly to regular rendering and then set corresponding
  14548. // depth materials per each chunk instead of just once per object)
  14549. objectMaterial = getObjectMaterial( object );
  14550. useMorphing = object.geometry.morphTargets !== undefined && object.geometry.morphTargets.length > 0 && objectMaterial.morphTargets;
  14551. useSkinning = object instanceof THREE.SkinnedMesh && objectMaterial.skinning;
  14552. if ( object.customDepthMaterial ) {
  14553. material = object.customDepthMaterial;
  14554. } else if ( useSkinning ) {
  14555. material = useMorphing ? _depthMaterialMorphSkin : _depthMaterialSkin;
  14556. } else if ( useMorphing ) {
  14557. material = _depthMaterialMorph;
  14558. } else {
  14559. material = _depthMaterial;
  14560. }
  14561. _renderer.setMaterialFaces( objectMaterial );
  14562. _renderer.renderBufferDirect( shadowCamera, _lights, fog, material, object );
  14563. }
  14564. // set matrices and render immediate objects
  14565. for ( j = 0, jl = _webglObjectsImmediate.length; j < jl; j ++ ) {
  14566. webglObject = _webglObjectsImmediate[ j ];
  14567. object = webglObject.object;
  14568. if ( object.visible && object.castShadow ) {
  14569. object._modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  14570. _renderer.renderImmediateObject( shadowCamera, _lights, fog, _depthMaterial, object );
  14571. }
  14572. }
  14573. }
  14574. // restore GL state
  14575. var clearColor = _renderer.getClearColor(),
  14576. clearAlpha = _renderer.getClearAlpha();
  14577. _gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearAlpha );
  14578. _state.setBlend( true );
  14579. if ( scope.cullFace === THREE.CullFaceFront ) {
  14580. _gl.cullFace( _gl.BACK );
  14581. }
  14582. _renderer.resetGLState();
  14583. };
  14584. function projectObject( object, shadowCamera ) {
  14585. if ( object.visible === true ) {
  14586. var webglObject = _objects.objects[ object.id ];
  14587. if ( webglObject && object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  14588. object._modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  14589. _renderList.push( webglObject );
  14590. }
  14591. for ( var i = 0, l = object.children.length; i < l; i ++ ) {
  14592. projectObject( object.children[ i ], shadowCamera );
  14593. }
  14594. }
  14595. }
  14596. function createVirtualLight( light, cascade ) {
  14597. var virtualLight = new THREE.DirectionalLight();
  14598. virtualLight.isVirtual = true;
  14599. virtualLight.onlyShadow = true;
  14600. virtualLight.castShadow = true;
  14601. virtualLight.shadowCameraNear = light.shadowCameraNear;
  14602. virtualLight.shadowCameraFar = light.shadowCameraFar;
  14603. virtualLight.shadowCameraLeft = light.shadowCameraLeft;
  14604. virtualLight.shadowCameraRight = light.shadowCameraRight;
  14605. virtualLight.shadowCameraBottom = light.shadowCameraBottom;
  14606. virtualLight.shadowCameraTop = light.shadowCameraTop;
  14607. virtualLight.shadowCameraVisible = light.shadowCameraVisible;
  14608. virtualLight.shadowDarkness = light.shadowDarkness;
  14609. virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
  14610. virtualLight.shadowMapWidth = light.shadowCascadeWidth[ cascade ];
  14611. virtualLight.shadowMapHeight = light.shadowCascadeHeight[ cascade ];
  14612. virtualLight.pointsWorld = [];
  14613. virtualLight.pointsFrustum = [];
  14614. var pointsWorld = virtualLight.pointsWorld,
  14615. pointsFrustum = virtualLight.pointsFrustum;
  14616. for ( var i = 0; i < 8; i ++ ) {
  14617. pointsWorld[ i ] = new THREE.Vector3();
  14618. pointsFrustum[ i ] = new THREE.Vector3();
  14619. }
  14620. var nearZ = light.shadowCascadeNearZ[ cascade ];
  14621. var farZ = light.shadowCascadeFarZ[ cascade ];
  14622. pointsFrustum[ 0 ].set( - 1, - 1, nearZ );
  14623. pointsFrustum[ 1 ].set( 1, - 1, nearZ );
  14624. pointsFrustum[ 2 ].set( - 1, 1, nearZ );
  14625. pointsFrustum[ 3 ].set( 1, 1, nearZ );
  14626. pointsFrustum[ 4 ].set( - 1, - 1, farZ );
  14627. pointsFrustum[ 5 ].set( 1, - 1, farZ );
  14628. pointsFrustum[ 6 ].set( - 1, 1, farZ );
  14629. pointsFrustum[ 7 ].set( 1, 1, farZ );
  14630. return virtualLight;
  14631. }
  14632. // Synchronize virtual light with the original light
  14633. function updateVirtualLight( light, cascade ) {
  14634. var virtualLight = light.shadowCascadeArray[ cascade ];
  14635. virtualLight.position.copy( light.position );
  14636. virtualLight.target.position.copy( light.target.position );
  14637. virtualLight.lookAt( virtualLight.target );
  14638. virtualLight.shadowCameraVisible = light.shadowCameraVisible;
  14639. virtualLight.shadowDarkness = light.shadowDarkness;
  14640. virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
  14641. var nearZ = light.shadowCascadeNearZ[ cascade ];
  14642. var farZ = light.shadowCascadeFarZ[ cascade ];
  14643. var pointsFrustum = virtualLight.pointsFrustum;
  14644. pointsFrustum[ 0 ].z = nearZ;
  14645. pointsFrustum[ 1 ].z = nearZ;
  14646. pointsFrustum[ 2 ].z = nearZ;
  14647. pointsFrustum[ 3 ].z = nearZ;
  14648. pointsFrustum[ 4 ].z = farZ;
  14649. pointsFrustum[ 5 ].z = farZ;
  14650. pointsFrustum[ 6 ].z = farZ;
  14651. pointsFrustum[ 7 ].z = farZ;
  14652. }
  14653. // Fit shadow camera's ortho frustum to camera frustum
  14654. function updateShadowCamera( camera, light ) {
  14655. var shadowCamera = light.shadowCamera,
  14656. pointsFrustum = light.pointsFrustum,
  14657. pointsWorld = light.pointsWorld;
  14658. _min.set( Infinity, Infinity, Infinity );
  14659. _max.set( - Infinity, - Infinity, - Infinity );
  14660. for ( var i = 0; i < 8; i ++ ) {
  14661. var p = pointsWorld[ i ];
  14662. p.copy( pointsFrustum[ i ] );
  14663. p.unproject( camera );
  14664. p.applyMatrix4( shadowCamera.matrixWorldInverse );
  14665. if ( p.x < _min.x ) _min.x = p.x;
  14666. if ( p.x > _max.x ) _max.x = p.x;
  14667. if ( p.y < _min.y ) _min.y = p.y;
  14668. if ( p.y > _max.y ) _max.y = p.y;
  14669. if ( p.z < _min.z ) _min.z = p.z;
  14670. if ( p.z > _max.z ) _max.z = p.z;
  14671. }
  14672. shadowCamera.left = _min.x;
  14673. shadowCamera.right = _max.x;
  14674. shadowCamera.top = _max.y;
  14675. shadowCamera.bottom = _min.y;
  14676. // can't really fit near/far
  14677. //shadowCamera.near = _min.z;
  14678. //shadowCamera.far = _max.z;
  14679. shadowCamera.updateProjectionMatrix();
  14680. }
  14681. // For the moment just ignore objects that have multiple materials with different animation methods
  14682. // Only the first material will be taken into account for deciding which depth material to use for shadow maps
  14683. function getObjectMaterial( object ) {
  14684. return object.material instanceof THREE.MeshFaceMaterial
  14685. ? object.material.materials[ 0 ]
  14686. : object.material;
  14687. }
  14688. };
  14689. // File:src/renderers/webgl/WebGLState.js
  14690. /**
  14691. * @author mrdoob / http://mrdoob.com/
  14692. */
  14693. THREE.WebGLState = function ( gl, paramThreeToGL ) {
  14694. var _this = this;
  14695. var newAttributes = new Uint8Array( 16 );
  14696. var enabledAttributes = new Uint8Array( 16 );
  14697. var currentBlend = null;
  14698. var currentBlending = null;
  14699. var currentBlendEquation = null;
  14700. var currentBlendSrc = null;
  14701. var currentBlendDst = null;
  14702. var currentBlendEquationAlpha = null;
  14703. var currentBlendSrcAlpha = null;
  14704. var currentBlendDstAlpha = null;
  14705. var currentDepthFunc = null;
  14706. var currentDepthTest = null;
  14707. var currentDepthWrite = null;
  14708. var currentColorWrite = null;
  14709. var currentDoubleSided = null;
  14710. var currentFlipSided = null;
  14711. var currentLineWidth = null;
  14712. var currentPolygonOffset = null;
  14713. var currentPolygonOffsetFactor = null;
  14714. var currentPolygonOffsetUnits = null;
  14715. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  14716. var currentTextureSlot = undefined;
  14717. var currentBoundTextures = {};
  14718. this.init = function () {
  14719. gl.clearColor( 0, 0, 0, 1 );
  14720. gl.clearDepth( 1 );
  14721. gl.clearStencil( 0 );
  14722. gl.enable( gl.DEPTH_TEST );
  14723. gl.depthFunc( gl.LEQUAL );
  14724. gl.frontFace( gl.CCW );
  14725. gl.cullFace( gl.BACK );
  14726. gl.enable( gl.CULL_FACE );
  14727. gl.enable( gl.BLEND );
  14728. gl.blendEquation( gl.FUNC_ADD );
  14729. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  14730. };
  14731. this.initAttributes = function () {
  14732. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  14733. newAttributes[ i ] = 0;
  14734. }
  14735. };
  14736. this.enableAttribute = function ( attribute ) {
  14737. newAttributes[ attribute ] = 1;
  14738. if ( enabledAttributes[ attribute ] === 0 ) {
  14739. gl.enableVertexAttribArray( attribute );
  14740. enabledAttributes[ attribute ] = 1;
  14741. }
  14742. };
  14743. this.disableUnusedAttributes = function () {
  14744. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  14745. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  14746. gl.disableVertexAttribArray( i );
  14747. enabledAttributes[ i ] = 0;
  14748. }
  14749. }
  14750. };
  14751. this.setBlend = function ( blend ) {
  14752. if ( blend !== currentBlend ) {
  14753. if ( blend ) {
  14754. gl.enable( gl.BLEND );
  14755. } else {
  14756. gl.disable( gl.BLEND );
  14757. }
  14758. currentBlend = blend;
  14759. }
  14760. };
  14761. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  14762. if ( blending !== currentBlending ) {
  14763. if ( blending === THREE.NoBlending ) {
  14764. this.setBlend( false );
  14765. } else if ( blending === THREE.AdditiveBlending ) {
  14766. this.setBlend( true );
  14767. gl.blendEquation( gl.FUNC_ADD );
  14768. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  14769. } else if ( blending === THREE.SubtractiveBlending ) {
  14770. // TODO: Find blendFuncSeparate() combination
  14771. this.setBlend( true );
  14772. gl.blendEquation( gl.FUNC_ADD );
  14773. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  14774. } else if ( blending === THREE.MultiplyBlending ) {
  14775. // TODO: Find blendFuncSeparate() combination
  14776. this.setBlend( true );
  14777. gl.blendEquation( gl.FUNC_ADD );
  14778. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  14779. } else if ( blending === THREE.CustomBlending ) {
  14780. this.setBlend( true );
  14781. } else {
  14782. this.setBlend( true );
  14783. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  14784. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  14785. }
  14786. currentBlending = blending;
  14787. }
  14788. if ( blending === THREE.CustomBlending ) {
  14789. blendEquationAlpha = blendEquationAlpha || blendEquation;
  14790. blendSrcAlpha = blendSrcAlpha || blendSrc;
  14791. blendDstAlpha = blendDstAlpha || blendDst;
  14792. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  14793. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  14794. currentBlendEquation = blendEquation;
  14795. currentBlendEquationAlpha = blendEquationAlpha;
  14796. }
  14797. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  14798. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  14799. currentBlendSrc = blendSrc;
  14800. currentBlendDst = blendDst;
  14801. currentBlendSrcAlpha = blendSrcAlpha;
  14802. currentBlendDstAlpha = blendDstAlpha;
  14803. }
  14804. } else {
  14805. currentBlendEquation = null;
  14806. currentBlendSrc = null;
  14807. currentBlendDst = null;
  14808. currentBlendEquationAlpha = null;
  14809. currentBlendSrcAlpha = null;
  14810. currentBlendDstAlpha = null;
  14811. }
  14812. };
  14813. this.setDepthFunc = function ( depthFunc ) {
  14814. if ( currentDepthFunc !== depthFunc ) {
  14815. if ( depthFunc ) {
  14816. switch ( depthFunc ) {
  14817. case THREE.NeverDepth:
  14818. gl.depthFunc( gl.NEVER );
  14819. break;
  14820. case THREE.AlwaysDepth:
  14821. gl.depthFunc( gl.ALWAYS );
  14822. break;
  14823. case THREE.LessDepth:
  14824. gl.depthFunc( gl.LESS );
  14825. break;
  14826. case THREE.LessEqualDepth:
  14827. gl.depthFunc( gl.LEQUAL );
  14828. break;
  14829. case THREE.EqualDepth:
  14830. gl.depthFunc( gl.EQUAL );
  14831. break;
  14832. case THREE.GreaterEqualDepth:
  14833. gl.depthFunc( gl.GEQUAL );
  14834. break;
  14835. case THREE.GreaterDepth:
  14836. gl.depthFunc( gl.GREATER );
  14837. break;
  14838. case THREE.NotEqualDepth:
  14839. gl.depthFunc( gl.NOTEQUAL );
  14840. break;
  14841. default:
  14842. gl.depthFunc( gl.LEQUAL );
  14843. }
  14844. } else {
  14845. gl.depthFunc( gl.LEQUAL );
  14846. }
  14847. currentDepthFunc = depthFunc;
  14848. }
  14849. };
  14850. this.setDepthTest = function ( depthTest ) {
  14851. if ( currentDepthTest !== depthTest ) {
  14852. if ( depthTest ) {
  14853. gl.enable( gl.DEPTH_TEST );
  14854. } else {
  14855. gl.disable( gl.DEPTH_TEST );
  14856. }
  14857. currentDepthTest = depthTest;
  14858. }
  14859. };
  14860. this.setDepthWrite = function ( depthWrite ) {
  14861. if ( currentDepthWrite !== depthWrite ) {
  14862. gl.depthMask( depthWrite );
  14863. currentDepthWrite = depthWrite;
  14864. }
  14865. };
  14866. this.setColorWrite = function ( colorWrite ) {
  14867. if ( currentColorWrite !== colorWrite ) {
  14868. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  14869. currentColorWrite = colorWrite;
  14870. }
  14871. };
  14872. this.setDoubleSided = function ( doubleSided ) {
  14873. if ( currentDoubleSided !== doubleSided ) {
  14874. if ( doubleSided ) {
  14875. gl.disable( gl.CULL_FACE );
  14876. } else {
  14877. gl.enable( gl.CULL_FACE );
  14878. }
  14879. currentDoubleSided = doubleSided;
  14880. }
  14881. };
  14882. this.setFlipSided = function ( flipSided ) {
  14883. if ( currentFlipSided !== flipSided ) {
  14884. if ( flipSided ) {
  14885. gl.frontFace( gl.CW );
  14886. } else {
  14887. gl.frontFace( gl.CCW );
  14888. }
  14889. currentFlipSided = flipSided;
  14890. }
  14891. };
  14892. this.setLineWidth = function ( width ) {
  14893. if ( width !== currentLineWidth ) {
  14894. gl.lineWidth( width );
  14895. currentLineWidth = width;
  14896. }
  14897. };
  14898. this.setPolygonOffset = function ( polygonoffset, factor, units ) {
  14899. if ( currentPolygonOffset !== polygonoffset ) {
  14900. if ( polygonoffset ) {
  14901. gl.enable( gl.POLYGON_OFFSET_FILL );
  14902. } else {
  14903. gl.disable( gl.POLYGON_OFFSET_FILL );
  14904. }
  14905. currentPolygonOffset = polygonoffset;
  14906. }
  14907. if ( polygonoffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  14908. gl.polygonOffset( factor, units );
  14909. currentPolygonOffsetFactor = factor;
  14910. currentPolygonOffsetUnits = units;
  14911. }
  14912. };
  14913. // texture
  14914. this.activeTexture = function ( webglSlot ) {
  14915. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  14916. if ( currentTextureSlot !== webglSlot ) {
  14917. gl.activeTexture( webglSlot );
  14918. currentTextureSlot = webglSlot;
  14919. }
  14920. }
  14921. this.bindTexture = function ( webglType, webglTexture ) {
  14922. if ( currentTextureSlot === undefined ) {
  14923. _this.activeTexture();
  14924. }
  14925. var boundTexture = currentBoundTextures[currentTextureSlot];
  14926. if ( boundTexture === undefined ) {
  14927. boundTexture = { type: undefined, texture: undefined };
  14928. currentBoundTextures[currentTextureSlot] = boundTexture;
  14929. }
  14930. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  14931. gl.bindTexture( webglType, webglTexture );
  14932. boundTexture.type = webglType;
  14933. boundTexture.texture = webglTexture;
  14934. }
  14935. };
  14936. this.compressedTexImage2D = function () {
  14937. try {
  14938. gl.compressedTexImage2D.apply( gl, arguments );
  14939. } catch ( error ) {
  14940. console.error( error );
  14941. }
  14942. };
  14943. this.texImage2D = function () {
  14944. try {
  14945. gl.texImage2D.apply( gl, arguments );
  14946. } catch ( error ) {
  14947. console.error( error );
  14948. }
  14949. };
  14950. //
  14951. this.reset = function () {
  14952. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  14953. if ( enabledAttributes[ i ] === 1 ) {
  14954. gl.disableVertexAttribArray( i );
  14955. enabledAttributes[ i ] = 0;
  14956. }
  14957. }
  14958. currentBlending = null;
  14959. currentDepthTest = null;
  14960. currentDepthWrite = null;
  14961. currentColorWrite = null;
  14962. currentDoubleSided = null;
  14963. currentFlipSided = null;
  14964. };
  14965. };
  14966. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  14967. /**
  14968. * @author mikael emtinger / http://gomo.se/
  14969. * @author alteredq / http://alteredqualia.com/
  14970. */
  14971. THREE.LensFlarePlugin = function ( renderer, flares ) {
  14972. var gl = renderer.context;
  14973. var state = renderer.state;
  14974. var vertexBuffer, elementBuffer;
  14975. var program, attributes, uniforms;
  14976. var hasVertexTexture;
  14977. var tempTexture, occlusionTexture;
  14978. var init = function () {
  14979. var vertices = new Float32Array( [
  14980. -1, -1, 0, 0,
  14981. 1, -1, 1, 0,
  14982. 1, 1, 1, 1,
  14983. -1, 1, 0, 1
  14984. ] );
  14985. var faces = new Uint16Array( [
  14986. 0, 1, 2,
  14987. 0, 2, 3
  14988. ] );
  14989. // buffers
  14990. vertexBuffer = gl.createBuffer();
  14991. elementBuffer = gl.createBuffer();
  14992. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  14993. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  14994. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  14995. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  14996. // textures
  14997. tempTexture = gl.createTexture();
  14998. occlusionTexture = gl.createTexture();
  14999. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15000. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  15001. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  15002. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  15003. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  15004. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  15005. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  15006. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  15007. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  15008. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  15009. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  15010. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  15011. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  15012. var shader;
  15013. if ( hasVertexTexture ) {
  15014. shader = {
  15015. vertexShader: [
  15016. "uniform lowp int renderType;",
  15017. "uniform vec3 screenPosition;",
  15018. "uniform vec2 scale;",
  15019. "uniform float rotation;",
  15020. "uniform sampler2D occlusionMap;",
  15021. "attribute vec2 position;",
  15022. "attribute vec2 uv;",
  15023. "varying vec2 vUV;",
  15024. "varying float vVisibility;",
  15025. "void main() {",
  15026. "vUV = uv;",
  15027. "vec2 pos = position;",
  15028. "if( renderType == 2 ) {",
  15029. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  15030. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  15031. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  15032. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  15033. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  15034. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  15035. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  15036. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  15037. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  15038. "vVisibility = visibility.r / 9.0;",
  15039. "vVisibility *= 1.0 - visibility.g / 9.0;",
  15040. "vVisibility *= visibility.b / 9.0;",
  15041. "vVisibility *= 1.0 - visibility.a / 9.0;",
  15042. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  15043. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  15044. "}",
  15045. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  15046. "}"
  15047. ].join( "\n" ),
  15048. fragmentShader: [
  15049. "uniform lowp int renderType;",
  15050. "uniform sampler2D map;",
  15051. "uniform float opacity;",
  15052. "uniform vec3 color;",
  15053. "varying vec2 vUV;",
  15054. "varying float vVisibility;",
  15055. "void main() {",
  15056. // pink square
  15057. "if( renderType == 0 ) {",
  15058. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  15059. // restore
  15060. "} else if( renderType == 1 ) {",
  15061. "gl_FragColor = texture2D( map, vUV );",
  15062. // flare
  15063. "} else {",
  15064. "vec4 texture = texture2D( map, vUV );",
  15065. "texture.a *= opacity * vVisibility;",
  15066. "gl_FragColor = texture;",
  15067. "gl_FragColor.rgb *= color;",
  15068. "}",
  15069. "}"
  15070. ].join( "\n" )
  15071. };
  15072. } else {
  15073. shader = {
  15074. vertexShader: [
  15075. "uniform lowp int renderType;",
  15076. "uniform vec3 screenPosition;",
  15077. "uniform vec2 scale;",
  15078. "uniform float rotation;",
  15079. "attribute vec2 position;",
  15080. "attribute vec2 uv;",
  15081. "varying vec2 vUV;",
  15082. "void main() {",
  15083. "vUV = uv;",
  15084. "vec2 pos = position;",
  15085. "if( renderType == 2 ) {",
  15086. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  15087. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  15088. "}",
  15089. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  15090. "}"
  15091. ].join( "\n" ),
  15092. fragmentShader: [
  15093. "precision mediump float;",
  15094. "uniform lowp int renderType;",
  15095. "uniform sampler2D map;",
  15096. "uniform sampler2D occlusionMap;",
  15097. "uniform float opacity;",
  15098. "uniform vec3 color;",
  15099. "varying vec2 vUV;",
  15100. "void main() {",
  15101. // pink square
  15102. "if( renderType == 0 ) {",
  15103. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  15104. // restore
  15105. "} else if( renderType == 1 ) {",
  15106. "gl_FragColor = texture2D( map, vUV );",
  15107. // flare
  15108. "} else {",
  15109. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  15110. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  15111. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  15112. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  15113. "visibility = ( 1.0 - visibility / 4.0 );",
  15114. "vec4 texture = texture2D( map, vUV );",
  15115. "texture.a *= opacity * visibility;",
  15116. "gl_FragColor = texture;",
  15117. "gl_FragColor.rgb *= color;",
  15118. "}",
  15119. "}"
  15120. ].join( "\n" )
  15121. };
  15122. }
  15123. program = createProgram( shader );
  15124. attributes = {
  15125. vertex: gl.getAttribLocation ( program, "position" ),
  15126. uv: gl.getAttribLocation ( program, "uv" )
  15127. };
  15128. uniforms = {
  15129. renderType: gl.getUniformLocation( program, "renderType" ),
  15130. map: gl.getUniformLocation( program, "map" ),
  15131. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  15132. opacity: gl.getUniformLocation( program, "opacity" ),
  15133. color: gl.getUniformLocation( program, "color" ),
  15134. scale: gl.getUniformLocation( program, "scale" ),
  15135. rotation: gl.getUniformLocation( program, "rotation" ),
  15136. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  15137. };
  15138. };
  15139. /*
  15140. * Render lens flares
  15141. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  15142. * reads these back and calculates occlusion.
  15143. */
  15144. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  15145. if ( flares.length === 0 ) return;
  15146. var tempPosition = new THREE.Vector3();
  15147. var invAspect = viewportHeight / viewportWidth,
  15148. halfViewportWidth = viewportWidth * 0.5,
  15149. halfViewportHeight = viewportHeight * 0.5;
  15150. var size = 16 / viewportHeight,
  15151. scale = new THREE.Vector2( size * invAspect, size );
  15152. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  15153. screenPositionPixels = new THREE.Vector2( 1, 1 );
  15154. if ( program === undefined ) {
  15155. init();
  15156. }
  15157. gl.useProgram( program );
  15158. state.initAttributes();
  15159. state.enableAttribute( attributes.vertex );
  15160. state.enableAttribute( attributes.uv );
  15161. state.disableUnusedAttributes();
  15162. // loop through all lens flares to update their occlusion and positions
  15163. // setup gl and common used attribs/uniforms
  15164. gl.uniform1i( uniforms.occlusionMap, 0 );
  15165. gl.uniform1i( uniforms.map, 1 );
  15166. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15167. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  15168. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  15169. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15170. gl.disable( gl.CULL_FACE );
  15171. gl.depthMask( false );
  15172. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  15173. size = 16 / viewportHeight;
  15174. scale.set( size * invAspect, size );
  15175. // calc object screen position
  15176. var flare = flares[ i ];
  15177. tempPosition.set( flare.matrixWorld.elements[12], flare.matrixWorld.elements[13], flare.matrixWorld.elements[14] );
  15178. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  15179. tempPosition.applyProjection( camera.projectionMatrix );
  15180. // setup arrays for gl programs
  15181. screenPosition.copy( tempPosition );
  15182. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  15183. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  15184. // screen cull
  15185. if ( hasVertexTexture || (
  15186. screenPositionPixels.x > 0 &&
  15187. screenPositionPixels.x < viewportWidth &&
  15188. screenPositionPixels.y > 0 &&
  15189. screenPositionPixels.y < viewportHeight ) ) {
  15190. // save current RGB to temp texture
  15191. state.activeTexture( gl.TEXTURE0 );
  15192. state.bindTexture( gl.TEXTURE_2D, null );
  15193. state.activeTexture( gl.TEXTURE1 );
  15194. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15195. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  15196. // render pink quad
  15197. gl.uniform1i( uniforms.renderType, 0 );
  15198. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  15199. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  15200. state.setBlend( false );
  15201. gl.enable( gl.DEPTH_TEST );
  15202. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15203. // copy result to occlusionMap
  15204. state.activeTexture( gl.TEXTURE0 );
  15205. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  15206. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  15207. // restore graphics
  15208. gl.uniform1i( uniforms.renderType, 1 );
  15209. gl.disable( gl.DEPTH_TEST );
  15210. state.activeTexture( gl.TEXTURE1 );
  15211. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15212. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15213. // update object positions
  15214. flare.positionScreen.copy( screenPosition );
  15215. if ( flare.customUpdateCallback ) {
  15216. flare.customUpdateCallback( flare );
  15217. } else {
  15218. flare.updateLensFlares();
  15219. }
  15220. // render flares
  15221. gl.uniform1i( uniforms.renderType, 2 );
  15222. state.setBlend( true );
  15223. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  15224. var sprite = flare.lensFlares[ j ];
  15225. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  15226. screenPosition.x = sprite.x;
  15227. screenPosition.y = sprite.y;
  15228. screenPosition.z = sprite.z;
  15229. size = sprite.size * sprite.scale / viewportHeight;
  15230. scale.x = size * invAspect;
  15231. scale.y = size;
  15232. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  15233. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  15234. gl.uniform1f( uniforms.rotation, sprite.rotation );
  15235. gl.uniform1f( uniforms.opacity, sprite.opacity );
  15236. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  15237. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  15238. renderer.setTexture( sprite.texture, 1 );
  15239. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15240. }
  15241. }
  15242. }
  15243. }
  15244. // restore gl
  15245. gl.enable( gl.CULL_FACE );
  15246. gl.enable( gl.DEPTH_TEST );
  15247. gl.depthMask( true );
  15248. renderer.resetGLState();
  15249. };
  15250. function createProgram ( shader ) {
  15251. var program = gl.createProgram();
  15252. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  15253. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  15254. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  15255. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  15256. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  15257. gl.compileShader( fragmentShader );
  15258. gl.compileShader( vertexShader );
  15259. gl.attachShader( program, fragmentShader );
  15260. gl.attachShader( program, vertexShader );
  15261. gl.linkProgram( program );
  15262. return program;
  15263. }
  15264. };
  15265. // File:src/renderers/webgl/plugins/SpritePlugin.js
  15266. /**
  15267. * @author mikael emtinger / http://gomo.se/
  15268. * @author alteredq / http://alteredqualia.com/
  15269. */
  15270. THREE.SpritePlugin = function ( renderer, sprites ) {
  15271. var gl = renderer.context;
  15272. var state = renderer.state;
  15273. var vertexBuffer, elementBuffer;
  15274. var program, attributes, uniforms;
  15275. var texture;
  15276. // decompose matrixWorld
  15277. var spritePosition = new THREE.Vector3();
  15278. var spriteRotation = new THREE.Quaternion();
  15279. var spriteScale = new THREE.Vector3();
  15280. var init = function () {
  15281. var vertices = new Float32Array( [
  15282. - 0.5, - 0.5, 0, 0,
  15283. 0.5, - 0.5, 1, 0,
  15284. 0.5, 0.5, 1, 1,
  15285. - 0.5, 0.5, 0, 1
  15286. ] );
  15287. var faces = new Uint16Array( [
  15288. 0, 1, 2,
  15289. 0, 2, 3
  15290. ] );
  15291. vertexBuffer = gl.createBuffer();
  15292. elementBuffer = gl.createBuffer();
  15293. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15294. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  15295. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15296. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  15297. program = createProgram();
  15298. attributes = {
  15299. position: gl.getAttribLocation ( program, 'position' ),
  15300. uv: gl.getAttribLocation ( program, 'uv' )
  15301. };
  15302. uniforms = {
  15303. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  15304. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  15305. rotation: gl.getUniformLocation( program, 'rotation' ),
  15306. scale: gl.getUniformLocation( program, 'scale' ),
  15307. color: gl.getUniformLocation( program, 'color' ),
  15308. map: gl.getUniformLocation( program, 'map' ),
  15309. opacity: gl.getUniformLocation( program, 'opacity' ),
  15310. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  15311. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  15312. fogType: gl.getUniformLocation( program, 'fogType' ),
  15313. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  15314. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  15315. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  15316. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  15317. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  15318. };
  15319. var canvas = document.createElement( 'canvas' );
  15320. canvas.width = 8;
  15321. canvas.height = 8;
  15322. var context = canvas.getContext( '2d' );
  15323. context.fillStyle = 'white';
  15324. context.fillRect( 0, 0, 8, 8 );
  15325. texture = new THREE.Texture( canvas );
  15326. texture.needsUpdate = true;
  15327. };
  15328. this.render = function ( scene, camera ) {
  15329. if ( sprites.length === 0 ) return;
  15330. // setup gl
  15331. if ( program === undefined ) {
  15332. init();
  15333. }
  15334. gl.useProgram( program );
  15335. state.initAttributes();
  15336. state.enableAttribute( attributes.position );
  15337. state.enableAttribute( attributes.uv );
  15338. state.disableUnusedAttributes();
  15339. gl.disable( gl.CULL_FACE );
  15340. state.setBlend( true );
  15341. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15342. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  15343. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  15344. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15345. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  15346. state.activeTexture( gl.TEXTURE0 );
  15347. gl.uniform1i( uniforms.map, 0 );
  15348. var oldFogType = 0;
  15349. var sceneFogType = 0;
  15350. var fog = scene.fog;
  15351. if ( fog ) {
  15352. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  15353. if ( fog instanceof THREE.Fog ) {
  15354. gl.uniform1f( uniforms.fogNear, fog.near );
  15355. gl.uniform1f( uniforms.fogFar, fog.far );
  15356. gl.uniform1i( uniforms.fogType, 1 );
  15357. oldFogType = 1;
  15358. sceneFogType = 1;
  15359. } else if ( fog instanceof THREE.FogExp2 ) {
  15360. gl.uniform1f( uniforms.fogDensity, fog.density );
  15361. gl.uniform1i( uniforms.fogType, 2 );
  15362. oldFogType = 2;
  15363. sceneFogType = 2;
  15364. }
  15365. } else {
  15366. gl.uniform1i( uniforms.fogType, 0 );
  15367. oldFogType = 0;
  15368. sceneFogType = 0;
  15369. }
  15370. // update positions and sort
  15371. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  15372. var sprite = sprites[ i ];
  15373. sprite._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  15374. sprite.z = - sprite._modelViewMatrix.elements[ 14 ];
  15375. }
  15376. sprites.sort( painterSortStable );
  15377. // render all sprites
  15378. var scale = [];
  15379. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  15380. var sprite = sprites[ i ];
  15381. var material = sprite.material;
  15382. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  15383. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite._modelViewMatrix.elements );
  15384. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  15385. scale[ 0 ] = spriteScale.x;
  15386. scale[ 1 ] = spriteScale.y;
  15387. var fogType = 0;
  15388. if ( scene.fog && material.fog ) {
  15389. fogType = sceneFogType;
  15390. }
  15391. if ( oldFogType !== fogType ) {
  15392. gl.uniform1i( uniforms.fogType, fogType );
  15393. oldFogType = fogType;
  15394. }
  15395. if ( material.map !== null ) {
  15396. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  15397. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  15398. } else {
  15399. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  15400. gl.uniform2f( uniforms.uvScale, 1, 1 );
  15401. }
  15402. gl.uniform1f( uniforms.opacity, material.opacity );
  15403. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  15404. gl.uniform1f( uniforms.rotation, material.rotation );
  15405. gl.uniform2fv( uniforms.scale, scale );
  15406. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  15407. state.setDepthTest( material.depthTest );
  15408. state.setDepthWrite( material.depthWrite );
  15409. if ( material.map && material.map.image && material.map.image.width ) {
  15410. renderer.setTexture( material.map, 0 );
  15411. } else {
  15412. renderer.setTexture( texture, 0 );
  15413. }
  15414. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15415. }
  15416. // restore gl
  15417. gl.enable( gl.CULL_FACE );
  15418. renderer.resetGLState();
  15419. };
  15420. function createProgram () {
  15421. var program = gl.createProgram();
  15422. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  15423. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  15424. gl.shaderSource( vertexShader, [
  15425. 'precision ' + renderer.getPrecision() + ' float;',
  15426. 'uniform mat4 modelViewMatrix;',
  15427. 'uniform mat4 projectionMatrix;',
  15428. 'uniform float rotation;',
  15429. 'uniform vec2 scale;',
  15430. 'uniform vec2 uvOffset;',
  15431. 'uniform vec2 uvScale;',
  15432. 'attribute vec2 position;',
  15433. 'attribute vec2 uv;',
  15434. 'varying vec2 vUV;',
  15435. 'void main() {',
  15436. 'vUV = uvOffset + uv * uvScale;',
  15437. 'vec2 alignedPosition = position * scale;',
  15438. 'vec2 rotatedPosition;',
  15439. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  15440. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  15441. 'vec4 finalPosition;',
  15442. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  15443. 'finalPosition.xy += rotatedPosition;',
  15444. 'finalPosition = projectionMatrix * finalPosition;',
  15445. 'gl_Position = finalPosition;',
  15446. '}'
  15447. ].join( '\n' ) );
  15448. gl.shaderSource( fragmentShader, [
  15449. 'precision ' + renderer.getPrecision() + ' float;',
  15450. 'uniform vec3 color;',
  15451. 'uniform sampler2D map;',
  15452. 'uniform float opacity;',
  15453. 'uniform int fogType;',
  15454. 'uniform vec3 fogColor;',
  15455. 'uniform float fogDensity;',
  15456. 'uniform float fogNear;',
  15457. 'uniform float fogFar;',
  15458. 'uniform float alphaTest;',
  15459. 'varying vec2 vUV;',
  15460. 'void main() {',
  15461. 'vec4 texture = texture2D( map, vUV );',
  15462. 'if ( texture.a < alphaTest ) discard;',
  15463. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  15464. 'if ( fogType > 0 ) {',
  15465. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  15466. 'float fogFactor = 0.0;',
  15467. 'if ( fogType == 1 ) {',
  15468. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  15469. '} else {',
  15470. 'const float LOG2 = 1.442695;',
  15471. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  15472. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  15473. '}',
  15474. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  15475. '}',
  15476. '}'
  15477. ].join( '\n' ) );
  15478. gl.compileShader( vertexShader );
  15479. gl.compileShader( fragmentShader );
  15480. gl.attachShader( program, vertexShader );
  15481. gl.attachShader( program, fragmentShader );
  15482. gl.linkProgram( program );
  15483. return program;
  15484. }
  15485. function painterSortStable ( a, b ) {
  15486. if ( a.z !== b.z ) {
  15487. return b.z - a.z;
  15488. } else {
  15489. return b.id - a.id;
  15490. }
  15491. }
  15492. };
  15493. // File:src/extras/GeometryUtils.js
  15494. /**
  15495. * @author mrdoob / http://mrdoob.com/
  15496. */
  15497. THREE.GeometryUtils = {
  15498. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  15499. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  15500. var matrix;
  15501. if ( geometry2 instanceof THREE.Mesh ) {
  15502. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  15503. matrix = geometry2.matrix;
  15504. geometry2 = geometry2.geometry;
  15505. }
  15506. geometry1.merge( geometry2, matrix, materialIndexOffset );
  15507. },
  15508. center: function ( geometry ) {
  15509. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  15510. return geometry.center();
  15511. }
  15512. };
  15513. // File:src/extras/ImageUtils.js
  15514. /**
  15515. * @author alteredq / http://alteredqualia.com/
  15516. * @author mrdoob / http://mrdoob.com/
  15517. * @author Daosheng Mu / https://github.com/DaoshengMu/
  15518. */
  15519. THREE.ImageUtils = {
  15520. crossOrigin: undefined,
  15521. loadTexture: function ( url, mapping, onLoad, onError ) {
  15522. var loader = new THREE.ImageLoader();
  15523. loader.crossOrigin = this.crossOrigin;
  15524. var texture = new THREE.Texture( undefined, mapping );
  15525. loader.load( url, function ( image ) {
  15526. texture.image = image;
  15527. texture.needsUpdate = true;
  15528. if ( onLoad ) onLoad( texture );
  15529. }, undefined, function ( event ) {
  15530. if ( onError ) onError( event );
  15531. } );
  15532. texture.sourceFile = url;
  15533. return texture;
  15534. },
  15535. loadTextureCube: function ( array, mapping, onLoad, onError ) {
  15536. var images = [];
  15537. var loader = new THREE.ImageLoader();
  15538. loader.crossOrigin = this.crossOrigin;
  15539. var texture = new THREE.CubeTexture( images, mapping );
  15540. // no flipping needed for cube textures
  15541. texture.flipY = false;
  15542. var loaded = 0;
  15543. var loadTexture = function ( i ) {
  15544. loader.load( array[ i ], function ( image ) {
  15545. texture.images[ i ] = image;
  15546. loaded += 1;
  15547. if ( loaded === 6 ) {
  15548. texture.needsUpdate = true;
  15549. if ( onLoad ) onLoad( texture );
  15550. }
  15551. }, undefined, onError );
  15552. };
  15553. for ( var i = 0, il = array.length; i < il; ++ i ) {
  15554. loadTexture( i );
  15555. }
  15556. return texture;
  15557. },
  15558. loadCompressedTexture: function () {
  15559. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
  15560. },
  15561. loadCompressedTextureCube: function () {
  15562. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
  15563. },
  15564. getNormalMap: function ( image, depth ) {
  15565. // Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
  15566. var cross = function ( a, b ) {
  15567. 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 ] ];
  15568. };
  15569. var subtract = function ( a, b ) {
  15570. return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ];
  15571. };
  15572. var normalize = function ( a ) {
  15573. var l = Math.sqrt( a[ 0 ] * a[ 0 ] + a[ 1 ] * a[ 1 ] + a[ 2 ] * a[ 2 ] );
  15574. return [ a[ 0 ] / l, a[ 1 ] / l, a[ 2 ] / l ];
  15575. };
  15576. depth = depth | 1;
  15577. var width = image.width;
  15578. var height = image.height;
  15579. var canvas = document.createElement( 'canvas' );
  15580. canvas.width = width;
  15581. canvas.height = height;
  15582. var context = canvas.getContext( '2d' );
  15583. context.drawImage( image, 0, 0 );
  15584. var data = context.getImageData( 0, 0, width, height ).data;
  15585. var imageData = context.createImageData( width, height );
  15586. var output = imageData.data;
  15587. for ( var x = 0; x < width; x ++ ) {
  15588. for ( var y = 0; y < height; y ++ ) {
  15589. var ly = y - 1 < 0 ? 0 : y - 1;
  15590. var uy = y + 1 > height - 1 ? height - 1 : y + 1;
  15591. var lx = x - 1 < 0 ? 0 : x - 1;
  15592. var ux = x + 1 > width - 1 ? width - 1 : x + 1;
  15593. var points = [];
  15594. var origin = [ 0, 0, data[ ( y * width + x ) * 4 ] / 255 * depth ];
  15595. points.push( [ - 1, 0, data[ ( y * width + lx ) * 4 ] / 255 * depth ] );
  15596. points.push( [ - 1, - 1, data[ ( ly * width + lx ) * 4 ] / 255 * depth ] );
  15597. points.push( [ 0, - 1, data[ ( ly * width + x ) * 4 ] / 255 * depth ] );
  15598. points.push( [ 1, - 1, data[ ( ly * width + ux ) * 4 ] / 255 * depth ] );
  15599. points.push( [ 1, 0, data[ ( y * width + ux ) * 4 ] / 255 * depth ] );
  15600. points.push( [ 1, 1, data[ ( uy * width + ux ) * 4 ] / 255 * depth ] );
  15601. points.push( [ 0, 1, data[ ( uy * width + x ) * 4 ] / 255 * depth ] );
  15602. points.push( [ - 1, 1, data[ ( uy * width + lx ) * 4 ] / 255 * depth ] );
  15603. var normals = [];
  15604. var num_points = points.length;
  15605. for ( var i = 0; i < num_points; i ++ ) {
  15606. var v1 = points[ i ];
  15607. var v2 = points[ ( i + 1 ) % num_points ];
  15608. v1 = subtract( v1, origin );
  15609. v2 = subtract( v2, origin );
  15610. normals.push( normalize( cross( v1, v2 ) ) );
  15611. }
  15612. var normal = [ 0, 0, 0 ];
  15613. for ( var i = 0; i < normals.length; i ++ ) {
  15614. normal[ 0 ] += normals[ i ][ 0 ];
  15615. normal[ 1 ] += normals[ i ][ 1 ];
  15616. normal[ 2 ] += normals[ i ][ 2 ];
  15617. }
  15618. normal[ 0 ] /= normals.length;
  15619. normal[ 1 ] /= normals.length;
  15620. normal[ 2 ] /= normals.length;
  15621. var idx = ( y * width + x ) * 4;
  15622. output[ idx ] = ( ( normal[ 0 ] + 1.0 ) / 2.0 * 255 ) | 0;
  15623. output[ idx + 1 ] = ( ( normal[ 1 ] + 1.0 ) / 2.0 * 255 ) | 0;
  15624. output[ idx + 2 ] = ( normal[ 2 ] * 255 ) | 0;
  15625. output[ idx + 3 ] = 255;
  15626. }
  15627. }
  15628. context.putImageData( imageData, 0, 0 );
  15629. return canvas;
  15630. },
  15631. generateDataTexture: function ( width, height, color ) {
  15632. var size = width * height;
  15633. var data = new Uint8Array( 3 * size );
  15634. var r = Math.floor( color.r * 255 );
  15635. var g = Math.floor( color.g * 255 );
  15636. var b = Math.floor( color.b * 255 );
  15637. for ( var i = 0; i < size; i ++ ) {
  15638. data[ i * 3 ] = r;
  15639. data[ i * 3 + 1 ] = g;
  15640. data[ i * 3 + 2 ] = b;
  15641. }
  15642. var texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
  15643. texture.needsUpdate = true;
  15644. return texture;
  15645. }
  15646. };
  15647. // File:src/extras/SceneUtils.js
  15648. /**
  15649. * @author alteredq / http://alteredqualia.com/
  15650. */
  15651. THREE.SceneUtils = {
  15652. createMultiMaterialObject: function ( geometry, materials ) {
  15653. var group = new THREE.Object3D();
  15654. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  15655. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  15656. }
  15657. return group;
  15658. },
  15659. detach: function ( child, parent, scene ) {
  15660. child.applyMatrix( parent.matrixWorld );
  15661. parent.remove( child );
  15662. scene.add( child );
  15663. },
  15664. attach: function ( child, scene, parent ) {
  15665. var matrixWorldInverse = new THREE.Matrix4();
  15666. matrixWorldInverse.getInverse( parent.matrixWorld );
  15667. child.applyMatrix( matrixWorldInverse );
  15668. scene.remove( child );
  15669. parent.add( child );
  15670. }
  15671. };
  15672. // File:src/extras/FontUtils.js
  15673. /**
  15674. * @author zz85 / http://www.lab4games.net/zz85/blog
  15675. * @author alteredq / http://alteredqualia.com/
  15676. *
  15677. * For Text operations in three.js (See TextGeometry)
  15678. *
  15679. * It uses techniques used in:
  15680. *
  15681. * Triangulation ported from AS3
  15682. * Simple Polygon Triangulation
  15683. * http://actionsnippet.com/?p=1462
  15684. *
  15685. * A Method to triangulate shapes with holes
  15686. * http://www.sakri.net/blog/2009/06/12/an-approach-to-triangulating-polygons-with-holes/
  15687. *
  15688. */
  15689. THREE.FontUtils = {
  15690. faces: {},
  15691. // Just for now. face[weight][style]
  15692. face: 'helvetiker',
  15693. weight: 'normal',
  15694. style: 'normal',
  15695. size: 150,
  15696. divisions: 10,
  15697. getFace: function () {
  15698. try {
  15699. return this.faces[ this.face.toLowerCase() ][ this.weight ][ this.style ];
  15700. } catch (e) {
  15701. throw "The font " + this.face + " with " + this.weight + " weight and " + this.style + " style is missing."
  15702. }
  15703. },
  15704. loadFace: function ( data ) {
  15705. var family = data.familyName.toLowerCase();
  15706. var ThreeFont = this;
  15707. ThreeFont.faces[ family ] = ThreeFont.faces[ family ] || {};
  15708. ThreeFont.faces[ family ][ data.cssFontWeight ] = ThreeFont.faces[ family ][ data.cssFontWeight ] || {};
  15709. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15710. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15711. return data;
  15712. },
  15713. drawText: function ( text ) {
  15714. // RenderText
  15715. var i,
  15716. face = this.getFace(),
  15717. scale = this.size / face.resolution,
  15718. offset = 0,
  15719. chars = String( text ).split( '' ),
  15720. length = chars.length;
  15721. var fontPaths = [];
  15722. for ( i = 0; i < length; i ++ ) {
  15723. var path = new THREE.Path();
  15724. var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
  15725. offset += ret.offset;
  15726. fontPaths.push( ret.path );
  15727. }
  15728. // get the width
  15729. var width = offset / 2;
  15730. //
  15731. // for ( p = 0; p < allPts.length; p++ ) {
  15732. //
  15733. // allPts[ p ].x -= width;
  15734. //
  15735. // }
  15736. //var extract = this.extractPoints( allPts, characterPts );
  15737. //extract.contour = allPts;
  15738. //extract.paths = fontPaths;
  15739. //extract.offset = width;
  15740. return { paths: fontPaths, offset: width };
  15741. },
  15742. extractGlyphPoints: function ( c, face, scale, offset, path ) {
  15743. var pts = [];
  15744. var i, i2, divisions,
  15745. outline, action, length,
  15746. scaleX, scaleY,
  15747. x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2,
  15748. laste,
  15749. glyph = face.glyphs[ c ] || face.glyphs[ '?' ];
  15750. if ( ! glyph ) return;
  15751. if ( glyph.o ) {
  15752. outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  15753. length = outline.length;
  15754. scaleX = scale;
  15755. scaleY = scale;
  15756. for ( i = 0; i < length; ) {
  15757. action = outline[ i ++ ];
  15758. //console.log( action );
  15759. switch ( action ) {
  15760. case 'm':
  15761. // Move To
  15762. x = outline[ i ++ ] * scaleX + offset;
  15763. y = outline[ i ++ ] * scaleY;
  15764. path.moveTo( x, y );
  15765. break;
  15766. case 'l':
  15767. // Line To
  15768. x = outline[ i ++ ] * scaleX + offset;
  15769. y = outline[ i ++ ] * scaleY;
  15770. path.lineTo( x, y );
  15771. break;
  15772. case 'q':
  15773. // QuadraticCurveTo
  15774. cpx = outline[ i ++ ] * scaleX + offset;
  15775. cpy = outline[ i ++ ] * scaleY;
  15776. cpx1 = outline[ i ++ ] * scaleX + offset;
  15777. cpy1 = outline[ i ++ ] * scaleY;
  15778. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  15779. laste = pts[ pts.length - 1 ];
  15780. if ( laste ) {
  15781. cpx0 = laste.x;
  15782. cpy0 = laste.y;
  15783. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  15784. var t = i2 / divisions;
  15785. THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  15786. THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  15787. }
  15788. }
  15789. break;
  15790. case 'b':
  15791. // Cubic Bezier Curve
  15792. cpx = outline[ i ++ ] * scaleX + offset;
  15793. cpy = outline[ i ++ ] * scaleY;
  15794. cpx1 = outline[ i ++ ] * scaleX + offset;
  15795. cpy1 = outline[ i ++ ] * scaleY;
  15796. cpx2 = outline[ i ++ ] * scaleX + offset;
  15797. cpy2 = outline[ i ++ ] * scaleY;
  15798. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  15799. laste = pts[ pts.length - 1 ];
  15800. if ( laste ) {
  15801. cpx0 = laste.x;
  15802. cpy0 = laste.y;
  15803. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  15804. var t = i2 / divisions;
  15805. THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  15806. THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  15807. }
  15808. }
  15809. break;
  15810. }
  15811. }
  15812. }
  15813. return { offset: glyph.ha * scale, path:path };
  15814. }
  15815. };
  15816. THREE.FontUtils.generateShapes = function ( text, parameters ) {
  15817. // Parameters
  15818. parameters = parameters || {};
  15819. var size = parameters.size !== undefined ? parameters.size : 100;
  15820. var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments : 4;
  15821. var font = parameters.font !== undefined ? parameters.font : 'helvetiker';
  15822. var weight = parameters.weight !== undefined ? parameters.weight : 'normal';
  15823. var style = parameters.style !== undefined ? parameters.style : 'normal';
  15824. THREE.FontUtils.size = size;
  15825. THREE.FontUtils.divisions = curveSegments;
  15826. THREE.FontUtils.face = font;
  15827. THREE.FontUtils.weight = weight;
  15828. THREE.FontUtils.style = style;
  15829. // Get a Font data json object
  15830. var data = THREE.FontUtils.drawText( text );
  15831. var paths = data.paths;
  15832. var shapes = [];
  15833. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  15834. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  15835. }
  15836. return shapes;
  15837. };
  15838. /**
  15839. * This code is a quick port of code written in C++ which was submitted to
  15840. * flipcode.com by John W. Ratcliff // July 22, 2000
  15841. * See original code and more information here:
  15842. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  15843. *
  15844. * ported to actionscript by Zevan Rosser
  15845. * www.actionsnippet.com
  15846. *
  15847. * ported to javascript by Joshua Koo
  15848. * http://www.lab4games.net/zz85/blog
  15849. *
  15850. */
  15851. ( function ( namespace ) {
  15852. var EPSILON = 0.0000000001;
  15853. // takes in an contour array and returns
  15854. var process = function ( contour, indices ) {
  15855. var n = contour.length;
  15856. if ( n < 3 ) return null;
  15857. var result = [],
  15858. verts = [],
  15859. vertIndices = [];
  15860. /* we want a counter-clockwise polygon in verts */
  15861. var u, v, w;
  15862. if ( area( contour ) > 0.0 ) {
  15863. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  15864. } else {
  15865. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  15866. }
  15867. var nv = n;
  15868. /* remove nv - 2 vertices, creating 1 triangle every time */
  15869. var count = 2 * nv; /* error detection */
  15870. for ( v = nv - 1; nv > 2; ) {
  15871. /* if we loop, it is probably a non-simple polygon */
  15872. if ( ( count -- ) <= 0 ) {
  15873. //** Triangulate: ERROR - probable bad polygon!
  15874. //throw ( "Warning, unable to triangulate polygon!" );
  15875. //return null;
  15876. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  15877. console.warn( 'THREE.FontUtils: Warning, unable to triangulate polygon! in Triangulate.process()' );
  15878. if ( indices ) return vertIndices;
  15879. return result;
  15880. }
  15881. /* three consecutive vertices in current polygon, <u,v,w> */
  15882. u = v; if ( nv <= u ) u = 0; /* previous */
  15883. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  15884. w = v + 1; if ( nv <= w ) w = 0; /* next */
  15885. if ( snip( contour, u, v, w, nv, verts ) ) {
  15886. var a, b, c, s, t;
  15887. /* true names of the vertices */
  15888. a = verts[ u ];
  15889. b = verts[ v ];
  15890. c = verts[ w ];
  15891. /* output Triangle */
  15892. result.push( [ contour[ a ],
  15893. contour[ b ],
  15894. contour[ c ] ] );
  15895. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  15896. /* remove v from the remaining polygon */
  15897. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  15898. verts[ s ] = verts[ t ];
  15899. }
  15900. nv --;
  15901. /* reset error detection counter */
  15902. count = 2 * nv;
  15903. }
  15904. }
  15905. if ( indices ) return vertIndices;
  15906. return result;
  15907. };
  15908. // calculate area of the contour polygon
  15909. var area = function ( contour ) {
  15910. var n = contour.length;
  15911. var a = 0.0;
  15912. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  15913. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  15914. }
  15915. return a * 0.5;
  15916. };
  15917. var snip = function ( contour, u, v, w, n, verts ) {
  15918. var p;
  15919. var ax, ay, bx, by;
  15920. var cx, cy, px, py;
  15921. ax = contour[ verts[ u ] ].x;
  15922. ay = contour[ verts[ u ] ].y;
  15923. bx = contour[ verts[ v ] ].x;
  15924. by = contour[ verts[ v ] ].y;
  15925. cx = contour[ verts[ w ] ].x;
  15926. cy = contour[ verts[ w ] ].y;
  15927. if ( EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  15928. var aX, aY, bX, bY, cX, cY;
  15929. var apx, apy, bpx, bpy, cpx, cpy;
  15930. var cCROSSap, bCROSScp, aCROSSbp;
  15931. aX = cx - bx; aY = cy - by;
  15932. bX = ax - cx; bY = ay - cy;
  15933. cX = bx - ax; cY = by - ay;
  15934. for ( p = 0; p < n; p ++ ) {
  15935. px = contour[ verts[ p ] ].x;
  15936. py = contour[ verts[ p ] ].y;
  15937. if ( ( ( px === ax ) && ( py === ay ) ) ||
  15938. ( ( px === bx ) && ( py === by ) ) ||
  15939. ( ( px === cx ) && ( py === cy ) ) ) continue;
  15940. apx = px - ax; apy = py - ay;
  15941. bpx = px - bx; bpy = py - by;
  15942. cpx = px - cx; cpy = py - cy;
  15943. // see if p is inside triangle abc
  15944. aCROSSbp = aX * bpy - aY * bpx;
  15945. cCROSSap = cX * apy - cY * apx;
  15946. bCROSScp = bX * cpy - bY * cpx;
  15947. if ( ( aCROSSbp >= - EPSILON ) && ( bCROSScp >= - EPSILON ) && ( cCROSSap >= - EPSILON ) ) return false;
  15948. }
  15949. return true;
  15950. };
  15951. namespace.Triangulate = process;
  15952. namespace.Triangulate.area = area;
  15953. return namespace;
  15954. } )( THREE.FontUtils );
  15955. // To use the typeface.js face files, hook up the API
  15956. THREE.typeface_js = { faces: THREE.FontUtils.faces, loadFace: THREE.FontUtils.loadFace };
  15957. if ( typeof self !== 'undefined' ) self._typeface_js = THREE.typeface_js;
  15958. // File:src/extras/audio/Audio.js
  15959. /**
  15960. * @author mrdoob / http://mrdoob.com/
  15961. */
  15962. THREE.Audio = function ( listener ) {
  15963. THREE.Object3D.call( this );
  15964. this.type = 'Audio';
  15965. this.context = listener.context;
  15966. this.source = this.context.createBufferSource();
  15967. this.source.onended = this.onEnded.bind(this);
  15968. this.gain = this.context.createGain();
  15969. this.gain.connect( this.context.destination );
  15970. this.panner = this.context.createPanner();
  15971. this.panner.connect( this.gain );
  15972. this.autoplay = false;
  15973. this.startTime = 0;
  15974. this.isPlaying = false;
  15975. };
  15976. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  15977. THREE.Audio.prototype.constructor = THREE.Audio;
  15978. THREE.Audio.prototype.load = function ( file ) {
  15979. var scope = this;
  15980. var request = new XMLHttpRequest();
  15981. request.open( 'GET', file, true );
  15982. request.responseType = 'arraybuffer';
  15983. request.onload = function ( e ) {
  15984. scope.context.decodeAudioData( this.response, function ( buffer ) {
  15985. scope.source.buffer = buffer;
  15986. if( scope.autoplay ) scope.play();
  15987. } );
  15988. };
  15989. request.send();
  15990. return this;
  15991. };
  15992. THREE.Audio.prototype.play = function () {
  15993. if ( this.isPlaying === true ) {
  15994. console.warn( 'THREE.Audio: Audio is already playing.' );
  15995. return;
  15996. }
  15997. var source = this.context.createBufferSource();
  15998. source.buffer = this.source.buffer;
  15999. source.loop = this.source.loop;
  16000. source.onended = this.source.onended;
  16001. source.connect( this.panner );
  16002. source.start( 0, this.startTime );
  16003. this.isPlaying = true;
  16004. this.source = source;
  16005. };
  16006. THREE.Audio.prototype.pause = function () {
  16007. this.source.stop();
  16008. this.startTime = this.context.currentTime;
  16009. };
  16010. THREE.Audio.prototype.stop = function () {
  16011. this.source.stop();
  16012. this.startTime = 0;
  16013. };
  16014. THREE.Audio.prototype.onEnded = function() {
  16015. this.isPlaying = false;
  16016. };
  16017. THREE.Audio.prototype.setLoop = function ( value ) {
  16018. this.source.loop = value;
  16019. };
  16020. THREE.Audio.prototype.setRefDistance = function ( value ) {
  16021. this.panner.refDistance = value;
  16022. };
  16023. THREE.Audio.prototype.setRolloffFactor = function ( value ) {
  16024. this.panner.rolloffFactor = value;
  16025. };
  16026. THREE.Audio.prototype.setVolume = function ( value ) {
  16027. this.gain.gain.value = value;
  16028. };
  16029. THREE.Audio.prototype.updateMatrixWorld = ( function () {
  16030. var position = new THREE.Vector3();
  16031. return function ( force ) {
  16032. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  16033. position.setFromMatrixPosition( this.matrixWorld );
  16034. this.panner.setPosition( position.x, position.y, position.z );
  16035. };
  16036. } )();
  16037. // File:src/extras/audio/AudioListener.js
  16038. /**
  16039. * @author mrdoob / http://mrdoob.com/
  16040. */
  16041. THREE.AudioListener = function () {
  16042. THREE.Object3D.call( this );
  16043. this.type = 'AudioListener';
  16044. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  16045. };
  16046. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  16047. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  16048. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  16049. var position = new THREE.Vector3();
  16050. var quaternion = new THREE.Quaternion();
  16051. var scale = new THREE.Vector3();
  16052. var orientation = new THREE.Vector3();
  16053. return function ( force ) {
  16054. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  16055. var listener = this.context.listener;
  16056. var up = this.up;
  16057. this.matrixWorld.decompose( position, quaternion, scale );
  16058. orientation.set( 0, 0, -1 ).applyQuaternion( quaternion );
  16059. listener.setPosition( position.x, position.y, position.z );
  16060. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  16061. };
  16062. } )();
  16063. // File:src/extras/core/Curve.js
  16064. /**
  16065. * @author zz85 / http://www.lab4games.net/zz85/blog
  16066. * Extensible curve object
  16067. *
  16068. * Some common of Curve methods
  16069. * .getPoint(t), getTangent(t)
  16070. * .getPointAt(u), getTagentAt(u)
  16071. * .getPoints(), .getSpacedPoints()
  16072. * .getLength()
  16073. * .updateArcLengths()
  16074. *
  16075. * This following classes subclasses THREE.Curve:
  16076. *
  16077. * -- 2d classes --
  16078. * THREE.LineCurve
  16079. * THREE.QuadraticBezierCurve
  16080. * THREE.CubicBezierCurve
  16081. * THREE.SplineCurve
  16082. * THREE.ArcCurve
  16083. * THREE.EllipseCurve
  16084. *
  16085. * -- 3d classes --
  16086. * THREE.LineCurve3
  16087. * THREE.QuadraticBezierCurve3
  16088. * THREE.CubicBezierCurve3
  16089. * THREE.SplineCurve3
  16090. * THREE.ClosedSplineCurve3
  16091. *
  16092. * A series of curves can be represented as a THREE.CurvePath
  16093. *
  16094. **/
  16095. /**************************************************************
  16096. * Abstract Curve base class
  16097. **************************************************************/
  16098. THREE.Curve = function () {
  16099. };
  16100. // Virtual base class method to overwrite and implement in subclasses
  16101. // - t [0 .. 1]
  16102. THREE.Curve.prototype.getPoint = function ( t ) {
  16103. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  16104. return null;
  16105. };
  16106. // Get point at relative position in curve according to arc length
  16107. // - u [0 .. 1]
  16108. THREE.Curve.prototype.getPointAt = function ( u ) {
  16109. var t = this.getUtoTmapping( u );
  16110. return this.getPoint( t );
  16111. };
  16112. // Get sequence of points using getPoint( t )
  16113. THREE.Curve.prototype.getPoints = function ( divisions ) {
  16114. if ( ! divisions ) divisions = 5;
  16115. var d, pts = [];
  16116. for ( d = 0; d <= divisions; d ++ ) {
  16117. pts.push( this.getPoint( d / divisions ) );
  16118. }
  16119. return pts;
  16120. };
  16121. // Get sequence of points using getPointAt( u )
  16122. THREE.Curve.prototype.getSpacedPoints = function ( divisions ) {
  16123. if ( ! divisions ) divisions = 5;
  16124. var d, pts = [];
  16125. for ( d = 0; d <= divisions; d ++ ) {
  16126. pts.push( this.getPointAt( d / divisions ) );
  16127. }
  16128. return pts;
  16129. };
  16130. // Get total curve arc length
  16131. THREE.Curve.prototype.getLength = function () {
  16132. var lengths = this.getLengths();
  16133. return lengths[ lengths.length - 1 ];
  16134. };
  16135. // Get list of cumulative segment lengths
  16136. THREE.Curve.prototype.getLengths = function ( divisions ) {
  16137. if ( ! divisions ) divisions = (this.__arcLengthDivisions) ? (this.__arcLengthDivisions) : 200;
  16138. if ( this.cacheArcLengths
  16139. && ( this.cacheArcLengths.length === divisions + 1 )
  16140. && ! this.needsUpdate) {
  16141. //console.log( "cached", this.cacheArcLengths );
  16142. return this.cacheArcLengths;
  16143. }
  16144. this.needsUpdate = false;
  16145. var cache = [];
  16146. var current, last = this.getPoint( 0 );
  16147. var p, sum = 0;
  16148. cache.push( 0 );
  16149. for ( p = 1; p <= divisions; p ++ ) {
  16150. current = this.getPoint ( p / divisions );
  16151. sum += current.distanceTo( last );
  16152. cache.push( sum );
  16153. last = current;
  16154. }
  16155. this.cacheArcLengths = cache;
  16156. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  16157. };
  16158. THREE.Curve.prototype.updateArcLengths = function() {
  16159. this.needsUpdate = true;
  16160. this.getLengths();
  16161. };
  16162. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  16163. THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
  16164. var arcLengths = this.getLengths();
  16165. var i = 0, il = arcLengths.length;
  16166. var targetArcLength; // The targeted u distance value to get
  16167. if ( distance ) {
  16168. targetArcLength = distance;
  16169. } else {
  16170. targetArcLength = u * arcLengths[ il - 1 ];
  16171. }
  16172. //var time = Date.now();
  16173. // binary search for the index with largest value smaller than target u distance
  16174. var low = 0, high = il - 1, comparison;
  16175. while ( low <= high ) {
  16176. 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
  16177. comparison = arcLengths[ i ] - targetArcLength;
  16178. if ( comparison < 0 ) {
  16179. low = i + 1;
  16180. } else if ( comparison > 0 ) {
  16181. high = i - 1;
  16182. } else {
  16183. high = i;
  16184. break;
  16185. // DONE
  16186. }
  16187. }
  16188. i = high;
  16189. //console.log('b' , i, low, high, Date.now()- time);
  16190. if ( arcLengths[ i ] === targetArcLength ) {
  16191. var t = i / ( il - 1 );
  16192. return t;
  16193. }
  16194. // we could get finer grain at lengths, or use simple interpolation between two points
  16195. var lengthBefore = arcLengths[ i ];
  16196. var lengthAfter = arcLengths[ i + 1 ];
  16197. var segmentLength = lengthAfter - lengthBefore;
  16198. // determine where we are between the 'before' and 'after' points
  16199. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  16200. // add that fractional amount to t
  16201. var t = ( i + segmentFraction ) / ( il - 1 );
  16202. return t;
  16203. };
  16204. // Returns a unit vector tangent at t
  16205. // In case any sub curve does not implement its tangent derivation,
  16206. // 2 points a small delta apart will be used to find its gradient
  16207. // which seems to give a reasonable approximation
  16208. THREE.Curve.prototype.getTangent = function( t ) {
  16209. var delta = 0.0001;
  16210. var t1 = t - delta;
  16211. var t2 = t + delta;
  16212. // Capping in case of danger
  16213. if ( t1 < 0 ) t1 = 0;
  16214. if ( t2 > 1 ) t2 = 1;
  16215. var pt1 = this.getPoint( t1 );
  16216. var pt2 = this.getPoint( t2 );
  16217. var vec = pt2.clone().sub(pt1);
  16218. return vec.normalize();
  16219. };
  16220. THREE.Curve.prototype.getTangentAt = function ( u ) {
  16221. var t = this.getUtoTmapping( u );
  16222. return this.getTangent( t );
  16223. };
  16224. /**************************************************************
  16225. * Utils
  16226. **************************************************************/
  16227. THREE.Curve.Utils = {
  16228. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  16229. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  16230. },
  16231. // Puay Bing, thanks for helping with this derivative!
  16232. tangentCubicBezier: function (t, p0, p1, p2, p3 ) {
  16233. return - 3 * p0 * (1 - t) * (1 - t) +
  16234. 3 * p1 * (1 - t) * (1 - t) - 6 * t * p1 * (1 - t) +
  16235. 6 * t * p2 * (1 - t) - 3 * t * t * p2 +
  16236. 3 * t * t * p3;
  16237. },
  16238. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  16239. // To check if my formulas are correct
  16240. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  16241. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  16242. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  16243. var h11 = 3 * t * t - 2 * t; // t3 − t2
  16244. return h00 + h10 + h01 + h11;
  16245. },
  16246. // Catmull-Rom
  16247. interpolate: function( p0, p1, p2, p3, t ) {
  16248. var v0 = ( p2 - p0 ) * 0.5;
  16249. var v1 = ( p3 - p1 ) * 0.5;
  16250. var t2 = t * t;
  16251. var t3 = t * t2;
  16252. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  16253. }
  16254. };
  16255. // TODO: Transformation for Curves?
  16256. /**************************************************************
  16257. * 3D Curves
  16258. **************************************************************/
  16259. // A Factory method for creating new curve subclasses
  16260. THREE.Curve.create = function ( constructor, getPointFunc ) {
  16261. constructor.prototype = Object.create( THREE.Curve.prototype );
  16262. constructor.prototype.constructor = constructor;
  16263. constructor.prototype.getPoint = getPointFunc;
  16264. return constructor;
  16265. };
  16266. // File:src/extras/core/CurvePath.js
  16267. /**
  16268. * @author zz85 / http://www.lab4games.net/zz85/blog
  16269. *
  16270. **/
  16271. /**************************************************************
  16272. * Curved Path - a curve path is simply a array of connected
  16273. * curves, but retains the api of a curve
  16274. **************************************************************/
  16275. THREE.CurvePath = function () {
  16276. this.curves = [];
  16277. this.bends = [];
  16278. this.autoClose = false; // Automatically closes the path
  16279. };
  16280. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  16281. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  16282. THREE.CurvePath.prototype.add = function ( curve ) {
  16283. this.curves.push( curve );
  16284. };
  16285. THREE.CurvePath.prototype.checkConnection = function() {
  16286. // TODO
  16287. // If the ending of curve is not connected to the starting
  16288. // or the next curve, then, this is not a real path
  16289. };
  16290. THREE.CurvePath.prototype.closePath = function() {
  16291. // TODO Test
  16292. // and verify for vector3 (needs to implement equals)
  16293. // Add a line curve if start and end of lines are not connected
  16294. var startPoint = this.curves[0].getPoint(0);
  16295. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  16296. if (! startPoint.equals(endPoint)) {
  16297. this.curves.push( new THREE.LineCurve(endPoint, startPoint) );
  16298. }
  16299. };
  16300. // To get accurate point with reference to
  16301. // entire path distance at time t,
  16302. // following has to be done:
  16303. // 1. Length of each sub path have to be known
  16304. // 2. Locate and identify type of curve
  16305. // 3. Get t for the curve
  16306. // 4. Return curve.getPointAt(t')
  16307. THREE.CurvePath.prototype.getPoint = function( t ) {
  16308. var d = t * this.getLength();
  16309. var curveLengths = this.getCurveLengths();
  16310. var i = 0, diff, curve;
  16311. // To think about boundaries points.
  16312. while ( i < curveLengths.length ) {
  16313. if ( curveLengths[ i ] >= d ) {
  16314. diff = curveLengths[ i ] - d;
  16315. curve = this.curves[ i ];
  16316. var u = 1 - diff / curve.getLength();
  16317. return curve.getPointAt( u );
  16318. }
  16319. i ++;
  16320. }
  16321. return null;
  16322. // loop where sum != 0, sum > d , sum+1 <d
  16323. };
  16324. /*
  16325. THREE.CurvePath.prototype.getTangent = function( t ) {
  16326. };*/
  16327. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  16328. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  16329. // getPoint() depends on getLength
  16330. THREE.CurvePath.prototype.getLength = function() {
  16331. var lens = this.getCurveLengths();
  16332. return lens[ lens.length - 1 ];
  16333. };
  16334. // Compute lengths and cache them
  16335. // We cannot overwrite getLengths() because UtoT mapping uses it.
  16336. THREE.CurvePath.prototype.getCurveLengths = function() {
  16337. // We use cache values if curves and cache array are same length
  16338. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  16339. return this.cacheLengths;
  16340. }
  16341. // Get length of sub-curve
  16342. // Push sums into cached array
  16343. var lengths = [], sums = 0;
  16344. var i, il = this.curves.length;
  16345. for ( i = 0; i < il; i ++ ) {
  16346. sums += this.curves[ i ].getLength();
  16347. lengths.push( sums );
  16348. }
  16349. this.cacheLengths = lengths;
  16350. return lengths;
  16351. };
  16352. // Returns min and max coordinates
  16353. THREE.CurvePath.prototype.getBoundingBox = function () {
  16354. var points = this.getPoints();
  16355. var maxX, maxY, maxZ;
  16356. var minX, minY, minZ;
  16357. maxX = maxY = Number.NEGATIVE_INFINITY;
  16358. minX = minY = Number.POSITIVE_INFINITY;
  16359. var p, i, il, sum;
  16360. var v3 = points[0] instanceof THREE.Vector3;
  16361. sum = v3 ? new THREE.Vector3() : new THREE.Vector2();
  16362. for ( i = 0, il = points.length; i < il; i ++ ) {
  16363. p = points[ i ];
  16364. if ( p.x > maxX ) maxX = p.x;
  16365. else if ( p.x < minX ) minX = p.x;
  16366. if ( p.y > maxY ) maxY = p.y;
  16367. else if ( p.y < minY ) minY = p.y;
  16368. if ( v3 ) {
  16369. if ( p.z > maxZ ) maxZ = p.z;
  16370. else if ( p.z < minZ ) minZ = p.z;
  16371. }
  16372. sum.add( p );
  16373. }
  16374. var ret = {
  16375. minX: minX,
  16376. minY: minY,
  16377. maxX: maxX,
  16378. maxY: maxY
  16379. };
  16380. if ( v3 ) {
  16381. ret.maxZ = maxZ;
  16382. ret.minZ = minZ;
  16383. }
  16384. return ret;
  16385. };
  16386. /**************************************************************
  16387. * Create Geometries Helpers
  16388. **************************************************************/
  16389. /// Generate geometry from path points (for Line or Points objects)
  16390. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  16391. var pts = this.getPoints( divisions, true );
  16392. return this.createGeometry( pts );
  16393. };
  16394. // Generate geometry from equidistant sampling along the path
  16395. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  16396. var pts = this.getSpacedPoints( divisions, true );
  16397. return this.createGeometry( pts );
  16398. };
  16399. THREE.CurvePath.prototype.createGeometry = function( points ) {
  16400. var geometry = new THREE.Geometry();
  16401. for ( var i = 0; i < points.length; i ++ ) {
  16402. geometry.vertices.push( new THREE.Vector3( points[ i ].x, points[ i ].y, points[ i ].z || 0) );
  16403. }
  16404. return geometry;
  16405. };
  16406. /**************************************************************
  16407. * Bend / Wrap Helper Methods
  16408. **************************************************************/
  16409. // Wrap path / Bend modifiers?
  16410. THREE.CurvePath.prototype.addWrapPath = function ( bendpath ) {
  16411. this.bends.push( bendpath );
  16412. };
  16413. THREE.CurvePath.prototype.getTransformedPoints = function( segments, bends ) {
  16414. var oldPts = this.getPoints( segments ); // getPoints getSpacedPoints
  16415. var i, il;
  16416. if ( ! bends ) {
  16417. bends = this.bends;
  16418. }
  16419. for ( i = 0, il = bends.length; i < il; i ++ ) {
  16420. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  16421. }
  16422. return oldPts;
  16423. };
  16424. THREE.CurvePath.prototype.getTransformedSpacedPoints = function( segments, bends ) {
  16425. var oldPts = this.getSpacedPoints( segments );
  16426. var i, il;
  16427. if ( ! bends ) {
  16428. bends = this.bends;
  16429. }
  16430. for ( i = 0, il = bends.length; i < il; i ++ ) {
  16431. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  16432. }
  16433. return oldPts;
  16434. };
  16435. // This returns getPoints() bend/wrapped around the contour of a path.
  16436. // Read http://www.planetclegg.com/projects/WarpingTextToSplines.html
  16437. THREE.CurvePath.prototype.getWrapPoints = function ( oldPts, path ) {
  16438. var bounds = this.getBoundingBox();
  16439. var i, il, p, oldX, oldY, xNorm;
  16440. for ( i = 0, il = oldPts.length; i < il; i ++ ) {
  16441. p = oldPts[ i ];
  16442. oldX = p.x;
  16443. oldY = p.y;
  16444. xNorm = oldX / bounds.maxX;
  16445. // If using actual distance, for length > path, requires line extrusions
  16446. //xNorm = path.getUtoTmapping(xNorm, oldX); // 3 styles. 1) wrap stretched. 2) wrap stretch by arc length 3) warp by actual distance
  16447. xNorm = path.getUtoTmapping( xNorm, oldX );
  16448. // check for out of bounds?
  16449. var pathPt = path.getPoint( xNorm );
  16450. var normal = path.getTangent( xNorm );
  16451. normal.set( - normal.y, normal.x ).multiplyScalar( oldY );
  16452. p.x = pathPt.x + normal.x;
  16453. p.y = pathPt.y + normal.y;
  16454. }
  16455. return oldPts;
  16456. };
  16457. // File:src/extras/core/Gyroscope.js
  16458. /**
  16459. * @author alteredq / http://alteredqualia.com/
  16460. */
  16461. THREE.Gyroscope = function () {
  16462. THREE.Object3D.call( this );
  16463. };
  16464. THREE.Gyroscope.prototype = Object.create( THREE.Object3D.prototype );
  16465. THREE.Gyroscope.prototype.constructor = THREE.Gyroscope;
  16466. THREE.Gyroscope.prototype.updateMatrixWorld = ( function () {
  16467. var translationObject = new THREE.Vector3();
  16468. var quaternionObject = new THREE.Quaternion();
  16469. var scaleObject = new THREE.Vector3();
  16470. var translationWorld = new THREE.Vector3();
  16471. var quaternionWorld = new THREE.Quaternion();
  16472. var scaleWorld = new THREE.Vector3();
  16473. return function ( force ) {
  16474. this.matrixAutoUpdate && this.updateMatrix();
  16475. // update matrixWorld
  16476. if ( this.matrixWorldNeedsUpdate || force ) {
  16477. if ( this.parent ) {
  16478. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  16479. this.matrixWorld.decompose( translationWorld, quaternionWorld, scaleWorld );
  16480. this.matrix.decompose( translationObject, quaternionObject, scaleObject );
  16481. this.matrixWorld.compose( translationWorld, quaternionObject, scaleWorld );
  16482. } else {
  16483. this.matrixWorld.copy( this.matrix );
  16484. }
  16485. this.matrixWorldNeedsUpdate = false;
  16486. force = true;
  16487. }
  16488. // update children
  16489. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  16490. this.children[ i ].updateMatrixWorld( force );
  16491. }
  16492. };
  16493. }() );
  16494. // File:src/extras/core/Path.js
  16495. /**
  16496. * @author zz85 / http://www.lab4games.net/zz85/blog
  16497. * Creates free form 2d path using series of points, lines or curves.
  16498. *
  16499. **/
  16500. THREE.Path = function ( points ) {
  16501. THREE.CurvePath.call(this);
  16502. this.actions = [];
  16503. if ( points ) {
  16504. this.fromPoints( points );
  16505. }
  16506. };
  16507. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  16508. THREE.Path.prototype.constructor = THREE.Path;
  16509. THREE.PathActions = {
  16510. MOVE_TO: 'moveTo',
  16511. LINE_TO: 'lineTo',
  16512. QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
  16513. BEZIER_CURVE_TO: 'bezierCurveTo', // Bezier cubic curve
  16514. CSPLINE_THRU: 'splineThru', // Catmull-Rom spline
  16515. ARC: 'arc', // Circle
  16516. ELLIPSE: 'ellipse'
  16517. };
  16518. // TODO Clean up PATH API
  16519. // Create path using straight lines to connect all points
  16520. // - vectors: array of Vector2
  16521. THREE.Path.prototype.fromPoints = function ( vectors ) {
  16522. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  16523. for ( var v = 1, vlen = vectors.length; v < vlen; v ++ ) {
  16524. this.lineTo( vectors[ v ].x, vectors[ v ].y );
  16525. }
  16526. };
  16527. // startPath() endPath()?
  16528. THREE.Path.prototype.moveTo = function ( x, y ) {
  16529. var args = Array.prototype.slice.call( arguments );
  16530. this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
  16531. };
  16532. THREE.Path.prototype.lineTo = function ( x, y ) {
  16533. var args = Array.prototype.slice.call( arguments );
  16534. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16535. var x0 = lastargs[ lastargs.length - 2 ];
  16536. var y0 = lastargs[ lastargs.length - 1 ];
  16537. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  16538. this.curves.push( curve );
  16539. this.actions.push( { action: THREE.PathActions.LINE_TO, args: args } );
  16540. };
  16541. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  16542. var args = Array.prototype.slice.call( arguments );
  16543. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16544. var x0 = lastargs[ lastargs.length - 2 ];
  16545. var y0 = lastargs[ lastargs.length - 1 ];
  16546. var curve = new THREE.QuadraticBezierCurve( new THREE.Vector2( x0, y0 ),
  16547. new THREE.Vector2( aCPx, aCPy ),
  16548. new THREE.Vector2( aX, aY ) );
  16549. this.curves.push( curve );
  16550. this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args } );
  16551. };
  16552. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y,
  16553. aCP2x, aCP2y,
  16554. aX, aY ) {
  16555. var args = Array.prototype.slice.call( arguments );
  16556. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16557. var x0 = lastargs[ lastargs.length - 2 ];
  16558. var y0 = lastargs[ lastargs.length - 1 ];
  16559. var curve = new THREE.CubicBezierCurve( new THREE.Vector2( x0, y0 ),
  16560. new THREE.Vector2( aCP1x, aCP1y ),
  16561. new THREE.Vector2( aCP2x, aCP2y ),
  16562. new THREE.Vector2( aX, aY ) );
  16563. this.curves.push( curve );
  16564. this.actions.push( { action: THREE.PathActions.BEZIER_CURVE_TO, args: args } );
  16565. };
  16566. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  16567. var args = Array.prototype.slice.call( arguments );
  16568. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16569. var x0 = lastargs[ lastargs.length - 2 ];
  16570. var y0 = lastargs[ lastargs.length - 1 ];
  16571. //---
  16572. var npts = [ new THREE.Vector2( x0, y0 ) ];
  16573. Array.prototype.push.apply( npts, pts );
  16574. var curve = new THREE.SplineCurve( npts );
  16575. this.curves.push( curve );
  16576. this.actions.push( { action: THREE.PathActions.CSPLINE_THRU, args: args } );
  16577. };
  16578. // FUTURE: Change the API or follow canvas API?
  16579. THREE.Path.prototype.arc = function ( aX, aY, aRadius,
  16580. aStartAngle, aEndAngle, aClockwise ) {
  16581. var lastargs = this.actions[ this.actions.length - 1].args;
  16582. var x0 = lastargs[ lastargs.length - 2 ];
  16583. var y0 = lastargs[ lastargs.length - 1 ];
  16584. this.absarc(aX + x0, aY + y0, aRadius,
  16585. aStartAngle, aEndAngle, aClockwise );
  16586. };
  16587. THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
  16588. aStartAngle, aEndAngle, aClockwise ) {
  16589. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  16590. };
  16591. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius,
  16592. aStartAngle, aEndAngle, aClockwise ) {
  16593. var lastargs = this.actions[ this.actions.length - 1].args;
  16594. var x0 = lastargs[ lastargs.length - 2 ];
  16595. var y0 = lastargs[ lastargs.length - 1 ];
  16596. this.absellipse(aX + x0, aY + y0, xRadius, yRadius,
  16597. aStartAngle, aEndAngle, aClockwise );
  16598. };
  16599. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius,
  16600. aStartAngle, aEndAngle, aClockwise ) {
  16601. var args = Array.prototype.slice.call( arguments );
  16602. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius,
  16603. aStartAngle, aEndAngle, aClockwise );
  16604. this.curves.push( curve );
  16605. var lastPoint = curve.getPoint(1);
  16606. args.push(lastPoint.x);
  16607. args.push(lastPoint.y);
  16608. this.actions.push( { action: THREE.PathActions.ELLIPSE, args: args } );
  16609. };
  16610. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  16611. if ( ! divisions ) divisions = 40;
  16612. var points = [];
  16613. for ( var i = 0; i < divisions; i ++ ) {
  16614. points.push( this.getPoint( i / divisions ) );
  16615. //if( !this.getPoint( i / divisions ) ) throw "DIE";
  16616. }
  16617. // if ( closedPath ) {
  16618. //
  16619. // points.push( points[ 0 ] );
  16620. //
  16621. // }
  16622. return points;
  16623. };
  16624. /* Return an array of vectors based on contour of the path */
  16625. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  16626. if (this.useSpacedPoints) {
  16627. return this.getSpacedPoints( divisions, closedPath );
  16628. }
  16629. divisions = divisions || 12;
  16630. var points = [];
  16631. var i, il, item, action, args;
  16632. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  16633. laste, j,
  16634. t, tx, ty;
  16635. for ( i = 0, il = this.actions.length; i < il; i ++ ) {
  16636. item = this.actions[ i ];
  16637. action = item.action;
  16638. args = item.args;
  16639. switch ( action ) {
  16640. case THREE.PathActions.MOVE_TO:
  16641. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  16642. break;
  16643. case THREE.PathActions.LINE_TO:
  16644. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  16645. break;
  16646. case THREE.PathActions.QUADRATIC_CURVE_TO:
  16647. cpx = args[ 2 ];
  16648. cpy = args[ 3 ];
  16649. cpx1 = args[ 0 ];
  16650. cpy1 = args[ 1 ];
  16651. if ( points.length > 0 ) {
  16652. laste = points[ points.length - 1 ];
  16653. cpx0 = laste.x;
  16654. cpy0 = laste.y;
  16655. } else {
  16656. laste = this.actions[ i - 1 ].args;
  16657. cpx0 = laste[ laste.length - 2 ];
  16658. cpy0 = laste[ laste.length - 1 ];
  16659. }
  16660. for ( j = 1; j <= divisions; j ++ ) {
  16661. t = j / divisions;
  16662. tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  16663. ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  16664. points.push( new THREE.Vector2( tx, ty ) );
  16665. }
  16666. break;
  16667. case THREE.PathActions.BEZIER_CURVE_TO:
  16668. cpx = args[ 4 ];
  16669. cpy = args[ 5 ];
  16670. cpx1 = args[ 0 ];
  16671. cpy1 = args[ 1 ];
  16672. cpx2 = args[ 2 ];
  16673. cpy2 = args[ 3 ];
  16674. if ( points.length > 0 ) {
  16675. laste = points[ points.length - 1 ];
  16676. cpx0 = laste.x;
  16677. cpy0 = laste.y;
  16678. } else {
  16679. laste = this.actions[ i - 1 ].args;
  16680. cpx0 = laste[ laste.length - 2 ];
  16681. cpy0 = laste[ laste.length - 1 ];
  16682. }
  16683. for ( j = 1; j <= divisions; j ++ ) {
  16684. t = j / divisions;
  16685. tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  16686. ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  16687. points.push( new THREE.Vector2( tx, ty ) );
  16688. }
  16689. break;
  16690. case THREE.PathActions.CSPLINE_THRU:
  16691. laste = this.actions[ i - 1 ].args;
  16692. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  16693. var spts = [ last ];
  16694. var n = divisions * args[ 0 ].length;
  16695. spts = spts.concat( args[ 0 ] );
  16696. var spline = new THREE.SplineCurve( spts );
  16697. for ( j = 1; j <= n; j ++ ) {
  16698. points.push( spline.getPointAt( j / n ) ) ;
  16699. }
  16700. break;
  16701. case THREE.PathActions.ARC:
  16702. var aX = args[ 0 ], aY = args[ 1 ],
  16703. aRadius = args[ 2 ],
  16704. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  16705. aClockwise = !! args[ 5 ];
  16706. var deltaAngle = aEndAngle - aStartAngle;
  16707. var angle;
  16708. var tdivisions = divisions * 2;
  16709. for ( j = 1; j <= tdivisions; j ++ ) {
  16710. t = j / tdivisions;
  16711. if ( ! aClockwise ) {
  16712. t = 1 - t;
  16713. }
  16714. angle = aStartAngle + t * deltaAngle;
  16715. tx = aX + aRadius * Math.cos( angle );
  16716. ty = aY + aRadius * Math.sin( angle );
  16717. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  16718. points.push( new THREE.Vector2( tx, ty ) );
  16719. }
  16720. //console.log(points);
  16721. break;
  16722. case THREE.PathActions.ELLIPSE:
  16723. var aX = args[ 0 ], aY = args[ 1 ],
  16724. xRadius = args[ 2 ],
  16725. yRadius = args[ 3 ],
  16726. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  16727. aClockwise = !! args[ 6 ];
  16728. var deltaAngle = aEndAngle - aStartAngle;
  16729. var angle;
  16730. var tdivisions = divisions * 2;
  16731. for ( j = 1; j <= tdivisions; j ++ ) {
  16732. t = j / tdivisions;
  16733. if ( ! aClockwise ) {
  16734. t = 1 - t;
  16735. }
  16736. angle = aStartAngle + t * deltaAngle;
  16737. tx = aX + xRadius * Math.cos( angle );
  16738. ty = aY + yRadius * Math.sin( angle );
  16739. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  16740. points.push( new THREE.Vector2( tx, ty ) );
  16741. }
  16742. //console.log(points);
  16743. break;
  16744. } // end switch
  16745. }
  16746. // Normalize to remove the closing point by default.
  16747. var lastPoint = points[ points.length - 1];
  16748. var EPSILON = 0.0000000001;
  16749. if ( Math.abs(lastPoint.x - points[ 0 ].x) < EPSILON &&
  16750. Math.abs(lastPoint.y - points[ 0 ].y) < EPSILON)
  16751. points.splice( points.length - 1, 1);
  16752. if ( closedPath ) {
  16753. points.push( points[ 0 ] );
  16754. }
  16755. return points;
  16756. };
  16757. //
  16758. // Breaks path into shapes
  16759. //
  16760. // Assumptions (if parameter isCCW==true the opposite holds):
  16761. // - solid shapes are defined clockwise (CW)
  16762. // - holes are defined counterclockwise (CCW)
  16763. //
  16764. // If parameter noHoles==true:
  16765. // - all subPaths are regarded as solid shapes
  16766. // - definition order CW/CCW has no relevance
  16767. //
  16768. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  16769. function extractSubpaths( inActions ) {
  16770. var i, il, item, action, args;
  16771. var subPaths = [], lastPath = new THREE.Path();
  16772. for ( i = 0, il = inActions.length; i < il; i ++ ) {
  16773. item = inActions[ i ];
  16774. args = item.args;
  16775. action = item.action;
  16776. if ( action === THREE.PathActions.MOVE_TO ) {
  16777. if ( lastPath.actions.length !== 0 ) {
  16778. subPaths.push( lastPath );
  16779. lastPath = new THREE.Path();
  16780. }
  16781. }
  16782. lastPath[ action ].apply( lastPath, args );
  16783. }
  16784. if ( lastPath.actions.length !== 0 ) {
  16785. subPaths.push( lastPath );
  16786. }
  16787. // console.log(subPaths);
  16788. return subPaths;
  16789. }
  16790. function toShapesNoHoles( inSubpaths ) {
  16791. var shapes = [];
  16792. for ( var i = 0, il = inSubpaths.length; i < il; i ++ ) {
  16793. var tmpPath = inSubpaths[ i ];
  16794. var tmpShape = new THREE.Shape();
  16795. tmpShape.actions = tmpPath.actions;
  16796. tmpShape.curves = tmpPath.curves;
  16797. shapes.push( tmpShape );
  16798. }
  16799. //console.log("shape", shapes);
  16800. return shapes;
  16801. }
  16802. function isPointInsidePolygon( inPt, inPolygon ) {
  16803. var EPSILON = 0.0000000001;
  16804. var polyLen = inPolygon.length;
  16805. // inPt on polygon contour => immediate success or
  16806. // toggling of inside/outside at every single! intersection point of an edge
  16807. // with the horizontal line through inPt, left of inPt
  16808. // not counting lowerY endpoints of edges and whole edges on that line
  16809. var inside = false;
  16810. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  16811. var edgeLowPt = inPolygon[ p ];
  16812. var edgeHighPt = inPolygon[ q ];
  16813. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  16814. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  16815. if ( Math.abs(edgeDy) > EPSILON ) { // not parallel
  16816. if ( edgeDy < 0 ) {
  16817. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  16818. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  16819. }
  16820. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  16821. if ( inPt.y === edgeLowPt.y ) {
  16822. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  16823. // continue; // no intersection or edgeLowPt => doesn't count !!!
  16824. } else {
  16825. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  16826. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  16827. if ( perpEdge < 0 ) continue;
  16828. inside = ! inside; // true intersection left of inPt
  16829. }
  16830. } else { // parallel or collinear
  16831. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  16832. // edge lies on the same horizontal line as inPt
  16833. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  16834. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  16835. // continue;
  16836. }
  16837. }
  16838. return inside;
  16839. }
  16840. var subPaths = extractSubpaths( this.actions );
  16841. if ( subPaths.length === 0 ) return [];
  16842. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  16843. var solid, tmpPath, tmpShape, shapes = [];
  16844. if ( subPaths.length === 1) {
  16845. tmpPath = subPaths[0];
  16846. tmpShape = new THREE.Shape();
  16847. tmpShape.actions = tmpPath.actions;
  16848. tmpShape.curves = tmpPath.curves;
  16849. shapes.push( tmpShape );
  16850. return shapes;
  16851. }
  16852. var holesFirst = ! THREE.Shape.Utils.isClockWise( subPaths[ 0 ].getPoints() );
  16853. holesFirst = isCCW ? ! holesFirst : holesFirst;
  16854. // console.log("Holes first", holesFirst);
  16855. var betterShapeHoles = [];
  16856. var newShapes = [];
  16857. var newShapeHoles = [];
  16858. var mainIdx = 0;
  16859. var tmpPoints;
  16860. newShapes[mainIdx] = undefined;
  16861. newShapeHoles[mainIdx] = [];
  16862. var i, il;
  16863. for ( i = 0, il = subPaths.length; i < il; i ++ ) {
  16864. tmpPath = subPaths[ i ];
  16865. tmpPoints = tmpPath.getPoints();
  16866. solid = THREE.Shape.Utils.isClockWise( tmpPoints );
  16867. solid = isCCW ? ! solid : solid;
  16868. if ( solid ) {
  16869. if ( (! holesFirst ) && ( newShapes[mainIdx] ) ) mainIdx ++;
  16870. newShapes[mainIdx] = { s: new THREE.Shape(), p: tmpPoints };
  16871. newShapes[mainIdx].s.actions = tmpPath.actions;
  16872. newShapes[mainIdx].s.curves = tmpPath.curves;
  16873. if ( holesFirst ) mainIdx ++;
  16874. newShapeHoles[mainIdx] = [];
  16875. //console.log('cw', i);
  16876. } else {
  16877. newShapeHoles[mainIdx].push( { h: tmpPath, p: tmpPoints[0] } );
  16878. //console.log('ccw', i);
  16879. }
  16880. }
  16881. // only Holes? -> probably all Shapes with wrong orientation
  16882. if ( ! newShapes[0] ) return toShapesNoHoles( subPaths );
  16883. if ( newShapes.length > 1 ) {
  16884. var ambiguous = false;
  16885. var toChange = [];
  16886. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  16887. betterShapeHoles[sIdx] = [];
  16888. }
  16889. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  16890. var sho = newShapeHoles[sIdx];
  16891. for (var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  16892. var ho = sho[hIdx];
  16893. var hole_unassigned = true;
  16894. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  16895. if ( isPointInsidePolygon( ho.p, newShapes[s2Idx].p ) ) {
  16896. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  16897. if ( hole_unassigned ) {
  16898. hole_unassigned = false;
  16899. betterShapeHoles[s2Idx].push( ho );
  16900. } else {
  16901. ambiguous = true;
  16902. }
  16903. }
  16904. }
  16905. if ( hole_unassigned ) { betterShapeHoles[sIdx].push( ho ); }
  16906. }
  16907. }
  16908. // console.log("ambiguous: ", ambiguous);
  16909. if ( toChange.length > 0 ) {
  16910. // console.log("to change: ", toChange);
  16911. if (! ambiguous) newShapeHoles = betterShapeHoles;
  16912. }
  16913. }
  16914. var tmpHoles, j, jl;
  16915. for ( i = 0, il = newShapes.length; i < il; i ++ ) {
  16916. tmpShape = newShapes[i].s;
  16917. shapes.push( tmpShape );
  16918. tmpHoles = newShapeHoles[i];
  16919. for ( j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  16920. tmpShape.holes.push( tmpHoles[j].h );
  16921. }
  16922. }
  16923. //console.log("shape", shapes);
  16924. return shapes;
  16925. };
  16926. // File:src/extras/core/Shape.js
  16927. /**
  16928. * @author zz85 / http://www.lab4games.net/zz85/blog
  16929. * Defines a 2d shape plane using paths.
  16930. **/
  16931. // STEP 1 Create a path.
  16932. // STEP 2 Turn path into shape.
  16933. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  16934. // STEP 3a - Extract points from each shape, turn to vertices
  16935. // STEP 3b - Triangulate each shape, add faces.
  16936. THREE.Shape = function () {
  16937. THREE.Path.apply( this, arguments );
  16938. this.holes = [];
  16939. };
  16940. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  16941. THREE.Shape.prototype.constructor = THREE.Shape;
  16942. // Convenience method to return ExtrudeGeometry
  16943. THREE.Shape.prototype.extrude = function ( options ) {
  16944. var extruded = new THREE.ExtrudeGeometry( this, options );
  16945. return extruded;
  16946. };
  16947. // Convenience method to return ShapeGeometry
  16948. THREE.Shape.prototype.makeGeometry = function ( options ) {
  16949. var geometry = new THREE.ShapeGeometry( this, options );
  16950. return geometry;
  16951. };
  16952. // Get points of holes
  16953. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  16954. var i, il = this.holes.length, holesPts = [];
  16955. for ( i = 0; i < il; i ++ ) {
  16956. holesPts[ i ] = this.holes[ i ].getTransformedPoints( divisions, this.bends );
  16957. }
  16958. return holesPts;
  16959. };
  16960. // Get points of holes (spaced by regular distance)
  16961. THREE.Shape.prototype.getSpacedPointsHoles = function ( divisions ) {
  16962. var i, il = this.holes.length, holesPts = [];
  16963. for ( i = 0; i < il; i ++ ) {
  16964. holesPts[ i ] = this.holes[ i ].getTransformedSpacedPoints( divisions, this.bends );
  16965. }
  16966. return holesPts;
  16967. };
  16968. // Get points of shape and holes (keypoints based on segments parameter)
  16969. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  16970. return {
  16971. shape: this.getTransformedPoints( divisions ),
  16972. holes: this.getPointsHoles( divisions )
  16973. };
  16974. };
  16975. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  16976. if (this.useSpacedPoints) {
  16977. return this.extractAllSpacedPoints(divisions);
  16978. }
  16979. return this.extractAllPoints(divisions);
  16980. };
  16981. //
  16982. // THREE.Shape.prototype.extractAllPointsWithBend = function ( divisions, bend ) {
  16983. //
  16984. // return {
  16985. //
  16986. // shape: this.transform( bend, divisions ),
  16987. // holes: this.getPointsHoles( divisions, bend )
  16988. //
  16989. // };
  16990. //
  16991. // };
  16992. // Get points of shape and holes (spaced by regular distance)
  16993. THREE.Shape.prototype.extractAllSpacedPoints = function ( divisions ) {
  16994. return {
  16995. shape: this.getTransformedSpacedPoints( divisions ),
  16996. holes: this.getSpacedPointsHoles( divisions )
  16997. };
  16998. };
  16999. /**************************************************************
  17000. * Utils
  17001. **************************************************************/
  17002. THREE.Shape.Utils = {
  17003. triangulateShape: function ( contour, holes ) {
  17004. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  17005. // inOtherPt needs to be collinear to the inSegment
  17006. if ( inSegPt1.x !== inSegPt2.x ) {
  17007. if ( inSegPt1.x < inSegPt2.x ) {
  17008. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  17009. } else {
  17010. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  17011. }
  17012. } else {
  17013. if ( inSegPt1.y < inSegPt2.y ) {
  17014. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  17015. } else {
  17016. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  17017. }
  17018. }
  17019. }
  17020. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  17021. var EPSILON = 0.0000000001;
  17022. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  17023. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  17024. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  17025. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  17026. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  17027. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  17028. if ( Math.abs(limit) > EPSILON ) { // not parallel
  17029. var perpSeg2;
  17030. if ( limit > 0 ) {
  17031. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  17032. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17033. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  17034. } else {
  17035. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  17036. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17037. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  17038. }
  17039. // i.e. to reduce rounding errors
  17040. // intersection at endpoint of segment#1?
  17041. if ( perpSeg2 === 0 ) {
  17042. if ( ( inExcludeAdjacentSegs ) &&
  17043. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17044. return [ inSeg1Pt1 ];
  17045. }
  17046. if ( perpSeg2 === limit ) {
  17047. if ( ( inExcludeAdjacentSegs ) &&
  17048. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17049. return [ inSeg1Pt2 ];
  17050. }
  17051. // intersection at endpoint of segment#2?
  17052. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  17053. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  17054. // return real intersection point
  17055. var factorSeg1 = perpSeg2 / limit;
  17056. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  17057. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  17058. } else { // parallel or collinear
  17059. if ( ( perpSeg1 !== 0 ) ||
  17060. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  17061. // they are collinear or degenerate
  17062. var seg1Pt = ( (seg1dx === 0) && (seg1dy === 0) ); // segment1 is just a point?
  17063. var seg2Pt = ( (seg2dx === 0) && (seg2dy === 0) ); // segment2 is just a point?
  17064. // both segments are points
  17065. if ( seg1Pt && seg2Pt ) {
  17066. if ( (inSeg1Pt1.x !== inSeg2Pt1.x) ||
  17067. (inSeg1Pt1.y !== inSeg2Pt1.y) ) return []; // they are distinct points
  17068. return [ inSeg1Pt1 ]; // they are the same point
  17069. }
  17070. // segment#1 is a single point
  17071. if ( seg1Pt ) {
  17072. if (! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  17073. return [ inSeg1Pt1 ];
  17074. }
  17075. // segment#2 is a single point
  17076. if ( seg2Pt ) {
  17077. if (! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  17078. return [ inSeg2Pt1 ];
  17079. }
  17080. // they are collinear segments, which might overlap
  17081. var seg1min, seg1max, seg1minVal, seg1maxVal;
  17082. var seg2min, seg2max, seg2minVal, seg2maxVal;
  17083. if (seg1dx !== 0) { // the segments are NOT on a vertical line
  17084. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  17085. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  17086. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  17087. } else {
  17088. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  17089. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  17090. }
  17091. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  17092. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  17093. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  17094. } else {
  17095. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  17096. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  17097. }
  17098. } else { // the segments are on a vertical line
  17099. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  17100. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  17101. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  17102. } else {
  17103. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  17104. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  17105. }
  17106. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  17107. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  17108. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  17109. } else {
  17110. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  17111. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  17112. }
  17113. }
  17114. if ( seg1minVal <= seg2minVal ) {
  17115. if ( seg1maxVal < seg2minVal ) return [];
  17116. if ( seg1maxVal === seg2minVal ) {
  17117. if ( inExcludeAdjacentSegs ) return [];
  17118. return [ seg2min ];
  17119. }
  17120. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  17121. return [ seg2min, seg2max ];
  17122. } else {
  17123. if ( seg1minVal > seg2maxVal ) return [];
  17124. if ( seg1minVal === seg2maxVal ) {
  17125. if ( inExcludeAdjacentSegs ) return [];
  17126. return [ seg1min ];
  17127. }
  17128. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  17129. return [ seg1min, seg2max ];
  17130. }
  17131. }
  17132. }
  17133. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  17134. // The order of legs is important
  17135. var EPSILON = 0.0000000001;
  17136. // translation of all points, so that Vertex is at (0,0)
  17137. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  17138. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  17139. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  17140. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  17141. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  17142. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  17143. if ( Math.abs(from2toAngle) > EPSILON ) { // angle != 180 deg.
  17144. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  17145. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  17146. if ( from2toAngle > 0 ) { // main angle < 180 deg.
  17147. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  17148. } else { // main angle > 180 deg.
  17149. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  17150. }
  17151. } else { // angle == 180 deg.
  17152. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  17153. return ( from2otherAngle > 0 );
  17154. }
  17155. }
  17156. function removeHoles( contour, holes ) {
  17157. var shape = contour.concat(); // work on this shape
  17158. var hole;
  17159. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  17160. // Check if hole point lies within angle around shape point
  17161. var lastShapeIdx = shape.length - 1;
  17162. var prevShapeIdx = inShapeIdx - 1;
  17163. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  17164. var nextShapeIdx = inShapeIdx + 1;
  17165. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  17166. var insideAngle = isPointInsideAngle( shape[inShapeIdx], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[inHoleIdx] );
  17167. if (! insideAngle ) {
  17168. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  17169. return false;
  17170. }
  17171. // Check if shape point lies within angle around hole point
  17172. var lastHoleIdx = hole.length - 1;
  17173. var prevHoleIdx = inHoleIdx - 1;
  17174. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  17175. var nextHoleIdx = inHoleIdx + 1;
  17176. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  17177. insideAngle = isPointInsideAngle( hole[inHoleIdx], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[inShapeIdx] );
  17178. if (! insideAngle ) {
  17179. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  17180. return false;
  17181. }
  17182. return true;
  17183. }
  17184. function intersectsShapeEdge( inShapePt, inHolePt ) {
  17185. // checks for intersections with shape edges
  17186. var sIdx, nextIdx, intersection;
  17187. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  17188. nextIdx = sIdx + 1; nextIdx %= shape.length;
  17189. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[sIdx], shape[nextIdx], true );
  17190. if ( intersection.length > 0 ) return true;
  17191. }
  17192. return false;
  17193. }
  17194. var indepHoles = [];
  17195. function intersectsHoleEdge( inShapePt, inHolePt ) {
  17196. // checks for intersections with hole edges
  17197. var ihIdx, chkHole,
  17198. hIdx, nextIdx, intersection;
  17199. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  17200. chkHole = holes[indepHoles[ihIdx]];
  17201. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  17202. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  17203. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[hIdx], chkHole[nextIdx], true );
  17204. if ( intersection.length > 0 ) return true;
  17205. }
  17206. }
  17207. return false;
  17208. }
  17209. var holeIndex, shapeIndex,
  17210. shapePt, holePt,
  17211. holeIdx, cutKey, failedCuts = [],
  17212. tmpShape1, tmpShape2,
  17213. tmpHole1, tmpHole2;
  17214. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17215. indepHoles.push( h );
  17216. }
  17217. var minShapeIndex = 0;
  17218. var counter = indepHoles.length * 2;
  17219. while ( indepHoles.length > 0 ) {
  17220. counter --;
  17221. if ( counter < 0 ) {
  17222. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  17223. break;
  17224. }
  17225. // search for shape-vertex and hole-vertex,
  17226. // which can be connected without intersections
  17227. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  17228. shapePt = shape[ shapeIndex ];
  17229. holeIndex = - 1;
  17230. // search for hole which can be reached without intersections
  17231. for ( var h = 0; h < indepHoles.length; h ++ ) {
  17232. holeIdx = indepHoles[h];
  17233. // prevent multiple checks
  17234. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  17235. if ( failedCuts[cutKey] !== undefined ) continue;
  17236. hole = holes[holeIdx];
  17237. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  17238. holePt = hole[ h2 ];
  17239. if (! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  17240. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  17241. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  17242. holeIndex = h2;
  17243. indepHoles.splice(h, 1);
  17244. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  17245. tmpShape2 = shape.slice( shapeIndex );
  17246. tmpHole1 = hole.slice( holeIndex );
  17247. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  17248. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  17249. minShapeIndex = shapeIndex;
  17250. // Debug only, to show the selected cuts
  17251. // glob_CutLines.push( [ shapePt, holePt ] );
  17252. break;
  17253. }
  17254. if ( holeIndex >= 0 ) break; // hole-vertex found
  17255. failedCuts[cutKey] = true; // remember failure
  17256. }
  17257. if ( holeIndex >= 0 ) break; // hole-vertex found
  17258. }
  17259. }
  17260. return shape; /* shape with no holes */
  17261. }
  17262. var i, il, f, face,
  17263. key, index,
  17264. allPointsMap = {};
  17265. // 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.
  17266. var allpoints = contour.concat();
  17267. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17268. Array.prototype.push.apply( allpoints, holes[h] );
  17269. }
  17270. //console.log( "allpoints",allpoints, allpoints.length );
  17271. // prepare all points map
  17272. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  17273. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  17274. if ( allPointsMap[ key ] !== undefined ) {
  17275. console.warn( "THREE.Shape: Duplicate point", key );
  17276. }
  17277. allPointsMap[ key ] = i;
  17278. }
  17279. // remove holes by cutting paths to holes and adding them to the shape
  17280. var shapeWithoutHoles = removeHoles( contour, holes );
  17281. var triangles = THREE.FontUtils.Triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  17282. //console.log( "triangles",triangles, triangles.length );
  17283. // check all face vertices against all points map
  17284. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  17285. face = triangles[ i ];
  17286. for ( f = 0; f < 3; f ++ ) {
  17287. key = face[ f ].x + ":" + face[ f ].y;
  17288. index = allPointsMap[ key ];
  17289. if ( index !== undefined ) {
  17290. face[ f ] = index;
  17291. }
  17292. }
  17293. }
  17294. return triangles.concat();
  17295. },
  17296. isClockWise: function ( pts ) {
  17297. return THREE.FontUtils.Triangulate.area( pts ) < 0;
  17298. },
  17299. // Bezier Curves formulas obtained from
  17300. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  17301. // Quad Bezier Functions
  17302. b2p0: function ( t, p ) {
  17303. var k = 1 - t;
  17304. return k * k * p;
  17305. },
  17306. b2p1: function ( t, p ) {
  17307. return 2 * ( 1 - t ) * t * p;
  17308. },
  17309. b2p2: function ( t, p ) {
  17310. return t * t * p;
  17311. },
  17312. b2: function ( t, p0, p1, p2 ) {
  17313. return this.b2p0( t, p0 ) + this.b2p1( t, p1 ) + this.b2p2( t, p2 );
  17314. },
  17315. // Cubic Bezier Functions
  17316. b3p0: function ( t, p ) {
  17317. var k = 1 - t;
  17318. return k * k * k * p;
  17319. },
  17320. b3p1: function ( t, p ) {
  17321. var k = 1 - t;
  17322. return 3 * k * k * t * p;
  17323. },
  17324. b3p2: function ( t, p ) {
  17325. var k = 1 - t;
  17326. return 3 * k * t * t * p;
  17327. },
  17328. b3p3: function ( t, p ) {
  17329. return t * t * t * p;
  17330. },
  17331. b3: function ( t, p0, p1, p2, p3 ) {
  17332. return this.b3p0( t, p0 ) + this.b3p1( t, p1 ) + this.b3p2( t, p2 ) + this.b3p3( t, p3 );
  17333. }
  17334. };
  17335. // File:src/extras/curves/LineCurve.js
  17336. /**************************************************************
  17337. * Line
  17338. **************************************************************/
  17339. THREE.LineCurve = function ( v1, v2 ) {
  17340. this.v1 = v1;
  17341. this.v2 = v2;
  17342. };
  17343. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  17344. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  17345. THREE.LineCurve.prototype.getPoint = function ( t ) {
  17346. var point = this.v2.clone().sub(this.v1);
  17347. point.multiplyScalar( t ).add( this.v1 );
  17348. return point;
  17349. };
  17350. // Line curve is linear, so we can overwrite default getPointAt
  17351. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  17352. return this.getPoint( u );
  17353. };
  17354. THREE.LineCurve.prototype.getTangent = function( t ) {
  17355. var tangent = this.v2.clone().sub(this.v1);
  17356. return tangent.normalize();
  17357. };
  17358. // File:src/extras/curves/QuadraticBezierCurve.js
  17359. /**************************************************************
  17360. * Quadratic Bezier curve
  17361. **************************************************************/
  17362. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  17363. this.v0 = v0;
  17364. this.v1 = v1;
  17365. this.v2 = v2;
  17366. };
  17367. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  17368. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  17369. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  17370. var vector = new THREE.Vector2();
  17371. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  17372. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  17373. return vector;
  17374. };
  17375. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  17376. var vector = new THREE.Vector2();
  17377. vector.x = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
  17378. vector.y = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
  17379. // returns unit vector
  17380. return vector.normalize();
  17381. };
  17382. // File:src/extras/curves/CubicBezierCurve.js
  17383. /**************************************************************
  17384. * Cubic Bezier curve
  17385. **************************************************************/
  17386. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  17387. this.v0 = v0;
  17388. this.v1 = v1;
  17389. this.v2 = v2;
  17390. this.v3 = v3;
  17391. };
  17392. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  17393. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  17394. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  17395. var tx, ty;
  17396. tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17397. ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17398. return new THREE.Vector2( tx, ty );
  17399. };
  17400. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  17401. var tx, ty;
  17402. tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17403. ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17404. var tangent = new THREE.Vector2( tx, ty );
  17405. tangent.normalize();
  17406. return tangent;
  17407. };
  17408. // File:src/extras/curves/SplineCurve.js
  17409. /**************************************************************
  17410. * Spline curve
  17411. **************************************************************/
  17412. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  17413. this.points = ( points == undefined ) ? [] : points;
  17414. };
  17415. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  17416. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  17417. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  17418. var points = this.points;
  17419. var point = ( points.length - 1 ) * t;
  17420. var intPoint = Math.floor( point );
  17421. var weight = point - intPoint;
  17422. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  17423. var point1 = points[ intPoint ];
  17424. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  17425. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  17426. var vector = new THREE.Vector2();
  17427. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17428. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17429. return vector;
  17430. };
  17431. // File:src/extras/curves/EllipseCurve.js
  17432. /**************************************************************
  17433. * Ellipse curve
  17434. **************************************************************/
  17435. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise ) {
  17436. this.aX = aX;
  17437. this.aY = aY;
  17438. this.xRadius = xRadius;
  17439. this.yRadius = yRadius;
  17440. this.aStartAngle = aStartAngle;
  17441. this.aEndAngle = aEndAngle;
  17442. this.aClockwise = aClockwise;
  17443. };
  17444. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  17445. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  17446. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  17447. var deltaAngle = this.aEndAngle - this.aStartAngle;
  17448. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  17449. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  17450. var angle;
  17451. if ( this.aClockwise === true ) {
  17452. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  17453. } else {
  17454. angle = this.aStartAngle + t * deltaAngle;
  17455. }
  17456. var vector = new THREE.Vector2();
  17457. vector.x = this.aX + this.xRadius * Math.cos( angle );
  17458. vector.y = this.aY + this.yRadius * Math.sin( angle );
  17459. return vector;
  17460. };
  17461. // File:src/extras/curves/ArcCurve.js
  17462. /**************************************************************
  17463. * Arc curve
  17464. **************************************************************/
  17465. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  17466. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  17467. };
  17468. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  17469. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  17470. // File:src/extras/curves/LineCurve3.js
  17471. /**************************************************************
  17472. * Line3D
  17473. **************************************************************/
  17474. THREE.LineCurve3 = THREE.Curve.create(
  17475. function ( v1, v2 ) {
  17476. this.v1 = v1;
  17477. this.v2 = v2;
  17478. },
  17479. function ( t ) {
  17480. var vector = new THREE.Vector3();
  17481. vector.subVectors( this.v2, this.v1 ); // diff
  17482. vector.multiplyScalar( t );
  17483. vector.add( this.v1 );
  17484. return vector;
  17485. }
  17486. );
  17487. // File:src/extras/curves/QuadraticBezierCurve3.js
  17488. /**************************************************************
  17489. * Quadratic Bezier 3D curve
  17490. **************************************************************/
  17491. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  17492. function ( v0, v1, v2 ) {
  17493. this.v0 = v0;
  17494. this.v1 = v1;
  17495. this.v2 = v2;
  17496. },
  17497. function ( t ) {
  17498. var vector = new THREE.Vector3();
  17499. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  17500. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  17501. vector.z = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
  17502. return vector;
  17503. }
  17504. );
  17505. // File:src/extras/curves/CubicBezierCurve3.js
  17506. /**************************************************************
  17507. * Cubic Bezier 3D curve
  17508. **************************************************************/
  17509. THREE.CubicBezierCurve3 = THREE.Curve.create(
  17510. function ( v0, v1, v2, v3 ) {
  17511. this.v0 = v0;
  17512. this.v1 = v1;
  17513. this.v2 = v2;
  17514. this.v3 = v3;
  17515. },
  17516. function ( t ) {
  17517. var vector = new THREE.Vector3();
  17518. vector.x = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17519. vector.y = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17520. vector.z = THREE.Shape.Utils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );
  17521. return vector;
  17522. }
  17523. );
  17524. // File:src/extras/curves/SplineCurve3.js
  17525. /**************************************************************
  17526. * Spline 3D curve
  17527. **************************************************************/
  17528. THREE.SplineCurve3 = THREE.Curve.create(
  17529. function ( points /* array of Vector3 */) {
  17530. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  17531. this.points = ( points == undefined ) ? [] : points;
  17532. },
  17533. function ( t ) {
  17534. var points = this.points;
  17535. var point = ( points.length - 1 ) * t;
  17536. var intPoint = Math.floor( point );
  17537. var weight = point - intPoint;
  17538. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  17539. var point1 = points[ intPoint ];
  17540. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  17541. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  17542. var vector = new THREE.Vector3();
  17543. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17544. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17545. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  17546. return vector;
  17547. }
  17548. );
  17549. // File:src/extras/curves/CatmullRomCurve3.js
  17550. /**
  17551. * @author zz85 https://github.com/zz85
  17552. *
  17553. * Centripetal CatmullRom Curve - which is useful for avoiding
  17554. * cusps and self-intersections in non-uniform catmull rom curves.
  17555. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  17556. *
  17557. * curve.type accepts centripetal(default), chordal and catmullrom
  17558. * curve.tension is used for catmullrom which defaults to 0.5
  17559. */
  17560. THREE.CatmullRomCurve3 = ( function() {
  17561. var
  17562. tmp = new THREE.Vector3(),
  17563. px = new CubicPoly(),
  17564. py = new CubicPoly(),
  17565. pz = new CubicPoly();
  17566. /*
  17567. Based on an optimized c++ solution in
  17568. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  17569. - http://ideone.com/NoEbVM
  17570. This CubicPoly class could be used for reusing some variables and calculations,
  17571. but for three.js curve use, it could be possible inlined and flatten into a single function call
  17572. which can be placed in CurveUtils.
  17573. */
  17574. function CubicPoly() {
  17575. }
  17576. /*
  17577. * Compute coefficients for a cubic polynomial
  17578. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  17579. * such that
  17580. * p(0) = x0, p(1) = x1
  17581. * and
  17582. * p'(0) = t0, p'(1) = t1.
  17583. */
  17584. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  17585. this.c0 = x0;
  17586. this.c1 = t0;
  17587. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  17588. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  17589. };
  17590. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  17591. // compute tangents when parameterized in [t1,t2]
  17592. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  17593. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  17594. // rescale tangents for parametrization in [0,1]
  17595. t1 *= dt1;
  17596. t2 *= dt1;
  17597. // initCubicPoly
  17598. this.init( x1, x2, t1, t2 );
  17599. };
  17600. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  17601. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  17602. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  17603. };
  17604. CubicPoly.prototype.calc = function( t ) {
  17605. var t2 = t * t;
  17606. var t3 = t2 * t;
  17607. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  17608. };
  17609. // Subclass Three.js curve
  17610. return THREE.Curve.create(
  17611. function ( p /* array of Vector3 */ ) {
  17612. this.points = p || [];
  17613. },
  17614. function ( t ) {
  17615. var points = this.points,
  17616. point, intPoint, weight, l;
  17617. l = points.length;
  17618. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  17619. point = ( l - 1 ) * t;
  17620. intPoint = Math.floor( point );
  17621. weight = point - intPoint;
  17622. if ( weight === 0 && intPoint === l - 1 ) {
  17623. intPoint = l - 2;
  17624. weight = 1;
  17625. }
  17626. var p0, p1, p2, p3;
  17627. if ( intPoint === 0 ) {
  17628. // extrapolate first point
  17629. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  17630. p0 = tmp;
  17631. } else {
  17632. p0 = points[ intPoint - 1 ];
  17633. }
  17634. p1 = points[ intPoint ];
  17635. p2 = points[ intPoint + 1 ];
  17636. if ( intPoint + 2 < l ) {
  17637. p3 = points[ intPoint + 2 ]
  17638. } else {
  17639. // extrapolate last point
  17640. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 2 ] );
  17641. p3 = tmp;
  17642. }
  17643. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  17644. // init Centripetal / Chordal Catmull-Rom
  17645. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  17646. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  17647. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  17648. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  17649. // safety check for repeated points
  17650. if ( dt1 < 1e-4 ) dt1 = 1.0;
  17651. if ( dt0 < 1e-4 ) dt0 = dt1;
  17652. if ( dt2 < 1e-4 ) dt2 = dt1;
  17653. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  17654. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  17655. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  17656. } else if ( this.type === 'catmullrom' ) {
  17657. var tension = this.tension !== undefined ? this.tension : 0.5;
  17658. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  17659. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  17660. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  17661. }
  17662. var v = new THREE.Vector3(
  17663. px.calc( weight ),
  17664. py.calc( weight ),
  17665. pz.calc( weight )
  17666. );
  17667. return v;
  17668. }
  17669. );
  17670. } )();
  17671. // File:src/extras/curves/ClosedSplineCurve3.js
  17672. /**************************************************************
  17673. * Closed Spline 3D curve
  17674. **************************************************************/
  17675. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  17676. function ( points /* array of Vector3 */) {
  17677. this.points = ( points == undefined ) ? [] : points;
  17678. },
  17679. function ( t ) {
  17680. var points = this.points;
  17681. var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
  17682. var intPoint = Math.floor( point );
  17683. var weight = point - intPoint;
  17684. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  17685. var point0 = points[ ( intPoint - 1 ) % points.length ];
  17686. var point1 = points[ ( intPoint ) % points.length ];
  17687. var point2 = points[ ( intPoint + 1 ) % points.length ];
  17688. var point3 = points[ ( intPoint + 2 ) % points.length ];
  17689. var vector = new THREE.Vector3();
  17690. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17691. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17692. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  17693. return vector;
  17694. }
  17695. );
  17696. // File:src/extras/animation/AnimationHandler.js
  17697. /**
  17698. * @author mikael emtinger / http://gomo.se/
  17699. */
  17700. THREE.AnimationHandler = {
  17701. LINEAR: 0,
  17702. CATMULLROM: 1,
  17703. CATMULLROM_FORWARD: 2,
  17704. //
  17705. add: function () { console.warn( 'THREE.AnimationHandler.add() has been deprecated.' ); },
  17706. get: function () { console.warn( 'THREE.AnimationHandler.get() has been deprecated.' ); },
  17707. remove: function () { console.warn( 'THREE.AnimationHandler.remove() has been deprecated.' ); },
  17708. //
  17709. animations: [],
  17710. init: function ( data ) {
  17711. if ( data.initialized === true ) return data;
  17712. // loop through all keys
  17713. for ( var h = 0; h < data.hierarchy.length; h ++ ) {
  17714. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17715. // remove minus times
  17716. if ( data.hierarchy[ h ].keys[ k ].time < 0 ) {
  17717. data.hierarchy[ h ].keys[ k ].time = 0;
  17718. }
  17719. // create quaternions
  17720. if ( data.hierarchy[ h ].keys[ k ].rot !== undefined &&
  17721. ! ( data.hierarchy[ h ].keys[ k ].rot instanceof THREE.Quaternion ) ) {
  17722. var quat = data.hierarchy[ h ].keys[ k ].rot;
  17723. data.hierarchy[ h ].keys[ k ].rot = new THREE.Quaternion().fromArray( quat );
  17724. }
  17725. }
  17726. // prepare morph target keys
  17727. if ( data.hierarchy[ h ].keys.length && data.hierarchy[ h ].keys[ 0 ].morphTargets !== undefined ) {
  17728. // get all used
  17729. var usedMorphTargets = {};
  17730. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17731. for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  17732. var morphTargetName = data.hierarchy[ h ].keys[ k ].morphTargets[ m ];
  17733. usedMorphTargets[ morphTargetName ] = - 1;
  17734. }
  17735. }
  17736. data.hierarchy[ h ].usedMorphTargets = usedMorphTargets;
  17737. // set all used on all frames
  17738. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17739. var influences = {};
  17740. for ( var morphTargetName in usedMorphTargets ) {
  17741. for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  17742. if ( data.hierarchy[ h ].keys[ k ].morphTargets[ m ] === morphTargetName ) {
  17743. influences[ morphTargetName ] = data.hierarchy[ h ].keys[ k ].morphTargetsInfluences[ m ];
  17744. break;
  17745. }
  17746. }
  17747. if ( m === data.hierarchy[ h ].keys[ k ].morphTargets.length ) {
  17748. influences[ morphTargetName ] = 0;
  17749. }
  17750. }
  17751. data.hierarchy[ h ].keys[ k ].morphTargetsInfluences = influences;
  17752. }
  17753. }
  17754. // remove all keys that are on the same time
  17755. for ( var k = 1; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17756. if ( data.hierarchy[ h ].keys[ k ].time === data.hierarchy[ h ].keys[ k - 1 ].time ) {
  17757. data.hierarchy[ h ].keys.splice( k, 1 );
  17758. k --;
  17759. }
  17760. }
  17761. // set index
  17762. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17763. data.hierarchy[ h ].keys[ k ].index = k;
  17764. }
  17765. }
  17766. data.initialized = true;
  17767. return data;
  17768. },
  17769. parse: function ( root ) {
  17770. var parseRecurseHierarchy = function ( root, hierarchy ) {
  17771. hierarchy.push( root );
  17772. for ( var c = 0; c < root.children.length; c ++ )
  17773. parseRecurseHierarchy( root.children[ c ], hierarchy );
  17774. };
  17775. // setup hierarchy
  17776. var hierarchy = [];
  17777. if ( root instanceof THREE.SkinnedMesh ) {
  17778. for ( var b = 0; b < root.skeleton.bones.length; b ++ ) {
  17779. hierarchy.push( root.skeleton.bones[ b ] );
  17780. }
  17781. } else {
  17782. parseRecurseHierarchy( root, hierarchy );
  17783. }
  17784. return hierarchy;
  17785. },
  17786. play: function ( animation ) {
  17787. if ( this.animations.indexOf( animation ) === - 1 ) {
  17788. this.animations.push( animation );
  17789. }
  17790. },
  17791. stop: function ( animation ) {
  17792. var index = this.animations.indexOf( animation );
  17793. if ( index !== - 1 ) {
  17794. this.animations.splice( index, 1 );
  17795. }
  17796. },
  17797. update: function ( deltaTimeMS ) {
  17798. for ( var i = 0; i < this.animations.length; i ++ ) {
  17799. this.animations[ i ].resetBlendWeights( );
  17800. }
  17801. for ( var i = 0; i < this.animations.length; i ++ ) {
  17802. this.animations[ i ].update( deltaTimeMS );
  17803. }
  17804. }
  17805. };
  17806. // File:src/extras/animation/Animation.js
  17807. /**
  17808. * @author mikael emtinger / http://gomo.se/
  17809. * @author mrdoob / http://mrdoob.com/
  17810. * @author alteredq / http://alteredqualia.com/
  17811. */
  17812. THREE.Animation = function ( root, data ) {
  17813. this.root = root;
  17814. this.data = THREE.AnimationHandler.init( data );
  17815. this.hierarchy = THREE.AnimationHandler.parse( root );
  17816. this.currentTime = 0;
  17817. this.timeScale = 1;
  17818. this.isPlaying = false;
  17819. this.loop = true;
  17820. this.weight = 0;
  17821. this.interpolationType = THREE.AnimationHandler.LINEAR;
  17822. };
  17823. THREE.Animation.prototype = {
  17824. constructor: THREE.Animation,
  17825. keyTypes: [ "pos", "rot", "scl" ],
  17826. play: function ( startTime, weight ) {
  17827. this.currentTime = startTime !== undefined ? startTime : 0;
  17828. this.weight = weight !== undefined ? weight : 1;
  17829. this.isPlaying = true;
  17830. this.reset();
  17831. THREE.AnimationHandler.play( this );
  17832. },
  17833. stop: function() {
  17834. this.isPlaying = false;
  17835. THREE.AnimationHandler.stop( this );
  17836. },
  17837. reset: function () {
  17838. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  17839. var object = this.hierarchy[ h ];
  17840. if ( object.animationCache === undefined ) {
  17841. object.animationCache = {
  17842. animations: {},
  17843. blending: {
  17844. positionWeight: 0.0,
  17845. quaternionWeight: 0.0,
  17846. scaleWeight: 0.0
  17847. }
  17848. };
  17849. }
  17850. var name = this.data.name;
  17851. var animations = object.animationCache.animations;
  17852. var animationCache = animations[ name ];
  17853. if ( animationCache === undefined ) {
  17854. animationCache = {
  17855. prevKey: { pos: 0, rot: 0, scl: 0 },
  17856. nextKey: { pos: 0, rot: 0, scl: 0 },
  17857. originalMatrix: object.matrix
  17858. };
  17859. animations[ name ] = animationCache;
  17860. }
  17861. // Get keys to match our current time
  17862. for ( var t = 0; t < 3; t ++ ) {
  17863. var type = this.keyTypes[ t ];
  17864. var prevKey = this.data.hierarchy[ h ].keys[ 0 ];
  17865. var nextKey = this.getNextKeyWith( type, h, 1 );
  17866. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  17867. prevKey = nextKey;
  17868. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  17869. }
  17870. animationCache.prevKey[ type ] = prevKey;
  17871. animationCache.nextKey[ type ] = nextKey;
  17872. }
  17873. }
  17874. },
  17875. resetBlendWeights: function () {
  17876. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  17877. var object = this.hierarchy[ h ];
  17878. var animationCache = object.animationCache;
  17879. if ( animationCache !== undefined ) {
  17880. var blending = animationCache.blending;
  17881. blending.positionWeight = 0.0;
  17882. blending.quaternionWeight = 0.0;
  17883. blending.scaleWeight = 0.0;
  17884. }
  17885. }
  17886. },
  17887. update: ( function() {
  17888. var points = [];
  17889. var target = new THREE.Vector3();
  17890. var newVector = new THREE.Vector3();
  17891. var newQuat = new THREE.Quaternion();
  17892. // Catmull-Rom spline
  17893. var interpolateCatmullRom = function ( points, scale ) {
  17894. var c = [], v3 = [],
  17895. point, intPoint, weight, w2, w3,
  17896. pa, pb, pc, pd;
  17897. point = ( points.length - 1 ) * scale;
  17898. intPoint = Math.floor( point );
  17899. weight = point - intPoint;
  17900. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  17901. c[ 1 ] = intPoint;
  17902. c[ 2 ] = intPoint > points.length - 2 ? intPoint : intPoint + 1;
  17903. c[ 3 ] = intPoint > points.length - 3 ? intPoint : intPoint + 2;
  17904. pa = points[ c[ 0 ] ];
  17905. pb = points[ c[ 1 ] ];
  17906. pc = points[ c[ 2 ] ];
  17907. pd = points[ c[ 3 ] ];
  17908. w2 = weight * weight;
  17909. w3 = weight * w2;
  17910. v3[ 0 ] = interpolate( pa[ 0 ], pb[ 0 ], pc[ 0 ], pd[ 0 ], weight, w2, w3 );
  17911. v3[ 1 ] = interpolate( pa[ 1 ], pb[ 1 ], pc[ 1 ], pd[ 1 ], weight, w2, w3 );
  17912. v3[ 2 ] = interpolate( pa[ 2 ], pb[ 2 ], pc[ 2 ], pd[ 2 ], weight, w2, w3 );
  17913. return v3;
  17914. };
  17915. var interpolate = function ( p0, p1, p2, p3, t, t2, t3 ) {
  17916. var v0 = ( p2 - p0 ) * 0.5,
  17917. v1 = ( p3 - p1 ) * 0.5;
  17918. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  17919. };
  17920. return function ( delta ) {
  17921. if ( this.isPlaying === false ) return;
  17922. this.currentTime += delta * this.timeScale;
  17923. if ( this.weight === 0 )
  17924. return;
  17925. //
  17926. var duration = this.data.length;
  17927. if ( this.currentTime > duration || this.currentTime < 0 ) {
  17928. if ( this.loop ) {
  17929. this.currentTime %= duration;
  17930. if ( this.currentTime < 0 )
  17931. this.currentTime += duration;
  17932. this.reset();
  17933. } else {
  17934. this.stop();
  17935. }
  17936. }
  17937. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  17938. var object = this.hierarchy[ h ];
  17939. var animationCache = object.animationCache.animations[this.data.name];
  17940. var blending = object.animationCache.blending;
  17941. // loop through pos/rot/scl
  17942. for ( var t = 0; t < 3; t ++ ) {
  17943. // get keys
  17944. var type = this.keyTypes[ t ];
  17945. var prevKey = animationCache.prevKey[ type ];
  17946. var nextKey = animationCache.nextKey[ type ];
  17947. if ( ( this.timeScale > 0 && nextKey.time <= this.currentTime ) ||
  17948. ( this.timeScale < 0 && prevKey.time >= this.currentTime ) ) {
  17949. prevKey = this.data.hierarchy[ h ].keys[ 0 ];
  17950. nextKey = this.getNextKeyWith( type, h, 1 );
  17951. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  17952. prevKey = nextKey;
  17953. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  17954. }
  17955. animationCache.prevKey[ type ] = prevKey;
  17956. animationCache.nextKey[ type ] = nextKey;
  17957. }
  17958. var scale = ( this.currentTime - prevKey.time ) / ( nextKey.time - prevKey.time );
  17959. var prevXYZ = prevKey[ type ];
  17960. var nextXYZ = nextKey[ type ];
  17961. if ( scale < 0 ) scale = 0;
  17962. if ( scale > 1 ) scale = 1;
  17963. // interpolate
  17964. if ( type === "pos" ) {
  17965. if ( this.interpolationType === THREE.AnimationHandler.LINEAR ) {
  17966. newVector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  17967. newVector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  17968. newVector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  17969. // blend
  17970. var proportionalWeight = this.weight / ( this.weight + blending.positionWeight );
  17971. object.position.lerp( newVector, proportionalWeight );
  17972. blending.positionWeight += this.weight;
  17973. } else if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  17974. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  17975. points[ 0 ] = this.getPrevKeyWith( "pos", h, prevKey.index - 1 )[ "pos" ];
  17976. points[ 1 ] = prevXYZ;
  17977. points[ 2 ] = nextXYZ;
  17978. points[ 3 ] = this.getNextKeyWith( "pos", h, nextKey.index + 1 )[ "pos" ];
  17979. scale = scale * 0.33 + 0.33;
  17980. var currentPoint = interpolateCatmullRom( points, scale );
  17981. var proportionalWeight = this.weight / ( this.weight + blending.positionWeight );
  17982. blending.positionWeight += this.weight;
  17983. // blend
  17984. var vector = object.position;
  17985. vector.x = vector.x + ( currentPoint[ 0 ] - vector.x ) * proportionalWeight;
  17986. vector.y = vector.y + ( currentPoint[ 1 ] - vector.y ) * proportionalWeight;
  17987. vector.z = vector.z + ( currentPoint[ 2 ] - vector.z ) * proportionalWeight;
  17988. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  17989. var forwardPoint = interpolateCatmullRom( points, scale * 1.01 );
  17990. target.set( forwardPoint[ 0 ], forwardPoint[ 1 ], forwardPoint[ 2 ] );
  17991. target.sub( vector );
  17992. target.y = 0;
  17993. target.normalize();
  17994. var angle = Math.atan2( target.x, target.z );
  17995. object.rotation.set( 0, angle, 0 );
  17996. }
  17997. }
  17998. } else if ( type === "rot" ) {
  17999. THREE.Quaternion.slerp( prevXYZ, nextXYZ, newQuat, scale );
  18000. // Avoid paying the cost of an additional slerp if we don't have to
  18001. if ( blending.quaternionWeight === 0 ) {
  18002. object.quaternion.copy(newQuat);
  18003. blending.quaternionWeight = this.weight;
  18004. } else {
  18005. var proportionalWeight = this.weight / ( this.weight + blending.quaternionWeight );
  18006. THREE.Quaternion.slerp( object.quaternion, newQuat, object.quaternion, proportionalWeight );
  18007. blending.quaternionWeight += this.weight;
  18008. }
  18009. } else if ( type === "scl" ) {
  18010. newVector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  18011. newVector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  18012. newVector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  18013. var proportionalWeight = this.weight / ( this.weight + blending.scaleWeight );
  18014. object.scale.lerp( newVector, proportionalWeight );
  18015. blending.scaleWeight += this.weight;
  18016. }
  18017. }
  18018. }
  18019. return true;
  18020. };
  18021. } )(),
  18022. getNextKeyWith: function ( type, h, key ) {
  18023. var keys = this.data.hierarchy[ h ].keys;
  18024. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18025. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18026. key = key < keys.length - 1 ? key : keys.length - 1;
  18027. } else {
  18028. key = key % keys.length;
  18029. }
  18030. for ( ; key < keys.length; key ++ ) {
  18031. if ( keys[ key ][ type ] !== undefined ) {
  18032. return keys[ key ];
  18033. }
  18034. }
  18035. return this.data.hierarchy[ h ].keys[ 0 ];
  18036. },
  18037. getPrevKeyWith: function ( type, h, key ) {
  18038. var keys = this.data.hierarchy[ h ].keys;
  18039. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18040. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18041. key = key > 0 ? key : 0;
  18042. } else {
  18043. key = key >= 0 ? key : key + keys.length;
  18044. }
  18045. for ( ; key >= 0; key -- ) {
  18046. if ( keys[ key ][ type ] !== undefined ) {
  18047. return keys[ key ];
  18048. }
  18049. }
  18050. return this.data.hierarchy[ h ].keys[ keys.length - 1 ];
  18051. }
  18052. };
  18053. // File:src/extras/animation/KeyFrameAnimation.js
  18054. /**
  18055. * @author mikael emtinger / http://gomo.se/
  18056. * @author mrdoob / http://mrdoob.com/
  18057. * @author alteredq / http://alteredqualia.com/
  18058. * @author khang duong
  18059. * @author erik kitson
  18060. */
  18061. THREE.KeyFrameAnimation = function ( data ) {
  18062. this.root = data.node;
  18063. this.data = THREE.AnimationHandler.init( data );
  18064. this.hierarchy = THREE.AnimationHandler.parse( this.root );
  18065. this.currentTime = 0;
  18066. this.timeScale = 0.001;
  18067. this.isPlaying = false;
  18068. this.isPaused = true;
  18069. this.loop = true;
  18070. // initialize to first keyframes
  18071. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18072. var keys = this.data.hierarchy[h].keys,
  18073. sids = this.data.hierarchy[h].sids,
  18074. obj = this.hierarchy[h];
  18075. if ( keys.length && sids ) {
  18076. for ( var s = 0; s < sids.length; s ++ ) {
  18077. var sid = sids[ s ],
  18078. next = this.getNextKeyWith( sid, h, 0 );
  18079. if ( next ) {
  18080. next.apply( sid );
  18081. }
  18082. }
  18083. obj.matrixAutoUpdate = false;
  18084. this.data.hierarchy[h].node.updateMatrix();
  18085. obj.matrixWorldNeedsUpdate = true;
  18086. }
  18087. }
  18088. };
  18089. THREE.KeyFrameAnimation.prototype = {
  18090. constructor: THREE.KeyFrameAnimation,
  18091. play: function ( startTime ) {
  18092. this.currentTime = startTime !== undefined ? startTime : 0;
  18093. if ( this.isPlaying === false ) {
  18094. this.isPlaying = true;
  18095. // reset key cache
  18096. var h, hl = this.hierarchy.length,
  18097. object,
  18098. node;
  18099. for ( h = 0; h < hl; h ++ ) {
  18100. object = this.hierarchy[ h ];
  18101. node = this.data.hierarchy[ h ];
  18102. if ( node.animationCache === undefined ) {
  18103. node.animationCache = {};
  18104. node.animationCache.prevKey = null;
  18105. node.animationCache.nextKey = null;
  18106. node.animationCache.originalMatrix = object.matrix;
  18107. }
  18108. var keys = this.data.hierarchy[h].keys;
  18109. if (keys.length) {
  18110. node.animationCache.prevKey = keys[ 0 ];
  18111. node.animationCache.nextKey = keys[ 1 ];
  18112. this.startTime = Math.min( keys[0].time, this.startTime );
  18113. this.endTime = Math.max( keys[keys.length - 1].time, this.endTime );
  18114. }
  18115. }
  18116. this.update( 0 );
  18117. }
  18118. this.isPaused = false;
  18119. THREE.AnimationHandler.play( this );
  18120. },
  18121. stop: function () {
  18122. this.isPlaying = false;
  18123. this.isPaused = false;
  18124. THREE.AnimationHandler.stop( this );
  18125. // reset JIT matrix and remove cache
  18126. for ( var h = 0; h < this.data.hierarchy.length; h ++ ) {
  18127. var obj = this.hierarchy[ h ];
  18128. var node = this.data.hierarchy[ h ];
  18129. if ( node.animationCache !== undefined ) {
  18130. var original = node.animationCache.originalMatrix;
  18131. original.copy( obj.matrix );
  18132. obj.matrix = original;
  18133. delete node.animationCache;
  18134. }
  18135. }
  18136. },
  18137. update: function ( delta ) {
  18138. if ( this.isPlaying === false ) return;
  18139. this.currentTime += delta * this.timeScale;
  18140. //
  18141. var duration = this.data.length;
  18142. if ( this.loop === true && this.currentTime > duration ) {
  18143. this.currentTime %= duration;
  18144. }
  18145. this.currentTime = Math.min( this.currentTime, duration );
  18146. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18147. var object = this.hierarchy[ h ];
  18148. var node = this.data.hierarchy[ h ];
  18149. var keys = node.keys,
  18150. animationCache = node.animationCache;
  18151. if ( keys.length ) {
  18152. var prevKey = animationCache.prevKey;
  18153. var nextKey = animationCache.nextKey;
  18154. if ( nextKey.time <= this.currentTime ) {
  18155. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  18156. prevKey = nextKey;
  18157. nextKey = keys[ prevKey.index + 1 ];
  18158. }
  18159. animationCache.prevKey = prevKey;
  18160. animationCache.nextKey = nextKey;
  18161. }
  18162. if ( nextKey.time >= this.currentTime ) {
  18163. prevKey.interpolate( nextKey, this.currentTime );
  18164. } else {
  18165. prevKey.interpolate( nextKey, nextKey.time );
  18166. }
  18167. this.data.hierarchy[ h ].node.updateMatrix();
  18168. object.matrixWorldNeedsUpdate = true;
  18169. }
  18170. }
  18171. },
  18172. getNextKeyWith: function ( sid, h, key ) {
  18173. var keys = this.data.hierarchy[ h ].keys;
  18174. key = key % keys.length;
  18175. for ( ; key < keys.length; key ++ ) {
  18176. if ( keys[ key ].hasTarget( sid ) ) {
  18177. return keys[ key ];
  18178. }
  18179. }
  18180. return keys[ 0 ];
  18181. },
  18182. getPrevKeyWith: function ( sid, h, key ) {
  18183. var keys = this.data.hierarchy[ h ].keys;
  18184. key = key >= 0 ? key : key + keys.length;
  18185. for ( ; key >= 0; key -- ) {
  18186. if ( keys[ key ].hasTarget( sid ) ) {
  18187. return keys[ key ];
  18188. }
  18189. }
  18190. return keys[ keys.length - 1 ];
  18191. }
  18192. };
  18193. // File:src/extras/animation/MorphAnimation.js
  18194. /**
  18195. * @author mrdoob / http://mrdoob.com
  18196. * @author willy-vvu / http://willy-vvu.github.io
  18197. */
  18198. THREE.MorphAnimation = function ( mesh ) {
  18199. this.mesh = mesh;
  18200. this.frames = mesh.morphTargetInfluences.length;
  18201. this.currentTime = 0;
  18202. this.duration = 1000;
  18203. this.loop = true;
  18204. this.lastFrame = 0;
  18205. this.currentFrame = 0;
  18206. this.isPlaying = false;
  18207. };
  18208. THREE.MorphAnimation.prototype = {
  18209. constructor: THREE.MorphAnimation,
  18210. play: function () {
  18211. this.isPlaying = true;
  18212. },
  18213. pause: function () {
  18214. this.isPlaying = false;
  18215. },
  18216. update: function ( delta ) {
  18217. if ( this.isPlaying === false ) return;
  18218. this.currentTime += delta;
  18219. if ( this.loop === true && this.currentTime > this.duration ) {
  18220. this.currentTime %= this.duration;
  18221. }
  18222. this.currentTime = Math.min( this.currentTime, this.duration );
  18223. var interpolation = this.duration / this.frames;
  18224. var frame = Math.floor( this.currentTime / interpolation );
  18225. var influences = this.mesh.morphTargetInfluences;
  18226. if ( frame !== this.currentFrame ) {
  18227. influences[ this.lastFrame ] = 0;
  18228. influences[ this.currentFrame ] = 1;
  18229. influences[ frame ] = 0;
  18230. this.lastFrame = this.currentFrame;
  18231. this.currentFrame = frame;
  18232. }
  18233. influences[ frame ] = ( this.currentTime % interpolation ) / interpolation;
  18234. influences[ this.lastFrame ] = 1 - influences[ frame ];
  18235. }
  18236. };
  18237. // File:src/extras/geometries/BoxGeometry.js
  18238. /**
  18239. * @author mrdoob / http://mrdoob.com/
  18240. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  18241. */
  18242. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  18243. THREE.Geometry.call( this );
  18244. this.type = 'BoxGeometry';
  18245. this.parameters = {
  18246. width: width,
  18247. height: height,
  18248. depth: depth,
  18249. widthSegments: widthSegments,
  18250. heightSegments: heightSegments,
  18251. depthSegments: depthSegments
  18252. };
  18253. this.widthSegments = widthSegments || 1;
  18254. this.heightSegments = heightSegments || 1;
  18255. this.depthSegments = depthSegments || 1;
  18256. var scope = this;
  18257. var width_half = width / 2;
  18258. var height_half = height / 2;
  18259. var depth_half = depth / 2;
  18260. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half ); // px
  18261. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half ); // nx
  18262. buildPlane( 'x', 'z', 1, 1, width, depth, height_half ); // py
  18263. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half ); // ny
  18264. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half ); // pz
  18265. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half ); // nz
  18266. function buildPlane( u, v, udir, vdir, width, height, depth ) {
  18267. var w, ix, iy,
  18268. gridX = scope.widthSegments,
  18269. gridY = scope.heightSegments,
  18270. width_half = width / 2,
  18271. height_half = height / 2,
  18272. offset = scope.vertices.length;
  18273. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  18274. w = 'z';
  18275. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  18276. w = 'y';
  18277. gridY = scope.depthSegments;
  18278. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  18279. w = 'x';
  18280. gridX = scope.depthSegments;
  18281. }
  18282. var gridX1 = gridX + 1,
  18283. gridY1 = gridY + 1,
  18284. segment_width = width / gridX,
  18285. segment_height = height / gridY,
  18286. normal = new THREE.Vector3();
  18287. normal[ w ] = depth > 0 ? 1 : - 1;
  18288. for ( iy = 0; iy < gridY1; iy ++ ) {
  18289. for ( ix = 0; ix < gridX1; ix ++ ) {
  18290. var vector = new THREE.Vector3();
  18291. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  18292. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  18293. vector[ w ] = depth;
  18294. scope.vertices.push( vector );
  18295. }
  18296. }
  18297. for ( iy = 0; iy < gridY; iy ++ ) {
  18298. for ( ix = 0; ix < gridX; ix ++ ) {
  18299. var a = ix + gridX1 * iy;
  18300. var b = ix + gridX1 * ( iy + 1 );
  18301. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  18302. var d = ( ix + 1 ) + gridX1 * iy;
  18303. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  18304. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  18305. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  18306. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  18307. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  18308. face.normal.copy( normal );
  18309. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18310. scope.faces.push( face );
  18311. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  18312. face = new THREE.Face3( b + offset, c + offset, d + offset );
  18313. face.normal.copy( normal );
  18314. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18315. scope.faces.push( face );
  18316. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  18317. }
  18318. }
  18319. }
  18320. this.mergeVertices();
  18321. };
  18322. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18323. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  18324. THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
  18325. // File:src/extras/geometries/CircleGeometry.js
  18326. /**
  18327. * @author hughes
  18328. */
  18329. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18330. THREE.Geometry.call( this );
  18331. this.type = 'CircleGeometry';
  18332. this.parameters = {
  18333. radius: radius,
  18334. segments: segments,
  18335. thetaStart: thetaStart,
  18336. thetaLength: thetaLength
  18337. };
  18338. radius = radius || 50;
  18339. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18340. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18341. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18342. var i, uvs = [],
  18343. center = new THREE.Vector3(), centerUV = new THREE.Vector2( 0.5, 0.5 );
  18344. this.vertices.push(center);
  18345. uvs.push( centerUV );
  18346. for ( i = 0; i <= segments; i ++ ) {
  18347. var vertex = new THREE.Vector3();
  18348. var segment = thetaStart + i / segments * thetaLength;
  18349. vertex.x = radius * Math.cos( segment );
  18350. vertex.y = radius * Math.sin( segment );
  18351. this.vertices.push( vertex );
  18352. uvs.push( new THREE.Vector2( ( vertex.x / radius + 1 ) / 2, ( vertex.y / radius + 1 ) / 2 ) );
  18353. }
  18354. var n = new THREE.Vector3( 0, 0, 1 );
  18355. for ( i = 1; i <= segments; i ++ ) {
  18356. this.faces.push( new THREE.Face3( i, i + 1, 0, [ n.clone(), n.clone(), n.clone() ] ) );
  18357. this.faceVertexUvs[ 0 ].push( [ uvs[ i ].clone(), uvs[ i + 1 ].clone(), centerUV.clone() ] );
  18358. }
  18359. this.computeFaceNormals();
  18360. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18361. };
  18362. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18363. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  18364. // File:src/extras/geometries/CircleBufferGeometry.js
  18365. /**
  18366. * @author benaadams / https://twitter.com/ben_a_adams
  18367. */
  18368. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18369. THREE.BufferGeometry.call( this );
  18370. this.type = 'CircleBufferGeometry';
  18371. this.parameters = {
  18372. radius: radius,
  18373. segments: segments,
  18374. thetaStart: thetaStart,
  18375. thetaLength: thetaLength
  18376. };
  18377. radius = radius || 50;
  18378. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18379. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18380. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18381. var vertices = segments + 2;
  18382. var positions = new Float32Array( vertices * 3 );
  18383. var normals = new Float32Array( vertices * 3 );
  18384. var uvs = new Float32Array( vertices * 2 );
  18385. // center data is already zero, but need to set a few extras
  18386. normals[3] = 1.0;
  18387. uvs[0] = 0.5;
  18388. uvs[1] = 0.5;
  18389. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s++, i += 3, ii += 2 ) {
  18390. var segment = thetaStart + s / segments * thetaLength;
  18391. positions[i] = radius * Math.cos( segment );
  18392. positions[i + 1] = radius * Math.sin( segment );
  18393. normals[i + 2] = 1; // normal z
  18394. uvs[ii] = ( positions[i] / radius + 1 ) / 2;
  18395. uvs[ii + 1] = ( positions[i + 1] / radius + 1 ) / 2;
  18396. }
  18397. var indices = [];
  18398. for ( var i = 1; i <= segments; i ++ ) {
  18399. indices.push( i );
  18400. indices.push( i + 1 );
  18401. indices.push( 0 );
  18402. }
  18403. this.addAttribute( 'index', new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  18404. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  18405. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  18406. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  18407. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18408. };
  18409. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18410. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  18411. // File:src/extras/geometries/CylinderGeometry.js
  18412. /**
  18413. * @author mrdoob / http://mrdoob.com/
  18414. */
  18415. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18416. THREE.Geometry.call( this );
  18417. this.type = 'CylinderGeometry';
  18418. this.parameters = {
  18419. radiusTop: radiusTop,
  18420. radiusBottom: radiusBottom,
  18421. height: height,
  18422. radialSegments: radialSegments,
  18423. heightSegments: heightSegments,
  18424. openEnded: openEnded,
  18425. thetaStart: thetaStart,
  18426. thetaLength: thetaLength
  18427. };
  18428. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  18429. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  18430. height = height !== undefined ? height : 100;
  18431. radialSegments = radialSegments || 8;
  18432. heightSegments = heightSegments || 1;
  18433. openEnded = openEnded !== undefined ? openEnded : false;
  18434. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18435. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  18436. var heightHalf = height / 2;
  18437. var x, y, vertices = [], uvs = [];
  18438. for ( y = 0; y <= heightSegments; y ++ ) {
  18439. var verticesRow = [];
  18440. var uvsRow = [];
  18441. var v = y / heightSegments;
  18442. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18443. for ( x = 0; x <= radialSegments; x ++ ) {
  18444. var u = x / radialSegments;
  18445. var vertex = new THREE.Vector3();
  18446. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  18447. vertex.y = - v * height + heightHalf;
  18448. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  18449. this.vertices.push( vertex );
  18450. verticesRow.push( this.vertices.length - 1 );
  18451. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  18452. }
  18453. vertices.push( verticesRow );
  18454. uvs.push( uvsRow );
  18455. }
  18456. var tanTheta = ( radiusBottom - radiusTop ) / height;
  18457. var na, nb;
  18458. for ( x = 0; x < radialSegments; x ++ ) {
  18459. if ( radiusTop !== 0 ) {
  18460. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  18461. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  18462. } else {
  18463. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  18464. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  18465. }
  18466. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  18467. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  18468. for ( y = 0; y < heightSegments; y ++ ) {
  18469. var v1 = vertices[ y ][ x ];
  18470. var v2 = vertices[ y + 1 ][ x ];
  18471. var v3 = vertices[ y + 1 ][ x + 1 ];
  18472. var v4 = vertices[ y ][ x + 1 ];
  18473. var n1 = na.clone();
  18474. var n2 = na.clone();
  18475. var n3 = nb.clone();
  18476. var n4 = nb.clone();
  18477. var uv1 = uvs[ y ][ x ].clone();
  18478. var uv2 = uvs[ y + 1 ][ x ].clone();
  18479. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  18480. var uv4 = uvs[ y ][ x + 1 ].clone();
  18481. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  18482. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  18483. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  18484. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  18485. }
  18486. }
  18487. // top cap
  18488. if ( openEnded === false && radiusTop > 0 ) {
  18489. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  18490. for ( x = 0; x < radialSegments; x ++ ) {
  18491. var v1 = vertices[ 0 ][ x ];
  18492. var v2 = vertices[ 0 ][ x + 1 ];
  18493. var v3 = this.vertices.length - 1;
  18494. var n1 = new THREE.Vector3( 0, 1, 0 );
  18495. var n2 = new THREE.Vector3( 0, 1, 0 );
  18496. var n3 = new THREE.Vector3( 0, 1, 0 );
  18497. var uv1 = uvs[ 0 ][ x ].clone();
  18498. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  18499. var uv3 = new THREE.Vector2( uv2.x, 0 );
  18500. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  18501. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18502. }
  18503. }
  18504. // bottom cap
  18505. if ( openEnded === false && radiusBottom > 0 ) {
  18506. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  18507. for ( x = 0; x < radialSegments; x ++ ) {
  18508. var v1 = vertices[ heightSegments ][ x + 1 ];
  18509. var v2 = vertices[ heightSegments ][ x ];
  18510. var v3 = this.vertices.length - 1;
  18511. var n1 = new THREE.Vector3( 0, - 1, 0 );
  18512. var n2 = new THREE.Vector3( 0, - 1, 0 );
  18513. var n3 = new THREE.Vector3( 0, - 1, 0 );
  18514. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  18515. var uv2 = uvs[ heightSegments ][ x ].clone();
  18516. var uv3 = new THREE.Vector2( uv2.x, 1 );
  18517. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  18518. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18519. }
  18520. }
  18521. this.computeFaceNormals();
  18522. };
  18523. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18524. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  18525. // File:src/extras/geometries/EdgesGeometry.js
  18526. /**
  18527. * @author WestLangley / http://github.com/WestLangley
  18528. */
  18529. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  18530. THREE.BufferGeometry.call( this );
  18531. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18532. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  18533. var edge = [ 0, 0 ], hash = {};
  18534. var sortFunction = function ( a, b ) { return a - b };
  18535. var keys = [ 'a', 'b', 'c' ];
  18536. var geometry2;
  18537. if ( geometry instanceof THREE.BufferGeometry ) {
  18538. geometry2 = new THREE.Geometry();
  18539. geometry2.fromBufferGeometry( geometry );
  18540. } else {
  18541. geometry2 = geometry.clone();
  18542. }
  18543. geometry2.mergeVertices();
  18544. geometry2.computeFaceNormals();
  18545. var vertices = geometry2.vertices;
  18546. var faces = geometry2.faces;
  18547. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18548. var face = faces[ i ];
  18549. for ( var j = 0; j < 3; j ++ ) {
  18550. edge[ 0 ] = face[ keys[ j ] ];
  18551. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  18552. edge.sort( sortFunction );
  18553. var key = edge.toString();
  18554. if ( hash[ key ] === undefined ) {
  18555. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  18556. } else {
  18557. hash[ key ].face2 = i;
  18558. }
  18559. }
  18560. }
  18561. var coords = [];
  18562. for ( var key in hash ) {
  18563. var h = hash[ key ];
  18564. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  18565. var vertex = vertices[ h.vert1 ];
  18566. coords.push( vertex.x );
  18567. coords.push( vertex.y );
  18568. coords.push( vertex.z );
  18569. vertex = vertices[ h.vert2 ];
  18570. coords.push( vertex.x );
  18571. coords.push( vertex.y );
  18572. coords.push( vertex.z );
  18573. }
  18574. }
  18575. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  18576. };
  18577. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18578. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  18579. // File:src/extras/geometries/ExtrudeGeometry.js
  18580. /**
  18581. * @author zz85 / http://www.lab4games.net/zz85/blog
  18582. *
  18583. * Creates extruded geometry from a path shape.
  18584. *
  18585. * parameters = {
  18586. *
  18587. * curveSegments: <int>, // number of points on the curves
  18588. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  18589. * amount: <int>, // Depth to extrude the shape
  18590. *
  18591. * bevelEnabled: <bool>, // turn on bevel
  18592. * bevelThickness: <float>, // how deep into the original shape bevel goes
  18593. * bevelSize: <float>, // how far from shape outline is bevel
  18594. * bevelSegments: <int>, // number of bevel layers
  18595. *
  18596. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  18597. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  18598. *
  18599. * uvGenerator: <Object> // object that provides UV generator functions
  18600. *
  18601. * }
  18602. **/
  18603. THREE.ExtrudeGeometry = function ( shapes, options ) {
  18604. if ( typeof( shapes ) === "undefined" ) {
  18605. shapes = [];
  18606. return;
  18607. }
  18608. THREE.Geometry.call( this );
  18609. this.type = 'ExtrudeGeometry';
  18610. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  18611. this.addShapeList( shapes, options );
  18612. this.computeFaceNormals();
  18613. // can't really use automatic vertex normals
  18614. // as then front and back sides get smoothed too
  18615. // should do separate smoothing just for sides
  18616. //this.computeVertexNormals();
  18617. //console.log( "took", ( Date.now() - startTime ) );
  18618. };
  18619. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18620. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  18621. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  18622. var sl = shapes.length;
  18623. for ( var s = 0; s < sl; s ++ ) {
  18624. var shape = shapes[ s ];
  18625. this.addShape( shape, options );
  18626. }
  18627. };
  18628. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  18629. var amount = options.amount !== undefined ? options.amount : 100;
  18630. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  18631. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  18632. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18633. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  18634. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18635. var steps = options.steps !== undefined ? options.steps : 1;
  18636. var extrudePath = options.extrudePath;
  18637. var extrudePts, extrudeByPath = false;
  18638. // Use default WorldUVGenerator if no UV generators are specified.
  18639. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  18640. var splineTube, binormal, normal, position2;
  18641. if ( extrudePath ) {
  18642. extrudePts = extrudePath.getSpacedPoints( steps );
  18643. extrudeByPath = true;
  18644. bevelEnabled = false; // bevels not supported for path extrusion
  18645. // SETUP TNB variables
  18646. // Reuse TNB from TubeGeomtry for now.
  18647. // TODO1 - have a .isClosed in spline?
  18648. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames(extrudePath, steps, false);
  18649. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18650. binormal = new THREE.Vector3();
  18651. normal = new THREE.Vector3();
  18652. position2 = new THREE.Vector3();
  18653. }
  18654. // Safeguards if bevels are not enabled
  18655. if ( ! bevelEnabled ) {
  18656. bevelSegments = 0;
  18657. bevelThickness = 0;
  18658. bevelSize = 0;
  18659. }
  18660. // Variables initialization
  18661. var ahole, h, hl; // looping of holes
  18662. var scope = this;
  18663. var shapesOffset = this.vertices.length;
  18664. var shapePoints = shape.extractPoints( curveSegments );
  18665. var vertices = shapePoints.shape;
  18666. var holes = shapePoints.holes;
  18667. var reverse = ! THREE.Shape.Utils.isClockWise( vertices ) ;
  18668. if ( reverse ) {
  18669. vertices = vertices.reverse();
  18670. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18671. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18672. ahole = holes[ h ];
  18673. if ( THREE.Shape.Utils.isClockWise( ahole ) ) {
  18674. holes[ h ] = ahole.reverse();
  18675. }
  18676. }
  18677. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  18678. }
  18679. var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
  18680. /* Vertices */
  18681. var contour = vertices; // vertices has all points but contour has only points of circumference
  18682. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18683. ahole = holes[ h ];
  18684. vertices = vertices.concat( ahole );
  18685. }
  18686. function scalePt2 ( pt, vec, size ) {
  18687. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  18688. return vec.clone().multiplyScalar( size ).add( pt );
  18689. }
  18690. var b, bs, t, z,
  18691. vert, vlen = vertices.length,
  18692. face, flen = faces.length;
  18693. // Find directions for point movement
  18694. function getBevelVec( inPt, inPrev, inNext ) {
  18695. var EPSILON = 0.0000000001;
  18696. // computes for inPt the corresponding point inPt' on a new contour
  18697. // shifted by 1 unit (length of normalized vector) to the left
  18698. // if we walk along contour clockwise, this new contour is outside the old one
  18699. //
  18700. // inPt' is the intersection of the two lines parallel to the two
  18701. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18702. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  18703. // good reading for geometry algorithms (here: line-line intersection)
  18704. // http://geomalgorithms.com/a05-_intersect-1.html
  18705. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  18706. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  18707. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  18708. // check for collinear edges
  18709. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18710. if ( Math.abs( collinear0 ) > EPSILON ) { // not collinear
  18711. // length of vectors for normalizing
  18712. var v_prev_len = Math.sqrt( v_prev_lensq );
  18713. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  18714. // shift adjacent points by unit vectors to the left
  18715. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  18716. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  18717. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  18718. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  18719. // scaling factor for v_prev to intersection point
  18720. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  18721. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  18722. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18723. // vector from inPt to intersection point
  18724. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  18725. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  18726. // Don't normalize!, otherwise sharp corners become ugly
  18727. // but prevent crazy spikes
  18728. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  18729. if ( v_trans_lensq <= 2 ) {
  18730. return new THREE.Vector2( v_trans_x, v_trans_y );
  18731. } else {
  18732. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  18733. }
  18734. } else { // handle special case of collinear edges
  18735. var direction_eq = false; // assumes: opposite
  18736. if ( v_prev_x > EPSILON ) {
  18737. if ( v_next_x > EPSILON ) { direction_eq = true; }
  18738. } else {
  18739. if ( v_prev_x < - EPSILON ) {
  18740. if ( v_next_x < - EPSILON ) { direction_eq = true; }
  18741. } else {
  18742. if ( Math.sign(v_prev_y) === Math.sign(v_next_y) ) { direction_eq = true; }
  18743. }
  18744. }
  18745. if ( direction_eq ) {
  18746. // console.log("Warning: lines are a straight sequence");
  18747. v_trans_x = - v_prev_y;
  18748. v_trans_y = v_prev_x;
  18749. shrink_by = Math.sqrt( v_prev_lensq );
  18750. } else {
  18751. // console.log("Warning: lines are a straight spike");
  18752. v_trans_x = v_prev_x;
  18753. v_trans_y = v_prev_y;
  18754. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  18755. }
  18756. }
  18757. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  18758. }
  18759. var contourMovements = [];
  18760. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18761. if ( j === il ) j = 0;
  18762. if ( k === il ) k = 0;
  18763. // (j)---(i)---(k)
  18764. // console.log('i,j,k', i, j , k)
  18765. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  18766. }
  18767. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  18768. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18769. ahole = holes[ h ];
  18770. oneHoleMovements = [];
  18771. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18772. if ( j === il ) j = 0;
  18773. if ( k === il ) k = 0;
  18774. // (j)---(i)---(k)
  18775. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  18776. }
  18777. holesMovements.push( oneHoleMovements );
  18778. verticesMovements = verticesMovements.concat( oneHoleMovements );
  18779. }
  18780. // Loop bevelSegments, 1 for the front, 1 for the back
  18781. for ( b = 0; b < bevelSegments; b ++ ) {
  18782. //for ( b = bevelSegments; b > 0; b -- ) {
  18783. t = b / bevelSegments;
  18784. z = bevelThickness * ( 1 - t );
  18785. //z = bevelThickness * t;
  18786. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ) ; // curved
  18787. //bs = bevelSize * t ; // linear
  18788. // contract shape
  18789. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18790. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18791. v( vert.x, vert.y, - z );
  18792. }
  18793. // expand holes
  18794. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18795. ahole = holes[ h ];
  18796. oneHoleMovements = holesMovements[ h ];
  18797. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18798. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18799. v( vert.x, vert.y, - z );
  18800. }
  18801. }
  18802. }
  18803. bs = bevelSize;
  18804. // Back facing vertices
  18805. for ( i = 0; i < vlen; i ++ ) {
  18806. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18807. if ( ! extrudeByPath ) {
  18808. v( vert.x, vert.y, 0 );
  18809. } else {
  18810. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18811. normal.copy( splineTube.normals[0] ).multiplyScalar(vert.x);
  18812. binormal.copy( splineTube.binormals[0] ).multiplyScalar(vert.y);
  18813. position2.copy( extrudePts[0] ).add(normal).add(binormal);
  18814. v( position2.x, position2.y, position2.z );
  18815. }
  18816. }
  18817. // Add stepped vertices...
  18818. // Including front facing vertices
  18819. var s;
  18820. for ( s = 1; s <= steps; s ++ ) {
  18821. for ( i = 0; i < vlen; i ++ ) {
  18822. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18823. if ( ! extrudeByPath ) {
  18824. v( vert.x, vert.y, amount / steps * s );
  18825. } else {
  18826. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18827. normal.copy( splineTube.normals[s] ).multiplyScalar( vert.x );
  18828. binormal.copy( splineTube.binormals[s] ).multiplyScalar( vert.y );
  18829. position2.copy( extrudePts[s] ).add( normal ).add( binormal );
  18830. v( position2.x, position2.y, position2.z );
  18831. }
  18832. }
  18833. }
  18834. // Add bevel segments planes
  18835. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18836. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  18837. t = b / bevelSegments;
  18838. z = bevelThickness * ( 1 - t );
  18839. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  18840. bs = bevelSize * Math.sin ( t * Math.PI / 2 ) ;
  18841. // contract shape
  18842. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18843. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18844. v( vert.x, vert.y, amount + z );
  18845. }
  18846. // expand holes
  18847. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18848. ahole = holes[ h ];
  18849. oneHoleMovements = holesMovements[ h ];
  18850. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18851. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18852. if ( ! extrudeByPath ) {
  18853. v( vert.x, vert.y, amount + z );
  18854. } else {
  18855. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  18856. }
  18857. }
  18858. }
  18859. }
  18860. /* Faces */
  18861. // Top and bottom faces
  18862. buildLidFaces();
  18863. // Sides faces
  18864. buildSideFaces();
  18865. ///// Internal functions
  18866. function buildLidFaces() {
  18867. if ( bevelEnabled ) {
  18868. var layer = 0 ; // steps + 1
  18869. var offset = vlen * layer;
  18870. // Bottom faces
  18871. for ( i = 0; i < flen; i ++ ) {
  18872. face = faces[ i ];
  18873. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  18874. }
  18875. layer = steps + bevelSegments * 2;
  18876. offset = vlen * layer;
  18877. // Top faces
  18878. for ( i = 0; i < flen; i ++ ) {
  18879. face = faces[ i ];
  18880. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  18881. }
  18882. } else {
  18883. // Bottom faces
  18884. for ( i = 0; i < flen; i ++ ) {
  18885. face = faces[ i ];
  18886. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  18887. }
  18888. // Top faces
  18889. for ( i = 0; i < flen; i ++ ) {
  18890. face = faces[ i ];
  18891. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  18892. }
  18893. }
  18894. }
  18895. // Create faces for the z-sides of the shape
  18896. function buildSideFaces() {
  18897. var layeroffset = 0;
  18898. sidewalls( contour, layeroffset );
  18899. layeroffset += contour.length;
  18900. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18901. ahole = holes[ h ];
  18902. sidewalls( ahole, layeroffset );
  18903. //, true
  18904. layeroffset += ahole.length;
  18905. }
  18906. }
  18907. function sidewalls( contour, layeroffset ) {
  18908. var j, k;
  18909. i = contour.length;
  18910. while ( -- i >= 0 ) {
  18911. j = i;
  18912. k = i - 1;
  18913. if ( k < 0 ) k = contour.length - 1;
  18914. //console.log('b', i,j, i-1, k,vertices.length);
  18915. var s = 0, sl = steps + bevelSegments * 2;
  18916. for ( s = 0; s < sl; s ++ ) {
  18917. var slen1 = vlen * s;
  18918. var slen2 = vlen * ( s + 1 );
  18919. var a = layeroffset + j + slen1,
  18920. b = layeroffset + k + slen1,
  18921. c = layeroffset + k + slen2,
  18922. d = layeroffset + j + slen2;
  18923. f4( a, b, c, d, contour, s, sl, j, k );
  18924. }
  18925. }
  18926. }
  18927. function v( x, y, z ) {
  18928. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  18929. }
  18930. function f3( a, b, c ) {
  18931. a += shapesOffset;
  18932. b += shapesOffset;
  18933. c += shapesOffset;
  18934. scope.faces.push( new THREE.Face3( a, b, c ) );
  18935. var uvs = uvgen.generateTopUV( scope, a, b, c );
  18936. scope.faceVertexUvs[ 0 ].push( uvs );
  18937. }
  18938. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  18939. a += shapesOffset;
  18940. b += shapesOffset;
  18941. c += shapesOffset;
  18942. d += shapesOffset;
  18943. scope.faces.push( new THREE.Face3( a, b, d ) );
  18944. scope.faces.push( new THREE.Face3( b, c, d ) );
  18945. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  18946. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  18947. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  18948. }
  18949. };
  18950. THREE.ExtrudeGeometry.WorldUVGenerator = {
  18951. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  18952. var vertices = geometry.vertices;
  18953. var a = vertices[ indexA ];
  18954. var b = vertices[ indexB ];
  18955. var c = vertices[ indexC ];
  18956. return [
  18957. new THREE.Vector2( a.x, a.y ),
  18958. new THREE.Vector2( b.x, b.y ),
  18959. new THREE.Vector2( c.x, c.y )
  18960. ];
  18961. },
  18962. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  18963. var vertices = geometry.vertices;
  18964. var a = vertices[ indexA ];
  18965. var b = vertices[ indexB ];
  18966. var c = vertices[ indexC ];
  18967. var d = vertices[ indexD ];
  18968. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  18969. return [
  18970. new THREE.Vector2( a.x, 1 - a.z ),
  18971. new THREE.Vector2( b.x, 1 - b.z ),
  18972. new THREE.Vector2( c.x, 1 - c.z ),
  18973. new THREE.Vector2( d.x, 1 - d.z )
  18974. ];
  18975. } else {
  18976. return [
  18977. new THREE.Vector2( a.y, 1 - a.z ),
  18978. new THREE.Vector2( b.y, 1 - b.z ),
  18979. new THREE.Vector2( c.y, 1 - c.z ),
  18980. new THREE.Vector2( d.y, 1 - d.z )
  18981. ];
  18982. }
  18983. }
  18984. };
  18985. // File:src/extras/geometries/ShapeGeometry.js
  18986. /**
  18987. * @author jonobr1 / http://jonobr1.com
  18988. *
  18989. * Creates a one-sided polygonal geometry from a path shape. Similar to
  18990. * ExtrudeGeometry.
  18991. *
  18992. * parameters = {
  18993. *
  18994. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  18995. *
  18996. * material: <int> // material index for front and back faces
  18997. * uvGenerator: <Object> // object that provides UV generator functions
  18998. *
  18999. * }
  19000. **/
  19001. THREE.ShapeGeometry = function ( shapes, options ) {
  19002. THREE.Geometry.call( this );
  19003. this.type = 'ShapeGeometry';
  19004. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  19005. this.addShapeList( shapes, options );
  19006. this.computeFaceNormals();
  19007. };
  19008. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19009. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  19010. /**
  19011. * Add an array of shapes to THREE.ShapeGeometry.
  19012. */
  19013. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19014. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19015. this.addShape( shapes[ i ], options );
  19016. }
  19017. return this;
  19018. };
  19019. /**
  19020. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  19021. */
  19022. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  19023. if ( options === undefined ) options = {};
  19024. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19025. var material = options.material;
  19026. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  19027. //
  19028. var i, l, hole;
  19029. var shapesOffset = this.vertices.length;
  19030. var shapePoints = shape.extractPoints( curveSegments );
  19031. var vertices = shapePoints.shape;
  19032. var holes = shapePoints.holes;
  19033. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  19034. if ( reverse ) {
  19035. vertices = vertices.reverse();
  19036. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  19037. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19038. hole = holes[ i ];
  19039. if ( THREE.Shape.Utils.isClockWise( hole ) ) {
  19040. holes[ i ] = hole.reverse();
  19041. }
  19042. }
  19043. reverse = false;
  19044. }
  19045. var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
  19046. // Vertices
  19047. var contour = vertices;
  19048. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19049. hole = holes[ i ];
  19050. vertices = vertices.concat( hole );
  19051. }
  19052. //
  19053. var vert, vlen = vertices.length;
  19054. var face, flen = faces.length;
  19055. for ( i = 0; i < vlen; i ++ ) {
  19056. vert = vertices[ i ];
  19057. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  19058. }
  19059. for ( i = 0; i < flen; i ++ ) {
  19060. face = faces[ i ];
  19061. var a = face[ 0 ] + shapesOffset;
  19062. var b = face[ 1 ] + shapesOffset;
  19063. var c = face[ 2 ] + shapesOffset;
  19064. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  19065. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  19066. }
  19067. };
  19068. // File:src/extras/geometries/LatheGeometry.js
  19069. /**
  19070. * @author astrodud / http://astrodud.isgreat.org/
  19071. * @author zz85 / https://github.com/zz85
  19072. * @author bhouston / http://exocortex.com
  19073. */
  19074. // points - to create a closed torus, one must use a set of points
  19075. // like so: [ a, b, c, d, a ], see first is the same as last.
  19076. // segments - the number of circumference segments to create
  19077. // phiStart - the starting radian
  19078. // phiLength - the radian (0 to 2*PI) range of the lathed section
  19079. // 2*pi is a closed lathe, less than 2PI is a portion.
  19080. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  19081. THREE.Geometry.call( this );
  19082. this.type = 'LatheGeometry';
  19083. this.parameters = {
  19084. points: points,
  19085. segments: segments,
  19086. phiStart: phiStart,
  19087. phiLength: phiLength
  19088. };
  19089. segments = segments || 12;
  19090. phiStart = phiStart || 0;
  19091. phiLength = phiLength || 2 * Math.PI;
  19092. var inversePointLength = 1.0 / ( points.length - 1 );
  19093. var inverseSegments = 1.0 / segments;
  19094. for ( var i = 0, il = segments; i <= il; i ++ ) {
  19095. var phi = phiStart + i * inverseSegments * phiLength;
  19096. var c = Math.cos( phi ),
  19097. s = Math.sin( phi );
  19098. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  19099. var pt = points[ j ];
  19100. var vertex = new THREE.Vector3();
  19101. vertex.x = c * pt.x - s * pt.y;
  19102. vertex.y = s * pt.x + c * pt.y;
  19103. vertex.z = pt.z;
  19104. this.vertices.push( vertex );
  19105. }
  19106. }
  19107. var np = points.length;
  19108. for ( var i = 0, il = segments; i < il; i ++ ) {
  19109. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  19110. var base = j + np * i;
  19111. var a = base;
  19112. var b = base + np;
  19113. var c = base + 1 + np;
  19114. var d = base + 1;
  19115. var u0 = i * inverseSegments;
  19116. var v0 = j * inversePointLength;
  19117. var u1 = u0 + inverseSegments;
  19118. var v1 = v0 + inversePointLength;
  19119. this.faces.push( new THREE.Face3( a, b, d ) );
  19120. this.faceVertexUvs[ 0 ].push( [
  19121. new THREE.Vector2( u0, v0 ),
  19122. new THREE.Vector2( u1, v0 ),
  19123. new THREE.Vector2( u0, v1 )
  19124. ] );
  19125. this.faces.push( new THREE.Face3( b, c, d ) );
  19126. this.faceVertexUvs[ 0 ].push( [
  19127. new THREE.Vector2( u1, v0 ),
  19128. new THREE.Vector2( u1, v1 ),
  19129. new THREE.Vector2( u0, v1 )
  19130. ] );
  19131. }
  19132. }
  19133. this.mergeVertices();
  19134. this.computeFaceNormals();
  19135. this.computeVertexNormals();
  19136. };
  19137. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19138. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  19139. // File:src/extras/geometries/PlaneGeometry.js
  19140. /**
  19141. * @author mrdoob / http://mrdoob.com/
  19142. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19143. */
  19144. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  19145. THREE.Geometry.call( this );
  19146. this.type = 'PlaneGeometry';
  19147. this.parameters = {
  19148. width: width,
  19149. height: height,
  19150. widthSegments: widthSegments,
  19151. heightSegments: heightSegments
  19152. };
  19153. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  19154. };
  19155. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19156. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  19157. // File:src/extras/geometries/PlaneBufferGeometry.js
  19158. /**
  19159. * @author mrdoob / http://mrdoob.com/
  19160. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19161. */
  19162. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  19163. THREE.BufferGeometry.call( this );
  19164. this.type = 'PlaneBufferGeometry';
  19165. this.parameters = {
  19166. width: width,
  19167. height: height,
  19168. widthSegments: widthSegments,
  19169. heightSegments: heightSegments
  19170. };
  19171. var width_half = width / 2;
  19172. var height_half = height / 2;
  19173. var gridX = Math.floor( widthSegments ) || 1;
  19174. var gridY = Math.floor( heightSegments ) || 1;
  19175. var gridX1 = gridX + 1;
  19176. var gridY1 = gridY + 1;
  19177. var segment_width = width / gridX;
  19178. var segment_height = height / gridY;
  19179. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  19180. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  19181. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  19182. var offset = 0;
  19183. var offset2 = 0;
  19184. for ( var iy = 0; iy < gridY1; iy ++ ) {
  19185. var y = iy * segment_height - height_half;
  19186. for ( var ix = 0; ix < gridX1; ix ++ ) {
  19187. var x = ix * segment_width - width_half;
  19188. vertices[ offset ] = x;
  19189. vertices[ offset + 1 ] = - y;
  19190. normals[ offset + 2 ] = 1;
  19191. uvs[ offset2 ] = ix / gridX;
  19192. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  19193. offset += 3;
  19194. offset2 += 2;
  19195. }
  19196. }
  19197. offset = 0;
  19198. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  19199. for ( var iy = 0; iy < gridY; iy ++ ) {
  19200. for ( var ix = 0; ix < gridX; ix ++ ) {
  19201. var a = ix + gridX1 * iy;
  19202. var b = ix + gridX1 * ( iy + 1 );
  19203. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  19204. var d = ( ix + 1 ) + gridX1 * iy;
  19205. indices[ offset ] = a;
  19206. indices[ offset + 1 ] = b;
  19207. indices[ offset + 2 ] = d;
  19208. indices[ offset + 3 ] = b;
  19209. indices[ offset + 4 ] = c;
  19210. indices[ offset + 5 ] = d;
  19211. offset += 6;
  19212. }
  19213. }
  19214. this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
  19215. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  19216. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  19217. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  19218. };
  19219. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19220. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  19221. // File:src/extras/geometries/RingGeometry.js
  19222. /**
  19223. * @author Kaleb Murphy
  19224. */
  19225. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  19226. THREE.Geometry.call( this );
  19227. this.type = 'RingGeometry';
  19228. this.parameters = {
  19229. innerRadius: innerRadius,
  19230. outerRadius: outerRadius,
  19231. thetaSegments: thetaSegments,
  19232. phiSegments: phiSegments,
  19233. thetaStart: thetaStart,
  19234. thetaLength: thetaLength
  19235. };
  19236. innerRadius = innerRadius || 0;
  19237. outerRadius = outerRadius || 50;
  19238. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19239. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19240. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  19241. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  19242. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  19243. for ( i = 0; i < phiSegments + 1; i ++ ) { // concentric circles inside ring
  19244. for ( o = 0; o < thetaSegments + 1; o ++ ) { // number of segments per circle
  19245. var vertex = new THREE.Vector3();
  19246. var segment = thetaStart + o / thetaSegments * thetaLength;
  19247. vertex.x = radius * Math.cos( segment );
  19248. vertex.y = radius * Math.sin( segment );
  19249. this.vertices.push( vertex );
  19250. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  19251. }
  19252. radius += radiusStep;
  19253. }
  19254. var n = new THREE.Vector3( 0, 0, 1 );
  19255. for ( i = 0; i < phiSegments; i ++ ) { // concentric circles inside ring
  19256. var thetaSegment = i * (thetaSegments + 1);
  19257. for ( o = 0; o < thetaSegments ; o ++ ) { // number of segments per circle
  19258. var segment = o + thetaSegment;
  19259. var v1 = segment;
  19260. var v2 = segment + thetaSegments + 1;
  19261. var v3 = segment + thetaSegments + 2;
  19262. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  19263. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ]);
  19264. v1 = segment;
  19265. v2 = segment + thetaSegments + 2;
  19266. v3 = segment + 1;
  19267. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  19268. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ]);
  19269. }
  19270. }
  19271. this.computeFaceNormals();
  19272. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19273. };
  19274. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19275. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  19276. // File:src/extras/geometries/SphereGeometry.js
  19277. /**
  19278. * @author mrdoob / http://mrdoob.com/
  19279. */
  19280. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19281. console.log( 'THREE.SphereGeometry: Consider using THREE.SphereBufferGeometry for lower memory footprint.' );
  19282. THREE.Geometry.call( this );
  19283. this.type = 'SphereGeometry';
  19284. this.parameters = {
  19285. radius: radius,
  19286. widthSegments: widthSegments,
  19287. heightSegments: heightSegments,
  19288. phiStart: phiStart,
  19289. phiLength: phiLength,
  19290. thetaStart: thetaStart,
  19291. thetaLength: thetaLength
  19292. };
  19293. radius = radius || 50;
  19294. widthSegments = Math.max( 2, Math.floor( widthSegments ) || 8 );
  19295. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19296. phiStart = phiStart !== undefined ? phiStart : 0;
  19297. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19298. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19299. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19300. var x, y, vertices = [], uvs = [];
  19301. for ( y = 0; y <= heightSegments; y ++ ) {
  19302. var verticesRow = [];
  19303. var uvsRow = [];
  19304. for ( x = 0; x <= widthSegments; x ++ ) {
  19305. var u = x / widthSegments;
  19306. var v = y / heightSegments;
  19307. var vertex = new THREE.Vector3();
  19308. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19309. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  19310. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19311. this.vertices.push( vertex );
  19312. verticesRow.push( this.vertices.length - 1 );
  19313. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  19314. }
  19315. vertices.push( verticesRow );
  19316. uvs.push( uvsRow );
  19317. }
  19318. for ( y = 0; y < heightSegments; y ++ ) {
  19319. for ( x = 0; x < widthSegments; x ++ ) {
  19320. var v1 = vertices[ y ][ x + 1 ];
  19321. var v2 = vertices[ y ][ x ];
  19322. var v3 = vertices[ y + 1 ][ x ];
  19323. var v4 = vertices[ y + 1 ][ x + 1 ];
  19324. var n1 = this.vertices[ v1 ].clone().normalize();
  19325. var n2 = this.vertices[ v2 ].clone().normalize();
  19326. var n3 = this.vertices[ v3 ].clone().normalize();
  19327. var n4 = this.vertices[ v4 ].clone().normalize();
  19328. var uv1 = uvs[ y ][ x + 1 ].clone();
  19329. var uv2 = uvs[ y ][ x ].clone();
  19330. var uv3 = uvs[ y + 1 ][ x ].clone();
  19331. var uv4 = uvs[ y + 1 ][ x + 1 ].clone();
  19332. if ( Math.abs( this.vertices[ v1 ].y ) === radius ) {
  19333. uv1.x = ( uv1.x + uv2.x ) / 2;
  19334. this.faces.push( new THREE.Face3( v1, v3, v4, [ n1, n3, n4 ] ) );
  19335. this.faceVertexUvs[ 0 ].push( [ uv1, uv3, uv4 ] );
  19336. } else if ( Math.abs( this.vertices[ v3 ].y ) === radius ) {
  19337. uv3.x = ( uv3.x + uv4.x ) / 2;
  19338. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  19339. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  19340. } else {
  19341. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  19342. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  19343. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  19344. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  19345. }
  19346. }
  19347. }
  19348. this.computeFaceNormals();
  19349. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19350. };
  19351. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19352. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  19353. // File:src/extras/geometries/SphereBufferGeometry.js
  19354. /**
  19355. * @author benaadams / https://twitter.com/ben_a_adams
  19356. * based on THREE.SphereGeometry
  19357. */
  19358. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19359. THREE.BufferGeometry.call( this );
  19360. this.type = 'SphereBufferGeometry';
  19361. this.parameters = {
  19362. radius: radius,
  19363. widthSegments: widthSegments,
  19364. heightSegments: heightSegments,
  19365. phiStart: phiStart,
  19366. phiLength: phiLength,
  19367. thetaStart: thetaStart,
  19368. thetaLength: thetaLength
  19369. };
  19370. radius = radius || 50;
  19371. widthSegments = Math.max( 2, Math.floor( widthSegments ) || 8 );
  19372. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19373. phiStart = phiStart !== undefined ? phiStart : 0;
  19374. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19375. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19376. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19377. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  19378. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  19379. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3);
  19380. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  19381. var index = 0, vertices = [], normal = new THREE.Vector3();
  19382. for ( var y = 0; y <= heightSegments; y ++ ) {
  19383. var verticesRow = [];
  19384. var v = y / heightSegments;
  19385. for ( var x = 0; x <= widthSegments; x ++ ) {
  19386. var u = x / widthSegments;
  19387. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19388. var py = radius * Math.cos( thetaStart + v * thetaLength );
  19389. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19390. normal.set( px, py, pz ).normalize();
  19391. positions.setXYZ( index, px, py, pz );
  19392. normals.setXYZ( index, normal.x, normal.y, normal.z );
  19393. uvs.setXY( index, u, 1 - v );
  19394. verticesRow.push( index );
  19395. index++;
  19396. }
  19397. vertices.push( verticesRow );
  19398. }
  19399. var indices = [];
  19400. for ( var y = 0; y < heightSegments; y ++ ) {
  19401. for ( var x = 0; x < widthSegments; x ++ ) {
  19402. var v1 = vertices[ y ][ x + 1 ];
  19403. var v2 = vertices[ y ][ x ];
  19404. var v3 = vertices[ y + 1 ][ x ];
  19405. var v4 = vertices[ y + 1 ][ x + 1 ];
  19406. if ( y !== 0 ) indices.push( v1, v2, v4 );
  19407. if ( y !== heightSegments - 1 ) indices.push( v2, v3, v4 );
  19408. }
  19409. }
  19410. this.addAttribute( 'index', new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  19411. this.addAttribute( 'position', positions );
  19412. this.addAttribute( 'normal', normals );
  19413. this.addAttribute( 'uv', uvs );
  19414. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19415. };
  19416. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19417. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  19418. // File:src/extras/geometries/TextGeometry.js
  19419. /**
  19420. * @author zz85 / http://www.lab4games.net/zz85/blog
  19421. * @author alteredq / http://alteredqualia.com/
  19422. *
  19423. * For creating 3D text geometry in three.js
  19424. *
  19425. * Text = 3D Text
  19426. *
  19427. * parameters = {
  19428. * size: <float>, // size of the text
  19429. * height: <float>, // thickness to extrude text
  19430. * curveSegments: <int>, // number of points on the curves
  19431. *
  19432. * font: <string>, // font name
  19433. * weight: <string>, // font weight (normal, bold)
  19434. * style: <string>, // font style (normal, italics)
  19435. *
  19436. * bevelEnabled: <bool>, // turn on bevel
  19437. * bevelThickness: <float>, // how deep into text bevel goes
  19438. * bevelSize: <float>, // how far from text outline is bevel
  19439. * }
  19440. *
  19441. */
  19442. /* Usage Examples
  19443. // TextGeometry wrapper
  19444. var text3d = new TextGeometry( text, options );
  19445. // Complete manner
  19446. var textShapes = THREE.FontUtils.generateShapes( text, options );
  19447. var text3d = new ExtrudeGeometry( textShapes, options );
  19448. */
  19449. THREE.TextGeometry = function ( text, parameters ) {
  19450. parameters = parameters || {};
  19451. var textShapes = THREE.FontUtils.generateShapes( text, parameters );
  19452. // translate parameters to ExtrudeGeometry API
  19453. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  19454. // defaults
  19455. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  19456. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  19457. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  19458. THREE.ExtrudeGeometry.call( this, textShapes, parameters );
  19459. this.type = 'TextGeometry';
  19460. };
  19461. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  19462. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  19463. // File:src/extras/geometries/TorusGeometry.js
  19464. /**
  19465. * @author oosmoxiecode
  19466. * @author mrdoob / http://mrdoob.com/
  19467. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  19468. */
  19469. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  19470. THREE.Geometry.call( this );
  19471. this.type = 'TorusGeometry';
  19472. this.parameters = {
  19473. radius: radius,
  19474. tube: tube,
  19475. radialSegments: radialSegments,
  19476. tubularSegments: tubularSegments,
  19477. arc: arc
  19478. };
  19479. radius = radius || 100;
  19480. tube = tube || 40;
  19481. radialSegments = radialSegments || 8;
  19482. tubularSegments = tubularSegments || 6;
  19483. arc = arc || Math.PI * 2;
  19484. var center = new THREE.Vector3(), uvs = [], normals = [];
  19485. for ( var j = 0; j <= radialSegments; j ++ ) {
  19486. for ( var i = 0; i <= tubularSegments; i ++ ) {
  19487. var u = i / tubularSegments * arc;
  19488. var v = j / radialSegments * Math.PI * 2;
  19489. center.x = radius * Math.cos( u );
  19490. center.y = radius * Math.sin( u );
  19491. var vertex = new THREE.Vector3();
  19492. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  19493. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  19494. vertex.z = tube * Math.sin( v );
  19495. this.vertices.push( vertex );
  19496. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  19497. normals.push( vertex.clone().sub( center ).normalize() );
  19498. }
  19499. }
  19500. for ( var j = 1; j <= radialSegments; j ++ ) {
  19501. for ( var i = 1; i <= tubularSegments; i ++ ) {
  19502. var a = ( tubularSegments + 1 ) * j + i - 1;
  19503. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  19504. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  19505. var d = ( tubularSegments + 1 ) * j + i;
  19506. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  19507. this.faces.push( face );
  19508. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  19509. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  19510. this.faces.push( face );
  19511. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  19512. }
  19513. }
  19514. this.computeFaceNormals();
  19515. };
  19516. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19517. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  19518. // File:src/extras/geometries/TorusKnotGeometry.js
  19519. /**
  19520. * @author oosmoxiecode
  19521. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  19522. */
  19523. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  19524. THREE.Geometry.call( this );
  19525. this.type = 'TorusKnotGeometry';
  19526. this.parameters = {
  19527. radius: radius,
  19528. tube: tube,
  19529. radialSegments: radialSegments,
  19530. tubularSegments: tubularSegments,
  19531. p: p,
  19532. q: q,
  19533. heightScale: heightScale
  19534. };
  19535. radius = radius || 100;
  19536. tube = tube || 40;
  19537. radialSegments = radialSegments || 64;
  19538. tubularSegments = tubularSegments || 8;
  19539. p = p || 2;
  19540. q = q || 3;
  19541. heightScale = heightScale || 1;
  19542. var grid = new Array( radialSegments );
  19543. var tang = new THREE.Vector3();
  19544. var n = new THREE.Vector3();
  19545. var bitan = new THREE.Vector3();
  19546. for ( var i = 0; i < radialSegments; ++ i ) {
  19547. grid[ i ] = new Array( tubularSegments );
  19548. var u = i / radialSegments * 2 * p * Math.PI;
  19549. var p1 = getPos( u, q, p, radius, heightScale );
  19550. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  19551. tang.subVectors( p2, p1 );
  19552. n.addVectors( p2, p1 );
  19553. bitan.crossVectors( tang, n );
  19554. n.crossVectors( bitan, tang );
  19555. bitan.normalize();
  19556. n.normalize();
  19557. for ( var j = 0; j < tubularSegments; ++ j ) {
  19558. var v = j / tubularSegments * 2 * Math.PI;
  19559. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  19560. var cy = tube * Math.sin( v );
  19561. var pos = new THREE.Vector3();
  19562. pos.x = p1.x + cx * n.x + cy * bitan.x;
  19563. pos.y = p1.y + cx * n.y + cy * bitan.y;
  19564. pos.z = p1.z + cx * n.z + cy * bitan.z;
  19565. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  19566. }
  19567. }
  19568. for ( var i = 0; i < radialSegments; ++ i ) {
  19569. for ( var j = 0; j < tubularSegments; ++ j ) {
  19570. var ip = ( i + 1 ) % radialSegments;
  19571. var jp = ( j + 1 ) % tubularSegments;
  19572. var a = grid[ i ][ j ];
  19573. var b = grid[ ip ][ j ];
  19574. var c = grid[ ip ][ jp ];
  19575. var d = grid[ i ][ jp ];
  19576. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  19577. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  19578. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  19579. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  19580. this.faces.push( new THREE.Face3( a, b, d ) );
  19581. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19582. this.faces.push( new THREE.Face3( b, c, d ) );
  19583. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19584. }
  19585. }
  19586. this.computeFaceNormals();
  19587. this.computeVertexNormals();
  19588. function getPos( u, in_q, in_p, radius, heightScale ) {
  19589. var cu = Math.cos( u );
  19590. var su = Math.sin( u );
  19591. var quOverP = in_q / in_p * u;
  19592. var cs = Math.cos( quOverP );
  19593. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  19594. var ty = radius * ( 2 + cs ) * su * 0.5;
  19595. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  19596. return new THREE.Vector3( tx, ty, tz );
  19597. }
  19598. };
  19599. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19600. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  19601. // File:src/extras/geometries/TubeGeometry.js
  19602. /**
  19603. * @author WestLangley / https://github.com/WestLangley
  19604. * @author zz85 / https://github.com/zz85
  19605. * @author miningold / https://github.com/miningold
  19606. * @author jonobr1 / https://github.com/jonobr1
  19607. *
  19608. * Modified from the TorusKnotGeometry by @oosmoxiecode
  19609. *
  19610. * Creates a tube which extrudes along a 3d spline
  19611. *
  19612. * Uses parallel transport frames as described in
  19613. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  19614. */
  19615. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  19616. THREE.Geometry.call( this );
  19617. this.type = 'TubeGeometry';
  19618. this.parameters = {
  19619. path: path,
  19620. segments: segments,
  19621. radius: radius,
  19622. radialSegments: radialSegments,
  19623. closed: closed
  19624. };
  19625. segments = segments || 64;
  19626. radius = radius || 1;
  19627. radialSegments = radialSegments || 8;
  19628. closed = closed || false;
  19629. taper = taper || THREE.TubeGeometry.NoTaper;
  19630. var grid = [];
  19631. var scope = this,
  19632. tangent,
  19633. normal,
  19634. binormal,
  19635. numpoints = segments + 1,
  19636. u, v, r,
  19637. cx, cy,
  19638. pos, pos2 = new THREE.Vector3(),
  19639. i, j,
  19640. ip, jp,
  19641. a, b, c, d,
  19642. uva, uvb, uvc, uvd;
  19643. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  19644. tangents = frames.tangents,
  19645. normals = frames.normals,
  19646. binormals = frames.binormals;
  19647. // proxy internals
  19648. this.tangents = tangents;
  19649. this.normals = normals;
  19650. this.binormals = binormals;
  19651. function vert( x, y, z ) {
  19652. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  19653. }
  19654. // construct the grid
  19655. for ( i = 0; i < numpoints; i ++ ) {
  19656. grid[ i ] = [];
  19657. u = i / ( numpoints - 1 );
  19658. pos = path.getPointAt( u );
  19659. tangent = tangents[ i ];
  19660. normal = normals[ i ];
  19661. binormal = binormals[ i ];
  19662. r = radius * taper( u );
  19663. for ( j = 0; j < radialSegments; j ++ ) {
  19664. v = j / radialSegments * 2 * Math.PI;
  19665. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  19666. cy = r * Math.sin( v );
  19667. pos2.copy( pos );
  19668. pos2.x += cx * normal.x + cy * binormal.x;
  19669. pos2.y += cx * normal.y + cy * binormal.y;
  19670. pos2.z += cx * normal.z + cy * binormal.z;
  19671. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  19672. }
  19673. }
  19674. // construct the mesh
  19675. for ( i = 0; i < segments; i ++ ) {
  19676. for ( j = 0; j < radialSegments; j ++ ) {
  19677. ip = ( closed ) ? (i + 1) % segments : i + 1;
  19678. jp = (j + 1) % radialSegments;
  19679. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  19680. b = grid[ ip ][ j ];
  19681. c = grid[ ip ][ jp ];
  19682. d = grid[ i ][ jp ];
  19683. uva = new THREE.Vector2( i / segments, j / radialSegments );
  19684. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  19685. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  19686. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  19687. this.faces.push( new THREE.Face3( a, b, d ) );
  19688. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19689. this.faces.push( new THREE.Face3( b, c, d ) );
  19690. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19691. }
  19692. }
  19693. this.computeFaceNormals();
  19694. this.computeVertexNormals();
  19695. };
  19696. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19697. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  19698. THREE.TubeGeometry.NoTaper = function ( u ) {
  19699. return 1;
  19700. };
  19701. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  19702. return Math.sin( Math.PI * u );
  19703. };
  19704. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  19705. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  19706. var normal = new THREE.Vector3(),
  19707. tangents = [],
  19708. normals = [],
  19709. binormals = [],
  19710. vec = new THREE.Vector3(),
  19711. mat = new THREE.Matrix4(),
  19712. numpoints = segments + 1,
  19713. theta,
  19714. epsilon = 0.0001,
  19715. smallest,
  19716. tx, ty, tz,
  19717. i, u;
  19718. // expose internals
  19719. this.tangents = tangents;
  19720. this.normals = normals;
  19721. this.binormals = binormals;
  19722. // compute the tangent vectors for each segment on the path
  19723. for ( i = 0; i < numpoints; i ++ ) {
  19724. u = i / ( numpoints - 1 );
  19725. tangents[ i ] = path.getTangentAt( u );
  19726. tangents[ i ].normalize();
  19727. }
  19728. initialNormal3();
  19729. /*
  19730. function initialNormal1(lastBinormal) {
  19731. // fixed start binormal. Has dangers of 0 vectors
  19732. normals[ 0 ] = new THREE.Vector3();
  19733. binormals[ 0 ] = new THREE.Vector3();
  19734. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  19735. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  19736. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  19737. }
  19738. function initialNormal2() {
  19739. // This uses the Frenet-Serret formula for deriving binormal
  19740. var t2 = path.getTangentAt( epsilon );
  19741. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  19742. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  19743. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  19744. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  19745. }
  19746. */
  19747. function initialNormal3() {
  19748. // select an initial normal vector perpendicular to the first tangent vector,
  19749. // and in the direction of the smallest tangent xyz component
  19750. normals[ 0 ] = new THREE.Vector3();
  19751. binormals[ 0 ] = new THREE.Vector3();
  19752. smallest = Number.MAX_VALUE;
  19753. tx = Math.abs( tangents[ 0 ].x );
  19754. ty = Math.abs( tangents[ 0 ].y );
  19755. tz = Math.abs( tangents[ 0 ].z );
  19756. if ( tx <= smallest ) {
  19757. smallest = tx;
  19758. normal.set( 1, 0, 0 );
  19759. }
  19760. if ( ty <= smallest ) {
  19761. smallest = ty;
  19762. normal.set( 0, 1, 0 );
  19763. }
  19764. if ( tz <= smallest ) {
  19765. normal.set( 0, 0, 1 );
  19766. }
  19767. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  19768. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  19769. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  19770. }
  19771. // compute the slowly-varying normal and binormal vectors for each segment on the path
  19772. for ( i = 1; i < numpoints; i ++ ) {
  19773. normals[ i ] = normals[ i - 1 ].clone();
  19774. binormals[ i ] = binormals[ i - 1 ].clone();
  19775. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  19776. if ( vec.length() > epsilon ) {
  19777. vec.normalize();
  19778. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  19779. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  19780. }
  19781. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  19782. }
  19783. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  19784. if ( closed ) {
  19785. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  19786. theta /= ( numpoints - 1 );
  19787. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  19788. theta = - theta;
  19789. }
  19790. for ( i = 1; i < numpoints; i ++ ) {
  19791. // twist a little...
  19792. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  19793. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  19794. }
  19795. }
  19796. };
  19797. // File:src/extras/geometries/PolyhedronGeometry.js
  19798. /**
  19799. * @author clockworkgeek / https://github.com/clockworkgeek
  19800. * @author timothypratley / https://github.com/timothypratley
  19801. * @author WestLangley / http://github.com/WestLangley
  19802. */
  19803. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  19804. THREE.Geometry.call( this );
  19805. this.type = 'PolyhedronGeometry';
  19806. this.parameters = {
  19807. vertices: vertices,
  19808. indices: indices,
  19809. radius: radius,
  19810. detail: detail
  19811. };
  19812. radius = radius || 1;
  19813. detail = detail || 0;
  19814. var that = this;
  19815. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  19816. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  19817. }
  19818. var p = this.vertices;
  19819. var faces = [];
  19820. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  19821. var v1 = p[ indices[ i ] ];
  19822. var v2 = p[ indices[ i + 1 ] ];
  19823. var v3 = p[ indices[ i + 2 ] ];
  19824. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  19825. }
  19826. var centroid = new THREE.Vector3();
  19827. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  19828. subdivide( faces[ i ], detail );
  19829. }
  19830. // Handle case when face straddles the seam
  19831. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  19832. var uvs = this.faceVertexUvs[ 0 ][ i ];
  19833. var x0 = uvs[ 0 ].x;
  19834. var x1 = uvs[ 1 ].x;
  19835. var x2 = uvs[ 2 ].x;
  19836. var max = Math.max( x0, Math.max( x1, x2 ) );
  19837. var min = Math.min( x0, Math.min( x1, x2 ) );
  19838. if ( max > 0.9 && min < 0.1 ) { // 0.9 is somewhat arbitrary
  19839. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  19840. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  19841. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  19842. }
  19843. }
  19844. // Apply radius
  19845. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  19846. this.vertices[ i ].multiplyScalar( radius );
  19847. }
  19848. // Merge vertices
  19849. this.mergeVertices();
  19850. this.computeFaceNormals();
  19851. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19852. // Project vector onto sphere's surface
  19853. function prepare( vector ) {
  19854. var vertex = vector.normalize().clone();
  19855. vertex.index = that.vertices.push( vertex ) - 1;
  19856. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  19857. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  19858. var v = inclination( vector ) / Math.PI + 0.5;
  19859. vertex.uv = new THREE.Vector2( u, 1 - v );
  19860. return vertex;
  19861. }
  19862. // Approximate a curved face with recursively sub-divided triangles.
  19863. function make( v1, v2, v3 ) {
  19864. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  19865. that.faces.push( face );
  19866. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  19867. var azi = azimuth( centroid );
  19868. that.faceVertexUvs[ 0 ].push( [
  19869. correctUV( v1.uv, v1, azi ),
  19870. correctUV( v2.uv, v2, azi ),
  19871. correctUV( v3.uv, v3, azi )
  19872. ] );
  19873. }
  19874. // Analytically subdivide a face to the required detail level.
  19875. function subdivide( face, detail ) {
  19876. var cols = Math.pow(2, detail);
  19877. var a = prepare( that.vertices[ face.a ] );
  19878. var b = prepare( that.vertices[ face.b ] );
  19879. var c = prepare( that.vertices[ face.c ] );
  19880. var v = [];
  19881. // Construct all of the vertices for this subdivision.
  19882. for ( var i = 0 ; i <= cols; i ++ ) {
  19883. v[ i ] = [];
  19884. var aj = prepare( a.clone().lerp( c, i / cols ) );
  19885. var bj = prepare( b.clone().lerp( c, i / cols ) );
  19886. var rows = cols - i;
  19887. for ( var j = 0; j <= rows; j ++) {
  19888. if ( j === 0 && i === cols ) {
  19889. v[ i ][ j ] = aj;
  19890. } else {
  19891. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  19892. }
  19893. }
  19894. }
  19895. // Construct all of the faces.
  19896. for ( var i = 0; i < cols ; i ++ ) {
  19897. for ( var j = 0; j < 2 * (cols - i) - 1; j ++ ) {
  19898. var k = Math.floor( j / 2 );
  19899. if ( j % 2 === 0 ) {
  19900. make(
  19901. v[ i ][ k + 1],
  19902. v[ i + 1 ][ k ],
  19903. v[ i ][ k ]
  19904. );
  19905. } else {
  19906. make(
  19907. v[ i ][ k + 1 ],
  19908. v[ i + 1][ k + 1],
  19909. v[ i + 1 ][ k ]
  19910. );
  19911. }
  19912. }
  19913. }
  19914. }
  19915. // Angle around the Y axis, counter-clockwise when looking from above.
  19916. function azimuth( vector ) {
  19917. return Math.atan2( vector.z, - vector.x );
  19918. }
  19919. // Angle above the XZ plane.
  19920. function inclination( vector ) {
  19921. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  19922. }
  19923. // Texture fixing helper. Spheres have some odd behaviours.
  19924. function correctUV( uv, vector, azimuth ) {
  19925. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  19926. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  19927. return uv.clone();
  19928. }
  19929. };
  19930. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19931. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  19932. // File:src/extras/geometries/DodecahedronGeometry.js
  19933. /**
  19934. * @author Abe Pazos / https://hamoid.com
  19935. */
  19936. THREE.DodecahedronGeometry = function ( radius, detail ) {
  19937. this.parameters = {
  19938. radius: radius,
  19939. detail: detail
  19940. };
  19941. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  19942. var r = 1 / t;
  19943. var vertices = [
  19944. // (±1, ±1, ±1)
  19945. -1, -1, -1, -1, -1, 1,
  19946. -1, 1, -1, -1, 1, 1,
  19947. 1, -1, -1, 1, -1, 1,
  19948. 1, 1, -1, 1, 1, 1,
  19949. // (0, ±1/φ, ±φ)
  19950. 0, -r, -t, 0, -r, t,
  19951. 0, r, -t, 0, r, t,
  19952. // (±1/φ, ±φ, 0)
  19953. -r, -t, 0, -r, t, 0,
  19954. r, -t, 0, r, t, 0,
  19955. // (±φ, 0, ±1/φ)
  19956. -t, 0, -r, t, 0, -r,
  19957. -t, 0, r, t, 0, r
  19958. ];
  19959. var indices = [
  19960. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  19961. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  19962. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  19963. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  19964. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  19965. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  19966. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  19967. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  19968. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  19969. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  19970. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  19971. 1, 12, 14, 1, 14, 5, 1, 5, 9
  19972. ];
  19973. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  19974. };
  19975. THREE.DodecahedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19976. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  19977. // File:src/extras/geometries/IcosahedronGeometry.js
  19978. /**
  19979. * @author timothypratley / https://github.com/timothypratley
  19980. */
  19981. THREE.IcosahedronGeometry = function ( radius, detail ) {
  19982. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  19983. var vertices = [
  19984. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  19985. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  19986. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  19987. ];
  19988. var indices = [
  19989. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  19990. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  19991. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  19992. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  19993. ];
  19994. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  19995. this.type = 'IcosahedronGeometry';
  19996. this.parameters = {
  19997. radius: radius,
  19998. detail: detail
  19999. };
  20000. };
  20001. THREE.IcosahedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20002. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  20003. // File:src/extras/geometries/OctahedronGeometry.js
  20004. /**
  20005. * @author timothypratley / https://github.com/timothypratley
  20006. */
  20007. THREE.OctahedronGeometry = function ( radius, detail ) {
  20008. this.parameters = {
  20009. radius: radius,
  20010. detail: detail
  20011. };
  20012. var vertices = [
  20013. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0,- 1, 0, 0, 0, 1, 0, 0,- 1
  20014. ];
  20015. var indices = [
  20016. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  20017. ];
  20018. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20019. this.type = 'OctahedronGeometry';
  20020. this.parameters = {
  20021. radius: radius,
  20022. detail: detail
  20023. };
  20024. };
  20025. THREE.OctahedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20026. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  20027. // File:src/extras/geometries/TetrahedronGeometry.js
  20028. /**
  20029. * @author timothypratley / https://github.com/timothypratley
  20030. */
  20031. THREE.TetrahedronGeometry = function ( radius, detail ) {
  20032. var vertices = [
  20033. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  20034. ];
  20035. var indices = [
  20036. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  20037. ];
  20038. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20039. this.type = 'TetrahedronGeometry';
  20040. this.parameters = {
  20041. radius: radius,
  20042. detail: detail
  20043. };
  20044. };
  20045. THREE.TetrahedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20046. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  20047. // File:src/extras/geometries/ParametricGeometry.js
  20048. /**
  20049. * @author zz85 / https://github.com/zz85
  20050. * Parametric Surfaces Geometry
  20051. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  20052. *
  20053. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  20054. *
  20055. */
  20056. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  20057. THREE.Geometry.call( this );
  20058. this.type = 'ParametricGeometry';
  20059. this.parameters = {
  20060. func: func,
  20061. slices: slices,
  20062. stacks: stacks
  20063. };
  20064. var verts = this.vertices;
  20065. var faces = this.faces;
  20066. var uvs = this.faceVertexUvs[ 0 ];
  20067. var i, j, p;
  20068. var u, v;
  20069. var sliceCount = slices + 1;
  20070. for ( i = 0; i <= stacks; i ++ ) {
  20071. v = i / stacks;
  20072. for ( j = 0; j <= slices; j ++ ) {
  20073. u = j / slices;
  20074. p = func( u, v );
  20075. verts.push( p );
  20076. }
  20077. }
  20078. var a, b, c, d;
  20079. var uva, uvb, uvc, uvd;
  20080. for ( i = 0; i < stacks; i ++ ) {
  20081. for ( j = 0; j < slices; j ++ ) {
  20082. a = i * sliceCount + j;
  20083. b = i * sliceCount + j + 1;
  20084. c = (i + 1) * sliceCount + j + 1;
  20085. d = (i + 1) * sliceCount + j;
  20086. uva = new THREE.Vector2( j / slices, i / stacks );
  20087. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  20088. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  20089. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  20090. faces.push( new THREE.Face3( a, b, d ) );
  20091. uvs.push( [ uva, uvb, uvd ] );
  20092. faces.push( new THREE.Face3( b, c, d ) );
  20093. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  20094. }
  20095. }
  20096. // console.log(this);
  20097. // magic bullet
  20098. // var diff = this.mergeVertices();
  20099. // console.log('removed ', diff, ' vertices by merging');
  20100. this.computeFaceNormals();
  20101. this.computeVertexNormals();
  20102. };
  20103. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20104. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  20105. // File:src/extras/geometries/WireframeGeometry.js
  20106. /**
  20107. * @author mrdoob / http://mrdoob.com/
  20108. */
  20109. THREE.WireframeGeometry = function ( geometry ) {
  20110. THREE.BufferGeometry.call( this );
  20111. var edge = [ 0, 0 ], hash = {};
  20112. var sortFunction = function ( a, b ) { return a - b };
  20113. var keys = [ 'a', 'b', 'c' ];
  20114. if ( geometry instanceof THREE.Geometry ) {
  20115. var vertices = geometry.vertices;
  20116. var faces = geometry.faces;
  20117. var numEdges = 0;
  20118. // allocate maximal size
  20119. var edges = new Uint32Array( 6 * faces.length );
  20120. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20121. var face = faces[ i ];
  20122. for ( var j = 0; j < 3; j ++ ) {
  20123. edge[ 0 ] = face[ keys[ j ] ];
  20124. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  20125. edge.sort( sortFunction );
  20126. var key = edge.toString();
  20127. if ( hash[ key ] === undefined ) {
  20128. edges[ 2 * numEdges ] = edge[ 0 ];
  20129. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  20130. hash[ key ] = true;
  20131. numEdges ++;
  20132. }
  20133. }
  20134. }
  20135. var coords = new Float32Array( numEdges * 2 * 3 );
  20136. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  20137. for ( var j = 0; j < 2; j ++ ) {
  20138. var vertex = vertices[ edges [ 2 * i + j] ];
  20139. var index = 6 * i + 3 * j;
  20140. coords[ index + 0 ] = vertex.x;
  20141. coords[ index + 1 ] = vertex.y;
  20142. coords[ index + 2 ] = vertex.z;
  20143. }
  20144. }
  20145. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20146. } else if ( geometry instanceof THREE.BufferGeometry ) {
  20147. if ( geometry.attributes.index !== undefined ) { // Indexed BufferGeometry
  20148. var vertices = geometry.attributes.position;
  20149. var indices = geometry.attributes.index.array;
  20150. var drawcalls = geometry.drawcalls;
  20151. var numEdges = 0;
  20152. if ( drawcalls.length === 0 ) {
  20153. drawcalls = [ { count : indices.length, index : 0, start : 0 } ];
  20154. }
  20155. // allocate maximal size
  20156. var edges = new Uint32Array( 2 * indices.length );
  20157. for ( var o = 0, ol = drawcalls.length; o < ol; ++ o ) {
  20158. var start = drawcalls[ o ].start;
  20159. var count = drawcalls[ o ].count;
  20160. var index = drawcalls[ o ].index;
  20161. for ( var i = start, il = start + count; i < il; i += 3 ) {
  20162. for ( var j = 0; j < 3; j ++ ) {
  20163. edge[ 0 ] = index + indices[ i + j ];
  20164. edge[ 1 ] = index + indices[ i + ( j + 1 ) % 3 ];
  20165. edge.sort( sortFunction );
  20166. var key = edge.toString();
  20167. if ( hash[ key ] === undefined ) {
  20168. edges[ 2 * numEdges ] = edge[ 0 ];
  20169. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  20170. hash[ key ] = true;
  20171. numEdges ++;
  20172. }
  20173. }
  20174. }
  20175. }
  20176. var coords = new Float32Array( numEdges * 2 * 3 );
  20177. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  20178. for ( var j = 0; j < 2; j ++ ) {
  20179. var index = 6 * i + 3 * j;
  20180. var index2 = edges[2 * i + j];
  20181. coords[ index + 0 ] = vertices.getX( index2 );
  20182. coords[ index + 1 ] = vertices.getY( index2 );
  20183. coords[ index + 2 ] = vertices.getZ( index2 );
  20184. }
  20185. }
  20186. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20187. } else { // non-indexed BufferGeometry
  20188. var vertices = geometry.attributes.position.array;
  20189. var numEdges = vertices.length / 3;
  20190. var numTris = numEdges / 3;
  20191. var coords = new Float32Array( numEdges * 2 * 3 );
  20192. for ( var i = 0, l = numTris; i < l; i ++ ) {
  20193. for ( var j = 0; j < 3; j ++ ) {
  20194. var index = 18 * i + 6 * j;
  20195. var index1 = 9 * i + 3 * j;
  20196. coords[ index + 0 ] = vertices[ index1 ];
  20197. coords[ index + 1 ] = vertices[ index1 + 1 ];
  20198. coords[ index + 2 ] = vertices[ index1 + 2 ];
  20199. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  20200. coords[ index + 3 ] = vertices[ index2 ];
  20201. coords[ index + 4 ] = vertices[ index2 + 1 ];
  20202. coords[ index + 5 ] = vertices[ index2 + 2 ];
  20203. }
  20204. }
  20205. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20206. }
  20207. }
  20208. };
  20209. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  20210. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  20211. // File:src/extras/helpers/AxisHelper.js
  20212. /**
  20213. * @author sroucheray / http://sroucheray.org/
  20214. * @author mrdoob / http://mrdoob.com/
  20215. */
  20216. THREE.AxisHelper = function ( size ) {
  20217. size = size || 1;
  20218. var vertices = new Float32Array( [
  20219. 0, 0, 0, size, 0, 0,
  20220. 0, 0, 0, 0, size, 0,
  20221. 0, 0, 0, 0, 0, size
  20222. ] );
  20223. var colors = new Float32Array( [
  20224. 1, 0, 0, 1, 0.6, 0,
  20225. 0, 1, 0, 0.6, 1, 0,
  20226. 0, 0, 1, 0, 0.6, 1
  20227. ] );
  20228. var geometry = new THREE.BufferGeometry();
  20229. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  20230. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  20231. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  20232. THREE.LineSegments.call( this, geometry, material );
  20233. };
  20234. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20235. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  20236. // File:src/extras/helpers/ArrowHelper.js
  20237. /**
  20238. * @author WestLangley / http://github.com/WestLangley
  20239. * @author zz85 / http://github.com/zz85
  20240. * @author bhouston / http://exocortex.com
  20241. *
  20242. * Creates an arrow for visualizing directions
  20243. *
  20244. * Parameters:
  20245. * dir - Vector3
  20246. * origin - Vector3
  20247. * length - Number
  20248. * color - color in hex value
  20249. * headLength - Number
  20250. * headWidth - Number
  20251. */
  20252. THREE.ArrowHelper = ( function () {
  20253. var lineGeometry = new THREE.Geometry();
  20254. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  20255. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  20256. coneGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
  20257. return function ( dir, origin, length, color, headLength, headWidth ) {
  20258. // dir is assumed to be normalized
  20259. THREE.Object3D.call( this );
  20260. if ( color === undefined ) color = 0xffff00;
  20261. if ( length === undefined ) length = 1;
  20262. if ( headLength === undefined ) headLength = 0.2 * length;
  20263. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  20264. this.position.copy( origin );
  20265. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  20266. this.line.matrixAutoUpdate = false;
  20267. this.add( this.line );
  20268. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  20269. this.cone.matrixAutoUpdate = false;
  20270. this.add( this.cone );
  20271. this.setDirection( dir );
  20272. this.setLength( length, headLength, headWidth );
  20273. }
  20274. }() );
  20275. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  20276. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  20277. THREE.ArrowHelper.prototype.setDirection = ( function () {
  20278. var axis = new THREE.Vector3();
  20279. var radians;
  20280. return function ( dir ) {
  20281. // dir is assumed to be normalized
  20282. if ( dir.y > 0.99999 ) {
  20283. this.quaternion.set( 0, 0, 0, 1 );
  20284. } else if ( dir.y < - 0.99999 ) {
  20285. this.quaternion.set( 1, 0, 0, 0 );
  20286. } else {
  20287. axis.set( dir.z, 0, - dir.x ).normalize();
  20288. radians = Math.acos( dir.y );
  20289. this.quaternion.setFromAxisAngle( axis, radians );
  20290. }
  20291. };
  20292. }() );
  20293. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  20294. if ( headLength === undefined ) headLength = 0.2 * length;
  20295. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  20296. this.line.scale.set( 1, length - headLength, 1 );
  20297. this.line.updateMatrix();
  20298. this.cone.scale.set( headWidth, headLength, headWidth );
  20299. this.cone.position.y = length;
  20300. this.cone.updateMatrix();
  20301. };
  20302. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  20303. this.line.material.color.set( color );
  20304. this.cone.material.color.set( color );
  20305. };
  20306. // File:src/extras/helpers/BoxHelper.js
  20307. /**
  20308. * @author mrdoob / http://mrdoob.com/
  20309. */
  20310. THREE.BoxHelper = function ( object ) {
  20311. var geometry = new THREE.BufferGeometry();
  20312. geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( 72 ), 3 ) );
  20313. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  20314. if ( object !== undefined ) {
  20315. this.update( object );
  20316. }
  20317. };
  20318. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20319. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  20320. THREE.BoxHelper.prototype.update = function ( object ) {
  20321. var geometry = object.geometry;
  20322. if ( geometry.boundingBox === null ) {
  20323. geometry.computeBoundingBox();
  20324. }
  20325. var min = geometry.boundingBox.min;
  20326. var max = geometry.boundingBox.max;
  20327. /*
  20328. 5____4
  20329. 1/___0/|
  20330. | 6__|_7
  20331. 2/___3/
  20332. 0: max.x, max.y, max.z
  20333. 1: min.x, max.y, max.z
  20334. 2: min.x, min.y, max.z
  20335. 3: max.x, min.y, max.z
  20336. 4: max.x, max.y, min.z
  20337. 5: min.x, max.y, min.z
  20338. 6: min.x, min.y, min.z
  20339. 7: max.x, min.y, min.z
  20340. */
  20341. var vertices = this.geometry.attributes.position.array;
  20342. vertices[ 0 ] = max.x; vertices[ 1 ] = max.y; vertices[ 2 ] = max.z;
  20343. vertices[ 3 ] = min.x; vertices[ 4 ] = max.y; vertices[ 5 ] = max.z;
  20344. vertices[ 6 ] = min.x; vertices[ 7 ] = max.y; vertices[ 8 ] = max.z;
  20345. vertices[ 9 ] = min.x; vertices[ 10 ] = min.y; vertices[ 11 ] = max.z;
  20346. vertices[ 12 ] = min.x; vertices[ 13 ] = min.y; vertices[ 14 ] = max.z;
  20347. vertices[ 15 ] = max.x; vertices[ 16 ] = min.y; vertices[ 17 ] = max.z;
  20348. vertices[ 18 ] = max.x; vertices[ 19 ] = min.y; vertices[ 20 ] = max.z;
  20349. vertices[ 21 ] = max.x; vertices[ 22 ] = max.y; vertices[ 23 ] = max.z;
  20350. //
  20351. vertices[ 24 ] = max.x; vertices[ 25 ] = max.y; vertices[ 26 ] = min.z;
  20352. vertices[ 27 ] = min.x; vertices[ 28 ] = max.y; vertices[ 29 ] = min.z;
  20353. vertices[ 30 ] = min.x; vertices[ 31 ] = max.y; vertices[ 32 ] = min.z;
  20354. vertices[ 33 ] = min.x; vertices[ 34 ] = min.y; vertices[ 35 ] = min.z;
  20355. vertices[ 36 ] = min.x; vertices[ 37 ] = min.y; vertices[ 38 ] = min.z;
  20356. vertices[ 39 ] = max.x; vertices[ 40 ] = min.y; vertices[ 41 ] = min.z;
  20357. vertices[ 42 ] = max.x; vertices[ 43 ] = min.y; vertices[ 44 ] = min.z;
  20358. vertices[ 45 ] = max.x; vertices[ 46 ] = max.y; vertices[ 47 ] = min.z;
  20359. //
  20360. vertices[ 48 ] = max.x; vertices[ 49 ] = max.y; vertices[ 50 ] = max.z;
  20361. vertices[ 51 ] = max.x; vertices[ 52 ] = max.y; vertices[ 53 ] = min.z;
  20362. vertices[ 54 ] = min.x; vertices[ 55 ] = max.y; vertices[ 56 ] = max.z;
  20363. vertices[ 57 ] = min.x; vertices[ 58 ] = max.y; vertices[ 59 ] = min.z;
  20364. vertices[ 60 ] = min.x; vertices[ 61 ] = min.y; vertices[ 62 ] = max.z;
  20365. vertices[ 63 ] = min.x; vertices[ 64 ] = min.y; vertices[ 65 ] = min.z;
  20366. vertices[ 66 ] = max.x; vertices[ 67 ] = min.y; vertices[ 68 ] = max.z;
  20367. vertices[ 69 ] = max.x; vertices[ 70 ] = min.y; vertices[ 71 ] = min.z;
  20368. this.geometry.attributes.position.needsUpdate = true;
  20369. this.geometry.computeBoundingSphere();
  20370. this.matrix = object.matrixWorld;
  20371. this.matrixAutoUpdate = false;
  20372. };
  20373. // File:src/extras/helpers/BoundingBoxHelper.js
  20374. /**
  20375. * @author WestLangley / http://github.com/WestLangley
  20376. */
  20377. // a helper to show the world-axis-aligned bounding box for an object
  20378. THREE.BoundingBoxHelper = function ( object, hex ) {
  20379. var color = ( hex !== undefined ) ? hex : 0x888888;
  20380. this.object = object;
  20381. this.box = new THREE.Box3();
  20382. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  20383. };
  20384. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  20385. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  20386. THREE.BoundingBoxHelper.prototype.update = function () {
  20387. this.box.setFromObject( this.object );
  20388. this.box.size( this.scale );
  20389. this.box.center( this.position );
  20390. };
  20391. // File:src/extras/helpers/CameraHelper.js
  20392. /**
  20393. * @author alteredq / http://alteredqualia.com/
  20394. *
  20395. * - shows frustum, line of sight and up of the camera
  20396. * - suitable for fast updates
  20397. * - based on frustum visualization in lightgl.js shadowmap example
  20398. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  20399. */
  20400. THREE.CameraHelper = function ( camera ) {
  20401. var geometry = new THREE.Geometry();
  20402. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  20403. var pointMap = {};
  20404. // colors
  20405. var hexFrustum = 0xffaa00;
  20406. var hexCone = 0xff0000;
  20407. var hexUp = 0x00aaff;
  20408. var hexTarget = 0xffffff;
  20409. var hexCross = 0x333333;
  20410. // near
  20411. addLine( "n1", "n2", hexFrustum );
  20412. addLine( "n2", "n4", hexFrustum );
  20413. addLine( "n4", "n3", hexFrustum );
  20414. addLine( "n3", "n1", hexFrustum );
  20415. // far
  20416. addLine( "f1", "f2", hexFrustum );
  20417. addLine( "f2", "f4", hexFrustum );
  20418. addLine( "f4", "f3", hexFrustum );
  20419. addLine( "f3", "f1", hexFrustum );
  20420. // sides
  20421. addLine( "n1", "f1", hexFrustum );
  20422. addLine( "n2", "f2", hexFrustum );
  20423. addLine( "n3", "f3", hexFrustum );
  20424. addLine( "n4", "f4", hexFrustum );
  20425. // cone
  20426. addLine( "p", "n1", hexCone );
  20427. addLine( "p", "n2", hexCone );
  20428. addLine( "p", "n3", hexCone );
  20429. addLine( "p", "n4", hexCone );
  20430. // up
  20431. addLine( "u1", "u2", hexUp );
  20432. addLine( "u2", "u3", hexUp );
  20433. addLine( "u3", "u1", hexUp );
  20434. // target
  20435. addLine( "c", "t", hexTarget );
  20436. addLine( "p", "c", hexCross );
  20437. // cross
  20438. addLine( "cn1", "cn2", hexCross );
  20439. addLine( "cn3", "cn4", hexCross );
  20440. addLine( "cf1", "cf2", hexCross );
  20441. addLine( "cf3", "cf4", hexCross );
  20442. function addLine( a, b, hex ) {
  20443. addPoint( a, hex );
  20444. addPoint( b, hex );
  20445. }
  20446. function addPoint( id, hex ) {
  20447. geometry.vertices.push( new THREE.Vector3() );
  20448. geometry.colors.push( new THREE.Color( hex ) );
  20449. if ( pointMap[ id ] === undefined ) {
  20450. pointMap[ id ] = [];
  20451. }
  20452. pointMap[ id ].push( geometry.vertices.length - 1 );
  20453. }
  20454. THREE.LineSegments.call( this, geometry, material );
  20455. this.camera = camera;
  20456. this.matrix = camera.matrixWorld;
  20457. this.matrixAutoUpdate = false;
  20458. this.pointMap = pointMap;
  20459. this.update();
  20460. };
  20461. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20462. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  20463. THREE.CameraHelper.prototype.update = function () {
  20464. var geometry, pointMap;
  20465. var vector = new THREE.Vector3();
  20466. var camera = new THREE.Camera();
  20467. var setPoint = function ( point, x, y, z ) {
  20468. vector.set( x, y, z ).unproject( camera );
  20469. var points = pointMap[ point ];
  20470. if ( points !== undefined ) {
  20471. for ( var i = 0, il = points.length; i < il; i ++ ) {
  20472. geometry.vertices[ points[ i ] ].copy( vector );
  20473. }
  20474. }
  20475. };
  20476. return function () {
  20477. geometry = this.geometry;
  20478. pointMap = this.pointMap;
  20479. var w = 1, h = 1;
  20480. // we need just camera projection matrix
  20481. // world matrix must be identity
  20482. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  20483. // center / target
  20484. setPoint( "c", 0, 0, - 1 );
  20485. setPoint( "t", 0, 0, 1 );
  20486. // near
  20487. setPoint( "n1", - w, - h, - 1 );
  20488. setPoint( "n2", w, - h, - 1 );
  20489. setPoint( "n3", - w, h, - 1 );
  20490. setPoint( "n4", w, h, - 1 );
  20491. // far
  20492. setPoint( "f1", - w, - h, 1 );
  20493. setPoint( "f2", w, - h, 1 );
  20494. setPoint( "f3", - w, h, 1 );
  20495. setPoint( "f4", w, h, 1 );
  20496. // up
  20497. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  20498. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  20499. setPoint( "u3", 0, h * 2, - 1 );
  20500. // cross
  20501. setPoint( "cf1", - w, 0, 1 );
  20502. setPoint( "cf2", w, 0, 1 );
  20503. setPoint( "cf3", 0, - h, 1 );
  20504. setPoint( "cf4", 0, h, 1 );
  20505. setPoint( "cn1", - w, 0, - 1 );
  20506. setPoint( "cn2", w, 0, - 1 );
  20507. setPoint( "cn3", 0, - h, - 1 );
  20508. setPoint( "cn4", 0, h, - 1 );
  20509. geometry.verticesNeedUpdate = true;
  20510. };
  20511. }();
  20512. // File:src/extras/helpers/DirectionalLightHelper.js
  20513. /**
  20514. * @author alteredq / http://alteredqualia.com/
  20515. * @author mrdoob / http://mrdoob.com/
  20516. * @author WestLangley / http://github.com/WestLangley
  20517. */
  20518. THREE.DirectionalLightHelper = function ( light, size ) {
  20519. THREE.Object3D.call( this );
  20520. this.light = light;
  20521. this.light.updateMatrixWorld();
  20522. this.matrix = light.matrixWorld;
  20523. this.matrixAutoUpdate = false;
  20524. size = size || 1;
  20525. var geometry = new THREE.Geometry();
  20526. geometry.vertices.push(
  20527. new THREE.Vector3( - size, size, 0 ),
  20528. new THREE.Vector3( size, size, 0 ),
  20529. new THREE.Vector3( size, - size, 0 ),
  20530. new THREE.Vector3( - size, - size, 0 ),
  20531. new THREE.Vector3( - size, size, 0 )
  20532. );
  20533. var material = new THREE.LineBasicMaterial( { fog: false } );
  20534. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20535. this.lightPlane = new THREE.Line( geometry, material );
  20536. this.add( this.lightPlane );
  20537. geometry = new THREE.Geometry();
  20538. geometry.vertices.push(
  20539. new THREE.Vector3(),
  20540. new THREE.Vector3()
  20541. );
  20542. material = new THREE.LineBasicMaterial( { fog: false } );
  20543. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20544. this.targetLine = new THREE.Line( geometry, material );
  20545. this.add( this.targetLine );
  20546. this.update();
  20547. };
  20548. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  20549. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  20550. THREE.DirectionalLightHelper.prototype.dispose = function () {
  20551. this.lightPlane.geometry.dispose();
  20552. this.lightPlane.material.dispose();
  20553. this.targetLine.geometry.dispose();
  20554. this.targetLine.material.dispose();
  20555. };
  20556. THREE.DirectionalLightHelper.prototype.update = function () {
  20557. var v1 = new THREE.Vector3();
  20558. var v2 = new THREE.Vector3();
  20559. var v3 = new THREE.Vector3();
  20560. return function () {
  20561. v1.setFromMatrixPosition( this.light.matrixWorld );
  20562. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  20563. v3.subVectors( v2, v1 );
  20564. this.lightPlane.lookAt( v3 );
  20565. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20566. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  20567. this.targetLine.geometry.verticesNeedUpdate = true;
  20568. this.targetLine.material.color.copy( this.lightPlane.material.color );
  20569. };
  20570. }();
  20571. // File:src/extras/helpers/EdgesHelper.js
  20572. /**
  20573. * @author WestLangley / http://github.com/WestLangley
  20574. * @param object THREE.Mesh whose geometry will be used
  20575. * @param hex line color
  20576. * @param thresholdAngle the minimum angle (in degrees),
  20577. * between the face normals of adjacent faces,
  20578. * that is required to render an edge. A value of 10 means
  20579. * an edge is only rendered if the angle is at least 10 degrees.
  20580. */
  20581. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  20582. var color = ( hex !== undefined ) ? hex : 0xffffff;
  20583. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  20584. this.matrix = object.matrixWorld;
  20585. this.matrixAutoUpdate = false;
  20586. };
  20587. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20588. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  20589. // File:src/extras/helpers/FaceNormalsHelper.js
  20590. /**
  20591. * @author mrdoob / http://mrdoob.com/
  20592. * @author WestLangley / http://github.com/WestLangley
  20593. */
  20594. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  20595. // FaceNormalsHelper only supports THREE.Geometry
  20596. this.object = object;
  20597. this.size = ( size !== undefined ) ? size : 1;
  20598. var color = ( hex !== undefined ) ? hex : 0xffff00;
  20599. var width = ( linewidth !== undefined ) ? linewidth : 1;
  20600. //
  20601. var nNormals = 0;
  20602. var objGeometry = this.object.geometry;
  20603. if ( objGeometry instanceof THREE.Geometry ) {
  20604. nNormals = objGeometry.faces.length;
  20605. } else {
  20606. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  20607. }
  20608. //
  20609. var geometry = new THREE.BufferGeometry();
  20610. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  20611. geometry.addAttribute( 'position', positions );
  20612. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  20613. //
  20614. this.matrixAutoUpdate = false;
  20615. this.normalMatrix = new THREE.Matrix3();
  20616. this.update();
  20617. };
  20618. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20619. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  20620. THREE.FaceNormalsHelper.prototype.update = ( function () {
  20621. var v1 = new THREE.Vector3();
  20622. var v2 = new THREE.Vector3();
  20623. return function() {
  20624. this.object.updateMatrixWorld( true );
  20625. this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
  20626. var matrixWorld = this.object.matrixWorld;
  20627. var position = this.geometry.attributes.position;
  20628. //
  20629. var objGeometry = this.object.geometry;
  20630. var vertices = objGeometry.vertices;
  20631. var faces = objGeometry.faces;
  20632. var idx = 0;
  20633. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20634. var face = faces[ i ];
  20635. var normal = face.normal;
  20636. v1.copy( vertices[ face.a ] )
  20637. .add( vertices[ face.b ] )
  20638. .add( vertices[ face.c ] )
  20639. .divideScalar( 3 )
  20640. .applyMatrix4( matrixWorld );
  20641. v2.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  20642. position.setXYZ( idx, v1.x, v1.y, v1.z );
  20643. idx = idx + 1;
  20644. position.setXYZ( idx, v2.x, v2.y, v2.z );
  20645. idx = idx + 1;
  20646. }
  20647. position.needsUpdate = true;
  20648. return this;
  20649. }
  20650. }());
  20651. // File:src/extras/helpers/GridHelper.js
  20652. /**
  20653. * @author mrdoob / http://mrdoob.com/
  20654. */
  20655. THREE.GridHelper = function ( size, step ) {
  20656. var geometry = new THREE.Geometry();
  20657. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  20658. this.color1 = new THREE.Color( 0x444444 );
  20659. this.color2 = new THREE.Color( 0x888888 );
  20660. for ( var i = - size; i <= size; i += step ) {
  20661. geometry.vertices.push(
  20662. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  20663. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  20664. );
  20665. var color = i === 0 ? this.color1 : this.color2;
  20666. geometry.colors.push( color, color, color, color );
  20667. }
  20668. THREE.LineSegments.call( this, geometry, material );
  20669. };
  20670. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20671. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  20672. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  20673. this.color1.set( colorCenterLine );
  20674. this.color2.set( colorGrid );
  20675. this.geometry.colorsNeedUpdate = true;
  20676. };
  20677. // File:src/extras/helpers/HemisphereLightHelper.js
  20678. /**
  20679. * @author alteredq / http://alteredqualia.com/
  20680. * @author mrdoob / http://mrdoob.com/
  20681. */
  20682. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  20683. THREE.Object3D.call( this );
  20684. this.light = light;
  20685. this.light.updateMatrixWorld();
  20686. this.matrix = light.matrixWorld;
  20687. this.matrixAutoUpdate = false;
  20688. this.colors = [ new THREE.Color(), new THREE.Color() ];
  20689. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  20690. geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
  20691. for ( var i = 0, il = 8; i < il; i ++ ) {
  20692. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  20693. }
  20694. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  20695. this.lightSphere = new THREE.Mesh( geometry, material );
  20696. this.add( this.lightSphere );
  20697. this.update();
  20698. };
  20699. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  20700. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  20701. THREE.HemisphereLightHelper.prototype.dispose = function () {
  20702. this.lightSphere.geometry.dispose();
  20703. this.lightSphere.material.dispose();
  20704. };
  20705. THREE.HemisphereLightHelper.prototype.update = function () {
  20706. var vector = new THREE.Vector3();
  20707. return function () {
  20708. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  20709. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  20710. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  20711. this.lightSphere.geometry.colorsNeedUpdate = true;
  20712. }
  20713. }();
  20714. // File:src/extras/helpers/PointLightHelper.js
  20715. /**
  20716. * @author alteredq / http://alteredqualia.com/
  20717. * @author mrdoob / http://mrdoob.com/
  20718. */
  20719. THREE.PointLightHelper = function ( light, sphereSize ) {
  20720. this.light = light;
  20721. this.light.updateMatrixWorld();
  20722. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  20723. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  20724. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20725. THREE.Mesh.call( this, geometry, material );
  20726. this.matrix = this.light.matrixWorld;
  20727. this.matrixAutoUpdate = false;
  20728. /*
  20729. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  20730. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  20731. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  20732. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  20733. var d = light.distance;
  20734. if ( d === 0.0 ) {
  20735. this.lightDistance.visible = false;
  20736. } else {
  20737. this.lightDistance.scale.set( d, d, d );
  20738. }
  20739. this.add( this.lightDistance );
  20740. */
  20741. };
  20742. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  20743. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  20744. THREE.PointLightHelper.prototype.dispose = function () {
  20745. this.geometry.dispose();
  20746. this.material.dispose();
  20747. };
  20748. THREE.PointLightHelper.prototype.update = function () {
  20749. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20750. /*
  20751. var d = this.light.distance;
  20752. if ( d === 0.0 ) {
  20753. this.lightDistance.visible = false;
  20754. } else {
  20755. this.lightDistance.visible = true;
  20756. this.lightDistance.scale.set( d, d, d );
  20757. }
  20758. */
  20759. };
  20760. // File:src/extras/helpers/SkeletonHelper.js
  20761. /**
  20762. * @author Sean Griffin / http://twitter.com/sgrif
  20763. * @author Michael Guerrero / http://realitymeltdown.com
  20764. * @author mrdoob / http://mrdoob.com/
  20765. * @author ikerr / http://verold.com
  20766. */
  20767. THREE.SkeletonHelper = function ( object ) {
  20768. this.bones = this.getBoneList( object );
  20769. var geometry = new THREE.Geometry();
  20770. for ( var i = 0; i < this.bones.length; i ++ ) {
  20771. var bone = this.bones[ i ];
  20772. if ( bone.parent instanceof THREE.Bone ) {
  20773. geometry.vertices.push( new THREE.Vector3() );
  20774. geometry.vertices.push( new THREE.Vector3() );
  20775. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  20776. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  20777. }
  20778. }
  20779. geometry.dynamic = true;
  20780. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  20781. THREE.LineSegments.call( this, geometry, material );
  20782. this.root = object;
  20783. this.matrix = object.matrixWorld;
  20784. this.matrixAutoUpdate = false;
  20785. this.update();
  20786. };
  20787. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20788. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  20789. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  20790. var boneList = [];
  20791. if ( object instanceof THREE.Bone ) {
  20792. boneList.push( object );
  20793. }
  20794. for ( var i = 0; i < object.children.length; i ++ ) {
  20795. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  20796. }
  20797. return boneList;
  20798. };
  20799. THREE.SkeletonHelper.prototype.update = function () {
  20800. var geometry = this.geometry;
  20801. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  20802. var boneMatrix = new THREE.Matrix4();
  20803. var j = 0;
  20804. for ( var i = 0; i < this.bones.length; i ++ ) {
  20805. var bone = this.bones[ i ];
  20806. if ( bone.parent instanceof THREE.Bone ) {
  20807. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  20808. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  20809. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  20810. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  20811. j += 2;
  20812. }
  20813. }
  20814. geometry.verticesNeedUpdate = true;
  20815. geometry.computeBoundingSphere();
  20816. };
  20817. // File:src/extras/helpers/SpotLightHelper.js
  20818. /**
  20819. * @author alteredq / http://alteredqualia.com/
  20820. * @author mrdoob / http://mrdoob.com/
  20821. * @author WestLangley / http://github.com/WestLangley
  20822. */
  20823. THREE.SpotLightHelper = function ( light ) {
  20824. THREE.Object3D.call( this );
  20825. this.light = light;
  20826. this.light.updateMatrixWorld();
  20827. this.matrix = light.matrixWorld;
  20828. this.matrixAutoUpdate = false;
  20829. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  20830. geometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
  20831. geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
  20832. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  20833. this.cone = new THREE.Mesh( geometry, material );
  20834. this.add( this.cone );
  20835. this.update();
  20836. };
  20837. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  20838. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  20839. THREE.SpotLightHelper.prototype.dispose = function () {
  20840. this.cone.geometry.dispose();
  20841. this.cone.material.dispose();
  20842. };
  20843. THREE.SpotLightHelper.prototype.update = function () {
  20844. var vector = new THREE.Vector3();
  20845. var vector2 = new THREE.Vector3();
  20846. return function () {
  20847. var coneLength = this.light.distance ? this.light.distance : 10000;
  20848. var coneWidth = coneLength * Math.tan( this.light.angle );
  20849. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  20850. vector.setFromMatrixPosition( this.light.matrixWorld );
  20851. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  20852. this.cone.lookAt( vector2.sub( vector ) );
  20853. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20854. };
  20855. }();
  20856. // File:src/extras/helpers/VertexNormalsHelper.js
  20857. /**
  20858. * @author mrdoob / http://mrdoob.com/
  20859. * @author WestLangley / http://github.com/WestLangley
  20860. */
  20861. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  20862. this.object = object;
  20863. this.size = ( size !== undefined ) ? size : 1;
  20864. var color = ( hex !== undefined ) ? hex : 0xff0000;
  20865. var width = ( linewidth !== undefined ) ? linewidth : 1;
  20866. //
  20867. var nNormals = 0;
  20868. var objGeometry = this.object.geometry;
  20869. if ( objGeometry instanceof THREE.Geometry ) {
  20870. nNormals = objGeometry.faces.length * 3;
  20871. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  20872. nNormals = objGeometry.attributes.normal.count
  20873. }
  20874. //
  20875. var geometry = new THREE.BufferGeometry();
  20876. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  20877. geometry.addAttribute( 'position', positions );
  20878. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  20879. //
  20880. this.matrixAutoUpdate = false;
  20881. this.normalMatrix = new THREE.Matrix3();
  20882. this.update();
  20883. };
  20884. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20885. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  20886. THREE.VertexNormalsHelper.prototype.update = ( function () {
  20887. var v1 = new THREE.Vector3();
  20888. var v2 = new THREE.Vector3();
  20889. return function() {
  20890. var keys = [ 'a', 'b', 'c' ];
  20891. this.object.updateMatrixWorld( true );
  20892. this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
  20893. var matrixWorld = this.object.matrixWorld;
  20894. var position = this.geometry.attributes.position;
  20895. //
  20896. var objGeometry = this.object.geometry;
  20897. if ( objGeometry instanceof THREE.Geometry ) {
  20898. var vertices = objGeometry.vertices;
  20899. var faces = objGeometry.faces;
  20900. var idx = 0;
  20901. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20902. var face = faces[ i ];
  20903. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  20904. var vertex = vertices[ face[ keys[ j ] ] ];
  20905. var normal = face.vertexNormals[ j ];
  20906. v1.copy( vertex ).applyMatrix4( matrixWorld );
  20907. v2.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  20908. position.setXYZ( idx, v1.x, v1.y, v1.z );
  20909. idx = idx + 1;
  20910. position.setXYZ( idx, v2.x, v2.y, v2.z );
  20911. idx = idx + 1;
  20912. }
  20913. }
  20914. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  20915. var objPos = objGeometry.attributes.position;
  20916. var objNorm = objGeometry.attributes.normal;
  20917. var idx = 0;
  20918. // for simplicity, ignore index and drawcalls, and render every normal
  20919. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  20920. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  20921. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  20922. v2.applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  20923. position.setXYZ( idx, v1.x, v1.y, v1.z );
  20924. idx = idx + 1;
  20925. position.setXYZ( idx, v2.x, v2.y, v2.z );
  20926. idx = idx + 1;
  20927. }
  20928. }
  20929. position.needsUpdate = true;
  20930. return this;
  20931. }
  20932. }());
  20933. // File:src/extras/helpers/VertexTangentsHelper.js
  20934. /**
  20935. * @author mrdoob / http://mrdoob.com/
  20936. * @author WestLangley / http://github.com/WestLangley
  20937. */
  20938. THREE.VertexTangentsHelper = function ( object, size, hex, linewidth ) {
  20939. this.object = object;
  20940. this.size = ( size !== undefined ) ? size : 1;
  20941. var color = ( hex !== undefined ) ? hex : 0x0000ff;
  20942. var width = ( linewidth !== undefined ) ? linewidth : 1;
  20943. //
  20944. var nTangents = 0;
  20945. var objGeometry = this.object.geometry;
  20946. if ( objGeometry instanceof THREE.Geometry ) {
  20947. nTangents = objGeometry.faces.length * 3;
  20948. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  20949. nTangents = objGeometry.attributes.tangent.count
  20950. }
  20951. //
  20952. var geometry = new THREE.BufferGeometry();
  20953. var positions = new THREE.Float32Attribute( nTangents * 2 * 3, 3 );
  20954. geometry.addAttribute( 'position', positions );
  20955. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  20956. //
  20957. this.matrixAutoUpdate = false;
  20958. this.update();
  20959. };
  20960. THREE.VertexTangentsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20961. THREE.VertexTangentsHelper.prototype.constructor = THREE.VertexTangentsHelper;
  20962. THREE.VertexTangentsHelper.prototype.update = ( function ( object ) {
  20963. var v1 = new THREE.Vector3();
  20964. var v2 = new THREE.Vector3();
  20965. return function() {
  20966. var keys = [ 'a', 'b', 'c' ];
  20967. this.object.updateMatrixWorld( true );
  20968. var matrixWorld = this.object.matrixWorld;
  20969. var position = this.geometry.attributes.position;
  20970. //
  20971. var objGeometry = this.object.geometry;
  20972. if ( objGeometry instanceof THREE.Geometry ) {
  20973. var vertices = objGeometry.vertices;
  20974. var faces = objGeometry.faces;
  20975. var idx = 0;
  20976. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20977. var face = faces[ i ];
  20978. for ( var j = 0, jl = face.vertexTangents.length; j < jl; j ++ ) {
  20979. var vertex = vertices[ face[ keys[ j ] ] ];
  20980. var tangent = face.vertexTangents[ j ];
  20981. v1.copy( vertex ).applyMatrix4( matrixWorld );
  20982. v2.set( tangent.x, tangent.y, tangent.z ); // tangent.w used for bitangents only
  20983. v2.transformDirection( matrixWorld ).multiplyScalar( this.size ).add( v1 );
  20984. position.setXYZ( idx, v1.x, v1.y, v1.z );
  20985. idx = idx + 1;
  20986. position.setXYZ( idx, v2.x, v2.y, v2.z );
  20987. idx = idx + 1;
  20988. }
  20989. }
  20990. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  20991. var objPos = objGeometry.attributes.position;
  20992. var objTan = objGeometry.attributes.tangent;
  20993. var idx = 0;
  20994. // for simplicity, ignore index and drawcalls, and render every tangent
  20995. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  20996. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  20997. v2.set( objTan.getX( j ), objTan.getY( j ), objTan.getZ( j ) ); // tangent.w used for bitangents only
  20998. v2.transformDirection( matrixWorld ).multiplyScalar( this.size ).add( v1 );
  20999. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21000. idx = idx + 1;
  21001. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21002. idx = idx + 1;
  21003. }
  21004. }
  21005. position.needsUpdate = true;
  21006. return this;
  21007. }
  21008. }());
  21009. // File:src/extras/helpers/WireframeHelper.js
  21010. /**
  21011. * @author mrdoob / http://mrdoob.com/
  21012. */
  21013. THREE.WireframeHelper = function ( object, hex ) {
  21014. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21015. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  21016. this.matrix = object.matrixWorld;
  21017. this.matrixAutoUpdate = false;
  21018. };
  21019. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21020. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  21021. // File:src/extras/objects/ImmediateRenderObject.js
  21022. /**
  21023. * @author alteredq / http://alteredqualia.com/
  21024. */
  21025. THREE.ImmediateRenderObject = function () {
  21026. THREE.Object3D.call( this );
  21027. this.render = function ( renderCallback ) {};
  21028. };
  21029. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  21030. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  21031. // File:src/extras/objects/MorphBlendMesh.js
  21032. /**
  21033. * @author alteredq / http://alteredqualia.com/
  21034. */
  21035. THREE.MorphBlendMesh = function( geometry, material ) {
  21036. THREE.Mesh.call( this, geometry, material );
  21037. this.animationsMap = {};
  21038. this.animationsList = [];
  21039. // prepare default animation
  21040. // (all frames played together in 1 second)
  21041. var numFrames = this.geometry.morphTargets.length;
  21042. var name = "__default";
  21043. var startFrame = 0;
  21044. var endFrame = numFrames - 1;
  21045. var fps = numFrames / 1;
  21046. this.createAnimation( name, startFrame, endFrame, fps );
  21047. this.setAnimationWeight( name, 1 );
  21048. };
  21049. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  21050. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  21051. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  21052. var animation = {
  21053. startFrame: start,
  21054. endFrame: end,
  21055. length: end - start + 1,
  21056. fps: fps,
  21057. duration: ( end - start ) / fps,
  21058. lastFrame: 0,
  21059. currentFrame: 0,
  21060. active: false,
  21061. time: 0,
  21062. direction: 1,
  21063. weight: 1,
  21064. directionBackwards: false,
  21065. mirroredLoop: false
  21066. };
  21067. this.animationsMap[ name ] = animation;
  21068. this.animationsList.push( animation );
  21069. };
  21070. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  21071. var pattern = /([a-z]+)_?(\d+)/;
  21072. var firstAnimation, frameRanges = {};
  21073. var geometry = this.geometry;
  21074. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  21075. var morph = geometry.morphTargets[ i ];
  21076. var chunks = morph.name.match( pattern );
  21077. if ( chunks && chunks.length > 1 ) {
  21078. var name = chunks[ 1 ];
  21079. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  21080. var range = frameRanges[ name ];
  21081. if ( i < range.start ) range.start = i;
  21082. if ( i > range.end ) range.end = i;
  21083. if ( ! firstAnimation ) firstAnimation = name;
  21084. }
  21085. }
  21086. for ( var name in frameRanges ) {
  21087. var range = frameRanges[ name ];
  21088. this.createAnimation( name, range.start, range.end, fps );
  21089. }
  21090. this.firstAnimation = firstAnimation;
  21091. };
  21092. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  21093. var animation = this.animationsMap[ name ];
  21094. if ( animation ) {
  21095. animation.direction = 1;
  21096. animation.directionBackwards = false;
  21097. }
  21098. };
  21099. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  21100. var animation = this.animationsMap[ name ];
  21101. if ( animation ) {
  21102. animation.direction = - 1;
  21103. animation.directionBackwards = true;
  21104. }
  21105. };
  21106. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  21107. var animation = this.animationsMap[ name ];
  21108. if ( animation ) {
  21109. animation.fps = fps;
  21110. animation.duration = ( animation.end - animation.start ) / animation.fps;
  21111. }
  21112. };
  21113. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  21114. var animation = this.animationsMap[ name ];
  21115. if ( animation ) {
  21116. animation.duration = duration;
  21117. animation.fps = ( animation.end - animation.start ) / animation.duration;
  21118. }
  21119. };
  21120. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  21121. var animation = this.animationsMap[ name ];
  21122. if ( animation ) {
  21123. animation.weight = weight;
  21124. }
  21125. };
  21126. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  21127. var animation = this.animationsMap[ name ];
  21128. if ( animation ) {
  21129. animation.time = time;
  21130. }
  21131. };
  21132. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  21133. var time = 0;
  21134. var animation = this.animationsMap[ name ];
  21135. if ( animation ) {
  21136. time = animation.time;
  21137. }
  21138. return time;
  21139. };
  21140. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  21141. var duration = - 1;
  21142. var animation = this.animationsMap[ name ];
  21143. if ( animation ) {
  21144. duration = animation.duration;
  21145. }
  21146. return duration;
  21147. };
  21148. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  21149. var animation = this.animationsMap[ name ];
  21150. if ( animation ) {
  21151. animation.time = 0;
  21152. animation.active = true;
  21153. } else {
  21154. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  21155. }
  21156. };
  21157. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  21158. var animation = this.animationsMap[ name ];
  21159. if ( animation ) {
  21160. animation.active = false;
  21161. }
  21162. };
  21163. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  21164. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  21165. var animation = this.animationsList[ i ];
  21166. if ( ! animation.active ) continue;
  21167. var frameTime = animation.duration / animation.length;
  21168. animation.time += animation.direction * delta;
  21169. if ( animation.mirroredLoop ) {
  21170. if ( animation.time > animation.duration || animation.time < 0 ) {
  21171. animation.direction *= - 1;
  21172. if ( animation.time > animation.duration ) {
  21173. animation.time = animation.duration;
  21174. animation.directionBackwards = true;
  21175. }
  21176. if ( animation.time < 0 ) {
  21177. animation.time = 0;
  21178. animation.directionBackwards = false;
  21179. }
  21180. }
  21181. } else {
  21182. animation.time = animation.time % animation.duration;
  21183. if ( animation.time < 0 ) animation.time += animation.duration;
  21184. }
  21185. var keyframe = animation.startFrame + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  21186. var weight = animation.weight;
  21187. if ( keyframe !== animation.currentFrame ) {
  21188. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  21189. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  21190. this.morphTargetInfluences[ keyframe ] = 0;
  21191. animation.lastFrame = animation.currentFrame;
  21192. animation.currentFrame = keyframe;
  21193. }
  21194. var mix = ( animation.time % frameTime ) / frameTime;
  21195. if ( animation.directionBackwards ) mix = 1 - mix;
  21196. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  21197. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  21198. }
  21199. };
粤ICP备19079148号