three.js 774 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824
  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. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  18. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  19. // GL STATE CONSTANTS
  20. THREE.CullFaceNone = 0;
  21. THREE.CullFaceBack = 1;
  22. THREE.CullFaceFront = 2;
  23. THREE.CullFaceFrontBack = 3;
  24. THREE.FrontFaceDirectionCW = 0;
  25. THREE.FrontFaceDirectionCCW = 1;
  26. // SHADOWING TYPES
  27. THREE.BasicShadowMap = 0;
  28. THREE.PCFShadowMap = 1;
  29. THREE.PCFSoftShadowMap = 2;
  30. // MATERIAL CONSTANTS
  31. // side
  32. THREE.FrontSide = 0;
  33. THREE.BackSide = 1;
  34. THREE.DoubleSide = 2;
  35. // shading
  36. THREE.NoShading = 0;
  37. THREE.FlatShading = 1;
  38. THREE.SmoothShading = 2;
  39. // colors
  40. THREE.NoColors = 0;
  41. THREE.FaceColors = 1;
  42. THREE.VertexColors = 2;
  43. // blending modes
  44. THREE.NoBlending = 0;
  45. THREE.NormalBlending = 1;
  46. THREE.AdditiveBlending = 2;
  47. THREE.SubtractiveBlending = 3;
  48. THREE.MultiplyBlending = 4;
  49. THREE.CustomBlending = 5;
  50. // custom blending equations
  51. // (numbers start from 100 not to clash with other
  52. // mappings to OpenGL constants defined in Texture.js)
  53. THREE.AddEquation = 100;
  54. THREE.SubtractEquation = 101;
  55. THREE.ReverseSubtractEquation = 102;
  56. THREE.MinEquation = 103;
  57. THREE.MaxEquation = 104;
  58. // custom blending destination factors
  59. THREE.ZeroFactor = 200;
  60. THREE.OneFactor = 201;
  61. THREE.SrcColorFactor = 202;
  62. THREE.OneMinusSrcColorFactor = 203;
  63. THREE.SrcAlphaFactor = 204;
  64. THREE.OneMinusSrcAlphaFactor = 205;
  65. THREE.DstAlphaFactor = 206;
  66. THREE.OneMinusDstAlphaFactor = 207;
  67. // custom blending source factors
  68. //THREE.ZeroFactor = 200;
  69. //THREE.OneFactor = 201;
  70. //THREE.SrcAlphaFactor = 204;
  71. //THREE.OneMinusSrcAlphaFactor = 205;
  72. //THREE.DstAlphaFactor = 206;
  73. //THREE.OneMinusDstAlphaFactor = 207;
  74. THREE.DstColorFactor = 208;
  75. THREE.OneMinusDstColorFactor = 209;
  76. THREE.SrcAlphaSaturateFactor = 210;
  77. // depth modes
  78. THREE.NeverDepth = 0;
  79. THREE.AlwaysDepth = 1;
  80. THREE.LessDepth = 2;
  81. THREE.LessEqualDepth = 3;
  82. THREE.EqualDepth = 4;
  83. THREE.GreaterEqualDepth = 5;
  84. THREE.GreaterDepth = 6;
  85. THREE.NotEqualDepth = 7;
  86. // TEXTURE CONSTANTS
  87. THREE.MultiplyOperation = 0;
  88. THREE.MixOperation = 1;
  89. THREE.AddOperation = 2;
  90. // Mapping modes
  91. THREE.UVMapping = 300;
  92. THREE.CubeReflectionMapping = 301;
  93. THREE.CubeRefractionMapping = 302;
  94. THREE.EquirectangularReflectionMapping = 303;
  95. THREE.EquirectangularRefractionMapping = 304;
  96. THREE.SphericalReflectionMapping = 305;
  97. // Wrapping modes
  98. THREE.RepeatWrapping = 1000;
  99. THREE.ClampToEdgeWrapping = 1001;
  100. THREE.MirroredRepeatWrapping = 1002;
  101. // Filters
  102. THREE.NearestFilter = 1003;
  103. THREE.NearestMipMapNearestFilter = 1004;
  104. THREE.NearestMipMapLinearFilter = 1005;
  105. THREE.LinearFilter = 1006;
  106. THREE.LinearMipMapNearestFilter = 1007;
  107. THREE.LinearMipMapLinearFilter = 1008;
  108. // Data types
  109. THREE.UnsignedByteType = 1009;
  110. THREE.ByteType = 1010;
  111. THREE.ShortType = 1011;
  112. THREE.UnsignedShortType = 1012;
  113. THREE.IntType = 1013;
  114. THREE.UnsignedIntType = 1014;
  115. THREE.FloatType = 1015;
  116. THREE.HalfFloatType = 1025;
  117. // Pixel types
  118. //THREE.UnsignedByteType = 1009;
  119. THREE.UnsignedShort4444Type = 1016;
  120. THREE.UnsignedShort5551Type = 1017;
  121. THREE.UnsignedShort565Type = 1018;
  122. // Pixel formats
  123. THREE.AlphaFormat = 1019;
  124. THREE.RGBFormat = 1020;
  125. THREE.RGBAFormat = 1021;
  126. THREE.LuminanceFormat = 1022;
  127. THREE.LuminanceAlphaFormat = 1023;
  128. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  129. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  130. // DDS / ST3C Compressed texture formats
  131. THREE.RGB_S3TC_DXT1_Format = 2001;
  132. THREE.RGBA_S3TC_DXT1_Format = 2002;
  133. THREE.RGBA_S3TC_DXT3_Format = 2003;
  134. THREE.RGBA_S3TC_DXT5_Format = 2004;
  135. // PVRTC compressed texture formats
  136. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  137. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  138. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  139. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  140. // DEPRECATED
  141. THREE.Projector = function () {
  142. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  143. this.projectVector = function ( vector, camera ) {
  144. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  145. vector.project( camera );
  146. };
  147. this.unprojectVector = function ( vector, camera ) {
  148. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  149. vector.unproject( camera );
  150. };
  151. this.pickingRay = function ( vector, camera ) {
  152. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  153. };
  154. };
  155. THREE.CanvasRenderer = function () {
  156. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  157. this.domElement = document.createElement( 'canvas' );
  158. this.clear = function () {};
  159. this.render = function () {};
  160. this.setClearColor = function () {};
  161. this.setSize = function () {};
  162. };
  163. // File:src/math/Color.js
  164. /**
  165. * @author mrdoob / http://mrdoob.com/
  166. */
  167. THREE.Color = function ( color ) {
  168. if ( arguments.length === 3 ) {
  169. return this.setRGB( arguments[ 0 ], arguments[ 1 ], arguments[ 2 ] );
  170. }
  171. return this.set( color )
  172. };
  173. THREE.Color.prototype = {
  174. constructor: THREE.Color,
  175. r: 1, g: 1, b: 1,
  176. set: function ( value ) {
  177. if ( value instanceof THREE.Color ) {
  178. this.copy( value );
  179. } else if ( typeof value === 'number' ) {
  180. this.setHex( value );
  181. } else if ( typeof value === 'string' ) {
  182. this.setStyle( value );
  183. }
  184. return this;
  185. },
  186. setHex: function ( hex ) {
  187. hex = Math.floor( hex );
  188. this.r = ( hex >> 16 & 255 ) / 255;
  189. this.g = ( hex >> 8 & 255 ) / 255;
  190. this.b = ( hex & 255 ) / 255;
  191. return this;
  192. },
  193. setRGB: function ( r, g, b ) {
  194. this.r = r;
  195. this.g = g;
  196. this.b = b;
  197. return this;
  198. },
  199. setHSL: function ( h, s, l ) {
  200. // h,s,l ranges are in 0.0 - 1.0
  201. if ( s === 0 ) {
  202. this.r = this.g = this.b = l;
  203. } else {
  204. var hue2rgb = function ( p, q, t ) {
  205. if ( t < 0 ) t += 1;
  206. if ( t > 1 ) t -= 1;
  207. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  208. if ( t < 1 / 2 ) return q;
  209. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  210. return p;
  211. };
  212. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  213. var q = ( 2 * l ) - p;
  214. this.r = hue2rgb( q, p, h + 1 / 3 );
  215. this.g = hue2rgb( q, p, h );
  216. this.b = hue2rgb( q, p, h - 1 / 3 );
  217. }
  218. return this;
  219. },
  220. setStyle: function ( style ) {
  221. // rgb(255,0,0)
  222. if ( /^rgb\((\d+), ?(\d+), ?(\d+)\)$/i.test( style ) ) {
  223. var color = /^rgb\((\d+), ?(\d+), ?(\d+)\)$/i.exec( style );
  224. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  225. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  226. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  227. return this;
  228. }
  229. // rgb(100%,0%,0%)
  230. if ( /^rgb\((\d+)\%, ?(\d+)\%, ?(\d+)\%\)$/i.test( style ) ) {
  231. var color = /^rgb\((\d+)\%, ?(\d+)\%, ?(\d+)\%\)$/i.exec( style );
  232. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  233. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  234. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  235. return this;
  236. }
  237. // #ff0000
  238. if ( /^\#([0-9a-f]{6})$/i.test( style ) ) {
  239. var color = /^\#([0-9a-f]{6})$/i.exec( style );
  240. this.setHex( parseInt( color[ 1 ], 16 ) );
  241. return this;
  242. }
  243. // #f00
  244. if ( /^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.test( style ) ) {
  245. var color = /^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec( style );
  246. this.setHex( parseInt( color[ 1 ] + color[ 1 ] + color[ 2 ] + color[ 2 ] + color[ 3 ] + color[ 3 ], 16 ) );
  247. return this;
  248. }
  249. // red
  250. if ( /^(\w+)$/i.test( style ) ) {
  251. this.setHex( THREE.ColorKeywords[ style ] );
  252. return this;
  253. }
  254. },
  255. copy: function ( color ) {
  256. this.r = color.r;
  257. this.g = color.g;
  258. this.b = color.b;
  259. return this;
  260. },
  261. copyGammaToLinear: function ( color, gammaFactor ) {
  262. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  263. this.r = Math.pow( color.r, gammaFactor );
  264. this.g = Math.pow( color.g, gammaFactor );
  265. this.b = Math.pow( color.b, gammaFactor );
  266. return this;
  267. },
  268. copyLinearToGamma: function ( color, gammaFactor ) {
  269. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  270. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  271. this.r = Math.pow( color.r, safeInverse );
  272. this.g = Math.pow( color.g, safeInverse );
  273. this.b = Math.pow( color.b, safeInverse );
  274. return this;
  275. },
  276. convertGammaToLinear: function () {
  277. var r = this.r, g = this.g, b = this.b;
  278. this.r = r * r;
  279. this.g = g * g;
  280. this.b = b * b;
  281. return this;
  282. },
  283. convertLinearToGamma: function () {
  284. this.r = Math.sqrt( this.r );
  285. this.g = Math.sqrt( this.g );
  286. this.b = Math.sqrt( this.b );
  287. return this;
  288. },
  289. getHex: function () {
  290. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  291. },
  292. getHexString: function () {
  293. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  294. },
  295. getHSL: function ( optionalTarget ) {
  296. // h,s,l ranges are in 0.0 - 1.0
  297. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  298. var r = this.r, g = this.g, b = this.b;
  299. var max = Math.max( r, g, b );
  300. var min = Math.min( r, g, b );
  301. var hue, saturation;
  302. var lightness = ( min + max ) / 2.0;
  303. if ( min === max ) {
  304. hue = 0;
  305. saturation = 0;
  306. } else {
  307. var delta = max - min;
  308. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  309. switch ( max ) {
  310. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  311. case g: hue = ( b - r ) / delta + 2; break;
  312. case b: hue = ( r - g ) / delta + 4; break;
  313. }
  314. hue /= 6;
  315. }
  316. hsl.h = hue;
  317. hsl.s = saturation;
  318. hsl.l = lightness;
  319. return hsl;
  320. },
  321. getStyle: function () {
  322. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  323. },
  324. offsetHSL: function ( h, s, l ) {
  325. var hsl = this.getHSL();
  326. hsl.h += h; hsl.s += s; hsl.l += l;
  327. this.setHSL( hsl.h, hsl.s, hsl.l );
  328. return this;
  329. },
  330. add: function ( color ) {
  331. this.r += color.r;
  332. this.g += color.g;
  333. this.b += color.b;
  334. return this;
  335. },
  336. addColors: function ( color1, color2 ) {
  337. this.r = color1.r + color2.r;
  338. this.g = color1.g + color2.g;
  339. this.b = color1.b + color2.b;
  340. return this;
  341. },
  342. addScalar: function ( s ) {
  343. this.r += s;
  344. this.g += s;
  345. this.b += s;
  346. return this;
  347. },
  348. multiply: function ( color ) {
  349. this.r *= color.r;
  350. this.g *= color.g;
  351. this.b *= color.b;
  352. return this;
  353. },
  354. multiplyScalar: function ( s ) {
  355. this.r *= s;
  356. this.g *= s;
  357. this.b *= s;
  358. return this;
  359. },
  360. lerp: function ( color, alpha ) {
  361. this.r += ( color.r - this.r ) * alpha;
  362. this.g += ( color.g - this.g ) * alpha;
  363. this.b += ( color.b - this.b ) * alpha;
  364. return this;
  365. },
  366. equals: function ( c ) {
  367. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  368. },
  369. fromArray: function ( array ) {
  370. this.r = array[ 0 ];
  371. this.g = array[ 1 ];
  372. this.b = array[ 2 ];
  373. return this;
  374. },
  375. toArray: function ( array, offset ) {
  376. if ( array === undefined ) array = [];
  377. if ( offset === undefined ) offset = 0;
  378. array[ offset ] = this.r;
  379. array[ offset + 1 ] = this.g;
  380. array[ offset + 2 ] = this.b;
  381. return array;
  382. },
  383. clone: function () {
  384. return new THREE.Color().setRGB( this.r, this.g, this.b );
  385. }
  386. };
  387. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  388. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  389. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  390. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  391. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  392. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  393. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  394. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  395. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  396. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  397. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  398. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  399. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  400. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  401. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  402. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  403. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  404. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  405. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  406. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  407. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  408. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  409. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  410. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  411. // File:src/math/Quaternion.js
  412. /**
  413. * @author mikael emtinger / http://gomo.se/
  414. * @author alteredq / http://alteredqualia.com/
  415. * @author WestLangley / http://github.com/WestLangley
  416. * @author bhouston / http://exocortex.com
  417. */
  418. THREE.Quaternion = function ( x, y, z, w ) {
  419. this._x = x || 0;
  420. this._y = y || 0;
  421. this._z = z || 0;
  422. this._w = ( w !== undefined ) ? w : 1;
  423. };
  424. THREE.Quaternion.prototype = {
  425. constructor: THREE.Quaternion,
  426. _x: 0,_y: 0, _z: 0, _w: 0,
  427. get x () {
  428. return this._x;
  429. },
  430. set x ( value ) {
  431. this._x = value;
  432. this.onChangeCallback();
  433. },
  434. get y () {
  435. return this._y;
  436. },
  437. set y ( value ) {
  438. this._y = value;
  439. this.onChangeCallback();
  440. },
  441. get z () {
  442. return this._z;
  443. },
  444. set z ( value ) {
  445. this._z = value;
  446. this.onChangeCallback();
  447. },
  448. get w () {
  449. return this._w;
  450. },
  451. set w ( value ) {
  452. this._w = value;
  453. this.onChangeCallback();
  454. },
  455. set: function ( x, y, z, w ) {
  456. this._x = x;
  457. this._y = y;
  458. this._z = z;
  459. this._w = w;
  460. this.onChangeCallback();
  461. return this;
  462. },
  463. copy: function ( quaternion ) {
  464. this._x = quaternion.x;
  465. this._y = quaternion.y;
  466. this._z = quaternion.z;
  467. this._w = quaternion.w;
  468. this.onChangeCallback();
  469. return this;
  470. },
  471. setFromEuler: function ( euler, update ) {
  472. if ( euler instanceof THREE.Euler === false ) {
  473. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  474. }
  475. // http://www.mathworks.com/matlabcentral/fileexchange/
  476. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  477. // content/SpinCalc.m
  478. var c1 = Math.cos( euler._x / 2 );
  479. var c2 = Math.cos( euler._y / 2 );
  480. var c3 = Math.cos( euler._z / 2 );
  481. var s1 = Math.sin( euler._x / 2 );
  482. var s2 = Math.sin( euler._y / 2 );
  483. var s3 = Math.sin( euler._z / 2 );
  484. if ( euler.order === 'XYZ' ) {
  485. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  486. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  487. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  488. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  489. } else if ( euler.order === 'YXZ' ) {
  490. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  491. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  492. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  493. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  494. } else if ( euler.order === 'ZXY' ) {
  495. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  496. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  497. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  498. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  499. } else if ( euler.order === 'ZYX' ) {
  500. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  501. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  502. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  503. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  504. } else if ( euler.order === 'YZX' ) {
  505. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  506. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  507. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  508. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  509. } else if ( euler.order === 'XZY' ) {
  510. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  511. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  512. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  513. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  514. }
  515. if ( update !== false ) this.onChangeCallback();
  516. return this;
  517. },
  518. setFromAxisAngle: function ( axis, angle ) {
  519. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  520. // assumes axis is normalized
  521. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  522. this._x = axis.x * s;
  523. this._y = axis.y * s;
  524. this._z = axis.z * s;
  525. this._w = Math.cos( halfAngle );
  526. this.onChangeCallback();
  527. return this;
  528. },
  529. setFromRotationMatrix: function ( m ) {
  530. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  531. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  532. var te = m.elements,
  533. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  534. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  535. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  536. trace = m11 + m22 + m33,
  537. s;
  538. if ( trace > 0 ) {
  539. s = 0.5 / Math.sqrt( trace + 1.0 );
  540. this._w = 0.25 / s;
  541. this._x = ( m32 - m23 ) * s;
  542. this._y = ( m13 - m31 ) * s;
  543. this._z = ( m21 - m12 ) * s;
  544. } else if ( m11 > m22 && m11 > m33 ) {
  545. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  546. this._w = ( m32 - m23 ) / s;
  547. this._x = 0.25 * s;
  548. this._y = ( m12 + m21 ) / s;
  549. this._z = ( m13 + m31 ) / s;
  550. } else if ( m22 > m33 ) {
  551. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  552. this._w = ( m13 - m31 ) / s;
  553. this._x = ( m12 + m21 ) / s;
  554. this._y = 0.25 * s;
  555. this._z = ( m23 + m32 ) / s;
  556. } else {
  557. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  558. this._w = ( m21 - m12 ) / s;
  559. this._x = ( m13 + m31 ) / s;
  560. this._y = ( m23 + m32 ) / s;
  561. this._z = 0.25 * s;
  562. }
  563. this.onChangeCallback();
  564. return this;
  565. },
  566. setFromUnitVectors: function () {
  567. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  568. // assumes direction vectors vFrom and vTo are normalized
  569. var v1, r;
  570. var EPS = 0.000001;
  571. return function ( vFrom, vTo ) {
  572. if ( v1 === undefined ) v1 = new THREE.Vector3();
  573. r = vFrom.dot( vTo ) + 1;
  574. if ( r < EPS ) {
  575. r = 0;
  576. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  577. v1.set( - vFrom.y, vFrom.x, 0 );
  578. } else {
  579. v1.set( 0, - vFrom.z, vFrom.y );
  580. }
  581. } else {
  582. v1.crossVectors( vFrom, vTo );
  583. }
  584. this._x = v1.x;
  585. this._y = v1.y;
  586. this._z = v1.z;
  587. this._w = r;
  588. this.normalize();
  589. return this;
  590. }
  591. }(),
  592. inverse: function () {
  593. this.conjugate().normalize();
  594. return this;
  595. },
  596. conjugate: function () {
  597. this._x *= - 1;
  598. this._y *= - 1;
  599. this._z *= - 1;
  600. this.onChangeCallback();
  601. return this;
  602. },
  603. dot: function ( v ) {
  604. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  605. },
  606. lengthSq: function () {
  607. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  608. },
  609. length: function () {
  610. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  611. },
  612. normalize: function () {
  613. var l = this.length();
  614. if ( l === 0 ) {
  615. this._x = 0;
  616. this._y = 0;
  617. this._z = 0;
  618. this._w = 1;
  619. } else {
  620. l = 1 / l;
  621. this._x = this._x * l;
  622. this._y = this._y * l;
  623. this._z = this._z * l;
  624. this._w = this._w * l;
  625. }
  626. this.onChangeCallback();
  627. return this;
  628. },
  629. multiply: function ( q, p ) {
  630. if ( p !== undefined ) {
  631. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  632. return this.multiplyQuaternions( q, p );
  633. }
  634. return this.multiplyQuaternions( this, q );
  635. },
  636. multiplyQuaternions: function ( a, b ) {
  637. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  638. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  639. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  640. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  641. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  642. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  643. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  644. this.onChangeCallback();
  645. return this;
  646. },
  647. multiplyVector3: function ( vector ) {
  648. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  649. return vector.applyQuaternion( this );
  650. },
  651. slerp: function ( qb, t ) {
  652. if ( t === 0 ) return this;
  653. if ( t === 1 ) return this.copy( qb );
  654. var x = this._x, y = this._y, z = this._z, w = this._w;
  655. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  656. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  657. if ( cosHalfTheta < 0 ) {
  658. this._w = - qb._w;
  659. this._x = - qb._x;
  660. this._y = - qb._y;
  661. this._z = - qb._z;
  662. cosHalfTheta = - cosHalfTheta;
  663. } else {
  664. this.copy( qb );
  665. }
  666. if ( cosHalfTheta >= 1.0 ) {
  667. this._w = w;
  668. this._x = x;
  669. this._y = y;
  670. this._z = z;
  671. return this;
  672. }
  673. var halfTheta = Math.acos( cosHalfTheta );
  674. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  675. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  676. this._w = 0.5 * ( w + this._w );
  677. this._x = 0.5 * ( x + this._x );
  678. this._y = 0.5 * ( y + this._y );
  679. this._z = 0.5 * ( z + this._z );
  680. return this;
  681. }
  682. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  683. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  684. this._w = ( w * ratioA + this._w * ratioB );
  685. this._x = ( x * ratioA + this._x * ratioB );
  686. this._y = ( y * ratioA + this._y * ratioB );
  687. this._z = ( z * ratioA + this._z * ratioB );
  688. this.onChangeCallback();
  689. return this;
  690. },
  691. equals: function ( quaternion ) {
  692. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  693. },
  694. fromArray: function ( array, offset ) {
  695. if ( offset === undefined ) offset = 0;
  696. this._x = array[ offset ];
  697. this._y = array[ offset + 1 ];
  698. this._z = array[ offset + 2 ];
  699. this._w = array[ offset + 3 ];
  700. this.onChangeCallback();
  701. return this;
  702. },
  703. toArray: function ( array, offset ) {
  704. if ( array === undefined ) array = [];
  705. if ( offset === undefined ) offset = 0;
  706. array[ offset ] = this._x;
  707. array[ offset + 1 ] = this._y;
  708. array[ offset + 2 ] = this._z;
  709. array[ offset + 3 ] = this._w;
  710. return array;
  711. },
  712. onChange: function ( callback ) {
  713. this.onChangeCallback = callback;
  714. return this;
  715. },
  716. onChangeCallback: function () {},
  717. clone: function () {
  718. return new THREE.Quaternion( this._x, this._y, this._z, this._w );
  719. }
  720. };
  721. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  722. return qm.copy( qa ).slerp( qb, t );
  723. };
  724. // File:src/math/Vector2.js
  725. /**
  726. * @author mrdoob / http://mrdoob.com/
  727. * @author philogb / http://blog.thejit.org/
  728. * @author egraether / http://egraether.com/
  729. * @author zz85 / http://www.lab4games.net/zz85/blog
  730. */
  731. THREE.Vector2 = function ( x, y ) {
  732. this.x = x || 0;
  733. this.y = y || 0;
  734. };
  735. THREE.Vector2.prototype = {
  736. constructor: THREE.Vector2,
  737. set: function ( x, y ) {
  738. this.x = x;
  739. this.y = y;
  740. return this;
  741. },
  742. setX: function ( x ) {
  743. this.x = x;
  744. return this;
  745. },
  746. setY: function ( y ) {
  747. this.y = y;
  748. return this;
  749. },
  750. setComponent: function ( index, value ) {
  751. switch ( index ) {
  752. case 0: this.x = value; break;
  753. case 1: this.y = value; break;
  754. default: throw new Error( 'index is out of range: ' + index );
  755. }
  756. },
  757. getComponent: function ( index ) {
  758. switch ( index ) {
  759. case 0: return this.x;
  760. case 1: return this.y;
  761. default: throw new Error( 'index is out of range: ' + index );
  762. }
  763. },
  764. copy: function ( v ) {
  765. this.x = v.x;
  766. this.y = v.y;
  767. return this;
  768. },
  769. add: function ( v, w ) {
  770. if ( w !== undefined ) {
  771. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  772. return this.addVectors( v, w );
  773. }
  774. this.x += v.x;
  775. this.y += v.y;
  776. return this;
  777. },
  778. addScalar: function ( s ) {
  779. this.x += s;
  780. this.y += s;
  781. return this;
  782. },
  783. addVectors: function ( a, b ) {
  784. this.x = a.x + b.x;
  785. this.y = a.y + b.y;
  786. return this;
  787. },
  788. sub: function ( v, w ) {
  789. if ( w !== undefined ) {
  790. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  791. return this.subVectors( v, w );
  792. }
  793. this.x -= v.x;
  794. this.y -= v.y;
  795. return this;
  796. },
  797. subScalar: function ( s ) {
  798. this.x -= s;
  799. this.y -= s;
  800. return this;
  801. },
  802. subVectors: function ( a, b ) {
  803. this.x = a.x - b.x;
  804. this.y = a.y - b.y;
  805. return this;
  806. },
  807. multiply: function ( v ) {
  808. this.x *= v.x;
  809. this.y *= v.y;
  810. return this;
  811. },
  812. multiplyScalar: function ( s ) {
  813. this.x *= s;
  814. this.y *= s;
  815. return this;
  816. },
  817. divide: function ( v ) {
  818. this.x /= v.x;
  819. this.y /= v.y;
  820. return this;
  821. },
  822. divideScalar: function ( scalar ) {
  823. if ( scalar !== 0 ) {
  824. var invScalar = 1 / scalar;
  825. this.x *= invScalar;
  826. this.y *= invScalar;
  827. } else {
  828. this.x = 0;
  829. this.y = 0;
  830. }
  831. return this;
  832. },
  833. min: function ( v ) {
  834. if ( this.x > v.x ) {
  835. this.x = v.x;
  836. }
  837. if ( this.y > v.y ) {
  838. this.y = v.y;
  839. }
  840. return this;
  841. },
  842. max: function ( v ) {
  843. if ( this.x < v.x ) {
  844. this.x = v.x;
  845. }
  846. if ( this.y < v.y ) {
  847. this.y = v.y;
  848. }
  849. return this;
  850. },
  851. clamp: function ( min, max ) {
  852. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  853. if ( this.x < min.x ) {
  854. this.x = min.x;
  855. } else if ( this.x > max.x ) {
  856. this.x = max.x;
  857. }
  858. if ( this.y < min.y ) {
  859. this.y = min.y;
  860. } else if ( this.y > max.y ) {
  861. this.y = max.y;
  862. }
  863. return this;
  864. },
  865. clampScalar: ( function () {
  866. var min, max;
  867. return function ( minVal, maxVal ) {
  868. if ( min === undefined ) {
  869. min = new THREE.Vector2();
  870. max = new THREE.Vector2();
  871. }
  872. min.set( minVal, minVal );
  873. max.set( maxVal, maxVal );
  874. return this.clamp( min, max );
  875. };
  876. } )(),
  877. floor: function () {
  878. this.x = Math.floor( this.x );
  879. this.y = Math.floor( this.y );
  880. return this;
  881. },
  882. ceil: function () {
  883. this.x = Math.ceil( this.x );
  884. this.y = Math.ceil( this.y );
  885. return this;
  886. },
  887. round: function () {
  888. this.x = Math.round( this.x );
  889. this.y = Math.round( this.y );
  890. return this;
  891. },
  892. roundToZero: function () {
  893. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  894. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  895. return this;
  896. },
  897. negate: function () {
  898. this.x = - this.x;
  899. this.y = - this.y;
  900. return this;
  901. },
  902. dot: function ( v ) {
  903. return this.x * v.x + this.y * v.y;
  904. },
  905. lengthSq: function () {
  906. return this.x * this.x + this.y * this.y;
  907. },
  908. length: function () {
  909. return Math.sqrt( this.x * this.x + this.y * this.y );
  910. },
  911. normalize: function () {
  912. return this.divideScalar( this.length() );
  913. },
  914. distanceTo: function ( v ) {
  915. return Math.sqrt( this.distanceToSquared( v ) );
  916. },
  917. distanceToSquared: function ( v ) {
  918. var dx = this.x - v.x, dy = this.y - v.y;
  919. return dx * dx + dy * dy;
  920. },
  921. setLength: function ( l ) {
  922. var oldLength = this.length();
  923. if ( oldLength !== 0 && l !== oldLength ) {
  924. this.multiplyScalar( l / oldLength );
  925. }
  926. return this;
  927. },
  928. lerp: function ( v, alpha ) {
  929. this.x += ( v.x - this.x ) * alpha;
  930. this.y += ( v.y - this.y ) * alpha;
  931. return this;
  932. },
  933. lerpVectors: function ( v1, v2, alpha ) {
  934. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  935. return this;
  936. },
  937. equals: function ( v ) {
  938. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  939. },
  940. fromArray: function ( array, offset ) {
  941. if ( offset === undefined ) offset = 0;
  942. this.x = array[ offset ];
  943. this.y = array[ offset + 1 ];
  944. return this;
  945. },
  946. toArray: function ( array, offset ) {
  947. if ( array === undefined ) array = [];
  948. if ( offset === undefined ) offset = 0;
  949. array[ offset ] = this.x;
  950. array[ offset + 1 ] = this.y;
  951. return array;
  952. },
  953. fromAttribute: function ( attribute, index, offset ) {
  954. if ( offset === undefined ) offset = 0;
  955. index = index * attribute.itemSize + offset;
  956. this.x = attribute.array[ index ];
  957. this.y = attribute.array[ index + 1 ];
  958. return this;
  959. },
  960. clone: function () {
  961. return new THREE.Vector2( this.x, this.y );
  962. }
  963. };
  964. // File:src/math/Vector3.js
  965. /**
  966. * @author mrdoob / http://mrdoob.com/
  967. * @author *kile / http://kile.stravaganza.org/
  968. * @author philogb / http://blog.thejit.org/
  969. * @author mikael emtinger / http://gomo.se/
  970. * @author egraether / http://egraether.com/
  971. * @author WestLangley / http://github.com/WestLangley
  972. */
  973. THREE.Vector3 = function ( x, y, z ) {
  974. this.x = x || 0;
  975. this.y = y || 0;
  976. this.z = z || 0;
  977. };
  978. THREE.Vector3.prototype = {
  979. constructor: THREE.Vector3,
  980. set: function ( x, y, z ) {
  981. this.x = x;
  982. this.y = y;
  983. this.z = z;
  984. return this;
  985. },
  986. setX: function ( x ) {
  987. this.x = x;
  988. return this;
  989. },
  990. setY: function ( y ) {
  991. this.y = y;
  992. return this;
  993. },
  994. setZ: function ( z ) {
  995. this.z = z;
  996. return this;
  997. },
  998. setComponent: function ( index, value ) {
  999. switch ( index ) {
  1000. case 0: this.x = value; break;
  1001. case 1: this.y = value; break;
  1002. case 2: this.z = value; break;
  1003. default: throw new Error( 'index is out of range: ' + index );
  1004. }
  1005. },
  1006. getComponent: function ( index ) {
  1007. switch ( index ) {
  1008. case 0: return this.x;
  1009. case 1: return this.y;
  1010. case 2: return this.z;
  1011. default: throw new Error( 'index is out of range: ' + index );
  1012. }
  1013. },
  1014. copy: function ( v ) {
  1015. this.x = v.x;
  1016. this.y = v.y;
  1017. this.z = v.z;
  1018. return this;
  1019. },
  1020. add: function ( v, w ) {
  1021. if ( w !== undefined ) {
  1022. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1023. return this.addVectors( v, w );
  1024. }
  1025. this.x += v.x;
  1026. this.y += v.y;
  1027. this.z += v.z;
  1028. return this;
  1029. },
  1030. addScalar: function ( s ) {
  1031. this.x += s;
  1032. this.y += s;
  1033. this.z += s;
  1034. return this;
  1035. },
  1036. addVectors: function ( a, b ) {
  1037. this.x = a.x + b.x;
  1038. this.y = a.y + b.y;
  1039. this.z = a.z + b.z;
  1040. return this;
  1041. },
  1042. sub: function ( v, w ) {
  1043. if ( w !== undefined ) {
  1044. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1045. return this.subVectors( v, w );
  1046. }
  1047. this.x -= v.x;
  1048. this.y -= v.y;
  1049. this.z -= v.z;
  1050. return this;
  1051. },
  1052. subScalar: function ( s ) {
  1053. this.x -= s;
  1054. this.y -= s;
  1055. this.z -= s;
  1056. return this;
  1057. },
  1058. subVectors: function ( a, b ) {
  1059. this.x = a.x - b.x;
  1060. this.y = a.y - b.y;
  1061. this.z = a.z - b.z;
  1062. return this;
  1063. },
  1064. multiply: function ( v, w ) {
  1065. if ( w !== undefined ) {
  1066. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1067. return this.multiplyVectors( v, w );
  1068. }
  1069. this.x *= v.x;
  1070. this.y *= v.y;
  1071. this.z *= v.z;
  1072. return this;
  1073. },
  1074. multiplyScalar: function ( scalar ) {
  1075. this.x *= scalar;
  1076. this.y *= scalar;
  1077. this.z *= scalar;
  1078. return this;
  1079. },
  1080. multiplyVectors: function ( a, b ) {
  1081. this.x = a.x * b.x;
  1082. this.y = a.y * b.y;
  1083. this.z = a.z * b.z;
  1084. return this;
  1085. },
  1086. applyEuler: function () {
  1087. var quaternion;
  1088. return function ( euler ) {
  1089. if ( euler instanceof THREE.Euler === false ) {
  1090. console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  1091. }
  1092. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1093. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1094. return this;
  1095. };
  1096. }(),
  1097. applyAxisAngle: function () {
  1098. var quaternion;
  1099. return function ( axis, angle ) {
  1100. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1101. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1102. return this;
  1103. };
  1104. }(),
  1105. applyMatrix3: function ( m ) {
  1106. var x = this.x;
  1107. var y = this.y;
  1108. var z = this.z;
  1109. var e = m.elements;
  1110. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1111. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1112. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1113. return this;
  1114. },
  1115. applyMatrix4: function ( m ) {
  1116. // input: THREE.Matrix4 affine matrix
  1117. var x = this.x, y = this.y, z = this.z;
  1118. var e = m.elements;
  1119. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1120. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1121. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1122. return this;
  1123. },
  1124. applyProjection: function ( m ) {
  1125. // input: THREE.Matrix4 projection matrix
  1126. var x = this.x, y = this.y, z = this.z;
  1127. var e = m.elements;
  1128. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1129. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1130. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1131. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1132. return this;
  1133. },
  1134. applyQuaternion: function ( q ) {
  1135. var x = this.x;
  1136. var y = this.y;
  1137. var z = this.z;
  1138. var qx = q.x;
  1139. var qy = q.y;
  1140. var qz = q.z;
  1141. var qw = q.w;
  1142. // calculate quat * vector
  1143. var ix = qw * x + qy * z - qz * y;
  1144. var iy = qw * y + qz * x - qx * z;
  1145. var iz = qw * z + qx * y - qy * x;
  1146. var iw = - qx * x - qy * y - qz * z;
  1147. // calculate result * inverse quat
  1148. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1149. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1150. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1151. return this;
  1152. },
  1153. project: function () {
  1154. var matrix;
  1155. return function ( camera ) {
  1156. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1157. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1158. return this.applyProjection( matrix );
  1159. };
  1160. }(),
  1161. unproject: function () {
  1162. var matrix;
  1163. return function ( camera ) {
  1164. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1165. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1166. return this.applyProjection( matrix );
  1167. };
  1168. }(),
  1169. transformDirection: function ( m ) {
  1170. // input: THREE.Matrix4 affine matrix
  1171. // vector interpreted as a direction
  1172. var x = this.x, y = this.y, z = this.z;
  1173. var e = m.elements;
  1174. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1175. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1176. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1177. this.normalize();
  1178. return this;
  1179. },
  1180. divide: function ( v ) {
  1181. this.x /= v.x;
  1182. this.y /= v.y;
  1183. this.z /= v.z;
  1184. return this;
  1185. },
  1186. divideScalar: function ( scalar ) {
  1187. if ( scalar !== 0 ) {
  1188. var invScalar = 1 / scalar;
  1189. this.x *= invScalar;
  1190. this.y *= invScalar;
  1191. this.z *= invScalar;
  1192. } else {
  1193. this.x = 0;
  1194. this.y = 0;
  1195. this.z = 0;
  1196. }
  1197. return this;
  1198. },
  1199. min: function ( v ) {
  1200. if ( this.x > v.x ) {
  1201. this.x = v.x;
  1202. }
  1203. if ( this.y > v.y ) {
  1204. this.y = v.y;
  1205. }
  1206. if ( this.z > v.z ) {
  1207. this.z = v.z;
  1208. }
  1209. return this;
  1210. },
  1211. max: function ( v ) {
  1212. if ( this.x < v.x ) {
  1213. this.x = v.x;
  1214. }
  1215. if ( this.y < v.y ) {
  1216. this.y = v.y;
  1217. }
  1218. if ( this.z < v.z ) {
  1219. this.z = v.z;
  1220. }
  1221. return this;
  1222. },
  1223. clamp: function ( min, max ) {
  1224. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1225. if ( this.x < min.x ) {
  1226. this.x = min.x;
  1227. } else if ( this.x > max.x ) {
  1228. this.x = max.x;
  1229. }
  1230. if ( this.y < min.y ) {
  1231. this.y = min.y;
  1232. } else if ( this.y > max.y ) {
  1233. this.y = max.y;
  1234. }
  1235. if ( this.z < min.z ) {
  1236. this.z = min.z;
  1237. } else if ( this.z > max.z ) {
  1238. this.z = max.z;
  1239. }
  1240. return this;
  1241. },
  1242. clampScalar: ( function () {
  1243. var min, max;
  1244. return function ( minVal, maxVal ) {
  1245. if ( min === undefined ) {
  1246. min = new THREE.Vector3();
  1247. max = new THREE.Vector3();
  1248. }
  1249. min.set( minVal, minVal, minVal );
  1250. max.set( maxVal, maxVal, maxVal );
  1251. return this.clamp( min, max );
  1252. };
  1253. } )(),
  1254. floor: function () {
  1255. this.x = Math.floor( this.x );
  1256. this.y = Math.floor( this.y );
  1257. this.z = Math.floor( this.z );
  1258. return this;
  1259. },
  1260. ceil: function () {
  1261. this.x = Math.ceil( this.x );
  1262. this.y = Math.ceil( this.y );
  1263. this.z = Math.ceil( this.z );
  1264. return this;
  1265. },
  1266. round: function () {
  1267. this.x = Math.round( this.x );
  1268. this.y = Math.round( this.y );
  1269. this.z = Math.round( this.z );
  1270. return this;
  1271. },
  1272. roundToZero: function () {
  1273. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1274. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1275. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1276. return this;
  1277. },
  1278. negate: function () {
  1279. this.x = - this.x;
  1280. this.y = - this.y;
  1281. this.z = - this.z;
  1282. return this;
  1283. },
  1284. dot: function ( v ) {
  1285. return this.x * v.x + this.y * v.y + this.z * v.z;
  1286. },
  1287. lengthSq: function () {
  1288. return this.x * this.x + this.y * this.y + this.z * this.z;
  1289. },
  1290. length: function () {
  1291. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1292. },
  1293. lengthManhattan: function () {
  1294. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1295. },
  1296. normalize: function () {
  1297. return this.divideScalar( this.length() );
  1298. },
  1299. setLength: function ( l ) {
  1300. var oldLength = this.length();
  1301. if ( oldLength !== 0 && l !== oldLength ) {
  1302. this.multiplyScalar( l / oldLength );
  1303. }
  1304. return this;
  1305. },
  1306. lerp: function ( v, alpha ) {
  1307. this.x += ( v.x - this.x ) * alpha;
  1308. this.y += ( v.y - this.y ) * alpha;
  1309. this.z += ( v.z - this.z ) * alpha;
  1310. return this;
  1311. },
  1312. lerpVectors: function ( v1, v2, alpha ) {
  1313. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1314. return this;
  1315. },
  1316. cross: function ( v, w ) {
  1317. if ( w !== undefined ) {
  1318. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1319. return this.crossVectors( v, w );
  1320. }
  1321. var x = this.x, y = this.y, z = this.z;
  1322. this.x = y * v.z - z * v.y;
  1323. this.y = z * v.x - x * v.z;
  1324. this.z = x * v.y - y * v.x;
  1325. return this;
  1326. },
  1327. crossVectors: function ( a, b ) {
  1328. var ax = a.x, ay = a.y, az = a.z;
  1329. var bx = b.x, by = b.y, bz = b.z;
  1330. this.x = ay * bz - az * by;
  1331. this.y = az * bx - ax * bz;
  1332. this.z = ax * by - ay * bx;
  1333. return this;
  1334. },
  1335. projectOnVector: function () {
  1336. var v1, dot;
  1337. return function ( vector ) {
  1338. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1339. v1.copy( vector ).normalize();
  1340. dot = this.dot( v1 );
  1341. return this.copy( v1 ).multiplyScalar( dot );
  1342. };
  1343. }(),
  1344. projectOnPlane: function () {
  1345. var v1;
  1346. return function ( planeNormal ) {
  1347. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1348. v1.copy( this ).projectOnVector( planeNormal );
  1349. return this.sub( v1 );
  1350. }
  1351. }(),
  1352. reflect: function () {
  1353. // reflect incident vector off plane orthogonal to normal
  1354. // normal is assumed to have unit length
  1355. var v1;
  1356. return function ( normal ) {
  1357. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1358. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1359. }
  1360. }(),
  1361. angleTo: function ( v ) {
  1362. var theta = this.dot( v ) / ( this.length() * v.length() );
  1363. // clamp, to handle numerical problems
  1364. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1365. },
  1366. distanceTo: function ( v ) {
  1367. return Math.sqrt( this.distanceToSquared( v ) );
  1368. },
  1369. distanceToSquared: function ( v ) {
  1370. var dx = this.x - v.x;
  1371. var dy = this.y - v.y;
  1372. var dz = this.z - v.z;
  1373. return dx * dx + dy * dy + dz * dz;
  1374. },
  1375. setEulerFromRotationMatrix: function ( m, order ) {
  1376. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  1377. },
  1378. setEulerFromQuaternion: function ( q, order ) {
  1379. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  1380. },
  1381. getPositionFromMatrix: function ( m ) {
  1382. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  1383. return this.setFromMatrixPosition( m );
  1384. },
  1385. getScaleFromMatrix: function ( m ) {
  1386. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  1387. return this.setFromMatrixScale( m );
  1388. },
  1389. getColumnFromMatrix: function ( index, matrix ) {
  1390. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  1391. return this.setFromMatrixColumn( index, matrix );
  1392. },
  1393. setFromMatrixPosition: function ( m ) {
  1394. this.x = m.elements[ 12 ];
  1395. this.y = m.elements[ 13 ];
  1396. this.z = m.elements[ 14 ];
  1397. return this;
  1398. },
  1399. setFromMatrixScale: function ( m ) {
  1400. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1401. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1402. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1403. this.x = sx;
  1404. this.y = sy;
  1405. this.z = sz;
  1406. return this;
  1407. },
  1408. setFromMatrixColumn: function ( index, matrix ) {
  1409. var offset = index * 4;
  1410. var me = matrix.elements;
  1411. this.x = me[ offset ];
  1412. this.y = me[ offset + 1 ];
  1413. this.z = me[ offset + 2 ];
  1414. return this;
  1415. },
  1416. equals: function ( v ) {
  1417. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1418. },
  1419. fromArray: function ( array, offset ) {
  1420. if ( offset === undefined ) offset = 0;
  1421. this.x = array[ offset ];
  1422. this.y = array[ offset + 1 ];
  1423. this.z = array[ offset + 2 ];
  1424. return this;
  1425. },
  1426. toArray: function ( array, offset ) {
  1427. if ( array === undefined ) array = [];
  1428. if ( offset === undefined ) offset = 0;
  1429. array[ offset ] = this.x;
  1430. array[ offset + 1 ] = this.y;
  1431. array[ offset + 2 ] = this.z;
  1432. return array;
  1433. },
  1434. fromAttribute: function ( attribute, index, offset ) {
  1435. if ( offset === undefined ) offset = 0;
  1436. index = index * attribute.itemSize + offset;
  1437. this.x = attribute.array[ index ];
  1438. this.y = attribute.array[ index + 1 ];
  1439. this.z = attribute.array[ index + 2 ];
  1440. return this;
  1441. },
  1442. clone: function () {
  1443. return new THREE.Vector3( this.x, this.y, this.z );
  1444. }
  1445. };
  1446. // File:src/math/Vector4.js
  1447. /**
  1448. * @author supereggbert / http://www.paulbrunt.co.uk/
  1449. * @author philogb / http://blog.thejit.org/
  1450. * @author mikael emtinger / http://gomo.se/
  1451. * @author egraether / http://egraether.com/
  1452. * @author WestLangley / http://github.com/WestLangley
  1453. */
  1454. THREE.Vector4 = function ( x, y, z, w ) {
  1455. this.x = x || 0;
  1456. this.y = y || 0;
  1457. this.z = z || 0;
  1458. this.w = ( w !== undefined ) ? w : 1;
  1459. };
  1460. THREE.Vector4.prototype = {
  1461. constructor: THREE.Vector4,
  1462. set: function ( x, y, z, w ) {
  1463. this.x = x;
  1464. this.y = y;
  1465. this.z = z;
  1466. this.w = w;
  1467. return this;
  1468. },
  1469. setX: function ( x ) {
  1470. this.x = x;
  1471. return this;
  1472. },
  1473. setY: function ( y ) {
  1474. this.y = y;
  1475. return this;
  1476. },
  1477. setZ: function ( z ) {
  1478. this.z = z;
  1479. return this;
  1480. },
  1481. setW: function ( w ) {
  1482. this.w = w;
  1483. return this;
  1484. },
  1485. setComponent: function ( index, value ) {
  1486. switch ( index ) {
  1487. case 0: this.x = value; break;
  1488. case 1: this.y = value; break;
  1489. case 2: this.z = value; break;
  1490. case 3: this.w = value; break;
  1491. default: throw new Error( 'index is out of range: ' + index );
  1492. }
  1493. },
  1494. getComponent: function ( index ) {
  1495. switch ( index ) {
  1496. case 0: return this.x;
  1497. case 1: return this.y;
  1498. case 2: return this.z;
  1499. case 3: return this.w;
  1500. default: throw new Error( 'index is out of range: ' + index );
  1501. }
  1502. },
  1503. copy: function ( v ) {
  1504. this.x = v.x;
  1505. this.y = v.y;
  1506. this.z = v.z;
  1507. this.w = ( v.w !== undefined ) ? v.w : 1;
  1508. return this;
  1509. },
  1510. add: function ( v, w ) {
  1511. if ( w !== undefined ) {
  1512. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1513. return this.addVectors( v, w );
  1514. }
  1515. this.x += v.x;
  1516. this.y += v.y;
  1517. this.z += v.z;
  1518. this.w += v.w;
  1519. return this;
  1520. },
  1521. addScalar: function ( s ) {
  1522. this.x += s;
  1523. this.y += s;
  1524. this.z += s;
  1525. this.w += s;
  1526. return this;
  1527. },
  1528. addVectors: function ( a, b ) {
  1529. this.x = a.x + b.x;
  1530. this.y = a.y + b.y;
  1531. this.z = a.z + b.z;
  1532. this.w = a.w + b.w;
  1533. return this;
  1534. },
  1535. sub: function ( v, w ) {
  1536. if ( w !== undefined ) {
  1537. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1538. return this.subVectors( v, w );
  1539. }
  1540. this.x -= v.x;
  1541. this.y -= v.y;
  1542. this.z -= v.z;
  1543. this.w -= v.w;
  1544. return this;
  1545. },
  1546. subScalar: function ( s ) {
  1547. this.x -= s;
  1548. this.y -= s;
  1549. this.z -= s;
  1550. this.w -= s;
  1551. return this;
  1552. },
  1553. subVectors: function ( a, b ) {
  1554. this.x = a.x - b.x;
  1555. this.y = a.y - b.y;
  1556. this.z = a.z - b.z;
  1557. this.w = a.w - b.w;
  1558. return this;
  1559. },
  1560. multiplyScalar: function ( scalar ) {
  1561. this.x *= scalar;
  1562. this.y *= scalar;
  1563. this.z *= scalar;
  1564. this.w *= scalar;
  1565. return this;
  1566. },
  1567. applyMatrix4: function ( m ) {
  1568. var x = this.x;
  1569. var y = this.y;
  1570. var z = this.z;
  1571. var w = this.w;
  1572. var e = m.elements;
  1573. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1574. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1575. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1576. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1577. return this;
  1578. },
  1579. divideScalar: function ( scalar ) {
  1580. if ( scalar !== 0 ) {
  1581. var invScalar = 1 / scalar;
  1582. this.x *= invScalar;
  1583. this.y *= invScalar;
  1584. this.z *= invScalar;
  1585. this.w *= invScalar;
  1586. } else {
  1587. this.x = 0;
  1588. this.y = 0;
  1589. this.z = 0;
  1590. this.w = 1;
  1591. }
  1592. return this;
  1593. },
  1594. setAxisAngleFromQuaternion: function ( q ) {
  1595. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1596. // q is assumed to be normalized
  1597. this.w = 2 * Math.acos( q.w );
  1598. var s = Math.sqrt( 1 - q.w * q.w );
  1599. if ( s < 0.0001 ) {
  1600. this.x = 1;
  1601. this.y = 0;
  1602. this.z = 0;
  1603. } else {
  1604. this.x = q.x / s;
  1605. this.y = q.y / s;
  1606. this.z = q.z / s;
  1607. }
  1608. return this;
  1609. },
  1610. setAxisAngleFromRotationMatrix: function ( m ) {
  1611. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1612. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1613. var angle, x, y, z, // variables for result
  1614. epsilon = 0.01, // margin to allow for rounding errors
  1615. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1616. te = m.elements,
  1617. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1618. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1619. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1620. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1621. && ( Math.abs( m13 - m31 ) < epsilon )
  1622. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1623. // singularity found
  1624. // first check for identity matrix which must have +1 for all terms
  1625. // in leading diagonal and zero in other terms
  1626. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1627. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1628. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1629. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1630. // this singularity is identity matrix so angle = 0
  1631. this.set( 1, 0, 0, 0 );
  1632. return this; // zero angle, arbitrary axis
  1633. }
  1634. // otherwise this singularity is angle = 180
  1635. angle = Math.PI;
  1636. var xx = ( m11 + 1 ) / 2;
  1637. var yy = ( m22 + 1 ) / 2;
  1638. var zz = ( m33 + 1 ) / 2;
  1639. var xy = ( m12 + m21 ) / 4;
  1640. var xz = ( m13 + m31 ) / 4;
  1641. var yz = ( m23 + m32 ) / 4;
  1642. if ( ( xx > yy ) && ( xx > zz ) ) { // m11 is the largest diagonal term
  1643. if ( xx < epsilon ) {
  1644. x = 0;
  1645. y = 0.707106781;
  1646. z = 0.707106781;
  1647. } else {
  1648. x = Math.sqrt( xx );
  1649. y = xy / x;
  1650. z = xz / x;
  1651. }
  1652. } else if ( yy > zz ) { // m22 is the largest diagonal term
  1653. if ( yy < epsilon ) {
  1654. x = 0.707106781;
  1655. y = 0;
  1656. z = 0.707106781;
  1657. } else {
  1658. y = Math.sqrt( yy );
  1659. x = xy / y;
  1660. z = yz / y;
  1661. }
  1662. } else { // m33 is the largest diagonal term so base result on this
  1663. if ( zz < epsilon ) {
  1664. x = 0.707106781;
  1665. y = 0.707106781;
  1666. z = 0;
  1667. } else {
  1668. z = Math.sqrt( zz );
  1669. x = xz / z;
  1670. y = yz / z;
  1671. }
  1672. }
  1673. this.set( x, y, z, angle );
  1674. return this; // return 180 deg rotation
  1675. }
  1676. // as we have reached here there are no singularities so we can handle normally
  1677. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1678. + ( m13 - m31 ) * ( m13 - m31 )
  1679. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1680. if ( Math.abs( s ) < 0.001 ) s = 1;
  1681. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1682. // caught by singularity test above, but I've left it in just in case
  1683. this.x = ( m32 - m23 ) / s;
  1684. this.y = ( m13 - m31 ) / s;
  1685. this.z = ( m21 - m12 ) / s;
  1686. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1687. return this;
  1688. },
  1689. min: function ( v ) {
  1690. if ( this.x > v.x ) {
  1691. this.x = v.x;
  1692. }
  1693. if ( this.y > v.y ) {
  1694. this.y = v.y;
  1695. }
  1696. if ( this.z > v.z ) {
  1697. this.z = v.z;
  1698. }
  1699. if ( this.w > v.w ) {
  1700. this.w = v.w;
  1701. }
  1702. return this;
  1703. },
  1704. max: function ( v ) {
  1705. if ( this.x < v.x ) {
  1706. this.x = v.x;
  1707. }
  1708. if ( this.y < v.y ) {
  1709. this.y = v.y;
  1710. }
  1711. if ( this.z < v.z ) {
  1712. this.z = v.z;
  1713. }
  1714. if ( this.w < v.w ) {
  1715. this.w = v.w;
  1716. }
  1717. return this;
  1718. },
  1719. clamp: function ( min, max ) {
  1720. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1721. if ( this.x < min.x ) {
  1722. this.x = min.x;
  1723. } else if ( this.x > max.x ) {
  1724. this.x = max.x;
  1725. }
  1726. if ( this.y < min.y ) {
  1727. this.y = min.y;
  1728. } else if ( this.y > max.y ) {
  1729. this.y = max.y;
  1730. }
  1731. if ( this.z < min.z ) {
  1732. this.z = min.z;
  1733. } else if ( this.z > max.z ) {
  1734. this.z = max.z;
  1735. }
  1736. if ( this.w < min.w ) {
  1737. this.w = min.w;
  1738. } else if ( this.w > max.w ) {
  1739. this.w = max.w;
  1740. }
  1741. return this;
  1742. },
  1743. clampScalar: ( function () {
  1744. var min, max;
  1745. return function ( minVal, maxVal ) {
  1746. if ( min === undefined ) {
  1747. min = new THREE.Vector4();
  1748. max = new THREE.Vector4();
  1749. }
  1750. min.set( minVal, minVal, minVal, minVal );
  1751. max.set( maxVal, maxVal, maxVal, maxVal );
  1752. return this.clamp( min, max );
  1753. };
  1754. } )(),
  1755. floor: function () {
  1756. this.x = Math.floor( this.x );
  1757. this.y = Math.floor( this.y );
  1758. this.z = Math.floor( this.z );
  1759. this.w = Math.floor( this.w );
  1760. return this;
  1761. },
  1762. ceil: function () {
  1763. this.x = Math.ceil( this.x );
  1764. this.y = Math.ceil( this.y );
  1765. this.z = Math.ceil( this.z );
  1766. this.w = Math.ceil( this.w );
  1767. return this;
  1768. },
  1769. round: function () {
  1770. this.x = Math.round( this.x );
  1771. this.y = Math.round( this.y );
  1772. this.z = Math.round( this.z );
  1773. this.w = Math.round( this.w );
  1774. return this;
  1775. },
  1776. roundToZero: function () {
  1777. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1778. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1779. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1780. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1781. return this;
  1782. },
  1783. negate: function () {
  1784. this.x = - this.x;
  1785. this.y = - this.y;
  1786. this.z = - this.z;
  1787. this.w = - this.w;
  1788. return this;
  1789. },
  1790. dot: function ( v ) {
  1791. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1792. },
  1793. lengthSq: function () {
  1794. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1795. },
  1796. length: function () {
  1797. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1798. },
  1799. lengthManhattan: function () {
  1800. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1801. },
  1802. normalize: function () {
  1803. return this.divideScalar( this.length() );
  1804. },
  1805. setLength: function ( l ) {
  1806. var oldLength = this.length();
  1807. if ( oldLength !== 0 && l !== oldLength ) {
  1808. this.multiplyScalar( l / oldLength );
  1809. }
  1810. return this;
  1811. },
  1812. lerp: function ( v, alpha ) {
  1813. this.x += ( v.x - this.x ) * alpha;
  1814. this.y += ( v.y - this.y ) * alpha;
  1815. this.z += ( v.z - this.z ) * alpha;
  1816. this.w += ( v.w - this.w ) * alpha;
  1817. return this;
  1818. },
  1819. lerpVectors: function ( v1, v2, alpha ) {
  1820. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1821. return this;
  1822. },
  1823. equals: function ( v ) {
  1824. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1825. },
  1826. fromArray: function ( array, offset ) {
  1827. if ( offset === undefined ) offset = 0;
  1828. this.x = array[ offset ];
  1829. this.y = array[ offset + 1 ];
  1830. this.z = array[ offset + 2 ];
  1831. this.w = array[ offset + 3 ];
  1832. return this;
  1833. },
  1834. toArray: function ( array, offset ) {
  1835. if ( array === undefined ) array = [];
  1836. if ( offset === undefined ) offset = 0;
  1837. array[ offset ] = this.x;
  1838. array[ offset + 1 ] = this.y;
  1839. array[ offset + 2 ] = this.z;
  1840. array[ offset + 3 ] = this.w;
  1841. return array;
  1842. },
  1843. fromAttribute: function ( attribute, index, offset ) {
  1844. if ( offset === undefined ) offset = 0;
  1845. index = index * attribute.itemSize + offset;
  1846. this.x = attribute.array[ index ];
  1847. this.y = attribute.array[ index + 1 ];
  1848. this.z = attribute.array[ index + 2 ];
  1849. this.w = attribute.array[ index + 3 ];
  1850. return this;
  1851. },
  1852. clone: function () {
  1853. return new THREE.Vector4( this.x, this.y, this.z, this.w );
  1854. }
  1855. };
  1856. // File:src/math/Euler.js
  1857. /**
  1858. * @author mrdoob / http://mrdoob.com/
  1859. * @author WestLangley / http://github.com/WestLangley
  1860. * @author bhouston / http://exocortex.com
  1861. */
  1862. THREE.Euler = function ( x, y, z, order ) {
  1863. this._x = x || 0;
  1864. this._y = y || 0;
  1865. this._z = z || 0;
  1866. this._order = order || THREE.Euler.DefaultOrder;
  1867. };
  1868. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1869. THREE.Euler.DefaultOrder = 'XYZ';
  1870. THREE.Euler.prototype = {
  1871. constructor: THREE.Euler,
  1872. _x: 0, _y: 0, _z: 0, _order: THREE.Euler.DefaultOrder,
  1873. get x () {
  1874. return this._x;
  1875. },
  1876. set x ( value ) {
  1877. this._x = value;
  1878. this.onChangeCallback();
  1879. },
  1880. get y () {
  1881. return this._y;
  1882. },
  1883. set y ( value ) {
  1884. this._y = value;
  1885. this.onChangeCallback();
  1886. },
  1887. get z () {
  1888. return this._z;
  1889. },
  1890. set z ( value ) {
  1891. this._z = value;
  1892. this.onChangeCallback();
  1893. },
  1894. get order () {
  1895. return this._order;
  1896. },
  1897. set order ( value ) {
  1898. this._order = value;
  1899. this.onChangeCallback();
  1900. },
  1901. set: function ( x, y, z, order ) {
  1902. this._x = x;
  1903. this._y = y;
  1904. this._z = z;
  1905. this._order = order || this._order;
  1906. this.onChangeCallback();
  1907. return this;
  1908. },
  1909. copy: function ( euler ) {
  1910. this._x = euler._x;
  1911. this._y = euler._y;
  1912. this._z = euler._z;
  1913. this._order = euler._order;
  1914. this.onChangeCallback();
  1915. return this;
  1916. },
  1917. setFromRotationMatrix: function ( m, order, update ) {
  1918. var clamp = THREE.Math.clamp;
  1919. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1920. var te = m.elements;
  1921. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  1922. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  1923. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1924. order = order || this._order;
  1925. if ( order === 'XYZ' ) {
  1926. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  1927. if ( Math.abs( m13 ) < 0.99999 ) {
  1928. this._x = Math.atan2( - m23, m33 );
  1929. this._z = Math.atan2( - m12, m11 );
  1930. } else {
  1931. this._x = Math.atan2( m32, m22 );
  1932. this._z = 0;
  1933. }
  1934. } else if ( order === 'YXZ' ) {
  1935. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  1936. if ( Math.abs( m23 ) < 0.99999 ) {
  1937. this._y = Math.atan2( m13, m33 );
  1938. this._z = Math.atan2( m21, m22 );
  1939. } else {
  1940. this._y = Math.atan2( - m31, m11 );
  1941. this._z = 0;
  1942. }
  1943. } else if ( order === 'ZXY' ) {
  1944. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  1945. if ( Math.abs( m32 ) < 0.99999 ) {
  1946. this._y = Math.atan2( - m31, m33 );
  1947. this._z = Math.atan2( - m12, m22 );
  1948. } else {
  1949. this._y = 0;
  1950. this._z = Math.atan2( m21, m11 );
  1951. }
  1952. } else if ( order === 'ZYX' ) {
  1953. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  1954. if ( Math.abs( m31 ) < 0.99999 ) {
  1955. this._x = Math.atan2( m32, m33 );
  1956. this._z = Math.atan2( m21, m11 );
  1957. } else {
  1958. this._x = 0;
  1959. this._z = Math.atan2( - m12, m22 );
  1960. }
  1961. } else if ( order === 'YZX' ) {
  1962. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  1963. if ( Math.abs( m21 ) < 0.99999 ) {
  1964. this._x = Math.atan2( - m23, m22 );
  1965. this._y = Math.atan2( - m31, m11 );
  1966. } else {
  1967. this._x = 0;
  1968. this._y = Math.atan2( m13, m33 );
  1969. }
  1970. } else if ( order === 'XZY' ) {
  1971. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  1972. if ( Math.abs( m12 ) < 0.99999 ) {
  1973. this._x = Math.atan2( m32, m22 );
  1974. this._y = Math.atan2( m13, m11 );
  1975. } else {
  1976. this._x = Math.atan2( - m23, m33 );
  1977. this._y = 0;
  1978. }
  1979. } else {
  1980. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  1981. }
  1982. this._order = order;
  1983. if ( update !== false ) this.onChangeCallback();
  1984. return this;
  1985. },
  1986. setFromQuaternion: function () {
  1987. var matrix;
  1988. return function ( q, order, update ) {
  1989. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1990. matrix.makeRotationFromQuaternion( q );
  1991. this.setFromRotationMatrix( matrix, order, update );
  1992. return this;
  1993. };
  1994. }(),
  1995. setFromVector3: function ( v, order ) {
  1996. return this.set( v.x, v.y, v.z, order || this._order );
  1997. },
  1998. reorder: function () {
  1999. // WARNING: this discards revolution information -bhouston
  2000. var q = new THREE.Quaternion();
  2001. return function ( newOrder ) {
  2002. q.setFromEuler( this );
  2003. this.setFromQuaternion( q, newOrder );
  2004. };
  2005. }(),
  2006. equals: function ( euler ) {
  2007. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2008. },
  2009. fromArray: function ( array ) {
  2010. this._x = array[ 0 ];
  2011. this._y = array[ 1 ];
  2012. this._z = array[ 2 ];
  2013. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2014. this.onChangeCallback();
  2015. return this;
  2016. },
  2017. toArray: function ( array, offset ) {
  2018. if ( array === undefined ) array = [];
  2019. if ( offset === undefined ) offset = 0;
  2020. array[ offset ] = this._x;
  2021. array[ offset + 1 ] = this._y;
  2022. array[ offset + 2 ] = this._z;
  2023. array[ offset + 3 ] = this._order;
  2024. return array;
  2025. },
  2026. toVector3: function ( optionalResult ) {
  2027. if ( optionalResult ) {
  2028. return optionalResult.set( this._x, this._y, this._z );
  2029. } else {
  2030. return new THREE.Vector3( this._x, this._y, this._z );
  2031. }
  2032. },
  2033. onChange: function ( callback ) {
  2034. this.onChangeCallback = callback;
  2035. return this;
  2036. },
  2037. onChangeCallback: function () {},
  2038. clone: function () {
  2039. return new THREE.Euler( this._x, this._y, this._z, this._order );
  2040. }
  2041. };
  2042. // File:src/math/Line3.js
  2043. /**
  2044. * @author bhouston / http://exocortex.com
  2045. */
  2046. THREE.Line3 = function ( start, end ) {
  2047. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2048. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2049. };
  2050. THREE.Line3.prototype = {
  2051. constructor: THREE.Line3,
  2052. set: function ( start, end ) {
  2053. this.start.copy( start );
  2054. this.end.copy( end );
  2055. return this;
  2056. },
  2057. copy: function ( line ) {
  2058. this.start.copy( line.start );
  2059. this.end.copy( line.end );
  2060. return this;
  2061. },
  2062. center: function ( optionalTarget ) {
  2063. var result = optionalTarget || new THREE.Vector3();
  2064. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2065. },
  2066. delta: function ( optionalTarget ) {
  2067. var result = optionalTarget || new THREE.Vector3();
  2068. return result.subVectors( this.end, this.start );
  2069. },
  2070. distanceSq: function () {
  2071. return this.start.distanceToSquared( this.end );
  2072. },
  2073. distance: function () {
  2074. return this.start.distanceTo( this.end );
  2075. },
  2076. at: function ( t, optionalTarget ) {
  2077. var result = optionalTarget || new THREE.Vector3();
  2078. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2079. },
  2080. closestPointToPointParameter: function () {
  2081. var startP = new THREE.Vector3();
  2082. var startEnd = new THREE.Vector3();
  2083. return function ( point, clampToLine ) {
  2084. startP.subVectors( point, this.start );
  2085. startEnd.subVectors( this.end, this.start );
  2086. var startEnd2 = startEnd.dot( startEnd );
  2087. var startEnd_startP = startEnd.dot( startP );
  2088. var t = startEnd_startP / startEnd2;
  2089. if ( clampToLine ) {
  2090. t = THREE.Math.clamp( t, 0, 1 );
  2091. }
  2092. return t;
  2093. };
  2094. }(),
  2095. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2096. var t = this.closestPointToPointParameter( point, clampToLine );
  2097. var result = optionalTarget || new THREE.Vector3();
  2098. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2099. },
  2100. applyMatrix4: function ( matrix ) {
  2101. this.start.applyMatrix4( matrix );
  2102. this.end.applyMatrix4( matrix );
  2103. return this;
  2104. },
  2105. equals: function ( line ) {
  2106. return line.start.equals( this.start ) && line.end.equals( this.end );
  2107. },
  2108. clone: function () {
  2109. return new THREE.Line3().copy( this );
  2110. }
  2111. };
  2112. // File:src/math/Box2.js
  2113. /**
  2114. * @author bhouston / http://exocortex.com
  2115. */
  2116. THREE.Box2 = function ( min, max ) {
  2117. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  2118. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2119. };
  2120. THREE.Box2.prototype = {
  2121. constructor: THREE.Box2,
  2122. set: function ( min, max ) {
  2123. this.min.copy( min );
  2124. this.max.copy( max );
  2125. return this;
  2126. },
  2127. setFromPoints: function ( points ) {
  2128. this.makeEmpty();
  2129. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2130. this.expandByPoint( points[ i ] )
  2131. }
  2132. return this;
  2133. },
  2134. setFromCenterAndSize: function () {
  2135. var v1 = new THREE.Vector2();
  2136. return function ( center, size ) {
  2137. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2138. this.min.copy( center ).sub( halfSize );
  2139. this.max.copy( center ).add( halfSize );
  2140. return this;
  2141. };
  2142. }(),
  2143. copy: function ( box ) {
  2144. this.min.copy( box.min );
  2145. this.max.copy( box.max );
  2146. return this;
  2147. },
  2148. makeEmpty: function () {
  2149. this.min.x = this.min.y = Infinity;
  2150. this.max.x = this.max.y = - Infinity;
  2151. return this;
  2152. },
  2153. empty: function () {
  2154. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2155. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2156. },
  2157. center: function ( optionalTarget ) {
  2158. var result = optionalTarget || new THREE.Vector2();
  2159. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2160. },
  2161. size: function ( optionalTarget ) {
  2162. var result = optionalTarget || new THREE.Vector2();
  2163. return result.subVectors( this.max, this.min );
  2164. },
  2165. expandByPoint: function ( point ) {
  2166. this.min.min( point );
  2167. this.max.max( point );
  2168. return this;
  2169. },
  2170. expandByVector: function ( vector ) {
  2171. this.min.sub( vector );
  2172. this.max.add( vector );
  2173. return this;
  2174. },
  2175. expandByScalar: function ( scalar ) {
  2176. this.min.addScalar( - scalar );
  2177. this.max.addScalar( scalar );
  2178. return this;
  2179. },
  2180. containsPoint: function ( point ) {
  2181. if ( point.x < this.min.x || point.x > this.max.x ||
  2182. point.y < this.min.y || point.y > this.max.y ) {
  2183. return false;
  2184. }
  2185. return true;
  2186. },
  2187. containsBox: function ( box ) {
  2188. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2189. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2190. return true;
  2191. }
  2192. return false;
  2193. },
  2194. getParameter: function ( point, optionalTarget ) {
  2195. // This can potentially have a divide by zero if the box
  2196. // has a size dimension of 0.
  2197. var result = optionalTarget || new THREE.Vector2();
  2198. return result.set(
  2199. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2200. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2201. );
  2202. },
  2203. isIntersectionBox: function ( box ) {
  2204. // using 6 splitting planes to rule out intersections.
  2205. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2206. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2207. return false;
  2208. }
  2209. return true;
  2210. },
  2211. clampPoint: function ( point, optionalTarget ) {
  2212. var result = optionalTarget || new THREE.Vector2();
  2213. return result.copy( point ).clamp( this.min, this.max );
  2214. },
  2215. distanceToPoint: function () {
  2216. var v1 = new THREE.Vector2();
  2217. return function ( point ) {
  2218. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2219. return clampedPoint.sub( point ).length();
  2220. };
  2221. }(),
  2222. intersect: function ( box ) {
  2223. this.min.max( box.min );
  2224. this.max.min( box.max );
  2225. return this;
  2226. },
  2227. union: function ( box ) {
  2228. this.min.min( box.min );
  2229. this.max.max( box.max );
  2230. return this;
  2231. },
  2232. translate: function ( offset ) {
  2233. this.min.add( offset );
  2234. this.max.add( offset );
  2235. return this;
  2236. },
  2237. equals: function ( box ) {
  2238. return box.min.equals( this.min ) && box.max.equals( this.max );
  2239. },
  2240. clone: function () {
  2241. return new THREE.Box2().copy( this );
  2242. }
  2243. };
  2244. // File:src/math/Box3.js
  2245. /**
  2246. * @author bhouston / http://exocortex.com
  2247. * @author WestLangley / http://github.com/WestLangley
  2248. */
  2249. THREE.Box3 = function ( min, max ) {
  2250. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2251. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2252. };
  2253. THREE.Box3.prototype = {
  2254. constructor: THREE.Box3,
  2255. set: function ( min, max ) {
  2256. this.min.copy( min );
  2257. this.max.copy( max );
  2258. return this;
  2259. },
  2260. setFromPoints: function ( points ) {
  2261. this.makeEmpty();
  2262. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2263. this.expandByPoint( points[ i ] );
  2264. }
  2265. return this;
  2266. },
  2267. setFromCenterAndSize: function () {
  2268. var v1 = new THREE.Vector3();
  2269. return function ( center, size ) {
  2270. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2271. this.min.copy( center ).sub( halfSize );
  2272. this.max.copy( center ).add( halfSize );
  2273. return this;
  2274. };
  2275. }(),
  2276. setFromObject: function () {
  2277. // Computes the world-axis-aligned bounding box of an object (including its children),
  2278. // accounting for both the object's, and childrens', world transforms
  2279. var v1 = new THREE.Vector3();
  2280. return function ( object ) {
  2281. var scope = this;
  2282. object.updateMatrixWorld( true );
  2283. this.makeEmpty();
  2284. object.traverse( function ( node ) {
  2285. var geometry = node.geometry;
  2286. if ( geometry !== undefined ) {
  2287. if ( geometry instanceof THREE.Geometry ) {
  2288. var vertices = geometry.vertices;
  2289. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2290. v1.copy( vertices[ i ] );
  2291. v1.applyMatrix4( node.matrixWorld );
  2292. scope.expandByPoint( v1 );
  2293. }
  2294. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2295. var positions = geometry.attributes[ 'position' ].array;
  2296. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2297. v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
  2298. v1.applyMatrix4( node.matrixWorld );
  2299. scope.expandByPoint( v1 );
  2300. }
  2301. }
  2302. }
  2303. } );
  2304. return this;
  2305. };
  2306. }(),
  2307. copy: function ( box ) {
  2308. this.min.copy( box.min );
  2309. this.max.copy( box.max );
  2310. return this;
  2311. },
  2312. makeEmpty: function () {
  2313. this.min.x = this.min.y = this.min.z = Infinity;
  2314. this.max.x = this.max.y = this.max.z = - Infinity;
  2315. return this;
  2316. },
  2317. empty: function () {
  2318. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2319. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2320. },
  2321. center: function ( optionalTarget ) {
  2322. var result = optionalTarget || new THREE.Vector3();
  2323. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2324. },
  2325. size: function ( optionalTarget ) {
  2326. var result = optionalTarget || new THREE.Vector3();
  2327. return result.subVectors( this.max, this.min );
  2328. },
  2329. expandByPoint: function ( point ) {
  2330. this.min.min( point );
  2331. this.max.max( point );
  2332. return this;
  2333. },
  2334. expandByVector: function ( vector ) {
  2335. this.min.sub( vector );
  2336. this.max.add( vector );
  2337. return this;
  2338. },
  2339. expandByScalar: function ( scalar ) {
  2340. this.min.addScalar( - scalar );
  2341. this.max.addScalar( scalar );
  2342. return this;
  2343. },
  2344. containsPoint: function ( point ) {
  2345. if ( point.x < this.min.x || point.x > this.max.x ||
  2346. point.y < this.min.y || point.y > this.max.y ||
  2347. point.z < this.min.z || point.z > this.max.z ) {
  2348. return false;
  2349. }
  2350. return true;
  2351. },
  2352. containsBox: function ( box ) {
  2353. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2354. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2355. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2356. return true;
  2357. }
  2358. return false;
  2359. },
  2360. getParameter: function ( point, optionalTarget ) {
  2361. // This can potentially have a divide by zero if the box
  2362. // has a size dimension of 0.
  2363. var result = optionalTarget || new THREE.Vector3();
  2364. return result.set(
  2365. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2366. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2367. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2368. );
  2369. },
  2370. isIntersectionBox: function ( box ) {
  2371. // using 6 splitting planes to rule out intersections.
  2372. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2373. box.max.y < this.min.y || box.min.y > this.max.y ||
  2374. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2375. return false;
  2376. }
  2377. return true;
  2378. },
  2379. clampPoint: function ( point, optionalTarget ) {
  2380. var result = optionalTarget || new THREE.Vector3();
  2381. return result.copy( point ).clamp( this.min, this.max );
  2382. },
  2383. distanceToPoint: function () {
  2384. var v1 = new THREE.Vector3();
  2385. return function ( point ) {
  2386. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2387. return clampedPoint.sub( point ).length();
  2388. };
  2389. }(),
  2390. getBoundingSphere: function () {
  2391. var v1 = new THREE.Vector3();
  2392. return function ( optionalTarget ) {
  2393. var result = optionalTarget || new THREE.Sphere();
  2394. result.center = this.center();
  2395. result.radius = this.size( v1 ).length() * 0.5;
  2396. return result;
  2397. };
  2398. }(),
  2399. intersect: function ( box ) {
  2400. this.min.max( box.min );
  2401. this.max.min( box.max );
  2402. return this;
  2403. },
  2404. union: function ( box ) {
  2405. this.min.min( box.min );
  2406. this.max.max( box.max );
  2407. return this;
  2408. },
  2409. applyMatrix4: function () {
  2410. var points = [
  2411. new THREE.Vector3(),
  2412. new THREE.Vector3(),
  2413. new THREE.Vector3(),
  2414. new THREE.Vector3(),
  2415. new THREE.Vector3(),
  2416. new THREE.Vector3(),
  2417. new THREE.Vector3(),
  2418. new THREE.Vector3()
  2419. ];
  2420. return function ( matrix ) {
  2421. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2422. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2423. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2424. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2425. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2426. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2427. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2428. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2429. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2430. this.makeEmpty();
  2431. this.setFromPoints( points );
  2432. return this;
  2433. };
  2434. }(),
  2435. translate: function ( offset ) {
  2436. this.min.add( offset );
  2437. this.max.add( offset );
  2438. return this;
  2439. },
  2440. equals: function ( box ) {
  2441. return box.min.equals( this.min ) && box.max.equals( this.max );
  2442. },
  2443. clone: function () {
  2444. return new THREE.Box3().copy( this );
  2445. }
  2446. };
  2447. // File:src/math/Matrix3.js
  2448. /**
  2449. * @author alteredq / http://alteredqualia.com/
  2450. * @author WestLangley / http://github.com/WestLangley
  2451. * @author bhouston / http://exocortex.com
  2452. */
  2453. THREE.Matrix3 = function () {
  2454. this.elements = new Float32Array( [
  2455. 1, 0, 0,
  2456. 0, 1, 0,
  2457. 0, 0, 1
  2458. ] );
  2459. if ( arguments.length > 0 ) {
  2460. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2461. }
  2462. };
  2463. THREE.Matrix3.prototype = {
  2464. constructor: THREE.Matrix3,
  2465. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2466. var te = this.elements;
  2467. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2468. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2469. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2470. return this;
  2471. },
  2472. identity: function () {
  2473. this.set(
  2474. 1, 0, 0,
  2475. 0, 1, 0,
  2476. 0, 0, 1
  2477. );
  2478. return this;
  2479. },
  2480. copy: function ( m ) {
  2481. var me = m.elements;
  2482. this.set(
  2483. me[ 0 ], me[ 3 ], me[ 6 ],
  2484. me[ 1 ], me[ 4 ], me[ 7 ],
  2485. me[ 2 ], me[ 5 ], me[ 8 ]
  2486. );
  2487. return this;
  2488. },
  2489. multiplyVector3: function ( vector ) {
  2490. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  2491. return vector.applyMatrix3( this );
  2492. },
  2493. multiplyVector3Array: function ( a ) {
  2494. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2495. return this.applyToVector3Array( a );
  2496. },
  2497. applyToVector3Array: function () {
  2498. var v1;
  2499. return function ( array, offset, length ) {
  2500. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2501. if ( offset === undefined ) offset = 0;
  2502. if ( length === undefined ) length = array.length;
  2503. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2504. v1.fromArray( array, j );
  2505. v1.applyMatrix3( this );
  2506. v1.toArray( array, j );
  2507. }
  2508. return array;
  2509. };
  2510. }(),
  2511. applyToBuffer: function () {
  2512. var v1;
  2513. return function applyToBuffer( buffer, offset, length ) {
  2514. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2515. if ( offset === undefined ) offset = 0;
  2516. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2517. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2518. v1.x = buffer.getX( j );
  2519. v1.y = buffer.getY( j );
  2520. v1.z = buffer.getZ( j );
  2521. v1.applyMatrix3( this );
  2522. buffer.setXYZ( v1.x, v1.y, v1.z );
  2523. }
  2524. return buffer;
  2525. };
  2526. }(),
  2527. multiplyScalar: function ( s ) {
  2528. var te = this.elements;
  2529. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2530. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2531. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2532. return this;
  2533. },
  2534. determinant: function () {
  2535. var te = this.elements;
  2536. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2537. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2538. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2539. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2540. },
  2541. getInverse: function ( matrix, throwOnInvertible ) {
  2542. // input: THREE.Matrix4
  2543. // ( based on http://code.google.com/p/webgl-mjs/ )
  2544. var me = matrix.elements;
  2545. var te = this.elements;
  2546. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2547. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2548. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2549. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2550. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2551. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2552. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2553. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2554. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2555. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2556. // no inverse
  2557. if ( det === 0 ) {
  2558. var msg = "Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2559. if ( throwOnInvertible || false ) {
  2560. throw new Error( msg );
  2561. } else {
  2562. console.warn( msg );
  2563. }
  2564. this.identity();
  2565. return this;
  2566. }
  2567. this.multiplyScalar( 1.0 / det );
  2568. return this;
  2569. },
  2570. transpose: function () {
  2571. var tmp, m = this.elements;
  2572. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2573. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2574. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2575. return this;
  2576. },
  2577. flattenToArrayOffset: function ( array, offset ) {
  2578. var te = this.elements;
  2579. array[ offset ] = te[ 0 ];
  2580. array[ offset + 1 ] = te[ 1 ];
  2581. array[ offset + 2 ] = te[ 2 ];
  2582. array[ offset + 3 ] = te[ 3 ];
  2583. array[ offset + 4 ] = te[ 4 ];
  2584. array[ offset + 5 ] = te[ 5 ];
  2585. array[ offset + 6 ] = te[ 6 ];
  2586. array[ offset + 7 ] = te[ 7 ];
  2587. array[ offset + 8 ] = te[ 8 ];
  2588. return array;
  2589. },
  2590. getNormalMatrix: function ( m ) {
  2591. // input: THREE.Matrix4
  2592. this.getInverse( m ).transpose();
  2593. return this;
  2594. },
  2595. transposeIntoArray: function ( r ) {
  2596. var m = this.elements;
  2597. r[ 0 ] = m[ 0 ];
  2598. r[ 1 ] = m[ 3 ];
  2599. r[ 2 ] = m[ 6 ];
  2600. r[ 3 ] = m[ 1 ];
  2601. r[ 4 ] = m[ 4 ];
  2602. r[ 5 ] = m[ 7 ];
  2603. r[ 6 ] = m[ 2 ];
  2604. r[ 7 ] = m[ 5 ];
  2605. r[ 8 ] = m[ 8 ];
  2606. return this;
  2607. },
  2608. fromArray: function ( array ) {
  2609. this.elements.set( array );
  2610. return this;
  2611. },
  2612. toArray: function () {
  2613. var te = this.elements;
  2614. return [
  2615. te[ 0 ], te[ 1 ], te[ 2 ],
  2616. te[ 3 ], te[ 4 ], te[ 5 ],
  2617. te[ 6 ], te[ 7 ], te[ 8 ]
  2618. ];
  2619. },
  2620. clone: function () {
  2621. return new THREE.Matrix3().fromArray( this.elements );
  2622. }
  2623. };
  2624. // File:src/math/Matrix4.js
  2625. /**
  2626. * @author mrdoob / http://mrdoob.com/
  2627. * @author supereggbert / http://www.paulbrunt.co.uk/
  2628. * @author philogb / http://blog.thejit.org/
  2629. * @author jordi_ros / http://plattsoft.com
  2630. * @author D1plo1d / http://github.com/D1plo1d
  2631. * @author alteredq / http://alteredqualia.com/
  2632. * @author mikael emtinger / http://gomo.se/
  2633. * @author timknip / http://www.floorplanner.com/
  2634. * @author bhouston / http://exocortex.com
  2635. * @author WestLangley / http://github.com/WestLangley
  2636. */
  2637. THREE.Matrix4 = function () {
  2638. this.elements = new Float32Array( [
  2639. 1, 0, 0, 0,
  2640. 0, 1, 0, 0,
  2641. 0, 0, 1, 0,
  2642. 0, 0, 0, 1
  2643. ] );
  2644. if ( arguments.length > 0 ) {
  2645. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2646. }
  2647. };
  2648. THREE.Matrix4.prototype = {
  2649. constructor: THREE.Matrix4,
  2650. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2651. var te = this.elements;
  2652. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2653. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2654. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2655. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2656. return this;
  2657. },
  2658. identity: function () {
  2659. this.set(
  2660. 1, 0, 0, 0,
  2661. 0, 1, 0, 0,
  2662. 0, 0, 1, 0,
  2663. 0, 0, 0, 1
  2664. );
  2665. return this;
  2666. },
  2667. copy: function ( m ) {
  2668. this.elements.set( m.elements );
  2669. return this;
  2670. },
  2671. extractPosition: function ( m ) {
  2672. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  2673. return this.copyPosition( m );
  2674. },
  2675. copyPosition: function ( m ) {
  2676. var te = this.elements;
  2677. var me = m.elements;
  2678. te[ 12 ] = me[ 12 ];
  2679. te[ 13 ] = me[ 13 ];
  2680. te[ 14 ] = me[ 14 ];
  2681. return this;
  2682. },
  2683. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2684. var te = this.elements;
  2685. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2686. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2687. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2688. return this;
  2689. },
  2690. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2691. this.set(
  2692. xAxis.x, yAxis.x, zAxis.x, 0,
  2693. xAxis.y, yAxis.y, zAxis.y, 0,
  2694. xAxis.z, yAxis.z, zAxis.z, 0,
  2695. 0, 0, 0, 1
  2696. );
  2697. return this;
  2698. },
  2699. extractRotation: function () {
  2700. var v1;
  2701. return function ( m ) {
  2702. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2703. var te = this.elements;
  2704. var me = m.elements;
  2705. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2706. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2707. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2708. te[ 0 ] = me[ 0 ] * scaleX;
  2709. te[ 1 ] = me[ 1 ] * scaleX;
  2710. te[ 2 ] = me[ 2 ] * scaleX;
  2711. te[ 4 ] = me[ 4 ] * scaleY;
  2712. te[ 5 ] = me[ 5 ] * scaleY;
  2713. te[ 6 ] = me[ 6 ] * scaleY;
  2714. te[ 8 ] = me[ 8 ] * scaleZ;
  2715. te[ 9 ] = me[ 9 ] * scaleZ;
  2716. te[ 10 ] = me[ 10 ] * scaleZ;
  2717. return this;
  2718. };
  2719. }(),
  2720. makeRotationFromEuler: function ( euler ) {
  2721. if ( euler instanceof THREE.Euler === false ) {
  2722. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2723. }
  2724. var te = this.elements;
  2725. var x = euler.x, y = euler.y, z = euler.z;
  2726. var a = Math.cos( x ), b = Math.sin( x );
  2727. var c = Math.cos( y ), d = Math.sin( y );
  2728. var e = Math.cos( z ), f = Math.sin( z );
  2729. if ( euler.order === 'XYZ' ) {
  2730. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2731. te[ 0 ] = c * e;
  2732. te[ 4 ] = - c * f;
  2733. te[ 8 ] = d;
  2734. te[ 1 ] = af + be * d;
  2735. te[ 5 ] = ae - bf * d;
  2736. te[ 9 ] = - b * c;
  2737. te[ 2 ] = bf - ae * d;
  2738. te[ 6 ] = be + af * d;
  2739. te[ 10 ] = a * c;
  2740. } else if ( euler.order === 'YXZ' ) {
  2741. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2742. te[ 0 ] = ce + df * b;
  2743. te[ 4 ] = de * b - cf;
  2744. te[ 8 ] = a * d;
  2745. te[ 1 ] = a * f;
  2746. te[ 5 ] = a * e;
  2747. te[ 9 ] = - b;
  2748. te[ 2 ] = cf * b - de;
  2749. te[ 6 ] = df + ce * b;
  2750. te[ 10 ] = a * c;
  2751. } else if ( euler.order === 'ZXY' ) {
  2752. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2753. te[ 0 ] = ce - df * b;
  2754. te[ 4 ] = - a * f;
  2755. te[ 8 ] = de + cf * b;
  2756. te[ 1 ] = cf + de * b;
  2757. te[ 5 ] = a * e;
  2758. te[ 9 ] = df - ce * b;
  2759. te[ 2 ] = - a * d;
  2760. te[ 6 ] = b;
  2761. te[ 10 ] = a * c;
  2762. } else if ( euler.order === 'ZYX' ) {
  2763. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2764. te[ 0 ] = c * e;
  2765. te[ 4 ] = be * d - af;
  2766. te[ 8 ] = ae * d + bf;
  2767. te[ 1 ] = c * f;
  2768. te[ 5 ] = bf * d + ae;
  2769. te[ 9 ] = af * d - be;
  2770. te[ 2 ] = - d;
  2771. te[ 6 ] = b * c;
  2772. te[ 10 ] = a * c;
  2773. } else if ( euler.order === 'YZX' ) {
  2774. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2775. te[ 0 ] = c * e;
  2776. te[ 4 ] = bd - ac * f;
  2777. te[ 8 ] = bc * f + ad;
  2778. te[ 1 ] = f;
  2779. te[ 5 ] = a * e;
  2780. te[ 9 ] = - b * e;
  2781. te[ 2 ] = - d * e;
  2782. te[ 6 ] = ad * f + bc;
  2783. te[ 10 ] = ac - bd * f;
  2784. } else if ( euler.order === 'XZY' ) {
  2785. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2786. te[ 0 ] = c * e;
  2787. te[ 4 ] = - f;
  2788. te[ 8 ] = d * e;
  2789. te[ 1 ] = ac * f + bd;
  2790. te[ 5 ] = a * e;
  2791. te[ 9 ] = ad * f - bc;
  2792. te[ 2 ] = bc * f - ad;
  2793. te[ 6 ] = b * e;
  2794. te[ 10 ] = bd * f + ac;
  2795. }
  2796. // last column
  2797. te[ 3 ] = 0;
  2798. te[ 7 ] = 0;
  2799. te[ 11 ] = 0;
  2800. // bottom row
  2801. te[ 12 ] = 0;
  2802. te[ 13 ] = 0;
  2803. te[ 14 ] = 0;
  2804. te[ 15 ] = 1;
  2805. return this;
  2806. },
  2807. setRotationFromQuaternion: function ( q ) {
  2808. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  2809. return this.makeRotationFromQuaternion( q );
  2810. },
  2811. makeRotationFromQuaternion: function ( q ) {
  2812. var te = this.elements;
  2813. var x = q.x, y = q.y, z = q.z, w = q.w;
  2814. var x2 = x + x, y2 = y + y, z2 = z + z;
  2815. var xx = x * x2, xy = x * y2, xz = x * z2;
  2816. var yy = y * y2, yz = y * z2, zz = z * z2;
  2817. var wx = w * x2, wy = w * y2, wz = w * z2;
  2818. te[ 0 ] = 1 - ( yy + zz );
  2819. te[ 4 ] = xy - wz;
  2820. te[ 8 ] = xz + wy;
  2821. te[ 1 ] = xy + wz;
  2822. te[ 5 ] = 1 - ( xx + zz );
  2823. te[ 9 ] = yz - wx;
  2824. te[ 2 ] = xz - wy;
  2825. te[ 6 ] = yz + wx;
  2826. te[ 10 ] = 1 - ( xx + yy );
  2827. // last column
  2828. te[ 3 ] = 0;
  2829. te[ 7 ] = 0;
  2830. te[ 11 ] = 0;
  2831. // bottom row
  2832. te[ 12 ] = 0;
  2833. te[ 13 ] = 0;
  2834. te[ 14 ] = 0;
  2835. te[ 15 ] = 1;
  2836. return this;
  2837. },
  2838. lookAt: function () {
  2839. var x, y, z;
  2840. return function ( eye, target, up ) {
  2841. if ( x === undefined ) x = new THREE.Vector3();
  2842. if ( y === undefined ) y = new THREE.Vector3();
  2843. if ( z === undefined ) z = new THREE.Vector3();
  2844. var te = this.elements;
  2845. z.subVectors( eye, target ).normalize();
  2846. if ( z.length() === 0 ) {
  2847. z.z = 1;
  2848. }
  2849. x.crossVectors( up, z ).normalize();
  2850. if ( x.length() === 0 ) {
  2851. z.x += 0.0001;
  2852. x.crossVectors( up, z ).normalize();
  2853. }
  2854. y.crossVectors( z, x );
  2855. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2856. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2857. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2858. return this;
  2859. };
  2860. }(),
  2861. multiply: function ( m, n ) {
  2862. if ( n !== undefined ) {
  2863. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2864. return this.multiplyMatrices( m, n );
  2865. }
  2866. return this.multiplyMatrices( this, m );
  2867. },
  2868. multiplyMatrices: function ( a, b ) {
  2869. var ae = a.elements;
  2870. var be = b.elements;
  2871. var te = this.elements;
  2872. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2873. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2874. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2875. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2876. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2877. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2878. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2879. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2880. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2881. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2882. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2883. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2884. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2885. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2886. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2887. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2888. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2889. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2890. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2891. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2892. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2893. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2894. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2895. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2896. return this;
  2897. },
  2898. multiplyToArray: function ( a, b, r ) {
  2899. var te = this.elements;
  2900. this.multiplyMatrices( a, b );
  2901. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  2902. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  2903. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  2904. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  2905. return this;
  2906. },
  2907. multiplyScalar: function ( s ) {
  2908. var te = this.elements;
  2909. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2910. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2911. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2912. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2913. return this;
  2914. },
  2915. multiplyVector3: function ( vector ) {
  2916. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  2917. return vector.applyProjection( this );
  2918. },
  2919. multiplyVector4: function ( vector ) {
  2920. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  2921. return vector.applyMatrix4( this );
  2922. },
  2923. multiplyVector3Array: function ( a ) {
  2924. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2925. return this.applyToVector3Array( a );
  2926. },
  2927. applyToVector3Array: function () {
  2928. var v1;
  2929. return function ( array, offset, length ) {
  2930. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2931. if ( offset === undefined ) offset = 0;
  2932. if ( length === undefined ) length = array.length;
  2933. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2934. v1.fromArray( array, j );
  2935. v1.applyMatrix4( this );
  2936. v1.toArray( array, j );
  2937. }
  2938. return array;
  2939. };
  2940. }(),
  2941. applyToBuffer: function () {
  2942. var v1;
  2943. return function applyToBuffer( buffer, offset, length ) {
  2944. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2945. if ( offset === undefined ) offset = 0;
  2946. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2947. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2948. v1.x = buffer.getX( j );
  2949. v1.y = buffer.getY( j );
  2950. v1.z = buffer.getZ( j );
  2951. v1.applyMatrix4( this );
  2952. buffer.setXYZ( v1.x, v1.y, v1.z );
  2953. }
  2954. return buffer;
  2955. };
  2956. }(),
  2957. rotateAxis: function ( v ) {
  2958. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  2959. v.transformDirection( this );
  2960. },
  2961. crossVector: function ( vector ) {
  2962. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  2963. return vector.applyMatrix4( this );
  2964. },
  2965. determinant: function () {
  2966. var te = this.elements;
  2967. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  2968. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  2969. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  2970. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  2971. //TODO: make this more efficient
  2972. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  2973. return (
  2974. n41 * (
  2975. + n14 * n23 * n32
  2976. - n13 * n24 * n32
  2977. - n14 * n22 * n33
  2978. + n12 * n24 * n33
  2979. + n13 * n22 * n34
  2980. - n12 * n23 * n34
  2981. ) +
  2982. n42 * (
  2983. + n11 * n23 * n34
  2984. - n11 * n24 * n33
  2985. + n14 * n21 * n33
  2986. - n13 * n21 * n34
  2987. + n13 * n24 * n31
  2988. - n14 * n23 * n31
  2989. ) +
  2990. n43 * (
  2991. + n11 * n24 * n32
  2992. - n11 * n22 * n34
  2993. - n14 * n21 * n32
  2994. + n12 * n21 * n34
  2995. + n14 * n22 * n31
  2996. - n12 * n24 * n31
  2997. ) +
  2998. n44 * (
  2999. - n13 * n22 * n31
  3000. - n11 * n23 * n32
  3001. + n11 * n22 * n33
  3002. + n13 * n21 * n32
  3003. - n12 * n21 * n33
  3004. + n12 * n23 * n31
  3005. )
  3006. );
  3007. },
  3008. transpose: function () {
  3009. var te = this.elements;
  3010. var tmp;
  3011. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3012. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3013. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3014. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3015. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3016. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3017. return this;
  3018. },
  3019. flattenToArrayOffset: function ( array, offset ) {
  3020. var te = this.elements;
  3021. array[ offset ] = te[ 0 ];
  3022. array[ offset + 1 ] = te[ 1 ];
  3023. array[ offset + 2 ] = te[ 2 ];
  3024. array[ offset + 3 ] = te[ 3 ];
  3025. array[ offset + 4 ] = te[ 4 ];
  3026. array[ offset + 5 ] = te[ 5 ];
  3027. array[ offset + 6 ] = te[ 6 ];
  3028. array[ offset + 7 ] = te[ 7 ];
  3029. array[ offset + 8 ] = te[ 8 ];
  3030. array[ offset + 9 ] = te[ 9 ];
  3031. array[ offset + 10 ] = te[ 10 ];
  3032. array[ offset + 11 ] = te[ 11 ];
  3033. array[ offset + 12 ] = te[ 12 ];
  3034. array[ offset + 13 ] = te[ 13 ];
  3035. array[ offset + 14 ] = te[ 14 ];
  3036. array[ offset + 15 ] = te[ 15 ];
  3037. return array;
  3038. },
  3039. getPosition: function () {
  3040. var v1;
  3041. return function () {
  3042. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3043. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3044. var te = this.elements;
  3045. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3046. };
  3047. }(),
  3048. setPosition: function ( v ) {
  3049. var te = this.elements;
  3050. te[ 12 ] = v.x;
  3051. te[ 13 ] = v.y;
  3052. te[ 14 ] = v.z;
  3053. return this;
  3054. },
  3055. getInverse: function ( m, throwOnInvertible ) {
  3056. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3057. var te = this.elements;
  3058. var me = m.elements;
  3059. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3060. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3061. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3062. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3063. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3064. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3065. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3066. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3067. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3068. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3069. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3070. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3071. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3072. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3073. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3074. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3075. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3076. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3077. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3078. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3079. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3080. if ( det === 0 ) {
  3081. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3082. if ( throwOnInvertible || false ) {
  3083. throw new Error( msg );
  3084. } else {
  3085. console.warn( msg );
  3086. }
  3087. this.identity();
  3088. return this;
  3089. }
  3090. this.multiplyScalar( 1 / det );
  3091. return this;
  3092. },
  3093. translate: function ( v ) {
  3094. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  3095. },
  3096. rotateX: function ( angle ) {
  3097. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  3098. },
  3099. rotateY: function ( angle ) {
  3100. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  3101. },
  3102. rotateZ: function ( angle ) {
  3103. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  3104. },
  3105. rotateByAxis: function ( axis, angle ) {
  3106. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  3107. },
  3108. scale: function ( v ) {
  3109. var te = this.elements;
  3110. var x = v.x, y = v.y, z = v.z;
  3111. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3112. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3113. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3114. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3115. return this;
  3116. },
  3117. getMaxScaleOnAxis: function () {
  3118. var te = this.elements;
  3119. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3120. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3121. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3122. return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
  3123. },
  3124. makeTranslation: function ( x, y, z ) {
  3125. this.set(
  3126. 1, 0, 0, x,
  3127. 0, 1, 0, y,
  3128. 0, 0, 1, z,
  3129. 0, 0, 0, 1
  3130. );
  3131. return this;
  3132. },
  3133. makeRotationX: function ( theta ) {
  3134. var c = Math.cos( theta ), s = Math.sin( theta );
  3135. this.set(
  3136. 1, 0, 0, 0,
  3137. 0, c, - s, 0,
  3138. 0, s, c, 0,
  3139. 0, 0, 0, 1
  3140. );
  3141. return this;
  3142. },
  3143. makeRotationY: function ( theta ) {
  3144. var c = Math.cos( theta ), s = Math.sin( theta );
  3145. this.set(
  3146. c, 0, s, 0,
  3147. 0, 1, 0, 0,
  3148. - s, 0, c, 0,
  3149. 0, 0, 0, 1
  3150. );
  3151. return this;
  3152. },
  3153. makeRotationZ: function ( theta ) {
  3154. var c = Math.cos( theta ), s = Math.sin( theta );
  3155. this.set(
  3156. c, - s, 0, 0,
  3157. s, c, 0, 0,
  3158. 0, 0, 1, 0,
  3159. 0, 0, 0, 1
  3160. );
  3161. return this;
  3162. },
  3163. makeRotationAxis: function ( axis, angle ) {
  3164. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3165. var c = Math.cos( angle );
  3166. var s = Math.sin( angle );
  3167. var t = 1 - c;
  3168. var x = axis.x, y = axis.y, z = axis.z;
  3169. var tx = t * x, ty = t * y;
  3170. this.set(
  3171. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3172. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3173. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3174. 0, 0, 0, 1
  3175. );
  3176. return this;
  3177. },
  3178. makeScale: function ( x, y, z ) {
  3179. this.set(
  3180. x, 0, 0, 0,
  3181. 0, y, 0, 0,
  3182. 0, 0, z, 0,
  3183. 0, 0, 0, 1
  3184. );
  3185. return this;
  3186. },
  3187. compose: function ( position, quaternion, scale ) {
  3188. this.makeRotationFromQuaternion( quaternion );
  3189. this.scale( scale );
  3190. this.setPosition( position );
  3191. return this;
  3192. },
  3193. decompose: function () {
  3194. var vector, matrix;
  3195. return function ( position, quaternion, scale ) {
  3196. if ( vector === undefined ) vector = new THREE.Vector3();
  3197. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3198. var te = this.elements;
  3199. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3200. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3201. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3202. // if determine is negative, we need to invert one scale
  3203. var det = this.determinant();
  3204. if ( det < 0 ) {
  3205. sx = - sx;
  3206. }
  3207. position.x = te[ 12 ];
  3208. position.y = te[ 13 ];
  3209. position.z = te[ 14 ];
  3210. // scale the rotation part
  3211. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3212. var invSX = 1 / sx;
  3213. var invSY = 1 / sy;
  3214. var invSZ = 1 / sz;
  3215. matrix.elements[ 0 ] *= invSX;
  3216. matrix.elements[ 1 ] *= invSX;
  3217. matrix.elements[ 2 ] *= invSX;
  3218. matrix.elements[ 4 ] *= invSY;
  3219. matrix.elements[ 5 ] *= invSY;
  3220. matrix.elements[ 6 ] *= invSY;
  3221. matrix.elements[ 8 ] *= invSZ;
  3222. matrix.elements[ 9 ] *= invSZ;
  3223. matrix.elements[ 10 ] *= invSZ;
  3224. quaternion.setFromRotationMatrix( matrix );
  3225. scale.x = sx;
  3226. scale.y = sy;
  3227. scale.z = sz;
  3228. return this;
  3229. };
  3230. }(),
  3231. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3232. var te = this.elements;
  3233. var x = 2 * near / ( right - left );
  3234. var y = 2 * near / ( top - bottom );
  3235. var a = ( right + left ) / ( right - left );
  3236. var b = ( top + bottom ) / ( top - bottom );
  3237. var c = - ( far + near ) / ( far - near );
  3238. var d = - 2 * far * near / ( far - near );
  3239. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3240. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3241. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3242. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3243. return this;
  3244. },
  3245. makePerspective: function ( fov, aspect, near, far ) {
  3246. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3247. var ymin = - ymax;
  3248. var xmin = ymin * aspect;
  3249. var xmax = ymax * aspect;
  3250. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3251. },
  3252. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3253. var te = this.elements;
  3254. var w = right - left;
  3255. var h = top - bottom;
  3256. var p = far - near;
  3257. var x = ( right + left ) / w;
  3258. var y = ( top + bottom ) / h;
  3259. var z = ( far + near ) / p;
  3260. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3261. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3262. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3263. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3264. return this;
  3265. },
  3266. fromArray: function ( array ) {
  3267. this.elements.set( array );
  3268. return this;
  3269. },
  3270. toArray: function () {
  3271. var te = this.elements;
  3272. return [
  3273. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3274. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3275. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3276. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3277. ];
  3278. },
  3279. clone: function () {
  3280. return new THREE.Matrix4().fromArray( this.elements );
  3281. }
  3282. };
  3283. // File:src/math/Ray.js
  3284. /**
  3285. * @author bhouston / http://exocortex.com
  3286. */
  3287. THREE.Ray = function ( origin, direction ) {
  3288. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3289. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3290. };
  3291. THREE.Ray.prototype = {
  3292. constructor: THREE.Ray,
  3293. set: function ( origin, direction ) {
  3294. this.origin.copy( origin );
  3295. this.direction.copy( direction );
  3296. return this;
  3297. },
  3298. copy: function ( ray ) {
  3299. this.origin.copy( ray.origin );
  3300. this.direction.copy( ray.direction );
  3301. return this;
  3302. },
  3303. at: function ( t, optionalTarget ) {
  3304. var result = optionalTarget || new THREE.Vector3();
  3305. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3306. },
  3307. recast: function () {
  3308. var v1 = new THREE.Vector3();
  3309. return function ( t ) {
  3310. this.origin.copy( this.at( t, v1 ) );
  3311. return this;
  3312. };
  3313. }(),
  3314. closestPointToPoint: function ( point, optionalTarget ) {
  3315. var result = optionalTarget || new THREE.Vector3();
  3316. result.subVectors( point, this.origin );
  3317. var directionDistance = result.dot( this.direction );
  3318. if ( directionDistance < 0 ) {
  3319. return result.copy( this.origin );
  3320. }
  3321. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3322. },
  3323. distanceToPoint: function () {
  3324. var v1 = new THREE.Vector3();
  3325. return function ( point ) {
  3326. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3327. // point behind the ray
  3328. if ( directionDistance < 0 ) {
  3329. return this.origin.distanceTo( point );
  3330. }
  3331. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3332. return v1.distanceTo( point );
  3333. };
  3334. }(),
  3335. distanceSqToSegment: function () {
  3336. var segCenter = new THREE.Vector3();
  3337. var segDir = new THREE.Vector3();
  3338. var diff = new THREE.Vector3();
  3339. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3340. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3341. // It returns the min distance between the ray and the segment
  3342. // defined by v0 and v1
  3343. // It can also set two optional targets :
  3344. // - The closest point on the ray
  3345. // - The closest point on the segment
  3346. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3347. segDir.copy( v1 ).sub( v0 ).normalize();
  3348. diff.copy( this.origin ).sub( segCenter );
  3349. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3350. var a01 = - this.direction.dot( segDir );
  3351. var b0 = diff.dot( this.direction );
  3352. var b1 = - diff.dot( segDir );
  3353. var c = diff.lengthSq();
  3354. var det = Math.abs( 1 - a01 * a01 );
  3355. var s0, s1, sqrDist, extDet;
  3356. if ( det > 0 ) {
  3357. // The ray and segment are not parallel.
  3358. s0 = a01 * b1 - b0;
  3359. s1 = a01 * b0 - b1;
  3360. extDet = segExtent * det;
  3361. if ( s0 >= 0 ) {
  3362. if ( s1 >= - extDet ) {
  3363. if ( s1 <= extDet ) {
  3364. // region 0
  3365. // Minimum at interior points of ray and segment.
  3366. var invDet = 1 / det;
  3367. s0 *= invDet;
  3368. s1 *= invDet;
  3369. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3370. } else {
  3371. // region 1
  3372. s1 = segExtent;
  3373. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3374. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3375. }
  3376. } else {
  3377. // region 5
  3378. s1 = - segExtent;
  3379. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3380. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3381. }
  3382. } else {
  3383. if ( s1 <= - extDet ) {
  3384. // region 4
  3385. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3386. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3387. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3388. } else if ( s1 <= extDet ) {
  3389. // region 3
  3390. s0 = 0;
  3391. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3392. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3393. } else {
  3394. // region 2
  3395. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3396. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3397. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3398. }
  3399. }
  3400. } else {
  3401. // Ray and segment are parallel.
  3402. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3403. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3404. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3405. }
  3406. if ( optionalPointOnRay ) {
  3407. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3408. }
  3409. if ( optionalPointOnSegment ) {
  3410. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3411. }
  3412. return sqrDist;
  3413. };
  3414. }(),
  3415. isIntersectionSphere: function ( sphere ) {
  3416. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3417. },
  3418. intersectSphere: function () {
  3419. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3420. var v1 = new THREE.Vector3();
  3421. return function ( sphere, optionalTarget ) {
  3422. v1.subVectors( sphere.center, this.origin );
  3423. var tca = v1.dot( this.direction );
  3424. var d2 = v1.dot( v1 ) - tca * tca;
  3425. var radius2 = sphere.radius * sphere.radius;
  3426. if ( d2 > radius2 ) return null;
  3427. var thc = Math.sqrt( radius2 - d2 );
  3428. // t0 = first intersect point - entrance on front of sphere
  3429. var t0 = tca - thc;
  3430. // t1 = second intersect point - exit point on back of sphere
  3431. var t1 = tca + thc;
  3432. // test to see if both t0 and t1 are behind the ray - if so, return null
  3433. if ( t0 < 0 && t1 < 0 ) return null;
  3434. // test to see if t0 is behind the ray:
  3435. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3436. // in order to always return an intersect point that is in front of the ray.
  3437. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3438. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3439. return this.at( t0, optionalTarget );
  3440. }
  3441. }(),
  3442. isIntersectionPlane: function ( plane ) {
  3443. // check if the ray lies on the plane first
  3444. var distToPoint = plane.distanceToPoint( this.origin );
  3445. if ( distToPoint === 0 ) {
  3446. return true;
  3447. }
  3448. var denominator = plane.normal.dot( this.direction );
  3449. if ( denominator * distToPoint < 0 ) {
  3450. return true;
  3451. }
  3452. // ray origin is behind the plane (and is pointing behind it)
  3453. return false;
  3454. },
  3455. distanceToPlane: function ( plane ) {
  3456. var denominator = plane.normal.dot( this.direction );
  3457. if ( denominator === 0 ) {
  3458. // line is coplanar, return origin
  3459. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3460. return 0;
  3461. }
  3462. // Null is preferable to undefined since undefined means.... it is undefined
  3463. return null;
  3464. }
  3465. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3466. // Return if the ray never intersects the plane
  3467. return t >= 0 ? t : null;
  3468. },
  3469. intersectPlane: function ( plane, optionalTarget ) {
  3470. var t = this.distanceToPlane( plane );
  3471. if ( t === null ) {
  3472. return null;
  3473. }
  3474. return this.at( t, optionalTarget );
  3475. },
  3476. isIntersectionBox: function () {
  3477. var v = new THREE.Vector3();
  3478. return function ( box ) {
  3479. return this.intersectBox( box, v ) !== null;
  3480. };
  3481. }(),
  3482. intersectBox: function ( box, optionalTarget ) {
  3483. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3484. var tmin,tmax,tymin,tymax,tzmin,tzmax;
  3485. var invdirx = 1 / this.direction.x,
  3486. invdiry = 1 / this.direction.y,
  3487. invdirz = 1 / this.direction.z;
  3488. var origin = this.origin;
  3489. if ( invdirx >= 0 ) {
  3490. tmin = ( box.min.x - origin.x ) * invdirx;
  3491. tmax = ( box.max.x - origin.x ) * invdirx;
  3492. } else {
  3493. tmin = ( box.max.x - origin.x ) * invdirx;
  3494. tmax = ( box.min.x - origin.x ) * invdirx;
  3495. }
  3496. if ( invdiry >= 0 ) {
  3497. tymin = ( box.min.y - origin.y ) * invdiry;
  3498. tymax = ( box.max.y - origin.y ) * invdiry;
  3499. } else {
  3500. tymin = ( box.max.y - origin.y ) * invdiry;
  3501. tymax = ( box.min.y - origin.y ) * invdiry;
  3502. }
  3503. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3504. // These lines also handle the case where tmin or tmax is NaN
  3505. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3506. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3507. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3508. if ( invdirz >= 0 ) {
  3509. tzmin = ( box.min.z - origin.z ) * invdirz;
  3510. tzmax = ( box.max.z - origin.z ) * invdirz;
  3511. } else {
  3512. tzmin = ( box.max.z - origin.z ) * invdirz;
  3513. tzmax = ( box.min.z - origin.z ) * invdirz;
  3514. }
  3515. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3516. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3517. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3518. //return point closest to the ray (positive side)
  3519. if ( tmax < 0 ) return null;
  3520. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3521. },
  3522. intersectTriangle: function () {
  3523. // Compute the offset origin, edges, and normal.
  3524. var diff = new THREE.Vector3();
  3525. var edge1 = new THREE.Vector3();
  3526. var edge2 = new THREE.Vector3();
  3527. var normal = new THREE.Vector3();
  3528. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3529. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3530. edge1.subVectors( b, a );
  3531. edge2.subVectors( c, a );
  3532. normal.crossVectors( edge1, edge2 );
  3533. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3534. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3535. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3536. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3537. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3538. var DdN = this.direction.dot( normal );
  3539. var sign;
  3540. if ( DdN > 0 ) {
  3541. if ( backfaceCulling ) return null;
  3542. sign = 1;
  3543. } else if ( DdN < 0 ) {
  3544. sign = - 1;
  3545. DdN = - DdN;
  3546. } else {
  3547. return null;
  3548. }
  3549. diff.subVectors( this.origin, a );
  3550. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3551. // b1 < 0, no intersection
  3552. if ( DdQxE2 < 0 ) {
  3553. return null;
  3554. }
  3555. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3556. // b2 < 0, no intersection
  3557. if ( DdE1xQ < 0 ) {
  3558. return null;
  3559. }
  3560. // b1+b2 > 1, no intersection
  3561. if ( DdQxE2 + DdE1xQ > DdN ) {
  3562. return null;
  3563. }
  3564. // Line intersects triangle, check if ray does.
  3565. var QdN = - sign * diff.dot( normal );
  3566. // t < 0, no intersection
  3567. if ( QdN < 0 ) {
  3568. return null;
  3569. }
  3570. // Ray intersects triangle.
  3571. return this.at( QdN / DdN, optionalTarget );
  3572. };
  3573. }(),
  3574. applyMatrix4: function ( matrix4 ) {
  3575. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3576. this.origin.applyMatrix4( matrix4 );
  3577. this.direction.sub( this.origin );
  3578. this.direction.normalize();
  3579. return this;
  3580. },
  3581. equals: function ( ray ) {
  3582. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3583. },
  3584. clone: function () {
  3585. return new THREE.Ray().copy( this );
  3586. }
  3587. };
  3588. // File:src/math/Sphere.js
  3589. /**
  3590. * @author bhouston / http://exocortex.com
  3591. * @author mrdoob / http://mrdoob.com/
  3592. */
  3593. THREE.Sphere = function ( center, radius ) {
  3594. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3595. this.radius = ( radius !== undefined ) ? radius : 0;
  3596. };
  3597. THREE.Sphere.prototype = {
  3598. constructor: THREE.Sphere,
  3599. set: function ( center, radius ) {
  3600. this.center.copy( center );
  3601. this.radius = radius;
  3602. return this;
  3603. },
  3604. setFromPoints: function () {
  3605. var box = new THREE.Box3();
  3606. return function ( points, optionalCenter ) {
  3607. var center = this.center;
  3608. if ( optionalCenter !== undefined ) {
  3609. center.copy( optionalCenter );
  3610. } else {
  3611. box.setFromPoints( points ).center( center );
  3612. }
  3613. var maxRadiusSq = 0;
  3614. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3615. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3616. }
  3617. this.radius = Math.sqrt( maxRadiusSq );
  3618. return this;
  3619. };
  3620. }(),
  3621. copy: function ( sphere ) {
  3622. this.center.copy( sphere.center );
  3623. this.radius = sphere.radius;
  3624. return this;
  3625. },
  3626. empty: function () {
  3627. return ( this.radius <= 0 );
  3628. },
  3629. containsPoint: function ( point ) {
  3630. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3631. },
  3632. distanceToPoint: function ( point ) {
  3633. return ( point.distanceTo( this.center ) - this.radius );
  3634. },
  3635. intersectsSphere: function ( sphere ) {
  3636. var radiusSum = this.radius + sphere.radius;
  3637. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3638. },
  3639. clampPoint: function ( point, optionalTarget ) {
  3640. var deltaLengthSq = this.center.distanceToSquared( point );
  3641. var result = optionalTarget || new THREE.Vector3();
  3642. result.copy( point );
  3643. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3644. result.sub( this.center ).normalize();
  3645. result.multiplyScalar( this.radius ).add( this.center );
  3646. }
  3647. return result;
  3648. },
  3649. getBoundingBox: function ( optionalTarget ) {
  3650. var box = optionalTarget || new THREE.Box3();
  3651. box.set( this.center, this.center );
  3652. box.expandByScalar( this.radius );
  3653. return box;
  3654. },
  3655. applyMatrix4: function ( matrix ) {
  3656. this.center.applyMatrix4( matrix );
  3657. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3658. return this;
  3659. },
  3660. translate: function ( offset ) {
  3661. this.center.add( offset );
  3662. return this;
  3663. },
  3664. equals: function ( sphere ) {
  3665. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3666. },
  3667. clone: function () {
  3668. return new THREE.Sphere().copy( this );
  3669. }
  3670. };
  3671. // File:src/math/Frustum.js
  3672. /**
  3673. * @author mrdoob / http://mrdoob.com/
  3674. * @author alteredq / http://alteredqualia.com/
  3675. * @author bhouston / http://exocortex.com
  3676. */
  3677. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3678. this.planes = [
  3679. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3680. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3681. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3682. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3683. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3684. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3685. ];
  3686. };
  3687. THREE.Frustum.prototype = {
  3688. constructor: THREE.Frustum,
  3689. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3690. var planes = this.planes;
  3691. planes[ 0 ].copy( p0 );
  3692. planes[ 1 ].copy( p1 );
  3693. planes[ 2 ].copy( p2 );
  3694. planes[ 3 ].copy( p3 );
  3695. planes[ 4 ].copy( p4 );
  3696. planes[ 5 ].copy( p5 );
  3697. return this;
  3698. },
  3699. copy: function ( frustum ) {
  3700. var planes = this.planes;
  3701. for ( var i = 0; i < 6; i ++ ) {
  3702. planes[ i ].copy( frustum.planes[ i ] );
  3703. }
  3704. return this;
  3705. },
  3706. setFromMatrix: function ( m ) {
  3707. var planes = this.planes;
  3708. var me = m.elements;
  3709. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3710. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3711. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3712. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3713. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3714. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3715. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3716. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3717. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3718. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3719. return this;
  3720. },
  3721. intersectsObject: function () {
  3722. var sphere = new THREE.Sphere();
  3723. return function ( object ) {
  3724. var geometry = object.geometry;
  3725. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3726. sphere.copy( geometry.boundingSphere );
  3727. sphere.applyMatrix4( object.matrixWorld );
  3728. return this.intersectsSphere( sphere );
  3729. };
  3730. }(),
  3731. intersectsSphere: function ( sphere ) {
  3732. var planes = this.planes;
  3733. var center = sphere.center;
  3734. var negRadius = - sphere.radius;
  3735. for ( var i = 0; i < 6; i ++ ) {
  3736. var distance = planes[ i ].distanceToPoint( center );
  3737. if ( distance < negRadius ) {
  3738. return false;
  3739. }
  3740. }
  3741. return true;
  3742. },
  3743. intersectsBox: function () {
  3744. var p1 = new THREE.Vector3(),
  3745. p2 = new THREE.Vector3();
  3746. return function ( box ) {
  3747. var planes = this.planes;
  3748. for ( var i = 0; i < 6 ; i ++ ) {
  3749. var plane = planes[ i ];
  3750. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3751. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3752. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3753. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3754. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3755. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3756. var d1 = plane.distanceToPoint( p1 );
  3757. var d2 = plane.distanceToPoint( p2 );
  3758. // if both outside plane, no intersection
  3759. if ( d1 < 0 && d2 < 0 ) {
  3760. return false;
  3761. }
  3762. }
  3763. return true;
  3764. };
  3765. }(),
  3766. containsPoint: function ( point ) {
  3767. var planes = this.planes;
  3768. for ( var i = 0; i < 6; i ++ ) {
  3769. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3770. return false;
  3771. }
  3772. }
  3773. return true;
  3774. },
  3775. clone: function () {
  3776. return new THREE.Frustum().copy( this );
  3777. }
  3778. };
  3779. // File:src/math/Plane.js
  3780. /**
  3781. * @author bhouston / http://exocortex.com
  3782. */
  3783. THREE.Plane = function ( normal, constant ) {
  3784. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3785. this.constant = ( constant !== undefined ) ? constant : 0;
  3786. };
  3787. THREE.Plane.prototype = {
  3788. constructor: THREE.Plane,
  3789. set: function ( normal, constant ) {
  3790. this.normal.copy( normal );
  3791. this.constant = constant;
  3792. return this;
  3793. },
  3794. setComponents: function ( x, y, z, w ) {
  3795. this.normal.set( x, y, z );
  3796. this.constant = w;
  3797. return this;
  3798. },
  3799. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3800. this.normal.copy( normal );
  3801. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3802. return this;
  3803. },
  3804. setFromCoplanarPoints: function () {
  3805. var v1 = new THREE.Vector3();
  3806. var v2 = new THREE.Vector3();
  3807. return function ( a, b, c ) {
  3808. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3809. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3810. this.setFromNormalAndCoplanarPoint( normal, a );
  3811. return this;
  3812. };
  3813. }(),
  3814. copy: function ( plane ) {
  3815. this.normal.copy( plane.normal );
  3816. this.constant = plane.constant;
  3817. return this;
  3818. },
  3819. normalize: function () {
  3820. // Note: will lead to a divide by zero if the plane is invalid.
  3821. var inverseNormalLength = 1.0 / this.normal.length();
  3822. this.normal.multiplyScalar( inverseNormalLength );
  3823. this.constant *= inverseNormalLength;
  3824. return this;
  3825. },
  3826. negate: function () {
  3827. this.constant *= - 1;
  3828. this.normal.negate();
  3829. return this;
  3830. },
  3831. distanceToPoint: function ( point ) {
  3832. return this.normal.dot( point ) + this.constant;
  3833. },
  3834. distanceToSphere: function ( sphere ) {
  3835. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3836. },
  3837. projectPoint: function ( point, optionalTarget ) {
  3838. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3839. },
  3840. orthoPoint: function ( point, optionalTarget ) {
  3841. var perpendicularMagnitude = this.distanceToPoint( point );
  3842. var result = optionalTarget || new THREE.Vector3();
  3843. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3844. },
  3845. isIntersectionLine: function ( line ) {
  3846. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3847. var startSign = this.distanceToPoint( line.start );
  3848. var endSign = this.distanceToPoint( line.end );
  3849. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3850. },
  3851. intersectLine: function () {
  3852. var v1 = new THREE.Vector3();
  3853. return function ( line, optionalTarget ) {
  3854. var result = optionalTarget || new THREE.Vector3();
  3855. var direction = line.delta( v1 );
  3856. var denominator = this.normal.dot( direction );
  3857. if ( denominator === 0 ) {
  3858. // line is coplanar, return origin
  3859. if ( this.distanceToPoint( line.start ) === 0 ) {
  3860. return result.copy( line.start );
  3861. }
  3862. // Unsure if this is the correct method to handle this case.
  3863. return undefined;
  3864. }
  3865. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3866. if ( t < 0 || t > 1 ) {
  3867. return undefined;
  3868. }
  3869. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  3870. };
  3871. }(),
  3872. coplanarPoint: function ( optionalTarget ) {
  3873. var result = optionalTarget || new THREE.Vector3();
  3874. return result.copy( this.normal ).multiplyScalar( - this.constant );
  3875. },
  3876. applyMatrix4: function () {
  3877. var v1 = new THREE.Vector3();
  3878. var v2 = new THREE.Vector3();
  3879. var m1 = new THREE.Matrix3();
  3880. return function ( matrix, optionalNormalMatrix ) {
  3881. // compute new normal based on theory here:
  3882. // http://www.songho.ca/opengl/gl_normaltransform.html
  3883. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  3884. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  3885. var newCoplanarPoint = this.coplanarPoint( v2 );
  3886. newCoplanarPoint.applyMatrix4( matrix );
  3887. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  3888. return this;
  3889. };
  3890. }(),
  3891. translate: function ( offset ) {
  3892. this.constant = this.constant - offset.dot( this.normal );
  3893. return this;
  3894. },
  3895. equals: function ( plane ) {
  3896. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  3897. },
  3898. clone: function () {
  3899. return new THREE.Plane().copy( this );
  3900. }
  3901. };
  3902. // File:src/math/Math.js
  3903. /**
  3904. * @author alteredq / http://alteredqualia.com/
  3905. * @author mrdoob / http://mrdoob.com/
  3906. */
  3907. THREE.Math = {
  3908. generateUUID: function () {
  3909. // http://www.broofa.com/Tools/Math.uuid.htm
  3910. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  3911. var uuid = new Array( 36 );
  3912. var rnd = 0, r;
  3913. return function () {
  3914. for ( var i = 0; i < 36; i ++ ) {
  3915. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  3916. uuid[ i ] = '-';
  3917. } else if ( i === 14 ) {
  3918. uuid[ i ] = '4';
  3919. } else {
  3920. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  3921. r = rnd & 0xf;
  3922. rnd = rnd >> 4;
  3923. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  3924. }
  3925. }
  3926. return uuid.join( '' );
  3927. };
  3928. }(),
  3929. // Clamp value to range <a, b>
  3930. clamp: function ( x, a, b ) {
  3931. return ( x < a ) ? a : ( ( x > b ) ? b : x );
  3932. },
  3933. // Clamp value to range <a, inf)
  3934. clampBottom: function ( x, a ) {
  3935. return x < a ? a : x;
  3936. },
  3937. // Linear mapping from range <a1, a2> to range <b1, b2>
  3938. mapLinear: function ( x, a1, a2, b1, b2 ) {
  3939. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  3940. },
  3941. // http://en.wikipedia.org/wiki/Smoothstep
  3942. smoothstep: function ( x, min, max ) {
  3943. if ( x <= min ) return 0;
  3944. if ( x >= max ) return 1;
  3945. x = ( x - min ) / ( max - min );
  3946. return x * x * ( 3 - 2 * x );
  3947. },
  3948. smootherstep: function ( x, min, max ) {
  3949. if ( x <= min ) return 0;
  3950. if ( x >= max ) return 1;
  3951. x = ( x - min ) / ( max - min );
  3952. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  3953. },
  3954. // Random float from <0, 1> with 16 bits of randomness
  3955. // (standard Math.random() creates repetitive patterns when applied over larger space)
  3956. random16: function () {
  3957. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  3958. },
  3959. // Random integer from <low, high> interval
  3960. randInt: function ( low, high ) {
  3961. return Math.floor( this.randFloat( low, high ) );
  3962. },
  3963. // Random float from <low, high> interval
  3964. randFloat: function ( low, high ) {
  3965. return low + Math.random() * ( high - low );
  3966. },
  3967. // Random float from <-range/2, range/2> interval
  3968. randFloatSpread: function ( range ) {
  3969. return range * ( 0.5 - Math.random() );
  3970. },
  3971. degToRad: function () {
  3972. var degreeToRadiansFactor = Math.PI / 180;
  3973. return function ( degrees ) {
  3974. return degrees * degreeToRadiansFactor;
  3975. };
  3976. }(),
  3977. radToDeg: function () {
  3978. var radianToDegreesFactor = 180 / Math.PI;
  3979. return function ( radians ) {
  3980. return radians * radianToDegreesFactor;
  3981. };
  3982. }(),
  3983. isPowerOfTwo: function ( value ) {
  3984. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  3985. },
  3986. nextPowerOfTwo: function ( value ) {
  3987. value --;
  3988. value |= value >> 1;
  3989. value |= value >> 2;
  3990. value |= value >> 4;
  3991. value |= value >> 8;
  3992. value |= value >> 16;
  3993. value ++;
  3994. return value;
  3995. }
  3996. };
  3997. // File:src/math/Spline.js
  3998. /**
  3999. * Spline from Tween.js, slightly optimized (and trashed)
  4000. * http://sole.github.com/tween.js/examples/05_spline.html
  4001. *
  4002. * @author mrdoob / http://mrdoob.com/
  4003. * @author alteredq / http://alteredqualia.com/
  4004. */
  4005. THREE.Spline = function ( points ) {
  4006. this.points = points;
  4007. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4008. point, intPoint, weight, w2, w3,
  4009. pa, pb, pc, pd;
  4010. this.initFromArray = function ( a ) {
  4011. this.points = [];
  4012. for ( var i = 0; i < a.length; i ++ ) {
  4013. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4014. }
  4015. };
  4016. this.getPoint = function ( k ) {
  4017. point = ( this.points.length - 1 ) * k;
  4018. intPoint = Math.floor( point );
  4019. weight = point - intPoint;
  4020. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4021. c[ 1 ] = intPoint;
  4022. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4023. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4024. pa = this.points[ c[ 0 ] ];
  4025. pb = this.points[ c[ 1 ] ];
  4026. pc = this.points[ c[ 2 ] ];
  4027. pd = this.points[ c[ 3 ] ];
  4028. w2 = weight * weight;
  4029. w3 = weight * w2;
  4030. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4031. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4032. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4033. return v3;
  4034. };
  4035. this.getControlPointsArray = function () {
  4036. var i, p, l = this.points.length,
  4037. coords = [];
  4038. for ( i = 0; i < l; i ++ ) {
  4039. p = this.points[ i ];
  4040. coords[ i ] = [ p.x, p.y, p.z ];
  4041. }
  4042. return coords;
  4043. };
  4044. // approximate length by summing linear segments
  4045. this.getLength = function ( nSubDivisions ) {
  4046. var i, index, nSamples, position,
  4047. point = 0, intPoint = 0, oldIntPoint = 0,
  4048. oldPosition = new THREE.Vector3(),
  4049. tmpVec = new THREE.Vector3(),
  4050. chunkLengths = [],
  4051. totalLength = 0;
  4052. // first point has 0 length
  4053. chunkLengths[ 0 ] = 0;
  4054. if ( ! nSubDivisions ) nSubDivisions = 100;
  4055. nSamples = this.points.length * nSubDivisions;
  4056. oldPosition.copy( this.points[ 0 ] );
  4057. for ( i = 1; i < nSamples; i ++ ) {
  4058. index = i / nSamples;
  4059. position = this.getPoint( index );
  4060. tmpVec.copy( position );
  4061. totalLength += tmpVec.distanceTo( oldPosition );
  4062. oldPosition.copy( position );
  4063. point = ( this.points.length - 1 ) * index;
  4064. intPoint = Math.floor( point );
  4065. if ( intPoint !== oldIntPoint ) {
  4066. chunkLengths[ intPoint ] = totalLength;
  4067. oldIntPoint = intPoint;
  4068. }
  4069. }
  4070. // last point ends with total length
  4071. chunkLengths[ chunkLengths.length ] = totalLength;
  4072. return { chunks: chunkLengths, total: totalLength };
  4073. };
  4074. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4075. var i, j,
  4076. index, indexCurrent, indexNext,
  4077. realDistance,
  4078. sampling, position,
  4079. newpoints = [],
  4080. tmpVec = new THREE.Vector3(),
  4081. sl = this.getLength();
  4082. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4083. for ( i = 1; i < this.points.length; i ++ ) {
  4084. //tmpVec.copy( this.points[ i - 1 ] );
  4085. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4086. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4087. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4088. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4089. indexNext = i / ( this.points.length - 1 );
  4090. for ( j = 1; j < sampling - 1; j ++ ) {
  4091. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4092. position = this.getPoint( index );
  4093. newpoints.push( tmpVec.copy( position ).clone() );
  4094. }
  4095. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4096. }
  4097. this.points = newpoints;
  4098. };
  4099. // Catmull-Rom
  4100. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4101. var v0 = ( p2 - p0 ) * 0.5,
  4102. v1 = ( p3 - p1 ) * 0.5;
  4103. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4104. }
  4105. };
  4106. // File:src/math/Triangle.js
  4107. /**
  4108. * @author bhouston / http://exocortex.com
  4109. * @author mrdoob / http://mrdoob.com/
  4110. */
  4111. THREE.Triangle = function ( a, b, c ) {
  4112. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4113. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4114. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4115. };
  4116. THREE.Triangle.normal = function () {
  4117. var v0 = new THREE.Vector3();
  4118. return function ( a, b, c, optionalTarget ) {
  4119. var result = optionalTarget || new THREE.Vector3();
  4120. result.subVectors( c, b );
  4121. v0.subVectors( a, b );
  4122. result.cross( v0 );
  4123. var resultLengthSq = result.lengthSq();
  4124. if ( resultLengthSq > 0 ) {
  4125. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4126. }
  4127. return result.set( 0, 0, 0 );
  4128. };
  4129. }();
  4130. // static/instance method to calculate barycoordinates
  4131. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4132. THREE.Triangle.barycoordFromPoint = function () {
  4133. var v0 = new THREE.Vector3();
  4134. var v1 = new THREE.Vector3();
  4135. var v2 = new THREE.Vector3();
  4136. return function ( point, a, b, c, optionalTarget ) {
  4137. v0.subVectors( c, a );
  4138. v1.subVectors( b, a );
  4139. v2.subVectors( point, a );
  4140. var dot00 = v0.dot( v0 );
  4141. var dot01 = v0.dot( v1 );
  4142. var dot02 = v0.dot( v2 );
  4143. var dot11 = v1.dot( v1 );
  4144. var dot12 = v1.dot( v2 );
  4145. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4146. var result = optionalTarget || new THREE.Vector3();
  4147. // colinear or singular triangle
  4148. if ( denom === 0 ) {
  4149. // arbitrary location outside of triangle?
  4150. // not sure if this is the best idea, maybe should be returning undefined
  4151. return result.set( - 2, - 1, - 1 );
  4152. }
  4153. var invDenom = 1 / denom;
  4154. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4155. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4156. // barycoordinates must always sum to 1
  4157. return result.set( 1 - u - v, v, u );
  4158. };
  4159. }();
  4160. THREE.Triangle.containsPoint = function () {
  4161. var v1 = new THREE.Vector3();
  4162. return function ( point, a, b, c ) {
  4163. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4164. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4165. };
  4166. }();
  4167. THREE.Triangle.prototype = {
  4168. constructor: THREE.Triangle,
  4169. set: function ( a, b, c ) {
  4170. this.a.copy( a );
  4171. this.b.copy( b );
  4172. this.c.copy( c );
  4173. return this;
  4174. },
  4175. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4176. this.a.copy( points[ i0 ] );
  4177. this.b.copy( points[ i1 ] );
  4178. this.c.copy( points[ i2 ] );
  4179. return this;
  4180. },
  4181. copy: function ( triangle ) {
  4182. this.a.copy( triangle.a );
  4183. this.b.copy( triangle.b );
  4184. this.c.copy( triangle.c );
  4185. return this;
  4186. },
  4187. area: function () {
  4188. var v0 = new THREE.Vector3();
  4189. var v1 = new THREE.Vector3();
  4190. return function () {
  4191. v0.subVectors( this.c, this.b );
  4192. v1.subVectors( this.a, this.b );
  4193. return v0.cross( v1 ).length() * 0.5;
  4194. };
  4195. }(),
  4196. midpoint: function ( optionalTarget ) {
  4197. var result = optionalTarget || new THREE.Vector3();
  4198. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4199. },
  4200. normal: function ( optionalTarget ) {
  4201. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4202. },
  4203. plane: function ( optionalTarget ) {
  4204. var result = optionalTarget || new THREE.Plane();
  4205. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4206. },
  4207. barycoordFromPoint: function ( point, optionalTarget ) {
  4208. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4209. },
  4210. containsPoint: function ( point ) {
  4211. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4212. },
  4213. equals: function ( triangle ) {
  4214. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4215. },
  4216. clone: function () {
  4217. return new THREE.Triangle().copy( this );
  4218. }
  4219. };
  4220. // File:src/core/Clock.js
  4221. /**
  4222. * @author alteredq / http://alteredqualia.com/
  4223. */
  4224. THREE.Clock = function ( autoStart ) {
  4225. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4226. this.startTime = 0;
  4227. this.oldTime = 0;
  4228. this.elapsedTime = 0;
  4229. this.running = false;
  4230. };
  4231. THREE.Clock.prototype = {
  4232. constructor: THREE.Clock,
  4233. start: function () {
  4234. this.startTime = self.performance !== undefined && self.performance.now !== undefined
  4235. ? self.performance.now()
  4236. : Date.now();
  4237. this.oldTime = this.startTime;
  4238. this.running = true;
  4239. },
  4240. stop: function () {
  4241. this.getElapsedTime();
  4242. this.running = false;
  4243. },
  4244. getElapsedTime: function () {
  4245. this.getDelta();
  4246. return this.elapsedTime;
  4247. },
  4248. getDelta: function () {
  4249. var diff = 0;
  4250. if ( this.autoStart && ! this.running ) {
  4251. this.start();
  4252. }
  4253. if ( this.running ) {
  4254. var newTime = self.performance !== undefined && self.performance.now !== undefined
  4255. ? self.performance.now()
  4256. : Date.now();
  4257. diff = 0.001 * ( newTime - this.oldTime );
  4258. this.oldTime = newTime;
  4259. this.elapsedTime += diff;
  4260. }
  4261. return diff;
  4262. }
  4263. };
  4264. // File:src/core/EventDispatcher.js
  4265. /**
  4266. * https://github.com/mrdoob/eventdispatcher.js/
  4267. */
  4268. THREE.EventDispatcher = function () {};
  4269. THREE.EventDispatcher.prototype = {
  4270. constructor: THREE.EventDispatcher,
  4271. apply: function ( object ) {
  4272. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4273. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4274. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4275. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4276. },
  4277. addEventListener: function ( type, listener ) {
  4278. if ( this._listeners === undefined ) this._listeners = {};
  4279. var listeners = this._listeners;
  4280. if ( listeners[ type ] === undefined ) {
  4281. listeners[ type ] = [];
  4282. }
  4283. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4284. listeners[ type ].push( listener );
  4285. }
  4286. },
  4287. hasEventListener: function ( type, listener ) {
  4288. if ( this._listeners === undefined ) return false;
  4289. var listeners = this._listeners;
  4290. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4291. return true;
  4292. }
  4293. return false;
  4294. },
  4295. removeEventListener: function ( type, listener ) {
  4296. if ( this._listeners === undefined ) return;
  4297. var listeners = this._listeners;
  4298. var listenerArray = listeners[ type ];
  4299. if ( listenerArray !== undefined ) {
  4300. var index = listenerArray.indexOf( listener );
  4301. if ( index !== - 1 ) {
  4302. listenerArray.splice( index, 1 );
  4303. }
  4304. }
  4305. },
  4306. dispatchEvent: function ( event ) {
  4307. if ( this._listeners === undefined ) return;
  4308. var listeners = this._listeners;
  4309. var listenerArray = listeners[ event.type ];
  4310. if ( listenerArray !== undefined ) {
  4311. event.target = this;
  4312. var array = [];
  4313. var length = listenerArray.length;
  4314. for ( var i = 0; i < length; i ++ ) {
  4315. array[ i ] = listenerArray[ i ];
  4316. }
  4317. for ( var i = 0; i < length; i ++ ) {
  4318. array[ i ].call( this, event );
  4319. }
  4320. }
  4321. }
  4322. };
  4323. // File:src/core/Raycaster.js
  4324. /**
  4325. * @author mrdoob / http://mrdoob.com/
  4326. * @author bhouston / http://exocortex.com/
  4327. * @author stephomi / http://stephaneginier.com/
  4328. */
  4329. ( function ( THREE ) {
  4330. THREE.Raycaster = function ( origin, direction, near, far ) {
  4331. this.ray = new THREE.Ray( origin, direction );
  4332. // direction is assumed to be normalized (for accurate distance calculations)
  4333. this.near = near || 0;
  4334. this.far = far || Infinity;
  4335. this.params = {
  4336. Sprite: {},
  4337. Mesh: {},
  4338. PointCloud: { threshold: 1 },
  4339. LOD: {},
  4340. Line: {}
  4341. };
  4342. };
  4343. var descSort = function ( a, b ) {
  4344. return a.distance - b.distance;
  4345. };
  4346. var intersectObject = function ( object, raycaster, intersects, recursive ) {
  4347. object.raycast( raycaster, intersects );
  4348. if ( recursive === true ) {
  4349. var children = object.children;
  4350. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4351. intersectObject( children[ i ], raycaster, intersects, true );
  4352. }
  4353. }
  4354. };
  4355. //
  4356. THREE.Raycaster.prototype = {
  4357. constructor: THREE.Raycaster,
  4358. precision: 0.0001,
  4359. linePrecision: 1,
  4360. set: function ( origin, direction ) {
  4361. // direction is assumed to be normalized (for accurate distance calculations)
  4362. this.ray.set( origin, direction );
  4363. },
  4364. setFromCamera: function ( coords, camera ) {
  4365. if ( camera instanceof THREE.PerspectiveCamera ) {
  4366. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4367. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4368. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4369. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4370. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4371. } else {
  4372. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4373. }
  4374. },
  4375. intersectObject: function ( object, recursive ) {
  4376. var intersects = [];
  4377. intersectObject( object, this, intersects, recursive );
  4378. intersects.sort( descSort );
  4379. return intersects;
  4380. },
  4381. intersectObjects: function ( objects, recursive ) {
  4382. var intersects = [];
  4383. if ( Array.isArray( objects ) === false ) {
  4384. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4385. return intersects;
  4386. }
  4387. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4388. intersectObject( objects[ i ], this, intersects, recursive );
  4389. }
  4390. intersects.sort( descSort );
  4391. return intersects;
  4392. }
  4393. };
  4394. }( THREE ) );
  4395. // File:src/core/Object3D.js
  4396. /**
  4397. * @author mrdoob / http://mrdoob.com/
  4398. * @author mikael emtinger / http://gomo.se/
  4399. * @author alteredq / http://alteredqualia.com/
  4400. * @author WestLangley / http://github.com/WestLangley
  4401. * @author elephantatwork / www.elephantatwork.ch
  4402. */
  4403. THREE.Object3D = function () {
  4404. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4405. this.uuid = THREE.Math.generateUUID();
  4406. this.name = '';
  4407. this.type = 'Object3D';
  4408. this.parent = undefined;
  4409. this.children = [];
  4410. this.up = THREE.Object3D.DefaultUp.clone();
  4411. var position = new THREE.Vector3();
  4412. var rotation = new THREE.Euler();
  4413. var quaternion = new THREE.Quaternion();
  4414. var scale = new THREE.Vector3( 1, 1, 1 );
  4415. var onRotationChange = function () {
  4416. quaternion.setFromEuler( rotation, false );
  4417. };
  4418. var onQuaternionChange = function () {
  4419. rotation.setFromQuaternion( quaternion, undefined, false );
  4420. };
  4421. rotation.onChange( onRotationChange );
  4422. quaternion.onChange( onQuaternionChange );
  4423. Object.defineProperties( this, {
  4424. position: {
  4425. enumerable: true,
  4426. value: position
  4427. },
  4428. rotation: {
  4429. enumerable: true,
  4430. value: rotation
  4431. },
  4432. quaternion: {
  4433. enumerable: true,
  4434. value: quaternion
  4435. },
  4436. scale: {
  4437. enumerable: true,
  4438. value: scale
  4439. }
  4440. } );
  4441. this.rotationAutoUpdate = true;
  4442. this.matrix = new THREE.Matrix4();
  4443. this.matrixWorld = new THREE.Matrix4();
  4444. this.matrixAutoUpdate = true;
  4445. this.matrixWorldNeedsUpdate = false;
  4446. this.visible = true;
  4447. this.castShadow = false;
  4448. this.receiveShadow = false;
  4449. this.frustumCulled = true;
  4450. this.renderOrder = 0;
  4451. this.userData = {};
  4452. };
  4453. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4454. THREE.Object3D.prototype = {
  4455. constructor: THREE.Object3D,
  4456. get eulerOrder () {
  4457. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4458. return this.rotation.order;
  4459. },
  4460. set eulerOrder ( value ) {
  4461. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4462. this.rotation.order = value;
  4463. },
  4464. get useQuaternion () {
  4465. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4466. },
  4467. set useQuaternion ( value ) {
  4468. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4469. },
  4470. applyMatrix: function ( matrix ) {
  4471. this.matrix.multiplyMatrices( matrix, this.matrix );
  4472. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4473. },
  4474. setRotationFromAxisAngle: function ( axis, angle ) {
  4475. // assumes axis is normalized
  4476. this.quaternion.setFromAxisAngle( axis, angle );
  4477. },
  4478. setRotationFromEuler: function ( euler ) {
  4479. this.quaternion.setFromEuler( euler, true );
  4480. },
  4481. setRotationFromMatrix: function ( m ) {
  4482. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4483. this.quaternion.setFromRotationMatrix( m );
  4484. },
  4485. setRotationFromQuaternion: function ( q ) {
  4486. // assumes q is normalized
  4487. this.quaternion.copy( q );
  4488. },
  4489. rotateOnAxis: function () {
  4490. // rotate object on axis in object space
  4491. // axis is assumed to be normalized
  4492. var q1 = new THREE.Quaternion();
  4493. return function ( axis, angle ) {
  4494. q1.setFromAxisAngle( axis, angle );
  4495. this.quaternion.multiply( q1 );
  4496. return this;
  4497. }
  4498. }(),
  4499. rotateX: function () {
  4500. var v1 = new THREE.Vector3( 1, 0, 0 );
  4501. return function ( angle ) {
  4502. return this.rotateOnAxis( v1, angle );
  4503. };
  4504. }(),
  4505. rotateY: function () {
  4506. var v1 = new THREE.Vector3( 0, 1, 0 );
  4507. return function ( angle ) {
  4508. return this.rotateOnAxis( v1, angle );
  4509. };
  4510. }(),
  4511. rotateZ: function () {
  4512. var v1 = new THREE.Vector3( 0, 0, 1 );
  4513. return function ( angle ) {
  4514. return this.rotateOnAxis( v1, angle );
  4515. };
  4516. }(),
  4517. translateOnAxis: function () {
  4518. // translate object by distance along axis in object space
  4519. // axis is assumed to be normalized
  4520. var v1 = new THREE.Vector3();
  4521. return function ( axis, distance ) {
  4522. v1.copy( axis ).applyQuaternion( this.quaternion );
  4523. this.position.add( v1.multiplyScalar( distance ) );
  4524. return this;
  4525. }
  4526. }(),
  4527. translate: function ( distance, axis ) {
  4528. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  4529. return this.translateOnAxis( axis, distance );
  4530. },
  4531. translateX: function () {
  4532. var v1 = new THREE.Vector3( 1, 0, 0 );
  4533. return function ( distance ) {
  4534. return this.translateOnAxis( v1, distance );
  4535. };
  4536. }(),
  4537. translateY: function () {
  4538. var v1 = new THREE.Vector3( 0, 1, 0 );
  4539. return function ( distance ) {
  4540. return this.translateOnAxis( v1, distance );
  4541. };
  4542. }(),
  4543. translateZ: function () {
  4544. var v1 = new THREE.Vector3( 0, 0, 1 );
  4545. return function ( distance ) {
  4546. return this.translateOnAxis( v1, distance );
  4547. };
  4548. }(),
  4549. localToWorld: function ( vector ) {
  4550. return vector.applyMatrix4( this.matrixWorld );
  4551. },
  4552. worldToLocal: function () {
  4553. var m1 = new THREE.Matrix4();
  4554. return function ( vector ) {
  4555. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  4556. };
  4557. }(),
  4558. lookAt: function () {
  4559. // This routine does not support objects with rotated and/or translated parent(s)
  4560. var m1 = new THREE.Matrix4();
  4561. return function ( vector ) {
  4562. m1.lookAt( vector, this.position, this.up );
  4563. this.quaternion.setFromRotationMatrix( m1 );
  4564. };
  4565. }(),
  4566. add: function ( object ) {
  4567. if ( arguments.length > 1 ) {
  4568. for ( var i = 0; i < arguments.length; i ++ ) {
  4569. this.add( arguments[ i ] );
  4570. }
  4571. return this;
  4572. }
  4573. if ( object === this ) {
  4574. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  4575. return this;
  4576. }
  4577. if ( object instanceof THREE.Object3D ) {
  4578. if ( object.parent !== undefined ) {
  4579. object.parent.remove( object );
  4580. }
  4581. object.parent = this;
  4582. object.dispatchEvent( { type: 'added' } );
  4583. this.children.push( object );
  4584. } else {
  4585. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  4586. }
  4587. return this;
  4588. },
  4589. remove: function ( object ) {
  4590. if ( arguments.length > 1 ) {
  4591. for ( var i = 0; i < arguments.length; i ++ ) {
  4592. this.remove( arguments[ i ] );
  4593. }
  4594. }
  4595. var index = this.children.indexOf( object );
  4596. if ( index !== - 1 ) {
  4597. object.parent = undefined;
  4598. object.dispatchEvent( { type: 'removed' } );
  4599. this.children.splice( index, 1 );
  4600. }
  4601. },
  4602. getChildByName: function ( name ) {
  4603. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  4604. return this.getObjectByName( name );
  4605. },
  4606. getObjectById: function ( id ) {
  4607. return this.getObjectByProperty( 'id', id );
  4608. },
  4609. getObjectByName: function ( name ) {
  4610. return this.getObjectByProperty( 'name', name );
  4611. },
  4612. getObjectByProperty: function ( name, value ) {
  4613. if ( this[ name ] === value ) return this;
  4614. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4615. var child = this.children[ i ];
  4616. var object = child.getObjectByProperty( name, value );
  4617. if ( object !== undefined ) {
  4618. return object;
  4619. }
  4620. }
  4621. return undefined;
  4622. },
  4623. getWorldPosition: function ( optionalTarget ) {
  4624. var result = optionalTarget || new THREE.Vector3();
  4625. this.updateMatrixWorld( true );
  4626. return result.setFromMatrixPosition( this.matrixWorld );
  4627. },
  4628. getWorldQuaternion: function () {
  4629. var position = new THREE.Vector3();
  4630. var scale = new THREE.Vector3();
  4631. return function ( optionalTarget ) {
  4632. var result = optionalTarget || new THREE.Quaternion();
  4633. this.updateMatrixWorld( true );
  4634. this.matrixWorld.decompose( position, result, scale );
  4635. return result;
  4636. }
  4637. }(),
  4638. getWorldRotation: function () {
  4639. var quaternion = new THREE.Quaternion();
  4640. return function ( optionalTarget ) {
  4641. var result = optionalTarget || new THREE.Euler();
  4642. this.getWorldQuaternion( quaternion );
  4643. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  4644. }
  4645. }(),
  4646. getWorldScale: function () {
  4647. var position = new THREE.Vector3();
  4648. var quaternion = new THREE.Quaternion();
  4649. return function ( optionalTarget ) {
  4650. var result = optionalTarget || new THREE.Vector3();
  4651. this.updateMatrixWorld( true );
  4652. this.matrixWorld.decompose( position, quaternion, result );
  4653. return result;
  4654. }
  4655. }(),
  4656. getWorldDirection: function () {
  4657. var quaternion = new THREE.Quaternion();
  4658. return function ( optionalTarget ) {
  4659. var result = optionalTarget || new THREE.Vector3();
  4660. this.getWorldQuaternion( quaternion );
  4661. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  4662. }
  4663. }(),
  4664. raycast: function () {},
  4665. traverse: function ( callback ) {
  4666. callback( this );
  4667. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4668. this.children[ i ].traverse( callback );
  4669. }
  4670. },
  4671. traverseVisible: function ( callback ) {
  4672. if ( this.visible === false ) return;
  4673. callback( this );
  4674. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4675. this.children[ i ].traverseVisible( callback );
  4676. }
  4677. },
  4678. traverseAncestors: function ( callback ) {
  4679. if ( this.parent ) {
  4680. callback( this.parent );
  4681. this.parent.traverseAncestors( callback );
  4682. }
  4683. },
  4684. updateMatrix: function () {
  4685. this.matrix.compose( this.position, this.quaternion, this.scale );
  4686. this.matrixWorldNeedsUpdate = true;
  4687. },
  4688. updateMatrixWorld: function ( force ) {
  4689. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  4690. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  4691. if ( this.parent === undefined ) {
  4692. this.matrixWorld.copy( this.matrix );
  4693. } else {
  4694. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4695. }
  4696. this.matrixWorldNeedsUpdate = false;
  4697. force = true;
  4698. }
  4699. // update children
  4700. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4701. this.children[ i ].updateMatrixWorld( force );
  4702. }
  4703. },
  4704. toJSON: function ( meta ) {
  4705. var isRootObject = ( meta === undefined );
  4706. var data = {};
  4707. // meta is a hash used to collect geometries, materials.
  4708. // not providing it implies that this is the root object
  4709. // being serialized.
  4710. if ( isRootObject ) {
  4711. // initialize meta obj
  4712. meta = {
  4713. geometries: {},
  4714. materials: {},
  4715. textures: {},
  4716. images: {}
  4717. };
  4718. data.metadata = {
  4719. version: 4.4,
  4720. type: 'Object',
  4721. generator: 'Object3D.toJSON'
  4722. };
  4723. }
  4724. // standard Object3D serialization
  4725. data.uuid = this.uuid;
  4726. data.type = this.type;
  4727. if ( this.name !== '' ) data.name = this.name;
  4728. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  4729. if ( this.visible !== true ) data.visible = this.visible;
  4730. data.matrix = this.matrix.toArray();
  4731. if ( this.children.length > 0 ) {
  4732. data.children = [];
  4733. for ( var i = 0; i < this.children.length; i ++ ) {
  4734. data.children.push( this.children[ i ].toJSON( meta ).object );
  4735. }
  4736. }
  4737. var output = {};
  4738. if ( isRootObject ) {
  4739. var geometries = extractFromCache( meta.geometries );
  4740. var materials = extractFromCache( meta.materials );
  4741. var textures = extractFromCache( meta.textures );
  4742. var images = extractFromCache( meta.images );
  4743. if ( geometries.length > 0 ) output.geometries = geometries;
  4744. if ( materials.length > 0 ) output.materials = materials;
  4745. if ( textures.length > 0 ) output.textures = textures;
  4746. if ( images.length > 0 ) output.images = images;
  4747. }
  4748. output.object = data;
  4749. return output;
  4750. // extract data from the cache hash
  4751. // remove metadata on each item
  4752. // and return as array
  4753. function extractFromCache ( cache ) {
  4754. var values = [];
  4755. for ( var key in cache ) {
  4756. var data = cache[ key ];
  4757. delete data.metadata;
  4758. values.push( data );
  4759. }
  4760. return values;
  4761. }
  4762. },
  4763. clone: function ( object, recursive ) {
  4764. if ( object === undefined ) object = new THREE.Object3D();
  4765. if ( recursive === undefined ) recursive = true;
  4766. object.name = this.name;
  4767. object.up.copy( this.up );
  4768. object.position.copy( this.position );
  4769. object.quaternion.copy( this.quaternion );
  4770. object.scale.copy( this.scale );
  4771. object.rotationAutoUpdate = this.rotationAutoUpdate;
  4772. object.matrix.copy( this.matrix );
  4773. object.matrixWorld.copy( this.matrixWorld );
  4774. object.matrixAutoUpdate = this.matrixAutoUpdate;
  4775. object.matrixWorldNeedsUpdate = this.matrixWorldNeedsUpdate;
  4776. object.visible = this.visible;
  4777. object.castShadow = this.castShadow;
  4778. object.receiveShadow = this.receiveShadow;
  4779. object.frustumCulled = this.frustumCulled;
  4780. object.renderOrder = this.renderOrder;
  4781. object.userData = JSON.parse( JSON.stringify( this.userData ) );
  4782. if ( recursive === true ) {
  4783. for ( var i = 0; i < this.children.length; i ++ ) {
  4784. var child = this.children[ i ];
  4785. object.add( child.clone() );
  4786. }
  4787. }
  4788. return object;
  4789. }
  4790. };
  4791. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  4792. THREE.Object3DIdCount = 0;
  4793. // File:src/core/Face3.js
  4794. /**
  4795. * @author mrdoob / http://mrdoob.com/
  4796. * @author alteredq / http://alteredqualia.com/
  4797. */
  4798. THREE.Face3 = function ( a, b, c, normal, color ) {
  4799. this.a = a;
  4800. this.b = b;
  4801. this.c = c;
  4802. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  4803. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4804. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  4805. this.vertexColors = Array.isArray( color ) ? color : [];
  4806. this.vertexTangents = [];
  4807. };
  4808. THREE.Face3.prototype = {
  4809. constructor: THREE.Face3,
  4810. clone: function () {
  4811. var face = new THREE.Face3( this.a, this.b, this.c );
  4812. face.normal.copy( this.normal );
  4813. face.color.copy( this.color );
  4814. for ( var i = 0, il = this.vertexNormals.length; i < il; i ++ ) {
  4815. face.vertexNormals[ i ] = this.vertexNormals[ i ].clone();
  4816. }
  4817. for ( var i = 0, il = this.vertexColors.length; i < il; i ++ ) {
  4818. face.vertexColors[ i ] = this.vertexColors[ i ].clone();
  4819. }
  4820. for ( var i = 0, il = this.vertexTangents.length; i < il; i ++ ) {
  4821. face.vertexTangents[ i ] = this.vertexTangents[ i ].clone();
  4822. }
  4823. return face;
  4824. }
  4825. };
  4826. // File:src/core/Face4.js
  4827. /**
  4828. * @author mrdoob / http://mrdoob.com/
  4829. */
  4830. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  4831. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  4832. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  4833. };
  4834. // File:src/core/BufferAttribute.js
  4835. /**
  4836. * @author mrdoob / http://mrdoob.com/
  4837. */
  4838. THREE.BufferAttribute = function ( array, itemSize ) {
  4839. this.array = array;
  4840. this.itemSize = itemSize;
  4841. this.needsUpdate = false;
  4842. };
  4843. THREE.BufferAttribute.prototype = {
  4844. constructor: THREE.BufferAttribute,
  4845. get length () {
  4846. console.warn( 'THREE.BufferAttribute: .length has been renamed to .count.' );
  4847. return this.count;
  4848. },
  4849. get count() {
  4850. return this.array.length / this.itemSize;
  4851. },
  4852. copyAt: function ( index1, attribute, index2 ) {
  4853. index1 *= this.itemSize;
  4854. index2 *= attribute.itemSize;
  4855. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  4856. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  4857. }
  4858. return this;
  4859. },
  4860. copyArray: function ( array ) {
  4861. this.array.set( array );
  4862. return this;
  4863. },
  4864. copyColorsArray: function ( colors ) {
  4865. var array = this.array, offset = 0;
  4866. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  4867. var color = colors[ i ];
  4868. if ( color === undefined ) {
  4869. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  4870. color = new THREE.Color();
  4871. }
  4872. array[ offset ++ ] = color.r;
  4873. array[ offset ++ ] = color.g;
  4874. array[ offset ++ ] = color.b;
  4875. }
  4876. return this;
  4877. },
  4878. copyFacesArray: function ( faces ) {
  4879. var array = this.array, offset = 0;
  4880. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  4881. var face = faces[ i ];
  4882. array[ offset ++ ] = face.a;
  4883. array[ offset ++ ] = face.b;
  4884. array[ offset ++ ] = face.c;
  4885. }
  4886. return this;
  4887. },
  4888. copyVector2sArray: function ( vectors ) {
  4889. var array = this.array, offset = 0;
  4890. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  4891. var vector = vectors[ i ];
  4892. if ( vector === undefined ) {
  4893. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  4894. vector = new THREE.Vector2();
  4895. }
  4896. array[ offset ++ ] = vector.x;
  4897. array[ offset ++ ] = vector.y;
  4898. }
  4899. return this;
  4900. },
  4901. copyVector3sArray: function ( vectors ) {
  4902. var array = this.array, offset = 0;
  4903. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  4904. var vector = vectors[ i ];
  4905. if ( vector === undefined ) {
  4906. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  4907. vector = new THREE.Vector3();
  4908. }
  4909. array[ offset ++ ] = vector.x;
  4910. array[ offset ++ ] = vector.y;
  4911. array[ offset ++ ] = vector.z;
  4912. }
  4913. return this;
  4914. },
  4915. copyVector4sArray: function ( vectors ) {
  4916. var array = this.array, offset = 0;
  4917. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  4918. var vector = vectors[ i ];
  4919. if ( vector === undefined ) {
  4920. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  4921. vector = new THREE.Vector4();
  4922. }
  4923. array[ offset ++ ] = vector.x;
  4924. array[ offset ++ ] = vector.y;
  4925. array[ offset ++ ] = vector.z;
  4926. array[ offset ++ ] = vector.w;
  4927. }
  4928. return this;
  4929. },
  4930. set: function ( value, offset ) {
  4931. if ( offset === undefined ) offset = 0;
  4932. this.array.set( value, offset );
  4933. return this;
  4934. },
  4935. getX: function ( index ) {
  4936. return this.array[ index * this.itemSize ];
  4937. },
  4938. setX: function ( index, x ) {
  4939. this.array[ index * this.itemSize ] = x;
  4940. return this;
  4941. },
  4942. getY: function ( index ) {
  4943. return this.array[ index * this.itemSize + 1 ];
  4944. },
  4945. setY: function ( index, y ) {
  4946. this.array[ index * this.itemSize + 1 ] = y;
  4947. return this;
  4948. },
  4949. getZ: function ( index ) {
  4950. return this.array[ index * this.itemSize + 2 ];
  4951. },
  4952. setZ: function ( index, z ) {
  4953. this.array[ index * this.itemSize + 2 ] = z;
  4954. return this;
  4955. },
  4956. getW: function ( index ) {
  4957. return this.array[ index * this.itemSize + 3 ];
  4958. },
  4959. setW: function ( index, w ) {
  4960. this.array[ index * this.itemSize + 3 ] = w;
  4961. return this;
  4962. },
  4963. setXY: function ( index, x, y ) {
  4964. index *= this.itemSize;
  4965. this.array[ index + 0 ] = x;
  4966. this.array[ index + 1 ] = y;
  4967. return this;
  4968. },
  4969. setXYZ: function ( index, x, y, z ) {
  4970. index *= this.itemSize;
  4971. this.array[ index + 0 ] = x;
  4972. this.array[ index + 1 ] = y;
  4973. this.array[ index + 2 ] = z;
  4974. return this;
  4975. },
  4976. setXYZW: function ( index, x, y, z, w ) {
  4977. index *= this.itemSize;
  4978. this.array[ index + 0 ] = x;
  4979. this.array[ index + 1 ] = y;
  4980. this.array[ index + 2 ] = z;
  4981. this.array[ index + 3 ] = w;
  4982. return this;
  4983. },
  4984. clone: function () {
  4985. return new THREE.BufferAttribute( new this.array.constructor( this.array ), this.itemSize );
  4986. }
  4987. };
  4988. //
  4989. THREE.Int8Attribute = function ( array, itemSize ) {
  4990. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  4991. };
  4992. THREE.Uint8Attribute = function ( array, itemSize ) {
  4993. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  4994. };
  4995. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  4996. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  4997. };
  4998. THREE.Int16Attribute = function ( array, itemSize ) {
  4999. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5000. };
  5001. THREE.Uint16Attribute = function ( array, itemSize ) {
  5002. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5003. };
  5004. THREE.Int32Attribute = function ( array, itemSize ) {
  5005. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5006. };
  5007. THREE.Uint32Attribute = function ( array, itemSize ) {
  5008. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5009. };
  5010. THREE.Float32Attribute = function ( array, itemSize ) {
  5011. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5012. };
  5013. THREE.Float64Attribute = function ( array, itemSize ) {
  5014. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5015. };
  5016. // File:src/core/DynamicBufferAttribute.js
  5017. /**
  5018. * @author benaadams / https://twitter.com/ben_a_adams
  5019. * @author mrdoob / http://mrdoob.com/
  5020. */
  5021. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5022. THREE.BufferAttribute.call( this, array, itemSize );
  5023. this.updateRange = { offset: 0, count: -1 };
  5024. };
  5025. THREE.DynamicBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5026. THREE.DynamicBufferAttribute.prototype.constructor = THREE.DynamicBufferAttribute;
  5027. THREE.DynamicBufferAttribute.prototype.clone = function () {
  5028. return new THREE.DynamicBufferAttribute( new this.array.constructor( this.array ), this.itemSize );
  5029. };
  5030. // File:src/core/InstancedBufferAttribute.js
  5031. /**
  5032. * @author benaadams / https://twitter.com/ben_a_adams
  5033. */
  5034. THREE.InstancedBufferAttribute = function (array, itemSize, meshPerAttribute, dynamic) {
  5035. THREE.DynamicBufferAttribute.call( this, array, itemSize );
  5036. this.dynamic = dynamic || false;
  5037. this.meshPerAttribute = meshPerAttribute || 1;
  5038. };
  5039. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.DynamicBufferAttribute.prototype );
  5040. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5041. THREE.InstancedBufferAttribute.prototype.clone = function () {
  5042. return new THREE.InstancedBufferAttribute( new this.array.constructor( this.array ), this.itemSize, this.meshPerAttribute, this.dynamic );
  5043. };
  5044. // File:src/core/InterleavedBuffer.js
  5045. /**
  5046. * @author benaadams / https://twitter.com/ben_a_adams
  5047. */
  5048. THREE.InterleavedBuffer = function ( array, stride, dynamic ) {
  5049. this.array = array;
  5050. this.stride = stride;
  5051. this.needsUpdate = false;
  5052. this.dynamic = dynamic || false;
  5053. this.updateRange = { offset: 0, count: -1 };
  5054. };
  5055. THREE.InterleavedBuffer.prototype = {
  5056. constructor: THREE.InterleavedBuffer,
  5057. get length () {
  5058. return this.array.length;
  5059. },
  5060. copyAt: function ( index1, attribute, index2 ) {
  5061. index1 *= this.stride;
  5062. index2 *= attribute.stride;
  5063. for ( var i = 0, l = this.stride; i < l; i++ ) {
  5064. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5065. }
  5066. return this;
  5067. },
  5068. set: function ( value, offset ) {
  5069. if ( offset === undefined ) offset = 0;
  5070. this.array.set( value, offset );
  5071. return this;
  5072. },
  5073. clone: function () {
  5074. return new THREE.InterleavedBuffer( new this.array.constructor( this.array ), this.stride, this.dynamic );
  5075. }
  5076. };
  5077. // File:src/core/InstancedInterleavedBuffer.js
  5078. /**
  5079. * @author benaadams / https://twitter.com/ben_a_adams
  5080. */
  5081. THREE.InstancedInterleavedBuffer = function ( array, stride, dynamic, meshPerAttribute ) {
  5082. THREE.InterleavedBuffer.call( this, array, stride, dynamic );
  5083. this.meshPerAttribute = meshPerAttribute || 1;
  5084. };
  5085. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5086. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5087. THREE.InstancedInterleavedBuffer.prototype.clone = function () {
  5088. return new THREE.InstancedInterleavedBuffer( new this.array.constructor( this.array ), this.stride, this.dynamic, this.meshPerAttribute );
  5089. };
  5090. // File:src/core/InterleavedBufferAttribute.js
  5091. /**
  5092. * @author benaadams / https://twitter.com/ben_a_adams
  5093. */
  5094. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5095. this.data = interleavedBuffer;
  5096. this.itemSize = itemSize;
  5097. this.offset = offset;
  5098. };
  5099. THREE.InterleavedBufferAttribute.prototype = {
  5100. constructor: THREE.InterleavedBufferAttribute,
  5101. get length() {
  5102. console.warn( 'THREE.InterleavedBufferAttribute: .length has been renamed to .count.' );
  5103. return this.count;
  5104. },
  5105. get count() {
  5106. return this.data.array.length / this.data.stride;
  5107. },
  5108. setX: function ( index, x ) {
  5109. this.data.array[ index * this.data.stride + this.offset ] = x;
  5110. return this;
  5111. },
  5112. setY: function ( index, y ) {
  5113. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5114. return this;
  5115. },
  5116. setZ: function ( index, z ) {
  5117. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5118. return this;
  5119. },
  5120. setW: function ( index, w ) {
  5121. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5122. return this;
  5123. },
  5124. getX: function ( index ) {
  5125. return this.data.array[ index * this.data.stride + this.offset ];
  5126. },
  5127. getY: function ( index ) {
  5128. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5129. },
  5130. getZ: function ( index ) {
  5131. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5132. },
  5133. getW: function ( index ) {
  5134. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5135. },
  5136. setXY: function ( index, x, y ) {
  5137. index = index * this.data.stride + this.offset;
  5138. this.data.array[ index + 0 ] = x;
  5139. this.data.array[ index + 1 ] = y;
  5140. return this;
  5141. },
  5142. setXYZ: function ( index, x, y, z ) {
  5143. index = index * this.data.stride + this.offset;
  5144. this.data.array[ index + 0 ] = x;
  5145. this.data.array[ index + 1 ] = y;
  5146. this.data.array[ index + 2 ] = z;
  5147. return this;
  5148. },
  5149. setXYZW: function ( index, x, y, z, w ) {
  5150. index = index * this.data.stride + this.offset;
  5151. this.data.array[ index + 0 ] = x;
  5152. this.data.array[ index + 1 ] = y;
  5153. this.data.array[ index + 2 ] = z;
  5154. this.data.array[ index + 3 ] = w;
  5155. return this;
  5156. }
  5157. };
  5158. // File:src/core/Geometry.js
  5159. /**
  5160. * @author mrdoob / http://mrdoob.com/
  5161. * @author kile / http://kile.stravaganza.org/
  5162. * @author alteredq / http://alteredqualia.com/
  5163. * @author mikael emtinger / http://gomo.se/
  5164. * @author zz85 / http://www.lab4games.net/zz85/blog
  5165. * @author bhouston / http://exocortex.com
  5166. */
  5167. THREE.Geometry = function () {
  5168. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5169. this.uuid = THREE.Math.generateUUID();
  5170. this.name = '';
  5171. this.type = 'Geometry';
  5172. this.vertices = [];
  5173. this.colors = [];
  5174. this.faces = [];
  5175. this.faceVertexUvs = [ [] ];
  5176. this.morphTargets = [];
  5177. this.morphColors = [];
  5178. this.morphNormals = [];
  5179. this.skinWeights = [];
  5180. this.skinIndices = [];
  5181. this.lineDistances = [];
  5182. this.boundingBox = null;
  5183. this.boundingSphere = null;
  5184. this.hasTangents = false;
  5185. // update flags
  5186. this.verticesNeedUpdate = false;
  5187. this.elementsNeedUpdate = false;
  5188. this.uvsNeedUpdate = false;
  5189. this.normalsNeedUpdate = false;
  5190. this.tangentsNeedUpdate = false;
  5191. this.colorsNeedUpdate = false;
  5192. this.lineDistancesNeedUpdate = false;
  5193. this.groupsNeedUpdate = false;
  5194. };
  5195. THREE.Geometry.prototype = {
  5196. constructor: THREE.Geometry,
  5197. applyMatrix: function ( matrix ) {
  5198. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5199. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5200. var vertex = this.vertices[ i ];
  5201. vertex.applyMatrix4( matrix );
  5202. }
  5203. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5204. var face = this.faces[ i ];
  5205. face.normal.applyMatrix3( normalMatrix ).normalize();
  5206. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5207. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5208. }
  5209. }
  5210. if ( this.boundingBox !== null ) {
  5211. this.computeBoundingBox();
  5212. }
  5213. if ( this.boundingSphere !== null ) {
  5214. this.computeBoundingSphere();
  5215. }
  5216. this.verticesNeedUpdate = true;
  5217. this.normalsNeedUpdate = true;
  5218. },
  5219. fromBufferGeometry: function ( geometry ) {
  5220. var scope = this;
  5221. var attributes = geometry.attributes;
  5222. var vertices = attributes.position.array;
  5223. var indices = attributes.index !== undefined ? attributes.index.array : undefined;
  5224. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5225. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5226. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5227. var tempNormals = [];
  5228. var tempUVs = [];
  5229. for ( var i = 0, j = 0; i < vertices.length; i += 3, j += 2 ) {
  5230. scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  5231. if ( normals !== undefined ) {
  5232. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5233. }
  5234. if ( colors !== undefined ) {
  5235. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5236. }
  5237. if ( uvs !== undefined ) {
  5238. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5239. }
  5240. }
  5241. var addFace = function ( a, b, c ) {
  5242. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5243. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5244. scope.faces.push( new THREE.Face3( a, b, c, vertexNormals, vertexColors ) );
  5245. if ( uvs !== undefined ) {
  5246. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5247. }
  5248. };
  5249. if ( indices !== undefined ) {
  5250. var drawcalls = geometry.drawcalls;
  5251. if ( drawcalls.length > 0 ) {
  5252. for ( var i = 0; i < drawcalls.length; i ++ ) {
  5253. var drawcall = drawcalls[ i ];
  5254. var start = drawcall.start;
  5255. var count = drawcall.count;
  5256. var index = drawcall.index;
  5257. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5258. addFace( index + indices[ j ], index + indices[ j + 1 ], index + indices[ j + 2 ] );
  5259. }
  5260. }
  5261. } else {
  5262. for ( var i = 0; i < indices.length; i += 3 ) {
  5263. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5264. }
  5265. }
  5266. } else {
  5267. for ( var i = 0; i < vertices.length / 3; i += 3 ) {
  5268. addFace( i, i + 1, i + 2 );
  5269. }
  5270. }
  5271. this.computeFaceNormals();
  5272. if ( geometry.boundingBox !== null ) {
  5273. this.boundingBox = geometry.boundingBox.clone();
  5274. }
  5275. if ( geometry.boundingSphere !== null ) {
  5276. this.boundingSphere = geometry.boundingSphere.clone();
  5277. }
  5278. return this;
  5279. },
  5280. center: function () {
  5281. this.computeBoundingBox();
  5282. var offset = this.boundingBox.center().negate();
  5283. this.applyMatrix( new THREE.Matrix4().setPosition( offset ) );
  5284. return offset;
  5285. },
  5286. normalize: function () {
  5287. this.computeBoundingSphere();
  5288. var center = this.boundingSphere.center;
  5289. var radius = this.boundingSphere.radius;
  5290. var s = radius === 0 ? 1 : 1.0 / radius;
  5291. var matrix = new THREE.Matrix4();
  5292. matrix.set(
  5293. s, 0, 0, -s * center.x,
  5294. 0, s, 0, -s * center.y,
  5295. 0, 0, s, -s * center.z,
  5296. 0, 0, 0, 1
  5297. );
  5298. this.applyMatrix( matrix );
  5299. return this;
  5300. },
  5301. computeFaceNormals: function () {
  5302. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5303. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5304. var face = this.faces[ f ];
  5305. var vA = this.vertices[ face.a ];
  5306. var vB = this.vertices[ face.b ];
  5307. var vC = this.vertices[ face.c ];
  5308. cb.subVectors( vC, vB );
  5309. ab.subVectors( vA, vB );
  5310. cb.cross( ab );
  5311. cb.normalize();
  5312. face.normal.copy( cb );
  5313. }
  5314. },
  5315. computeVertexNormals: function ( areaWeighted ) {
  5316. var v, vl, f, fl, face, vertices;
  5317. vertices = new Array( this.vertices.length );
  5318. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5319. vertices[ v ] = new THREE.Vector3();
  5320. }
  5321. if ( areaWeighted ) {
  5322. // vertex normals weighted by triangle areas
  5323. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5324. var vA, vB, vC;
  5325. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5326. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5327. face = this.faces[ f ];
  5328. vA = this.vertices[ face.a ];
  5329. vB = this.vertices[ face.b ];
  5330. vC = this.vertices[ face.c ];
  5331. cb.subVectors( vC, vB );
  5332. ab.subVectors( vA, vB );
  5333. cb.cross( ab );
  5334. vertices[ face.a ].add( cb );
  5335. vertices[ face.b ].add( cb );
  5336. vertices[ face.c ].add( cb );
  5337. }
  5338. } else {
  5339. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5340. face = this.faces[ f ];
  5341. vertices[ face.a ].add( face.normal );
  5342. vertices[ face.b ].add( face.normal );
  5343. vertices[ face.c ].add( face.normal );
  5344. }
  5345. }
  5346. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5347. vertices[ v ].normalize();
  5348. }
  5349. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5350. face = this.faces[ f ];
  5351. face.vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5352. face.vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5353. face.vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5354. }
  5355. },
  5356. computeMorphNormals: function () {
  5357. var i, il, f, fl, face;
  5358. // save original normals
  5359. // - create temp variables on first access
  5360. // otherwise just copy (for faster repeated calls)
  5361. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5362. face = this.faces[ f ];
  5363. if ( ! face.__originalFaceNormal ) {
  5364. face.__originalFaceNormal = face.normal.clone();
  5365. } else {
  5366. face.__originalFaceNormal.copy( face.normal );
  5367. }
  5368. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5369. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5370. if ( ! face.__originalVertexNormals[ i ] ) {
  5371. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5372. } else {
  5373. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5374. }
  5375. }
  5376. }
  5377. // use temp geometry to compute face and vertex normals for each morph
  5378. var tmpGeo = new THREE.Geometry();
  5379. tmpGeo.faces = this.faces;
  5380. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5381. // create on first access
  5382. if ( ! this.morphNormals[ i ] ) {
  5383. this.morphNormals[ i ] = {};
  5384. this.morphNormals[ i ].faceNormals = [];
  5385. this.morphNormals[ i ].vertexNormals = [];
  5386. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5387. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5388. var faceNormal, vertexNormals;
  5389. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5390. faceNormal = new THREE.Vector3();
  5391. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5392. dstNormalsFace.push( faceNormal );
  5393. dstNormalsVertex.push( vertexNormals );
  5394. }
  5395. }
  5396. var morphNormals = this.morphNormals[ i ];
  5397. // set vertices to morph target
  5398. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5399. // compute morph normals
  5400. tmpGeo.computeFaceNormals();
  5401. tmpGeo.computeVertexNormals();
  5402. // store morph normals
  5403. var faceNormal, vertexNormals;
  5404. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5405. face = this.faces[ f ];
  5406. faceNormal = morphNormals.faceNormals[ f ];
  5407. vertexNormals = morphNormals.vertexNormals[ f ];
  5408. faceNormal.copy( face.normal );
  5409. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5410. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5411. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5412. }
  5413. }
  5414. // restore original normals
  5415. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5416. face = this.faces[ f ];
  5417. face.normal = face.__originalFaceNormal;
  5418. face.vertexNormals = face.__originalVertexNormals;
  5419. }
  5420. },
  5421. computeTangents: function () {
  5422. // based on http://www.terathon.com/code/tangent.html
  5423. // tangents go to vertices
  5424. var f, fl, v, vl, i, vertexIndex,
  5425. face, uv, vA, vB, vC, uvA, uvB, uvC,
  5426. x1, x2, y1, y2, z1, z2,
  5427. s1, s2, t1, t2, r, t, test,
  5428. tan1 = [], tan2 = [],
  5429. sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
  5430. tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(),
  5431. n = new THREE.Vector3(), w;
  5432. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5433. tan1[ v ] = new THREE.Vector3();
  5434. tan2[ v ] = new THREE.Vector3();
  5435. }
  5436. function handleTriangle( context, a, b, c, ua, ub, uc ) {
  5437. vA = context.vertices[ a ];
  5438. vB = context.vertices[ b ];
  5439. vC = context.vertices[ c ];
  5440. uvA = uv[ ua ];
  5441. uvB = uv[ ub ];
  5442. uvC = uv[ uc ];
  5443. x1 = vB.x - vA.x;
  5444. x2 = vC.x - vA.x;
  5445. y1 = vB.y - vA.y;
  5446. y2 = vC.y - vA.y;
  5447. z1 = vB.z - vA.z;
  5448. z2 = vC.z - vA.z;
  5449. s1 = uvB.x - uvA.x;
  5450. s2 = uvC.x - uvA.x;
  5451. t1 = uvB.y - uvA.y;
  5452. t2 = uvC.y - uvA.y;
  5453. r = 1.0 / ( s1 * t2 - s2 * t1 );
  5454. sdir.set( ( t2 * x1 - t1 * x2 ) * r,
  5455. ( t2 * y1 - t1 * y2 ) * r,
  5456. ( t2 * z1 - t1 * z2 ) * r );
  5457. tdir.set( ( s1 * x2 - s2 * x1 ) * r,
  5458. ( s1 * y2 - s2 * y1 ) * r,
  5459. ( s1 * z2 - s2 * z1 ) * r );
  5460. tan1[ a ].add( sdir );
  5461. tan1[ b ].add( sdir );
  5462. tan1[ c ].add( sdir );
  5463. tan2[ a ].add( tdir );
  5464. tan2[ b ].add( tdir );
  5465. tan2[ c ].add( tdir );
  5466. }
  5467. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5468. face = this.faces[ f ];
  5469. uv = this.faceVertexUvs[ 0 ][ f ]; // use UV layer 0 for tangents
  5470. handleTriangle( this, face.a, face.b, face.c, 0, 1, 2 );
  5471. }
  5472. var faceIndex = [ 'a', 'b', 'c', 'd' ];
  5473. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5474. face = this.faces[ f ];
  5475. for ( i = 0; i < Math.min( face.vertexNormals.length, 3 ); i ++ ) {
  5476. n.copy( face.vertexNormals[ i ] );
  5477. vertexIndex = face[ faceIndex[ i ] ];
  5478. t = tan1[ vertexIndex ];
  5479. // Gram-Schmidt orthogonalize
  5480. tmp.copy( t );
  5481. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  5482. // Calculate handedness
  5483. tmp2.crossVectors( face.vertexNormals[ i ], t );
  5484. test = tmp2.dot( tan2[ vertexIndex ] );
  5485. w = ( test < 0.0 ) ? - 1.0 : 1.0;
  5486. face.vertexTangents[ i ] = new THREE.Vector4( tmp.x, tmp.y, tmp.z, w );
  5487. }
  5488. }
  5489. this.hasTangents = true;
  5490. },
  5491. computeLineDistances: function () {
  5492. var d = 0;
  5493. var vertices = this.vertices;
  5494. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5495. if ( i > 0 ) {
  5496. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  5497. }
  5498. this.lineDistances[ i ] = d;
  5499. }
  5500. },
  5501. computeBoundingBox: function () {
  5502. if ( this.boundingBox === null ) {
  5503. this.boundingBox = new THREE.Box3();
  5504. }
  5505. this.boundingBox.setFromPoints( this.vertices );
  5506. },
  5507. computeBoundingSphere: function () {
  5508. if ( this.boundingSphere === null ) {
  5509. this.boundingSphere = new THREE.Sphere();
  5510. }
  5511. this.boundingSphere.setFromPoints( this.vertices );
  5512. },
  5513. merge: function ( geometry, matrix ) {
  5514. if ( geometry instanceof THREE.Geometry === false ) {
  5515. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5516. return;
  5517. }
  5518. var normalMatrix,
  5519. vertexOffset = this.vertices.length,
  5520. vertices1 = this.vertices,
  5521. vertices2 = geometry.vertices,
  5522. faces1 = this.faces,
  5523. faces2 = geometry.faces,
  5524. uvs1 = this.faceVertexUvs[ 0 ],
  5525. uvs2 = geometry.faceVertexUvs[ 0 ];
  5526. if ( matrix !== undefined ) {
  5527. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5528. }
  5529. // vertices
  5530. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5531. var vertex = vertices2[ i ];
  5532. var vertexCopy = vertex.clone();
  5533. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5534. vertices1.push( vertexCopy );
  5535. }
  5536. // faces
  5537. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5538. var face = faces2[ i ], faceCopy, normal, color,
  5539. faceVertexNormals = face.vertexNormals,
  5540. faceVertexColors = face.vertexColors;
  5541. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5542. faceCopy.normal.copy( face.normal );
  5543. if ( normalMatrix !== undefined ) {
  5544. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5545. }
  5546. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5547. normal = faceVertexNormals[ j ].clone();
  5548. if ( normalMatrix !== undefined ) {
  5549. normal.applyMatrix3( normalMatrix ).normalize();
  5550. }
  5551. faceCopy.vertexNormals.push( normal );
  5552. }
  5553. faceCopy.color.copy( face.color );
  5554. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5555. color = faceVertexColors[ j ];
  5556. faceCopy.vertexColors.push( color.clone() );
  5557. }
  5558. faces1.push( faceCopy );
  5559. }
  5560. // uvs
  5561. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5562. var uv = uvs2[ i ], uvCopy = [];
  5563. if ( uv === undefined ) {
  5564. continue;
  5565. }
  5566. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5567. uvCopy.push( uv[ j ].clone() );
  5568. }
  5569. uvs1.push( uvCopy );
  5570. }
  5571. },
  5572. mergeMesh: function ( mesh ) {
  5573. if ( mesh instanceof THREE.Mesh === false ) {
  5574. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5575. return;
  5576. }
  5577. mesh.matrixAutoUpdate && mesh.updateMatrix();
  5578. this.merge( mesh.geometry, mesh.matrix );
  5579. },
  5580. /*
  5581. * Checks for duplicate vertices with hashmap.
  5582. * Duplicated vertices are removed
  5583. * and faces' vertices are updated.
  5584. */
  5585. mergeVertices: function () {
  5586. var verticesMap = {}; // Hashmap for looking up vertice by position coordinates (and making sure they are unique)
  5587. var unique = [], changes = [];
  5588. var v, key;
  5589. var precisionPoints = 4; // number of decimal points, eg. 4 for epsilon of 0.0001
  5590. var precision = Math.pow( 10, precisionPoints );
  5591. var i, il, face;
  5592. var indices, j, jl;
  5593. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5594. v = this.vertices[ i ];
  5595. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5596. if ( verticesMap[ key ] === undefined ) {
  5597. verticesMap[ key ] = i;
  5598. unique.push( this.vertices[ i ] );
  5599. changes[ i ] = unique.length - 1;
  5600. } else {
  5601. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5602. changes[ i ] = changes[ verticesMap[ key ] ];
  5603. }
  5604. }
  5605. // if faces are completely degenerate after merging vertices, we
  5606. // have to remove them from the geometry.
  5607. var faceIndicesToRemove = [];
  5608. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5609. face = this.faces[ i ];
  5610. face.a = changes[ face.a ];
  5611. face.b = changes[ face.b ];
  5612. face.c = changes[ face.c ];
  5613. indices = [ face.a, face.b, face.c ];
  5614. var dupIndex = - 1;
  5615. // if any duplicate vertices are found in a Face3
  5616. // we have to remove the face as nothing can be saved
  5617. for ( var n = 0; n < 3; n ++ ) {
  5618. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5619. dupIndex = n;
  5620. faceIndicesToRemove.push( i );
  5621. break;
  5622. }
  5623. }
  5624. }
  5625. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5626. var idx = faceIndicesToRemove[ i ];
  5627. this.faces.splice( idx, 1 );
  5628. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5629. this.faceVertexUvs[ j ].splice( idx, 1 );
  5630. }
  5631. }
  5632. // Use unique set of vertices
  5633. var diff = this.vertices.length - unique.length;
  5634. this.vertices = unique;
  5635. return diff;
  5636. },
  5637. toJSON: function () {
  5638. var data = {
  5639. metadata: {
  5640. version: 4.4,
  5641. type: 'Geometry',
  5642. generator: 'Geometry.toJSON'
  5643. }
  5644. };
  5645. // standard Geometry serialization
  5646. data.uuid = this.uuid;
  5647. data.type = this.type;
  5648. if ( this.name !== '' ) data.name = this.name;
  5649. if ( this.parameters !== undefined ) {
  5650. var parameters = this.parameters;
  5651. for ( var key in parameters ) {
  5652. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5653. }
  5654. return data;
  5655. }
  5656. var vertices = [];
  5657. for ( var i = 0; i < this.vertices.length; i ++ ) {
  5658. var vertex = this.vertices[ i ];
  5659. vertices.push( vertex.x, vertex.y, vertex.z );
  5660. }
  5661. var faces = [];
  5662. var normals = [];
  5663. var normalsHash = {};
  5664. var colors = [];
  5665. var colorsHash = {};
  5666. var uvs = [];
  5667. var uvsHash = {};
  5668. for ( var i = 0; i < this.faces.length; i ++ ) {
  5669. var face = this.faces[ i ];
  5670. var hasMaterial = false; // face.materialIndex !== undefined;
  5671. var hasFaceUv = false; // deprecated
  5672. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  5673. var hasFaceNormal = face.normal.length() > 0;
  5674. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  5675. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  5676. var hasFaceVertexColor = face.vertexColors.length > 0;
  5677. var faceType = 0;
  5678. faceType = setBit( faceType, 0, 0 );
  5679. faceType = setBit( faceType, 1, hasMaterial );
  5680. faceType = setBit( faceType, 2, hasFaceUv );
  5681. faceType = setBit( faceType, 3, hasFaceVertexUv );
  5682. faceType = setBit( faceType, 4, hasFaceNormal );
  5683. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  5684. faceType = setBit( faceType, 6, hasFaceColor );
  5685. faceType = setBit( faceType, 7, hasFaceVertexColor );
  5686. faces.push( faceType );
  5687. faces.push( face.a, face.b, face.c );
  5688. if ( hasFaceVertexUv ) {
  5689. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  5690. faces.push(
  5691. getUvIndex( faceVertexUvs[ 0 ] ),
  5692. getUvIndex( faceVertexUvs[ 1 ] ),
  5693. getUvIndex( faceVertexUvs[ 2 ] )
  5694. );
  5695. }
  5696. if ( hasFaceNormal ) {
  5697. faces.push( getNormalIndex( face.normal ) );
  5698. }
  5699. if ( hasFaceVertexNormal ) {
  5700. var vertexNormals = face.vertexNormals;
  5701. faces.push(
  5702. getNormalIndex( vertexNormals[ 0 ] ),
  5703. getNormalIndex( vertexNormals[ 1 ] ),
  5704. getNormalIndex( vertexNormals[ 2 ] )
  5705. );
  5706. }
  5707. if ( hasFaceColor ) {
  5708. faces.push( getColorIndex( face.color ) );
  5709. }
  5710. if ( hasFaceVertexColor ) {
  5711. var vertexColors = face.vertexColors;
  5712. faces.push(
  5713. getColorIndex( vertexColors[ 0 ] ),
  5714. getColorIndex( vertexColors[ 1 ] ),
  5715. getColorIndex( vertexColors[ 2 ] )
  5716. );
  5717. }
  5718. }
  5719. function setBit( value, position, enabled ) {
  5720. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position) );
  5721. }
  5722. function getNormalIndex( normal ) {
  5723. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  5724. if ( normalsHash[ hash ] !== undefined ) {
  5725. return normalsHash[ hash ];
  5726. }
  5727. normalsHash[ hash ] = normals.length / 3;
  5728. normals.push( normal.x, normal.y, normal.z );
  5729. return normalsHash[ hash ];
  5730. }
  5731. function getColorIndex( color ) {
  5732. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  5733. if ( colorsHash[ hash ] !== undefined ) {
  5734. return colorsHash[ hash ];
  5735. }
  5736. colorsHash[ hash ] = colors.length;
  5737. colors.push( color.getHex() );
  5738. return colorsHash[ hash ];
  5739. }
  5740. function getUvIndex( uv ) {
  5741. var hash = uv.x.toString() + uv.y.toString();
  5742. if ( uvsHash[ hash ] !== undefined ) {
  5743. return uvsHash[ hash ];
  5744. }
  5745. uvsHash[ hash ] = uvs.length / 2;
  5746. uvs.push( uv.x, uv.y );
  5747. return uvsHash[ hash ];
  5748. }
  5749. data.data = {};
  5750. data.data.vertices = vertices;
  5751. data.data.normals = normals;
  5752. if ( colors.length > 0 ) data.data.colors = colors;
  5753. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  5754. data.data.faces = faces;
  5755. return data;
  5756. },
  5757. clone: function () {
  5758. var geometry = new THREE.Geometry();
  5759. var vertices = this.vertices;
  5760. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5761. geometry.vertices.push( vertices[ i ].clone() );
  5762. }
  5763. var faces = this.faces;
  5764. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  5765. geometry.faces.push( faces[ i ].clone() );
  5766. }
  5767. for ( var i = 0, il = this.faceVertexUvs.length; i < il; i ++ ) {
  5768. var faceVertexUvs = this.faceVertexUvs[ i ];
  5769. if ( geometry.faceVertexUvs[ i ] === undefined ) {
  5770. geometry.faceVertexUvs[ i ] = [];
  5771. }
  5772. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  5773. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  5774. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  5775. var uv = uvs[ k ];
  5776. uvsCopy.push( uv.clone() );
  5777. }
  5778. geometry.faceVertexUvs[ i ].push( uvsCopy );
  5779. }
  5780. }
  5781. return geometry;
  5782. },
  5783. dispose: function () {
  5784. this.dispatchEvent( { type: 'dispose' } );
  5785. }
  5786. };
  5787. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  5788. THREE.GeometryIdCount = 0;
  5789. // File:src/core/DynamicGeometry.js
  5790. /**
  5791. * @author mrdoob / http://mrdoob.com/
  5792. */
  5793. THREE.DynamicGeometry = function () {
  5794. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5795. this.uuid = THREE.Math.generateUUID();
  5796. this.name = '';
  5797. this.type = 'DynamicGeometry';
  5798. this.vertices = [];
  5799. this.colors = [];
  5800. this.normals = [];
  5801. this.colors = [];
  5802. this.uvs = [];
  5803. this.faces = [];
  5804. // this.lineDistances = [];
  5805. this.boundingBox = null;
  5806. this.boundingSphere = null;
  5807. // update flags
  5808. this.verticesNeedUpdate = false;
  5809. this.normalsNeedUpdate = false;
  5810. this.colorsNeedUpdate = false;
  5811. this.uvsNeedUpdate = false;
  5812. };
  5813. THREE.DynamicGeometry.prototype = {
  5814. constructor: THREE.DynamicGeometry,
  5815. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  5816. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  5817. computeFaceNormals: function () {
  5818. console.warn( 'THREE.DynamicGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  5819. return this;
  5820. },
  5821. computeVertexNormals: function () {
  5822. console.warn( 'THREE.DynamicGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  5823. return this;
  5824. },
  5825. fromGeometry: function ( geometry ) {
  5826. this.vertices = geometry.vertices;
  5827. this.faces = geometry.faces;
  5828. var faces = geometry.faces;
  5829. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  5830. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  5831. var face = faces[ i ];
  5832. var indices = [ face.a, face.b, face.c ];
  5833. var vertexNormals = face.vertexNormals;
  5834. var vertexColors = face.vertexColors;
  5835. var vertexUvs = faceVertexUvs[ i ];
  5836. for ( var j = 0, jl = vertexNormals.length; j < jl; j ++ ) {
  5837. this.normals[ indices[ j ] ] = vertexNormals[ j ];
  5838. }
  5839. for ( var j = 0, jl = vertexColors.length; j < jl; j ++ ) {
  5840. this.colors[ indices[ j ] ] = vertexColors[ j ];
  5841. }
  5842. if ( vertexUvs === undefined ) {
  5843. console.warn( 'THREE.DynamicGeometry.fromGeometry(): Missing vertexUVs', i );
  5844. vertexUvs = [ new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() ];
  5845. }
  5846. for ( var j = 0, jl = vertexUvs.length; j < jl; j ++ ) {
  5847. this.uvs[ indices[ j ] ] = vertexUvs[ j ];
  5848. }
  5849. }
  5850. if ( geometry.morphTargets ) this.morphTargets = geometry.morphTargets.slice( 0 );
  5851. if ( geometry.morphColors ) this.morphColors = geometry.morphColors.slice( 0 );
  5852. if ( geometry.morphNormals ) this.morphNormals = geometry.morphNormals.slice( 0 );
  5853. if ( geometry.skinIndices ) this.skinIndices = geometry.skinIndices.slice( 0 );
  5854. if ( geometry.skinWeights ) this.skinWeights = geometry.skinWeights.slice( 0 );
  5855. return this;
  5856. },
  5857. dispose: function () {
  5858. this.dispatchEvent( { type: 'dispose' } );
  5859. }
  5860. };
  5861. THREE.EventDispatcher.prototype.apply( THREE.DynamicGeometry.prototype );
  5862. // File:src/core/BufferGeometry.js
  5863. /**
  5864. * @author alteredq / http://alteredqualia.com/
  5865. * @author mrdoob / http://mrdoob.com/
  5866. */
  5867. THREE.BufferGeometry = function () {
  5868. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5869. this.uuid = THREE.Math.generateUUID();
  5870. this.name = '';
  5871. this.type = 'BufferGeometry';
  5872. this.attributes = {};
  5873. this.morphAttributes = [];
  5874. this.drawcalls = [];
  5875. this.offsets = this.drawcalls; // backwards compatibility
  5876. this.boundingBox = null;
  5877. this.boundingSphere = null;
  5878. };
  5879. THREE.BufferGeometry.prototype = {
  5880. constructor: THREE.BufferGeometry,
  5881. addAttribute: function ( name, attribute ) {
  5882. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  5883. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  5884. this.attributes[ name ] = { array: arguments[ 1 ], itemSize: arguments[ 2 ] };
  5885. return;
  5886. }
  5887. this.attributes[ name ] = attribute;
  5888. },
  5889. getAttribute: function ( name ) {
  5890. return this.attributes[ name ];
  5891. },
  5892. addDrawCall: function ( start, count, indexOffset ) {
  5893. this.drawcalls.push( {
  5894. start: start,
  5895. count: count,
  5896. index: indexOffset !== undefined ? indexOffset : 0
  5897. } );
  5898. },
  5899. applyMatrix: function ( matrix ) {
  5900. var position = this.attributes.position;
  5901. if ( position !== undefined ) {
  5902. matrix.applyToVector3Array( position.array );
  5903. position.needsUpdate = true;
  5904. }
  5905. var normal = this.attributes.normal;
  5906. if ( normal !== undefined ) {
  5907. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5908. normalMatrix.applyToVector3Array( normal.array );
  5909. normal.needsUpdate = true;
  5910. }
  5911. if ( this.boundingBox !== null ) {
  5912. this.computeBoundingBox();
  5913. }
  5914. if ( this.boundingSphere !== null ) {
  5915. this.computeBoundingSphere();
  5916. }
  5917. },
  5918. copy: function ( geometry ) {
  5919. var attributes = geometry.attributes;
  5920. var offsets = geometry.offsets;
  5921. for ( var name in attributes ) {
  5922. var attribute = attributes[ name ];
  5923. this.addAttribute( name, attribute.clone() );
  5924. }
  5925. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  5926. var offset = offsets[ i ];
  5927. this.offsets.push( {
  5928. start: offset.start,
  5929. index: offset.index,
  5930. count: offset.count
  5931. } );
  5932. }
  5933. return this;
  5934. },
  5935. center: function () {
  5936. this.computeBoundingBox();
  5937. var offset = this.boundingBox.center().negate();
  5938. this.applyMatrix( new THREE.Matrix4().setPosition( offset ) );
  5939. return offset;
  5940. },
  5941. setFromObject: function ( object ) {
  5942. console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  5943. var geometry = object.geometry;
  5944. var material = object.material;
  5945. if ( object instanceof THREE.PointCloud || object instanceof THREE.Line ) {
  5946. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  5947. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  5948. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  5949. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  5950. this.computeBoundingSphere();
  5951. } else if ( object instanceof THREE.Mesh ) {
  5952. // skinning
  5953. if ( object instanceof THREE.SkinnedMesh ) {
  5954. if ( geometry instanceof THREE.Geometry ) {
  5955. console.log( 'THREE.BufferGeometry.setFromObject(): Converted THREE.Geometry to THREE.DynamicGeometry as required for THREE.SkinnedMesh.', geometry );
  5956. geometry = new THREE.DynamicGeometry().fromGeometry( geometry );
  5957. }
  5958. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  5959. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  5960. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  5961. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  5962. }
  5963. // morphs
  5964. if ( object.morphTargetInfluences !== undefined ) {
  5965. if ( geometry instanceof THREE.Geometry ) {
  5966. console.log( 'THREE.BufferGeometry.setFromObject(): Converted THREE.Geometry to THREE.DynamicGeometry as required for MorphTargets.', geometry );
  5967. geometry = new THREE.DynamicGeometry().fromGeometry( geometry );
  5968. }
  5969. // positions
  5970. var morphTargets = geometry.morphTargets;
  5971. if ( morphTargets.length > 0 ) {
  5972. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  5973. var morphTarget = morphTargets[ i ];
  5974. var attribute = new THREE.Float32Attribute( morphTarget.vertices.length * 3, 3 );
  5975. this.morphAttributes.push( attribute.copyVector3sArray( morphTarget.vertices ) );
  5976. }
  5977. }
  5978. }
  5979. if ( geometry instanceof THREE.DynamicGeometry ) {
  5980. this.fromDynamicGeometry( geometry );
  5981. } else if ( geometry instanceof THREE.Geometry ) {
  5982. this.fromGeometry( geometry, material );
  5983. }
  5984. }
  5985. return this;
  5986. },
  5987. updateFromObject: function ( object ) {
  5988. var geometry = object.geometry;
  5989. if ( geometry.verticesNeedUpdate === true ) {
  5990. var attribute = this.attributes.position;
  5991. if ( attribute !== undefined ) {
  5992. attribute.copyVector3sArray( geometry.vertices );
  5993. attribute.needsUpdate = true;
  5994. }
  5995. geometry.verticesNeedUpdate = false;
  5996. }
  5997. if ( geometry.colorsNeedUpdate === true ) {
  5998. var attribute = this.attributes.color;
  5999. if ( attribute !== undefined ) {
  6000. attribute.copyColorsArray( geometry.colors );
  6001. attribute.needsUpdate = true;
  6002. }
  6003. geometry.colorsNeedUpdate = false;
  6004. }
  6005. },
  6006. fromGeometry: function ( geometry, material ) {
  6007. material = material || { 'vertexColors': THREE.NoColors };
  6008. var vertices = geometry.vertices;
  6009. var faces = geometry.faces;
  6010. var faceVertexUvs = geometry.faceVertexUvs;
  6011. var vertexColors = material.vertexColors;
  6012. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6013. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6014. var positions = new Float32Array( faces.length * 3 * 3 );
  6015. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  6016. var normals = new Float32Array( faces.length * 3 * 3 );
  6017. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  6018. if ( vertexColors !== THREE.NoColors ) {
  6019. var colors = new Float32Array( faces.length * 3 * 3 );
  6020. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  6021. }
  6022. if ( hasFaceVertexUv === true ) {
  6023. var uvs = new Float32Array( faces.length * 3 * 2 );
  6024. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  6025. }
  6026. if ( hasFaceVertexUv2 === true ) {
  6027. var uvs2 = new Float32Array( faces.length * 3 * 2 );
  6028. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ) );
  6029. }
  6030. for ( var i = 0, i2 = 0, i3 = 0; i < faces.length; i ++, i2 += 6, i3 += 9 ) {
  6031. var face = faces[ i ];
  6032. var a = vertices[ face.a ];
  6033. var b = vertices[ face.b ];
  6034. var c = vertices[ face.c ];
  6035. positions[ i3 ] = a.x;
  6036. positions[ i3 + 1 ] = a.y;
  6037. positions[ i3 + 2 ] = a.z;
  6038. positions[ i3 + 3 ] = b.x;
  6039. positions[ i3 + 4 ] = b.y;
  6040. positions[ i3 + 5 ] = b.z;
  6041. positions[ i3 + 6 ] = c.x;
  6042. positions[ i3 + 7 ] = c.y;
  6043. positions[ i3 + 8 ] = c.z;
  6044. var vertexNormals = face.vertexNormals;
  6045. if ( vertexNormals.length === 3 ) {
  6046. var na = vertexNormals[ 0 ];
  6047. var nb = vertexNormals[ 1 ];
  6048. var nc = vertexNormals[ 2 ];
  6049. normals[ i3 ] = na.x;
  6050. normals[ i3 + 1 ] = na.y;
  6051. normals[ i3 + 2 ] = na.z;
  6052. normals[ i3 + 3 ] = nb.x;
  6053. normals[ i3 + 4 ] = nb.y;
  6054. normals[ i3 + 5 ] = nb.z;
  6055. normals[ i3 + 6 ] = nc.x;
  6056. normals[ i3 + 7 ] = nc.y;
  6057. normals[ i3 + 8 ] = nc.z;
  6058. } else {
  6059. var n = face.normal;
  6060. normals[ i3 ] = n.x;
  6061. normals[ i3 + 1 ] = n.y;
  6062. normals[ i3 + 2 ] = n.z;
  6063. normals[ i3 + 3 ] = n.x;
  6064. normals[ i3 + 4 ] = n.y;
  6065. normals[ i3 + 5 ] = n.z;
  6066. normals[ i3 + 6 ] = n.x;
  6067. normals[ i3 + 7 ] = n.y;
  6068. normals[ i3 + 8 ] = n.z;
  6069. }
  6070. if ( vertexColors === THREE.FaceColors ) {
  6071. var fc = face.color;
  6072. colors[ i3 ] = fc.r;
  6073. colors[ i3 + 1 ] = fc.g;
  6074. colors[ i3 + 2 ] = fc.b;
  6075. colors[ i3 + 3 ] = fc.r;
  6076. colors[ i3 + 4 ] = fc.g;
  6077. colors[ i3 + 5 ] = fc.b;
  6078. colors[ i3 + 6 ] = fc.r;
  6079. colors[ i3 + 7 ] = fc.g;
  6080. colors[ i3 + 8 ] = fc.b;
  6081. } else if ( vertexColors === THREE.VertexColors ) {
  6082. var vca = face.vertexColors[ 0 ];
  6083. var vcb = face.vertexColors[ 1 ];
  6084. var vcc = face.vertexColors[ 2 ];
  6085. colors[ i3 ] = vca.r;
  6086. colors[ i3 + 1 ] = vca.g;
  6087. colors[ i3 + 2 ] = vca.b;
  6088. colors[ i3 + 3 ] = vcb.r;
  6089. colors[ i3 + 4 ] = vcb.g;
  6090. colors[ i3 + 5 ] = vcb.b;
  6091. colors[ i3 + 6 ] = vcc.r;
  6092. colors[ i3 + 7 ] = vcc.g;
  6093. colors[ i3 + 8 ] = vcc.b;
  6094. }
  6095. if ( hasFaceVertexUv === true ) {
  6096. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6097. if ( vertexUvs !== undefined ) {
  6098. var uva = vertexUvs[ 0 ];
  6099. var uvb = vertexUvs[ 1 ];
  6100. var uvc = vertexUvs[ 2 ];
  6101. uvs[ i2 ] = uva.x;
  6102. uvs[ i2 + 1 ] = uva.y;
  6103. uvs[ i2 + 2 ] = uvb.x;
  6104. uvs[ i2 + 3 ] = uvb.y;
  6105. uvs[ i2 + 4 ] = uvc.x;
  6106. uvs[ i2 + 5 ] = uvc.y;
  6107. } else {
  6108. console.warn( 'THREE.BufferGeometry.fromGeometry(): Undefined vertexUv', i );
  6109. }
  6110. }
  6111. if ( hasFaceVertexUv2 === true ) {
  6112. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6113. if ( vertexUvs !== undefined ) {
  6114. var uva = vertexUvs[ 0 ];
  6115. var uvb = vertexUvs[ 1 ];
  6116. var uvc = vertexUvs[ 2 ];
  6117. uvs2[ i2 ] = uva.x;
  6118. uvs2[ i2 + 1 ] = uva.y;
  6119. uvs2[ i2 + 2 ] = uvb.x;
  6120. uvs2[ i2 + 3 ] = uvb.y;
  6121. uvs2[ i2 + 4 ] = uvc.x;
  6122. uvs2[ i2 + 5 ] = uvc.y;
  6123. } else {
  6124. console.warn( 'THREE.BufferGeometry.fromGeometry(): Undefined vertexUv2', i );
  6125. }
  6126. }
  6127. }
  6128. this.computeBoundingSphere();
  6129. return this;
  6130. },
  6131. fromDynamicGeometry: function ( geometry ) {
  6132. var indices = new Uint16Array( geometry.faces.length * 3 );
  6133. this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ).copyFacesArray( geometry.faces ) );
  6134. var positions = new Float32Array( geometry.vertices.length * 3 );
  6135. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6136. if ( geometry.normals.length > 0 ) {
  6137. var normals = new Float32Array( geometry.normals.length * 3 );
  6138. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6139. }
  6140. if ( geometry.colors.length > 0 ) {
  6141. var colors = new Float32Array( geometry.colors.length * 3 );
  6142. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6143. }
  6144. if ( geometry.uvs.length > 0 ) {
  6145. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6146. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6147. }
  6148. this.computeBoundingSphere();
  6149. return this;
  6150. },
  6151. computeBoundingBox: function () {
  6152. var vector = new THREE.Vector3();
  6153. return function () {
  6154. if ( this.boundingBox === null ) {
  6155. this.boundingBox = new THREE.Box3();
  6156. }
  6157. var positions = this.attributes.position.array;
  6158. if ( positions ) {
  6159. var bb = this.boundingBox;
  6160. bb.makeEmpty();
  6161. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6162. vector.fromArray( positions, i );
  6163. bb.expandByPoint( vector );
  6164. }
  6165. }
  6166. if ( positions === undefined || positions.length === 0 ) {
  6167. this.boundingBox.min.set( 0, 0, 0 );
  6168. this.boundingBox.max.set( 0, 0, 0 );
  6169. }
  6170. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6171. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6172. }
  6173. };
  6174. }(),
  6175. computeBoundingSphere: function () {
  6176. var box = new THREE.Box3();
  6177. var vector = new THREE.Vector3();
  6178. return function () {
  6179. if ( this.boundingSphere === null ) {
  6180. this.boundingSphere = new THREE.Sphere();
  6181. }
  6182. var positions = this.attributes.position.array;
  6183. if ( positions ) {
  6184. box.makeEmpty();
  6185. var center = this.boundingSphere.center;
  6186. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6187. vector.fromArray( positions, i );
  6188. box.expandByPoint( vector );
  6189. }
  6190. box.center( center );
  6191. // hoping to find a boundingSphere with a radius smaller than the
  6192. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6193. var maxRadiusSq = 0;
  6194. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6195. vector.fromArray( positions, i );
  6196. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6197. }
  6198. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6199. if ( isNaN( this.boundingSphere.radius ) ) {
  6200. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6201. }
  6202. }
  6203. };
  6204. }(),
  6205. computeFaceNormals: function () {
  6206. // backwards compatibility
  6207. },
  6208. computeVertexNormals: function () {
  6209. var attributes = this.attributes;
  6210. if ( attributes.position ) {
  6211. var positions = attributes.position.array;
  6212. if ( attributes.normal === undefined ) {
  6213. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6214. } else {
  6215. // reset existing normals to zero
  6216. var normals = attributes.normal.array;
  6217. for ( var i = 0, il = normals.length; i < il; i ++ ) {
  6218. normals[ i ] = 0;
  6219. }
  6220. }
  6221. var normals = attributes.normal.array;
  6222. var vA, vB, vC,
  6223. pA = new THREE.Vector3(),
  6224. pB = new THREE.Vector3(),
  6225. pC = new THREE.Vector3(),
  6226. cb = new THREE.Vector3(),
  6227. ab = new THREE.Vector3();
  6228. // indexed elements
  6229. if ( attributes.index ) {
  6230. var indices = attributes.index.array;
  6231. var offsets = ( this.offsets.length > 0 ? this.offsets : [ { start: 0, count: indices.length, index: 0 } ] );
  6232. for ( var j = 0, jl = offsets.length; j < jl; ++ j ) {
  6233. var start = offsets[ j ].start;
  6234. var count = offsets[ j ].count;
  6235. var index = offsets[ j ].index;
  6236. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6237. vA = ( index + indices[ i ] ) * 3;
  6238. vB = ( index + indices[ i + 1 ] ) * 3;
  6239. vC = ( index + indices[ i + 2 ] ) * 3;
  6240. pA.fromArray( positions, vA );
  6241. pB.fromArray( positions, vB );
  6242. pC.fromArray( positions, vC );
  6243. cb.subVectors( pC, pB );
  6244. ab.subVectors( pA, pB );
  6245. cb.cross( ab );
  6246. normals[ vA ] += cb.x;
  6247. normals[ vA + 1 ] += cb.y;
  6248. normals[ vA + 2 ] += cb.z;
  6249. normals[ vB ] += cb.x;
  6250. normals[ vB + 1 ] += cb.y;
  6251. normals[ vB + 2 ] += cb.z;
  6252. normals[ vC ] += cb.x;
  6253. normals[ vC + 1 ] += cb.y;
  6254. normals[ vC + 2 ] += cb.z;
  6255. }
  6256. }
  6257. } else {
  6258. // non-indexed elements (unconnected triangle soup)
  6259. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6260. pA.fromArray( positions, i );
  6261. pB.fromArray( positions, i + 3 );
  6262. pC.fromArray( positions, i + 6 );
  6263. cb.subVectors( pC, pB );
  6264. ab.subVectors( pA, pB );
  6265. cb.cross( ab );
  6266. normals[ i ] = cb.x;
  6267. normals[ i + 1 ] = cb.y;
  6268. normals[ i + 2 ] = cb.z;
  6269. normals[ i + 3 ] = cb.x;
  6270. normals[ i + 4 ] = cb.y;
  6271. normals[ i + 5 ] = cb.z;
  6272. normals[ i + 6 ] = cb.x;
  6273. normals[ i + 7 ] = cb.y;
  6274. normals[ i + 8 ] = cb.z;
  6275. }
  6276. }
  6277. this.normalizeNormals();
  6278. attributes.normal.needsUpdate = true;
  6279. }
  6280. },
  6281. computeTangents: function () {
  6282. // based on http://www.terathon.com/code/tangent.html
  6283. // (per vertex tangents)
  6284. if ( this.attributes.index === undefined ||
  6285. this.attributes.position === undefined ||
  6286. this.attributes.normal === undefined ||
  6287. this.attributes.uv === undefined ) {
  6288. console.warn( 'THREE.BufferGeometry: Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()' );
  6289. return;
  6290. }
  6291. var indices = this.attributes.index.array;
  6292. var positions = this.attributes.position.array;
  6293. var normals = this.attributes.normal.array;
  6294. var uvs = this.attributes.uv.array;
  6295. var nVertices = positions.length / 3;
  6296. if ( this.attributes.tangent === undefined ) {
  6297. this.addAttribute( 'tangent', new THREE.BufferAttribute( new Float32Array( 4 * nVertices ), 4 ) );
  6298. }
  6299. var tangents = this.attributes.tangent.array;
  6300. var tan1 = [], tan2 = [];
  6301. for ( var k = 0; k < nVertices; k ++ ) {
  6302. tan1[ k ] = new THREE.Vector3();
  6303. tan2[ k ] = new THREE.Vector3();
  6304. }
  6305. var vA = new THREE.Vector3(),
  6306. vB = new THREE.Vector3(),
  6307. vC = new THREE.Vector3(),
  6308. uvA = new THREE.Vector2(),
  6309. uvB = new THREE.Vector2(),
  6310. uvC = new THREE.Vector2(),
  6311. x1, x2, y1, y2, z1, z2,
  6312. s1, s2, t1, t2, r;
  6313. var sdir = new THREE.Vector3(), tdir = new THREE.Vector3();
  6314. function handleTriangle( a, b, c ) {
  6315. vA.fromArray( positions, a * 3 );
  6316. vB.fromArray( positions, b * 3 );
  6317. vC.fromArray( positions, c * 3 );
  6318. uvA.fromArray( uvs, a * 2 );
  6319. uvB.fromArray( uvs, b * 2 );
  6320. uvC.fromArray( uvs, c * 2 );
  6321. x1 = vB.x - vA.x;
  6322. x2 = vC.x - vA.x;
  6323. y1 = vB.y - vA.y;
  6324. y2 = vC.y - vA.y;
  6325. z1 = vB.z - vA.z;
  6326. z2 = vC.z - vA.z;
  6327. s1 = uvB.x - uvA.x;
  6328. s2 = uvC.x - uvA.x;
  6329. t1 = uvB.y - uvA.y;
  6330. t2 = uvC.y - uvA.y;
  6331. r = 1.0 / ( s1 * t2 - s2 * t1 );
  6332. sdir.set(
  6333. ( t2 * x1 - t1 * x2 ) * r,
  6334. ( t2 * y1 - t1 * y2 ) * r,
  6335. ( t2 * z1 - t1 * z2 ) * r
  6336. );
  6337. tdir.set(
  6338. ( s1 * x2 - s2 * x1 ) * r,
  6339. ( s1 * y2 - s2 * y1 ) * r,
  6340. ( s1 * z2 - s2 * z1 ) * r
  6341. );
  6342. tan1[ a ].add( sdir );
  6343. tan1[ b ].add( sdir );
  6344. tan1[ c ].add( sdir );
  6345. tan2[ a ].add( tdir );
  6346. tan2[ b ].add( tdir );
  6347. tan2[ c ].add( tdir );
  6348. }
  6349. var i, il;
  6350. var j, jl;
  6351. var iA, iB, iC;
  6352. if ( this.drawcalls.length === 0 ) {
  6353. this.addDrawCall( 0, indices.length, 0 );
  6354. }
  6355. var drawcalls = this.drawcalls;
  6356. for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
  6357. var start = drawcalls[ j ].start;
  6358. var count = drawcalls[ j ].count;
  6359. var index = drawcalls[ j ].index;
  6360. for ( i = start, il = start + count; i < il; i += 3 ) {
  6361. iA = index + indices[ i ];
  6362. iB = index + indices[ i + 1 ];
  6363. iC = index + indices[ i + 2 ];
  6364. handleTriangle( iA, iB, iC );
  6365. }
  6366. }
  6367. var tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3();
  6368. var n = new THREE.Vector3(), n2 = new THREE.Vector3();
  6369. var w, t, test;
  6370. function handleVertex( v ) {
  6371. n.fromArray( normals, v * 3 );
  6372. n2.copy( n );
  6373. t = tan1[ v ];
  6374. // Gram-Schmidt orthogonalize
  6375. tmp.copy( t );
  6376. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  6377. // Calculate handedness
  6378. tmp2.crossVectors( n2, t );
  6379. test = tmp2.dot( tan2[ v ] );
  6380. w = ( test < 0.0 ) ? - 1.0 : 1.0;
  6381. tangents[ v * 4 ] = tmp.x;
  6382. tangents[ v * 4 + 1 ] = tmp.y;
  6383. tangents[ v * 4 + 2 ] = tmp.z;
  6384. tangents[ v * 4 + 3 ] = w;
  6385. }
  6386. for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
  6387. var start = drawcalls[ j ].start;
  6388. var count = drawcalls[ j ].count;
  6389. var index = drawcalls[ j ].index;
  6390. for ( i = start, il = start + count; i < il; i += 3 ) {
  6391. iA = index + indices[ i ];
  6392. iB = index + indices[ i + 1 ];
  6393. iC = index + indices[ i + 2 ];
  6394. handleVertex( iA );
  6395. handleVertex( iB );
  6396. handleVertex( iC );
  6397. }
  6398. }
  6399. },
  6400. /*
  6401. Compute the draw offset for large models by chunking the index buffer into chunks of 65k addressable vertices.
  6402. This method will effectively rewrite the index buffer and remap all attributes to match the new indices.
  6403. WARNING: This method will also expand the vertex count to prevent sprawled triangles across draw offsets.
  6404. size - Defaults to 65535 or 4294967296 if extension OES_element_index_uint supported, but allows for larger or smaller chunks.
  6405. */
  6406. computeOffsets: function ( size ) {
  6407. if ( size === undefined ) size = THREE.BufferGeometry.MaxIndex;
  6408. var indices = this.attributes.index.array;
  6409. var vertices = this.attributes.position.array;
  6410. var facesCount = ( indices.length / 3 );
  6411. var UintArray = ( ( vertices.length / 3 ) > 65535 && THREE.BufferGeometry.MaxIndex > 65535 ) ? Uint32Array : Uint16Array;
  6412. /*
  6413. console.log("Computing buffers in offsets of "+size+" -> indices:"+indices.length+" vertices:"+vertices.length);
  6414. console.log("Faces to process: "+(indices.length/3));
  6415. console.log("Reordering "+verticesCount+" vertices.");
  6416. */
  6417. var sortedIndices = new UintArray( indices.length );
  6418. var indexPtr = 0;
  6419. var vertexPtr = 0;
  6420. var offsets = [ { start:0, count:0, index:0 } ];
  6421. var offset = offsets[ 0 ];
  6422. var duplicatedVertices = 0;
  6423. var newVerticeMaps = 0;
  6424. var faceVertices = new Int32Array( 6 );
  6425. var vertexMap = new Int32Array( vertices.length );
  6426. var revVertexMap = new Int32Array( vertices.length );
  6427. for ( var j = 0; j < vertices.length; j ++ ) { vertexMap[ j ] = - 1; revVertexMap[ j ] = - 1; }
  6428. /*
  6429. Traverse every face and reorder vertices in the proper offsets of 65k.
  6430. We can have more than 'size' entries in the index buffer per offset, but only reference 'size' values.
  6431. */
  6432. for ( var findex = 0; findex < facesCount; findex ++ ) {
  6433. newVerticeMaps = 0;
  6434. for ( var vo = 0; vo < 3; vo ++ ) {
  6435. var vid = indices[ findex * 3 + vo ];
  6436. if ( vertexMap[ vid ] === - 1 ) {
  6437. //Unmapped vertice
  6438. faceVertices[ vo * 2 ] = vid;
  6439. faceVertices[ vo * 2 + 1 ] = - 1;
  6440. newVerticeMaps ++;
  6441. } else if ( vertexMap[ vid ] < offset.index ) {
  6442. //Reused vertices from previous block (duplicate)
  6443. faceVertices[ vo * 2 ] = vid;
  6444. faceVertices[ vo * 2 + 1 ] = - 1;
  6445. duplicatedVertices ++;
  6446. } else {
  6447. //Reused vertice in the current block
  6448. faceVertices[ vo * 2 ] = vid;
  6449. faceVertices[ vo * 2 + 1 ] = vertexMap[ vid ];
  6450. }
  6451. }
  6452. var faceMax = vertexPtr + newVerticeMaps;
  6453. if ( faceMax > ( offset.index + size ) ) {
  6454. var new_offset = { start:indexPtr, count:0, index:vertexPtr };
  6455. offsets.push( new_offset );
  6456. offset = new_offset;
  6457. //Re-evaluate reused vertices in light of new offset.
  6458. for ( var v = 0; v < 6; v += 2 ) {
  6459. var new_vid = faceVertices[ v + 1 ];
  6460. if ( new_vid > - 1 && new_vid < offset.index )
  6461. faceVertices[ v + 1 ] = - 1;
  6462. }
  6463. }
  6464. //Reindex the face.
  6465. for ( var v = 0; v < 6; v += 2 ) {
  6466. var vid = faceVertices[ v ];
  6467. var new_vid = faceVertices[ v + 1 ];
  6468. if ( new_vid === - 1 )
  6469. new_vid = vertexPtr ++;
  6470. vertexMap[ vid ] = new_vid;
  6471. revVertexMap[ new_vid ] = vid;
  6472. sortedIndices[ indexPtr ++ ] = new_vid - offset.index; //XXX overflows at 16bit
  6473. offset.count ++;
  6474. }
  6475. }
  6476. /* Move all attribute values to map to the new computed indices , also expand the vertice stack to match our new vertexPtr. */
  6477. this.reorderBuffers( sortedIndices, revVertexMap, vertexPtr );
  6478. this.offsets = offsets; // TODO: Deprecate
  6479. this.drawcalls = offsets;
  6480. /*
  6481. var orderTime = Date.now();
  6482. console.log("Reorder time: "+(orderTime-s)+"ms");
  6483. console.log("Duplicated "+duplicatedVertices+" vertices.");
  6484. console.log("Compute Buffers time: "+(Date.now()-s)+"ms");
  6485. console.log("Draw offsets: "+offsets.length);
  6486. */
  6487. return offsets;
  6488. },
  6489. merge: function ( geometry, offset ) {
  6490. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6491. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6492. return;
  6493. }
  6494. if ( offset === undefined ) offset = 0;
  6495. var attributes = this.attributes;
  6496. for ( var key in attributes ) {
  6497. if ( geometry.attributes[ key ] === undefined ) continue;
  6498. var attribute1 = attributes[ key ];
  6499. var attributeArray1 = attribute1.array;
  6500. var attribute2 = geometry.attributes[ key ];
  6501. var attributeArray2 = attribute2.array;
  6502. var attributeSize = attribute2.itemSize;
  6503. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6504. attributeArray1[ j ] = attributeArray2[ i ];
  6505. }
  6506. }
  6507. return this;
  6508. },
  6509. normalizeNormals: function () {
  6510. var normals = this.attributes.normal.array;
  6511. var x, y, z, n;
  6512. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6513. x = normals[ i ];
  6514. y = normals[ i + 1 ];
  6515. z = normals[ i + 2 ];
  6516. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6517. normals[ i ] *= n;
  6518. normals[ i + 1 ] *= n;
  6519. normals[ i + 2 ] *= n;
  6520. }
  6521. },
  6522. /*
  6523. reoderBuffers:
  6524. Reorder attributes based on a new indexBuffer and indexMap.
  6525. indexBuffer - Uint16Array of the new ordered indices.
  6526. indexMap - Int32Array where the position is the new vertex ID and the value the old vertex ID for each vertex.
  6527. vertexCount - Amount of total vertices considered in this reordering (in case you want to grow the vertice stack).
  6528. */
  6529. reorderBuffers: function ( indexBuffer, indexMap, vertexCount ) {
  6530. /* Create a copy of all attributes for reordering. */
  6531. var sortedAttributes = {};
  6532. for ( var attr in this.attributes ) {
  6533. if ( attr === 'index' )
  6534. continue;
  6535. var sourceArray = this.attributes[ attr ].array;
  6536. sortedAttributes[ attr ] = new sourceArray.constructor( this.attributes[ attr ].itemSize * vertexCount );
  6537. }
  6538. /* Move attribute positions based on the new index map */
  6539. for ( var new_vid = 0; new_vid < vertexCount; new_vid ++ ) {
  6540. var vid = indexMap[ new_vid ];
  6541. for ( var attr in this.attributes ) {
  6542. if ( attr === 'index' )
  6543. continue;
  6544. var attrArray = this.attributes[ attr ].array;
  6545. var attrSize = this.attributes[ attr ].itemSize;
  6546. var sortedAttr = sortedAttributes[ attr ];
  6547. for ( var k = 0; k < attrSize; k ++ )
  6548. sortedAttr[ new_vid * attrSize + k ] = attrArray[ vid * attrSize + k ];
  6549. }
  6550. }
  6551. /* Carry the new sorted buffers locally */
  6552. this.attributes[ 'index' ].array = indexBuffer;
  6553. for ( var attr in this.attributes ) {
  6554. if ( attr === 'index' )
  6555. continue;
  6556. this.attributes[ attr ].array = sortedAttributes[ attr ];
  6557. this.attributes[ attr ].numItems = this.attributes[ attr ].itemSize * vertexCount;
  6558. }
  6559. },
  6560. toJSON: function () {
  6561. var data = {
  6562. metadata: {
  6563. version: 4.4,
  6564. type: 'BufferGeometry',
  6565. generator: 'BufferGeometry.toJSON'
  6566. }
  6567. };
  6568. // standard BufferGeometry serialization
  6569. data.uuid = this.uuid;
  6570. data.type = this.type;
  6571. if ( this.name !== '' ) data.name = this.name;
  6572. if ( this.parameters !== undefined ) {
  6573. var parameters = this.parameters;
  6574. for ( var key in parameters ) {
  6575. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6576. }
  6577. return data;
  6578. }
  6579. data.data = { attributes: {} };
  6580. var attributes = this.attributes;
  6581. var offsets = this.offsets;
  6582. var boundingSphere = this.boundingSphere;
  6583. for ( var key in attributes ) {
  6584. var attribute = attributes[ key ];
  6585. var array = Array.prototype.slice.call( attribute.array );
  6586. data.data.attributes[ key ] = {
  6587. itemSize: attribute.itemSize,
  6588. type: attribute.array.constructor.name,
  6589. array: array
  6590. }
  6591. }
  6592. if ( offsets.length > 0 ) {
  6593. data.data.offsets = JSON.parse( JSON.stringify( offsets ) );
  6594. }
  6595. if ( boundingSphere !== null ) {
  6596. data.data.boundingSphere = {
  6597. center: boundingSphere.center.toArray(),
  6598. radius: boundingSphere.radius
  6599. }
  6600. }
  6601. return data;
  6602. },
  6603. clone: function () {
  6604. var geometry = new THREE.BufferGeometry();
  6605. for ( var attr in this.attributes ) {
  6606. var sourceAttr = this.attributes[ attr ];
  6607. geometry.addAttribute( attr, sourceAttr.clone() );
  6608. }
  6609. for ( var i = 0, il = this.offsets.length; i < il; i ++ ) {
  6610. var offset = this.offsets[ i ];
  6611. geometry.offsets.push( {
  6612. start: offset.start,
  6613. index: offset.index,
  6614. count: offset.count
  6615. } );
  6616. }
  6617. return geometry;
  6618. },
  6619. dispose: function () {
  6620. this.dispatchEvent( { type: 'dispose' } );
  6621. }
  6622. };
  6623. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  6624. THREE.BufferGeometry.MaxIndex = 65535;
  6625. // File:src/core/InstancedBufferGeometry.js
  6626. /**
  6627. * @author benaadams / https://twitter.com/ben_a_adams
  6628. */
  6629. THREE.InstancedBufferGeometry = function () {
  6630. THREE.BufferGeometry.call( this );
  6631. this.type = 'InstancedBufferGeometry';
  6632. this.maxInstancedCount = undefined;
  6633. };
  6634. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  6635. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  6636. THREE.InstancedBufferGeometry.prototype.addDrawCall = function ( start, count, indexOffset, instances ) {
  6637. this.drawcalls.push( {
  6638. start: start,
  6639. count: count,
  6640. index: indexOffset !== undefined ? indexOffset : 0,
  6641. instances: instances
  6642. } );
  6643. },
  6644. THREE.InstancedBufferGeometry.prototype.clone = function () {
  6645. var geometry = new THREE.InstancedBufferGeometry();
  6646. for ( var attr in this.attributes ) {
  6647. var sourceAttr = this.attributes[attr];
  6648. geometry.addAttribute( attr, sourceAttr.clone() );
  6649. }
  6650. for ( var i = 0, il = this.offsets.length; i < il; i++ ) {
  6651. var offset = this.offsets[i];
  6652. geometry.offsets.push( {
  6653. start: offset.start,
  6654. index: offset.index,
  6655. count: offset.count,
  6656. instances: offset.instances
  6657. } );
  6658. }
  6659. return geometry;
  6660. };
  6661. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  6662. // File:src/cameras/Camera.js
  6663. /**
  6664. * @author mrdoob / http://mrdoob.com/
  6665. * @author mikael emtinger / http://gomo.se/
  6666. * @author WestLangley / http://github.com/WestLangley
  6667. */
  6668. THREE.Camera = function () {
  6669. THREE.Object3D.call( this );
  6670. this.type = 'Camera';
  6671. this.matrixWorldInverse = new THREE.Matrix4();
  6672. this.projectionMatrix = new THREE.Matrix4();
  6673. };
  6674. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  6675. THREE.Camera.prototype.constructor = THREE.Camera;
  6676. THREE.Camera.prototype.getWorldDirection = function () {
  6677. var quaternion = new THREE.Quaternion();
  6678. return function ( optionalTarget ) {
  6679. var result = optionalTarget || new THREE.Vector3();
  6680. this.getWorldQuaternion( quaternion );
  6681. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  6682. };
  6683. }();
  6684. THREE.Camera.prototype.lookAt = function () {
  6685. // This routine does not support cameras with rotated and/or translated parent(s)
  6686. var m1 = new THREE.Matrix4();
  6687. return function ( vector ) {
  6688. m1.lookAt( this.position, vector, this.up );
  6689. this.quaternion.setFromRotationMatrix( m1 );
  6690. };
  6691. }();
  6692. THREE.Camera.prototype.clone = function ( camera ) {
  6693. if ( camera === undefined ) camera = new THREE.Camera();
  6694. THREE.Object3D.prototype.clone.call( this, camera );
  6695. camera.matrixWorldInverse.copy( this.matrixWorldInverse );
  6696. camera.projectionMatrix.copy( this.projectionMatrix );
  6697. return camera;
  6698. };
  6699. // File:src/cameras/CubeCamera.js
  6700. /**
  6701. * Camera for rendering cube maps
  6702. * - renders scene into axis-aligned cube
  6703. *
  6704. * @author alteredq / http://alteredqualia.com/
  6705. */
  6706. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  6707. THREE.Object3D.call( this );
  6708. this.type = 'CubeCamera';
  6709. var fov = 90, aspect = 1;
  6710. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6711. cameraPX.up.set( 0, - 1, 0 );
  6712. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  6713. this.add( cameraPX );
  6714. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6715. cameraNX.up.set( 0, - 1, 0 );
  6716. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  6717. this.add( cameraNX );
  6718. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6719. cameraPY.up.set( 0, 0, 1 );
  6720. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  6721. this.add( cameraPY );
  6722. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6723. cameraNY.up.set( 0, 0, - 1 );
  6724. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  6725. this.add( cameraNY );
  6726. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6727. cameraPZ.up.set( 0, - 1, 0 );
  6728. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  6729. this.add( cameraPZ );
  6730. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6731. cameraNZ.up.set( 0, - 1, 0 );
  6732. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  6733. this.add( cameraNZ );
  6734. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  6735. this.updateCubeMap = function ( renderer, scene ) {
  6736. if ( this.parent === undefined ) this.updateMatrixWorld();
  6737. var renderTarget = this.renderTarget;
  6738. var generateMipmaps = renderTarget.generateMipmaps;
  6739. renderTarget.generateMipmaps = false;
  6740. renderTarget.activeCubeFace = 0;
  6741. renderer.render( scene, cameraPX, renderTarget );
  6742. renderTarget.activeCubeFace = 1;
  6743. renderer.render( scene, cameraNX, renderTarget );
  6744. renderTarget.activeCubeFace = 2;
  6745. renderer.render( scene, cameraPY, renderTarget );
  6746. renderTarget.activeCubeFace = 3;
  6747. renderer.render( scene, cameraNY, renderTarget );
  6748. renderTarget.activeCubeFace = 4;
  6749. renderer.render( scene, cameraPZ, renderTarget );
  6750. renderTarget.generateMipmaps = generateMipmaps;
  6751. renderTarget.activeCubeFace = 5;
  6752. renderer.render( scene, cameraNZ, renderTarget );
  6753. renderer.setRenderTarget( null );
  6754. };
  6755. };
  6756. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  6757. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  6758. // File:src/cameras/OrthographicCamera.js
  6759. /**
  6760. * @author alteredq / http://alteredqualia.com/
  6761. */
  6762. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  6763. THREE.Camera.call( this );
  6764. this.type = 'OrthographicCamera';
  6765. this.zoom = 1;
  6766. this.left = left;
  6767. this.right = right;
  6768. this.top = top;
  6769. this.bottom = bottom;
  6770. this.near = ( near !== undefined ) ? near : 0.1;
  6771. this.far = ( far !== undefined ) ? far : 2000;
  6772. this.updateProjectionMatrix();
  6773. };
  6774. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  6775. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  6776. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  6777. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  6778. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  6779. var cx = ( this.right + this.left ) / 2;
  6780. var cy = ( this.top + this.bottom ) / 2;
  6781. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  6782. };
  6783. THREE.OrthographicCamera.prototype.clone = function () {
  6784. var camera = new THREE.OrthographicCamera();
  6785. THREE.Camera.prototype.clone.call( this, camera );
  6786. camera.zoom = this.zoom;
  6787. camera.left = this.left;
  6788. camera.right = this.right;
  6789. camera.top = this.top;
  6790. camera.bottom = this.bottom;
  6791. camera.near = this.near;
  6792. camera.far = this.far;
  6793. camera.projectionMatrix.copy( this.projectionMatrix );
  6794. return camera;
  6795. };
  6796. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  6797. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  6798. data.object.left = this.left;
  6799. data.object.right = this.right;
  6800. data.object.top = this.top;
  6801. data.object.bottom = this.bottom;
  6802. data.object.near = this.near;
  6803. data.object.far = this.far;
  6804. return data;
  6805. };
  6806. // File:src/cameras/PerspectiveCamera.js
  6807. /**
  6808. * @author mrdoob / http://mrdoob.com/
  6809. * @author greggman / http://games.greggman.com/
  6810. * @author zz85 / http://www.lab4games.net/zz85/blog
  6811. */
  6812. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  6813. THREE.Camera.call( this );
  6814. this.type = 'PerspectiveCamera';
  6815. this.zoom = 1;
  6816. this.fov = fov !== undefined ? fov : 50;
  6817. this.aspect = aspect !== undefined ? aspect : 1;
  6818. this.near = near !== undefined ? near : 0.1;
  6819. this.far = far !== undefined ? far : 2000;
  6820. this.updateProjectionMatrix();
  6821. };
  6822. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  6823. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  6824. /**
  6825. * Uses Focal Length (in mm) to estimate and set FOV
  6826. * 35mm (fullframe) camera is used if frame size is not specified;
  6827. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  6828. */
  6829. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  6830. if ( frameHeight === undefined ) frameHeight = 24;
  6831. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  6832. this.updateProjectionMatrix();
  6833. };
  6834. /**
  6835. * Sets an offset in a larger frustum. This is useful for multi-window or
  6836. * multi-monitor/multi-machine setups.
  6837. *
  6838. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  6839. * the monitors are in grid like this
  6840. *
  6841. * +---+---+---+
  6842. * | A | B | C |
  6843. * +---+---+---+
  6844. * | D | E | F |
  6845. * +---+---+---+
  6846. *
  6847. * then for each monitor you would call it like this
  6848. *
  6849. * var w = 1920;
  6850. * var h = 1080;
  6851. * var fullWidth = w * 3;
  6852. * var fullHeight = h * 2;
  6853. *
  6854. * --A--
  6855. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  6856. * --B--
  6857. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  6858. * --C--
  6859. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  6860. * --D--
  6861. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  6862. * --E--
  6863. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  6864. * --F--
  6865. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  6866. *
  6867. * Note there is no reason monitors have to be the same size or in a grid.
  6868. */
  6869. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  6870. this.fullWidth = fullWidth;
  6871. this.fullHeight = fullHeight;
  6872. this.x = x;
  6873. this.y = y;
  6874. this.width = width;
  6875. this.height = height;
  6876. this.updateProjectionMatrix();
  6877. };
  6878. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  6879. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  6880. if ( this.fullWidth ) {
  6881. var aspect = this.fullWidth / this.fullHeight;
  6882. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  6883. var bottom = - top;
  6884. var left = aspect * bottom;
  6885. var right = aspect * top;
  6886. var width = Math.abs( right - left );
  6887. var height = Math.abs( top - bottom );
  6888. this.projectionMatrix.makeFrustum(
  6889. left + this.x * width / this.fullWidth,
  6890. left + ( this.x + this.width ) * width / this.fullWidth,
  6891. top - ( this.y + this.height ) * height / this.fullHeight,
  6892. top - this.y * height / this.fullHeight,
  6893. this.near,
  6894. this.far
  6895. );
  6896. } else {
  6897. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  6898. }
  6899. };
  6900. THREE.PerspectiveCamera.prototype.clone = function () {
  6901. var camera = new THREE.PerspectiveCamera();
  6902. THREE.Camera.prototype.clone.call( this, camera );
  6903. camera.zoom = this.zoom;
  6904. camera.fov = this.fov;
  6905. camera.aspect = this.aspect;
  6906. camera.near = this.near;
  6907. camera.far = this.far;
  6908. camera.projectionMatrix.copy( this.projectionMatrix );
  6909. return camera;
  6910. };
  6911. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  6912. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  6913. data.object.fov = this.fov;
  6914. data.object.aspect = this.aspect;
  6915. data.object.near = this.near;
  6916. data.object.far = this.far;
  6917. return data;
  6918. };
  6919. // File:src/lights/Light.js
  6920. /**
  6921. * @author mrdoob / http://mrdoob.com/
  6922. * @author alteredq / http://alteredqualia.com/
  6923. */
  6924. THREE.Light = function ( color ) {
  6925. THREE.Object3D.call( this );
  6926. this.type = 'Light';
  6927. this.color = new THREE.Color( color );
  6928. };
  6929. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  6930. THREE.Light.prototype.constructor = THREE.Light;
  6931. THREE.Light.prototype.clone = function ( light ) {
  6932. if ( light === undefined ) light = new THREE.Light();
  6933. THREE.Object3D.prototype.clone.call( this, light );
  6934. light.color.copy( this.color );
  6935. return light;
  6936. };
  6937. // File:src/lights/AmbientLight.js
  6938. /**
  6939. * @author mrdoob / http://mrdoob.com/
  6940. */
  6941. THREE.AmbientLight = function ( color ) {
  6942. THREE.Light.call( this, color );
  6943. this.type = 'AmbientLight';
  6944. };
  6945. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  6946. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  6947. THREE.AmbientLight.prototype.clone = function () {
  6948. var light = new THREE.AmbientLight();
  6949. THREE.Light.prototype.clone.call( this, light );
  6950. return light;
  6951. };
  6952. THREE.AmbientLight.prototype.toJSON = function ( meta ) {
  6953. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  6954. data.object.color = this.color.getHex();
  6955. return data;
  6956. };
  6957. // File:src/lights/AreaLight.js
  6958. /**
  6959. * @author MPanknin / http://www.redplant.de/
  6960. * @author alteredq / http://alteredqualia.com/
  6961. */
  6962. THREE.AreaLight = function ( color, intensity ) {
  6963. THREE.Light.call( this, color );
  6964. this.type = 'AreaLight';
  6965. this.normal = new THREE.Vector3( 0, - 1, 0 );
  6966. this.right = new THREE.Vector3( 1, 0, 0 );
  6967. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  6968. this.width = 1.0;
  6969. this.height = 1.0;
  6970. this.constantAttenuation = 1.5;
  6971. this.linearAttenuation = 0.5;
  6972. this.quadraticAttenuation = 0.1;
  6973. };
  6974. THREE.AreaLight.prototype = Object.create( THREE.Light.prototype );
  6975. THREE.AreaLight.prototype.constructor = THREE.AreaLight;
  6976. // File:src/lights/DirectionalLight.js
  6977. /**
  6978. * @author mrdoob / http://mrdoob.com/
  6979. * @author alteredq / http://alteredqualia.com/
  6980. */
  6981. THREE.DirectionalLight = function ( color, intensity ) {
  6982. THREE.Light.call( this, color );
  6983. this.type = 'DirectionalLight';
  6984. this.position.set( 0, 1, 0 );
  6985. this.target = new THREE.Object3D();
  6986. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  6987. this.castShadow = false;
  6988. this.onlyShadow = false;
  6989. //
  6990. this.shadowCameraNear = 50;
  6991. this.shadowCameraFar = 5000;
  6992. this.shadowCameraLeft = - 500;
  6993. this.shadowCameraRight = 500;
  6994. this.shadowCameraTop = 500;
  6995. this.shadowCameraBottom = - 500;
  6996. this.shadowCameraVisible = false;
  6997. this.shadowBias = 0;
  6998. this.shadowDarkness = 0.5;
  6999. this.shadowMapWidth = 512;
  7000. this.shadowMapHeight = 512;
  7001. //
  7002. this.shadowCascade = false;
  7003. this.shadowCascadeOffset = new THREE.Vector3( 0, 0, - 1000 );
  7004. this.shadowCascadeCount = 2;
  7005. this.shadowCascadeBias = [ 0, 0, 0 ];
  7006. this.shadowCascadeWidth = [ 512, 512, 512 ];
  7007. this.shadowCascadeHeight = [ 512, 512, 512 ];
  7008. this.shadowCascadeNearZ = [ - 1.000, 0.990, 0.998 ];
  7009. this.shadowCascadeFarZ = [ 0.990, 0.998, 1.000 ];
  7010. this.shadowCascadeArray = [];
  7011. //
  7012. this.shadowMap = null;
  7013. this.shadowMapSize = null;
  7014. this.shadowCamera = null;
  7015. this.shadowMatrix = null;
  7016. };
  7017. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  7018. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  7019. THREE.DirectionalLight.prototype.clone = function () {
  7020. var light = new THREE.DirectionalLight();
  7021. THREE.Light.prototype.clone.call( this, light );
  7022. light.target = this.target.clone();
  7023. light.intensity = this.intensity;
  7024. light.castShadow = this.castShadow;
  7025. light.onlyShadow = this.onlyShadow;
  7026. //
  7027. light.shadowCameraNear = this.shadowCameraNear;
  7028. light.shadowCameraFar = this.shadowCameraFar;
  7029. light.shadowCameraLeft = this.shadowCameraLeft;
  7030. light.shadowCameraRight = this.shadowCameraRight;
  7031. light.shadowCameraTop = this.shadowCameraTop;
  7032. light.shadowCameraBottom = this.shadowCameraBottom;
  7033. light.shadowCameraVisible = this.shadowCameraVisible;
  7034. light.shadowBias = this.shadowBias;
  7035. light.shadowDarkness = this.shadowDarkness;
  7036. light.shadowMapWidth = this.shadowMapWidth;
  7037. light.shadowMapHeight = this.shadowMapHeight;
  7038. //
  7039. light.shadowCascade = this.shadowCascade;
  7040. light.shadowCascadeOffset.copy( this.shadowCascadeOffset );
  7041. light.shadowCascadeCount = this.shadowCascadeCount;
  7042. light.shadowCascadeBias = this.shadowCascadeBias.slice( 0 );
  7043. light.shadowCascadeWidth = this.shadowCascadeWidth.slice( 0 );
  7044. light.shadowCascadeHeight = this.shadowCascadeHeight.slice( 0 );
  7045. light.shadowCascadeNearZ = this.shadowCascadeNearZ.slice( 0 );
  7046. light.shadowCascadeFarZ = this.shadowCascadeFarZ.slice( 0 );
  7047. return light;
  7048. };
  7049. THREE.DirectionalLight.prototype.toJSON = function ( meta ) {
  7050. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7051. data.object.color = this.color.getHex();
  7052. data.object.intensity = this.intensity;
  7053. return data;
  7054. };
  7055. // File:src/lights/HemisphereLight.js
  7056. /**
  7057. * @author alteredq / http://alteredqualia.com/
  7058. */
  7059. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  7060. THREE.Light.call( this, skyColor );
  7061. this.type = 'HemisphereLight';
  7062. this.position.set( 0, 100, 0 );
  7063. this.groundColor = new THREE.Color( groundColor );
  7064. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7065. };
  7066. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  7067. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  7068. THREE.HemisphereLight.prototype.clone = function () {
  7069. var light = new THREE.HemisphereLight();
  7070. THREE.Light.prototype.clone.call( this, light );
  7071. light.groundColor.copy( this.groundColor );
  7072. light.intensity = this.intensity;
  7073. return light;
  7074. };
  7075. THREE.HemisphereLight.prototype.toJSON = function ( meta ) {
  7076. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7077. data.object.color = this.color.getHex();
  7078. data.object.groundColor = this.groundColor.getHex();
  7079. return data;
  7080. };
  7081. // File:src/lights/PointLight.js
  7082. /**
  7083. * @author mrdoob / http://mrdoob.com/
  7084. */
  7085. THREE.PointLight = function ( color, intensity, distance, decay ) {
  7086. THREE.Light.call( this, color );
  7087. this.type = 'PointLight';
  7088. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7089. this.distance = ( distance !== undefined ) ? distance : 0;
  7090. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  7091. };
  7092. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  7093. THREE.PointLight.prototype.constructor = THREE.PointLight;
  7094. THREE.PointLight.prototype.clone = function () {
  7095. var light = new THREE.PointLight();
  7096. THREE.Light.prototype.clone.call( this, light );
  7097. light.intensity = this.intensity;
  7098. light.distance = this.distance;
  7099. light.decay = this.decay;
  7100. return light;
  7101. };
  7102. THREE.PointLight.prototype.toJSON = function ( meta ) {
  7103. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7104. data.object.color = this.color.getHex();
  7105. data.object.intensity = this.intensity;
  7106. data.object.distance = this.distance;
  7107. data.object.decay = this.decay;
  7108. return data;
  7109. };
  7110. // File:src/lights/SpotLight.js
  7111. /**
  7112. * @author alteredq / http://alteredqualia.com/
  7113. */
  7114. THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
  7115. THREE.Light.call( this, color );
  7116. this.type = 'SpotLight';
  7117. this.position.set( 0, 1, 0 );
  7118. this.target = new THREE.Object3D();
  7119. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7120. this.distance = ( distance !== undefined ) ? distance : 0;
  7121. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  7122. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  7123. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  7124. this.castShadow = false;
  7125. this.onlyShadow = false;
  7126. //
  7127. this.shadowCameraNear = 50;
  7128. this.shadowCameraFar = 5000;
  7129. this.shadowCameraFov = 50;
  7130. this.shadowCameraVisible = false;
  7131. this.shadowBias = 0;
  7132. this.shadowDarkness = 0.5;
  7133. this.shadowMapWidth = 512;
  7134. this.shadowMapHeight = 512;
  7135. //
  7136. this.shadowMap = null;
  7137. this.shadowMapSize = null;
  7138. this.shadowCamera = null;
  7139. this.shadowMatrix = null;
  7140. };
  7141. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  7142. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  7143. THREE.SpotLight.prototype.clone = function () {
  7144. var light = new THREE.SpotLight();
  7145. THREE.Light.prototype.clone.call( this, light );
  7146. light.target = this.target.clone();
  7147. light.intensity = this.intensity;
  7148. light.distance = this.distance;
  7149. light.angle = this.angle;
  7150. light.exponent = this.exponent;
  7151. light.decay = this.decay;
  7152. light.castShadow = this.castShadow;
  7153. light.onlyShadow = this.onlyShadow;
  7154. //
  7155. light.shadowCameraNear = this.shadowCameraNear;
  7156. light.shadowCameraFar = this.shadowCameraFar;
  7157. light.shadowCameraFov = this.shadowCameraFov;
  7158. light.shadowCameraVisible = this.shadowCameraVisible;
  7159. light.shadowBias = this.shadowBias;
  7160. light.shadowDarkness = this.shadowDarkness;
  7161. light.shadowMapWidth = this.shadowMapWidth;
  7162. light.shadowMapHeight = this.shadowMapHeight;
  7163. return light;
  7164. };
  7165. THREE.SpotLight.prototype.toJSON = function ( meta ) {
  7166. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7167. data.object.color = this.color.getHex();
  7168. data.object.intensity = this.intensity;
  7169. data.object.distance = this.distance;
  7170. data.object.angle = this.angle;
  7171. data.object.exponent = this.exponent;
  7172. data.object.decay = this.decay;
  7173. return data;
  7174. };
  7175. // File:src/loaders/Cache.js
  7176. /**
  7177. * @author mrdoob / http://mrdoob.com/
  7178. */
  7179. THREE.Cache = {
  7180. files: {},
  7181. add: function ( key, file ) {
  7182. // console.log( 'THREE.Cache', 'Adding key:', key );
  7183. this.files[ key ] = file;
  7184. },
  7185. get: function ( key ) {
  7186. // console.log( 'THREE.Cache', 'Checking key:', key );
  7187. return this.files[ key ];
  7188. },
  7189. remove: function ( key ) {
  7190. delete this.files[ key ];
  7191. },
  7192. clear: function () {
  7193. this.files = {}
  7194. }
  7195. };
  7196. // File:src/loaders/Loader.js
  7197. /**
  7198. * @author alteredq / http://alteredqualia.com/
  7199. */
  7200. THREE.Loader = function ( showStatus ) {
  7201. this.showStatus = showStatus;
  7202. this.statusDomElement = showStatus ? THREE.Loader.prototype.addStatusElement() : null;
  7203. this.imageLoader = new THREE.ImageLoader();
  7204. this.onLoadStart = function () {};
  7205. this.onLoadProgress = function () {};
  7206. this.onLoadComplete = function () {};
  7207. };
  7208. THREE.Loader.prototype = {
  7209. constructor: THREE.Loader,
  7210. crossOrigin: undefined,
  7211. addStatusElement: function () {
  7212. var e = document.createElement( 'div' );
  7213. e.style.position = 'absolute';
  7214. e.style.right = '0px';
  7215. e.style.top = '0px';
  7216. e.style.fontSize = '0.8em';
  7217. e.style.textAlign = 'left';
  7218. e.style.background = 'rgba(0,0,0,0.25)';
  7219. e.style.color = '#fff';
  7220. e.style.width = '120px';
  7221. e.style.padding = '0.5em 0.5em 0.5em 0.5em';
  7222. e.style.zIndex = 1000;
  7223. e.innerHTML = 'Loading ...';
  7224. return e;
  7225. },
  7226. updateProgress: function ( progress ) {
  7227. var message = 'Loaded ';
  7228. if ( progress.total ) {
  7229. message += ( 100 * progress.loaded / progress.total ).toFixed( 0 ) + '%';
  7230. } else {
  7231. message += ( progress.loaded / 1024 ).toFixed( 2 ) + ' KB';
  7232. }
  7233. this.statusDomElement.innerHTML = message;
  7234. },
  7235. extractUrlBase: function ( url ) {
  7236. var parts = url.split( '/' );
  7237. if ( parts.length === 1 ) return './';
  7238. parts.pop();
  7239. return parts.join( '/' ) + '/';
  7240. },
  7241. initMaterials: function ( materials, texturePath ) {
  7242. var array = [];
  7243. for ( var i = 0; i < materials.length; ++ i ) {
  7244. array[ i ] = this.createMaterial( materials[ i ], texturePath );
  7245. }
  7246. return array;
  7247. },
  7248. needsTangents: function ( materials ) {
  7249. for ( var i = 0, il = materials.length; i < il; i ++ ) {
  7250. var m = materials[ i ];
  7251. if ( m instanceof THREE.ShaderMaterial ) return true;
  7252. }
  7253. return false;
  7254. },
  7255. createMaterial: function ( m, texturePath ) {
  7256. var scope = this;
  7257. function nearest_pow2( n ) {
  7258. var l = Math.log( n ) / Math.LN2;
  7259. return Math.pow( 2, Math.round( l ) );
  7260. }
  7261. function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) {
  7262. var fullPath = texturePath + sourceFile;
  7263. var texture;
  7264. var loader = THREE.Loader.Handlers.get( fullPath );
  7265. if ( loader !== null ) {
  7266. texture = loader.load( fullPath );
  7267. } else {
  7268. texture = new THREE.Texture();
  7269. loader = scope.imageLoader;
  7270. loader.crossOrigin = scope.crossOrigin;
  7271. loader.load( fullPath, function ( image ) {
  7272. if ( THREE.Math.isPowerOfTwo( image.width ) === false ||
  7273. THREE.Math.isPowerOfTwo( image.height ) === false ) {
  7274. var width = nearest_pow2( image.width );
  7275. var height = nearest_pow2( image.height );
  7276. var canvas = document.createElement( 'canvas' );
  7277. canvas.width = width;
  7278. canvas.height = height;
  7279. var context = canvas.getContext( '2d' );
  7280. context.drawImage( image, 0, 0, width, height );
  7281. texture.image = canvas;
  7282. } else {
  7283. texture.image = image;
  7284. }
  7285. texture.needsUpdate = true;
  7286. } );
  7287. }
  7288. texture.sourceFile = sourceFile;
  7289. if ( repeat ) {
  7290. texture.repeat.set( repeat[ 0 ], repeat[ 1 ] );
  7291. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  7292. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  7293. }
  7294. if ( offset ) {
  7295. texture.offset.set( offset[ 0 ], offset[ 1 ] );
  7296. }
  7297. if ( wrap ) {
  7298. var wrapMap = {
  7299. 'repeat': THREE.RepeatWrapping,
  7300. 'mirror': THREE.MirroredRepeatWrapping
  7301. };
  7302. if ( wrapMap[ wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ wrap[ 0 ] ];
  7303. if ( wrapMap[ wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ wrap[ 1 ] ];
  7304. }
  7305. if ( anisotropy ) {
  7306. texture.anisotropy = anisotropy;
  7307. }
  7308. where[ name ] = texture;
  7309. }
  7310. function rgb2hex( rgb ) {
  7311. return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
  7312. }
  7313. // defaults
  7314. var mtype = 'MeshLambertMaterial';
  7315. var mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, bumpMap: null, wireframe: false };
  7316. // parameters from model file
  7317. if ( m.shading ) {
  7318. var shading = m.shading.toLowerCase();
  7319. if ( shading === 'phong' ) mtype = 'MeshPhongMaterial';
  7320. else if ( shading === 'basic' ) mtype = 'MeshBasicMaterial';
  7321. }
  7322. if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
  7323. mpars.blending = THREE[ m.blending ];
  7324. }
  7325. if ( m.transparent !== undefined ) {
  7326. mpars.transparent = m.transparent;
  7327. }
  7328. if ( m.opacity !== undefined && m.opacity < 1.0 ) {
  7329. mpars.transparent = true;
  7330. }
  7331. if ( m.depthTest !== undefined ) {
  7332. mpars.depthTest = m.depthTest;
  7333. }
  7334. if ( m.depthWrite !== undefined ) {
  7335. mpars.depthWrite = m.depthWrite;
  7336. }
  7337. if ( m.visible !== undefined ) {
  7338. mpars.visible = m.visible;
  7339. }
  7340. if ( m.flipSided !== undefined ) {
  7341. mpars.side = THREE.BackSide;
  7342. }
  7343. if ( m.doubleSided !== undefined ) {
  7344. mpars.side = THREE.DoubleSide;
  7345. }
  7346. if ( m.wireframe !== undefined ) {
  7347. mpars.wireframe = m.wireframe;
  7348. }
  7349. if ( m.vertexColors !== undefined ) {
  7350. if ( m.vertexColors === 'face' ) {
  7351. mpars.vertexColors = THREE.FaceColors;
  7352. } else if ( m.vertexColors ) {
  7353. mpars.vertexColors = THREE.VertexColors;
  7354. }
  7355. }
  7356. // colors
  7357. if ( m.colorDiffuse ) {
  7358. mpars.color = rgb2hex( m.colorDiffuse );
  7359. } else if ( m.DbgColor ) {
  7360. mpars.color = m.DbgColor;
  7361. }
  7362. if ( m.colorSpecular ) {
  7363. mpars.specular = rgb2hex( m.colorSpecular );
  7364. }
  7365. if ( m.colorEmissive ) {
  7366. mpars.emissive = rgb2hex( m.colorEmissive );
  7367. }
  7368. // modifiers
  7369. if ( m.transparency !== undefined ) {
  7370. console.warn( 'THREE.Loader: transparency has been renamed to opacity' );
  7371. m.opacity = m.transparency;
  7372. }
  7373. if ( m.opacity !== undefined ) {
  7374. mpars.opacity = m.opacity;
  7375. }
  7376. if ( m.specularCoef ) {
  7377. mpars.shininess = m.specularCoef;
  7378. }
  7379. // textures
  7380. if ( m.mapDiffuse && texturePath ) {
  7381. create_texture( mpars, 'map', m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  7382. }
  7383. if ( m.mapLight && texturePath ) {
  7384. create_texture( mpars, 'lightMap', m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  7385. }
  7386. if ( m.mapAO && texturePath ) {
  7387. create_texture( mpars, 'aoMap', m.mapAO, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  7388. }
  7389. if ( m.mapBump && texturePath ) {
  7390. create_texture( mpars, 'bumpMap', m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  7391. }
  7392. if ( m.mapNormal && texturePath ) {
  7393. create_texture( mpars, 'normalMap', m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  7394. }
  7395. if ( m.mapSpecular && texturePath ) {
  7396. create_texture( mpars, 'specularMap', m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  7397. }
  7398. if ( m.mapAlpha && texturePath ) {
  7399. create_texture( mpars, 'alphaMap', m.mapAlpha, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  7400. }
  7401. //
  7402. if ( m.mapBumpScale ) {
  7403. mpars.bumpScale = m.mapBumpScale;
  7404. }
  7405. if ( m.mapNormalFactor ) {
  7406. mpars.normalScale = new THREE.Vector2( m.mapNormalFactor, m.mapNormalFactor );
  7407. }
  7408. var material = new THREE[ mtype ]( mpars );
  7409. if ( m.DbgName !== undefined ) material.name = m.DbgName;
  7410. return material;
  7411. }
  7412. };
  7413. THREE.Loader.Handlers = {
  7414. handlers: [],
  7415. add: function ( regex, loader ) {
  7416. this.handlers.push( regex, loader );
  7417. },
  7418. get: function ( file ) {
  7419. for ( var i = 0, l = this.handlers.length; i < l; i += 2 ) {
  7420. var regex = this.handlers[ i ];
  7421. var loader = this.handlers[ i + 1 ];
  7422. if ( regex.test( file ) ) {
  7423. return loader;
  7424. }
  7425. }
  7426. return null;
  7427. }
  7428. };
  7429. // File:src/loaders/XHRLoader.js
  7430. /**
  7431. * @author mrdoob / http://mrdoob.com/
  7432. */
  7433. THREE.XHRLoader = function ( manager ) {
  7434. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7435. };
  7436. THREE.XHRLoader.prototype = {
  7437. constructor: THREE.XHRLoader,
  7438. load: function ( url, onLoad, onProgress, onError ) {
  7439. var scope = this;
  7440. var cached = THREE.Cache.get( url );
  7441. if ( cached !== undefined ) {
  7442. if ( onLoad ) onLoad( cached );
  7443. return cached;
  7444. }
  7445. var request = new XMLHttpRequest();
  7446. request.open( 'GET', url, true );
  7447. request.addEventListener( 'load', function ( event ) {
  7448. THREE.Cache.add( url, this.response );
  7449. if ( onLoad ) onLoad( this.response );
  7450. scope.manager.itemEnd( url );
  7451. }, false );
  7452. if ( onProgress !== undefined ) {
  7453. request.addEventListener( 'progress', function ( event ) {
  7454. onProgress( event );
  7455. }, false );
  7456. }
  7457. if ( onError !== undefined ) {
  7458. request.addEventListener( 'error', function ( event ) {
  7459. onError( event );
  7460. }, false );
  7461. }
  7462. if ( this.crossOrigin !== undefined ) request.crossOrigin = this.crossOrigin;
  7463. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  7464. request.send( null );
  7465. scope.manager.itemStart( url );
  7466. },
  7467. setResponseType: function ( value ) {
  7468. this.responseType = value;
  7469. },
  7470. setCrossOrigin: function ( value ) {
  7471. this.crossOrigin = value;
  7472. }
  7473. };
  7474. // File:src/loaders/ImageLoader.js
  7475. /**
  7476. * @author mrdoob / http://mrdoob.com/
  7477. */
  7478. THREE.ImageLoader = function ( manager ) {
  7479. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7480. };
  7481. THREE.ImageLoader.prototype = {
  7482. constructor: THREE.ImageLoader,
  7483. load: function ( url, onLoad, onProgress, onError ) {
  7484. var scope = this;
  7485. var cached = THREE.Cache.get( url );
  7486. if ( cached !== undefined ) {
  7487. if ( onLoad ) onLoad( cached );
  7488. return cached;
  7489. }
  7490. var image = document.createElement( 'img' );
  7491. image.addEventListener( 'load', function ( event ) {
  7492. THREE.Cache.add( url, this );
  7493. if ( onLoad ) onLoad( this );
  7494. scope.manager.itemEnd( url );
  7495. }, false );
  7496. if ( onProgress !== undefined ) {
  7497. image.addEventListener( 'progress', function ( event ) {
  7498. onProgress( event );
  7499. }, false );
  7500. }
  7501. if ( onError !== undefined ) {
  7502. image.addEventListener( 'error', function ( event ) {
  7503. onError( event );
  7504. }, false );
  7505. }
  7506. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  7507. scope.manager.itemStart( url );
  7508. image.src = url;
  7509. return image;
  7510. },
  7511. setCrossOrigin: function ( value ) {
  7512. this.crossOrigin = value;
  7513. }
  7514. };
  7515. // File:src/loaders/JSONLoader.js
  7516. /**
  7517. * @author mrdoob / http://mrdoob.com/
  7518. * @author alteredq / http://alteredqualia.com/
  7519. */
  7520. THREE.JSONLoader = function ( showStatus ) {
  7521. THREE.Loader.call( this, showStatus );
  7522. this.withCredentials = false;
  7523. };
  7524. THREE.JSONLoader.prototype = Object.create( THREE.Loader.prototype );
  7525. THREE.JSONLoader.prototype.constructor = THREE.JSONLoader;
  7526. THREE.JSONLoader.prototype.load = function ( url, callback, texturePath ) {
  7527. // todo: unify load API to for easier SceneLoader use
  7528. texturePath = texturePath && ( typeof texturePath === 'string' ) ? texturePath : this.extractUrlBase( url );
  7529. this.onLoadStart();
  7530. this.loadAjaxJSON( this, url, callback, texturePath );
  7531. };
  7532. THREE.JSONLoader.prototype.loadAjaxJSON = function ( context, url, callback, texturePath, callbackProgress ) {
  7533. var xhr = new XMLHttpRequest();
  7534. var length = 0;
  7535. xhr.onreadystatechange = function () {
  7536. if ( xhr.readyState === xhr.DONE ) {
  7537. if ( xhr.status === 200 || xhr.status === 0 ) {
  7538. if ( xhr.responseText ) {
  7539. var json = JSON.parse( xhr.responseText );
  7540. var metadata = json.metadata;
  7541. if ( metadata !== undefined ) {
  7542. if ( metadata.type === 'object' ) {
  7543. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  7544. return;
  7545. }
  7546. if ( metadata.type === 'scene' ) {
  7547. console.error( 'THREE.JSONLoader: ' + url + ' seems to be a Scene. Use THREE.SceneLoader instead.' );
  7548. return;
  7549. }
  7550. }
  7551. var result = context.parse( json, texturePath );
  7552. callback( result.geometry, result.materials );
  7553. } else {
  7554. console.error( 'THREE.JSONLoader: ' + url + ' seems to be unreachable or the file is empty.' );
  7555. }
  7556. // in context of more complex asset initialization
  7557. // do not block on single failed file
  7558. // maybe should go even one more level up
  7559. context.onLoadComplete();
  7560. } else {
  7561. console.error( 'THREE.JSONLoader: Couldn\'t load ' + url + ' (' + xhr.status + ')' );
  7562. }
  7563. } else if ( xhr.readyState === xhr.LOADING ) {
  7564. if ( callbackProgress ) {
  7565. if ( length === 0 ) {
  7566. length = xhr.getResponseHeader( 'Content-Length' );
  7567. }
  7568. callbackProgress( { total: length, loaded: xhr.responseText.length } );
  7569. }
  7570. } else if ( xhr.readyState === xhr.HEADERS_RECEIVED ) {
  7571. if ( callbackProgress !== undefined ) {
  7572. length = xhr.getResponseHeader( 'Content-Length' );
  7573. }
  7574. }
  7575. };
  7576. xhr.open( 'GET', url, true );
  7577. xhr.withCredentials = this.withCredentials;
  7578. xhr.send( null );
  7579. };
  7580. THREE.JSONLoader.prototype.parse = function ( json, texturePath ) {
  7581. var geometry = new THREE.Geometry(),
  7582. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  7583. parseModel( scale );
  7584. parseSkin();
  7585. parseMorphing( scale );
  7586. geometry.computeFaceNormals();
  7587. geometry.computeBoundingSphere();
  7588. function parseModel( scale ) {
  7589. function isBitSet( value, position ) {
  7590. return value & ( 1 << position );
  7591. }
  7592. var i, j, fi,
  7593. offset, zLength,
  7594. colorIndex, normalIndex, uvIndex,
  7595. type,
  7596. isQuad,
  7597. hasMaterial,
  7598. hasFaceVertexUv,
  7599. hasFaceNormal, hasFaceVertexNormal,
  7600. hasFaceColor, hasFaceVertexColor,
  7601. vertex, face, faceA, faceB, hex, normal,
  7602. uvLayer, uv, u, v,
  7603. faces = json.faces,
  7604. vertices = json.vertices,
  7605. normals = json.normals,
  7606. colors = json.colors,
  7607. nUvLayers = 0;
  7608. if ( json.uvs !== undefined ) {
  7609. // disregard empty arrays
  7610. for ( i = 0; i < json.uvs.length; i ++ ) {
  7611. if ( json.uvs[ i ].length ) nUvLayers ++;
  7612. }
  7613. for ( i = 0; i < nUvLayers; i ++ ) {
  7614. geometry.faceVertexUvs[ i ] = [];
  7615. }
  7616. }
  7617. offset = 0;
  7618. zLength = vertices.length;
  7619. while ( offset < zLength ) {
  7620. vertex = new THREE.Vector3();
  7621. vertex.x = vertices[ offset ++ ] * scale;
  7622. vertex.y = vertices[ offset ++ ] * scale;
  7623. vertex.z = vertices[ offset ++ ] * scale;
  7624. geometry.vertices.push( vertex );
  7625. }
  7626. offset = 0;
  7627. zLength = faces.length;
  7628. while ( offset < zLength ) {
  7629. type = faces[ offset ++ ];
  7630. isQuad = isBitSet( type, 0 );
  7631. hasMaterial = isBitSet( type, 1 );
  7632. hasFaceVertexUv = isBitSet( type, 3 );
  7633. hasFaceNormal = isBitSet( type, 4 );
  7634. hasFaceVertexNormal = isBitSet( type, 5 );
  7635. hasFaceColor = isBitSet( type, 6 );
  7636. hasFaceVertexColor = isBitSet( type, 7 );
  7637. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  7638. if ( isQuad ) {
  7639. faceA = new THREE.Face3();
  7640. faceA.a = faces[ offset ];
  7641. faceA.b = faces[ offset + 1 ];
  7642. faceA.c = faces[ offset + 3 ];
  7643. faceB = new THREE.Face3();
  7644. faceB.a = faces[ offset + 1 ];
  7645. faceB.b = faces[ offset + 2 ];
  7646. faceB.c = faces[ offset + 3 ];
  7647. offset += 4;
  7648. if ( hasMaterial ) {
  7649. offset ++;
  7650. }
  7651. // to get face <=> uv index correspondence
  7652. fi = geometry.faces.length;
  7653. if ( hasFaceVertexUv ) {
  7654. for ( i = 0; i < nUvLayers; i ++ ) {
  7655. uvLayer = json.uvs[ i ];
  7656. geometry.faceVertexUvs[ i ][ fi ] = [];
  7657. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  7658. for ( j = 0; j < 4; j ++ ) {
  7659. uvIndex = faces[ offset ++ ];
  7660. u = uvLayer[ uvIndex * 2 ];
  7661. v = uvLayer[ uvIndex * 2 + 1 ];
  7662. uv = new THREE.Vector2( u, v );
  7663. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  7664. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  7665. }
  7666. }
  7667. }
  7668. if ( hasFaceNormal ) {
  7669. normalIndex = faces[ offset ++ ] * 3;
  7670. faceA.normal.set(
  7671. normals[ normalIndex ++ ],
  7672. normals[ normalIndex ++ ],
  7673. normals[ normalIndex ]
  7674. );
  7675. faceB.normal.copy( faceA.normal );
  7676. }
  7677. if ( hasFaceVertexNormal ) {
  7678. for ( i = 0; i < 4; i ++ ) {
  7679. normalIndex = faces[ offset ++ ] * 3;
  7680. normal = new THREE.Vector3(
  7681. normals[ normalIndex ++ ],
  7682. normals[ normalIndex ++ ],
  7683. normals[ normalIndex ]
  7684. );
  7685. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  7686. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  7687. }
  7688. }
  7689. if ( hasFaceColor ) {
  7690. colorIndex = faces[ offset ++ ];
  7691. hex = colors[ colorIndex ];
  7692. faceA.color.setHex( hex );
  7693. faceB.color.setHex( hex );
  7694. }
  7695. if ( hasFaceVertexColor ) {
  7696. for ( i = 0; i < 4; i ++ ) {
  7697. colorIndex = faces[ offset ++ ];
  7698. hex = colors[ colorIndex ];
  7699. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  7700. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  7701. }
  7702. }
  7703. geometry.faces.push( faceA );
  7704. geometry.faces.push( faceB );
  7705. } else {
  7706. face = new THREE.Face3();
  7707. face.a = faces[ offset ++ ];
  7708. face.b = faces[ offset ++ ];
  7709. face.c = faces[ offset ++ ];
  7710. if ( hasMaterial ) {
  7711. offset ++;
  7712. }
  7713. // to get face <=> uv index correspondence
  7714. fi = geometry.faces.length;
  7715. if ( hasFaceVertexUv ) {
  7716. for ( i = 0; i < nUvLayers; i ++ ) {
  7717. uvLayer = json.uvs[ i ];
  7718. geometry.faceVertexUvs[ i ][ fi ] = [];
  7719. for ( j = 0; j < 3; j ++ ) {
  7720. uvIndex = faces[ offset ++ ];
  7721. u = uvLayer[ uvIndex * 2 ];
  7722. v = uvLayer[ uvIndex * 2 + 1 ];
  7723. uv = new THREE.Vector2( u, v );
  7724. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  7725. }
  7726. }
  7727. }
  7728. if ( hasFaceNormal ) {
  7729. normalIndex = faces[ offset ++ ] * 3;
  7730. face.normal.set(
  7731. normals[ normalIndex ++ ],
  7732. normals[ normalIndex ++ ],
  7733. normals[ normalIndex ]
  7734. );
  7735. }
  7736. if ( hasFaceVertexNormal ) {
  7737. for ( i = 0; i < 3; i ++ ) {
  7738. normalIndex = faces[ offset ++ ] * 3;
  7739. normal = new THREE.Vector3(
  7740. normals[ normalIndex ++ ],
  7741. normals[ normalIndex ++ ],
  7742. normals[ normalIndex ]
  7743. );
  7744. face.vertexNormals.push( normal );
  7745. }
  7746. }
  7747. if ( hasFaceColor ) {
  7748. colorIndex = faces[ offset ++ ];
  7749. face.color.setHex( colors[ colorIndex ] );
  7750. }
  7751. if ( hasFaceVertexColor ) {
  7752. for ( i = 0; i < 3; i ++ ) {
  7753. colorIndex = faces[ offset ++ ];
  7754. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  7755. }
  7756. }
  7757. geometry.faces.push( face );
  7758. }
  7759. }
  7760. }
  7761. function parseSkin() {
  7762. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  7763. if ( json.skinWeights ) {
  7764. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  7765. var x = json.skinWeights[ i ];
  7766. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  7767. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  7768. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  7769. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  7770. }
  7771. }
  7772. if ( json.skinIndices ) {
  7773. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  7774. var a = json.skinIndices[ i ];
  7775. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  7776. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  7777. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  7778. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  7779. }
  7780. }
  7781. geometry.bones = json.bones;
  7782. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  7783. console.warn( 'THREE.JSONLoader: When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  7784. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  7785. }
  7786. // could change this to json.animations[0] or remove completely
  7787. geometry.animation = json.animation;
  7788. geometry.animations = json.animations;
  7789. }
  7790. function parseMorphing( scale ) {
  7791. if ( json.morphTargets !== undefined ) {
  7792. var i, l, v, vl, dstVertices, srcVertices;
  7793. for ( i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  7794. geometry.morphTargets[ i ] = {};
  7795. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  7796. geometry.morphTargets[ i ].vertices = [];
  7797. dstVertices = geometry.morphTargets[ i ].vertices;
  7798. srcVertices = json.morphTargets [ i ].vertices;
  7799. for ( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  7800. var vertex = new THREE.Vector3();
  7801. vertex.x = srcVertices[ v ] * scale;
  7802. vertex.y = srcVertices[ v + 1 ] * scale;
  7803. vertex.z = srcVertices[ v + 2 ] * scale;
  7804. dstVertices.push( vertex );
  7805. }
  7806. }
  7807. }
  7808. if ( json.morphColors !== undefined ) {
  7809. var i, l, c, cl, dstColors, srcColors, color;
  7810. for ( i = 0, l = json.morphColors.length; i < l; i ++ ) {
  7811. geometry.morphColors[ i ] = {};
  7812. geometry.morphColors[ i ].name = json.morphColors[ i ].name;
  7813. geometry.morphColors[ i ].colors = [];
  7814. dstColors = geometry.morphColors[ i ].colors;
  7815. srcColors = json.morphColors [ i ].colors;
  7816. for ( c = 0, cl = srcColors.length; c < cl; c += 3 ) {
  7817. color = new THREE.Color( 0xffaa00 );
  7818. color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
  7819. dstColors.push( color );
  7820. }
  7821. }
  7822. }
  7823. }
  7824. if ( json.materials === undefined || json.materials.length === 0 ) {
  7825. return { geometry: geometry };
  7826. } else {
  7827. var materials = this.initMaterials( json.materials, texturePath );
  7828. if ( this.needsTangents( materials ) ) {
  7829. geometry.computeTangents();
  7830. }
  7831. return { geometry: geometry, materials: materials };
  7832. }
  7833. };
  7834. // File:src/loaders/LoadingManager.js
  7835. /**
  7836. * @author mrdoob / http://mrdoob.com/
  7837. */
  7838. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  7839. var scope = this;
  7840. var loaded = 0, total = 0;
  7841. this.onLoad = onLoad;
  7842. this.onProgress = onProgress;
  7843. this.onError = onError;
  7844. this.itemStart = function ( url ) {
  7845. total ++;
  7846. };
  7847. this.itemEnd = function ( url ) {
  7848. loaded ++;
  7849. if ( scope.onProgress !== undefined ) {
  7850. scope.onProgress( url, loaded, total );
  7851. }
  7852. if ( loaded === total && scope.onLoad !== undefined ) {
  7853. scope.onLoad();
  7854. }
  7855. };
  7856. };
  7857. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  7858. // File:src/loaders/BufferGeometryLoader.js
  7859. /**
  7860. * @author mrdoob / http://mrdoob.com/
  7861. */
  7862. THREE.BufferGeometryLoader = function ( manager ) {
  7863. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7864. };
  7865. THREE.BufferGeometryLoader.prototype = {
  7866. constructor: THREE.BufferGeometryLoader,
  7867. load: function ( url, onLoad, onProgress, onError ) {
  7868. var scope = this;
  7869. var loader = new THREE.XHRLoader( scope.manager );
  7870. loader.setCrossOrigin( this.crossOrigin );
  7871. loader.load( url, function ( text ) {
  7872. onLoad( scope.parse( JSON.parse( text ) ) );
  7873. }, onProgress, onError );
  7874. },
  7875. setCrossOrigin: function ( value ) {
  7876. this.crossOrigin = value;
  7877. },
  7878. parse: function ( json ) {
  7879. var geometry = new THREE.BufferGeometry();
  7880. var attributes = json.data.attributes;
  7881. for ( var key in attributes ) {
  7882. var attribute = attributes[ key ];
  7883. var typedArray = new self[ attribute.type ]( attribute.array );
  7884. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  7885. }
  7886. var offsets = json.data.offsets;
  7887. if ( offsets !== undefined ) {
  7888. geometry.offsets = JSON.parse( JSON.stringify( offsets ) );
  7889. }
  7890. var boundingSphere = json.data.boundingSphere;
  7891. if ( boundingSphere !== undefined ) {
  7892. var center = new THREE.Vector3();
  7893. if ( boundingSphere.center !== undefined ) {
  7894. center.fromArray( boundingSphere.center );
  7895. }
  7896. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  7897. }
  7898. return geometry;
  7899. }
  7900. };
  7901. // File:src/loaders/MaterialLoader.js
  7902. /**
  7903. * @author mrdoob / http://mrdoob.com/
  7904. */
  7905. THREE.MaterialLoader = function ( manager ) {
  7906. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7907. };
  7908. THREE.MaterialLoader.prototype = {
  7909. constructor: THREE.MaterialLoader,
  7910. load: function ( url, onLoad, onProgress, onError ) {
  7911. var scope = this;
  7912. var loader = new THREE.XHRLoader( scope.manager );
  7913. loader.setCrossOrigin( this.crossOrigin );
  7914. loader.load( url, function ( text ) {
  7915. onLoad( scope.parse( JSON.parse( text ) ) );
  7916. }, onProgress, onError );
  7917. },
  7918. setCrossOrigin: function ( value ) {
  7919. this.crossOrigin = value;
  7920. },
  7921. parse: function ( json ) {
  7922. var material = new THREE[ json.type ];
  7923. if ( json.color !== undefined ) material.color.setHex( json.color );
  7924. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  7925. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  7926. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  7927. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  7928. if ( json.attributes !== undefined ) material.attributes = json.attributes;
  7929. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  7930. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  7931. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  7932. if ( json.shading !== undefined ) material.shading = json.shading;
  7933. if ( json.blending !== undefined ) material.blending = json.blending;
  7934. if ( json.side !== undefined ) material.side = json.side;
  7935. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  7936. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  7937. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  7938. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  7939. // for PointCloudMaterial
  7940. if ( json.size !== undefined ) material.size = json.size;
  7941. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  7942. if ( json.materials !== undefined ) {
  7943. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  7944. material.materials.push( this.parse( json.materials[ i ] ) );
  7945. }
  7946. }
  7947. return material;
  7948. }
  7949. };
  7950. // File:src/loaders/ObjectLoader.js
  7951. /**
  7952. * @author mrdoob / http://mrdoob.com/
  7953. */
  7954. THREE.ObjectLoader = function ( manager ) {
  7955. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7956. this.texturePath = '';
  7957. };
  7958. THREE.ObjectLoader.prototype = {
  7959. constructor: THREE.ObjectLoader,
  7960. load: function ( url, onLoad, onProgress, onError ) {
  7961. if ( this.texturePath === '' ) {
  7962. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  7963. }
  7964. var scope = this;
  7965. var loader = new THREE.XHRLoader( scope.manager );
  7966. loader.setCrossOrigin( this.crossOrigin );
  7967. loader.load( url, function ( text ) {
  7968. scope.parse( JSON.parse( text ), onLoad );
  7969. }, onProgress, onError );
  7970. },
  7971. setTexturePath: function ( value ) {
  7972. this.texturePath = value;
  7973. },
  7974. setCrossOrigin: function ( value ) {
  7975. this.crossOrigin = value;
  7976. },
  7977. parse: function ( json, onLoad ) {
  7978. var geometries = this.parseGeometries( json.geometries );
  7979. var images = this.parseImages( json.images, function () {
  7980. if ( onLoad !== undefined ) onLoad( object );
  7981. } );
  7982. var textures = this.parseTextures( json.textures, images );
  7983. var materials = this.parseMaterials( json.materials, textures );
  7984. var object = this.parseObject( json.object, geometries, materials );
  7985. if ( json.images === undefined || json.images.length === 0 ) {
  7986. if ( onLoad !== undefined ) onLoad( object );
  7987. }
  7988. return object;
  7989. },
  7990. parseGeometries: function ( json ) {
  7991. var geometries = {};
  7992. if ( json !== undefined ) {
  7993. var geometryLoader = new THREE.JSONLoader();
  7994. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  7995. for ( var i = 0, l = json.length; i < l; i ++ ) {
  7996. var geometry;
  7997. var data = json[ i ];
  7998. switch ( data.type ) {
  7999. case 'PlaneGeometry':
  8000. case 'PlaneBufferGeometry':
  8001. geometry = new THREE[ data.type ](
  8002. data.width,
  8003. data.height,
  8004. data.widthSegments,
  8005. data.heightSegments
  8006. );
  8007. break;
  8008. case 'BoxGeometry':
  8009. case 'CubeGeometry': // backwards compatible
  8010. geometry = new THREE.BoxGeometry(
  8011. data.width,
  8012. data.height,
  8013. data.depth,
  8014. data.widthSegments,
  8015. data.heightSegments,
  8016. data.depthSegments
  8017. );
  8018. break;
  8019. case 'CircleGeometry':
  8020. geometry = new THREE.CircleGeometry(
  8021. data.radius,
  8022. data.segments
  8023. );
  8024. break;
  8025. case 'CylinderGeometry':
  8026. geometry = new THREE.CylinderGeometry(
  8027. data.radiusTop,
  8028. data.radiusBottom,
  8029. data.height,
  8030. data.radialSegments,
  8031. data.heightSegments,
  8032. data.openEnded
  8033. );
  8034. break;
  8035. case 'SphereGeometry':
  8036. geometry = new THREE.SphereGeometry(
  8037. data.radius,
  8038. data.widthSegments,
  8039. data.heightSegments,
  8040. data.phiStart,
  8041. data.phiLength,
  8042. data.thetaStart,
  8043. data.thetaLength
  8044. );
  8045. break;
  8046. case 'IcosahedronGeometry':
  8047. geometry = new THREE.IcosahedronGeometry(
  8048. data.radius,
  8049. data.detail
  8050. );
  8051. break;
  8052. case 'TorusGeometry':
  8053. geometry = new THREE.TorusGeometry(
  8054. data.radius,
  8055. data.tube,
  8056. data.radialSegments,
  8057. data.tubularSegments,
  8058. data.arc
  8059. );
  8060. break;
  8061. case 'TorusKnotGeometry':
  8062. geometry = new THREE.TorusKnotGeometry(
  8063. data.radius,
  8064. data.tube,
  8065. data.radialSegments,
  8066. data.tubularSegments,
  8067. data.p,
  8068. data.q,
  8069. data.heightScale
  8070. );
  8071. break;
  8072. case 'BufferGeometry':
  8073. geometry = bufferGeometryLoader.parse( data );
  8074. break;
  8075. case 'Geometry':
  8076. geometry = geometryLoader.parse( data.data ).geometry;
  8077. break;
  8078. case 'TextGeometry':
  8079. geometry = new THREE.TextGeometry(
  8080. data.text,
  8081. data.data
  8082. );
  8083. break;
  8084. }
  8085. geometry.uuid = data.uuid;
  8086. if ( data.name !== undefined ) geometry.name = data.name;
  8087. geometries[ data.uuid ] = geometry;
  8088. }
  8089. }
  8090. return geometries;
  8091. },
  8092. parseMaterials: function ( json, textures ) {
  8093. var materials = {};
  8094. if ( json !== undefined ) {
  8095. var getTexture = function ( name ) {
  8096. if ( textures[ name ] === undefined ) {
  8097. console.warn( 'THREE.ObjectLoader: Undefined texture', name );
  8098. }
  8099. return textures[ name ];
  8100. };
  8101. var loader = new THREE.MaterialLoader();
  8102. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8103. var data = json[ i ];
  8104. var material = loader.parse( data );
  8105. material.uuid = data.uuid;
  8106. if ( data.depthTest !== undefined ) material.depthTest = data.depthTest;
  8107. if ( data.depthWrite !== undefined ) material.depthWrite = data.depthWrite;
  8108. if ( data.name !== undefined ) material.name = data.name;
  8109. if ( data.map !== undefined ) material.map = getTexture( data.map );
  8110. if ( data.alphaMap !== undefined ) {
  8111. material.alphaMap = getTexture( data.alphaMap );
  8112. material.transparent = true;
  8113. }
  8114. if ( data.bumpMap !== undefined ) material.bumpMap = getTexture( data.bumpMap );
  8115. if ( data.bumpScale !== undefined ) material.bumpScale = data.bumpScale;
  8116. if ( data.normalMap !== undefined ) material.normalMap = getTexture( data.normalMap );
  8117. if ( data.normalScale ) material.normalScale = new THREE.Vector2( data.normalScale, data.normalScale );
  8118. if ( data.specularMap !== undefined ) material.specularMap = getTexture( data.specularMap );
  8119. if ( data.envMap !== undefined ) {
  8120. material.envMap = getTexture( data.envMap );
  8121. material.combine = THREE.MultiplyOperation;
  8122. }
  8123. if ( data.reflectivity ) material.reflectivity = data.reflectivity;
  8124. if ( data.lightMap !== undefined ) material.lightMap = getTexture( data.lightMap );
  8125. if ( data.lightMapIntensity !== undefined ) material.lightMapIntensity = data.lightMapIntensity;
  8126. if ( data.aoMap !== undefined ) material.aoMap = getTexture( data.aoMap );
  8127. if ( data.aoMapIntensity !== undefined ) material.aoMapIntensity = data.aoMapIntensity;
  8128. materials[ data.uuid ] = material;
  8129. }
  8130. }
  8131. return materials;
  8132. },
  8133. parseImages: function ( json, onLoad ) {
  8134. var scope = this;
  8135. var images = {};
  8136. if ( json !== undefined && json.length > 0 ) {
  8137. var manager = new THREE.LoadingManager( onLoad );
  8138. var loader = new THREE.ImageLoader( manager );
  8139. loader.setCrossOrigin( this.crossOrigin );
  8140. var loadImage = function ( url ) {
  8141. scope.manager.itemStart( url );
  8142. return loader.load( url, function () {
  8143. scope.manager.itemEnd( url );
  8144. } );
  8145. };
  8146. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8147. var image = json[ i ];
  8148. images[ image.uuid ] = loadImage( image.url );
  8149. }
  8150. }
  8151. return images;
  8152. },
  8153. parseTextures: function ( json, images ) {
  8154. function parseConstant( value ) {
  8155. if ( typeof( value ) === 'number' ) return value;
  8156. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  8157. return THREE[ value ];
  8158. }
  8159. var textures = {};
  8160. if ( json !== undefined ) {
  8161. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8162. var data = json[ i ];
  8163. if ( data.image === undefined ) {
  8164. console.warn( 'THREE.ObjectLoader: No "image" speficied for', data.uuid );
  8165. }
  8166. if ( images[ data.image ] === undefined ) {
  8167. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  8168. }
  8169. var texture = new THREE.Texture( images[ data.image ] );
  8170. texture.needsUpdate = true;
  8171. texture.uuid = data.uuid;
  8172. if ( data.name !== undefined ) texture.name = data.name;
  8173. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  8174. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  8175. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  8176. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  8177. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  8178. if ( Array.isArray( data.wrap ) ) {
  8179. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  8180. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  8181. }
  8182. textures[ data.uuid ] = texture;
  8183. }
  8184. }
  8185. return textures;
  8186. },
  8187. parseObject: function () {
  8188. var matrix = new THREE.Matrix4();
  8189. return function ( data, geometries, materials ) {
  8190. var object;
  8191. var getGeometry = function ( name ) {
  8192. if ( geometries[ name ] === undefined ) {
  8193. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  8194. }
  8195. return geometries[ name ];
  8196. };
  8197. var getMaterial = function ( name ) {
  8198. if ( materials[ name ] === undefined ) {
  8199. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  8200. }
  8201. return materials[ name ];
  8202. };
  8203. switch ( data.type ) {
  8204. case 'Scene':
  8205. object = new THREE.Scene();
  8206. break;
  8207. case 'PerspectiveCamera':
  8208. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  8209. break;
  8210. case 'OrthographicCamera':
  8211. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  8212. break;
  8213. case 'AmbientLight':
  8214. object = new THREE.AmbientLight( data.color );
  8215. break;
  8216. case 'DirectionalLight':
  8217. object = new THREE.DirectionalLight( data.color, data.intensity );
  8218. break;
  8219. case 'PointLight':
  8220. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  8221. break;
  8222. case 'SpotLight':
  8223. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
  8224. break;
  8225. case 'HemisphereLight':
  8226. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  8227. break;
  8228. case 'Mesh':
  8229. object = new THREE.Mesh( getGeometry( data.geometry ), getMaterial( data.material ) );
  8230. break;
  8231. case 'Line':
  8232. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  8233. break;
  8234. case 'PointCloud':
  8235. object = new THREE.PointCloud( getGeometry( data.geometry ), getMaterial( data.material ) );
  8236. break;
  8237. case 'Sprite':
  8238. object = new THREE.Sprite( getMaterial( data.material ) );
  8239. break;
  8240. case 'Group':
  8241. object = new THREE.Group();
  8242. break;
  8243. default:
  8244. object = new THREE.Object3D();
  8245. }
  8246. object.uuid = data.uuid;
  8247. if ( data.name !== undefined ) object.name = data.name;
  8248. if ( data.matrix !== undefined ) {
  8249. matrix.fromArray( data.matrix );
  8250. matrix.decompose( object.position, object.quaternion, object.scale );
  8251. } else {
  8252. if ( data.position !== undefined ) object.position.fromArray( data.position );
  8253. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  8254. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  8255. }
  8256. if ( data.visible !== undefined ) object.visible = data.visible;
  8257. if ( data.userData !== undefined ) object.userData = data.userData;
  8258. if ( data.children !== undefined ) {
  8259. for ( var child in data.children ) {
  8260. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  8261. }
  8262. }
  8263. return object;
  8264. }
  8265. }()
  8266. };
  8267. // File:src/loaders/TextureLoader.js
  8268. /**
  8269. * @author mrdoob / http://mrdoob.com/
  8270. */
  8271. THREE.TextureLoader = function ( manager ) {
  8272. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8273. };
  8274. THREE.TextureLoader.prototype = {
  8275. constructor: THREE.TextureLoader,
  8276. load: function ( url, onLoad, onProgress, onError ) {
  8277. var scope = this;
  8278. var loader = new THREE.ImageLoader( scope.manager );
  8279. loader.setCrossOrigin( this.crossOrigin );
  8280. loader.load( url, function ( image ) {
  8281. var texture = new THREE.Texture( image );
  8282. texture.needsUpdate = true;
  8283. if ( onLoad !== undefined ) {
  8284. onLoad( texture );
  8285. }
  8286. }, onProgress, onError );
  8287. },
  8288. setCrossOrigin: function ( value ) {
  8289. this.crossOrigin = value;
  8290. }
  8291. };
  8292. // File:src/loaders/BinaryTextureLoader.js
  8293. /**
  8294. * @author Nikos M. / https://github.com/foo123/
  8295. *
  8296. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  8297. */
  8298. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function () {
  8299. // override in sub classes
  8300. this._parser = null;
  8301. };
  8302. THREE.BinaryTextureLoader.prototype = {
  8303. constructor: THREE.BinaryTextureLoader,
  8304. load: function ( url, onLoad, onProgress, onError ) {
  8305. var scope = this;
  8306. var texture = new THREE.DataTexture( );
  8307. var loader = new THREE.XHRLoader();
  8308. loader.setResponseType( 'arraybuffer' );
  8309. loader.load( url, function ( buffer ) {
  8310. var texData = scope._parser( buffer );
  8311. if ( !texData ) return;
  8312. if ( undefined !== texData.image ) {
  8313. texture.image = texData.image;
  8314. } else if ( undefined !== texData.data ) {
  8315. texture.image.width = texData.width;
  8316. texture.image.height = texData.height;
  8317. texture.image.data = texData.data;
  8318. }
  8319. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  8320. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  8321. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  8322. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  8323. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  8324. if ( undefined !== texData.format ) {
  8325. texture.format = texData.format;
  8326. }
  8327. if ( undefined !== texData.type ) {
  8328. texture.type = texData.type;
  8329. }
  8330. if ( undefined !== texData.mipmaps ) {
  8331. texture.mipmaps = texData.mipmaps;
  8332. }
  8333. if ( 1 === texData.mipmapCount ) {
  8334. texture.minFilter = THREE.LinearFilter;
  8335. }
  8336. texture.needsUpdate = true;
  8337. if ( onLoad ) onLoad( texture, texData );
  8338. }, onProgress, onError );
  8339. return texture;
  8340. }
  8341. };
  8342. // File:src/loaders/CompressedTextureLoader.js
  8343. /**
  8344. * @author mrdoob / http://mrdoob.com/
  8345. *
  8346. * Abstract Base class to block based textures loader (dds, pvr, ...)
  8347. */
  8348. THREE.CompressedTextureLoader = function () {
  8349. // override in sub classes
  8350. this._parser = null;
  8351. };
  8352. THREE.CompressedTextureLoader.prototype = {
  8353. constructor: THREE.CompressedTextureLoader,
  8354. load: function ( url, onLoad, onError ) {
  8355. var scope = this;
  8356. var images = [];
  8357. var texture = new THREE.CompressedTexture();
  8358. texture.image = images;
  8359. var loader = new THREE.XHRLoader();
  8360. loader.setResponseType( 'arraybuffer' );
  8361. if ( Array.isArray( url ) ) {
  8362. var loaded = 0;
  8363. var loadTexture = function ( i ) {
  8364. loader.load( url[ i ], function ( buffer ) {
  8365. var texDatas = scope._parser( buffer, true );
  8366. images[ i ] = {
  8367. width: texDatas.width,
  8368. height: texDatas.height,
  8369. format: texDatas.format,
  8370. mipmaps: texDatas.mipmaps
  8371. };
  8372. loaded += 1;
  8373. if ( loaded === 6 ) {
  8374. if (texDatas.mipmapCount === 1)
  8375. texture.minFilter = THREE.LinearFilter;
  8376. texture.format = texDatas.format;
  8377. texture.needsUpdate = true;
  8378. if ( onLoad ) onLoad( texture );
  8379. }
  8380. } );
  8381. };
  8382. for ( var i = 0, il = url.length; i < il; ++ i ) {
  8383. loadTexture( i );
  8384. }
  8385. } else {
  8386. // compressed cubemap texture stored in a single DDS file
  8387. loader.load( url, function ( buffer ) {
  8388. var texDatas = scope._parser( buffer, true );
  8389. if ( texDatas.isCubemap ) {
  8390. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  8391. for ( var f = 0; f < faces; f ++ ) {
  8392. images[ f ] = { mipmaps : [] };
  8393. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  8394. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  8395. images[ f ].format = texDatas.format;
  8396. images[ f ].width = texDatas.width;
  8397. images[ f ].height = texDatas.height;
  8398. }
  8399. }
  8400. } else {
  8401. texture.image.width = texDatas.width;
  8402. texture.image.height = texDatas.height;
  8403. texture.mipmaps = texDatas.mipmaps;
  8404. }
  8405. if ( texDatas.mipmapCount === 1 ) {
  8406. texture.minFilter = THREE.LinearFilter;
  8407. }
  8408. texture.format = texDatas.format;
  8409. texture.needsUpdate = true;
  8410. if ( onLoad ) onLoad( texture );
  8411. } );
  8412. }
  8413. return texture;
  8414. }
  8415. };
  8416. // File:src/materials/Material.js
  8417. /**
  8418. * @author mrdoob / http://mrdoob.com/
  8419. * @author alteredq / http://alteredqualia.com/
  8420. */
  8421. THREE.Material = function () {
  8422. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  8423. this.uuid = THREE.Math.generateUUID();
  8424. this.name = '';
  8425. this.type = 'Material';
  8426. this.side = THREE.FrontSide;
  8427. this.opacity = 1;
  8428. this.transparent = false;
  8429. this.blending = THREE.NormalBlending;
  8430. this.blendSrc = THREE.SrcAlphaFactor;
  8431. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  8432. this.blendEquation = THREE.AddEquation;
  8433. this.blendSrcAlpha = null;
  8434. this.blendDstAlpha = null;
  8435. this.blendEquationAlpha = null;
  8436. this.depthFunc = THREE.LessEqualDepth;
  8437. this.depthTest = true;
  8438. this.depthWrite = true;
  8439. this.colorWrite = true;
  8440. this.polygonOffset = false;
  8441. this.polygonOffsetFactor = 0;
  8442. this.polygonOffsetUnits = 0;
  8443. this.alphaTest = 0;
  8444. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  8445. this.visible = true;
  8446. this._needsUpdate = true;
  8447. };
  8448. THREE.Material.prototype = {
  8449. constructor: THREE.Material,
  8450. get needsUpdate () {
  8451. return this._needsUpdate;
  8452. },
  8453. set needsUpdate ( value ) {
  8454. if ( value === true ) this.update();
  8455. this._needsUpdate = value;
  8456. },
  8457. setValues: function ( values ) {
  8458. if ( values === undefined ) return;
  8459. for ( var key in values ) {
  8460. var newValue = values[ key ];
  8461. if ( newValue === undefined ) {
  8462. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  8463. continue;
  8464. }
  8465. if ( key in this ) {
  8466. var currentValue = this[ key ];
  8467. if ( currentValue instanceof THREE.Color ) {
  8468. currentValue.set( newValue );
  8469. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  8470. currentValue.copy( newValue );
  8471. } else if ( key === 'overdraw' ) {
  8472. // ensure overdraw is backwards-compatable with legacy boolean type
  8473. this[ key ] = Number( newValue );
  8474. } else {
  8475. this[ key ] = newValue;
  8476. }
  8477. }
  8478. }
  8479. },
  8480. toJSON: function ( meta ) {
  8481. var data = {
  8482. metadata: {
  8483. version: 4.4,
  8484. type: 'Material',
  8485. generator: 'Material.toJSON'
  8486. }
  8487. };
  8488. // standard Material serialization
  8489. data.uuid = this.uuid;
  8490. data.type = this.type;
  8491. if ( this.name !== '' ) data.name = this.name;
  8492. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  8493. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  8494. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  8495. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  8496. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  8497. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  8498. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  8499. if ( this.bumpMap instanceof THREE.Texture ) {
  8500. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  8501. data.bumpScale = this.bumpScale;
  8502. }
  8503. if ( this.normalMap instanceof THREE.Texture ) {
  8504. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  8505. data.normalScale = this.normalScale; // Removed for now, causes issue in editor ui.js
  8506. }
  8507. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  8508. if ( this.envMap instanceof THREE.Texture ) {
  8509. data.envMap = this.envMap.toJSON( meta ).uuid;
  8510. data.reflectivity = this.reflectivity; // Scale behind envMap
  8511. }
  8512. if ( this.size !== undefined ) data.size = this.size;
  8513. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  8514. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  8515. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  8516. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  8517. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  8518. if ( this.opacity < 1 ) data.opacity = this.opacity;
  8519. if ( this.transparent === true ) data.transparent = this.transparent;
  8520. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  8521. return data;
  8522. },
  8523. clone: function ( material ) {
  8524. if ( material === undefined ) material = new THREE.Material();
  8525. material.name = this.name;
  8526. material.side = this.side;
  8527. material.opacity = this.opacity;
  8528. material.transparent = this.transparent;
  8529. material.blending = this.blending;
  8530. material.blendSrc = this.blendSrc;
  8531. material.blendDst = this.blendDst;
  8532. material.blendEquation = this.blendEquation;
  8533. material.blendSrcAlpha = this.blendSrcAlpha;
  8534. material.blendDstAlpha = this.blendDstAlpha;
  8535. material.blendEquationAlpha = this.blendEquationAlpha;
  8536. material.depthFunc = this.depthFunc;
  8537. material.depthTest = this.depthTest;
  8538. material.depthWrite = this.depthWrite;
  8539. material.polygonOffset = this.polygonOffset;
  8540. material.polygonOffsetFactor = this.polygonOffsetFactor;
  8541. material.polygonOffsetUnits = this.polygonOffsetUnits;
  8542. material.alphaTest = this.alphaTest;
  8543. material.overdraw = this.overdraw;
  8544. material.visible = this.visible;
  8545. return material;
  8546. },
  8547. update: function () {
  8548. this.dispatchEvent( { type: 'update' } );
  8549. },
  8550. dispose: function () {
  8551. this.dispatchEvent( { type: 'dispose' } );
  8552. }
  8553. };
  8554. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  8555. THREE.MaterialIdCount = 0;
  8556. // File:src/materials/LineBasicMaterial.js
  8557. /**
  8558. * @author mrdoob / http://mrdoob.com/
  8559. * @author alteredq / http://alteredqualia.com/
  8560. *
  8561. * parameters = {
  8562. * color: <hex>,
  8563. * opacity: <float>,
  8564. *
  8565. * blending: THREE.NormalBlending,
  8566. * depthTest: <bool>,
  8567. * depthWrite: <bool>,
  8568. *
  8569. * linewidth: <float>,
  8570. * linecap: "round",
  8571. * linejoin: "round",
  8572. *
  8573. * vertexColors: <bool>
  8574. *
  8575. * fog: <bool>
  8576. * }
  8577. */
  8578. THREE.LineBasicMaterial = function ( parameters ) {
  8579. THREE.Material.call( this );
  8580. this.type = 'LineBasicMaterial';
  8581. this.color = new THREE.Color( 0xffffff );
  8582. this.linewidth = 1;
  8583. this.linecap = 'round';
  8584. this.linejoin = 'round';
  8585. this.vertexColors = THREE.NoColors;
  8586. this.fog = true;
  8587. this.setValues( parameters );
  8588. };
  8589. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  8590. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  8591. THREE.LineBasicMaterial.prototype.clone = function () {
  8592. var material = new THREE.LineBasicMaterial();
  8593. THREE.Material.prototype.clone.call( this, material );
  8594. material.color.copy( this.color );
  8595. material.linewidth = this.linewidth;
  8596. material.linecap = this.linecap;
  8597. material.linejoin = this.linejoin;
  8598. material.vertexColors = this.vertexColors;
  8599. material.fog = this.fog;
  8600. return material;
  8601. };
  8602. // File:src/materials/LineDashedMaterial.js
  8603. /**
  8604. * @author alteredq / http://alteredqualia.com/
  8605. *
  8606. * parameters = {
  8607. * color: <hex>,
  8608. * opacity: <float>,
  8609. *
  8610. * blending: THREE.NormalBlending,
  8611. * depthTest: <bool>,
  8612. * depthWrite: <bool>,
  8613. *
  8614. * linewidth: <float>,
  8615. *
  8616. * scale: <float>,
  8617. * dashSize: <float>,
  8618. * gapSize: <float>,
  8619. *
  8620. * vertexColors: <bool>
  8621. *
  8622. * fog: <bool>
  8623. * }
  8624. */
  8625. THREE.LineDashedMaterial = function ( parameters ) {
  8626. THREE.Material.call( this );
  8627. this.type = 'LineDashedMaterial';
  8628. this.color = new THREE.Color( 0xffffff );
  8629. this.linewidth = 1;
  8630. this.scale = 1;
  8631. this.dashSize = 3;
  8632. this.gapSize = 1;
  8633. this.vertexColors = false;
  8634. this.fog = true;
  8635. this.setValues( parameters );
  8636. };
  8637. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  8638. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  8639. THREE.LineDashedMaterial.prototype.clone = function () {
  8640. var material = new THREE.LineDashedMaterial();
  8641. THREE.Material.prototype.clone.call( this, material );
  8642. material.color.copy( this.color );
  8643. material.linewidth = this.linewidth;
  8644. material.scale = this.scale;
  8645. material.dashSize = this.dashSize;
  8646. material.gapSize = this.gapSize;
  8647. material.vertexColors = this.vertexColors;
  8648. material.fog = this.fog;
  8649. return material;
  8650. };
  8651. // File:src/materials/MeshBasicMaterial.js
  8652. /**
  8653. * @author mrdoob / http://mrdoob.com/
  8654. * @author alteredq / http://alteredqualia.com/
  8655. *
  8656. * parameters = {
  8657. * color: <hex>,
  8658. * opacity: <float>,
  8659. * map: new THREE.Texture( <Image> ),
  8660. *
  8661. * specularMap: new THREE.Texture( <Image> ),
  8662. *
  8663. * alphaMap: new THREE.Texture( <Image> ),
  8664. *
  8665. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  8666. * combine: THREE.Multiply,
  8667. * reflectivity: <float>,
  8668. * refractionRatio: <float>,
  8669. *
  8670. * shading: THREE.SmoothShading,
  8671. * blending: THREE.NormalBlending,
  8672. * depthTest: <bool>,
  8673. * depthWrite: <bool>,
  8674. *
  8675. * wireframe: <boolean>,
  8676. * wireframeLinewidth: <float>,
  8677. *
  8678. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  8679. *
  8680. * skinning: <bool>,
  8681. * morphTargets: <bool>,
  8682. *
  8683. * fog: <bool>
  8684. * }
  8685. */
  8686. THREE.MeshBasicMaterial = function ( parameters ) {
  8687. THREE.Material.call( this );
  8688. this.type = 'MeshBasicMaterial';
  8689. this.color = new THREE.Color( 0xffffff ); // emissive
  8690. this.map = null;
  8691. this.specularMap = null;
  8692. this.alphaMap = null;
  8693. this.envMap = null;
  8694. this.combine = THREE.MultiplyOperation;
  8695. this.reflectivity = 1;
  8696. this.refractionRatio = 0.98;
  8697. this.fog = true;
  8698. this.shading = THREE.SmoothShading;
  8699. this.wireframe = false;
  8700. this.wireframeLinewidth = 1;
  8701. this.wireframeLinecap = 'round';
  8702. this.wireframeLinejoin = 'round';
  8703. this.vertexColors = THREE.NoColors;
  8704. this.skinning = false;
  8705. this.morphTargets = false;
  8706. this.setValues( parameters );
  8707. };
  8708. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  8709. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  8710. THREE.MeshBasicMaterial.prototype.clone = function () {
  8711. var material = new THREE.MeshBasicMaterial();
  8712. THREE.Material.prototype.clone.call( this, material );
  8713. material.color.copy( this.color );
  8714. material.map = this.map;
  8715. material.specularMap = this.specularMap;
  8716. material.alphaMap = this.alphaMap;
  8717. material.envMap = this.envMap;
  8718. material.combine = this.combine;
  8719. material.reflectivity = this.reflectivity;
  8720. material.refractionRatio = this.refractionRatio;
  8721. material.fog = this.fog;
  8722. material.shading = this.shading;
  8723. material.wireframe = this.wireframe;
  8724. material.wireframeLinewidth = this.wireframeLinewidth;
  8725. material.wireframeLinecap = this.wireframeLinecap;
  8726. material.wireframeLinejoin = this.wireframeLinejoin;
  8727. material.vertexColors = this.vertexColors;
  8728. material.skinning = this.skinning;
  8729. material.morphTargets = this.morphTargets;
  8730. return material;
  8731. };
  8732. // File:src/materials/MeshLambertMaterial.js
  8733. /**
  8734. * @author mrdoob / http://mrdoob.com/
  8735. * @author alteredq / http://alteredqualia.com/
  8736. *
  8737. * parameters = {
  8738. * color: <hex>,
  8739. * emissive: <hex>,
  8740. * opacity: <float>,
  8741. *
  8742. * map: new THREE.Texture( <Image> ),
  8743. *
  8744. * specularMap: new THREE.Texture( <Image> ),
  8745. *
  8746. * alphaMap: new THREE.Texture( <Image> ),
  8747. *
  8748. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  8749. * combine: THREE.Multiply,
  8750. * reflectivity: <float>,
  8751. * refractionRatio: <float>,
  8752. *
  8753. * shading: THREE.SmoothShading,
  8754. * blending: THREE.NormalBlending,
  8755. * depthTest: <bool>,
  8756. * depthWrite: <bool>,
  8757. *
  8758. * wireframe: <boolean>,
  8759. * wireframeLinewidth: <float>,
  8760. *
  8761. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  8762. *
  8763. * skinning: <bool>,
  8764. * morphTargets: <bool>,
  8765. * morphNormals: <bool>,
  8766. *
  8767. * fog: <bool>
  8768. * }
  8769. */
  8770. THREE.MeshLambertMaterial = function ( parameters ) {
  8771. THREE.Material.call( this );
  8772. this.type = 'MeshLambertMaterial';
  8773. this.color = new THREE.Color( 0xffffff ); // diffuse
  8774. this.emissive = new THREE.Color( 0x000000 );
  8775. this.map = null;
  8776. this.specularMap = null;
  8777. this.alphaMap = null;
  8778. this.envMap = null;
  8779. this.combine = THREE.MultiplyOperation;
  8780. this.reflectivity = 1;
  8781. this.refractionRatio = 0.98;
  8782. this.fog = true;
  8783. this.shading = THREE.SmoothShading;
  8784. this.wireframe = false;
  8785. this.wireframeLinewidth = 1;
  8786. this.wireframeLinecap = 'round';
  8787. this.wireframeLinejoin = 'round';
  8788. this.vertexColors = THREE.NoColors;
  8789. this.skinning = false;
  8790. this.morphTargets = false;
  8791. this.morphNormals = false;
  8792. this.setValues( parameters );
  8793. };
  8794. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  8795. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  8796. THREE.MeshLambertMaterial.prototype.clone = function () {
  8797. var material = new THREE.MeshLambertMaterial();
  8798. THREE.Material.prototype.clone.call( this, material );
  8799. material.color.copy( this.color );
  8800. material.emissive.copy( this.emissive );
  8801. material.map = this.map;
  8802. material.specularMap = this.specularMap;
  8803. material.alphaMap = this.alphaMap;
  8804. material.envMap = this.envMap;
  8805. material.combine = this.combine;
  8806. material.reflectivity = this.reflectivity;
  8807. material.refractionRatio = this.refractionRatio;
  8808. material.fog = this.fog;
  8809. material.shading = this.shading;
  8810. material.wireframe = this.wireframe;
  8811. material.wireframeLinewidth = this.wireframeLinewidth;
  8812. material.wireframeLinecap = this.wireframeLinecap;
  8813. material.wireframeLinejoin = this.wireframeLinejoin;
  8814. material.vertexColors = this.vertexColors;
  8815. material.skinning = this.skinning;
  8816. material.morphTargets = this.morphTargets;
  8817. material.morphNormals = this.morphNormals;
  8818. return material;
  8819. };
  8820. // File:src/materials/MeshPhongMaterial.js
  8821. /**
  8822. * @author mrdoob / http://mrdoob.com/
  8823. * @author alteredq / http://alteredqualia.com/
  8824. *
  8825. * parameters = {
  8826. * color: <hex>,
  8827. * emissive: <hex>,
  8828. * specular: <hex>,
  8829. * shininess: <float>,
  8830. * opacity: <float>,
  8831. *
  8832. * map: new THREE.Texture( <Image> ),
  8833. *
  8834. * lightMap: new THREE.Texture( <Image> ),
  8835. * lightMapIntensity: <float>
  8836. *
  8837. * aoMap: new THREE.Texture( <Image> ),
  8838. * aoMapIntensity: <float>
  8839. *
  8840. * bumpMap: new THREE.Texture( <Image> ),
  8841. * bumpScale: <float>,
  8842. *
  8843. * normalMap: new THREE.Texture( <Image> ),
  8844. * normalScale: <Vector2>,
  8845. *
  8846. * specularMap: new THREE.Texture( <Image> ),
  8847. *
  8848. * alphaMap: new THREE.Texture( <Image> ),
  8849. *
  8850. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  8851. * combine: THREE.Multiply,
  8852. * reflectivity: <float>,
  8853. * refractionRatio: <float>,
  8854. *
  8855. * shading: THREE.SmoothShading,
  8856. * blending: THREE.NormalBlending,
  8857. * depthTest: <bool>,
  8858. * depthWrite: <bool>,
  8859. *
  8860. * wireframe: <boolean>,
  8861. * wireframeLinewidth: <float>,
  8862. *
  8863. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  8864. *
  8865. * skinning: <bool>,
  8866. * morphTargets: <bool>,
  8867. * morphNormals: <bool>,
  8868. *
  8869. * fog: <bool>
  8870. * }
  8871. */
  8872. THREE.MeshPhongMaterial = function ( parameters ) {
  8873. THREE.Material.call( this );
  8874. this.type = 'MeshPhongMaterial';
  8875. this.color = new THREE.Color( 0xffffff ); // diffuse
  8876. this.emissive = new THREE.Color( 0x000000 );
  8877. this.specular = new THREE.Color( 0x111111 );
  8878. this.shininess = 30;
  8879. this.metal = false;
  8880. this.map = null;
  8881. this.lightMap = null;
  8882. this.lightMapIntensity = 1.0;
  8883. this.aoMap = null;
  8884. this.aoMapIntensity = 1.0;
  8885. this.bumpMap = null;
  8886. this.bumpScale = 1;
  8887. this.normalMap = null;
  8888. this.normalScale = new THREE.Vector2( 1, 1 );
  8889. this.specularMap = null;
  8890. this.alphaMap = null;
  8891. this.envMap = null;
  8892. this.combine = THREE.MultiplyOperation;
  8893. this.reflectivity = 1;
  8894. this.refractionRatio = 0.98;
  8895. this.fog = true;
  8896. this.shading = THREE.SmoothShading;
  8897. this.wireframe = false;
  8898. this.wireframeLinewidth = 1;
  8899. this.wireframeLinecap = 'round';
  8900. this.wireframeLinejoin = 'round';
  8901. this.vertexColors = THREE.NoColors;
  8902. this.skinning = false;
  8903. this.morphTargets = false;
  8904. this.morphNormals = false;
  8905. this.setValues( parameters );
  8906. };
  8907. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  8908. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  8909. THREE.MeshPhongMaterial.prototype.clone = function () {
  8910. var material = new THREE.MeshPhongMaterial();
  8911. THREE.Material.prototype.clone.call( this, material );
  8912. material.color.copy( this.color );
  8913. material.emissive.copy( this.emissive );
  8914. material.specular.copy( this.specular );
  8915. material.shininess = this.shininess;
  8916. material.metal = this.metal;
  8917. material.map = this.map;
  8918. material.lightMap = this.lightMap;
  8919. material.lightMapIntensity = this.lightMapIntensity;
  8920. material.aoMap = this.aoMap;
  8921. material.aoMapIntensity = this.aoMapIntensity;
  8922. material.bumpMap = this.bumpMap;
  8923. material.bumpScale = this.bumpScale;
  8924. material.normalMap = this.normalMap;
  8925. material.normalScale.copy( this.normalScale );
  8926. material.specularMap = this.specularMap;
  8927. material.alphaMap = this.alphaMap;
  8928. material.envMap = this.envMap;
  8929. material.combine = this.combine;
  8930. material.reflectivity = this.reflectivity;
  8931. material.refractionRatio = this.refractionRatio;
  8932. material.fog = this.fog;
  8933. material.shading = this.shading;
  8934. material.wireframe = this.wireframe;
  8935. material.wireframeLinewidth = this.wireframeLinewidth;
  8936. material.wireframeLinecap = this.wireframeLinecap;
  8937. material.wireframeLinejoin = this.wireframeLinejoin;
  8938. material.vertexColors = this.vertexColors;
  8939. material.skinning = this.skinning;
  8940. material.morphTargets = this.morphTargets;
  8941. material.morphNormals = this.morphNormals;
  8942. return material;
  8943. };
  8944. // File:src/materials/MeshDepthMaterial.js
  8945. /**
  8946. * @author mrdoob / http://mrdoob.com/
  8947. * @author alteredq / http://alteredqualia.com/
  8948. *
  8949. * parameters = {
  8950. * opacity: <float>,
  8951. *
  8952. * blending: THREE.NormalBlending,
  8953. * depthTest: <bool>,
  8954. * depthWrite: <bool>,
  8955. *
  8956. * wireframe: <boolean>,
  8957. * wireframeLinewidth: <float>
  8958. * }
  8959. */
  8960. THREE.MeshDepthMaterial = function ( parameters ) {
  8961. THREE.Material.call( this );
  8962. this.type = 'MeshDepthMaterial';
  8963. this.morphTargets = false;
  8964. this.wireframe = false;
  8965. this.wireframeLinewidth = 1;
  8966. this.setValues( parameters );
  8967. };
  8968. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  8969. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  8970. THREE.MeshDepthMaterial.prototype.clone = function () {
  8971. var material = new THREE.MeshDepthMaterial();
  8972. THREE.Material.prototype.clone.call( this, material );
  8973. material.wireframe = this.wireframe;
  8974. material.wireframeLinewidth = this.wireframeLinewidth;
  8975. return material;
  8976. };
  8977. // File:src/materials/MeshNormalMaterial.js
  8978. /**
  8979. * @author mrdoob / http://mrdoob.com/
  8980. *
  8981. * parameters = {
  8982. * opacity: <float>,
  8983. *
  8984. * shading: THREE.FlatShading,
  8985. * blending: THREE.NormalBlending,
  8986. * depthTest: <bool>,
  8987. * depthWrite: <bool>,
  8988. *
  8989. * wireframe: <boolean>,
  8990. * wireframeLinewidth: <float>
  8991. * }
  8992. */
  8993. THREE.MeshNormalMaterial = function ( parameters ) {
  8994. THREE.Material.call( this, parameters );
  8995. this.type = 'MeshNormalMaterial';
  8996. this.wireframe = false;
  8997. this.wireframeLinewidth = 1;
  8998. this.morphTargets = false;
  8999. this.setValues( parameters );
  9000. };
  9001. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  9002. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  9003. THREE.MeshNormalMaterial.prototype.clone = function () {
  9004. var material = new THREE.MeshNormalMaterial();
  9005. THREE.Material.prototype.clone.call( this, material );
  9006. material.wireframe = this.wireframe;
  9007. material.wireframeLinewidth = this.wireframeLinewidth;
  9008. return material;
  9009. };
  9010. // File:src/materials/MeshFaceMaterial.js
  9011. /**
  9012. * @author mrdoob / http://mrdoob.com/
  9013. */
  9014. THREE.MeshFaceMaterial = function ( materials ) {
  9015. console.error( 'THREE.MeshFaceMaterial has been removed.' );
  9016. var material = Array.isArray( materials ) ? materials[ 0 ] : new THREE.MeshBasicMaterial();
  9017. material.materials = []; // temporal workaround
  9018. return material;
  9019. };
  9020. // File:src/materials/PointCloudMaterial.js
  9021. /**
  9022. * @author mrdoob / http://mrdoob.com/
  9023. * @author alteredq / http://alteredqualia.com/
  9024. *
  9025. * parameters = {
  9026. * color: <hex>,
  9027. * opacity: <float>,
  9028. * map: new THREE.Texture( <Image> ),
  9029. *
  9030. * size: <float>,
  9031. * sizeAttenuation: <bool>,
  9032. *
  9033. * blending: THREE.NormalBlending,
  9034. * depthTest: <bool>,
  9035. * depthWrite: <bool>,
  9036. *
  9037. * vertexColors: <bool>,
  9038. *
  9039. * fog: <bool>
  9040. * }
  9041. */
  9042. THREE.PointCloudMaterial = function ( parameters ) {
  9043. THREE.Material.call( this );
  9044. this.type = 'PointCloudMaterial';
  9045. this.color = new THREE.Color( 0xffffff );
  9046. this.map = null;
  9047. this.size = 1;
  9048. this.sizeAttenuation = true;
  9049. this.vertexColors = THREE.NoColors;
  9050. this.fog = true;
  9051. this.setValues( parameters );
  9052. };
  9053. THREE.PointCloudMaterial.prototype = Object.create( THREE.Material.prototype );
  9054. THREE.PointCloudMaterial.prototype.constructor = THREE.PointCloudMaterial;
  9055. THREE.PointCloudMaterial.prototype.clone = function () {
  9056. var material = new THREE.PointCloudMaterial();
  9057. THREE.Material.prototype.clone.call( this, material );
  9058. material.color.copy( this.color );
  9059. material.map = this.map;
  9060. material.size = this.size;
  9061. material.sizeAttenuation = this.sizeAttenuation;
  9062. material.vertexColors = this.vertexColors;
  9063. material.fog = this.fog;
  9064. return material;
  9065. };
  9066. // backwards compatibility
  9067. THREE.ParticleBasicMaterial = function ( parameters ) {
  9068. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointCloudMaterial.' );
  9069. return new THREE.PointCloudMaterial( parameters );
  9070. };
  9071. THREE.ParticleSystemMaterial = function ( parameters ) {
  9072. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointCloudMaterial.' );
  9073. return new THREE.PointCloudMaterial( parameters );
  9074. };
  9075. // File:src/materials/ShaderMaterial.js
  9076. /**
  9077. * @author alteredq / http://alteredqualia.com/
  9078. *
  9079. * parameters = {
  9080. * defines: { "label" : "value" },
  9081. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  9082. *
  9083. * fragmentShader: <string>,
  9084. * vertexShader: <string>,
  9085. *
  9086. * shading: THREE.SmoothShading,
  9087. * blending: THREE.NormalBlending,
  9088. * depthTest: <bool>,
  9089. * depthWrite: <bool>,
  9090. *
  9091. * wireframe: <boolean>,
  9092. * wireframeLinewidth: <float>,
  9093. *
  9094. * lights: <bool>,
  9095. *
  9096. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9097. *
  9098. * skinning: <bool>,
  9099. * morphTargets: <bool>,
  9100. * morphNormals: <bool>,
  9101. *
  9102. * fog: <bool>
  9103. * }
  9104. */
  9105. THREE.ShaderMaterial = function ( parameters ) {
  9106. THREE.Material.call( this );
  9107. this.type = 'ShaderMaterial';
  9108. this.defines = {};
  9109. this.uniforms = {};
  9110. this.attributes = [];
  9111. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  9112. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  9113. this.shading = THREE.SmoothShading;
  9114. this.linewidth = 1;
  9115. this.wireframe = false;
  9116. this.wireframeLinewidth = 1;
  9117. this.fog = false; // set to use scene fog
  9118. this.lights = false; // set to use scene lights
  9119. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  9120. this.skinning = false; // set to use skinning attribute streams
  9121. this.morphTargets = false; // set to use morph targets
  9122. this.morphNormals = false; // set to use morph normals
  9123. this.derivatives = false; // set to use derivatives
  9124. // When rendered geometry doesn't include these attributes but the material does,
  9125. // use these default values in WebGL. This avoids errors when buffer data is missing.
  9126. this.defaultAttributeValues = {
  9127. 'color': [ 1, 1, 1 ],
  9128. 'uv': [ 0, 0 ],
  9129. 'uv2': [ 0, 0 ]
  9130. };
  9131. this.index0AttributeName = undefined;
  9132. if ( parameters !== undefined ) {
  9133. if ( parameters.attributes !== undefined && Array.isArray( parameters.attributes ) === false ) {
  9134. console.warn( 'THREE.ShaderMaterial: attributes should now be an array of attribute names.' );
  9135. parameters.attributes = Object.keys( parameters.attributes );
  9136. }
  9137. this.setValues( parameters );
  9138. }
  9139. };
  9140. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  9141. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  9142. THREE.ShaderMaterial.prototype.clone = function ( material ) {
  9143. if ( material === undefined ) material = new THREE.ShaderMaterial();
  9144. THREE.Material.prototype.clone.call( this, material );
  9145. material.fragmentShader = this.fragmentShader;
  9146. material.vertexShader = this.vertexShader;
  9147. material.uniforms = THREE.UniformsUtils.clone( this.uniforms );
  9148. material.attributes = this.attributes;
  9149. material.defines = this.defines;
  9150. material.shading = this.shading;
  9151. material.wireframe = this.wireframe;
  9152. material.wireframeLinewidth = this.wireframeLinewidth;
  9153. material.fog = this.fog;
  9154. material.lights = this.lights;
  9155. material.vertexColors = this.vertexColors;
  9156. material.skinning = this.skinning;
  9157. material.morphTargets = this.morphTargets;
  9158. material.morphNormals = this.morphNormals;
  9159. return material;
  9160. };
  9161. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  9162. var data = THREE.Material.prototype.toJSON.call( this, meta );
  9163. data.uniforms = this.uniforms;
  9164. data.attributes = this.attributes;
  9165. data.vertexShader = this.vertexShader;
  9166. data.fragmentShader = this.fragmentShader;
  9167. return data;
  9168. };
  9169. // File:src/materials/RawShaderMaterial.js
  9170. /**
  9171. * @author mrdoob / http://mrdoob.com/
  9172. */
  9173. THREE.RawShaderMaterial = function ( parameters ) {
  9174. THREE.ShaderMaterial.call( this, parameters );
  9175. this.type = 'RawShaderMaterial';
  9176. };
  9177. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  9178. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  9179. THREE.RawShaderMaterial.prototype.clone = function () {
  9180. var material = new THREE.RawShaderMaterial();
  9181. THREE.ShaderMaterial.prototype.clone.call( this, material );
  9182. return material;
  9183. };
  9184. // File:src/materials/SpriteMaterial.js
  9185. /**
  9186. * @author alteredq / http://alteredqualia.com/
  9187. *
  9188. * parameters = {
  9189. * color: <hex>,
  9190. * opacity: <float>,
  9191. * map: new THREE.Texture( <Image> ),
  9192. *
  9193. * blending: THREE.NormalBlending,
  9194. * depthTest: <bool>,
  9195. * depthWrite: <bool>,
  9196. *
  9197. * uvOffset: new THREE.Vector2(),
  9198. * uvScale: new THREE.Vector2(),
  9199. *
  9200. * fog: <bool>
  9201. * }
  9202. */
  9203. THREE.SpriteMaterial = function ( parameters ) {
  9204. THREE.Material.call( this );
  9205. this.type = 'SpriteMaterial';
  9206. this.color = new THREE.Color( 0xffffff );
  9207. this.map = null;
  9208. this.rotation = 0;
  9209. this.fog = false;
  9210. // set parameters
  9211. this.setValues( parameters );
  9212. };
  9213. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  9214. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  9215. THREE.SpriteMaterial.prototype.clone = function () {
  9216. var material = new THREE.SpriteMaterial();
  9217. THREE.Material.prototype.clone.call( this, material );
  9218. material.color.copy( this.color );
  9219. material.map = this.map;
  9220. material.rotation = this.rotation;
  9221. material.fog = this.fog;
  9222. return material;
  9223. };
  9224. // File:src/textures/Texture.js
  9225. /**
  9226. * @author mrdoob / http://mrdoob.com/
  9227. * @author alteredq / http://alteredqualia.com/
  9228. * @author szimek / https://github.com/szimek/
  9229. */
  9230. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9231. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  9232. this.uuid = THREE.Math.generateUUID();
  9233. this.name = '';
  9234. this.sourceFile = '';
  9235. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  9236. this.mipmaps = [];
  9237. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  9238. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  9239. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  9240. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  9241. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  9242. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  9243. this.format = format !== undefined ? format : THREE.RGBAFormat;
  9244. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  9245. this.offset = new THREE.Vector2( 0, 0 );
  9246. this.repeat = new THREE.Vector2( 1, 1 );
  9247. this.generateMipmaps = true;
  9248. this.premultiplyAlpha = false;
  9249. this.flipY = true;
  9250. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  9251. this._needsUpdate = false;
  9252. this.onUpdate = null;
  9253. };
  9254. THREE.Texture.DEFAULT_IMAGE = undefined;
  9255. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  9256. THREE.Texture.prototype = {
  9257. constructor: THREE.Texture,
  9258. get needsUpdate () {
  9259. return this._needsUpdate;
  9260. },
  9261. set needsUpdate ( value ) {
  9262. if ( value === true ) this.update();
  9263. this._needsUpdate = value;
  9264. },
  9265. clone: function ( texture ) {
  9266. if ( texture === undefined ) texture = new THREE.Texture();
  9267. texture.image = this.image;
  9268. texture.mipmaps = this.mipmaps.slice( 0 );
  9269. texture.mapping = this.mapping;
  9270. texture.wrapS = this.wrapS;
  9271. texture.wrapT = this.wrapT;
  9272. texture.magFilter = this.magFilter;
  9273. texture.minFilter = this.minFilter;
  9274. texture.anisotropy = this.anisotropy;
  9275. texture.format = this.format;
  9276. texture.type = this.type;
  9277. texture.offset.copy( this.offset );
  9278. texture.repeat.copy( this.repeat );
  9279. texture.generateMipmaps = this.generateMipmaps;
  9280. texture.premultiplyAlpha = this.premultiplyAlpha;
  9281. texture.flipY = this.flipY;
  9282. texture.unpackAlignment = this.unpackAlignment;
  9283. return texture;
  9284. },
  9285. toJSON: function ( meta ) {
  9286. if ( meta.textures[ this.uuid ] !== undefined ) {
  9287. return meta.textures[ this.uuid ];
  9288. }
  9289. var output = {
  9290. metadata: {
  9291. version: 4.4,
  9292. type: 'Texture',
  9293. generator: 'Texture.toJSON'
  9294. },
  9295. uuid: this.uuid,
  9296. name: this.name,
  9297. mapping: this.mapping,
  9298. repeat: [ this.repeat.x, this.repeat.y ],
  9299. offset: [ this.offset.x, this.offset.y ],
  9300. wrap: [ this.wrapS, this.wrapT ],
  9301. minFilter: this.minFilter,
  9302. magFilter: this.magFilter,
  9303. anisotropy: this.anisotropy
  9304. };
  9305. if ( this.image !== undefined ) {
  9306. // TODO: Move to THREE.Image
  9307. var image = this.image;
  9308. if ( image.uuid === undefined ) {
  9309. image.uuid = THREE.Math.generateUUID(); // UGH
  9310. }
  9311. if ( meta.images[ this.image.uuid ] === undefined ) {
  9312. var canvas = document.createElement( 'canvas' );
  9313. canvas.width = image.width;
  9314. canvas.height = image.height;
  9315. var context = canvas.getContext( '2d' );
  9316. context.drawImage( image, 0, 0, image.width, image.height );
  9317. var src;
  9318. if ( image.width > 2048 || image.height > 2048 ) {
  9319. src = canvas.toDataURL( 'image/jpeg', 0.6 );
  9320. } else {
  9321. src = canvas.toDataURL( 'image/png' );
  9322. }
  9323. meta.images[ this.image.uuid ] = { uuid: this.image.uuid, url: src };
  9324. }
  9325. output.image = image.uuid;
  9326. }
  9327. meta.textures[ this.uuid ] = output;
  9328. return output;
  9329. },
  9330. update: function () {
  9331. this.dispatchEvent( { type: 'update' } );
  9332. },
  9333. dispose: function () {
  9334. this.dispatchEvent( { type: 'dispose' } );
  9335. }
  9336. };
  9337. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  9338. THREE.TextureIdCount = 0;
  9339. // File:src/textures/CubeTexture.js
  9340. /**
  9341. * @author mrdoob / http://mrdoob.com/
  9342. */
  9343. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9344. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  9345. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9346. this.images = images;
  9347. };
  9348. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  9349. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  9350. THREE.CubeTexture.clone = function ( texture ) {
  9351. if ( texture === undefined ) texture = new THREE.CubeTexture();
  9352. THREE.Texture.prototype.clone.call( this, texture );
  9353. texture.images = this.images;
  9354. return texture;
  9355. };
  9356. // File:src/textures/CompressedTexture.js
  9357. /**
  9358. * @author alteredq / http://alteredqualia.com/
  9359. */
  9360. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  9361. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9362. this.image = { width: width, height: height };
  9363. this.mipmaps = mipmaps;
  9364. // no flipping for cube textures
  9365. // (also flipping doesn't work for compressed textures )
  9366. this.flipY = false;
  9367. // can't generate mipmaps for compressed textures
  9368. // mips must be embedded in DDS files
  9369. this.generateMipmaps = false;
  9370. };
  9371. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  9372. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  9373. THREE.CompressedTexture.prototype.clone = function () {
  9374. var texture = new THREE.CompressedTexture();
  9375. THREE.Texture.prototype.clone.call( this, texture );
  9376. return texture;
  9377. };
  9378. // File:src/textures/DataTexture.js
  9379. /**
  9380. * @author alteredq / http://alteredqualia.com/
  9381. */
  9382. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  9383. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9384. this.image = { data: data, width: width, height: height };
  9385. };
  9386. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  9387. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  9388. THREE.DataTexture.prototype.clone = function () {
  9389. var texture = new THREE.DataTexture();
  9390. THREE.Texture.prototype.clone.call( this, texture );
  9391. return texture;
  9392. };
  9393. // File:src/textures/VideoTexture.js
  9394. /**
  9395. * @author mrdoob / http://mrdoob.com/
  9396. */
  9397. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9398. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9399. this.generateMipmaps = false;
  9400. var scope = this;
  9401. var update = function () {
  9402. requestAnimationFrame( update );
  9403. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  9404. scope.needsUpdate = true;
  9405. }
  9406. };
  9407. update();
  9408. };
  9409. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  9410. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  9411. // File:src/objects/Group.js
  9412. /**
  9413. * @author mrdoob / http://mrdoob.com/
  9414. */
  9415. THREE.Group = function () {
  9416. THREE.Object3D.call( this );
  9417. this.type = 'Group';
  9418. };
  9419. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  9420. THREE.Group.prototype.constructor = THREE.Group;
  9421. // File:src/objects/PointCloud.js
  9422. /**
  9423. * @author alteredq / http://alteredqualia.com/
  9424. */
  9425. THREE.PointCloud = function ( geometry, material ) {
  9426. THREE.Object3D.call( this );
  9427. this.type = 'PointCloud';
  9428. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9429. this.material = material !== undefined ? material : new THREE.PointCloudMaterial( { color: Math.random() * 0xffffff } );
  9430. };
  9431. THREE.PointCloud.prototype = Object.create( THREE.Object3D.prototype );
  9432. THREE.PointCloud.prototype.constructor = THREE.PointCloud;
  9433. THREE.PointCloud.prototype.raycast = ( function () {
  9434. var inverseMatrix = new THREE.Matrix4();
  9435. var ray = new THREE.Ray();
  9436. return function ( raycaster, intersects ) {
  9437. var object = this;
  9438. var geometry = object.geometry;
  9439. var threshold = raycaster.params.PointCloud.threshold;
  9440. inverseMatrix.getInverse( this.matrixWorld );
  9441. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9442. if ( geometry.boundingBox !== null ) {
  9443. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  9444. return;
  9445. }
  9446. }
  9447. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  9448. var position = new THREE.Vector3();
  9449. var testPoint = function ( point, index ) {
  9450. var rayPointDistance = ray.distanceToPoint( point );
  9451. if ( rayPointDistance < localThreshold ) {
  9452. var intersectPoint = ray.closestPointToPoint( point );
  9453. intersectPoint.applyMatrix4( object.matrixWorld );
  9454. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  9455. intersects.push( {
  9456. distance: distance,
  9457. distanceToRay: rayPointDistance,
  9458. point: intersectPoint.clone(),
  9459. index: index,
  9460. face: null,
  9461. object: object
  9462. } );
  9463. }
  9464. };
  9465. if ( geometry instanceof THREE.BufferGeometry ) {
  9466. var attributes = geometry.attributes;
  9467. var positions = attributes.position.array;
  9468. if ( attributes.index !== undefined ) {
  9469. var indices = attributes.index.array;
  9470. var offsets = geometry.offsets;
  9471. if ( offsets.length === 0 ) {
  9472. var offset = {
  9473. start: 0,
  9474. count: indices.length,
  9475. index: 0
  9476. };
  9477. offsets = [ offset ];
  9478. }
  9479. for ( var oi = 0, ol = offsets.length; oi < ol; ++ oi ) {
  9480. var start = offsets[ oi ].start;
  9481. var count = offsets[ oi ].count;
  9482. var index = offsets[ oi ].index;
  9483. for ( var i = start, il = start + count; i < il; i ++ ) {
  9484. var a = index + indices[ i ];
  9485. position.fromArray( positions, a * 3 );
  9486. testPoint( position, a );
  9487. }
  9488. }
  9489. } else {
  9490. var pointCount = positions.length / 3;
  9491. for ( var i = 0; i < pointCount; i ++ ) {
  9492. position.set(
  9493. positions[ 3 * i ],
  9494. positions[ 3 * i + 1 ],
  9495. positions[ 3 * i + 2 ]
  9496. );
  9497. testPoint( position, i );
  9498. }
  9499. }
  9500. } else {
  9501. var vertices = this.geometry.vertices;
  9502. for ( var i = 0; i < vertices.length; i ++ ) {
  9503. testPoint( vertices[ i ], i );
  9504. }
  9505. }
  9506. };
  9507. }() );
  9508. THREE.PointCloud.prototype.clone = function ( object ) {
  9509. if ( object === undefined ) object = new THREE.PointCloud( this.geometry, this.material );
  9510. THREE.Object3D.prototype.clone.call( this, object );
  9511. return object;
  9512. };
  9513. THREE.PointCloud.prototype.toJSON = function ( meta ) {
  9514. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9515. // only serialize if not in meta geometries cache
  9516. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  9517. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  9518. }
  9519. // only serialize if not in meta materials cache
  9520. if ( meta.materials[ this.material.uuid ] === undefined ) {
  9521. meta.materials[ this.material.uuid ] = this.material.toJSON();
  9522. }
  9523. data.object.geometry = this.geometry.uuid;
  9524. data.object.material = this.material.uuid;
  9525. return data;
  9526. };
  9527. // Backwards compatibility
  9528. THREE.ParticleSystem = function ( geometry, material ) {
  9529. console.warn( 'THREE.ParticleSystem has been renamed to THREE.PointCloud.' );
  9530. return new THREE.PointCloud( geometry, material );
  9531. };
  9532. // File:src/objects/Line.js
  9533. /**
  9534. * @author mrdoob / http://mrdoob.com/
  9535. */
  9536. THREE.Line = function ( geometry, material, mode ) {
  9537. if ( mode === 1 ) {
  9538. console.error( 'THREE.Line: THREE.LinePieces mode has been removed. Use THREE.LineSegments instead.' );
  9539. }
  9540. THREE.Object3D.call( this );
  9541. this.type = 'Line';
  9542. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9543. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  9544. };
  9545. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  9546. THREE.Line.prototype.constructor = THREE.Line;
  9547. THREE.Line.prototype.raycast = ( function () {
  9548. var inverseMatrix = new THREE.Matrix4();
  9549. var ray = new THREE.Ray();
  9550. var sphere = new THREE.Sphere();
  9551. return function ( raycaster, intersects ) {
  9552. var precision = raycaster.linePrecision;
  9553. var precisionSq = precision * precision;
  9554. var geometry = this.geometry;
  9555. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9556. // Checking boundingSphere distance to ray
  9557. sphere.copy( geometry.boundingSphere );
  9558. sphere.applyMatrix4( this.matrixWorld );
  9559. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  9560. return;
  9561. }
  9562. inverseMatrix.getInverse( this.matrixWorld );
  9563. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9564. var vStart = new THREE.Vector3();
  9565. var vEnd = new THREE.Vector3();
  9566. var interSegment = new THREE.Vector3();
  9567. var interRay = new THREE.Vector3();
  9568. var step = this instanceof THREE.LineSegments ? 2 : 1;
  9569. if ( geometry instanceof THREE.BufferGeometry ) {
  9570. var attributes = geometry.attributes;
  9571. if ( attributes.index !== undefined ) {
  9572. var indices = attributes.index.array;
  9573. var positions = attributes.position.array;
  9574. var offsets = geometry.offsets;
  9575. if ( offsets.length === 0 ) {
  9576. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  9577. }
  9578. for ( var oi = 0; oi < offsets.length; oi ++) {
  9579. var start = offsets[ oi ].start;
  9580. var count = offsets[ oi ].count;
  9581. var index = offsets[ oi ].index;
  9582. for ( var i = start; i < start + count - 1; i += step ) {
  9583. var a = index + indices[ i ];
  9584. var b = index + indices[ i + 1 ];
  9585. vStart.fromArray( positions, a * 3 );
  9586. vEnd.fromArray( positions, b * 3 );
  9587. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  9588. if ( distSq > precisionSq ) continue;
  9589. var distance = ray.origin.distanceTo( interRay );
  9590. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9591. intersects.push( {
  9592. distance: distance,
  9593. // What do we want? intersection point on the ray or on the segment??
  9594. // point: raycaster.ray.at( distance ),
  9595. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9596. index: i,
  9597. offsetIndex: oi,
  9598. face: null,
  9599. faceIndex: null,
  9600. object: this
  9601. } );
  9602. }
  9603. }
  9604. } else {
  9605. var positions = attributes.position.array;
  9606. for ( var i = 0; i < positions.length / 3 - 1; i += step ) {
  9607. vStart.fromArray( positions, 3 * i );
  9608. vEnd.fromArray( positions, 3 * i + 3 );
  9609. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  9610. if ( distSq > precisionSq ) continue;
  9611. var distance = ray.origin.distanceTo( interRay );
  9612. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9613. intersects.push( {
  9614. distance: distance,
  9615. // What do we want? intersection point on the ray or on the segment??
  9616. // point: raycaster.ray.at( distance ),
  9617. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9618. index: i,
  9619. face: null,
  9620. faceIndex: null,
  9621. object: this
  9622. } );
  9623. }
  9624. }
  9625. } else if ( geometry instanceof THREE.Geometry ) {
  9626. var vertices = geometry.vertices;
  9627. var nbVertices = vertices.length;
  9628. for ( var i = 0; i < nbVertices - 1; i += step ) {
  9629. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  9630. if ( distSq > precisionSq ) continue;
  9631. var distance = ray.origin.distanceTo( interRay );
  9632. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9633. intersects.push( {
  9634. distance: distance,
  9635. // What do we want? intersection point on the ray or on the segment??
  9636. // point: raycaster.ray.at( distance ),
  9637. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9638. index: i,
  9639. face: null,
  9640. faceIndex: null,
  9641. object: this
  9642. } );
  9643. }
  9644. }
  9645. };
  9646. }() );
  9647. THREE.Line.prototype.clone = function ( object ) {
  9648. if ( object === undefined ) object = new THREE[ this.type ]( this.geometry, this.material );
  9649. THREE.Object3D.prototype.clone.call( this, object );
  9650. return object;
  9651. };
  9652. THREE.Line.prototype.toJSON = function ( meta ) {
  9653. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9654. // only serialize if not in meta geometries cache
  9655. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  9656. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  9657. }
  9658. // only serialize if not in meta materials cache
  9659. if ( meta.materials[ this.material.uuid ] === undefined ) {
  9660. meta.materials[ this.material.uuid ] = this.material.toJSON();
  9661. }
  9662. data.object.geometry = this.geometry.uuid;
  9663. data.object.material = this.material.uuid;
  9664. return data;
  9665. };
  9666. // DEPRECATED
  9667. THREE.LineStrip = 0;
  9668. THREE.LinePieces = 1;
  9669. // File:src/objects/LineSegments.js
  9670. /**
  9671. * @author mrdoob / http://mrdoob.com/
  9672. */
  9673. THREE.LineSegments = function ( geometry, material ) {
  9674. THREE.Line.call( this, geometry, material );
  9675. this.type = 'LineSegments';
  9676. };
  9677. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  9678. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  9679. // File:src/objects/Mesh.js
  9680. /**
  9681. * @author mrdoob / http://mrdoob.com/
  9682. * @author alteredq / http://alteredqualia.com/
  9683. * @author mikael emtinger / http://gomo.se/
  9684. * @author jonobr1 / http://jonobr1.com/
  9685. */
  9686. THREE.Mesh = function ( geometry, material ) {
  9687. THREE.Object3D.call( this );
  9688. this.type = 'Mesh';
  9689. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9690. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  9691. this.updateMorphTargets();
  9692. };
  9693. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  9694. THREE.Mesh.prototype.constructor = THREE.Mesh;
  9695. THREE.Mesh.prototype.updateMorphTargets = function () {
  9696. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  9697. this.morphTargetBase = - 1;
  9698. this.morphTargetForcedOrder = [];
  9699. this.morphTargetInfluences = [];
  9700. this.morphTargetDictionary = {};
  9701. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  9702. this.morphTargetInfluences.push( 0 );
  9703. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  9704. }
  9705. }
  9706. };
  9707. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  9708. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  9709. return this.morphTargetDictionary[ name ];
  9710. }
  9711. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  9712. return 0;
  9713. };
  9714. THREE.Mesh.prototype.raycast = ( function () {
  9715. var inverseMatrix = new THREE.Matrix4();
  9716. var ray = new THREE.Ray();
  9717. var sphere = new THREE.Sphere();
  9718. var vA = new THREE.Vector3();
  9719. var vB = new THREE.Vector3();
  9720. var vC = new THREE.Vector3();
  9721. return function ( raycaster, intersects ) {
  9722. var geometry = this.geometry;
  9723. // Checking boundingSphere distance to ray
  9724. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9725. sphere.copy( geometry.boundingSphere );
  9726. sphere.applyMatrix4( this.matrixWorld );
  9727. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  9728. return;
  9729. }
  9730. // Check boundingBox before continuing
  9731. inverseMatrix.getInverse( this.matrixWorld );
  9732. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9733. if ( geometry.boundingBox !== null ) {
  9734. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  9735. return;
  9736. }
  9737. }
  9738. if ( geometry instanceof THREE.BufferGeometry ) {
  9739. var material = this.material;
  9740. if ( material === undefined ) return;
  9741. var attributes = geometry.attributes;
  9742. var a, b, c;
  9743. var precision = raycaster.precision;
  9744. if ( attributes.index !== undefined ) {
  9745. var indices = attributes.index.array;
  9746. var positions = attributes.position.array;
  9747. var offsets = geometry.offsets;
  9748. if ( offsets.length === 0 ) {
  9749. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  9750. }
  9751. for ( var oi = 0, ol = offsets.length; oi < ol; ++ oi ) {
  9752. var start = offsets[ oi ].start;
  9753. var count = offsets[ oi ].count;
  9754. var index = offsets[ oi ].index;
  9755. for ( var i = start, il = start + count; i < il; i += 3 ) {
  9756. a = index + indices[ i ];
  9757. b = index + indices[ i + 1 ];
  9758. c = index + indices[ i + 2 ];
  9759. vA.fromArray( positions, a * 3 );
  9760. vB.fromArray( positions, b * 3 );
  9761. vC.fromArray( positions, c * 3 );
  9762. if ( material.side === THREE.BackSide ) {
  9763. var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
  9764. } else {
  9765. var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
  9766. }
  9767. if ( intersectionPoint === null ) continue;
  9768. intersectionPoint.applyMatrix4( this.matrixWorld );
  9769. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  9770. if ( distance < precision || distance < raycaster.near || distance > raycaster.far ) continue;
  9771. intersects.push( {
  9772. distance: distance,
  9773. point: intersectionPoint,
  9774. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  9775. faceIndex: null,
  9776. object: this
  9777. } );
  9778. }
  9779. }
  9780. } else {
  9781. var positions = attributes.position.array;
  9782. for ( var i = 0, j = 0, il = positions.length; i < il; i += 3, j += 9 ) {
  9783. a = i;
  9784. b = i + 1;
  9785. c = i + 2;
  9786. vA.fromArray( positions, j );
  9787. vB.fromArray( positions, j + 3 );
  9788. vC.fromArray( positions, j + 6 );
  9789. if ( material.side === THREE.BackSide ) {
  9790. var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
  9791. } else {
  9792. var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
  9793. }
  9794. if ( intersectionPoint === null ) continue;
  9795. intersectionPoint.applyMatrix4( this.matrixWorld );
  9796. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  9797. if ( distance < precision || distance < raycaster.near || distance > raycaster.far ) continue;
  9798. intersects.push( {
  9799. distance: distance,
  9800. point: intersectionPoint,
  9801. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  9802. faceIndex: null,
  9803. object: this
  9804. } );
  9805. }
  9806. }
  9807. } else if ( geometry instanceof THREE.Geometry ) {
  9808. var isFaceMaterial = this.material instanceof THREE.MeshFaceMaterial;
  9809. var objectMaterials = isFaceMaterial === true ? this.material.materials : null;
  9810. var a, b, c;
  9811. var precision = raycaster.precision;
  9812. var vertices = geometry.vertices;
  9813. for ( var f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
  9814. var face = geometry.faces[ f ];
  9815. var material = isFaceMaterial === true ? objectMaterials[ face.materialIndex ] : this.material;
  9816. if ( material === undefined ) continue;
  9817. a = vertices[ face.a ];
  9818. b = vertices[ face.b ];
  9819. c = vertices[ face.c ];
  9820. if ( material.morphTargets === true ) {
  9821. var morphTargets = geometry.morphTargets;
  9822. var morphInfluences = this.morphTargetInfluences;
  9823. vA.set( 0, 0, 0 );
  9824. vB.set( 0, 0, 0 );
  9825. vC.set( 0, 0, 0 );
  9826. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  9827. var influence = morphInfluences[ t ];
  9828. if ( influence === 0 ) continue;
  9829. var targets = morphTargets[ t ].vertices;
  9830. vA.x += ( targets[ face.a ].x - a.x ) * influence;
  9831. vA.y += ( targets[ face.a ].y - a.y ) * influence;
  9832. vA.z += ( targets[ face.a ].z - a.z ) * influence;
  9833. vB.x += ( targets[ face.b ].x - b.x ) * influence;
  9834. vB.y += ( targets[ face.b ].y - b.y ) * influence;
  9835. vB.z += ( targets[ face.b ].z - b.z ) * influence;
  9836. vC.x += ( targets[ face.c ].x - c.x ) * influence;
  9837. vC.y += ( targets[ face.c ].y - c.y ) * influence;
  9838. vC.z += ( targets[ face.c ].z - c.z ) * influence;
  9839. }
  9840. vA.add( a );
  9841. vB.add( b );
  9842. vC.add( c );
  9843. a = vA;
  9844. b = vB;
  9845. c = vC;
  9846. }
  9847. if ( material.side === THREE.BackSide ) {
  9848. var intersectionPoint = ray.intersectTriangle( c, b, a, true );
  9849. } else {
  9850. var intersectionPoint = ray.intersectTriangle( a, b, c, material.side !== THREE.DoubleSide );
  9851. }
  9852. if ( intersectionPoint === null ) continue;
  9853. intersectionPoint.applyMatrix4( this.matrixWorld );
  9854. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  9855. if ( distance < precision || distance < raycaster.near || distance > raycaster.far ) continue;
  9856. intersects.push( {
  9857. distance: distance,
  9858. point: intersectionPoint,
  9859. face: face,
  9860. faceIndex: f,
  9861. object: this
  9862. } );
  9863. }
  9864. }
  9865. };
  9866. }() );
  9867. THREE.Mesh.prototype.clone = function ( object, recursive ) {
  9868. if ( object === undefined ) object = new THREE.Mesh( this.geometry, this.material );
  9869. THREE.Object3D.prototype.clone.call( this, object, recursive );
  9870. return object;
  9871. };
  9872. THREE.Mesh.prototype.toJSON = function ( meta ) {
  9873. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9874. // only serialize if not in meta geometries cache
  9875. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  9876. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  9877. }
  9878. // only serialize if not in meta materials cache
  9879. if ( meta.materials[ this.material.uuid ] === undefined ) {
  9880. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  9881. }
  9882. data.object.geometry = this.geometry.uuid;
  9883. data.object.material = this.material.uuid;
  9884. return data;
  9885. };
  9886. // File:src/objects/Bone.js
  9887. /**
  9888. * @author mikael emtinger / http://gomo.se/
  9889. * @author alteredq / http://alteredqualia.com/
  9890. * @author ikerr / http://verold.com
  9891. */
  9892. THREE.Bone = function ( skin ) {
  9893. THREE.Object3D.call( this );
  9894. this.type = 'Bone';
  9895. this.skin = skin;
  9896. };
  9897. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  9898. THREE.Bone.prototype.constructor = THREE.Bone;
  9899. // File:src/objects/Skeleton.js
  9900. /**
  9901. * @author mikael emtinger / http://gomo.se/
  9902. * @author alteredq / http://alteredqualia.com/
  9903. * @author michael guerrero / http://realitymeltdown.com
  9904. * @author ikerr / http://verold.com
  9905. */
  9906. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  9907. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  9908. this.identityMatrix = new THREE.Matrix4();
  9909. // copy the bone array
  9910. bones = bones || [];
  9911. this.bones = bones.slice( 0 );
  9912. // create a bone texture or an array of floats
  9913. if ( this.useVertexTexture ) {
  9914. // layout (1 matrix = 4 pixels)
  9915. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  9916. // with 8x8 pixel texture max 16 bones (8 * 8 / 4)
  9917. // 16x16 pixel texture max 64 bones (16 * 16 / 4)
  9918. // 32x32 pixel texture max 256 bones (32 * 32 / 4)
  9919. // 64x64 pixel texture max 1024 bones (64 * 64 / 4)
  9920. var size;
  9921. if ( this.bones.length > 256 )
  9922. size = 64;
  9923. else if ( this.bones.length > 64 )
  9924. size = 32;
  9925. else if ( this.bones.length > 16 )
  9926. size = 16;
  9927. else
  9928. size = 8;
  9929. this.boneTextureWidth = size;
  9930. this.boneTextureHeight = size;
  9931. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  9932. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  9933. this.boneTexture.minFilter = THREE.NearestFilter;
  9934. this.boneTexture.magFilter = THREE.NearestFilter;
  9935. this.boneTexture.generateMipmaps = false;
  9936. this.boneTexture.flipY = false;
  9937. } else {
  9938. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  9939. }
  9940. // use the supplied bone inverses or calculate the inverses
  9941. if ( boneInverses === undefined ) {
  9942. this.calculateInverses();
  9943. } else {
  9944. if ( this.bones.length === boneInverses.length ) {
  9945. this.boneInverses = boneInverses.slice( 0 );
  9946. } else {
  9947. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  9948. this.boneInverses = [];
  9949. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  9950. this.boneInverses.push( new THREE.Matrix4() );
  9951. }
  9952. }
  9953. }
  9954. };
  9955. THREE.Skeleton.prototype.calculateInverses = function () {
  9956. this.boneInverses = [];
  9957. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  9958. var inverse = new THREE.Matrix4();
  9959. if ( this.bones[ b ] ) {
  9960. inverse.getInverse( this.bones[ b ].matrixWorld );
  9961. }
  9962. this.boneInverses.push( inverse );
  9963. }
  9964. };
  9965. THREE.Skeleton.prototype.pose = function () {
  9966. var bone;
  9967. // recover the bind-time world matrices
  9968. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  9969. bone = this.bones[ b ];
  9970. if ( bone ) {
  9971. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  9972. }
  9973. }
  9974. // compute the local matrices, positions, rotations and scales
  9975. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  9976. bone = this.bones[ b ];
  9977. if ( bone ) {
  9978. if ( bone.parent ) {
  9979. bone.matrix.getInverse( bone.parent.matrixWorld );
  9980. bone.matrix.multiply( bone.matrixWorld );
  9981. } else {
  9982. bone.matrix.copy( bone.matrixWorld );
  9983. }
  9984. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  9985. }
  9986. }
  9987. };
  9988. THREE.Skeleton.prototype.update = ( function () {
  9989. var offsetMatrix = new THREE.Matrix4();
  9990. return function () {
  9991. // flatten bone matrices to array
  9992. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  9993. // compute the offset between the current and the original transform
  9994. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  9995. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  9996. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  9997. }
  9998. if ( this.useVertexTexture ) {
  9999. this.boneTexture.needsUpdate = true;
  10000. }
  10001. };
  10002. } )();
  10003. // File:src/objects/SkinnedMesh.js
  10004. /**
  10005. * @author mikael emtinger / http://gomo.se/
  10006. * @author alteredq / http://alteredqualia.com/
  10007. * @author ikerr / http://verold.com
  10008. */
  10009. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  10010. THREE.Mesh.call( this, geometry, material );
  10011. this.type = 'SkinnedMesh';
  10012. this.bindMode = "attached";
  10013. this.bindMatrix = new THREE.Matrix4();
  10014. this.bindMatrixInverse = new THREE.Matrix4();
  10015. // init bones
  10016. // TODO: remove bone creation as there is no reason (other than
  10017. // convenience) for THREE.SkinnedMesh to do this.
  10018. var bones = [];
  10019. if ( this.geometry && this.geometry.bones !== undefined ) {
  10020. var bone, gbone, p, q, s;
  10021. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  10022. gbone = this.geometry.bones[ b ];
  10023. p = gbone.pos;
  10024. q = gbone.rotq;
  10025. s = gbone.scl;
  10026. bone = new THREE.Bone( this );
  10027. bones.push( bone );
  10028. bone.name = gbone.name;
  10029. bone.position.set( p[ 0 ], p[ 1 ], p[ 2 ] );
  10030. bone.quaternion.set( q[ 0 ], q[ 1 ], q[ 2 ], q[ 3 ] );
  10031. if ( s !== undefined ) {
  10032. bone.scale.set( s[ 0 ], s[ 1 ], s[ 2 ] );
  10033. } else {
  10034. bone.scale.set( 1, 1, 1 );
  10035. }
  10036. }
  10037. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  10038. gbone = this.geometry.bones[ b ];
  10039. if ( gbone.parent !== - 1 ) {
  10040. bones[ gbone.parent ].add( bones[ b ] );
  10041. } else {
  10042. this.add( bones[ b ] );
  10043. }
  10044. }
  10045. }
  10046. this.normalizeSkinWeights();
  10047. this.updateMatrixWorld( true );
  10048. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ) );
  10049. };
  10050. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  10051. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  10052. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  10053. this.skeleton = skeleton;
  10054. if ( bindMatrix === undefined ) {
  10055. this.updateMatrixWorld( true );
  10056. bindMatrix = this.matrixWorld;
  10057. }
  10058. this.bindMatrix.copy( bindMatrix );
  10059. this.bindMatrixInverse.getInverse( bindMatrix );
  10060. };
  10061. THREE.SkinnedMesh.prototype.pose = function () {
  10062. this.skeleton.pose();
  10063. };
  10064. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  10065. if ( this.geometry instanceof THREE.Geometry ) {
  10066. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  10067. var sw = this.geometry.skinWeights[ i ];
  10068. var scale = 1.0 / sw.lengthManhattan();
  10069. if ( scale !== Infinity ) {
  10070. sw.multiplyScalar( scale );
  10071. } else {
  10072. sw.set( 1 ); // this will be normalized by the shader anyway
  10073. }
  10074. }
  10075. } else {
  10076. // skinning weights assumed to be normalized for THREE.BufferGeometry
  10077. }
  10078. };
  10079. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  10080. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  10081. if ( this.bindMode === "attached" ) {
  10082. this.bindMatrixInverse.getInverse( this.matrixWorld );
  10083. } else if ( this.bindMode === "detached" ) {
  10084. this.bindMatrixInverse.getInverse( this.bindMatrix );
  10085. } else {
  10086. console.warn( 'THREE.SkinnedMesh unreckognized bindMode: ' + this.bindMode );
  10087. }
  10088. };
  10089. THREE.SkinnedMesh.prototype.clone = function( object ) {
  10090. if ( object === undefined ) {
  10091. object = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture );
  10092. }
  10093. THREE.Mesh.prototype.clone.call( this, object );
  10094. return object;
  10095. };
  10096. // File:src/objects/MorphAnimMesh.js
  10097. /**
  10098. * @author alteredq / http://alteredqualia.com/
  10099. */
  10100. THREE.MorphAnimMesh = function ( geometry, material ) {
  10101. THREE.Mesh.call( this, geometry, material );
  10102. this.type = 'MorphAnimMesh';
  10103. // API
  10104. this.duration = 1000; // milliseconds
  10105. this.mirroredLoop = false;
  10106. this.time = 0;
  10107. // internals
  10108. this.lastKeyframe = 0;
  10109. this.currentKeyframe = 0;
  10110. this.direction = 1;
  10111. this.directionBackwards = false;
  10112. this.setFrameRange( 0, this.geometry.morphTargets.length - 1 );
  10113. };
  10114. THREE.MorphAnimMesh.prototype = Object.create( THREE.Mesh.prototype );
  10115. THREE.MorphAnimMesh.prototype.constructor = THREE.MorphAnimMesh;
  10116. THREE.MorphAnimMesh.prototype.setFrameRange = function ( start, end ) {
  10117. this.startKeyframe = start;
  10118. this.endKeyframe = end;
  10119. this.length = this.endKeyframe - this.startKeyframe + 1;
  10120. };
  10121. THREE.MorphAnimMesh.prototype.setDirectionForward = function () {
  10122. this.direction = 1;
  10123. this.directionBackwards = false;
  10124. };
  10125. THREE.MorphAnimMesh.prototype.setDirectionBackward = function () {
  10126. this.direction = - 1;
  10127. this.directionBackwards = true;
  10128. };
  10129. THREE.MorphAnimMesh.prototype.parseAnimations = function () {
  10130. var geometry = this.geometry;
  10131. if ( ! geometry.animations ) geometry.animations = {};
  10132. var firstAnimation, animations = geometry.animations;
  10133. var pattern = /([a-z]+)_?(\d+)/;
  10134. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  10135. var morph = geometry.morphTargets[ i ];
  10136. var parts = morph.name.match( pattern );
  10137. if ( parts && parts.length > 1 ) {
  10138. var label = parts[ 1 ];
  10139. if ( ! animations[ label ] ) animations[ label ] = { start: Infinity, end: - Infinity };
  10140. var animation = animations[ label ];
  10141. if ( i < animation.start ) animation.start = i;
  10142. if ( i > animation.end ) animation.end = i;
  10143. if ( ! firstAnimation ) firstAnimation = label;
  10144. }
  10145. }
  10146. geometry.firstAnimation = firstAnimation;
  10147. };
  10148. THREE.MorphAnimMesh.prototype.setAnimationLabel = function ( label, start, end ) {
  10149. if ( ! this.geometry.animations ) this.geometry.animations = {};
  10150. this.geometry.animations[ label ] = { start: start, end: end };
  10151. };
  10152. THREE.MorphAnimMesh.prototype.playAnimation = function ( label, fps ) {
  10153. var animation = this.geometry.animations[ label ];
  10154. if ( animation ) {
  10155. this.setFrameRange( animation.start, animation.end );
  10156. this.duration = 1000 * ( ( animation.end - animation.start ) / fps );
  10157. this.time = 0;
  10158. } else {
  10159. console.warn( 'THREE.MorphAnimMesh: animation[' + label + '] undefined in .playAnimation()' );
  10160. }
  10161. };
  10162. THREE.MorphAnimMesh.prototype.updateAnimation = function ( delta ) {
  10163. var frameTime = this.duration / this.length;
  10164. this.time += this.direction * delta;
  10165. if ( this.mirroredLoop ) {
  10166. if ( this.time > this.duration || this.time < 0 ) {
  10167. this.direction *= - 1;
  10168. if ( this.time > this.duration ) {
  10169. this.time = this.duration;
  10170. this.directionBackwards = true;
  10171. }
  10172. if ( this.time < 0 ) {
  10173. this.time = 0;
  10174. this.directionBackwards = false;
  10175. }
  10176. }
  10177. } else {
  10178. this.time = this.time % this.duration;
  10179. if ( this.time < 0 ) this.time += this.duration;
  10180. }
  10181. var keyframe = this.startKeyframe + THREE.Math.clamp( Math.floor( this.time / frameTime ), 0, this.length - 1 );
  10182. if ( keyframe !== this.currentKeyframe ) {
  10183. this.morphTargetInfluences[ this.lastKeyframe ] = 0;
  10184. this.morphTargetInfluences[ this.currentKeyframe ] = 1;
  10185. this.morphTargetInfluences[ keyframe ] = 0;
  10186. this.lastKeyframe = this.currentKeyframe;
  10187. this.currentKeyframe = keyframe;
  10188. }
  10189. var mix = ( this.time % frameTime ) / frameTime;
  10190. if ( this.directionBackwards ) {
  10191. mix = 1 - mix;
  10192. }
  10193. this.morphTargetInfluences[ this.currentKeyframe ] = mix;
  10194. this.morphTargetInfluences[ this.lastKeyframe ] = 1 - mix;
  10195. };
  10196. THREE.MorphAnimMesh.prototype.interpolateTargets = function ( a, b, t ) {
  10197. var influences = this.morphTargetInfluences;
  10198. for ( var i = 0, l = influences.length; i < l; i ++ ) {
  10199. influences[ i ] = 0;
  10200. }
  10201. if ( a > -1 ) influences[ a ] = 1 - t;
  10202. if ( b > -1 ) influences[ b ] = t;
  10203. };
  10204. THREE.MorphAnimMesh.prototype.clone = function ( object ) {
  10205. if ( object === undefined ) object = new THREE.MorphAnimMesh( this.geometry, this.material );
  10206. object.duration = this.duration;
  10207. object.mirroredLoop = this.mirroredLoop;
  10208. object.time = this.time;
  10209. object.lastKeyframe = this.lastKeyframe;
  10210. object.currentKeyframe = this.currentKeyframe;
  10211. object.direction = this.direction;
  10212. object.directionBackwards = this.directionBackwards;
  10213. THREE.Mesh.prototype.clone.call( this, object );
  10214. return object;
  10215. };
  10216. // File:src/objects/LOD.js
  10217. /**
  10218. * @author mikael emtinger / http://gomo.se/
  10219. * @author alteredq / http://alteredqualia.com/
  10220. * @author mrdoob / http://mrdoob.com/
  10221. */
  10222. THREE.LOD = function () {
  10223. THREE.Object3D.call( this );
  10224. this.objects = [];
  10225. };
  10226. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  10227. THREE.LOD.prototype.constructor = THREE.LOD;
  10228. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  10229. if ( distance === undefined ) distance = 0;
  10230. distance = Math.abs( distance );
  10231. for ( var l = 0; l < this.objects.length; l ++ ) {
  10232. if ( distance < this.objects[ l ].distance ) {
  10233. break;
  10234. }
  10235. }
  10236. this.objects.splice( l, 0, { distance: distance, object: object } );
  10237. this.add( object );
  10238. };
  10239. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  10240. for ( var i = 1, l = this.objects.length; i < l; i ++ ) {
  10241. if ( distance < this.objects[ i ].distance ) {
  10242. break;
  10243. }
  10244. }
  10245. return this.objects[ i - 1 ].object;
  10246. };
  10247. THREE.LOD.prototype.raycast = ( function () {
  10248. var matrixPosition = new THREE.Vector3();
  10249. return function ( raycaster, intersects ) {
  10250. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  10251. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  10252. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  10253. };
  10254. }() );
  10255. THREE.LOD.prototype.update = function () {
  10256. var v1 = new THREE.Vector3();
  10257. var v2 = new THREE.Vector3();
  10258. return function ( camera ) {
  10259. if ( this.objects.length > 1 ) {
  10260. v1.setFromMatrixPosition( camera.matrixWorld );
  10261. v2.setFromMatrixPosition( this.matrixWorld );
  10262. var distance = v1.distanceTo( v2 );
  10263. this.objects[ 0 ].object.visible = true;
  10264. for ( var i = 1, l = this.objects.length; i < l; i ++ ) {
  10265. if ( distance >= this.objects[ i ].distance ) {
  10266. this.objects[ i - 1 ].object.visible = false;
  10267. this.objects[ i ].object.visible = true;
  10268. } else {
  10269. break;
  10270. }
  10271. }
  10272. for ( ; i < l; i ++ ) {
  10273. this.objects[ i ].object.visible = false;
  10274. }
  10275. }
  10276. };
  10277. }();
  10278. THREE.LOD.prototype.clone = function ( object ) {
  10279. if ( object === undefined ) object = new THREE.LOD();
  10280. THREE.Object3D.prototype.clone.call( this, object );
  10281. for ( var i = 0, l = this.objects.length; i < l; i ++ ) {
  10282. var x = this.objects[ i ].object.clone();
  10283. x.visible = i === 0;
  10284. object.addLevel( x, this.objects[ i ].distance );
  10285. }
  10286. return object;
  10287. };
  10288. // File:src/objects/Sprite.js
  10289. /**
  10290. * @author mikael emtinger / http://gomo.se/
  10291. * @author alteredq / http://alteredqualia.com/
  10292. */
  10293. THREE.Sprite = ( function () {
  10294. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  10295. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  10296. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  10297. var geometry = new THREE.BufferGeometry();
  10298. geometry.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
  10299. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  10300. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  10301. return function ( material ) {
  10302. THREE.Object3D.call( this );
  10303. this.type = 'Sprite';
  10304. this.geometry = geometry;
  10305. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  10306. };
  10307. } )();
  10308. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  10309. THREE.Sprite.prototype.constructor = THREE.Sprite;
  10310. THREE.Sprite.prototype.raycast = ( function () {
  10311. var matrixPosition = new THREE.Vector3();
  10312. return function ( raycaster, intersects ) {
  10313. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  10314. var distance = raycaster.ray.distanceToPoint( matrixPosition );
  10315. if ( distance > this.scale.x ) {
  10316. return;
  10317. }
  10318. intersects.push( {
  10319. distance: distance,
  10320. point: this.position,
  10321. face: null,
  10322. object: this
  10323. } );
  10324. };
  10325. }() );
  10326. THREE.Sprite.prototype.clone = function ( object ) {
  10327. if ( object === undefined ) object = new THREE.Sprite( this.material );
  10328. THREE.Object3D.prototype.clone.call( this, object );
  10329. return object;
  10330. };
  10331. THREE.Sprite.prototype.toJSON = function ( meta ) {
  10332. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10333. // only serialize if not in meta materials cache
  10334. if ( meta.materials[ this.material.uuid ] === undefined ) {
  10335. meta.materials[ this.material.uuid ] = this.material.toJSON();
  10336. }
  10337. data.object.material = this.material.uuid;
  10338. return data;
  10339. };
  10340. // Backwards compatibility
  10341. THREE.Particle = THREE.Sprite;
  10342. // File:src/objects/LensFlare.js
  10343. /**
  10344. * @author mikael emtinger / http://gomo.se/
  10345. * @author alteredq / http://alteredqualia.com/
  10346. */
  10347. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  10348. THREE.Object3D.call( this );
  10349. this.lensFlares = [];
  10350. this.positionScreen = new THREE.Vector3();
  10351. this.customUpdateCallback = undefined;
  10352. if ( texture !== undefined ) {
  10353. this.add( texture, size, distance, blending, color );
  10354. }
  10355. };
  10356. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  10357. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  10358. /*
  10359. * Add: adds another flare
  10360. */
  10361. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  10362. if ( size === undefined ) size = - 1;
  10363. if ( distance === undefined ) distance = 0;
  10364. if ( opacity === undefined ) opacity = 1;
  10365. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  10366. if ( blending === undefined ) blending = THREE.NormalBlending;
  10367. distance = Math.min( distance, Math.max( 0, distance ) );
  10368. this.lensFlares.push( {
  10369. texture: texture, // THREE.Texture
  10370. size: size, // size in pixels (-1 = use texture.width)
  10371. distance: distance, // distance (0-1) from light source (0=at light source)
  10372. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is ontop z = 1 is back
  10373. scale: 1, // scale
  10374. rotation: 1, // rotation
  10375. opacity: opacity, // opacity
  10376. color: color, // color
  10377. blending: blending // blending
  10378. } );
  10379. };
  10380. /*
  10381. * Update lens flares update positions on all flares based on the screen position
  10382. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  10383. */
  10384. THREE.LensFlare.prototype.updateLensFlares = function () {
  10385. var f, fl = this.lensFlares.length;
  10386. var flare;
  10387. var vecX = - this.positionScreen.x * 2;
  10388. var vecY = - this.positionScreen.y * 2;
  10389. for ( f = 0; f < fl; f ++ ) {
  10390. flare = this.lensFlares[ f ];
  10391. flare.x = this.positionScreen.x + vecX * flare.distance;
  10392. flare.y = this.positionScreen.y + vecY * flare.distance;
  10393. flare.wantedRotation = flare.x * Math.PI * 0.25;
  10394. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  10395. }
  10396. };
  10397. // File:src/scenes/Scene.js
  10398. /**
  10399. * @author mrdoob / http://mrdoob.com/
  10400. */
  10401. THREE.Scene = function () {
  10402. THREE.Object3D.call( this );
  10403. this.type = 'Scene';
  10404. this.fog = null;
  10405. this.overrideMaterial = null;
  10406. this.autoUpdate = true; // checked by the renderer
  10407. };
  10408. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  10409. THREE.Scene.prototype.constructor = THREE.Scene;
  10410. THREE.Scene.prototype.clone = function ( object ) {
  10411. if ( object === undefined ) object = new THREE.Scene();
  10412. THREE.Object3D.prototype.clone.call( this, object );
  10413. if ( this.fog !== null ) object.fog = this.fog.clone();
  10414. if ( this.overrideMaterial !== null ) object.overrideMaterial = this.overrideMaterial.clone();
  10415. object.autoUpdate = this.autoUpdate;
  10416. object.matrixAutoUpdate = this.matrixAutoUpdate;
  10417. return object;
  10418. };
  10419. // File:src/scenes/Fog.js
  10420. /**
  10421. * @author mrdoob / http://mrdoob.com/
  10422. * @author alteredq / http://alteredqualia.com/
  10423. */
  10424. THREE.Fog = function ( color, near, far ) {
  10425. this.name = '';
  10426. this.color = new THREE.Color( color );
  10427. this.near = ( near !== undefined ) ? near : 1;
  10428. this.far = ( far !== undefined ) ? far : 1000;
  10429. };
  10430. THREE.Fog.prototype.clone = function () {
  10431. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  10432. };
  10433. // File:src/scenes/FogExp2.js
  10434. /**
  10435. * @author mrdoob / http://mrdoob.com/
  10436. * @author alteredq / http://alteredqualia.com/
  10437. */
  10438. THREE.FogExp2 = function ( color, density ) {
  10439. this.name = '';
  10440. this.color = new THREE.Color( color );
  10441. this.density = ( density !== undefined ) ? density : 0.00025;
  10442. };
  10443. THREE.FogExp2.prototype.clone = function () {
  10444. return new THREE.FogExp2( this.color.getHex(), this.density );
  10445. };
  10446. // File:src/renderers/shaders/ShaderChunk.js
  10447. THREE.ShaderChunk = {};
  10448. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  10449. THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n\n#endif\n";
  10450. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  10451. THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n\n uniform sampler2D alphaMap;\n\n#endif\n";
  10452. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  10453. THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n\n if ( diffuseColor.a < ALPHATEST ) discard;\n\n#endif\n";
  10454. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  10455. THREE.ShaderChunk[ 'aomap_fragment'] = "#ifdef USE_AOMAP\n\n totalAmbientLight *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n#endif\n";
  10456. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  10457. THREE.ShaderChunk[ 'aomap_pars_fragment'] = "#ifdef USE_AOMAP\n\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n\n#endif";
  10458. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  10459. 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";
  10460. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  10461. THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n\n diffuseColor.rgb *= vColor;\n\n#endif";
  10462. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  10463. THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif\n";
  10464. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  10465. THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif";
  10466. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  10467. THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n\n vColor.xyz = inputToLinear( color.xyz );\n\n#endif";
  10468. // File:src/renderers/shaders/ShaderChunk/common.glsl
  10469. 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";
  10470. // File:src/renderers/shaders/ShaderChunk/default_vertex.glsl
  10471. 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";
  10472. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  10473. 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";
  10474. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  10475. 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";
  10476. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  10477. 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";
  10478. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  10479. 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";
  10480. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  10481. 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";
  10482. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  10483. 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";
  10484. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  10485. 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";
  10486. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  10487. THREE.ShaderChunk[ 'lightmap_fragment'] = "#ifdef USE_LIGHTMAP\n\n totalAmbientLight += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\n#endif\n";
  10488. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  10489. THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n\n#endif";
  10490. // File:src/renderers/shaders/ShaderChunk/lights_lambert_pars_vertex.glsl
  10491. 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";
  10492. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  10493. 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";
  10494. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  10495. 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 + emissive;\n\n#else\n\n outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) + totalSpecularLight + emissive;\n\n#endif\n";
  10496. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  10497. 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";
  10498. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  10499. 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";
  10500. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  10501. THREE.ShaderChunk[ 'lights_phong_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n vWorldPosition = worldPosition.xyz;\n\n#endif";
  10502. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  10503. THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  10504. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  10505. THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n\n#endif";
  10506. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  10507. 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";
  10508. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  10509. 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";
  10510. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  10511. 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";
  10512. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  10513. 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";
  10514. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  10515. THREE.ShaderChunk[ 'map_pars_fragment'] = "#ifdef USE_MAP\n\n uniform sampler2D map;\n\n#endif";
  10516. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  10517. 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";
  10518. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  10519. THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n\n#endif\n";
  10520. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  10521. 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";
  10522. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  10523. 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";
  10524. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  10525. 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";
  10526. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  10527. 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";
  10528. // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  10529. 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 // NOTE: I am unsure if this is correct in linear space. -bhouston, Dec 29, 2014\n shadowColor = inputToLinear( shadowColor );\n\n outgoingLight = outgoingLight * shadowColor;\n\n#endif\n";
  10530. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  10531. 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";
  10532. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  10533. THREE.ShaderChunk[ 'shadowmap_pars_vertex'] = "#ifdef USE_SHADOWMAP\n\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n uniform mat4 shadowMatrix[ MAX_SHADOWS ];\n\n#endif";
  10534. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  10535. 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";
  10536. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  10537. 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";
  10538. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  10539. 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";
  10540. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  10541. 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";
  10542. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  10543. 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";
  10544. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  10545. 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";
  10546. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  10547. THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n\n uniform sampler2D specularMap;\n\n#endif";
  10548. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  10549. THREE.ShaderChunk[ 'uv2_pars_fragment'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n varying vec2 vUv2;\n\n#endif";
  10550. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  10551. THREE.ShaderChunk[ 'uv2_pars_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n attribute vec2 uv2;\n varying vec2 vUv2;\n\n#endif";
  10552. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  10553. THREE.ShaderChunk[ 'uv2_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n vUv2 = uv2;\n\n#endif";
  10554. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  10555. THREE.ShaderChunk[ 'uv_pars_fragment'] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP )\n\n varying vec2 vUv;\n\n#endif";
  10556. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  10557. THREE.ShaderChunk[ 'uv_pars_vertex'] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP )\n\n varying vec2 vUv;\n uniform vec4 offsetRepeat;\n\n#endif\n";
  10558. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  10559. THREE.ShaderChunk[ 'uv_vertex'] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP )\n\n vUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n\n#endif";
  10560. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  10561. 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";
  10562. // File:src/renderers/shaders/UniformsUtils.js
  10563. /**
  10564. * Uniform Utilities
  10565. */
  10566. THREE.UniformsUtils = {
  10567. merge: function ( uniforms ) {
  10568. var merged = {};
  10569. for ( var u = 0; u < uniforms.length; u ++ ) {
  10570. var tmp = this.clone( uniforms[ u ] );
  10571. for ( var p in tmp ) {
  10572. merged[ p ] = tmp[ p ];
  10573. }
  10574. }
  10575. return merged;
  10576. },
  10577. clone: function ( uniforms_src ) {
  10578. var uniforms_dst = {};
  10579. for ( var u in uniforms_src ) {
  10580. uniforms_dst[ u ] = {};
  10581. for ( var p in uniforms_src[ u ] ) {
  10582. var parameter_src = uniforms_src[ u ][ p ];
  10583. if ( parameter_src instanceof THREE.Color ||
  10584. parameter_src instanceof THREE.Vector2 ||
  10585. parameter_src instanceof THREE.Vector3 ||
  10586. parameter_src instanceof THREE.Vector4 ||
  10587. parameter_src instanceof THREE.Matrix3 ||
  10588. parameter_src instanceof THREE.Matrix4 ||
  10589. parameter_src instanceof THREE.Texture ) {
  10590. uniforms_dst[ u ][ p ] = parameter_src.clone();
  10591. } else if ( Array.isArray( parameter_src ) ) {
  10592. uniforms_dst[ u ][ p ] = parameter_src.slice();
  10593. } else {
  10594. uniforms_dst[ u ][ p ] = parameter_src;
  10595. }
  10596. }
  10597. }
  10598. return uniforms_dst;
  10599. }
  10600. };
  10601. // File:src/renderers/shaders/UniformsLib.js
  10602. /**
  10603. * Uniforms library for shared webgl shaders
  10604. */
  10605. THREE.UniformsLib = {
  10606. common: {
  10607. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  10608. "opacity" : { type: "f", value: 1.0 },
  10609. "map" : { type: "t", value: null },
  10610. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  10611. "specularMap" : { type: "t", value: null },
  10612. "alphaMap" : { type: "t", value: null },
  10613. "envMap" : { type: "t", value: null },
  10614. "flipEnvMap" : { type: "f", value: - 1 },
  10615. "reflectivity" : { type: "f", value: 1.0 },
  10616. "refractionRatio" : { type: "f", value: 0.98 }
  10617. },
  10618. aomap: {
  10619. "aoMap" : { type: "t", value: null },
  10620. "aoMapIntensity" : { type: "f", value: 1 },
  10621. },
  10622. lightmap: {
  10623. "lightMap" : { type: "t", value: null },
  10624. "lightMapIntensity" : { type: "f", value: 1 },
  10625. },
  10626. bump: {
  10627. "bumpMap" : { type: "t", value: null },
  10628. "bumpScale" : { type: "f", value: 1 }
  10629. },
  10630. normalmap: {
  10631. "normalMap" : { type: "t", value: null },
  10632. "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  10633. },
  10634. fog : {
  10635. "fogDensity" : { type: "f", value: 0.00025 },
  10636. "fogNear" : { type: "f", value: 1 },
  10637. "fogFar" : { type: "f", value: 2000 },
  10638. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  10639. },
  10640. lights: {
  10641. "ambientLightColor" : { type: "fv", value: [] },
  10642. "directionalLightDirection" : { type: "fv", value: [] },
  10643. "directionalLightColor" : { type: "fv", value: [] },
  10644. "hemisphereLightDirection" : { type: "fv", value: [] },
  10645. "hemisphereLightSkyColor" : { type: "fv", value: [] },
  10646. "hemisphereLightGroundColor" : { type: "fv", value: [] },
  10647. "pointLightColor" : { type: "fv", value: [] },
  10648. "pointLightPosition" : { type: "fv", value: [] },
  10649. "pointLightDistance" : { type: "fv1", value: [] },
  10650. "pointLightDecay" : { type: "fv1", value: [] },
  10651. "spotLightColor" : { type: "fv", value: [] },
  10652. "spotLightPosition" : { type: "fv", value: [] },
  10653. "spotLightDirection" : { type: "fv", value: [] },
  10654. "spotLightDistance" : { type: "fv1", value: [] },
  10655. "spotLightAngleCos" : { type: "fv1", value: [] },
  10656. "spotLightExponent" : { type: "fv1", value: [] },
  10657. "spotLightDecay" : { type: "fv1", value: [] }
  10658. },
  10659. particle: {
  10660. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  10661. "opacity" : { type: "f", value: 1.0 },
  10662. "size" : { type: "f", value: 1.0 },
  10663. "scale" : { type: "f", value: 1.0 },
  10664. "map" : { type: "t", value: null },
  10665. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  10666. "fogDensity" : { type: "f", value: 0.00025 },
  10667. "fogNear" : { type: "f", value: 1 },
  10668. "fogFar" : { type: "f", value: 2000 },
  10669. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  10670. },
  10671. shadowmap: {
  10672. "shadowMap": { type: "tv", value: [] },
  10673. "shadowMapSize": { type: "v2v", value: [] },
  10674. "shadowBias" : { type: "fv1", value: [] },
  10675. "shadowDarkness": { type: "fv1", value: [] },
  10676. "shadowMatrix" : { type: "m4v", value: [] }
  10677. }
  10678. };
  10679. // File:src/renderers/shaders/ShaderLib.js
  10680. /**
  10681. * Webgl Shader Library for three.js
  10682. *
  10683. * @author alteredq / http://alteredqualia.com/
  10684. * @author mrdoob / http://mrdoob.com/
  10685. * @author mikael emtinger / http://gomo.se/
  10686. */
  10687. THREE.ShaderLib = {
  10688. 'basic': {
  10689. uniforms: THREE.UniformsUtils.merge( [
  10690. THREE.UniformsLib[ "common" ],
  10691. THREE.UniformsLib[ "fog" ],
  10692. THREE.UniformsLib[ "shadowmap" ]
  10693. ] ),
  10694. vertexShader: [
  10695. THREE.ShaderChunk[ "common" ],
  10696. THREE.ShaderChunk[ "uv_pars_vertex" ],
  10697. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  10698. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  10699. THREE.ShaderChunk[ "color_pars_vertex" ],
  10700. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  10701. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  10702. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  10703. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  10704. "void main() {",
  10705. THREE.ShaderChunk[ "uv_vertex" ],
  10706. THREE.ShaderChunk[ "uv2_vertex" ],
  10707. THREE.ShaderChunk[ "color_vertex" ],
  10708. THREE.ShaderChunk[ "skinbase_vertex" ],
  10709. " #ifdef USE_ENVMAP",
  10710. THREE.ShaderChunk[ "morphnormal_vertex" ],
  10711. THREE.ShaderChunk[ "skinnormal_vertex" ],
  10712. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  10713. " #endif",
  10714. THREE.ShaderChunk[ "morphtarget_vertex" ],
  10715. THREE.ShaderChunk[ "skinning_vertex" ],
  10716. THREE.ShaderChunk[ "default_vertex" ],
  10717. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  10718. THREE.ShaderChunk[ "worldpos_vertex" ],
  10719. THREE.ShaderChunk[ "envmap_vertex" ],
  10720. THREE.ShaderChunk[ "shadowmap_vertex" ],
  10721. "}"
  10722. ].join("\n"),
  10723. fragmentShader: [
  10724. "uniform vec3 diffuse;",
  10725. "uniform float opacity;",
  10726. THREE.ShaderChunk[ "common" ],
  10727. THREE.ShaderChunk[ "color_pars_fragment" ],
  10728. THREE.ShaderChunk[ "uv_pars_fragment" ],
  10729. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  10730. THREE.ShaderChunk[ "map_pars_fragment" ],
  10731. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  10732. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  10733. THREE.ShaderChunk[ "fog_pars_fragment" ],
  10734. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  10735. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  10736. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  10737. "void main() {",
  10738. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  10739. " vec4 diffuseColor = vec4( diffuse, opacity );",
  10740. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  10741. THREE.ShaderChunk[ "map_fragment" ],
  10742. THREE.ShaderChunk[ "color_fragment" ],
  10743. THREE.ShaderChunk[ "alphamap_fragment" ],
  10744. THREE.ShaderChunk[ "alphatest_fragment" ],
  10745. THREE.ShaderChunk[ "specularmap_fragment" ],
  10746. " outgoingLight = diffuseColor.rgb;", // simple shader
  10747. THREE.ShaderChunk[ "envmap_fragment" ],
  10748. THREE.ShaderChunk[ "shadowmap_fragment" ], // TODO: Shadows on an otherwise unlit surface doesn't make sense.
  10749. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  10750. THREE.ShaderChunk[ "fog_fragment" ],
  10751. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
  10752. "}"
  10753. ].join("\n")
  10754. },
  10755. 'lambert': {
  10756. uniforms: THREE.UniformsUtils.merge( [
  10757. THREE.UniformsLib[ "common" ],
  10758. THREE.UniformsLib[ "fog" ],
  10759. THREE.UniformsLib[ "lights" ],
  10760. THREE.UniformsLib[ "shadowmap" ],
  10761. {
  10762. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  10763. }
  10764. ] ),
  10765. vertexShader: [
  10766. "#define LAMBERT",
  10767. "varying vec3 vLightFront;",
  10768. "#ifdef DOUBLE_SIDED",
  10769. " varying vec3 vLightBack;",
  10770. "#endif",
  10771. THREE.ShaderChunk[ "common" ],
  10772. THREE.ShaderChunk[ "uv_pars_vertex" ],
  10773. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  10774. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  10775. THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
  10776. THREE.ShaderChunk[ "color_pars_vertex" ],
  10777. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  10778. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  10779. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  10780. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  10781. "void main() {",
  10782. THREE.ShaderChunk[ "uv_vertex" ],
  10783. THREE.ShaderChunk[ "uv2_vertex" ],
  10784. THREE.ShaderChunk[ "color_vertex" ],
  10785. THREE.ShaderChunk[ "morphnormal_vertex" ],
  10786. THREE.ShaderChunk[ "skinbase_vertex" ],
  10787. THREE.ShaderChunk[ "skinnormal_vertex" ],
  10788. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  10789. THREE.ShaderChunk[ "morphtarget_vertex" ],
  10790. THREE.ShaderChunk[ "skinning_vertex" ],
  10791. THREE.ShaderChunk[ "default_vertex" ],
  10792. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  10793. THREE.ShaderChunk[ "worldpos_vertex" ],
  10794. THREE.ShaderChunk[ "envmap_vertex" ],
  10795. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  10796. THREE.ShaderChunk[ "shadowmap_vertex" ],
  10797. "}"
  10798. ].join("\n"),
  10799. fragmentShader: [
  10800. "uniform vec3 diffuse;",
  10801. "uniform vec3 emissive;",
  10802. "uniform float opacity;",
  10803. "varying vec3 vLightFront;",
  10804. "#ifdef DOUBLE_SIDED",
  10805. " varying vec3 vLightBack;",
  10806. "#endif",
  10807. THREE.ShaderChunk[ "common" ],
  10808. THREE.ShaderChunk[ "color_pars_fragment" ],
  10809. THREE.ShaderChunk[ "uv_pars_fragment" ],
  10810. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  10811. THREE.ShaderChunk[ "map_pars_fragment" ],
  10812. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  10813. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  10814. THREE.ShaderChunk[ "fog_pars_fragment" ],
  10815. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  10816. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  10817. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  10818. "void main() {",
  10819. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  10820. " vec4 diffuseColor = vec4( diffuse, opacity );",
  10821. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  10822. THREE.ShaderChunk[ "map_fragment" ],
  10823. THREE.ShaderChunk[ "color_fragment" ],
  10824. THREE.ShaderChunk[ "alphamap_fragment" ],
  10825. THREE.ShaderChunk[ "alphatest_fragment" ],
  10826. THREE.ShaderChunk[ "specularmap_fragment" ],
  10827. " #ifdef DOUBLE_SIDED",
  10828. //"float isFront = float( gl_FrontFacing );",
  10829. //"gl_FragColor.xyz *= isFront * vLightFront + ( 1.0 - isFront ) * vLightBack;",
  10830. " if ( gl_FrontFacing )",
  10831. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  10832. " else",
  10833. " outgoingLight += diffuseColor.rgb * vLightBack + emissive;",
  10834. " #else",
  10835. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  10836. " #endif",
  10837. THREE.ShaderChunk[ "envmap_fragment" ],
  10838. THREE.ShaderChunk[ "shadowmap_fragment" ],
  10839. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  10840. THREE.ShaderChunk[ "fog_fragment" ],
  10841. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
  10842. "}"
  10843. ].join("\n")
  10844. },
  10845. 'phong': {
  10846. uniforms: THREE.UniformsUtils.merge( [
  10847. THREE.UniformsLib[ "common" ],
  10848. THREE.UniformsLib[ "aomap" ],
  10849. THREE.UniformsLib[ "lightmap" ],
  10850. THREE.UniformsLib[ "bump" ],
  10851. THREE.UniformsLib[ "normalmap" ],
  10852. THREE.UniformsLib[ "fog" ],
  10853. THREE.UniformsLib[ "lights" ],
  10854. THREE.UniformsLib[ "shadowmap" ],
  10855. {
  10856. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  10857. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  10858. "shininess": { type: "f", value: 30 }
  10859. }
  10860. ] ),
  10861. vertexShader: [
  10862. "#define PHONG",
  10863. "varying vec3 vViewPosition;",
  10864. "#ifndef FLAT_SHADED",
  10865. " varying vec3 vNormal;",
  10866. "#endif",
  10867. THREE.ShaderChunk[ "common" ],
  10868. THREE.ShaderChunk[ "uv_pars_vertex" ],
  10869. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  10870. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  10871. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  10872. THREE.ShaderChunk[ "color_pars_vertex" ],
  10873. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  10874. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  10875. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  10876. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  10877. "void main() {",
  10878. THREE.ShaderChunk[ "uv_vertex" ],
  10879. THREE.ShaderChunk[ "uv2_vertex" ],
  10880. THREE.ShaderChunk[ "color_vertex" ],
  10881. THREE.ShaderChunk[ "morphnormal_vertex" ],
  10882. THREE.ShaderChunk[ "skinbase_vertex" ],
  10883. THREE.ShaderChunk[ "skinnormal_vertex" ],
  10884. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  10885. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  10886. " vNormal = normalize( transformedNormal );",
  10887. "#endif",
  10888. THREE.ShaderChunk[ "morphtarget_vertex" ],
  10889. THREE.ShaderChunk[ "skinning_vertex" ],
  10890. THREE.ShaderChunk[ "default_vertex" ],
  10891. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  10892. " vViewPosition = -mvPosition.xyz;",
  10893. THREE.ShaderChunk[ "worldpos_vertex" ],
  10894. THREE.ShaderChunk[ "envmap_vertex" ],
  10895. THREE.ShaderChunk[ "lights_phong_vertex" ],
  10896. THREE.ShaderChunk[ "shadowmap_vertex" ],
  10897. "}"
  10898. ].join("\n"),
  10899. fragmentShader: [
  10900. "#define PHONG",
  10901. "uniform vec3 diffuse;",
  10902. "uniform vec3 emissive;",
  10903. "uniform vec3 specular;",
  10904. "uniform float shininess;",
  10905. "uniform float opacity;",
  10906. THREE.ShaderChunk[ "common" ],
  10907. THREE.ShaderChunk[ "color_pars_fragment" ],
  10908. THREE.ShaderChunk[ "uv_pars_fragment" ],
  10909. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  10910. THREE.ShaderChunk[ "map_pars_fragment" ],
  10911. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  10912. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  10913. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  10914. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  10915. THREE.ShaderChunk[ "fog_pars_fragment" ],
  10916. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  10917. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  10918. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  10919. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  10920. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  10921. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  10922. "void main() {",
  10923. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  10924. " vec4 diffuseColor = vec4( diffuse, opacity );",
  10925. " vec3 totalAmbientLight = ambientLightColor;",
  10926. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  10927. THREE.ShaderChunk[ "map_fragment" ],
  10928. THREE.ShaderChunk[ "color_fragment" ],
  10929. THREE.ShaderChunk[ "alphamap_fragment" ],
  10930. THREE.ShaderChunk[ "alphatest_fragment" ],
  10931. THREE.ShaderChunk[ "specularmap_fragment" ],
  10932. THREE.ShaderChunk[ "lightmap_fragment" ],
  10933. THREE.ShaderChunk[ "aomap_fragment" ],
  10934. THREE.ShaderChunk[ "lights_phong_fragment" ],
  10935. THREE.ShaderChunk[ "envmap_fragment" ],
  10936. THREE.ShaderChunk[ "shadowmap_fragment" ],
  10937. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  10938. THREE.ShaderChunk[ "fog_fragment" ],
  10939. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
  10940. "}"
  10941. ].join("\n")
  10942. },
  10943. 'particle_basic': {
  10944. uniforms: THREE.UniformsUtils.merge( [
  10945. THREE.UniformsLib[ "particle" ],
  10946. THREE.UniformsLib[ "shadowmap" ]
  10947. ] ),
  10948. vertexShader: [
  10949. "uniform float size;",
  10950. "uniform float scale;",
  10951. THREE.ShaderChunk[ "common" ],
  10952. THREE.ShaderChunk[ "color_pars_vertex" ],
  10953. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  10954. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  10955. "void main() {",
  10956. THREE.ShaderChunk[ "color_vertex" ],
  10957. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  10958. " #ifdef USE_SIZEATTENUATION",
  10959. " gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
  10960. " #else",
  10961. " gl_PointSize = size;",
  10962. " #endif",
  10963. " gl_Position = projectionMatrix * mvPosition;",
  10964. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  10965. THREE.ShaderChunk[ "worldpos_vertex" ],
  10966. THREE.ShaderChunk[ "shadowmap_vertex" ],
  10967. "}"
  10968. ].join("\n"),
  10969. fragmentShader: [
  10970. "uniform vec3 psColor;",
  10971. "uniform float opacity;",
  10972. THREE.ShaderChunk[ "common" ],
  10973. THREE.ShaderChunk[ "color_pars_fragment" ],
  10974. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  10975. THREE.ShaderChunk[ "fog_pars_fragment" ],
  10976. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  10977. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  10978. "void main() {",
  10979. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  10980. " vec4 diffuseColor = vec4( psColor, opacity );",
  10981. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  10982. THREE.ShaderChunk[ "map_particle_fragment" ],
  10983. THREE.ShaderChunk[ "color_fragment" ],
  10984. THREE.ShaderChunk[ "alphatest_fragment" ],
  10985. " outgoingLight = diffuseColor.rgb;", // simple shader
  10986. THREE.ShaderChunk[ "shadowmap_fragment" ],
  10987. THREE.ShaderChunk[ "fog_fragment" ],
  10988. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
  10989. "}"
  10990. ].join("\n")
  10991. },
  10992. 'dashed': {
  10993. uniforms: THREE.UniformsUtils.merge( [
  10994. THREE.UniformsLib[ "common" ],
  10995. THREE.UniformsLib[ "fog" ],
  10996. {
  10997. "scale" : { type: "f", value: 1 },
  10998. "dashSize" : { type: "f", value: 1 },
  10999. "totalSize": { type: "f", value: 2 }
  11000. }
  11001. ] ),
  11002. vertexShader: [
  11003. "uniform float scale;",
  11004. "attribute float lineDistance;",
  11005. "varying float vLineDistance;",
  11006. THREE.ShaderChunk[ "common" ],
  11007. THREE.ShaderChunk[ "color_pars_vertex" ],
  11008. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11009. "void main() {",
  11010. THREE.ShaderChunk[ "color_vertex" ],
  11011. " vLineDistance = scale * lineDistance;",
  11012. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  11013. " gl_Position = projectionMatrix * mvPosition;",
  11014. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11015. "}"
  11016. ].join("\n"),
  11017. fragmentShader: [
  11018. "uniform vec3 diffuse;",
  11019. "uniform float opacity;",
  11020. "uniform float dashSize;",
  11021. "uniform float totalSize;",
  11022. "varying float vLineDistance;",
  11023. THREE.ShaderChunk[ "common" ],
  11024. THREE.ShaderChunk[ "color_pars_fragment" ],
  11025. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11026. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11027. "void main() {",
  11028. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  11029. " discard;",
  11030. " }",
  11031. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  11032. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11033. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11034. THREE.ShaderChunk[ "color_fragment" ],
  11035. " outgoingLight = diffuseColor.rgb;", // simple shader
  11036. THREE.ShaderChunk[ "fog_fragment" ],
  11037. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
  11038. "}"
  11039. ].join("\n")
  11040. },
  11041. 'depth': {
  11042. uniforms: {
  11043. "mNear": { type: "f", value: 1.0 },
  11044. "mFar" : { type: "f", value: 2000.0 },
  11045. "opacity" : { type: "f", value: 1.0 }
  11046. },
  11047. vertexShader: [
  11048. THREE.ShaderChunk[ "common" ],
  11049. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11050. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11051. "void main() {",
  11052. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11053. THREE.ShaderChunk[ "default_vertex" ],
  11054. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11055. "}"
  11056. ].join("\n"),
  11057. fragmentShader: [
  11058. "uniform float mNear;",
  11059. "uniform float mFar;",
  11060. "uniform float opacity;",
  11061. THREE.ShaderChunk[ "common" ],
  11062. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11063. "void main() {",
  11064. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11065. " #ifdef USE_LOGDEPTHBUF_EXT",
  11066. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  11067. " #else",
  11068. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  11069. " #endif",
  11070. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  11071. " gl_FragColor = vec4( vec3( color ), opacity );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
  11072. "}"
  11073. ].join("\n")
  11074. },
  11075. 'normal': {
  11076. uniforms: {
  11077. "opacity" : { type: "f", value: 1.0 }
  11078. },
  11079. vertexShader: [
  11080. "varying vec3 vNormal;",
  11081. THREE.ShaderChunk[ "common" ],
  11082. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11083. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11084. "void main() {",
  11085. " vNormal = normalize( normalMatrix * normal );",
  11086. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11087. THREE.ShaderChunk[ "default_vertex" ],
  11088. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11089. "}"
  11090. ].join("\n"),
  11091. fragmentShader: [
  11092. "uniform float opacity;",
  11093. "varying vec3 vNormal;",
  11094. THREE.ShaderChunk[ "common" ],
  11095. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11096. "void main() {",
  11097. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  11098. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11099. "}"
  11100. ].join("\n")
  11101. },
  11102. /* -------------------------------------------------------------------------
  11103. // Cube map shader
  11104. ------------------------------------------------------------------------- */
  11105. 'cube': {
  11106. uniforms: { "tCube": { type: "t", value: null },
  11107. "tFlip": { type: "f", value: - 1 } },
  11108. vertexShader: [
  11109. "varying vec3 vWorldPosition;",
  11110. THREE.ShaderChunk[ "common" ],
  11111. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11112. "void main() {",
  11113. " vWorldPosition = transformDirection( position, modelMatrix );",
  11114. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  11115. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11116. "}"
  11117. ].join("\n"),
  11118. fragmentShader: [
  11119. "uniform samplerCube tCube;",
  11120. "uniform float tFlip;",
  11121. "varying vec3 vWorldPosition;",
  11122. THREE.ShaderChunk[ "common" ],
  11123. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11124. "void main() {",
  11125. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  11126. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11127. "}"
  11128. ].join("\n")
  11129. },
  11130. /* -------------------------------------------------------------------------
  11131. // Cube map shader
  11132. ------------------------------------------------------------------------- */
  11133. 'equirect': {
  11134. uniforms: { "tEquirect": { type: "t", value: null },
  11135. "tFlip": { type: "f", value: - 1 } },
  11136. vertexShader: [
  11137. "varying vec3 vWorldPosition;",
  11138. THREE.ShaderChunk[ "common" ],
  11139. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11140. "void main() {",
  11141. " vWorldPosition = transformDirection( position, modelMatrix );",
  11142. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  11143. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11144. "}"
  11145. ].join("\n"),
  11146. fragmentShader: [
  11147. "uniform sampler2D tEquirect;",
  11148. "uniform float tFlip;",
  11149. "varying vec3 vWorldPosition;",
  11150. THREE.ShaderChunk[ "common" ],
  11151. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11152. "void main() {",
  11153. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  11154. "vec3 direction = normalize( vWorldPosition );",
  11155. "vec2 sampleUV;",
  11156. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  11157. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  11158. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  11159. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11160. "}"
  11161. ].join("\n")
  11162. },
  11163. /* Depth encoding into RGBA texture
  11164. *
  11165. * based on SpiderGL shadow map example
  11166. * http://spidergl.org/example.php?id=6
  11167. *
  11168. * originally from
  11169. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  11170. *
  11171. * see also
  11172. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  11173. */
  11174. 'depthRGBA': {
  11175. uniforms: {},
  11176. vertexShader: [
  11177. THREE.ShaderChunk[ "common" ],
  11178. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11179. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11180. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11181. "void main() {",
  11182. THREE.ShaderChunk[ "skinbase_vertex" ],
  11183. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11184. THREE.ShaderChunk[ "skinning_vertex" ],
  11185. THREE.ShaderChunk[ "default_vertex" ],
  11186. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11187. "}"
  11188. ].join("\n"),
  11189. fragmentShader: [
  11190. THREE.ShaderChunk[ "common" ],
  11191. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11192. "vec4 pack_depth( const in float depth ) {",
  11193. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  11194. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  11195. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
  11196. " res -= res.xxyz * bit_mask;",
  11197. " return res;",
  11198. "}",
  11199. "void main() {",
  11200. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11201. " #ifdef USE_LOGDEPTHBUF_EXT",
  11202. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  11203. " #else",
  11204. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  11205. " #endif",
  11206. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  11207. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  11208. //"gl_FragData[ 0 ] = pack_depth( z );",
  11209. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  11210. "}"
  11211. ].join("\n")
  11212. }
  11213. };
  11214. // File:src/renderers/WebGLRenderer.js
  11215. /**
  11216. * @author supereggbert / http://www.paulbrunt.co.uk/
  11217. * @author mrdoob / http://mrdoob.com/
  11218. * @author alteredq / http://alteredqualia.com/
  11219. * @author szimek / https://github.com/szimek/
  11220. */
  11221. THREE.WebGLRenderer = function ( parameters ) {
  11222. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  11223. parameters = parameters || {};
  11224. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  11225. _context = parameters.context !== undefined ? parameters.context : null,
  11226. _width = _canvas.width,
  11227. _height = _canvas.height,
  11228. pixelRatio = 1,
  11229. _precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  11230. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  11231. _depth = parameters.depth !== undefined ? parameters.depth : true,
  11232. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  11233. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  11234. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  11235. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  11236. _logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false,
  11237. _clearColor = new THREE.Color( 0x000000 ),
  11238. _clearAlpha = 0;
  11239. var lights = [];
  11240. var opaqueObjects = [];
  11241. var transparentObjects = [];
  11242. var sprites = [];
  11243. var lensFlares = [];
  11244. // public properties
  11245. this.domElement = _canvas;
  11246. this.context = null;
  11247. // clearing
  11248. this.autoClear = true;
  11249. this.autoClearColor = true;
  11250. this.autoClearDepth = true;
  11251. this.autoClearStencil = true;
  11252. // scene graph
  11253. this.sortObjects = true;
  11254. // physically based shading
  11255. this.gammaFactor = 2.0; // for backwards compatibility
  11256. this.gammaInput = false;
  11257. this.gammaOutput = false;
  11258. // morphs
  11259. this.maxMorphTargets = 8;
  11260. this.maxMorphNormals = 4;
  11261. // flags
  11262. this.autoScaleCubemaps = true;
  11263. // info
  11264. this.info = {
  11265. memory: {
  11266. programs: 0,
  11267. geometries: 0,
  11268. textures: 0
  11269. },
  11270. render: {
  11271. calls: 0,
  11272. vertices: 0,
  11273. faces: 0,
  11274. points: 0
  11275. }
  11276. };
  11277. // internal properties
  11278. var _this = this,
  11279. _programs = [],
  11280. // internal state cache
  11281. _currentProgram = null,
  11282. _currentFramebuffer = null,
  11283. _currentMaterialId = - 1,
  11284. _currentGeometryProgram = '',
  11285. _currentCamera = null,
  11286. _usedTextureUnits = 0,
  11287. _viewportX = 0,
  11288. _viewportY = 0,
  11289. _viewportWidth = _canvas.width,
  11290. _viewportHeight = _canvas.height,
  11291. _currentWidth = 0,
  11292. _currentHeight = 0,
  11293. // frustum
  11294. _frustum = new THREE.Frustum(),
  11295. // camera matrices cache
  11296. _projScreenMatrix = new THREE.Matrix4(),
  11297. _vector3 = new THREE.Vector3(),
  11298. // light arrays cache
  11299. _direction = new THREE.Vector3(),
  11300. _lightsNeedUpdate = true,
  11301. _lights = {
  11302. ambient: [ 0, 0, 0 ],
  11303. directional: { length: 0, colors:[], positions: [] },
  11304. point: { length: 0, colors: [], positions: [], distances: [], decays: [] },
  11305. spot: { length: 0, colors: [], positions: [], distances: [], directions: [], anglesCos: [], exponents: [], decays: [] },
  11306. hemi: { length: 0, skyColors: [], groundColors: [], positions: [] }
  11307. };
  11308. // initialize
  11309. var _gl;
  11310. try {
  11311. var attributes = {
  11312. alpha: _alpha,
  11313. depth: _depth,
  11314. stencil: _stencil,
  11315. antialias: _antialias,
  11316. premultipliedAlpha: _premultipliedAlpha,
  11317. preserveDrawingBuffer: _preserveDrawingBuffer
  11318. };
  11319. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  11320. if ( _gl === null ) {
  11321. if ( _canvas.getContext( 'webgl') !== null ) {
  11322. throw 'Error creating WebGL context with your selected attributes.';
  11323. } else {
  11324. throw 'Error creating WebGL context.';
  11325. }
  11326. }
  11327. _canvas.addEventListener( 'webglcontextlost', function ( event ) {
  11328. event.preventDefault();
  11329. resetGLState();
  11330. setDefaultGLState();
  11331. objects.objects = {};
  11332. }, false);
  11333. } catch ( error ) {
  11334. console.error( 'THREE.WebGLRenderer: ' + error );
  11335. }
  11336. var state = new THREE.WebGLState( _gl, paramThreeToGL );
  11337. if ( _gl.getShaderPrecisionFormat === undefined ) {
  11338. _gl.getShaderPrecisionFormat = function () {
  11339. return {
  11340. 'rangeMin': 1,
  11341. 'rangeMax': 1,
  11342. 'precision': 1
  11343. };
  11344. }
  11345. }
  11346. var extensions = new THREE.WebGLExtensions( _gl );
  11347. var objects = new THREE.WebGLObjects( _gl, this.info );
  11348. extensions.get( 'OES_texture_float' );
  11349. extensions.get( 'OES_texture_float_linear' );
  11350. extensions.get( 'OES_texture_half_float' );
  11351. extensions.get( 'OES_texture_half_float_linear' );
  11352. extensions.get( 'OES_standard_derivatives' );
  11353. extensions.get( 'ANGLE_instanced_arrays' );
  11354. if ( extensions.get( 'OES_element_index_uint' ) ) {
  11355. THREE.BufferGeometry.MaxIndex = 4294967296;
  11356. }
  11357. if ( _logarithmicDepthBuffer ) {
  11358. extensions.get( 'EXT_frag_depth' );
  11359. }
  11360. //
  11361. var glClearColor = function ( r, g, b, a ) {
  11362. if ( _premultipliedAlpha === true ) {
  11363. r *= a; g *= a; b *= a;
  11364. }
  11365. _gl.clearColor( r, g, b, a );
  11366. };
  11367. var setDefaultGLState = function () {
  11368. _gl.clearColor( 0, 0, 0, 1 );
  11369. _gl.clearDepth( 1 );
  11370. _gl.clearStencil( 0 );
  11371. _gl.enable( _gl.DEPTH_TEST );
  11372. _gl.depthFunc( _gl.LEQUAL );
  11373. _gl.frontFace( _gl.CCW );
  11374. _gl.cullFace( _gl.BACK );
  11375. _gl.enable( _gl.CULL_FACE );
  11376. _gl.enable( _gl.BLEND );
  11377. _gl.blendEquation( _gl.FUNC_ADD );
  11378. _gl.blendFunc( _gl.SRC_ALPHA, _gl.ONE_MINUS_SRC_ALPHA );
  11379. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  11380. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11381. };
  11382. var resetGLState = function () {
  11383. _currentProgram = null;
  11384. _currentCamera = null;
  11385. _currentGeometryProgram = '';
  11386. _currentMaterialId = - 1;
  11387. _lightsNeedUpdate = true;
  11388. state.reset();
  11389. };
  11390. setDefaultGLState();
  11391. this.context = _gl;
  11392. this.extensions = extensions;
  11393. this.state = state;
  11394. // shadow map
  11395. var shadowMap = new THREE.WebGLShadowMap( this, lights, objects );
  11396. this.shadowMap = shadowMap;
  11397. // GPU capabilities
  11398. var _maxTextures = _gl.getParameter( _gl.MAX_TEXTURE_IMAGE_UNITS );
  11399. var _maxVertexTextures = _gl.getParameter( _gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  11400. var _maxTextureSize = _gl.getParameter( _gl.MAX_TEXTURE_SIZE );
  11401. var _maxCubemapSize = _gl.getParameter( _gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  11402. var _supportsVertexTextures = _maxVertexTextures > 0;
  11403. var _supportsBoneTextures = _supportsVertexTextures && extensions.get( 'OES_texture_float' );
  11404. var _supportsInstancedArrays = extensions.get( 'ANGLE_instanced_arrays' );
  11405. //
  11406. var _vertexShaderPrecisionHighpFloat = _gl.getShaderPrecisionFormat( _gl.VERTEX_SHADER, _gl.HIGH_FLOAT );
  11407. var _vertexShaderPrecisionMediumpFloat = _gl.getShaderPrecisionFormat( _gl.VERTEX_SHADER, _gl.MEDIUM_FLOAT );
  11408. var _fragmentShaderPrecisionHighpFloat = _gl.getShaderPrecisionFormat( _gl.FRAGMENT_SHADER, _gl.HIGH_FLOAT );
  11409. var _fragmentShaderPrecisionMediumpFloat = _gl.getShaderPrecisionFormat( _gl.FRAGMENT_SHADER, _gl.MEDIUM_FLOAT );
  11410. var getCompressedTextureFormats = ( function () {
  11411. var array;
  11412. return function () {
  11413. if ( array !== undefined ) {
  11414. return array;
  11415. }
  11416. array = [];
  11417. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) || extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
  11418. var formats = _gl.getParameter( _gl.COMPRESSED_TEXTURE_FORMATS );
  11419. for ( var i = 0; i < formats.length; i ++ ) {
  11420. array.push( formats[ i ] );
  11421. }
  11422. }
  11423. return array;
  11424. };
  11425. } )();
  11426. // clamp precision to maximum available
  11427. var highpAvailable = _vertexShaderPrecisionHighpFloat.precision > 0 && _fragmentShaderPrecisionHighpFloat.precision > 0;
  11428. var mediumpAvailable = _vertexShaderPrecisionMediumpFloat.precision > 0 && _fragmentShaderPrecisionMediumpFloat.precision > 0;
  11429. if ( _precision === 'highp' && ! highpAvailable ) {
  11430. if ( mediumpAvailable ) {
  11431. _precision = 'mediump';
  11432. console.warn( 'THREE.WebGLRenderer: highp not supported, using mediump.' );
  11433. } else {
  11434. _precision = 'lowp';
  11435. console.warn( 'THREE.WebGLRenderer: highp and mediump not supported, using lowp.' );
  11436. }
  11437. }
  11438. if ( _precision === 'mediump' && ! mediumpAvailable ) {
  11439. _precision = 'lowp';
  11440. console.warn( 'THREE.WebGLRenderer: mediump not supported, using lowp.' );
  11441. }
  11442. // Plugins
  11443. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  11444. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  11445. // API
  11446. this.getContext = function () {
  11447. return _gl;
  11448. };
  11449. this.forceContextLoss = function () {
  11450. extensions.get( 'WEBGL_lose_context' ).loseContext();
  11451. };
  11452. this.supportsVertexTextures = function () {
  11453. return _supportsVertexTextures;
  11454. };
  11455. this.supportsInstancedArrays = function () {
  11456. return _supportsInstancedArrays;
  11457. };
  11458. this.supportsFloatTextures = function () {
  11459. return extensions.get( 'OES_texture_float' );
  11460. };
  11461. this.supportsHalfFloatTextures = function () {
  11462. return extensions.get( 'OES_texture_half_float' );
  11463. };
  11464. this.supportsStandardDerivatives = function () {
  11465. return extensions.get( 'OES_standard_derivatives' );
  11466. };
  11467. this.supportsCompressedTextureS3TC = function () {
  11468. return extensions.get( 'WEBGL_compressed_texture_s3tc' );
  11469. };
  11470. this.supportsCompressedTexturePVRTC = function () {
  11471. return extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  11472. };
  11473. this.supportsBlendMinMax = function () {
  11474. return extensions.get( 'EXT_blend_minmax' );
  11475. };
  11476. this.getMaxAnisotropy = ( function () {
  11477. var value;
  11478. return function () {
  11479. if ( value !== undefined ) return value;
  11480. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  11481. if ( extension !== null ) {
  11482. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  11483. } else {
  11484. value = 0;
  11485. }
  11486. return value;
  11487. }
  11488. } )();
  11489. this.getPrecision = function () {
  11490. return _precision;
  11491. };
  11492. this.getPixelRatio = function () {
  11493. return pixelRatio;
  11494. };
  11495. this.setPixelRatio = function ( value ) {
  11496. pixelRatio = value;
  11497. };
  11498. this.getSize = function () {
  11499. return {
  11500. width: _width,
  11501. height: _height
  11502. };
  11503. };
  11504. this.setSize = function ( width, height, updateStyle ) {
  11505. _width = width;
  11506. _height = height;
  11507. _canvas.width = width * pixelRatio;
  11508. _canvas.height = height * pixelRatio;
  11509. if ( updateStyle !== false ) {
  11510. _canvas.style.width = width + 'px';
  11511. _canvas.style.height = height + 'px';
  11512. }
  11513. this.setViewport( 0, 0, width, height );
  11514. };
  11515. this.setViewport = function ( x, y, width, height ) {
  11516. _viewportX = x * pixelRatio;
  11517. _viewportY = y * pixelRatio;
  11518. _viewportWidth = width * pixelRatio;
  11519. _viewportHeight = height * pixelRatio;
  11520. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  11521. };
  11522. this.setScissor = function ( x, y, width, height ) {
  11523. _gl.scissor(
  11524. x * pixelRatio,
  11525. y * pixelRatio,
  11526. width * pixelRatio,
  11527. height * pixelRatio
  11528. );
  11529. };
  11530. this.enableScissorTest = function ( enable ) {
  11531. enable ? _gl.enable( _gl.SCISSOR_TEST ) : _gl.disable( _gl.SCISSOR_TEST );
  11532. };
  11533. // Clearing
  11534. this.getClearColor = function () {
  11535. return _clearColor;
  11536. };
  11537. this.setClearColor = function ( color, alpha ) {
  11538. _clearColor.set( color );
  11539. _clearAlpha = alpha !== undefined ? alpha : 1;
  11540. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11541. };
  11542. this.getClearAlpha = function () {
  11543. return _clearAlpha;
  11544. };
  11545. this.setClearAlpha = function ( alpha ) {
  11546. _clearAlpha = alpha;
  11547. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11548. };
  11549. this.clear = function ( color, depth, stencil ) {
  11550. var bits = 0;
  11551. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  11552. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  11553. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  11554. _gl.clear( bits );
  11555. };
  11556. this.clearColor = function () {
  11557. _gl.clear( _gl.COLOR_BUFFER_BIT );
  11558. };
  11559. this.clearDepth = function () {
  11560. _gl.clear( _gl.DEPTH_BUFFER_BIT );
  11561. };
  11562. this.clearStencil = function () {
  11563. _gl.clear( _gl.STENCIL_BUFFER_BIT );
  11564. };
  11565. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  11566. this.setRenderTarget( renderTarget );
  11567. this.clear( color, depth, stencil );
  11568. };
  11569. // Reset
  11570. this.resetGLState = resetGLState;
  11571. // Events
  11572. var onTextureDispose = function ( event ) {
  11573. var texture = event.target;
  11574. texture.removeEventListener( 'dispose', onTextureDispose );
  11575. deallocateTexture( texture );
  11576. _this.info.memory.textures --;
  11577. };
  11578. var onRenderTargetDispose = function ( event ) {
  11579. var renderTarget = event.target;
  11580. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  11581. deallocateRenderTarget( renderTarget );
  11582. _this.info.memory.textures --;
  11583. };
  11584. var onMaterialDispose = function ( event ) {
  11585. var material = event.target;
  11586. material.removeEventListener( 'dispose', onMaterialDispose );
  11587. deallocateMaterial( material );
  11588. };
  11589. // Buffer deallocation
  11590. var deallocateTexture = function ( texture ) {
  11591. if ( texture.image && texture.image.__webglTextureCube ) {
  11592. // cube texture
  11593. _gl.deleteTexture( texture.image.__webglTextureCube );
  11594. delete texture.image.__webglTextureCube;
  11595. } else {
  11596. // 2D texture
  11597. if ( texture.__webglInit === undefined ) return;
  11598. _gl.deleteTexture( texture.__webglTexture );
  11599. delete texture.__webglTexture;
  11600. delete texture.__webglInit;
  11601. }
  11602. };
  11603. var deallocateRenderTarget = function ( renderTarget ) {
  11604. if ( ! renderTarget || renderTarget.__webglTexture === undefined ) return;
  11605. _gl.deleteTexture( renderTarget.__webglTexture );
  11606. delete renderTarget.__webglTexture;
  11607. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  11608. for ( var i = 0; i < 6; i ++ ) {
  11609. _gl.deleteFramebuffer( renderTarget.__webglFramebuffer[ i ] );
  11610. _gl.deleteRenderbuffer( renderTarget.__webglRenderbuffer[ i ] );
  11611. }
  11612. } else {
  11613. _gl.deleteFramebuffer( renderTarget.__webglFramebuffer );
  11614. _gl.deleteRenderbuffer( renderTarget.__webglRenderbuffer );
  11615. }
  11616. delete renderTarget.__webglFramebuffer;
  11617. delete renderTarget.__webglRenderbuffer;
  11618. };
  11619. var deallocateMaterial = function ( material ) {
  11620. var program = material.program.program;
  11621. if ( program === undefined ) return;
  11622. material.program = undefined;
  11623. // only deallocate GL program if this was the last use of shared program
  11624. // assumed there is only single copy of any program in the _programs list
  11625. // (that's how it's constructed)
  11626. var i, il, programInfo;
  11627. var deleteProgram = false;
  11628. for ( i = 0, il = _programs.length; i < il; i ++ ) {
  11629. programInfo = _programs[ i ];
  11630. if ( programInfo.program === program ) {
  11631. programInfo.usedTimes --;
  11632. if ( programInfo.usedTimes === 0 ) {
  11633. deleteProgram = true;
  11634. }
  11635. break;
  11636. }
  11637. }
  11638. if ( deleteProgram === true ) {
  11639. // avoid using array.splice, this is costlier than creating new array from scratch
  11640. var newPrograms = [];
  11641. for ( i = 0, il = _programs.length; i < il; i ++ ) {
  11642. programInfo = _programs[ i ];
  11643. if ( programInfo.program !== program ) {
  11644. newPrograms.push( programInfo );
  11645. }
  11646. }
  11647. _programs = newPrograms;
  11648. _gl.deleteProgram( program );
  11649. _this.info.memory.programs --;
  11650. }
  11651. };
  11652. // Buffer rendering
  11653. this.renderBufferImmediate = function ( object, program, material ) {
  11654. state.initAttributes();
  11655. if ( object.hasPositions && ! object.__webglVertexBuffer ) object.__webglVertexBuffer = _gl.createBuffer();
  11656. if ( object.hasNormals && ! object.__webglNormalBuffer ) object.__webglNormalBuffer = _gl.createBuffer();
  11657. if ( object.hasUvs && ! object.__webglUvBuffer ) object.__webglUvBuffer = _gl.createBuffer();
  11658. if ( object.hasColors && ! object.__webglColorBuffer ) object.__webglColorBuffer = _gl.createBuffer();
  11659. if ( object.hasPositions ) {
  11660. _gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglVertexBuffer );
  11661. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  11662. state.enableAttribute( program.attributes.position );
  11663. _gl.vertexAttribPointer( program.attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  11664. }
  11665. if ( object.hasNormals ) {
  11666. _gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglNormalBuffer );
  11667. if ( material instanceof THREE.MeshPhongMaterial === false && material.shading === THREE.FlatShading ) {
  11668. var nx, ny, nz,
  11669. nax, nbx, ncx, nay, nby, ncy, naz, nbz, ncz,
  11670. normalArray,
  11671. i, il = object.count * 3;
  11672. for ( i = 0; i < il; i += 9 ) {
  11673. normalArray = object.normalArray;
  11674. nax = normalArray[ i ];
  11675. nay = normalArray[ i + 1 ];
  11676. naz = normalArray[ i + 2 ];
  11677. nbx = normalArray[ i + 3 ];
  11678. nby = normalArray[ i + 4 ];
  11679. nbz = normalArray[ i + 5 ];
  11680. ncx = normalArray[ i + 6 ];
  11681. ncy = normalArray[ i + 7 ];
  11682. ncz = normalArray[ i + 8 ];
  11683. nx = ( nax + nbx + ncx ) / 3;
  11684. ny = ( nay + nby + ncy ) / 3;
  11685. nz = ( naz + nbz + ncz ) / 3;
  11686. normalArray[ i ] = nx;
  11687. normalArray[ i + 1 ] = ny;
  11688. normalArray[ i + 2 ] = nz;
  11689. normalArray[ i + 3 ] = nx;
  11690. normalArray[ i + 4 ] = ny;
  11691. normalArray[ i + 5 ] = nz;
  11692. normalArray[ i + 6 ] = nx;
  11693. normalArray[ i + 7 ] = ny;
  11694. normalArray[ i + 8 ] = nz;
  11695. }
  11696. }
  11697. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  11698. state.enableAttribute( program.attributes.normal );
  11699. _gl.vertexAttribPointer( program.attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  11700. }
  11701. if ( object.hasUvs && material.map ) {
  11702. _gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglUvBuffer );
  11703. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  11704. state.enableAttribute( program.attributes.uv );
  11705. _gl.vertexAttribPointer( program.attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  11706. }
  11707. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  11708. _gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglColorBuffer );
  11709. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  11710. state.enableAttribute( program.attributes.color );
  11711. _gl.vertexAttribPointer( program.attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  11712. }
  11713. state.disableUnusedAttributes();
  11714. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  11715. object.count = 0;
  11716. };
  11717. function setupVertexAttributes( material, program, geometry, startIndex ) {
  11718. var extension;
  11719. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  11720. extension = extensions.get( 'ANGLE_instanced_arrays' );
  11721. if ( extension === null ) {
  11722. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  11723. return;
  11724. }
  11725. }
  11726. var geometryAttributes = geometry.attributes;
  11727. var programAttributes = program.attributes;
  11728. for ( var name in programAttributes ) {
  11729. var programAttribute = programAttributes[ name ];
  11730. if ( programAttribute >= 0 ) {
  11731. var geometryAttribute = geometryAttributes[ name ];
  11732. if ( geometryAttribute !== undefined ) {
  11733. var size = geometryAttribute.itemSize;
  11734. state.enableAttribute( programAttribute );
  11735. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  11736. var data = geometryAttribute.data;
  11737. var stride = data.stride;
  11738. var offset = geometryAttribute.offset;
  11739. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryAttribute.data.buffer );
  11740. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  11741. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  11742. if ( extension === null ) {
  11743. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
  11744. return;
  11745. }
  11746. extension.vertexAttribDivisorANGLE( programAttribute, data.meshPerAttribute );
  11747. if ( geometry.maxInstancedCount === undefined ) {
  11748. geometry.maxInstancedCount = data.meshPerAttribute * ( data.array.length / data.stride );
  11749. }
  11750. }
  11751. } else {
  11752. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryAttribute.buffer );
  11753. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  11754. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  11755. if ( extension === null ) {
  11756. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
  11757. return;
  11758. }
  11759. extension.vertexAttribDivisorANGLE( programAttribute, geometryAttribute.meshPerAttribute );
  11760. if ( geometry.maxInstancedCount === undefined ) {
  11761. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * ( geometryAttribute.array.length / geometryAttribute.itemSize );
  11762. }
  11763. }
  11764. }
  11765. } else if ( material.defaultAttributeValues !== undefined ) {
  11766. if ( material.defaultAttributeValues[ name ] !== undefined ) {
  11767. if ( material.defaultAttributeValues[ name ].length === 2 ) {
  11768. _gl.vertexAttrib2fv( programAttribute, material.defaultAttributeValues[ name ] );
  11769. } else if ( material.defaultAttributeValues[ name ].length === 3 ) {
  11770. _gl.vertexAttrib3fv( programAttribute, material.defaultAttributeValues[ name ] );
  11771. }
  11772. }
  11773. }
  11774. }
  11775. }
  11776. state.disableUnusedAttributes();
  11777. }
  11778. this.renderBufferDirect = function ( camera, lights, fog, material, object ) {
  11779. if ( material.visible === false ) return;
  11780. var geometry = objects.geometries.get( object );
  11781. var program = setProgram( camera, lights, fog, material, object );
  11782. var updateBuffers = false,
  11783. wireframeBit = material.wireframe ? 1 : 0,
  11784. geometryProgram = geometry.id + '_' + program.id + '_' + wireframeBit;
  11785. if ( geometryProgram !== _currentGeometryProgram ) {
  11786. _currentGeometryProgram = geometryProgram;
  11787. updateBuffers = true;
  11788. }
  11789. if ( updateBuffers ) {
  11790. state.initAttributes();
  11791. }
  11792. if ( object instanceof THREE.Mesh ) {
  11793. renderMesh( material, geometry, object, program, updateBuffers );
  11794. } else if ( object instanceof THREE.Line ) {
  11795. renderLine( material, geometry, object, program, updateBuffers );
  11796. } else if ( object instanceof THREE.PointCloud ) {
  11797. renderPointCloud( material, geometry, object, program, updateBuffers );
  11798. }
  11799. };
  11800. function renderMesh( material, geometry, object, program, updateBuffers ) {
  11801. var mode = material.wireframe === true ? _gl.LINES : _gl.TRIANGLES;
  11802. var index = geometry.attributes.index;
  11803. if ( index ) {
  11804. // indexed triangles
  11805. var type, size;
  11806. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  11807. type = _gl.UNSIGNED_INT;
  11808. size = 4;
  11809. } else {
  11810. type = _gl.UNSIGNED_SHORT;
  11811. size = 2;
  11812. }
  11813. var offsets = geometry.offsets;
  11814. if ( offsets.length === 0 ) {
  11815. if ( updateBuffers ) {
  11816. setupVertexAttributes( material, program, geometry, 0 );
  11817. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, index.buffer );
  11818. }
  11819. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  11820. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  11821. if ( extension === null ) {
  11822. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  11823. return;
  11824. }
  11825. extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount ); // Draw the instanced meshes
  11826. } else {
  11827. _gl.drawElements( mode, index.array.length, type, 0 );
  11828. }
  11829. _this.info.render.calls ++;
  11830. _this.info.render.vertices += index.array.length; // not really true, here vertices can be shared
  11831. _this.info.render.faces += index.array.length / 3;
  11832. } else {
  11833. // if there is more than 1 chunk
  11834. // must set attribute pointers to use new offsets for each chunk
  11835. // even if geometry and materials didn't change
  11836. updateBuffers = true;
  11837. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  11838. var startIndex = offsets[ i ].index;
  11839. if ( updateBuffers ) {
  11840. setupVertexAttributes( material, program, geometry, startIndex );
  11841. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, index.buffer );
  11842. }
  11843. // render indexed triangles
  11844. if ( geometry instanceof THREE.InstancedBufferGeometry && offsets[i].instances > 0 ) {
  11845. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  11846. if ( extension === null ) {
  11847. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  11848. return;
  11849. }
  11850. extension.drawElementsInstancedANGLE( mode, offsets[i].count, type, offsets[i].start * size, offsets[i].count, type, offsets[i].instances ); // Draw the instanced meshes
  11851. } else {
  11852. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
  11853. }
  11854. _this.info.render.calls ++;
  11855. _this.info.render.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  11856. _this.info.render.faces += offsets[ i ].count / 3;
  11857. }
  11858. }
  11859. } else {
  11860. // non-indexed triangles
  11861. var offsets = geometry.offsets;
  11862. if ( offsets.length === 0 ) {
  11863. if ( updateBuffers ) {
  11864. setupVertexAttributes( material, program, geometry, 0 );
  11865. }
  11866. var position = geometry.attributes.position;
  11867. // render non-indexed triangles
  11868. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  11869. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  11870. if ( extension === null ) {
  11871. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  11872. return;
  11873. }
  11874. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  11875. extension.drawArraysInstancedANGLE( mode, 0, position.data.array.length / position.data.stride, geometry.maxInstancedCount ); // Draw the instanced meshes
  11876. } else {
  11877. extension.drawArraysInstancedANGLE( mode, 0, position.array.length / position.itemSize, geometry.maxInstancedCount ); // Draw the instanced meshes
  11878. }
  11879. } else {
  11880. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  11881. _gl.drawArrays( mode, 0, position.data.array.length / position.data.stride );
  11882. } else {
  11883. _gl.drawArrays( mode, 0, position.array.length / position.itemSize );
  11884. }
  11885. }
  11886. _this.info.render.calls++;
  11887. _this.info.render.vertices += position.array.length / position.itemSize;
  11888. _this.info.render.faces += position.array.length / ( 3 * position.itemSize );
  11889. } else {
  11890. // if there is more than 1 chunk
  11891. // must set attribute pointers to use new offsets for each chunk
  11892. // even if geometry and materials didn't change
  11893. if ( updateBuffers ) {
  11894. setupVertexAttributes( material, program, geometry, 0 );
  11895. }
  11896. for ( var i = 0, il = offsets.length; i < il; i++ ) {
  11897. // render non-indexed triangles
  11898. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  11899. console.error( 'THREE.WebGLRenderer.renderMesh: cannot use drawCalls with THREE.InstancedBufferGeometry.' );
  11900. return;
  11901. } else {
  11902. _gl.drawArrays( mode, offsets[ i ].start, offsets[ i ].count );
  11903. }
  11904. _this.info.render.calls++;
  11905. _this.info.render.vertices += offsets[ i ].count;
  11906. _this.info.render.faces += ( offsets[ i ].count ) / 3;
  11907. }
  11908. }
  11909. }
  11910. }
  11911. function renderLine( material, geometry, object, program, updateBuffers ) {
  11912. var mode = object instanceof THREE.LineSegments ? _gl.LINES : _gl.LINE_STRIP;
  11913. // In case user is not using Line*Material by mistake
  11914. var lineWidth = material.linewidth !== undefined ? material.linewidth : 1;
  11915. state.setLineWidth( lineWidth * pixelRatio );
  11916. var index = geometry.attributes.index;
  11917. if ( index ) {
  11918. // indexed lines
  11919. var type, size;
  11920. if ( index.array instanceof Uint32Array ) {
  11921. type = _gl.UNSIGNED_INT;
  11922. size = 4;
  11923. } else {
  11924. type = _gl.UNSIGNED_SHORT;
  11925. size = 2;
  11926. }
  11927. var offsets = geometry.offsets;
  11928. if ( offsets.length === 0 ) {
  11929. if ( updateBuffers ) {
  11930. setupVertexAttributes( material, program, geometry, 0 );
  11931. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, index.buffer );
  11932. }
  11933. _gl.drawElements( mode, index.array.length, type, 0 ); // 2 bytes per Uint16Array
  11934. _this.info.render.calls ++;
  11935. _this.info.render.vertices += index.array.length; // not really true, here vertices can be shared
  11936. } else {
  11937. // if there is more than 1 chunk
  11938. // must set attribute pointers to use new offsets for each chunk
  11939. // even if geometry and materials didn't change
  11940. if ( offsets.length > 1 ) updateBuffers = true;
  11941. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  11942. var startIndex = offsets[ i ].index;
  11943. if ( updateBuffers ) {
  11944. setupVertexAttributes( material, program, geometry, startIndex );
  11945. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, index.buffer );
  11946. }
  11947. // render indexed lines
  11948. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size ); // 2 bytes per Uint16Array
  11949. _this.info.render.calls ++;
  11950. _this.info.render.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  11951. }
  11952. }
  11953. } else {
  11954. // non-indexed lines
  11955. if ( updateBuffers ) {
  11956. setupVertexAttributes( material, program, geometry, 0 );
  11957. }
  11958. var position = geometry.attributes.position;
  11959. var offsets = geometry.offsets;
  11960. if ( offsets.length === 0 ) {
  11961. _gl.drawArrays( mode, 0, position.array.length / 3 );
  11962. _this.info.render.calls ++;
  11963. _this.info.render.vertices += position.array.length / 3;
  11964. } else {
  11965. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  11966. _gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
  11967. _this.info.render.calls ++;
  11968. _this.info.render.vertices += offsets[ i ].count;
  11969. }
  11970. }
  11971. }
  11972. }
  11973. function renderPointCloud( material, geometry, object, program, updateBuffers ) {
  11974. var mode = _gl.POINTS;
  11975. var index = geometry.attributes.index;
  11976. if ( index ) {
  11977. // indexed points
  11978. var type, size;
  11979. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  11980. type = _gl.UNSIGNED_INT;
  11981. size = 4;
  11982. } else {
  11983. type = _gl.UNSIGNED_SHORT;
  11984. size = 2;
  11985. }
  11986. var offsets = geometry.offsets;
  11987. if ( offsets.length === 0 ) {
  11988. if ( updateBuffers ) {
  11989. setupVertexAttributes( material, program, geometry, 0 );
  11990. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, index.buffer );
  11991. }
  11992. _gl.drawElements( mode, index.array.length, type, 0);
  11993. _this.info.render.calls ++;
  11994. _this.info.render.points += index.array.length;
  11995. } else {
  11996. // if there is more than 1 chunk
  11997. // must set attribute pointers to use new offsets for each chunk
  11998. // even if geometry and materials didn't change
  11999. if ( offsets.length > 1 ) updateBuffers = true;
  12000. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12001. var startIndex = offsets[ i ].index;
  12002. if ( updateBuffers ) {
  12003. setupVertexAttributes( material, program, geometry, startIndex );
  12004. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, index.buffer );
  12005. }
  12006. // render indexed points
  12007. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
  12008. _this.info.render.calls ++;
  12009. _this.info.render.points += offsets[ i ].count;
  12010. }
  12011. }
  12012. } else {
  12013. // non-indexed points
  12014. if ( updateBuffers ) {
  12015. setupVertexAttributes( material, program, geometry, 0 );
  12016. }
  12017. var position = geometry.attributes.position;
  12018. var offsets = geometry.offsets;
  12019. if ( offsets.length === 0 ) {
  12020. _gl.drawArrays( mode, 0, position.array.length / 3 );
  12021. _this.info.render.calls ++;
  12022. _this.info.render.points += position.array.length / 3;
  12023. } else {
  12024. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12025. _gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
  12026. _this.info.render.calls ++;
  12027. _this.info.render.points += offsets[ i ].count;
  12028. }
  12029. }
  12030. }
  12031. }
  12032. // Sorting
  12033. function painterSortStable ( a, b ) {
  12034. if ( a.object.renderOrder !== b.object.renderOrder ) {
  12035. return a.object.renderOrder - b.object.renderOrder;
  12036. } else if ( a.object.material.id !== b.object.material.id ) {
  12037. return a.object.material.id - b.object.material.id;
  12038. } else if ( a.z !== b.z ) {
  12039. return a.z - b.z;
  12040. } else {
  12041. return a.id - b.id;
  12042. }
  12043. }
  12044. function reversePainterSortStable ( a, b ) {
  12045. if ( a.object.renderOrder !== b.object.renderOrder ) {
  12046. return a.object.renderOrder - b.object.renderOrder;
  12047. } if ( a.z !== b.z ) {
  12048. return b.z - a.z;
  12049. } else {
  12050. return a.id - b.id;
  12051. }
  12052. }
  12053. function numericalSort ( a, b ) {
  12054. return b[ 0 ] - a[ 0 ];
  12055. }
  12056. // Rendering
  12057. this.render = function ( scene, camera, renderTarget, forceClear ) {
  12058. if ( camera instanceof THREE.Camera === false ) {
  12059. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  12060. return;
  12061. }
  12062. var fog = scene.fog;
  12063. // reset caching for this frame
  12064. _currentGeometryProgram = '';
  12065. _currentMaterialId = - 1;
  12066. _currentCamera = null;
  12067. _lightsNeedUpdate = true;
  12068. // update scene graph
  12069. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  12070. // update camera matrices and frustum
  12071. if ( camera.parent === undefined ) camera.updateMatrixWorld();
  12072. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  12073. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  12074. _frustum.setFromMatrix( _projScreenMatrix );
  12075. lights.length = 0;
  12076. opaqueObjects.length = 0;
  12077. transparentObjects.length = 0;
  12078. sprites.length = 0;
  12079. lensFlares.length = 0;
  12080. projectObject( scene );
  12081. if ( _this.sortObjects === true ) {
  12082. opaqueObjects.sort( painterSortStable );
  12083. transparentObjects.sort( reversePainterSortStable );
  12084. }
  12085. objects.update( opaqueObjects );
  12086. objects.update( transparentObjects );
  12087. //
  12088. shadowMap.render( scene, camera );
  12089. //
  12090. _this.info.render.calls = 0;
  12091. _this.info.render.vertices = 0;
  12092. _this.info.render.faces = 0;
  12093. _this.info.render.points = 0;
  12094. this.setRenderTarget( renderTarget );
  12095. if ( this.autoClear || forceClear ) {
  12096. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  12097. }
  12098. // set matrices for immediate objects
  12099. for ( var i = 0, il = objects.objectsImmediate.length; i < il; i ++ ) {
  12100. var webglObject = objects.objectsImmediate[ i ];
  12101. var object = webglObject.object;
  12102. if ( object.visible ) {
  12103. setupMatrices( object, camera );
  12104. var material = object.material;
  12105. if ( material.transparent ) {
  12106. webglObject.transparent = material;
  12107. webglObject.opaque = null;
  12108. } else {
  12109. webglObject.opaque = material;
  12110. webglObject.transparent = null;
  12111. }
  12112. }
  12113. }
  12114. if ( scene.overrideMaterial ) {
  12115. var overrideMaterial = scene.overrideMaterial;
  12116. setMaterial( overrideMaterial );
  12117. renderObjects( opaqueObjects, camera, lights, fog, overrideMaterial );
  12118. renderObjects( transparentObjects, camera, lights, fog, overrideMaterial );
  12119. renderObjectsImmediate( objects.objectsImmediate, '', camera, lights, fog, overrideMaterial );
  12120. } else {
  12121. // opaque pass (front-to-back order)
  12122. state.setBlending( THREE.NoBlending );
  12123. renderObjects( opaqueObjects, camera, lights, fog, null );
  12124. renderObjectsImmediate( objects.objectsImmediate, 'opaque', camera, lights, fog, null );
  12125. // transparent pass (back-to-front order)
  12126. renderObjects( transparentObjects, camera, lights, fog, null );
  12127. renderObjectsImmediate( objects.objectsImmediate, 'transparent', camera, lights, fog, null );
  12128. }
  12129. // custom render plugins (post pass)
  12130. spritePlugin.render( scene, camera );
  12131. lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
  12132. // Generate mipmap if we're using any kind of mipmap filtering
  12133. if ( renderTarget && renderTarget.generateMipmaps && renderTarget.minFilter !== THREE.NearestFilter && renderTarget.minFilter !== THREE.LinearFilter ) {
  12134. updateRenderTargetMipmap( renderTarget );
  12135. }
  12136. // Ensure depth buffer writing is enabled so it can be cleared on next render
  12137. state.setDepthTest( true );
  12138. state.setDepthWrite( true );
  12139. state.setColorWrite( true );
  12140. // _gl.finish();
  12141. };
  12142. function projectObject( object ) {
  12143. if ( object.visible === false ) return;
  12144. if ( object instanceof THREE.Scene || object instanceof THREE.Group ) {
  12145. // skip
  12146. } else {
  12147. // update Skeleton objects
  12148. if ( object instanceof THREE.SkinnedMesh ) {
  12149. object.skeleton.update();
  12150. }
  12151. objects.init( object );
  12152. if ( object instanceof THREE.Light ) {
  12153. lights.push( object );
  12154. } else if ( object instanceof THREE.Sprite ) {
  12155. sprites.push( object );
  12156. } else if ( object instanceof THREE.LensFlare ) {
  12157. lensFlares.push( object );
  12158. } else {
  12159. var webglObject = objects.objects[ object.id ];
  12160. if ( webglObject && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  12161. var material = object.material;
  12162. if ( material.transparent ) {
  12163. transparentObjects.push( webglObject );
  12164. } else {
  12165. opaqueObjects.push( webglObject );
  12166. }
  12167. if ( _this.sortObjects === true ) {
  12168. _vector3.setFromMatrixPosition( object.matrixWorld );
  12169. _vector3.applyProjection( _projScreenMatrix );
  12170. webglObject.z = _vector3.z;
  12171. }
  12172. }
  12173. }
  12174. }
  12175. for ( var i = 0, l = object.children.length; i < l; i ++ ) {
  12176. projectObject( object.children[ i ] );
  12177. }
  12178. }
  12179. function renderObjects( renderList, camera, lights, fog, overrideMaterial ) {
  12180. var material;
  12181. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12182. var webglObject = renderList[ i ];
  12183. var object = webglObject.object;
  12184. setupMatrices( object, camera );
  12185. if ( overrideMaterial ) {
  12186. material = overrideMaterial;
  12187. } else {
  12188. material = object.material;
  12189. if ( ! material ) continue;
  12190. setMaterial( material );
  12191. }
  12192. _this.setMaterialFaces( material );
  12193. _this.renderBufferDirect( camera, lights, fog, material, object );
  12194. }
  12195. }
  12196. function renderObjectsImmediate ( renderList, materialType, camera, lights, fog, overrideMaterial ) {
  12197. var material;
  12198. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12199. var webglObject = renderList[ i ];
  12200. var object = webglObject.object;
  12201. if ( object.visible ) {
  12202. if ( overrideMaterial ) {
  12203. material = overrideMaterial;
  12204. } else {
  12205. material = webglObject[ materialType ];
  12206. if ( ! material ) continue;
  12207. setMaterial( material );
  12208. }
  12209. _this.renderImmediateObject( camera, lights, fog, material, object );
  12210. }
  12211. }
  12212. }
  12213. this.renderImmediateObject = function ( camera, lights, fog, material, object ) {
  12214. var program = setProgram( camera, lights, fog, material, object );
  12215. _currentGeometryProgram = '';
  12216. _this.setMaterialFaces( material );
  12217. if ( object.immediateRenderCallback ) {
  12218. object.immediateRenderCallback( program, _gl, _frustum );
  12219. } else {
  12220. object.render( function ( object ) { _this.renderBufferImmediate( object, program, material ); } );
  12221. }
  12222. };
  12223. // Materials
  12224. var shaderIDs = {
  12225. MeshDepthMaterial: 'depth',
  12226. MeshNormalMaterial: 'normal',
  12227. MeshBasicMaterial: 'basic',
  12228. MeshLambertMaterial: 'lambert',
  12229. MeshPhongMaterial: 'phong',
  12230. LineBasicMaterial: 'basic',
  12231. LineDashedMaterial: 'dashed',
  12232. PointCloudMaterial: 'particle_basic'
  12233. };
  12234. function initMaterial( material, lights, fog, object ) {
  12235. var shaderID = shaderIDs[ material.type ];
  12236. // heuristics to create shader parameters according to lights in the scene
  12237. // (not to blow over maxLights budget)
  12238. var maxLightCount = allocateLights( lights );
  12239. var maxShadows = allocateShadows( lights );
  12240. var maxBones = allocateBones( object );
  12241. var parameters = {
  12242. precision: _precision,
  12243. supportsVertexTextures: _supportsVertexTextures,
  12244. map: !! material.map,
  12245. envMap: !! material.envMap,
  12246. envMapMode: material.envMap && material.envMap.mapping,
  12247. lightMap: !! material.lightMap,
  12248. aoMap: !! material.aoMap,
  12249. bumpMap: !! material.bumpMap,
  12250. normalMap: !! material.normalMap,
  12251. specularMap: !! material.specularMap,
  12252. alphaMap: !! material.alphaMap,
  12253. combine: material.combine,
  12254. vertexColors: material.vertexColors,
  12255. fog: fog,
  12256. useFog: material.fog,
  12257. fogExp: fog instanceof THREE.FogExp2,
  12258. flatShading: material.shading === THREE.FlatShading,
  12259. sizeAttenuation: material.sizeAttenuation,
  12260. logarithmicDepthBuffer: _logarithmicDepthBuffer,
  12261. skinning: material.skinning,
  12262. maxBones: maxBones,
  12263. useVertexTexture: _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  12264. morphTargets: material.morphTargets,
  12265. morphNormals: material.morphNormals,
  12266. maxMorphTargets: _this.maxMorphTargets,
  12267. maxMorphNormals: _this.maxMorphNormals,
  12268. maxDirLights: maxLightCount.directional,
  12269. maxPointLights: maxLightCount.point,
  12270. maxSpotLights: maxLightCount.spot,
  12271. maxHemiLights: maxLightCount.hemi,
  12272. maxShadows: maxShadows,
  12273. shadowMapEnabled: shadowMap.enabled && object.receiveShadow && maxShadows > 0,
  12274. shadowMapType: shadowMap.type,
  12275. shadowMapDebug: shadowMap.debug,
  12276. shadowMapCascade: shadowMap.cascade,
  12277. alphaTest: material.alphaTest,
  12278. metal: material.metal,
  12279. doubleSided: material.side === THREE.DoubleSide,
  12280. flipSided: material.side === THREE.BackSide
  12281. };
  12282. // Generate code
  12283. var chunks = [];
  12284. if ( shaderID ) {
  12285. chunks.push( shaderID );
  12286. } else {
  12287. chunks.push( material.fragmentShader );
  12288. chunks.push( material.vertexShader );
  12289. }
  12290. if ( material.defines !== undefined ) {
  12291. for ( var name in material.defines ) {
  12292. chunks.push( name );
  12293. chunks.push( material.defines[ name ] );
  12294. }
  12295. }
  12296. for ( var name in parameters ) {
  12297. chunks.push( name );
  12298. chunks.push( parameters[ name ] );
  12299. }
  12300. var code = chunks.join();
  12301. if ( !material.program ) {
  12302. // new material
  12303. material.addEventListener( 'dispose', onMaterialDispose );
  12304. } else if ( material.program.code !== code ) {
  12305. // changed glsl or parameters
  12306. deallocateMaterial( material );
  12307. } else if ( shaderID !== undefined ) {
  12308. // same glsl
  12309. return;
  12310. } else if ( material.__webglShader.uniforms === material.uniforms ) {
  12311. // same uniforms (container object)
  12312. return;
  12313. }
  12314. if ( shaderID ) {
  12315. var shader = THREE.ShaderLib[ shaderID ];
  12316. material.__webglShader = {
  12317. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  12318. vertexShader: shader.vertexShader,
  12319. fragmentShader: shader.fragmentShader
  12320. }
  12321. } else {
  12322. material.__webglShader = {
  12323. uniforms: material.uniforms,
  12324. vertexShader: material.vertexShader,
  12325. fragmentShader: material.fragmentShader
  12326. }
  12327. }
  12328. var program;
  12329. // Check if code has been already compiled
  12330. for ( var p = 0, pl = _programs.length; p < pl; p ++ ) {
  12331. var programInfo = _programs[ p ];
  12332. if ( programInfo.code === code ) {
  12333. program = programInfo;
  12334. program.usedTimes ++;
  12335. break;
  12336. }
  12337. }
  12338. if ( program === undefined ) {
  12339. program = new THREE.WebGLProgram( _this, code, material, parameters );
  12340. _programs.push( program );
  12341. _this.info.memory.programs = _programs.length;
  12342. }
  12343. material.program = program;
  12344. var attributes = program.attributes;
  12345. if ( material.morphTargets ) {
  12346. material.numSupportedMorphTargets = 0;
  12347. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  12348. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  12349. material.numSupportedMorphTargets ++;
  12350. }
  12351. }
  12352. }
  12353. if ( material.morphNormals ) {
  12354. material.numSupportedMorphNormals = 0;
  12355. for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
  12356. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  12357. material.numSupportedMorphNormals ++;
  12358. }
  12359. }
  12360. }
  12361. material.uniformsList = [];
  12362. for ( var u in material.__webglShader.uniforms ) {
  12363. var location = material.program.uniforms[ u ];
  12364. if ( location ) {
  12365. material.uniformsList.push( [ material.__webglShader.uniforms[ u ], location ] );
  12366. }
  12367. }
  12368. }
  12369. function setMaterial( material ) {
  12370. if ( material.transparent === true ) {
  12371. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  12372. } else {
  12373. state.setBlending( THREE.NoBlending );
  12374. }
  12375. state.setDepthFunc( material.depthFunc );
  12376. state.setDepthTest( material.depthTest );
  12377. state.setDepthWrite( material.depthWrite );
  12378. state.setColorWrite( material.colorWrite );
  12379. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12380. }
  12381. function setProgram( camera, lights, fog, material, object ) {
  12382. _usedTextureUnits = 0;
  12383. if ( material.needsUpdate ) {
  12384. initMaterial( material, lights, fog, object );
  12385. material.needsUpdate = false;
  12386. }
  12387. var refreshProgram = false;
  12388. var refreshMaterial = false;
  12389. var refreshLights = false;
  12390. var program = material.program,
  12391. p_uniforms = program.uniforms,
  12392. m_uniforms = material.__webglShader.uniforms;
  12393. if ( program.id !== _currentProgram ) {
  12394. _gl.useProgram( program.program );
  12395. _currentProgram = program.id;
  12396. refreshProgram = true;
  12397. refreshMaterial = true;
  12398. refreshLights = true;
  12399. }
  12400. if ( material.id !== _currentMaterialId ) {
  12401. if ( _currentMaterialId === -1 ) refreshLights = true;
  12402. _currentMaterialId = material.id;
  12403. refreshMaterial = true;
  12404. }
  12405. if ( refreshProgram || camera !== _currentCamera ) {
  12406. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  12407. if ( _logarithmicDepthBuffer ) {
  12408. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  12409. }
  12410. if ( camera !== _currentCamera ) _currentCamera = camera;
  12411. // load material specific uniforms
  12412. // (shader material also gets them for the sake of genericity)
  12413. if ( material instanceof THREE.ShaderMaterial ||
  12414. material instanceof THREE.MeshPhongMaterial ||
  12415. material.envMap ) {
  12416. if ( p_uniforms.cameraPosition !== null ) {
  12417. _vector3.setFromMatrixPosition( camera.matrixWorld );
  12418. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  12419. }
  12420. }
  12421. if ( material instanceof THREE.MeshPhongMaterial ||
  12422. material instanceof THREE.MeshLambertMaterial ||
  12423. material instanceof THREE.MeshBasicMaterial ||
  12424. material instanceof THREE.ShaderMaterial ||
  12425. material.skinning ) {
  12426. if ( p_uniforms.viewMatrix !== null ) {
  12427. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  12428. }
  12429. }
  12430. }
  12431. // skinning uniforms must be set even if material didn't change
  12432. // auto-setting of texture unit for bone texture must go before other textures
  12433. // not sure why, but otherwise weird things happen
  12434. if ( material.skinning ) {
  12435. if ( object.bindMatrix && p_uniforms.bindMatrix !== null ) {
  12436. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  12437. }
  12438. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== null ) {
  12439. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  12440. }
  12441. if ( _supportsBoneTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  12442. if ( p_uniforms.boneTexture !== null ) {
  12443. var textureUnit = getTextureUnit();
  12444. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  12445. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  12446. }
  12447. if ( p_uniforms.boneTextureWidth !== null ) {
  12448. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  12449. }
  12450. if ( p_uniforms.boneTextureHeight !== null ) {
  12451. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  12452. }
  12453. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  12454. if ( p_uniforms.boneGlobalMatrices !== null ) {
  12455. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  12456. }
  12457. }
  12458. }
  12459. if ( refreshMaterial ) {
  12460. // refresh uniforms common to several materials
  12461. if ( fog && material.fog ) {
  12462. refreshUniformsFog( m_uniforms, fog );
  12463. }
  12464. if ( material instanceof THREE.MeshPhongMaterial ||
  12465. material instanceof THREE.MeshLambertMaterial ||
  12466. material.lights ) {
  12467. if ( _lightsNeedUpdate ) {
  12468. refreshLights = true;
  12469. setupLights( lights );
  12470. _lightsNeedUpdate = false;
  12471. }
  12472. if ( refreshLights ) {
  12473. refreshUniformsLights( m_uniforms, _lights );
  12474. markUniformsLightsNeedsUpdate( m_uniforms, true );
  12475. } else {
  12476. markUniformsLightsNeedsUpdate( m_uniforms, false );
  12477. }
  12478. }
  12479. if ( material instanceof THREE.MeshBasicMaterial ||
  12480. material instanceof THREE.MeshLambertMaterial ||
  12481. material instanceof THREE.MeshPhongMaterial ) {
  12482. refreshUniformsCommon( m_uniforms, material );
  12483. }
  12484. // refresh single material specific uniforms
  12485. if ( material instanceof THREE.LineBasicMaterial ) {
  12486. refreshUniformsLine( m_uniforms, material );
  12487. } else if ( material instanceof THREE.LineDashedMaterial ) {
  12488. refreshUniformsLine( m_uniforms, material );
  12489. refreshUniformsDash( m_uniforms, material );
  12490. } else if ( material instanceof THREE.PointCloudMaterial ) {
  12491. refreshUniformsParticle( m_uniforms, material );
  12492. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  12493. refreshUniformsPhong( m_uniforms, material );
  12494. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  12495. refreshUniformsLambert( m_uniforms, material );
  12496. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  12497. m_uniforms.mNear.value = camera.near;
  12498. m_uniforms.mFar.value = camera.far;
  12499. m_uniforms.opacity.value = material.opacity;
  12500. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  12501. m_uniforms.opacity.value = material.opacity;
  12502. }
  12503. if ( object.receiveShadow && ! material._shadowPass ) {
  12504. refreshUniformsShadow( m_uniforms, lights );
  12505. }
  12506. // load common uniforms
  12507. loadUniformsGeneric( material.uniformsList );
  12508. }
  12509. loadUniformsMatrices( p_uniforms, object );
  12510. if ( p_uniforms.modelMatrix !== null ) {
  12511. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  12512. }
  12513. return program;
  12514. }
  12515. // Uniforms (refresh uniforms objects)
  12516. function refreshUniformsCommon ( uniforms, material ) {
  12517. uniforms.opacity.value = material.opacity;
  12518. uniforms.diffuse.value = material.color;
  12519. uniforms.map.value = material.map;
  12520. uniforms.specularMap.value = material.specularMap;
  12521. uniforms.alphaMap.value = material.alphaMap;
  12522. if ( material.bumpMap ) {
  12523. uniforms.bumpMap.value = material.bumpMap;
  12524. uniforms.bumpScale.value = material.bumpScale;
  12525. }
  12526. if ( material.normalMap ) {
  12527. uniforms.normalMap.value = material.normalMap;
  12528. uniforms.normalScale.value.copy( material.normalScale );
  12529. }
  12530. // uv repeat and offset setting priorities
  12531. // 1. color map
  12532. // 2. specular map
  12533. // 3. normal map
  12534. // 4. bump map
  12535. // 5. alpha map
  12536. var uvScaleMap;
  12537. if ( material.map ) {
  12538. uvScaleMap = material.map;
  12539. } else if ( material.specularMap ) {
  12540. uvScaleMap = material.specularMap;
  12541. } else if ( material.normalMap ) {
  12542. uvScaleMap = material.normalMap;
  12543. } else if ( material.bumpMap ) {
  12544. uvScaleMap = material.bumpMap;
  12545. } else if ( material.alphaMap ) {
  12546. uvScaleMap = material.alphaMap;
  12547. }
  12548. if ( uvScaleMap !== undefined ) {
  12549. var offset = uvScaleMap.offset;
  12550. var repeat = uvScaleMap.repeat;
  12551. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  12552. }
  12553. uniforms.envMap.value = material.envMap;
  12554. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  12555. uniforms.reflectivity.value = material.reflectivity;
  12556. uniforms.refractionRatio.value = material.refractionRatio;
  12557. }
  12558. function refreshUniformsLine ( uniforms, material ) {
  12559. uniforms.diffuse.value = material.color;
  12560. uniforms.opacity.value = material.opacity;
  12561. }
  12562. function refreshUniformsDash ( uniforms, material ) {
  12563. uniforms.dashSize.value = material.dashSize;
  12564. uniforms.totalSize.value = material.dashSize + material.gapSize;
  12565. uniforms.scale.value = material.scale;
  12566. }
  12567. function refreshUniformsParticle ( uniforms, material ) {
  12568. uniforms.psColor.value = material.color;
  12569. uniforms.opacity.value = material.opacity;
  12570. uniforms.size.value = material.size;
  12571. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  12572. uniforms.map.value = material.map;
  12573. if ( material.map !== null ) {
  12574. var offset = material.map.offset;
  12575. var repeat = material.map.repeat;
  12576. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  12577. }
  12578. }
  12579. function refreshUniformsFog ( uniforms, fog ) {
  12580. uniforms.fogColor.value = fog.color;
  12581. if ( fog instanceof THREE.Fog ) {
  12582. uniforms.fogNear.value = fog.near;
  12583. uniforms.fogFar.value = fog.far;
  12584. } else if ( fog instanceof THREE.FogExp2 ) {
  12585. uniforms.fogDensity.value = fog.density;
  12586. }
  12587. }
  12588. function refreshUniformsPhong ( uniforms, material ) {
  12589. uniforms.shininess.value = material.shininess;
  12590. uniforms.emissive.value = material.emissive;
  12591. uniforms.specular.value = material.specular;
  12592. uniforms.lightMap.value = material.lightMap;
  12593. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  12594. uniforms.aoMap.value = material.aoMap;
  12595. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  12596. }
  12597. function refreshUniformsLambert ( uniforms, material ) {
  12598. uniforms.emissive.value = material.emissive;
  12599. }
  12600. function refreshUniformsLights ( uniforms, lights ) {
  12601. uniforms.ambientLightColor.value = lights.ambient;
  12602. uniforms.directionalLightColor.value = lights.directional.colors;
  12603. uniforms.directionalLightDirection.value = lights.directional.positions;
  12604. uniforms.pointLightColor.value = lights.point.colors;
  12605. uniforms.pointLightPosition.value = lights.point.positions;
  12606. uniforms.pointLightDistance.value = lights.point.distances;
  12607. uniforms.pointLightDecay.value = lights.point.decays;
  12608. uniforms.spotLightColor.value = lights.spot.colors;
  12609. uniforms.spotLightPosition.value = lights.spot.positions;
  12610. uniforms.spotLightDistance.value = lights.spot.distances;
  12611. uniforms.spotLightDirection.value = lights.spot.directions;
  12612. uniforms.spotLightAngleCos.value = lights.spot.anglesCos;
  12613. uniforms.spotLightExponent.value = lights.spot.exponents;
  12614. uniforms.spotLightDecay.value = lights.spot.decays;
  12615. uniforms.hemisphereLightSkyColor.value = lights.hemi.skyColors;
  12616. uniforms.hemisphereLightGroundColor.value = lights.hemi.groundColors;
  12617. uniforms.hemisphereLightDirection.value = lights.hemi.positions;
  12618. }
  12619. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  12620. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  12621. uniforms.ambientLightColor.needsUpdate = value;
  12622. uniforms.directionalLightColor.needsUpdate = value;
  12623. uniforms.directionalLightDirection.needsUpdate = value;
  12624. uniforms.pointLightColor.needsUpdate = value;
  12625. uniforms.pointLightPosition.needsUpdate = value;
  12626. uniforms.pointLightDistance.needsUpdate = value;
  12627. uniforms.pointLightDecay.needsUpdate = value;
  12628. uniforms.spotLightColor.needsUpdate = value;
  12629. uniforms.spotLightPosition.needsUpdate = value;
  12630. uniforms.spotLightDistance.needsUpdate = value;
  12631. uniforms.spotLightDirection.needsUpdate = value;
  12632. uniforms.spotLightAngleCos.needsUpdate = value;
  12633. uniforms.spotLightExponent.needsUpdate = value;
  12634. uniforms.spotLightDecay.needsUpdate = value;
  12635. uniforms.hemisphereLightSkyColor.needsUpdate = value;
  12636. uniforms.hemisphereLightGroundColor.needsUpdate = value;
  12637. uniforms.hemisphereLightDirection.needsUpdate = value;
  12638. }
  12639. function refreshUniformsShadow ( uniforms, lights ) {
  12640. if ( uniforms.shadowMatrix ) {
  12641. var j = 0;
  12642. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  12643. var light = lights[ i ];
  12644. if ( ! light.castShadow ) continue;
  12645. if ( light instanceof THREE.SpotLight || ( light instanceof THREE.DirectionalLight && ! light.shadowCascade ) ) {
  12646. uniforms.shadowMap.value[ j ] = light.shadowMap;
  12647. uniforms.shadowMapSize.value[ j ] = light.shadowMapSize;
  12648. uniforms.shadowMatrix.value[ j ] = light.shadowMatrix;
  12649. uniforms.shadowDarkness.value[ j ] = light.shadowDarkness;
  12650. uniforms.shadowBias.value[ j ] = light.shadowBias;
  12651. j ++;
  12652. }
  12653. }
  12654. }
  12655. }
  12656. // Uniforms (load to GPU)
  12657. function loadUniformsMatrices ( uniforms, object ) {
  12658. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object._modelViewMatrix.elements );
  12659. if ( uniforms.normalMatrix ) {
  12660. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object._normalMatrix.elements );
  12661. }
  12662. }
  12663. function getTextureUnit() {
  12664. var textureUnit = _usedTextureUnits;
  12665. if ( textureUnit >= _maxTextures ) {
  12666. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + _maxTextures );
  12667. }
  12668. _usedTextureUnits += 1;
  12669. return textureUnit;
  12670. }
  12671. function loadUniformsGeneric ( uniforms ) {
  12672. var texture, textureUnit, offset;
  12673. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  12674. var uniform = uniforms[ j ][ 0 ];
  12675. // needsUpdate property is not added to all uniforms.
  12676. if ( uniform.needsUpdate === false ) continue;
  12677. var type = uniform.type;
  12678. var value = uniform.value;
  12679. var location = uniforms[ j ][ 1 ];
  12680. switch ( type ) {
  12681. case '1i':
  12682. _gl.uniform1i( location, value );
  12683. break;
  12684. case '1f':
  12685. _gl.uniform1f( location, value );
  12686. break;
  12687. case '2f':
  12688. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  12689. break;
  12690. case '3f':
  12691. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  12692. break;
  12693. case '4f':
  12694. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  12695. break;
  12696. case '1iv':
  12697. _gl.uniform1iv( location, value );
  12698. break;
  12699. case '3iv':
  12700. _gl.uniform3iv( location, value );
  12701. break;
  12702. case '1fv':
  12703. _gl.uniform1fv( location, value );
  12704. break;
  12705. case '2fv':
  12706. _gl.uniform2fv( location, value );
  12707. break;
  12708. case '3fv':
  12709. _gl.uniform3fv( location, value );
  12710. break;
  12711. case '4fv':
  12712. _gl.uniform4fv( location, value );
  12713. break;
  12714. case 'Matrix3fv':
  12715. _gl.uniformMatrix3fv( location, false, value );
  12716. break;
  12717. case 'Matrix4fv':
  12718. _gl.uniformMatrix4fv( location, false, value );
  12719. break;
  12720. //
  12721. case 'i':
  12722. // single integer
  12723. _gl.uniform1i( location, value );
  12724. break;
  12725. case 'f':
  12726. // single float
  12727. _gl.uniform1f( location, value );
  12728. break;
  12729. case 'v2':
  12730. // single THREE.Vector2
  12731. _gl.uniform2f( location, value.x, value.y );
  12732. break;
  12733. case 'v3':
  12734. // single THREE.Vector3
  12735. _gl.uniform3f( location, value.x, value.y, value.z );
  12736. break;
  12737. case 'v4':
  12738. // single THREE.Vector4
  12739. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  12740. break;
  12741. case 'c':
  12742. // single THREE.Color
  12743. _gl.uniform3f( location, value.r, value.g, value.b );
  12744. break;
  12745. case 'iv1':
  12746. // flat array of integers (JS or typed array)
  12747. _gl.uniform1iv( location, value );
  12748. break;
  12749. case 'iv':
  12750. // flat array of integers with 3 x N size (JS or typed array)
  12751. _gl.uniform3iv( location, value );
  12752. break;
  12753. case 'fv1':
  12754. // flat array of floats (JS or typed array)
  12755. _gl.uniform1fv( location, value );
  12756. break;
  12757. case 'fv':
  12758. // flat array of floats with 3 x N size (JS or typed array)
  12759. _gl.uniform3fv( location, value );
  12760. break;
  12761. case 'v2v':
  12762. // array of THREE.Vector2
  12763. if ( uniform._array === undefined ) {
  12764. uniform._array = new Float32Array( 2 * value.length );
  12765. }
  12766. for ( var i = 0, il = value.length; i < il; i ++ ) {
  12767. offset = i * 2;
  12768. uniform._array[ offset + 0 ] = value[ i ].x;
  12769. uniform._array[ offset + 1 ] = value[ i ].y;
  12770. }
  12771. _gl.uniform2fv( location, uniform._array );
  12772. break;
  12773. case 'v3v':
  12774. // array of THREE.Vector3
  12775. if ( uniform._array === undefined ) {
  12776. uniform._array = new Float32Array( 3 * value.length );
  12777. }
  12778. for ( var i = 0, il = value.length; i < il; i ++ ) {
  12779. offset = i * 3;
  12780. uniform._array[ offset + 0 ] = value[ i ].x;
  12781. uniform._array[ offset + 1 ] = value[ i ].y;
  12782. uniform._array[ offset + 2 ] = value[ i ].z;
  12783. }
  12784. _gl.uniform3fv( location, uniform._array );
  12785. break;
  12786. case 'v4v':
  12787. // array of THREE.Vector4
  12788. if ( uniform._array === undefined ) {
  12789. uniform._array = new Float32Array( 4 * value.length );
  12790. }
  12791. for ( var i = 0, il = value.length; i < il; i ++ ) {
  12792. offset = i * 4;
  12793. uniform._array[ offset + 0 ] = value[ i ].x;
  12794. uniform._array[ offset + 1 ] = value[ i ].y;
  12795. uniform._array[ offset + 2 ] = value[ i ].z;
  12796. uniform._array[ offset + 3 ] = value[ i ].w;
  12797. }
  12798. _gl.uniform4fv( location, uniform._array );
  12799. break;
  12800. case 'm3':
  12801. // single THREE.Matrix3
  12802. _gl.uniformMatrix3fv( location, false, value.elements );
  12803. break;
  12804. case 'm3v':
  12805. // array of THREE.Matrix3
  12806. if ( uniform._array === undefined ) {
  12807. uniform._array = new Float32Array( 9 * value.length );
  12808. }
  12809. for ( var i = 0, il = value.length; i < il; i ++ ) {
  12810. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  12811. }
  12812. _gl.uniformMatrix3fv( location, false, uniform._array );
  12813. break;
  12814. case 'm4':
  12815. // single THREE.Matrix4
  12816. _gl.uniformMatrix4fv( location, false, value.elements );
  12817. break;
  12818. case 'm4v':
  12819. // array of THREE.Matrix4
  12820. if ( uniform._array === undefined ) {
  12821. uniform._array = new Float32Array( 16 * value.length );
  12822. }
  12823. for ( var i = 0, il = value.length; i < il; i ++ ) {
  12824. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  12825. }
  12826. _gl.uniformMatrix4fv( location, false, uniform._array );
  12827. break;
  12828. case 't':
  12829. // single THREE.Texture (2d or cube)
  12830. texture = value;
  12831. textureUnit = getTextureUnit();
  12832. _gl.uniform1i( location, textureUnit );
  12833. if ( ! texture ) continue;
  12834. if ( texture instanceof THREE.CubeTexture ||
  12835. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) { // CompressedTexture can have Array in image :/
  12836. setCubeTexture( texture, textureUnit );
  12837. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  12838. setCubeTextureDynamic( texture, textureUnit );
  12839. } else {
  12840. _this.setTexture( texture, textureUnit );
  12841. }
  12842. break;
  12843. case 'tv':
  12844. // array of THREE.Texture (2d)
  12845. if ( uniform._array === undefined ) {
  12846. uniform._array = [];
  12847. }
  12848. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  12849. uniform._array[ i ] = getTextureUnit();
  12850. }
  12851. _gl.uniform1iv( location, uniform._array );
  12852. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  12853. texture = uniform.value[ i ];
  12854. textureUnit = uniform._array[ i ];
  12855. if ( ! texture ) continue;
  12856. _this.setTexture( texture, textureUnit );
  12857. }
  12858. break;
  12859. default:
  12860. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  12861. }
  12862. }
  12863. }
  12864. function setupMatrices ( object, camera ) {
  12865. object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  12866. object._normalMatrix.getNormalMatrix( object._modelViewMatrix );
  12867. }
  12868. function setColorLinear( array, offset, color, intensity ) {
  12869. array[ offset + 0 ] = color.r * intensity;
  12870. array[ offset + 1 ] = color.g * intensity;
  12871. array[ offset + 2 ] = color.b * intensity;
  12872. }
  12873. function setupLights ( lights ) {
  12874. var l, ll, light,
  12875. r = 0, g = 0, b = 0,
  12876. color, skyColor, groundColor,
  12877. intensity,
  12878. distance,
  12879. zlights = _lights,
  12880. dirColors = zlights.directional.colors,
  12881. dirPositions = zlights.directional.positions,
  12882. pointColors = zlights.point.colors,
  12883. pointPositions = zlights.point.positions,
  12884. pointDistances = zlights.point.distances,
  12885. pointDecays = zlights.point.decays,
  12886. spotColors = zlights.spot.colors,
  12887. spotPositions = zlights.spot.positions,
  12888. spotDistances = zlights.spot.distances,
  12889. spotDirections = zlights.spot.directions,
  12890. spotAnglesCos = zlights.spot.anglesCos,
  12891. spotExponents = zlights.spot.exponents,
  12892. spotDecays = zlights.spot.decays,
  12893. hemiSkyColors = zlights.hemi.skyColors,
  12894. hemiGroundColors = zlights.hemi.groundColors,
  12895. hemiPositions = zlights.hemi.positions,
  12896. dirLength = 0,
  12897. pointLength = 0,
  12898. spotLength = 0,
  12899. hemiLength = 0,
  12900. dirCount = 0,
  12901. pointCount = 0,
  12902. spotCount = 0,
  12903. hemiCount = 0,
  12904. dirOffset = 0,
  12905. pointOffset = 0,
  12906. spotOffset = 0,
  12907. hemiOffset = 0;
  12908. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  12909. light = lights[ l ];
  12910. if ( light.onlyShadow ) continue;
  12911. color = light.color;
  12912. intensity = light.intensity;
  12913. distance = light.distance;
  12914. if ( light instanceof THREE.AmbientLight ) {
  12915. if ( ! light.visible ) continue;
  12916. r += color.r;
  12917. g += color.g;
  12918. b += color.b;
  12919. } else if ( light instanceof THREE.DirectionalLight ) {
  12920. dirCount += 1;
  12921. if ( ! light.visible ) continue;
  12922. _direction.setFromMatrixPosition( light.matrixWorld );
  12923. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  12924. _direction.sub( _vector3 );
  12925. _direction.normalize();
  12926. dirOffset = dirLength * 3;
  12927. dirPositions[ dirOffset + 0 ] = _direction.x;
  12928. dirPositions[ dirOffset + 1 ] = _direction.y;
  12929. dirPositions[ dirOffset + 2 ] = _direction.z;
  12930. setColorLinear( dirColors, dirOffset, color, intensity );
  12931. dirLength += 1;
  12932. } else if ( light instanceof THREE.PointLight ) {
  12933. pointCount += 1;
  12934. if ( ! light.visible ) continue;
  12935. pointOffset = pointLength * 3;
  12936. setColorLinear( pointColors, pointOffset, color, intensity );
  12937. _vector3.setFromMatrixPosition( light.matrixWorld );
  12938. pointPositions[ pointOffset + 0 ] = _vector3.x;
  12939. pointPositions[ pointOffset + 1 ] = _vector3.y;
  12940. pointPositions[ pointOffset + 2 ] = _vector3.z;
  12941. // distance is 0 if decay is 0, because there is no attenuation at all.
  12942. pointDistances[ pointLength ] = distance;
  12943. pointDecays[ pointLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  12944. pointLength += 1;
  12945. } else if ( light instanceof THREE.SpotLight ) {
  12946. spotCount += 1;
  12947. if ( ! light.visible ) continue;
  12948. spotOffset = spotLength * 3;
  12949. setColorLinear( spotColors, spotOffset, color, intensity );
  12950. _direction.setFromMatrixPosition( light.matrixWorld );
  12951. spotPositions[ spotOffset + 0 ] = _direction.x;
  12952. spotPositions[ spotOffset + 1 ] = _direction.y;
  12953. spotPositions[ spotOffset + 2 ] = _direction.z;
  12954. spotDistances[ spotLength ] = distance;
  12955. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  12956. _direction.sub( _vector3 );
  12957. _direction.normalize();
  12958. spotDirections[ spotOffset + 0 ] = _direction.x;
  12959. spotDirections[ spotOffset + 1 ] = _direction.y;
  12960. spotDirections[ spotOffset + 2 ] = _direction.z;
  12961. spotAnglesCos[ spotLength ] = Math.cos( light.angle );
  12962. spotExponents[ spotLength ] = light.exponent;
  12963. spotDecays[ spotLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  12964. spotLength += 1;
  12965. } else if ( light instanceof THREE.HemisphereLight ) {
  12966. hemiCount += 1;
  12967. if ( ! light.visible ) continue;
  12968. _direction.setFromMatrixPosition( light.matrixWorld );
  12969. _direction.normalize();
  12970. hemiOffset = hemiLength * 3;
  12971. hemiPositions[ hemiOffset + 0 ] = _direction.x;
  12972. hemiPositions[ hemiOffset + 1 ] = _direction.y;
  12973. hemiPositions[ hemiOffset + 2 ] = _direction.z;
  12974. skyColor = light.color;
  12975. groundColor = light.groundColor;
  12976. setColorLinear( hemiSkyColors, hemiOffset, skyColor, intensity );
  12977. setColorLinear( hemiGroundColors, hemiOffset, groundColor, intensity );
  12978. hemiLength += 1;
  12979. }
  12980. }
  12981. // null eventual remains from removed lights
  12982. // (this is to avoid if in shader)
  12983. for ( l = dirLength * 3, ll = Math.max( dirColors.length, dirCount * 3 ); l < ll; l ++ ) dirColors[ l ] = 0.0;
  12984. for ( l = pointLength * 3, ll = Math.max( pointColors.length, pointCount * 3 ); l < ll; l ++ ) pointColors[ l ] = 0.0;
  12985. for ( l = spotLength * 3, ll = Math.max( spotColors.length, spotCount * 3 ); l < ll; l ++ ) spotColors[ l ] = 0.0;
  12986. for ( l = hemiLength * 3, ll = Math.max( hemiSkyColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiSkyColors[ l ] = 0.0;
  12987. for ( l = hemiLength * 3, ll = Math.max( hemiGroundColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiGroundColors[ l ] = 0.0;
  12988. zlights.directional.length = dirLength;
  12989. zlights.point.length = pointLength;
  12990. zlights.spot.length = spotLength;
  12991. zlights.hemi.length = hemiLength;
  12992. zlights.ambient[ 0 ] = r;
  12993. zlights.ambient[ 1 ] = g;
  12994. zlights.ambient[ 2 ] = b;
  12995. }
  12996. // GL state setting
  12997. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  12998. if ( cullFace === THREE.CullFaceNone ) {
  12999. _gl.disable( _gl.CULL_FACE );
  13000. } else {
  13001. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  13002. _gl.frontFace( _gl.CW );
  13003. } else {
  13004. _gl.frontFace( _gl.CCW );
  13005. }
  13006. if ( cullFace === THREE.CullFaceBack ) {
  13007. _gl.cullFace( _gl.BACK );
  13008. } else if ( cullFace === THREE.CullFaceFront ) {
  13009. _gl.cullFace( _gl.FRONT );
  13010. } else {
  13011. _gl.cullFace( _gl.FRONT_AND_BACK );
  13012. }
  13013. _gl.enable( _gl.CULL_FACE );
  13014. }
  13015. };
  13016. this.setMaterialFaces = function ( material ) {
  13017. state.setDoubleSided( material.side === THREE.DoubleSide );
  13018. state.setFlipSided( material.side === THREE.BackSide );
  13019. };
  13020. // Textures
  13021. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  13022. var extension;
  13023. if ( isImagePowerOfTwo ) {
  13024. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  13025. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  13026. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  13027. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  13028. } else {
  13029. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  13030. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  13031. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  13032. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping. ( ' + texture.sourceFile + ' )' );
  13033. }
  13034. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  13035. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  13036. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  13037. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter. ( ' + texture.sourceFile + ' )' );
  13038. }
  13039. }
  13040. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  13041. if ( extension && texture.type !== THREE.FloatType && texture.type !== THREE.HalfFloatType ) {
  13042. if ( texture.anisotropy > 1 || texture.__currentAnisotropy ) {
  13043. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  13044. texture.__currentAnisotropy = texture.anisotropy;
  13045. }
  13046. }
  13047. }
  13048. this.uploadTexture = function ( texture, slot ) {
  13049. if ( texture.__webglInit === undefined ) {
  13050. texture.__webglInit = true;
  13051. texture.addEventListener( 'dispose', onTextureDispose );
  13052. texture.__webglTexture = _gl.createTexture();
  13053. _this.info.memory.textures ++;
  13054. }
  13055. state.activeTexture( _gl.TEXTURE0 + slot );
  13056. state.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
  13057. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  13058. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  13059. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  13060. texture.image = clampToMaxSize( texture.image, _maxTextureSize );
  13061. var image = texture.image,
  13062. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  13063. glFormat = paramThreeToGL( texture.format ),
  13064. glType = paramThreeToGL( texture.type );
  13065. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  13066. var mipmap, mipmaps = texture.mipmaps;
  13067. if ( texture instanceof THREE.DataTexture ) {
  13068. // use manually created mipmaps if available
  13069. // if there are no manual mipmaps
  13070. // set 0 level mipmap and then use GL to generate other mipmap levels
  13071. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  13072. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13073. mipmap = mipmaps[ i ];
  13074. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13075. }
  13076. texture.generateMipmaps = false;
  13077. } else {
  13078. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  13079. }
  13080. } else if ( texture instanceof THREE.CompressedTexture ) {
  13081. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13082. mipmap = mipmaps[ i ];
  13083. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  13084. if ( getCompressedTextureFormats().indexOf( glFormat ) > -1 ) {
  13085. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13086. } else {
  13087. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  13088. }
  13089. } else {
  13090. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13091. }
  13092. }
  13093. } else { // regular Texture (image, video, canvas)
  13094. // use manually created mipmaps if available
  13095. // if there are no manual mipmaps
  13096. // set 0 level mipmap and then use GL to generate other mipmap levels
  13097. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  13098. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13099. mipmap = mipmaps[ i ];
  13100. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  13101. }
  13102. texture.generateMipmaps = false;
  13103. } else {
  13104. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  13105. }
  13106. }
  13107. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  13108. texture.needsUpdate = false;
  13109. if ( texture.onUpdate ) texture.onUpdate( texture );
  13110. };
  13111. this.setTexture = function ( texture, slot ) {
  13112. if ( texture.needsUpdate === true ) {
  13113. var image = texture.image;
  13114. if ( image === undefined ) {
  13115. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  13116. return;
  13117. }
  13118. if ( image.complete === false ) {
  13119. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  13120. return;
  13121. }
  13122. _this.uploadTexture( texture, slot );
  13123. return;
  13124. }
  13125. state.activeTexture( _gl.TEXTURE0 + slot );
  13126. state.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
  13127. };
  13128. function clampToMaxSize ( image, maxSize ) {
  13129. if ( image.width > maxSize || image.height > maxSize ) {
  13130. // Warning: Scaling through the canvas will only work with images that use
  13131. // premultiplied alpha.
  13132. var scale = maxSize / Math.max( image.width, image.height );
  13133. var canvas = document.createElement( 'canvas' );
  13134. canvas.width = Math.floor( image.width * scale );
  13135. canvas.height = Math.floor( image.height * scale );
  13136. var context = canvas.getContext( '2d' );
  13137. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  13138. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  13139. return canvas;
  13140. }
  13141. return image;
  13142. }
  13143. function setCubeTexture ( texture, slot ) {
  13144. if ( texture.image.length === 6 ) {
  13145. if ( texture.needsUpdate ) {
  13146. if ( ! texture.image.__webglTextureCube ) {
  13147. texture.addEventListener( 'dispose', onTextureDispose );
  13148. texture.image.__webglTextureCube = _gl.createTexture();
  13149. _this.info.memory.textures ++;
  13150. }
  13151. state.activeTexture( _gl.TEXTURE0 + slot );
  13152. state.bindTexture( _gl.TEXTURE_CUBE_MAP, texture.image.__webglTextureCube );
  13153. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  13154. var isCompressed = texture instanceof THREE.CompressedTexture;
  13155. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  13156. var cubeImage = [];
  13157. for ( var i = 0; i < 6; i ++ ) {
  13158. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  13159. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], _maxCubemapSize );
  13160. } else {
  13161. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  13162. }
  13163. }
  13164. var image = cubeImage[ 0 ],
  13165. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  13166. glFormat = paramThreeToGL( texture.format ),
  13167. glType = paramThreeToGL( texture.type );
  13168. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  13169. for ( var i = 0; i < 6; i ++ ) {
  13170. if ( ! isCompressed ) {
  13171. if ( isDataTexture ) {
  13172. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  13173. } else {
  13174. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  13175. }
  13176. } else {
  13177. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  13178. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  13179. mipmap = mipmaps[ j ];
  13180. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  13181. if ( getCompressedTextureFormats().indexOf( glFormat ) > -1 ) {
  13182. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13183. } else {
  13184. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  13185. }
  13186. } else {
  13187. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13188. }
  13189. }
  13190. }
  13191. }
  13192. if ( texture.generateMipmaps && isImagePowerOfTwo ) {
  13193. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13194. }
  13195. texture.needsUpdate = false;
  13196. if ( texture.onUpdate ) texture.onUpdate( texture );
  13197. } else {
  13198. state.activeTexture( _gl.TEXTURE0 + slot );
  13199. state.bindTexture( _gl.TEXTURE_CUBE_MAP, texture.image.__webglTextureCube );
  13200. }
  13201. }
  13202. }
  13203. function setCubeTextureDynamic ( texture, slot ) {
  13204. state.activeTexture( _gl.TEXTURE0 + slot );
  13205. state.bindTexture( _gl.TEXTURE_CUBE_MAP, texture.__webglTexture );
  13206. }
  13207. // Render targets
  13208. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  13209. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13210. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, renderTarget.__webglTexture, 0 );
  13211. }
  13212. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  13213. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  13214. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13215. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  13216. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13217. /* For some reason this is not working. Defaulting to RGBA4.
  13218. } else if ( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13219. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  13220. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13221. */
  13222. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13223. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  13224. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13225. } else {
  13226. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  13227. }
  13228. }
  13229. this.setRenderTarget = function ( renderTarget ) {
  13230. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  13231. if ( renderTarget && renderTarget.__webglFramebuffer === undefined ) {
  13232. if ( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  13233. if ( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  13234. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13235. renderTarget.__webglTexture = _gl.createTexture();
  13236. _this.info.memory.textures ++;
  13237. // Setup texture, create render and frame buffers
  13238. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height ),
  13239. glFormat = paramThreeToGL( renderTarget.format ),
  13240. glType = paramThreeToGL( renderTarget.type );
  13241. if ( isCube ) {
  13242. renderTarget.__webglFramebuffer = [];
  13243. renderTarget.__webglRenderbuffer = [];
  13244. state.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTarget.__webglTexture );
  13245. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget, isTargetPowerOfTwo );
  13246. for ( var i = 0; i < 6; i ++ ) {
  13247. renderTarget.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13248. renderTarget.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  13249. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13250. setupFrameBuffer( renderTarget.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  13251. setupRenderBuffer( renderTarget.__webglRenderbuffer[ i ], renderTarget );
  13252. }
  13253. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13254. } else {
  13255. renderTarget.__webglFramebuffer = _gl.createFramebuffer();
  13256. if ( renderTarget.shareDepthFrom ) {
  13257. renderTarget.__webglRenderbuffer = renderTarget.shareDepthFrom.__webglRenderbuffer;
  13258. } else {
  13259. renderTarget.__webglRenderbuffer = _gl.createRenderbuffer();
  13260. }
  13261. state.bindTexture( _gl.TEXTURE_2D, renderTarget.__webglTexture );
  13262. setTextureParameters( _gl.TEXTURE_2D, renderTarget, isTargetPowerOfTwo );
  13263. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13264. setupFrameBuffer( renderTarget.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  13265. if ( renderTarget.shareDepthFrom ) {
  13266. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13267. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTarget.__webglRenderbuffer );
  13268. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13269. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderTarget.__webglRenderbuffer );
  13270. }
  13271. } else {
  13272. setupRenderBuffer( renderTarget.__webglRenderbuffer, renderTarget );
  13273. }
  13274. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  13275. }
  13276. // Release everything
  13277. if ( isCube ) {
  13278. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  13279. } else {
  13280. state.bindTexture( _gl.TEXTURE_2D, null );
  13281. }
  13282. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  13283. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  13284. }
  13285. var framebuffer, width, height, vx, vy;
  13286. if ( renderTarget ) {
  13287. if ( isCube ) {
  13288. framebuffer = renderTarget.__webglFramebuffer[ renderTarget.activeCubeFace ];
  13289. } else {
  13290. framebuffer = renderTarget.__webglFramebuffer;
  13291. }
  13292. width = renderTarget.width;
  13293. height = renderTarget.height;
  13294. vx = 0;
  13295. vy = 0;
  13296. } else {
  13297. framebuffer = null;
  13298. width = _viewportWidth;
  13299. height = _viewportHeight;
  13300. vx = _viewportX;
  13301. vy = _viewportY;
  13302. }
  13303. if ( framebuffer !== _currentFramebuffer ) {
  13304. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13305. _gl.viewport( vx, vy, width, height );
  13306. _currentFramebuffer = framebuffer;
  13307. }
  13308. _currentWidth = width;
  13309. _currentHeight = height;
  13310. };
  13311. this.readRenderTargetPixels = function( renderTarget, x, y, width, height, buffer ) {
  13312. if ( ! ( renderTarget instanceof THREE.WebGLRenderTarget ) ) {
  13313. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  13314. return;
  13315. }
  13316. if ( renderTarget.__webglFramebuffer ) {
  13317. if ( renderTarget.format !== THREE.RGBAFormat ) {
  13318. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA format. readPixels can read only RGBA format.' );
  13319. return;
  13320. }
  13321. var restore = false;
  13322. if ( renderTarget.__webglFramebuffer !== _currentFramebuffer ) {
  13323. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTarget.__webglFramebuffer );
  13324. restore = true;
  13325. }
  13326. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  13327. _gl.readPixels( x, y, width, height, _gl.RGBA, _gl.UNSIGNED_BYTE, buffer );
  13328. } else {
  13329. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  13330. }
  13331. if ( restore ) {
  13332. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  13333. }
  13334. }
  13335. };
  13336. function updateRenderTargetMipmap ( renderTarget ) {
  13337. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  13338. state.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTarget.__webglTexture );
  13339. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13340. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  13341. } else {
  13342. state.bindTexture( _gl.TEXTURE_2D, renderTarget.__webglTexture );
  13343. _gl.generateMipmap( _gl.TEXTURE_2D );
  13344. state.bindTexture( _gl.TEXTURE_2D, null );
  13345. }
  13346. }
  13347. // Fallback filters for non-power-of-2 textures
  13348. function filterFallback ( f ) {
  13349. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  13350. return _gl.NEAREST;
  13351. }
  13352. return _gl.LINEAR;
  13353. }
  13354. // Map three.js constants to WebGL constants
  13355. function paramThreeToGL ( p ) {
  13356. var extension;
  13357. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  13358. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  13359. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  13360. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  13361. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  13362. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  13363. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  13364. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  13365. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  13366. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  13367. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  13368. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  13369. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  13370. if ( p === THREE.ByteType ) return _gl.BYTE;
  13371. if ( p === THREE.ShortType ) return _gl.SHORT;
  13372. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  13373. if ( p === THREE.IntType ) return _gl.INT;
  13374. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  13375. if ( p === THREE.FloatType ) return _gl.FLOAT;
  13376. extension = extensions.get( 'OES_texture_half_float' );
  13377. if ( extension !== null ) {
  13378. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  13379. }
  13380. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  13381. if ( p === THREE.RGBFormat ) return _gl.RGB;
  13382. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  13383. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  13384. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  13385. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  13386. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  13387. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  13388. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  13389. if ( p === THREE.OneFactor ) return _gl.ONE;
  13390. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  13391. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  13392. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  13393. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  13394. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  13395. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  13396. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  13397. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  13398. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  13399. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13400. if ( extension !== null ) {
  13401. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13402. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13403. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13404. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13405. }
  13406. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13407. if ( extension !== null ) {
  13408. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13409. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13410. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13411. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13412. }
  13413. extension = extensions.get( 'EXT_blend_minmax' );
  13414. if ( extension !== null ) {
  13415. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  13416. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  13417. }
  13418. return 0;
  13419. }
  13420. // Allocations
  13421. function allocateBones ( object ) {
  13422. if ( _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  13423. return 1024;
  13424. } else {
  13425. // default for when object is not specified
  13426. // ( for example when prebuilding shader to be used with multiple objects )
  13427. //
  13428. // - leave some extra space for other uniforms
  13429. // - limit here is ANGLE's 254 max uniform vectors
  13430. // (up to 54 should be safe)
  13431. var nVertexUniforms = _gl.getParameter( _gl.MAX_VERTEX_UNIFORM_VECTORS );
  13432. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  13433. var maxBones = nVertexMatrices;
  13434. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  13435. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  13436. if ( maxBones < object.skeleton.bones.length ) {
  13437. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  13438. }
  13439. }
  13440. return maxBones;
  13441. }
  13442. }
  13443. function allocateLights( lights ) {
  13444. var dirLights = 0;
  13445. var pointLights = 0;
  13446. var spotLights = 0;
  13447. var hemiLights = 0;
  13448. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  13449. var light = lights[ l ];
  13450. if ( light.onlyShadow || light.visible === false ) continue;
  13451. if ( light instanceof THREE.DirectionalLight ) dirLights ++;
  13452. if ( light instanceof THREE.PointLight ) pointLights ++;
  13453. if ( light instanceof THREE.SpotLight ) spotLights ++;
  13454. if ( light instanceof THREE.HemisphereLight ) hemiLights ++;
  13455. }
  13456. return { 'directional': dirLights, 'point': pointLights, 'spot': spotLights, 'hemi': hemiLights };
  13457. }
  13458. function allocateShadows( lights ) {
  13459. var maxShadows = 0;
  13460. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  13461. var light = lights[ l ];
  13462. if ( ! light.castShadow ) continue;
  13463. if ( light instanceof THREE.SpotLight ) maxShadows ++;
  13464. if ( light instanceof THREE.DirectionalLight && ! light.shadowCascade ) maxShadows ++;
  13465. }
  13466. return maxShadows;
  13467. }
  13468. // DEPRECATED
  13469. this.initMaterial = function () {
  13470. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  13471. };
  13472. this.addPrePlugin = function () {
  13473. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  13474. };
  13475. this.addPostPlugin = function () {
  13476. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  13477. };
  13478. this.updateShadowMap = function () {
  13479. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  13480. };
  13481. Object.defineProperties( this, {
  13482. shadowMapEnabled: {
  13483. get: function () {
  13484. return shadowMap.enabled;
  13485. },
  13486. set: function ( value ) {
  13487. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  13488. shadowMap.enabled = value;
  13489. }
  13490. },
  13491. shadowMapType: {
  13492. get: function () {
  13493. return shadowMap.type;
  13494. },
  13495. set: function ( value ) {
  13496. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  13497. shadowMap.type = value;
  13498. }
  13499. },
  13500. shadowMapCullFace: {
  13501. get: function () {
  13502. return shadowMap.cullFace;
  13503. },
  13504. set: function ( value ) {
  13505. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  13506. shadowMap.cullFace = value;
  13507. }
  13508. },
  13509. shadowMapDebug: {
  13510. get: function () {
  13511. return shadowMap.debug;
  13512. },
  13513. set: function ( value ) {
  13514. console.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' );
  13515. shadowMap.debug = value;
  13516. }
  13517. },
  13518. shadowMapCascade: {
  13519. get: function () {
  13520. return shadowMap.cascade;
  13521. },
  13522. set: function ( value ) {
  13523. console.warn( 'THREE.WebGLRenderer: .shadowMapCascade is now .shadowMap.cascade.' );
  13524. shadowMap.cascade = value;
  13525. }
  13526. }
  13527. } );
  13528. };
  13529. // File:src/renderers/WebGLRenderTarget.js
  13530. /**
  13531. * @author szimek / https://github.com/szimek/
  13532. * @author alteredq / http://alteredqualia.com/
  13533. */
  13534. THREE.WebGLRenderTarget = function ( width, height, options ) {
  13535. this.width = width;
  13536. this.height = height;
  13537. options = options || {};
  13538. this.wrapS = options.wrapS !== undefined ? options.wrapS : THREE.ClampToEdgeWrapping;
  13539. this.wrapT = options.wrapT !== undefined ? options.wrapT : THREE.ClampToEdgeWrapping;
  13540. this.magFilter = options.magFilter !== undefined ? options.magFilter : THREE.LinearFilter;
  13541. this.minFilter = options.minFilter !== undefined ? options.minFilter : THREE.LinearMipMapLinearFilter;
  13542. this.anisotropy = options.anisotropy !== undefined ? options.anisotropy : 1;
  13543. this.offset = new THREE.Vector2( 0, 0 );
  13544. this.repeat = new THREE.Vector2( 1, 1 );
  13545. this.format = options.format !== undefined ? options.format : THREE.RGBAFormat;
  13546. this.type = options.type !== undefined ? options.type : THREE.UnsignedByteType;
  13547. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  13548. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  13549. this.generateMipmaps = true;
  13550. this.shareDepthFrom = options.shareDepthFrom !== undefined ? options.shareDepthFrom : null;
  13551. };
  13552. THREE.WebGLRenderTarget.prototype = {
  13553. constructor: THREE.WebGLRenderTarget,
  13554. setSize: function ( width, height ) {
  13555. if ( this.width !== width || this.height !== height ) {
  13556. this.width = width;
  13557. this.height = height;
  13558. this.dispose();
  13559. }
  13560. },
  13561. clone: function () {
  13562. var tmp = new THREE.WebGLRenderTarget( this.width, this.height );
  13563. tmp.wrapS = this.wrapS;
  13564. tmp.wrapT = this.wrapT;
  13565. tmp.magFilter = this.magFilter;
  13566. tmp.minFilter = this.minFilter;
  13567. tmp.anisotropy = this.anisotropy;
  13568. tmp.offset.copy( this.offset );
  13569. tmp.repeat.copy( this.repeat );
  13570. tmp.format = this.format;
  13571. tmp.type = this.type;
  13572. tmp.depthBuffer = this.depthBuffer;
  13573. tmp.stencilBuffer = this.stencilBuffer;
  13574. tmp.generateMipmaps = this.generateMipmaps;
  13575. tmp.shareDepthFrom = this.shareDepthFrom;
  13576. return tmp;
  13577. },
  13578. dispose: function () {
  13579. this.dispatchEvent( { type: 'dispose' } );
  13580. }
  13581. };
  13582. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  13583. // File:src/renderers/WebGLRenderTargetCube.js
  13584. /**
  13585. * @author alteredq / http://alteredqualia.com
  13586. */
  13587. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  13588. THREE.WebGLRenderTarget.call( this, width, height, options );
  13589. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  13590. };
  13591. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  13592. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  13593. // File:src/renderers/webgl/WebGLExtensions.js
  13594. /**
  13595. * @author mrdoob / http://mrdoob.com/
  13596. */
  13597. THREE.WebGLExtensions = function ( gl ) {
  13598. var extensions = {};
  13599. this.get = function ( name ) {
  13600. if ( extensions[ name ] !== undefined ) {
  13601. return extensions[ name ];
  13602. }
  13603. var extension;
  13604. switch ( name ) {
  13605. case 'EXT_texture_filter_anisotropic':
  13606. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  13607. break;
  13608. case 'WEBGL_compressed_texture_s3tc':
  13609. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  13610. break;
  13611. case 'WEBGL_compressed_texture_pvrtc':
  13612. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  13613. break;
  13614. default:
  13615. extension = gl.getExtension( name );
  13616. }
  13617. if ( extension === null ) {
  13618. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  13619. }
  13620. extensions[ name ] = extension;
  13621. return extension;
  13622. };
  13623. };
  13624. // File:src/renderers/webgl/WebGLGeometries.js
  13625. /**
  13626. * @author mrdoob / http://mrdoob.com/
  13627. */
  13628. THREE.WebGLGeometries = function ( gl, info ) {
  13629. var geometries = {};
  13630. this.get = function ( object ) {
  13631. var geometry = object.geometry;
  13632. if ( geometries[ geometry.id ] !== undefined ) {
  13633. return geometries[ geometry.id ];
  13634. }
  13635. geometry.addEventListener( 'dispose', onGeometryDispose );
  13636. if ( geometry instanceof THREE.BufferGeometry ) {
  13637. geometries[ geometry.id ] = geometry;
  13638. } else {
  13639. geometries[ geometry.id ] = new THREE.BufferGeometry().setFromObject( object );
  13640. }
  13641. info.memory.geometries ++;
  13642. return geometries[ geometry.id ];
  13643. };
  13644. function onGeometryDispose( event ) {
  13645. var geometry = event.target;
  13646. geometry.removeEventListener( 'dispose', onGeometryDispose );
  13647. geometry = geometries[ geometry.id ];
  13648. for ( var name in geometry.attributes ) {
  13649. var attribute = geometry.attributes[ name ];
  13650. if ( attribute.buffer !== undefined ) {
  13651. gl.deleteBuffer( attribute.buffer );
  13652. delete attribute.buffer;
  13653. }
  13654. }
  13655. info.memory.geometries --;
  13656. }
  13657. };
  13658. // File:src/renderers/webgl/WebGLObjects.js
  13659. /**
  13660. * @author mrdoob / http://mrdoob.com/
  13661. */
  13662. THREE.WebGLObjects = function ( gl, info ) {
  13663. var objects = {};
  13664. var objectsImmediate = [];
  13665. var morphInfluences = new Float32Array( 8 );
  13666. var geometries = new THREE.WebGLGeometries( gl, info );
  13667. //
  13668. function onObjectRemoved( event ) {
  13669. var object = event.target;
  13670. object.traverse( function ( child ) {
  13671. child.removeEventListener( 'remove', onObjectRemoved );
  13672. removeObject( child );
  13673. } );
  13674. }
  13675. function removeObject( object ) {
  13676. if ( object instanceof THREE.Mesh ||
  13677. object instanceof THREE.PointCloud ||
  13678. object instanceof THREE.Line ) {
  13679. delete objects[ object.id ];
  13680. } else if ( object instanceof THREE.ImmediateRenderObject || object.immediateRenderCallback ) {
  13681. removeInstances( objectsImmediate, object );
  13682. }
  13683. delete object.__webglInit;
  13684. delete object._modelViewMatrix;
  13685. delete object._normalMatrix;
  13686. delete object.__webglActive;
  13687. }
  13688. function removeInstances( objlist, object ) {
  13689. for ( var o = objlist.length - 1; o >= 0; o -- ) {
  13690. if ( objlist[ o ].object === object ) {
  13691. objlist.splice( o, 1 );
  13692. }
  13693. }
  13694. }
  13695. //
  13696. this.objects = objects;
  13697. this.objectsImmediate = objectsImmediate;
  13698. this.geometries = geometries;
  13699. this.init = function ( object ) {
  13700. if ( object.__webglInit === undefined ) {
  13701. object.__webglInit = true;
  13702. object._modelViewMatrix = new THREE.Matrix4();
  13703. object._normalMatrix = new THREE.Matrix3();
  13704. object.addEventListener( 'removed', onObjectRemoved );
  13705. }
  13706. if ( object.__webglActive === undefined ) {
  13707. object.__webglActive = true;
  13708. if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.PointCloud ) {
  13709. objects[ object.id ] = {
  13710. id: object.id,
  13711. object: object,
  13712. z: 0
  13713. };
  13714. } else if ( object instanceof THREE.ImmediateRenderObject || object.immediateRenderCallback ) {
  13715. objectsImmediate.push( {
  13716. id: null,
  13717. object: object,
  13718. opaque: null,
  13719. transparent: null,
  13720. z: 0
  13721. } );
  13722. }
  13723. }
  13724. };
  13725. function numericalSort ( a, b ) {
  13726. return b[ 0 ] - a[ 0 ];
  13727. }
  13728. function updateObject( object ) {
  13729. var geometry = geometries.get( object );
  13730. if ( object.geometry instanceof THREE.DynamicGeometry ) {
  13731. geometry.updateFromObject( object );
  13732. }
  13733. // morph targets
  13734. if ( object.morphTargetInfluences !== undefined ) {
  13735. var activeInfluences = [];
  13736. var morphTargetInfluences = object.morphTargetInfluences;
  13737. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  13738. var influence = morphTargetInfluences[ i ];
  13739. activeInfluences.push( [ influence, i ] );
  13740. }
  13741. activeInfluences.sort( numericalSort );
  13742. if ( activeInfluences.length > 8 ) {
  13743. activeInfluences.length = 8;
  13744. }
  13745. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  13746. morphInfluences[ i ] = activeInfluences[ i ][ 0 ];
  13747. var attribute = geometry.morphAttributes[ activeInfluences[ i ][ 1 ] ];
  13748. geometry.addAttribute( 'morphTarget' + i, attribute );
  13749. }
  13750. var material = object.material;
  13751. if ( material.program !== undefined ) {
  13752. if ( material.program.uniforms.morphTargetInfluences !== null ) {
  13753. gl.uniform1fv( material.program.uniforms.morphTargetInfluences, morphInfluences );
  13754. }
  13755. } else {
  13756. console.warn( 'TOFIX: material.program is undefined' );
  13757. }
  13758. }
  13759. //
  13760. if ( geometry instanceof THREE.BufferGeometry ) {
  13761. var attributes = geometry.attributes;
  13762. for ( var name in attributes ) {
  13763. var attribute = attributes[ name ];
  13764. var bufferType = ( name === 'index' ) ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER;
  13765. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  13766. if ( data.buffer === undefined ) {
  13767. data.buffer = gl.createBuffer();
  13768. gl.bindBuffer( bufferType, data.buffer );
  13769. var usage = gl.STATIC_DRAW;
  13770. if ( data instanceof THREE.DynamicBufferAttribute
  13771. || ( data instanceof THREE.InstancedBufferAttribute && data.dynamic === true )
  13772. || ( data instanceof THREE.InterleavedBuffer && data.dynamic === true ) ) {
  13773. usage = gl.DYNAMIC_DRAW;
  13774. }
  13775. gl.bufferData( bufferType, data.array, usage );
  13776. data.needsUpdate = false;
  13777. } else if ( data.needsUpdate === true ) {
  13778. gl.bindBuffer( bufferType, data.buffer );
  13779. if ( data.updateRange === undefined || data.updateRange.count === -1 ) { // Not using update ranges
  13780. gl.bufferSubData( bufferType, 0, data.array );
  13781. } else if ( data.updateRange.count === 0 ) {
  13782. 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.' );
  13783. } else {
  13784. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  13785. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  13786. data.updateRange.count = 0; // reset range
  13787. }
  13788. data.needsUpdate = false;
  13789. }
  13790. }
  13791. }
  13792. };
  13793. this.update = function ( renderList ) {
  13794. for ( var i = 0, ul = renderList.length; i < ul; i++ ) {
  13795. var object = renderList[i].object;
  13796. if ( object.material.visible !== false ) {
  13797. updateObject( object );
  13798. }
  13799. }
  13800. };
  13801. };
  13802. // File:src/renderers/webgl/WebGLProgram.js
  13803. THREE.WebGLProgram = ( function () {
  13804. var programIdCount = 0;
  13805. function generateDefines( defines ) {
  13806. var chunks = [];
  13807. for ( var name in defines ) {
  13808. var value = defines[ name ];
  13809. if ( value === false ) continue;
  13810. chunks.push( '#define ' + name + ' ' + value );
  13811. }
  13812. return chunks.join( '\n' );
  13813. }
  13814. function cacheUniformLocations( gl, program, identifiers ) {
  13815. var uniforms = {};
  13816. for ( var i = 0, l = identifiers.length; i < l; i ++ ) {
  13817. var id = identifiers[ i ];
  13818. uniforms[ id ] = gl.getUniformLocation( program, id );
  13819. }
  13820. return uniforms;
  13821. }
  13822. function cacheAttributeLocations( gl, program, identifiers ) {
  13823. var attributes = {};
  13824. for ( var i = 0, l = identifiers.length; i < l; i ++ ) {
  13825. var id = identifiers[ i ];
  13826. attributes[ id ] = gl.getAttribLocation( program, id );
  13827. }
  13828. return attributes;
  13829. }
  13830. function programArrayToString( previousValue, currentValue, index, array ) {
  13831. if ( currentValue !== '' && currentValue !== undefined && currentValue !== null ) {
  13832. return previousValue + currentValue + '\n';
  13833. }
  13834. return previousValue;
  13835. }
  13836. return function ( renderer, code, material, parameters ) {
  13837. var gl = renderer.context;
  13838. var defines = material.defines;
  13839. var uniforms = material.__webglShader.uniforms;
  13840. var attributes = material.attributes;
  13841. var vertexShader = material.__webglShader.vertexShader;
  13842. var fragmentShader = material.__webglShader.fragmentShader;
  13843. var index0AttributeName = material.index0AttributeName;
  13844. /*
  13845. if ( index0AttributeName === undefined && parameters.morphTargets === true ) {
  13846. // programs with morphTargets displace position out of attribute 0
  13847. index0AttributeName = 'position';
  13848. }
  13849. */
  13850. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  13851. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  13852. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  13853. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  13854. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  13855. }
  13856. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  13857. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  13858. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  13859. if ( parameters.envMap ) {
  13860. switch ( material.envMap.mapping ) {
  13861. case THREE.CubeReflectionMapping:
  13862. case THREE.CubeRefractionMapping:
  13863. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  13864. break;
  13865. case THREE.EquirectangularReflectionMapping:
  13866. case THREE.EquirectangularRefractionMapping:
  13867. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  13868. break;
  13869. case THREE.SphericalReflectionMapping:
  13870. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  13871. break;
  13872. }
  13873. switch ( material.envMap.mapping ) {
  13874. case THREE.CubeRefractionMapping:
  13875. case THREE.EquirectangularRefractionMapping:
  13876. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  13877. break;
  13878. }
  13879. switch ( material.combine ) {
  13880. case THREE.MultiplyOperation:
  13881. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  13882. break;
  13883. case THREE.MixOperation:
  13884. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  13885. break;
  13886. case THREE.AddOperation:
  13887. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  13888. break;
  13889. }
  13890. }
  13891. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  13892. // console.log( 'building new program ' );
  13893. //
  13894. var customDefines = generateDefines( defines );
  13895. //
  13896. var program = gl.createProgram();
  13897. var prefix_vertex, prefix_fragment;
  13898. if ( material instanceof THREE.RawShaderMaterial ) {
  13899. prefix_vertex = '';
  13900. prefix_fragment = '';
  13901. } else {
  13902. prefix_vertex = [
  13903. 'precision ' + parameters.precision + ' float;',
  13904. 'precision ' + parameters.precision + ' int;',
  13905. customDefines,
  13906. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  13907. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  13908. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  13909. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  13910. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  13911. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  13912. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  13913. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  13914. '#define MAX_SHADOWS ' + parameters.maxShadows,
  13915. '#define MAX_BONES ' + parameters.maxBones,
  13916. parameters.map ? '#define USE_MAP' : '',
  13917. parameters.envMap ? '#define USE_ENVMAP' : '',
  13918. parameters.envMap ? '#define ' + envMapModeDefine : '',
  13919. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  13920. parameters.aoMap ? '#define USE_AOMAP' : '',
  13921. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  13922. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  13923. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  13924. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  13925. parameters.vertexColors ? '#define USE_COLOR' : '',
  13926. parameters.flatShading ? '#define FLAT_SHADED': '',
  13927. parameters.skinning ? '#define USE_SKINNING' : '',
  13928. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  13929. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  13930. parameters.morphNormals ? '#define USE_MORPHNORMALS' : '',
  13931. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  13932. parameters.flipSided ? '#define FLIP_SIDED' : '',
  13933. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  13934. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  13935. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  13936. parameters.shadowMapCascade ? '#define SHADOWMAP_CASCADE' : '',
  13937. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  13938. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  13939. parameters.logarithmicDepthBuffer && renderer.extensions.get('EXT_frag_depth') ? '#define USE_LOGDEPTHBUF_EXT' : '',
  13940. 'uniform mat4 modelMatrix;',
  13941. 'uniform mat4 modelViewMatrix;',
  13942. 'uniform mat4 projectionMatrix;',
  13943. 'uniform mat4 viewMatrix;',
  13944. 'uniform mat3 normalMatrix;',
  13945. 'uniform vec3 cameraPosition;',
  13946. 'attribute vec3 position;',
  13947. 'attribute vec3 normal;',
  13948. 'attribute vec2 uv;',
  13949. '#ifdef USE_COLOR',
  13950. ' attribute vec3 color;',
  13951. '#endif',
  13952. '#ifdef USE_MORPHTARGETS',
  13953. ' attribute vec3 morphTarget0;',
  13954. ' attribute vec3 morphTarget1;',
  13955. ' attribute vec3 morphTarget2;',
  13956. ' attribute vec3 morphTarget3;',
  13957. ' #ifdef USE_MORPHNORMALS',
  13958. ' attribute vec3 morphNormal0;',
  13959. ' attribute vec3 morphNormal1;',
  13960. ' attribute vec3 morphNormal2;',
  13961. ' attribute vec3 morphNormal3;',
  13962. ' #else',
  13963. ' attribute vec3 morphTarget4;',
  13964. ' attribute vec3 morphTarget5;',
  13965. ' attribute vec3 morphTarget6;',
  13966. ' attribute vec3 morphTarget7;',
  13967. ' #endif',
  13968. '#endif',
  13969. '#ifdef USE_SKINNING',
  13970. ' attribute vec4 skinIndex;',
  13971. ' attribute vec4 skinWeight;',
  13972. '#endif',
  13973. ''
  13974. ].reduce( programArrayToString, '' );
  13975. prefix_fragment = [
  13976. ( parameters.bumpMap || parameters.normalMap || parameters.flatShading || material.derivatives ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  13977. 'precision ' + parameters.precision + ' float;',
  13978. 'precision ' + parameters.precision + ' int;',
  13979. customDefines,
  13980. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  13981. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  13982. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  13983. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  13984. '#define MAX_SHADOWS ' + parameters.maxShadows,
  13985. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  13986. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  13987. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  13988. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  13989. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  13990. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  13991. parameters.map ? '#define USE_MAP' : '',
  13992. parameters.envMap ? '#define USE_ENVMAP' : '',
  13993. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  13994. parameters.envMap ? '#define ' + envMapModeDefine : '',
  13995. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  13996. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  13997. parameters.aoMap ? '#define USE_AOMAP' : '',
  13998. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  13999. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  14000. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  14001. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  14002. parameters.vertexColors ? '#define USE_COLOR' : '',
  14003. parameters.flatShading ? '#define FLAT_SHADED': '',
  14004. parameters.metal ? '#define METAL' : '',
  14005. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  14006. parameters.flipSided ? '#define FLIP_SIDED' : '',
  14007. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  14008. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  14009. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  14010. parameters.shadowMapCascade ? '#define SHADOWMAP_CASCADE' : '',
  14011. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  14012. parameters.logarithmicDepthBuffer && renderer.extensions.get('EXT_frag_depth') ? '#define USE_LOGDEPTHBUF_EXT' : '',
  14013. 'uniform mat4 viewMatrix;',
  14014. 'uniform vec3 cameraPosition;',
  14015. ''
  14016. ].reduce( programArrayToString, '' );
  14017. }
  14018. var glVertexShader = new THREE.WebGLShader( gl, gl.VERTEX_SHADER, prefix_vertex + vertexShader );
  14019. var glFragmentShader = new THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, prefix_fragment + fragmentShader );
  14020. gl.attachShader( program, glVertexShader );
  14021. gl.attachShader( program, glFragmentShader );
  14022. if ( index0AttributeName !== undefined ) {
  14023. // Force a particular attribute to index 0.
  14024. // because potentially expensive emulation is done by browser if attribute 0 is disabled.
  14025. // And, color, for example is often automatically bound to index 0 so disabling it
  14026. gl.bindAttribLocation( program, 0, index0AttributeName );
  14027. }
  14028. gl.linkProgram( program );
  14029. var programLogInfo = gl.getProgramInfoLog( program );
  14030. var vertexErrorLogInfo = gl.getShaderInfoLog( glVertexShader );
  14031. var fragmentErrorLogInfo = gl.getShaderInfoLog( glFragmentShader );
  14032. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  14033. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLogInfo, vertexErrorLogInfo, fragmentErrorLogInfo );
  14034. }
  14035. if ( programLogInfo !== '' ) {
  14036. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLogInfo );
  14037. }
  14038. // clean up
  14039. gl.deleteShader( glVertexShader );
  14040. gl.deleteShader( glFragmentShader );
  14041. // cache uniform locations
  14042. var identifiers = [
  14043. 'viewMatrix',
  14044. 'modelViewMatrix',
  14045. 'projectionMatrix',
  14046. 'normalMatrix',
  14047. 'modelMatrix',
  14048. 'cameraPosition',
  14049. 'morphTargetInfluences',
  14050. 'bindMatrix',
  14051. 'bindMatrixInverse'
  14052. ];
  14053. if ( parameters.useVertexTexture ) {
  14054. identifiers.push( 'boneTexture', 'boneTextureWidth', 'boneTextureHeight' );
  14055. } else {
  14056. identifiers.push( 'boneGlobalMatrices' );
  14057. }
  14058. if ( parameters.logarithmicDepthBuffer ) {
  14059. identifiers.push( 'logDepthBufFC' );
  14060. }
  14061. for ( var u in uniforms ) {
  14062. identifiers.push( u );
  14063. }
  14064. this.uniforms = cacheUniformLocations( gl, program, identifiers );
  14065. // cache attributes locations
  14066. if ( material instanceof THREE.RawShaderMaterial ) {
  14067. identifiers = attributes;
  14068. } else {
  14069. identifiers = [
  14070. 'position',
  14071. 'normal',
  14072. 'uv',
  14073. 'uv2',
  14074. 'tangent',
  14075. 'color',
  14076. 'skinIndex',
  14077. 'skinWeight',
  14078. 'lineDistance'
  14079. ];
  14080. for ( var i = 0; i < parameters.maxMorphTargets; i ++ ) {
  14081. identifiers.push( 'morphTarget' + i );
  14082. }
  14083. for ( var i = 0; i < parameters.maxMorphNormals; i ++ ) {
  14084. identifiers.push( 'morphNormal' + i );
  14085. }
  14086. // ShaderMaterial attributes
  14087. if ( Array.isArray( attributes ) ) {
  14088. identifiers = identifiers.concat( attributes );
  14089. }
  14090. }
  14091. this.attributes = cacheAttributeLocations( gl, program, identifiers );
  14092. //
  14093. this.id = programIdCount ++;
  14094. this.code = code;
  14095. this.usedTimes = 1;
  14096. this.program = program;
  14097. this.vertexShader = glVertexShader;
  14098. this.fragmentShader = glFragmentShader;
  14099. return this;
  14100. };
  14101. } )();
  14102. // File:src/renderers/webgl/WebGLShader.js
  14103. THREE.WebGLShader = ( function () {
  14104. var addLineNumbers = function ( string ) {
  14105. var lines = string.split( '\n' );
  14106. for ( var i = 0; i < lines.length; i ++ ) {
  14107. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  14108. }
  14109. return lines.join( '\n' );
  14110. };
  14111. return function ( gl, type, string ) {
  14112. var shader = gl.createShader( type );
  14113. gl.shaderSource( shader, string );
  14114. gl.compileShader( shader );
  14115. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  14116. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  14117. }
  14118. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  14119. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  14120. }
  14121. // --enable-privileged-webgl-extension
  14122. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  14123. return shader;
  14124. };
  14125. } )();
  14126. // File:src/renderers/webgl/WebGLShadowMap.js
  14127. /**
  14128. * @author alteredq / http://alteredqualia.com/
  14129. * @author mrdoob / http://mrdoob.com/
  14130. */
  14131. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  14132. var _gl = _renderer.context,
  14133. _frustum = new THREE.Frustum(),
  14134. _projScreenMatrix = new THREE.Matrix4(),
  14135. _min = new THREE.Vector3(),
  14136. _max = new THREE.Vector3(),
  14137. _webglObjects = _objects.objects,
  14138. _webglObjectsImmediate = _objects.objectsImmediate,
  14139. _matrixPosition = new THREE.Vector3(),
  14140. _renderList = [];
  14141. // init
  14142. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  14143. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  14144. var _depthMaterial = new THREE.ShaderMaterial( {
  14145. uniforms: depthUniforms,
  14146. vertexShader: depthShader.vertexShader,
  14147. fragmentShader: depthShader.fragmentShader
  14148. } );
  14149. var _depthMaterialMorph = new THREE.ShaderMaterial( {
  14150. uniforms: depthUniforms,
  14151. vertexShader: depthShader.vertexShader,
  14152. fragmentShader: depthShader.fragmentShader,
  14153. morphTargets: true
  14154. } );
  14155. var _depthMaterialSkin = new THREE.ShaderMaterial( {
  14156. uniforms: depthUniforms,
  14157. vertexShader: depthShader.vertexShader,
  14158. fragmentShader: depthShader.fragmentShader,
  14159. skinning: true
  14160. } );
  14161. var _depthMaterialMorphSkin = new THREE.ShaderMaterial( {
  14162. uniforms: depthUniforms,
  14163. vertexShader: depthShader.vertexShader,
  14164. fragmentShader: depthShader.fragmentShader,
  14165. morphTargets: true,
  14166. skinning: true
  14167. } );
  14168. _depthMaterial._shadowPass = true;
  14169. _depthMaterialMorph._shadowPass = true;
  14170. _depthMaterialSkin._shadowPass = true;
  14171. _depthMaterialMorphSkin._shadowPass = true;
  14172. //
  14173. var scope = this;
  14174. this.enabled = false;
  14175. this.type = THREE.PCFShadowMap;
  14176. this.cullFace = THREE.CullFaceFront;
  14177. this.debug = false;
  14178. this.cascade = false;
  14179. this.render = function ( scene, camera ) {
  14180. if ( scope.enabled === false ) return;
  14181. var i, il, j, jl, n,
  14182. shadowMap, shadowMatrix, shadowCamera,
  14183. webglObject, object, material, light,
  14184. lights = [],
  14185. k = 0,
  14186. fog = null;
  14187. // set GL state for depth map
  14188. _gl.clearColor( 1, 1, 1, 1 );
  14189. _gl.disable( _gl.BLEND );
  14190. _gl.enable( _gl.CULL_FACE );
  14191. _gl.frontFace( _gl.CCW );
  14192. if ( scope.cullFace === THREE.CullFaceFront ) {
  14193. _gl.cullFace( _gl.FRONT );
  14194. } else {
  14195. _gl.cullFace( _gl.BACK );
  14196. }
  14197. _renderer.state.setDepthTest( true );
  14198. // preprocess lights
  14199. // - skip lights that are not casting shadows
  14200. // - create virtual lights for cascaded shadow maps
  14201. for ( i = 0, il = _lights.length; i < il; i ++ ) {
  14202. light = _lights[ i ];
  14203. if ( ! light.castShadow ) continue;
  14204. if ( ( light instanceof THREE.DirectionalLight ) && light.shadowCascade ) {
  14205. for ( n = 0; n < light.shadowCascadeCount; n ++ ) {
  14206. var virtualLight;
  14207. if ( ! light.shadowCascadeArray[ n ] ) {
  14208. virtualLight = createVirtualLight( light, n );
  14209. virtualLight.originalCamera = camera;
  14210. var gyro = new THREE.Gyroscope();
  14211. gyro.position.copy( light.shadowCascadeOffset );
  14212. gyro.add( virtualLight );
  14213. gyro.add( virtualLight.target );
  14214. camera.add( gyro );
  14215. light.shadowCascadeArray[ n ] = virtualLight;
  14216. //console.log( "Created virtualLight", virtualLight );
  14217. } else {
  14218. virtualLight = light.shadowCascadeArray[ n ];
  14219. }
  14220. updateVirtualLight( light, n );
  14221. lights[ k ] = virtualLight;
  14222. k ++;
  14223. }
  14224. } else {
  14225. lights[ k ] = light;
  14226. k ++;
  14227. }
  14228. }
  14229. // render depth map
  14230. for ( i = 0, il = lights.length; i < il; i ++ ) {
  14231. light = lights[ i ];
  14232. if ( ! light.shadowMap ) {
  14233. var shadowFilter = THREE.LinearFilter;
  14234. if ( scope.type === THREE.PCFSoftShadowMap ) {
  14235. shadowFilter = THREE.NearestFilter;
  14236. }
  14237. var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
  14238. light.shadowMap = new THREE.WebGLRenderTarget( light.shadowMapWidth, light.shadowMapHeight, pars );
  14239. light.shadowMapSize = new THREE.Vector2( light.shadowMapWidth, light.shadowMapHeight );
  14240. light.shadowMatrix = new THREE.Matrix4();
  14241. }
  14242. if ( ! light.shadowCamera ) {
  14243. if ( light instanceof THREE.SpotLight ) {
  14244. light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, light.shadowMapWidth / light.shadowMapHeight, light.shadowCameraNear, light.shadowCameraFar );
  14245. } else if ( light instanceof THREE.DirectionalLight ) {
  14246. light.shadowCamera = new THREE.OrthographicCamera( light.shadowCameraLeft, light.shadowCameraRight, light.shadowCameraTop, light.shadowCameraBottom, light.shadowCameraNear, light.shadowCameraFar );
  14247. } else {
  14248. console.error( "THREE.ShadowMapPlugin: Unsupported light type for shadow", light );
  14249. continue;
  14250. }
  14251. scene.add( light.shadowCamera );
  14252. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14253. }
  14254. if ( light.shadowCameraVisible && ! light.cameraHelper ) {
  14255. light.cameraHelper = new THREE.CameraHelper( light.shadowCamera );
  14256. scene.add( light.cameraHelper );
  14257. }
  14258. if ( light.isVirtual && virtualLight.originalCamera == camera ) {
  14259. updateShadowCamera( camera, light );
  14260. }
  14261. shadowMap = light.shadowMap;
  14262. shadowMatrix = light.shadowMatrix;
  14263. shadowCamera = light.shadowCamera;
  14264. //
  14265. shadowCamera.position.setFromMatrixPosition( light.matrixWorld );
  14266. _matrixPosition.setFromMatrixPosition( light.target.matrixWorld );
  14267. shadowCamera.lookAt( _matrixPosition );
  14268. shadowCamera.updateMatrixWorld();
  14269. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  14270. //
  14271. if ( light.cameraHelper ) light.cameraHelper.visible = light.shadowCameraVisible;
  14272. if ( light.shadowCameraVisible ) light.cameraHelper.update();
  14273. // compute shadow matrix
  14274. shadowMatrix.set(
  14275. 0.5, 0.0, 0.0, 0.5,
  14276. 0.0, 0.5, 0.0, 0.5,
  14277. 0.0, 0.0, 0.5, 0.5,
  14278. 0.0, 0.0, 0.0, 1.0
  14279. );
  14280. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  14281. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  14282. // update camera matrices and frustum
  14283. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  14284. _frustum.setFromMatrix( _projScreenMatrix );
  14285. // render shadow map
  14286. _renderer.setRenderTarget( shadowMap );
  14287. _renderer.clear();
  14288. // set object matrices & frustum culling
  14289. _renderList.length = 0;
  14290. projectObject( scene, shadowCamera );
  14291. // render regular objects
  14292. var objectMaterial, useMorphing, useSkinning;
  14293. for ( j = 0, jl = _renderList.length; j < jl; j ++ ) {
  14294. webglObject = _renderList[ j ];
  14295. object = webglObject.object;
  14296. // culling is overriden globally for all objects
  14297. // while rendering depth map
  14298. // need to deal with MeshFaceMaterial somehow
  14299. // in that case just use the first of material.materials for now
  14300. // (proper solution would require to break objects by materials
  14301. // similarly to regular rendering and then set corresponding
  14302. // depth materials per each chunk instead of just once per object)
  14303. objectMaterial = getObjectMaterial( object );
  14304. useMorphing = object.geometry.morphTargets !== undefined && object.geometry.morphTargets.length > 0 && objectMaterial.morphTargets;
  14305. useSkinning = object instanceof THREE.SkinnedMesh && objectMaterial.skinning;
  14306. if ( object.customDepthMaterial ) {
  14307. material = object.customDepthMaterial;
  14308. } else if ( useSkinning ) {
  14309. material = useMorphing ? _depthMaterialMorphSkin : _depthMaterialSkin;
  14310. } else if ( useMorphing ) {
  14311. material = _depthMaterialMorph;
  14312. } else {
  14313. material = _depthMaterial;
  14314. }
  14315. _renderer.setMaterialFaces( objectMaterial );
  14316. _renderer.renderBufferDirect( shadowCamera, _lights, fog, material, object );
  14317. }
  14318. // set matrices and render immediate objects
  14319. for ( j = 0, jl = _webglObjectsImmediate.length; j < jl; j ++ ) {
  14320. webglObject = _webglObjectsImmediate[ j ];
  14321. object = webglObject.object;
  14322. if ( object.visible && object.castShadow ) {
  14323. object._modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  14324. _renderer.renderImmediateObject( shadowCamera, _lights, fog, _depthMaterial, object );
  14325. }
  14326. }
  14327. }
  14328. // restore GL state
  14329. var clearColor = _renderer.getClearColor(),
  14330. clearAlpha = _renderer.getClearAlpha();
  14331. _gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearAlpha );
  14332. _gl.enable( _gl.BLEND );
  14333. if ( scope.cullFace === THREE.CullFaceFront ) {
  14334. _gl.cullFace( _gl.BACK );
  14335. }
  14336. _renderer.resetGLState();
  14337. };
  14338. function projectObject( object, shadowCamera ) {
  14339. if ( object.visible === true ) {
  14340. var webglObject = _objects.objects[ object.id ];
  14341. if ( webglObject && object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  14342. object._modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  14343. _renderList.push( webglObject );
  14344. }
  14345. for ( var i = 0, l = object.children.length; i < l; i ++ ) {
  14346. projectObject( object.children[ i ], shadowCamera );
  14347. }
  14348. }
  14349. }
  14350. function createVirtualLight( light, cascade ) {
  14351. var virtualLight = new THREE.DirectionalLight();
  14352. virtualLight.isVirtual = true;
  14353. virtualLight.onlyShadow = true;
  14354. virtualLight.castShadow = true;
  14355. virtualLight.shadowCameraNear = light.shadowCameraNear;
  14356. virtualLight.shadowCameraFar = light.shadowCameraFar;
  14357. virtualLight.shadowCameraLeft = light.shadowCameraLeft;
  14358. virtualLight.shadowCameraRight = light.shadowCameraRight;
  14359. virtualLight.shadowCameraBottom = light.shadowCameraBottom;
  14360. virtualLight.shadowCameraTop = light.shadowCameraTop;
  14361. virtualLight.shadowCameraVisible = light.shadowCameraVisible;
  14362. virtualLight.shadowDarkness = light.shadowDarkness;
  14363. virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
  14364. virtualLight.shadowMapWidth = light.shadowCascadeWidth[ cascade ];
  14365. virtualLight.shadowMapHeight = light.shadowCascadeHeight[ cascade ];
  14366. virtualLight.pointsWorld = [];
  14367. virtualLight.pointsFrustum = [];
  14368. var pointsWorld = virtualLight.pointsWorld,
  14369. pointsFrustum = virtualLight.pointsFrustum;
  14370. for ( var i = 0; i < 8; i ++ ) {
  14371. pointsWorld[ i ] = new THREE.Vector3();
  14372. pointsFrustum[ i ] = new THREE.Vector3();
  14373. }
  14374. var nearZ = light.shadowCascadeNearZ[ cascade ];
  14375. var farZ = light.shadowCascadeFarZ[ cascade ];
  14376. pointsFrustum[ 0 ].set( - 1, - 1, nearZ );
  14377. pointsFrustum[ 1 ].set( 1, - 1, nearZ );
  14378. pointsFrustum[ 2 ].set( - 1, 1, nearZ );
  14379. pointsFrustum[ 3 ].set( 1, 1, nearZ );
  14380. pointsFrustum[ 4 ].set( - 1, - 1, farZ );
  14381. pointsFrustum[ 5 ].set( 1, - 1, farZ );
  14382. pointsFrustum[ 6 ].set( - 1, 1, farZ );
  14383. pointsFrustum[ 7 ].set( 1, 1, farZ );
  14384. return virtualLight;
  14385. }
  14386. // Synchronize virtual light with the original light
  14387. function updateVirtualLight( light, cascade ) {
  14388. var virtualLight = light.shadowCascadeArray[ cascade ];
  14389. virtualLight.position.copy( light.position );
  14390. virtualLight.target.position.copy( light.target.position );
  14391. virtualLight.lookAt( virtualLight.target );
  14392. virtualLight.shadowCameraVisible = light.shadowCameraVisible;
  14393. virtualLight.shadowDarkness = light.shadowDarkness;
  14394. virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
  14395. var nearZ = light.shadowCascadeNearZ[ cascade ];
  14396. var farZ = light.shadowCascadeFarZ[ cascade ];
  14397. var pointsFrustum = virtualLight.pointsFrustum;
  14398. pointsFrustum[ 0 ].z = nearZ;
  14399. pointsFrustum[ 1 ].z = nearZ;
  14400. pointsFrustum[ 2 ].z = nearZ;
  14401. pointsFrustum[ 3 ].z = nearZ;
  14402. pointsFrustum[ 4 ].z = farZ;
  14403. pointsFrustum[ 5 ].z = farZ;
  14404. pointsFrustum[ 6 ].z = farZ;
  14405. pointsFrustum[ 7 ].z = farZ;
  14406. }
  14407. // Fit shadow camera's ortho frustum to camera frustum
  14408. function updateShadowCamera( camera, light ) {
  14409. var shadowCamera = light.shadowCamera,
  14410. pointsFrustum = light.pointsFrustum,
  14411. pointsWorld = light.pointsWorld;
  14412. _min.set( Infinity, Infinity, Infinity );
  14413. _max.set( - Infinity, - Infinity, - Infinity );
  14414. for ( var i = 0; i < 8; i ++ ) {
  14415. var p = pointsWorld[ i ];
  14416. p.copy( pointsFrustum[ i ] );
  14417. p.unproject( camera );
  14418. p.applyMatrix4( shadowCamera.matrixWorldInverse );
  14419. if ( p.x < _min.x ) _min.x = p.x;
  14420. if ( p.x > _max.x ) _max.x = p.x;
  14421. if ( p.y < _min.y ) _min.y = p.y;
  14422. if ( p.y > _max.y ) _max.y = p.y;
  14423. if ( p.z < _min.z ) _min.z = p.z;
  14424. if ( p.z > _max.z ) _max.z = p.z;
  14425. }
  14426. shadowCamera.left = _min.x;
  14427. shadowCamera.right = _max.x;
  14428. shadowCamera.top = _max.y;
  14429. shadowCamera.bottom = _min.y;
  14430. // can't really fit near/far
  14431. //shadowCamera.near = _min.z;
  14432. //shadowCamera.far = _max.z;
  14433. shadowCamera.updateProjectionMatrix();
  14434. }
  14435. // For the moment just ignore objects that have multiple materials with different animation methods
  14436. // Only the first material will be taken into account for deciding which depth material to use for shadow maps
  14437. function getObjectMaterial( object ) {
  14438. return object.material instanceof THREE.MeshFaceMaterial
  14439. ? object.material.materials[ 0 ]
  14440. : object.material;
  14441. }
  14442. };
  14443. // File:src/renderers/webgl/WebGLState.js
  14444. /**
  14445. * @author mrdoob / http://mrdoob.com/
  14446. */
  14447. THREE.WebGLState = function ( gl, paramThreeToGL ) {
  14448. var _this = this;
  14449. var newAttributes = new Uint8Array( 16 );
  14450. var enabledAttributes = new Uint8Array( 16 );
  14451. var currentBlending = null;
  14452. var currentBlendEquation = null;
  14453. var currentBlendSrc = null;
  14454. var currentBlendDst = null;
  14455. var currentBlendEquationAlpha = null;
  14456. var currentBlendSrcAlpha = null;
  14457. var currentBlendDstAlpha = null;
  14458. var currentDepthFunc = null;
  14459. var currentDepthTest = null;
  14460. var currentDepthWrite = null;
  14461. var currentColorWrite = null;
  14462. var currentDoubleSided = null;
  14463. var currentFlipSided = null;
  14464. var currentLineWidth = null;
  14465. var currentPolygonOffset = null;
  14466. var currentPolygonOffsetFactor = null;
  14467. var currentPolygonOffsetUnits = null;
  14468. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  14469. var currentTextureSlot = undefined;
  14470. var currentBoundTextures = {};
  14471. this.initAttributes = function () {
  14472. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  14473. newAttributes[ i ] = 0;
  14474. }
  14475. };
  14476. this.enableAttribute = function ( attribute ) {
  14477. newAttributes[ attribute ] = 1;
  14478. if ( enabledAttributes[ attribute ] === 0 ) {
  14479. gl.enableVertexAttribArray( attribute );
  14480. enabledAttributes[ attribute ] = 1;
  14481. }
  14482. };
  14483. this.disableUnusedAttributes = function () {
  14484. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  14485. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  14486. gl.disableVertexAttribArray( i );
  14487. enabledAttributes[ i ] = 0;
  14488. }
  14489. }
  14490. };
  14491. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  14492. if ( blending !== currentBlending ) {
  14493. if ( blending === THREE.NoBlending ) {
  14494. gl.disable( gl.BLEND );
  14495. } else if ( blending === THREE.AdditiveBlending ) {
  14496. gl.enable( gl.BLEND );
  14497. gl.blendEquation( gl.FUNC_ADD );
  14498. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  14499. } else if ( blending === THREE.SubtractiveBlending ) {
  14500. // TODO: Find blendFuncSeparate() combination
  14501. gl.enable( gl.BLEND );
  14502. gl.blendEquation( gl.FUNC_ADD );
  14503. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  14504. } else if ( blending === THREE.MultiplyBlending ) {
  14505. // TODO: Find blendFuncSeparate() combination
  14506. gl.enable( gl.BLEND );
  14507. gl.blendEquation( gl.FUNC_ADD );
  14508. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  14509. } else if ( blending === THREE.CustomBlending ) {
  14510. gl.enable( gl.BLEND );
  14511. } else {
  14512. gl.enable( gl.BLEND );
  14513. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  14514. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  14515. }
  14516. currentBlending = blending;
  14517. }
  14518. if ( blending === THREE.CustomBlending ) {
  14519. blendEquationAlpha = blendEquationAlpha || blendEquation;
  14520. blendSrcAlpha = blendSrcAlpha || blendSrc;
  14521. blendDstAlpha = blendDstAlpha || blendDst;
  14522. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  14523. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  14524. currentBlendEquation = blendEquation;
  14525. currentBlendEquationAlpha = blendEquationAlpha;
  14526. }
  14527. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  14528. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  14529. currentBlendSrc = blendSrc;
  14530. currentBlendDst = blendDst;
  14531. currentBlendSrcAlpha = blendSrcAlpha;
  14532. currentBlendDstAlpha = blendDstAlpha;
  14533. }
  14534. } else {
  14535. currentBlendEquation = null;
  14536. currentBlendSrc = null;
  14537. currentBlendDst = null;
  14538. currentBlendEquationAlpha = null;
  14539. currentBlendSrcAlpha = null;
  14540. currentBlendDstAlpha = null;
  14541. }
  14542. };
  14543. this.setDepthFunc = function ( depthFunc ) {
  14544. if ( currentDepthFunc !== depthFunc ) {
  14545. if ( depthFunc ) {
  14546. switch ( depthFunc ) {
  14547. case THREE.NeverDepth:
  14548. gl.depthFunc( gl.NEVER );
  14549. break;
  14550. case THREE.AlwaysDepth:
  14551. gl.depthFunc( gl.ALWAYS );
  14552. break;
  14553. case THREE.LessDepth:
  14554. gl.depthFunc( gl.LESS );
  14555. break;
  14556. case THREE.LessEqualDepth:
  14557. gl.depthFunc( gl.LEQUAL );
  14558. break;
  14559. case THREE.EqualDepth:
  14560. gl.depthFunc( gl.EQUAL );
  14561. break;
  14562. case THREE.GreaterEqualDepth:
  14563. gl.depthFunc( gl.GEQUAL );
  14564. break;
  14565. case THREE.GreaterDepth:
  14566. gl.depthFunc( gl.GREATER );
  14567. break;
  14568. case THREE.NotEqualDepth:
  14569. gl.depthFunc( gl.NOTEQUAL );
  14570. break;
  14571. default:
  14572. gl.depthFunc( gl.LEQUAL );
  14573. }
  14574. } else {
  14575. gl.depthFunc( gl.LEQUAL );
  14576. }
  14577. currentDepthFunc = depthFunc;
  14578. }
  14579. };
  14580. this.setDepthTest = function ( depthTest ) {
  14581. if ( currentDepthTest !== depthTest ) {
  14582. if ( depthTest ) {
  14583. gl.enable( gl.DEPTH_TEST );
  14584. } else {
  14585. gl.disable( gl.DEPTH_TEST );
  14586. }
  14587. currentDepthTest = depthTest;
  14588. }
  14589. };
  14590. this.setDepthWrite = function ( depthWrite ) {
  14591. if ( currentDepthWrite !== depthWrite ) {
  14592. gl.depthMask( depthWrite );
  14593. currentDepthWrite = depthWrite;
  14594. }
  14595. };
  14596. this.setColorWrite = function ( colorWrite ) {
  14597. if ( currentColorWrite !== colorWrite ) {
  14598. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  14599. currentColorWrite = colorWrite;
  14600. }
  14601. };
  14602. this.setDoubleSided = function ( doubleSided ) {
  14603. if ( currentDoubleSided !== doubleSided ) {
  14604. if ( doubleSided ) {
  14605. gl.disable( gl.CULL_FACE );
  14606. } else {
  14607. gl.enable( gl.CULL_FACE );
  14608. }
  14609. currentDoubleSided = doubleSided;
  14610. }
  14611. };
  14612. this.setFlipSided = function ( flipSided ) {
  14613. if ( currentFlipSided !== flipSided ) {
  14614. if ( flipSided ) {
  14615. gl.frontFace( gl.CW );
  14616. } else {
  14617. gl.frontFace( gl.CCW );
  14618. }
  14619. currentFlipSided = flipSided;
  14620. }
  14621. };
  14622. this.setLineWidth = function ( width ) {
  14623. if ( width !== currentLineWidth ) {
  14624. gl.lineWidth( width );
  14625. currentLineWidth = width;
  14626. }
  14627. };
  14628. this.setPolygonOffset = function ( polygonoffset, factor, units ) {
  14629. if ( currentPolygonOffset !== polygonoffset ) {
  14630. if ( polygonoffset ) {
  14631. gl.enable( gl.POLYGON_OFFSET_FILL );
  14632. } else {
  14633. gl.disable( gl.POLYGON_OFFSET_FILL );
  14634. }
  14635. currentPolygonOffset = polygonoffset;
  14636. }
  14637. if ( polygonoffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  14638. gl.polygonOffset( factor, units );
  14639. currentPolygonOffsetFactor = factor;
  14640. currentPolygonOffsetUnits = units;
  14641. }
  14642. };
  14643. // texture
  14644. this.activeTexture = function ( webglSlot ) {
  14645. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  14646. if ( currentTextureSlot !== webglSlot ) {
  14647. gl.activeTexture( webglSlot );
  14648. currentTextureSlot = webglSlot;
  14649. }
  14650. }
  14651. this.bindTexture = function ( webglType, webglTexture ) {
  14652. if ( currentTextureSlot === undefined ) {
  14653. _this.activeTexture();
  14654. }
  14655. var boundTexture = currentBoundTextures[currentTextureSlot];
  14656. if ( boundTexture === undefined ) {
  14657. boundTexture = { type: undefined, texture: undefined };
  14658. currentBoundTextures[currentTextureSlot] = boundTexture;
  14659. }
  14660. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  14661. gl.bindTexture( webglType, webglTexture );
  14662. boundTexture.type = webglType;
  14663. boundTexture.texture = webglTexture;
  14664. }
  14665. };
  14666. this.compressedTexImage2D = function () {
  14667. try {
  14668. gl.compressedTexImage2D.apply( gl, arguments );
  14669. } catch ( error ) {
  14670. console.error( error );
  14671. }
  14672. };
  14673. this.texImage2D = function () {
  14674. try {
  14675. gl.texImage2D.apply( gl, arguments );
  14676. } catch ( error ) {
  14677. console.error( error );
  14678. }
  14679. };
  14680. //
  14681. this.reset = function () {
  14682. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  14683. enabledAttributes[ i ] = 0;
  14684. }
  14685. currentBlending = null;
  14686. currentDepthTest = null;
  14687. currentDepthWrite = null;
  14688. currentColorWrite = null;
  14689. currentDoubleSided = null;
  14690. currentFlipSided = null;
  14691. };
  14692. };
  14693. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  14694. /**
  14695. * @author mikael emtinger / http://gomo.se/
  14696. * @author alteredq / http://alteredqualia.com/
  14697. */
  14698. THREE.LensFlarePlugin = function ( renderer, flares ) {
  14699. var gl = renderer.context;
  14700. var vertexBuffer, elementBuffer;
  14701. var program, attributes, uniforms;
  14702. var hasVertexTexture;
  14703. var tempTexture, occlusionTexture;
  14704. var init = function () {
  14705. var vertices = new Float32Array( [
  14706. -1, -1, 0, 0,
  14707. 1, -1, 1, 0,
  14708. 1, 1, 1, 1,
  14709. -1, 1, 0, 1
  14710. ] );
  14711. var faces = new Uint16Array( [
  14712. 0, 1, 2,
  14713. 0, 2, 3
  14714. ] );
  14715. // buffers
  14716. vertexBuffer = gl.createBuffer();
  14717. elementBuffer = gl.createBuffer();
  14718. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  14719. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  14720. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  14721. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  14722. // textures
  14723. tempTexture = gl.createTexture();
  14724. occlusionTexture = gl.createTexture();
  14725. renderer.state.bindTexture( gl.TEXTURE_2D, tempTexture );
  14726. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  14727. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  14728. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  14729. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  14730. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  14731. renderer.state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  14732. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  14733. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  14734. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  14735. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  14736. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  14737. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  14738. var shader;
  14739. if ( hasVertexTexture ) {
  14740. shader = {
  14741. vertexShader: [
  14742. "uniform lowp int renderType;",
  14743. "uniform vec3 screenPosition;",
  14744. "uniform vec2 scale;",
  14745. "uniform float rotation;",
  14746. "uniform sampler2D occlusionMap;",
  14747. "attribute vec2 position;",
  14748. "attribute vec2 uv;",
  14749. "varying vec2 vUV;",
  14750. "varying float vVisibility;",
  14751. "void main() {",
  14752. "vUV = uv;",
  14753. "vec2 pos = position;",
  14754. "if( renderType == 2 ) {",
  14755. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  14756. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  14757. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  14758. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  14759. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  14760. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  14761. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  14762. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  14763. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  14764. "vVisibility = visibility.r / 9.0;",
  14765. "vVisibility *= 1.0 - visibility.g / 9.0;",
  14766. "vVisibility *= visibility.b / 9.0;",
  14767. "vVisibility *= 1.0 - visibility.a / 9.0;",
  14768. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  14769. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  14770. "}",
  14771. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  14772. "}"
  14773. ].join( "\n" ),
  14774. fragmentShader: [
  14775. "uniform lowp int renderType;",
  14776. "uniform sampler2D map;",
  14777. "uniform float opacity;",
  14778. "uniform vec3 color;",
  14779. "varying vec2 vUV;",
  14780. "varying float vVisibility;",
  14781. "void main() {",
  14782. // pink square
  14783. "if( renderType == 0 ) {",
  14784. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  14785. // restore
  14786. "} else if( renderType == 1 ) {",
  14787. "gl_FragColor = texture2D( map, vUV );",
  14788. // flare
  14789. "} else {",
  14790. "vec4 texture = texture2D( map, vUV );",
  14791. "texture.a *= opacity * vVisibility;",
  14792. "gl_FragColor = texture;",
  14793. "gl_FragColor.rgb *= color;",
  14794. "}",
  14795. "}"
  14796. ].join( "\n" )
  14797. };
  14798. } else {
  14799. shader = {
  14800. vertexShader: [
  14801. "uniform lowp int renderType;",
  14802. "uniform vec3 screenPosition;",
  14803. "uniform vec2 scale;",
  14804. "uniform float rotation;",
  14805. "attribute vec2 position;",
  14806. "attribute vec2 uv;",
  14807. "varying vec2 vUV;",
  14808. "void main() {",
  14809. "vUV = uv;",
  14810. "vec2 pos = position;",
  14811. "if( renderType == 2 ) {",
  14812. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  14813. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  14814. "}",
  14815. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  14816. "}"
  14817. ].join( "\n" ),
  14818. fragmentShader: [
  14819. "precision mediump float;",
  14820. "uniform lowp int renderType;",
  14821. "uniform sampler2D map;",
  14822. "uniform sampler2D occlusionMap;",
  14823. "uniform float opacity;",
  14824. "uniform vec3 color;",
  14825. "varying vec2 vUV;",
  14826. "void main() {",
  14827. // pink square
  14828. "if( renderType == 0 ) {",
  14829. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  14830. // restore
  14831. "} else if( renderType == 1 ) {",
  14832. "gl_FragColor = texture2D( map, vUV );",
  14833. // flare
  14834. "} else {",
  14835. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  14836. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  14837. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  14838. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  14839. "visibility = ( 1.0 - visibility / 4.0 );",
  14840. "vec4 texture = texture2D( map, vUV );",
  14841. "texture.a *= opacity * visibility;",
  14842. "gl_FragColor = texture;",
  14843. "gl_FragColor.rgb *= color;",
  14844. "}",
  14845. "}"
  14846. ].join( "\n" )
  14847. };
  14848. }
  14849. program = createProgram( shader );
  14850. attributes = {
  14851. vertex: gl.getAttribLocation ( program, "position" ),
  14852. uv: gl.getAttribLocation ( program, "uv" )
  14853. };
  14854. uniforms = {
  14855. renderType: gl.getUniformLocation( program, "renderType" ),
  14856. map: gl.getUniformLocation( program, "map" ),
  14857. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  14858. opacity: gl.getUniformLocation( program, "opacity" ),
  14859. color: gl.getUniformLocation( program, "color" ),
  14860. scale: gl.getUniformLocation( program, "scale" ),
  14861. rotation: gl.getUniformLocation( program, "rotation" ),
  14862. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  14863. };
  14864. };
  14865. /*
  14866. * Render lens flares
  14867. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  14868. * reads these back and calculates occlusion.
  14869. */
  14870. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  14871. if ( flares.length === 0 ) return;
  14872. var tempPosition = new THREE.Vector3();
  14873. var invAspect = viewportHeight / viewportWidth,
  14874. halfViewportWidth = viewportWidth * 0.5,
  14875. halfViewportHeight = viewportHeight * 0.5;
  14876. var size = 16 / viewportHeight,
  14877. scale = new THREE.Vector2( size * invAspect, size );
  14878. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  14879. screenPositionPixels = new THREE.Vector2( 1, 1 );
  14880. if ( program === undefined ) {
  14881. init();
  14882. }
  14883. gl.useProgram( program );
  14884. renderer.state.initAttributes();
  14885. renderer.state.enableAttribute( attributes.vertex );
  14886. renderer.state.enableAttribute( attributes.uv );
  14887. renderer.state.disableUnusedAttributes();
  14888. // loop through all lens flares to update their occlusion and positions
  14889. // setup gl and common used attribs/unforms
  14890. gl.uniform1i( uniforms.occlusionMap, 0 );
  14891. gl.uniform1i( uniforms.map, 1 );
  14892. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  14893. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  14894. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  14895. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  14896. gl.disable( gl.CULL_FACE );
  14897. gl.depthMask( false );
  14898. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  14899. size = 16 / viewportHeight;
  14900. scale.set( size * invAspect, size );
  14901. // calc object screen position
  14902. var flare = flares[ i ];
  14903. tempPosition.set( flare.matrixWorld.elements[12], flare.matrixWorld.elements[13], flare.matrixWorld.elements[14] );
  14904. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  14905. tempPosition.applyProjection( camera.projectionMatrix );
  14906. // setup arrays for gl programs
  14907. screenPosition.copy( tempPosition );
  14908. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  14909. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  14910. // screen cull
  14911. if ( hasVertexTexture || (
  14912. screenPositionPixels.x > 0 &&
  14913. screenPositionPixels.x < viewportWidth &&
  14914. screenPositionPixels.y > 0 &&
  14915. screenPositionPixels.y < viewportHeight ) ) {
  14916. // save current RGB to temp texture
  14917. renderer.state.activeTexture( gl.TEXTURE1 );
  14918. renderer.state.bindTexture( gl.TEXTURE_2D, tempTexture );
  14919. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  14920. // render pink quad
  14921. gl.uniform1i( uniforms.renderType, 0 );
  14922. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  14923. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  14924. gl.disable( gl.BLEND );
  14925. gl.enable( gl.DEPTH_TEST );
  14926. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  14927. // copy result to occlusionMap
  14928. renderer.state.activeTexture( gl.TEXTURE0 );
  14929. renderer.state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  14930. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  14931. // restore graphics
  14932. gl.uniform1i( uniforms.renderType, 1 );
  14933. gl.disable( gl.DEPTH_TEST );
  14934. renderer.state.activeTexture( gl.TEXTURE1 );
  14935. renderer.state.bindTexture( gl.TEXTURE_2D, tempTexture );
  14936. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  14937. // update object positions
  14938. flare.positionScreen.copy( screenPosition );
  14939. if ( flare.customUpdateCallback ) {
  14940. flare.customUpdateCallback( flare );
  14941. } else {
  14942. flare.updateLensFlares();
  14943. }
  14944. // render flares
  14945. gl.uniform1i( uniforms.renderType, 2 );
  14946. gl.enable( gl.BLEND );
  14947. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  14948. var sprite = flare.lensFlares[ j ];
  14949. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  14950. screenPosition.x = sprite.x;
  14951. screenPosition.y = sprite.y;
  14952. screenPosition.z = sprite.z;
  14953. size = sprite.size * sprite.scale / viewportHeight;
  14954. scale.x = size * invAspect;
  14955. scale.y = size;
  14956. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  14957. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  14958. gl.uniform1f( uniforms.rotation, sprite.rotation );
  14959. gl.uniform1f( uniforms.opacity, sprite.opacity );
  14960. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  14961. renderer.state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  14962. renderer.setTexture( sprite.texture, 1 );
  14963. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  14964. }
  14965. }
  14966. }
  14967. }
  14968. // restore gl
  14969. gl.enable( gl.CULL_FACE );
  14970. gl.enable( gl.DEPTH_TEST );
  14971. gl.depthMask( true );
  14972. renderer.resetGLState();
  14973. };
  14974. function createProgram ( shader ) {
  14975. var program = gl.createProgram();
  14976. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  14977. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  14978. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  14979. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  14980. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  14981. gl.compileShader( fragmentShader );
  14982. gl.compileShader( vertexShader );
  14983. gl.attachShader( program, fragmentShader );
  14984. gl.attachShader( program, vertexShader );
  14985. gl.linkProgram( program );
  14986. return program;
  14987. }
  14988. };
  14989. // File:src/renderers/webgl/plugins/SpritePlugin.js
  14990. /**
  14991. * @author mikael emtinger / http://gomo.se/
  14992. * @author alteredq / http://alteredqualia.com/
  14993. */
  14994. THREE.SpritePlugin = function ( renderer, sprites ) {
  14995. var gl = renderer.context;
  14996. var vertexBuffer, elementBuffer;
  14997. var program, attributes, uniforms;
  14998. var texture;
  14999. // decompose matrixWorld
  15000. var spritePosition = new THREE.Vector3();
  15001. var spriteRotation = new THREE.Quaternion();
  15002. var spriteScale = new THREE.Vector3();
  15003. var init = function () {
  15004. var vertices = new Float32Array( [
  15005. - 0.5, - 0.5, 0, 0,
  15006. 0.5, - 0.5, 1, 0,
  15007. 0.5, 0.5, 1, 1,
  15008. - 0.5, 0.5, 0, 1
  15009. ] );
  15010. var faces = new Uint16Array( [
  15011. 0, 1, 2,
  15012. 0, 2, 3
  15013. ] );
  15014. vertexBuffer = gl.createBuffer();
  15015. elementBuffer = gl.createBuffer();
  15016. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15017. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  15018. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15019. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  15020. program = createProgram();
  15021. attributes = {
  15022. position: gl.getAttribLocation ( program, 'position' ),
  15023. uv: gl.getAttribLocation ( program, 'uv' )
  15024. };
  15025. uniforms = {
  15026. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  15027. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  15028. rotation: gl.getUniformLocation( program, 'rotation' ),
  15029. scale: gl.getUniformLocation( program, 'scale' ),
  15030. color: gl.getUniformLocation( program, 'color' ),
  15031. map: gl.getUniformLocation( program, 'map' ),
  15032. opacity: gl.getUniformLocation( program, 'opacity' ),
  15033. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  15034. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  15035. fogType: gl.getUniformLocation( program, 'fogType' ),
  15036. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  15037. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  15038. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  15039. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  15040. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  15041. };
  15042. var canvas = document.createElement( 'canvas' );
  15043. canvas.width = 8;
  15044. canvas.height = 8;
  15045. var context = canvas.getContext( '2d' );
  15046. context.fillStyle = 'white';
  15047. context.fillRect( 0, 0, 8, 8 );
  15048. texture = new THREE.Texture( canvas );
  15049. texture.needsUpdate = true;
  15050. };
  15051. this.render = function ( scene, camera ) {
  15052. if ( sprites.length === 0 ) return;
  15053. // setup gl
  15054. if ( program === undefined ) {
  15055. init();
  15056. }
  15057. gl.useProgram( program );
  15058. renderer.state.initAttributes();
  15059. renderer.state.enableAttribute( attributes.position );
  15060. renderer.state.enableAttribute( attributes.uv );
  15061. renderer.state.disableUnusedAttributes();
  15062. gl.disable( gl.CULL_FACE );
  15063. gl.enable( gl.BLEND );
  15064. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15065. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  15066. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  15067. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15068. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  15069. renderer.state.activeTexture( gl.TEXTURE0 );
  15070. gl.uniform1i( uniforms.map, 0 );
  15071. var oldFogType = 0;
  15072. var sceneFogType = 0;
  15073. var fog = scene.fog;
  15074. if ( fog ) {
  15075. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  15076. if ( fog instanceof THREE.Fog ) {
  15077. gl.uniform1f( uniforms.fogNear, fog.near );
  15078. gl.uniform1f( uniforms.fogFar, fog.far );
  15079. gl.uniform1i( uniforms.fogType, 1 );
  15080. oldFogType = 1;
  15081. sceneFogType = 1;
  15082. } else if ( fog instanceof THREE.FogExp2 ) {
  15083. gl.uniform1f( uniforms.fogDensity, fog.density );
  15084. gl.uniform1i( uniforms.fogType, 2 );
  15085. oldFogType = 2;
  15086. sceneFogType = 2;
  15087. }
  15088. } else {
  15089. gl.uniform1i( uniforms.fogType, 0 );
  15090. oldFogType = 0;
  15091. sceneFogType = 0;
  15092. }
  15093. // update positions and sort
  15094. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  15095. var sprite = sprites[ i ];
  15096. sprite._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  15097. sprite.z = - sprite._modelViewMatrix.elements[ 14 ];
  15098. }
  15099. sprites.sort( painterSortStable );
  15100. // render all sprites
  15101. var scale = [];
  15102. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  15103. var sprite = sprites[ i ];
  15104. var material = sprite.material;
  15105. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  15106. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite._modelViewMatrix.elements );
  15107. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  15108. scale[ 0 ] = spriteScale.x;
  15109. scale[ 1 ] = spriteScale.y;
  15110. var fogType = 0;
  15111. if ( scene.fog && material.fog ) {
  15112. fogType = sceneFogType;
  15113. }
  15114. if ( oldFogType !== fogType ) {
  15115. gl.uniform1i( uniforms.fogType, fogType );
  15116. oldFogType = fogType;
  15117. }
  15118. if ( material.map !== null ) {
  15119. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  15120. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  15121. } else {
  15122. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  15123. gl.uniform2f( uniforms.uvScale, 1, 1 );
  15124. }
  15125. gl.uniform1f( uniforms.opacity, material.opacity );
  15126. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  15127. gl.uniform1f( uniforms.rotation, material.rotation );
  15128. gl.uniform2fv( uniforms.scale, scale );
  15129. renderer.state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  15130. renderer.state.setDepthTest( material.depthTest );
  15131. renderer.state.setDepthWrite( material.depthWrite );
  15132. if ( material.map && material.map.image && material.map.image.width ) {
  15133. renderer.setTexture( material.map, 0 );
  15134. } else {
  15135. renderer.setTexture( texture, 0 );
  15136. }
  15137. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15138. }
  15139. // restore gl
  15140. gl.enable( gl.CULL_FACE );
  15141. renderer.resetGLState();
  15142. };
  15143. function createProgram () {
  15144. var program = gl.createProgram();
  15145. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  15146. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  15147. gl.shaderSource( vertexShader, [
  15148. 'precision ' + renderer.getPrecision() + ' float;',
  15149. 'uniform mat4 modelViewMatrix;',
  15150. 'uniform mat4 projectionMatrix;',
  15151. 'uniform float rotation;',
  15152. 'uniform vec2 scale;',
  15153. 'uniform vec2 uvOffset;',
  15154. 'uniform vec2 uvScale;',
  15155. 'attribute vec2 position;',
  15156. 'attribute vec2 uv;',
  15157. 'varying vec2 vUV;',
  15158. 'void main() {',
  15159. 'vUV = uvOffset + uv * uvScale;',
  15160. 'vec2 alignedPosition = position * scale;',
  15161. 'vec2 rotatedPosition;',
  15162. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  15163. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  15164. 'vec4 finalPosition;',
  15165. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  15166. 'finalPosition.xy += rotatedPosition;',
  15167. 'finalPosition = projectionMatrix * finalPosition;',
  15168. 'gl_Position = finalPosition;',
  15169. '}'
  15170. ].join( '\n' ) );
  15171. gl.shaderSource( fragmentShader, [
  15172. 'precision ' + renderer.getPrecision() + ' float;',
  15173. 'uniform vec3 color;',
  15174. 'uniform sampler2D map;',
  15175. 'uniform float opacity;',
  15176. 'uniform int fogType;',
  15177. 'uniform vec3 fogColor;',
  15178. 'uniform float fogDensity;',
  15179. 'uniform float fogNear;',
  15180. 'uniform float fogFar;',
  15181. 'uniform float alphaTest;',
  15182. 'varying vec2 vUV;',
  15183. 'void main() {',
  15184. 'vec4 texture = texture2D( map, vUV );',
  15185. 'if ( texture.a < alphaTest ) discard;',
  15186. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  15187. 'if ( fogType > 0 ) {',
  15188. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  15189. 'float fogFactor = 0.0;',
  15190. 'if ( fogType == 1 ) {',
  15191. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  15192. '} else {',
  15193. 'const float LOG2 = 1.442695;',
  15194. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  15195. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  15196. '}',
  15197. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  15198. '}',
  15199. '}'
  15200. ].join( '\n' ) );
  15201. gl.compileShader( vertexShader );
  15202. gl.compileShader( fragmentShader );
  15203. gl.attachShader( program, vertexShader );
  15204. gl.attachShader( program, fragmentShader );
  15205. gl.linkProgram( program );
  15206. return program;
  15207. }
  15208. function painterSortStable ( a, b ) {
  15209. if ( a.z !== b.z ) {
  15210. return b.z - a.z;
  15211. } else {
  15212. return b.id - a.id;
  15213. }
  15214. }
  15215. };
  15216. // File:src/extras/GeometryUtils.js
  15217. /**
  15218. * @author mrdoob / http://mrdoob.com/
  15219. */
  15220. THREE.GeometryUtils = {
  15221. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  15222. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  15223. var matrix;
  15224. if ( geometry2 instanceof THREE.Mesh ) {
  15225. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  15226. matrix = geometry2.matrix;
  15227. geometry2 = geometry2.geometry;
  15228. }
  15229. geometry1.merge( geometry2, matrix, materialIndexOffset );
  15230. },
  15231. center: function ( geometry ) {
  15232. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  15233. return geometry.center();
  15234. }
  15235. };
  15236. // File:src/extras/ImageUtils.js
  15237. /**
  15238. * @author alteredq / http://alteredqualia.com/
  15239. * @author mrdoob / http://mrdoob.com/
  15240. * @author Daosheng Mu / https://github.com/DaoshengMu/
  15241. */
  15242. THREE.ImageUtils = {
  15243. crossOrigin: undefined,
  15244. loadTexture: function ( url, mapping, onLoad, onError ) {
  15245. var loader = new THREE.ImageLoader();
  15246. loader.crossOrigin = this.crossOrigin;
  15247. var texture = new THREE.Texture( undefined, mapping );
  15248. loader.load( url, function ( image ) {
  15249. texture.image = image;
  15250. texture.needsUpdate = true;
  15251. if ( onLoad ) onLoad( texture );
  15252. }, undefined, function ( event ) {
  15253. if ( onError ) onError( event );
  15254. } );
  15255. texture.sourceFile = url;
  15256. return texture;
  15257. },
  15258. loadTextureCube: function ( array, mapping, onLoad, onError ) {
  15259. var images = [];
  15260. var loader = new THREE.ImageLoader();
  15261. loader.crossOrigin = this.crossOrigin;
  15262. var texture = new THREE.CubeTexture( images, mapping );
  15263. // no flipping needed for cube textures
  15264. texture.flipY = false;
  15265. var loaded = 0;
  15266. var loadTexture = function ( i ) {
  15267. loader.load( array[ i ], function ( image ) {
  15268. texture.images[ i ] = image;
  15269. loaded += 1;
  15270. if ( loaded === 6 ) {
  15271. texture.needsUpdate = true;
  15272. if ( onLoad ) onLoad( texture );
  15273. }
  15274. }, undefined, onError );
  15275. };
  15276. for ( var i = 0, il = array.length; i < il; ++ i ) {
  15277. loadTexture( i );
  15278. }
  15279. return texture;
  15280. },
  15281. loadCompressedTexture: function () {
  15282. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
  15283. },
  15284. loadCompressedTextureCube: function () {
  15285. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
  15286. },
  15287. getNormalMap: function ( image, depth ) {
  15288. // Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
  15289. var cross = function ( a, b ) {
  15290. 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 ] ];
  15291. };
  15292. var subtract = function ( a, b ) {
  15293. return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ];
  15294. };
  15295. var normalize = function ( a ) {
  15296. var l = Math.sqrt( a[ 0 ] * a[ 0 ] + a[ 1 ] * a[ 1 ] + a[ 2 ] * a[ 2 ] );
  15297. return [ a[ 0 ] / l, a[ 1 ] / l, a[ 2 ] / l ];
  15298. };
  15299. depth = depth | 1;
  15300. var width = image.width;
  15301. var height = image.height;
  15302. var canvas = document.createElement( 'canvas' );
  15303. canvas.width = width;
  15304. canvas.height = height;
  15305. var context = canvas.getContext( '2d' );
  15306. context.drawImage( image, 0, 0 );
  15307. var data = context.getImageData( 0, 0, width, height ).data;
  15308. var imageData = context.createImageData( width, height );
  15309. var output = imageData.data;
  15310. for ( var x = 0; x < width; x ++ ) {
  15311. for ( var y = 0; y < height; y ++ ) {
  15312. var ly = y - 1 < 0 ? 0 : y - 1;
  15313. var uy = y + 1 > height - 1 ? height - 1 : y + 1;
  15314. var lx = x - 1 < 0 ? 0 : x - 1;
  15315. var ux = x + 1 > width - 1 ? width - 1 : x + 1;
  15316. var points = [];
  15317. var origin = [ 0, 0, data[ ( y * width + x ) * 4 ] / 255 * depth ];
  15318. points.push( [ - 1, 0, data[ ( y * width + lx ) * 4 ] / 255 * depth ] );
  15319. points.push( [ - 1, - 1, data[ ( ly * width + lx ) * 4 ] / 255 * depth ] );
  15320. points.push( [ 0, - 1, data[ ( ly * width + x ) * 4 ] / 255 * depth ] );
  15321. points.push( [ 1, - 1, data[ ( ly * width + ux ) * 4 ] / 255 * depth ] );
  15322. points.push( [ 1, 0, data[ ( y * width + ux ) * 4 ] / 255 * depth ] );
  15323. points.push( [ 1, 1, data[ ( uy * width + ux ) * 4 ] / 255 * depth ] );
  15324. points.push( [ 0, 1, data[ ( uy * width + x ) * 4 ] / 255 * depth ] );
  15325. points.push( [ - 1, 1, data[ ( uy * width + lx ) * 4 ] / 255 * depth ] );
  15326. var normals = [];
  15327. var num_points = points.length;
  15328. for ( var i = 0; i < num_points; i ++ ) {
  15329. var v1 = points[ i ];
  15330. var v2 = points[ ( i + 1 ) % num_points ];
  15331. v1 = subtract( v1, origin );
  15332. v2 = subtract( v2, origin );
  15333. normals.push( normalize( cross( v1, v2 ) ) );
  15334. }
  15335. var normal = [ 0, 0, 0 ];
  15336. for ( var i = 0; i < normals.length; i ++ ) {
  15337. normal[ 0 ] += normals[ i ][ 0 ];
  15338. normal[ 1 ] += normals[ i ][ 1 ];
  15339. normal[ 2 ] += normals[ i ][ 2 ];
  15340. }
  15341. normal[ 0 ] /= normals.length;
  15342. normal[ 1 ] /= normals.length;
  15343. normal[ 2 ] /= normals.length;
  15344. var idx = ( y * width + x ) * 4;
  15345. output[ idx ] = ( ( normal[ 0 ] + 1.0 ) / 2.0 * 255 ) | 0;
  15346. output[ idx + 1 ] = ( ( normal[ 1 ] + 1.0 ) / 2.0 * 255 ) | 0;
  15347. output[ idx + 2 ] = ( normal[ 2 ] * 255 ) | 0;
  15348. output[ idx + 3 ] = 255;
  15349. }
  15350. }
  15351. context.putImageData( imageData, 0, 0 );
  15352. return canvas;
  15353. },
  15354. generateDataTexture: function ( width, height, color ) {
  15355. var size = width * height;
  15356. var data = new Uint8Array( 3 * size );
  15357. var r = Math.floor( color.r * 255 );
  15358. var g = Math.floor( color.g * 255 );
  15359. var b = Math.floor( color.b * 255 );
  15360. for ( var i = 0; i < size; i ++ ) {
  15361. data[ i * 3 ] = r;
  15362. data[ i * 3 + 1 ] = g;
  15363. data[ i * 3 + 2 ] = b;
  15364. }
  15365. var texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
  15366. texture.needsUpdate = true;
  15367. return texture;
  15368. }
  15369. };
  15370. // File:src/extras/SceneUtils.js
  15371. /**
  15372. * @author alteredq / http://alteredqualia.com/
  15373. */
  15374. THREE.SceneUtils = {
  15375. createMultiMaterialObject: function ( geometry, materials ) {
  15376. var group = new THREE.Object3D();
  15377. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  15378. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  15379. }
  15380. return group;
  15381. },
  15382. detach: function ( child, parent, scene ) {
  15383. child.applyMatrix( parent.matrixWorld );
  15384. parent.remove( child );
  15385. scene.add( child );
  15386. },
  15387. attach: function ( child, scene, parent ) {
  15388. var matrixWorldInverse = new THREE.Matrix4();
  15389. matrixWorldInverse.getInverse( parent.matrixWorld );
  15390. child.applyMatrix( matrixWorldInverse );
  15391. scene.remove( child );
  15392. parent.add( child );
  15393. }
  15394. };
  15395. // File:src/extras/FontUtils.js
  15396. /**
  15397. * @author zz85 / http://www.lab4games.net/zz85/blog
  15398. * @author alteredq / http://alteredqualia.com/
  15399. *
  15400. * For Text operations in three.js (See TextGeometry)
  15401. *
  15402. * It uses techniques used in:
  15403. *
  15404. * Triangulation ported from AS3
  15405. * Simple Polygon Triangulation
  15406. * http://actionsnippet.com/?p=1462
  15407. *
  15408. * A Method to triangulate shapes with holes
  15409. * http://www.sakri.net/blog/2009/06/12/an-approach-to-triangulating-polygons-with-holes/
  15410. *
  15411. */
  15412. THREE.FontUtils = {
  15413. faces: {},
  15414. // Just for now. face[weight][style]
  15415. face: 'helvetiker',
  15416. weight: 'normal',
  15417. style: 'normal',
  15418. size: 150,
  15419. divisions: 10,
  15420. getFace: function () {
  15421. try {
  15422. return this.faces[ this.face ][ this.weight ][ this.style ];
  15423. } catch (e) {
  15424. throw "The font " + this.face + " with " + this.weight + " weight and " + this.style + " style is missing."
  15425. }
  15426. },
  15427. loadFace: function ( data ) {
  15428. var family = data.familyName.toLowerCase();
  15429. var ThreeFont = this;
  15430. ThreeFont.faces[ family ] = ThreeFont.faces[ family ] || {};
  15431. ThreeFont.faces[ family ][ data.cssFontWeight ] = ThreeFont.faces[ family ][ data.cssFontWeight ] || {};
  15432. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15433. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15434. return data;
  15435. },
  15436. drawText: function ( text ) {
  15437. // RenderText
  15438. var i,
  15439. face = this.getFace(),
  15440. scale = this.size / face.resolution,
  15441. offset = 0,
  15442. chars = String( text ).split( '' ),
  15443. length = chars.length;
  15444. var fontPaths = [];
  15445. for ( i = 0; i < length; i ++ ) {
  15446. var path = new THREE.Path();
  15447. var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
  15448. offset += ret.offset;
  15449. fontPaths.push( ret.path );
  15450. }
  15451. // get the width
  15452. var width = offset / 2;
  15453. //
  15454. // for ( p = 0; p < allPts.length; p++ ) {
  15455. //
  15456. // allPts[ p ].x -= width;
  15457. //
  15458. // }
  15459. //var extract = this.extractPoints( allPts, characterPts );
  15460. //extract.contour = allPts;
  15461. //extract.paths = fontPaths;
  15462. //extract.offset = width;
  15463. return { paths: fontPaths, offset: width };
  15464. },
  15465. extractGlyphPoints: function ( c, face, scale, offset, path ) {
  15466. var pts = [];
  15467. var i, i2, divisions,
  15468. outline, action, length,
  15469. scaleX, scaleY,
  15470. x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2,
  15471. laste,
  15472. glyph = face.glyphs[ c ] || face.glyphs[ '?' ];
  15473. if ( ! glyph ) return;
  15474. if ( glyph.o ) {
  15475. outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  15476. length = outline.length;
  15477. scaleX = scale;
  15478. scaleY = scale;
  15479. for ( i = 0; i < length; ) {
  15480. action = outline[ i ++ ];
  15481. //console.log( action );
  15482. switch ( action ) {
  15483. case 'm':
  15484. // Move To
  15485. x = outline[ i ++ ] * scaleX + offset;
  15486. y = outline[ i ++ ] * scaleY;
  15487. path.moveTo( x, y );
  15488. break;
  15489. case 'l':
  15490. // Line To
  15491. x = outline[ i ++ ] * scaleX + offset;
  15492. y = outline[ i ++ ] * scaleY;
  15493. path.lineTo( x, y );
  15494. break;
  15495. case 'q':
  15496. // QuadraticCurveTo
  15497. cpx = outline[ i ++ ] * scaleX + offset;
  15498. cpy = outline[ i ++ ] * scaleY;
  15499. cpx1 = outline[ i ++ ] * scaleX + offset;
  15500. cpy1 = outline[ i ++ ] * scaleY;
  15501. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  15502. laste = pts[ pts.length - 1 ];
  15503. if ( laste ) {
  15504. cpx0 = laste.x;
  15505. cpy0 = laste.y;
  15506. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  15507. var t = i2 / divisions;
  15508. THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  15509. THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  15510. }
  15511. }
  15512. break;
  15513. case 'b':
  15514. // Cubic Bezier Curve
  15515. cpx = outline[ i ++ ] * scaleX + offset;
  15516. cpy = outline[ i ++ ] * scaleY;
  15517. cpx1 = outline[ i ++ ] * scaleX + offset;
  15518. cpy1 = outline[ i ++ ] * scaleY;
  15519. cpx2 = outline[ i ++ ] * scaleX + offset;
  15520. cpy2 = outline[ i ++ ] * scaleY;
  15521. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  15522. laste = pts[ pts.length - 1 ];
  15523. if ( laste ) {
  15524. cpx0 = laste.x;
  15525. cpy0 = laste.y;
  15526. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  15527. var t = i2 / divisions;
  15528. THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  15529. THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  15530. }
  15531. }
  15532. break;
  15533. }
  15534. }
  15535. }
  15536. return { offset: glyph.ha * scale, path:path };
  15537. }
  15538. };
  15539. THREE.FontUtils.generateShapes = function ( text, parameters ) {
  15540. // Parameters
  15541. parameters = parameters || {};
  15542. var size = parameters.size !== undefined ? parameters.size : 100;
  15543. var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments : 4;
  15544. var font = parameters.font !== undefined ? parameters.font : 'helvetiker';
  15545. var weight = parameters.weight !== undefined ? parameters.weight : 'normal';
  15546. var style = parameters.style !== undefined ? parameters.style : 'normal';
  15547. THREE.FontUtils.size = size;
  15548. THREE.FontUtils.divisions = curveSegments;
  15549. THREE.FontUtils.face = font;
  15550. THREE.FontUtils.weight = weight;
  15551. THREE.FontUtils.style = style;
  15552. // Get a Font data json object
  15553. var data = THREE.FontUtils.drawText( text );
  15554. var paths = data.paths;
  15555. var shapes = [];
  15556. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  15557. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  15558. }
  15559. return shapes;
  15560. };
  15561. /**
  15562. * This code is a quick port of code written in C++ which was submitted to
  15563. * flipcode.com by John W. Ratcliff // July 22, 2000
  15564. * See original code and more information here:
  15565. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  15566. *
  15567. * ported to actionscript by Zevan Rosser
  15568. * www.actionsnippet.com
  15569. *
  15570. * ported to javascript by Joshua Koo
  15571. * http://www.lab4games.net/zz85/blog
  15572. *
  15573. */
  15574. ( function ( namespace ) {
  15575. var EPSILON = 0.0000000001;
  15576. // takes in an contour array and returns
  15577. var process = function ( contour, indices ) {
  15578. var n = contour.length;
  15579. if ( n < 3 ) return null;
  15580. var result = [],
  15581. verts = [],
  15582. vertIndices = [];
  15583. /* we want a counter-clockwise polygon in verts */
  15584. var u, v, w;
  15585. if ( area( contour ) > 0.0 ) {
  15586. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  15587. } else {
  15588. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  15589. }
  15590. var nv = n;
  15591. /* remove nv - 2 vertices, creating 1 triangle every time */
  15592. var count = 2 * nv; /* error detection */
  15593. for ( v = nv - 1; nv > 2; ) {
  15594. /* if we loop, it is probably a non-simple polygon */
  15595. if ( ( count -- ) <= 0 ) {
  15596. //** Triangulate: ERROR - probable bad polygon!
  15597. //throw ( "Warning, unable to triangulate polygon!" );
  15598. //return null;
  15599. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  15600. console.warn( 'THREE.FontUtils: Warning, unable to triangulate polygon! in Triangulate.process()' );
  15601. if ( indices ) return vertIndices;
  15602. return result;
  15603. }
  15604. /* three consecutive vertices in current polygon, <u,v,w> */
  15605. u = v; if ( nv <= u ) u = 0; /* previous */
  15606. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  15607. w = v + 1; if ( nv <= w ) w = 0; /* next */
  15608. if ( snip( contour, u, v, w, nv, verts ) ) {
  15609. var a, b, c, s, t;
  15610. /* true names of the vertices */
  15611. a = verts[ u ];
  15612. b = verts[ v ];
  15613. c = verts[ w ];
  15614. /* output Triangle */
  15615. result.push( [ contour[ a ],
  15616. contour[ b ],
  15617. contour[ c ] ] );
  15618. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  15619. /* remove v from the remaining polygon */
  15620. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  15621. verts[ s ] = verts[ t ];
  15622. }
  15623. nv --;
  15624. /* reset error detection counter */
  15625. count = 2 * nv;
  15626. }
  15627. }
  15628. if ( indices ) return vertIndices;
  15629. return result;
  15630. };
  15631. // calculate area of the contour polygon
  15632. var area = function ( contour ) {
  15633. var n = contour.length;
  15634. var a = 0.0;
  15635. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  15636. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  15637. }
  15638. return a * 0.5;
  15639. };
  15640. var snip = function ( contour, u, v, w, n, verts ) {
  15641. var p;
  15642. var ax, ay, bx, by;
  15643. var cx, cy, px, py;
  15644. ax = contour[ verts[ u ] ].x;
  15645. ay = contour[ verts[ u ] ].y;
  15646. bx = contour[ verts[ v ] ].x;
  15647. by = contour[ verts[ v ] ].y;
  15648. cx = contour[ verts[ w ] ].x;
  15649. cy = contour[ verts[ w ] ].y;
  15650. if ( EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  15651. var aX, aY, bX, bY, cX, cY;
  15652. var apx, apy, bpx, bpy, cpx, cpy;
  15653. var cCROSSap, bCROSScp, aCROSSbp;
  15654. aX = cx - bx; aY = cy - by;
  15655. bX = ax - cx; bY = ay - cy;
  15656. cX = bx - ax; cY = by - ay;
  15657. for ( p = 0; p < n; p ++ ) {
  15658. px = contour[ verts[ p ] ].x;
  15659. py = contour[ verts[ p ] ].y;
  15660. if ( ( ( px === ax ) && ( py === ay ) ) ||
  15661. ( ( px === bx ) && ( py === by ) ) ||
  15662. ( ( px === cx ) && ( py === cy ) ) ) continue;
  15663. apx = px - ax; apy = py - ay;
  15664. bpx = px - bx; bpy = py - by;
  15665. cpx = px - cx; cpy = py - cy;
  15666. // see if p is inside triangle abc
  15667. aCROSSbp = aX * bpy - aY * bpx;
  15668. cCROSSap = cX * apy - cY * apx;
  15669. bCROSScp = bX * cpy - bY * cpx;
  15670. if ( ( aCROSSbp >= - EPSILON ) && ( bCROSScp >= - EPSILON ) && ( cCROSSap >= - EPSILON ) ) return false;
  15671. }
  15672. return true;
  15673. };
  15674. namespace.Triangulate = process;
  15675. namespace.Triangulate.area = area;
  15676. return namespace;
  15677. } )( THREE.FontUtils );
  15678. // To use the typeface.js face files, hook up the API
  15679. THREE.typeface_js = { faces: THREE.FontUtils.faces, loadFace: THREE.FontUtils.loadFace };
  15680. if ( typeof self !== 'undefined' ) self._typeface_js = THREE.typeface_js;
  15681. // File:src/extras/audio/Audio.js
  15682. /**
  15683. * @author mrdoob / http://mrdoob.com/
  15684. */
  15685. THREE.Audio = function ( listener ) {
  15686. THREE.Object3D.call( this );
  15687. this.type = 'Audio';
  15688. this.context = listener.context;
  15689. this.source = this.context.createBufferSource();
  15690. this.source.onended = this.onEnded.bind(this);
  15691. this.gain = this.context.createGain();
  15692. this.gain.connect( this.context.destination );
  15693. this.panner = this.context.createPanner();
  15694. this.panner.connect( this.gain );
  15695. this.autoplay = false;
  15696. this.startTime = 0;
  15697. this.isPlaying = false;
  15698. };
  15699. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  15700. THREE.Audio.prototype.constructor = THREE.Audio;
  15701. THREE.Audio.prototype.load = function ( file ) {
  15702. var scope = this;
  15703. var request = new XMLHttpRequest();
  15704. request.open( 'GET', file, true );
  15705. request.responseType = 'arraybuffer';
  15706. request.onload = function ( e ) {
  15707. scope.context.decodeAudioData( this.response, function ( buffer ) {
  15708. scope.source.buffer = buffer;
  15709. if( scope.autoplay ) scope.play();
  15710. } );
  15711. };
  15712. request.send();
  15713. return this;
  15714. };
  15715. THREE.Audio.prototype.play = function () {
  15716. if ( this.isPlaying === true ) {
  15717. console.warn( 'THREE.Audio: Audio is already playing.' );
  15718. return;
  15719. }
  15720. var source = this.context.createBufferSource();
  15721. source.buffer = this.source.buffer;
  15722. source.loop = this.source.loop;
  15723. source.onended = this.source.onended;
  15724. source.connect( this.panner );
  15725. source.start( 0, this.startTime );
  15726. this.isPlaying = true;
  15727. this.source = source;
  15728. };
  15729. THREE.Audio.prototype.pause = function () {
  15730. this.source.stop();
  15731. this.startTime = this.context.currentTime;
  15732. };
  15733. THREE.Audio.prototype.stop = function () {
  15734. this.source.stop();
  15735. this.startTime = 0;
  15736. };
  15737. THREE.Audio.prototype.onEnded = function() {
  15738. this.isPlaying = false;
  15739. };
  15740. THREE.Audio.prototype.setLoop = function ( value ) {
  15741. this.source.loop = value;
  15742. };
  15743. THREE.Audio.prototype.setRefDistance = function ( value ) {
  15744. this.panner.refDistance = value;
  15745. };
  15746. THREE.Audio.prototype.setRolloffFactor = function ( value ) {
  15747. this.panner.rolloffFactor = value;
  15748. };
  15749. THREE.Audio.prototype.setVolume = function ( value ) {
  15750. this.gain.gain.value = value;
  15751. };
  15752. THREE.Audio.prototype.updateMatrixWorld = ( function () {
  15753. var position = new THREE.Vector3();
  15754. return function ( force ) {
  15755. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  15756. position.setFromMatrixPosition( this.matrixWorld );
  15757. this.panner.setPosition( position.x, position.y, position.z );
  15758. };
  15759. } )();
  15760. // File:src/extras/audio/AudioListener.js
  15761. /**
  15762. * @author mrdoob / http://mrdoob.com/
  15763. */
  15764. THREE.AudioListener = function () {
  15765. THREE.Object3D.call( this );
  15766. this.type = 'AudioListener';
  15767. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  15768. };
  15769. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  15770. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  15771. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  15772. var position = new THREE.Vector3();
  15773. var quaternion = new THREE.Quaternion();
  15774. var scale = new THREE.Vector3();
  15775. var orientation = new THREE.Vector3();
  15776. return function ( force ) {
  15777. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  15778. var listener = this.context.listener;
  15779. var up = this.up;
  15780. this.matrixWorld.decompose( position, quaternion, scale );
  15781. orientation.set( 0, 0, -1 ).applyQuaternion( quaternion );
  15782. listener.setPosition( position.x, position.y, position.z );
  15783. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  15784. };
  15785. } )();
  15786. // File:src/extras/core/Curve.js
  15787. /**
  15788. * @author zz85 / http://www.lab4games.net/zz85/blog
  15789. * Extensible curve object
  15790. *
  15791. * Some common of Curve methods
  15792. * .getPoint(t), getTangent(t)
  15793. * .getPointAt(u), getTagentAt(u)
  15794. * .getPoints(), .getSpacedPoints()
  15795. * .getLength()
  15796. * .updateArcLengths()
  15797. *
  15798. * This following classes subclasses THREE.Curve:
  15799. *
  15800. * -- 2d classes --
  15801. * THREE.LineCurve
  15802. * THREE.QuadraticBezierCurve
  15803. * THREE.CubicBezierCurve
  15804. * THREE.SplineCurve
  15805. * THREE.ArcCurve
  15806. * THREE.EllipseCurve
  15807. *
  15808. * -- 3d classes --
  15809. * THREE.LineCurve3
  15810. * THREE.QuadraticBezierCurve3
  15811. * THREE.CubicBezierCurve3
  15812. * THREE.SplineCurve3
  15813. * THREE.ClosedSplineCurve3
  15814. *
  15815. * A series of curves can be represented as a THREE.CurvePath
  15816. *
  15817. **/
  15818. /**************************************************************
  15819. * Abstract Curve base class
  15820. **************************************************************/
  15821. THREE.Curve = function () {
  15822. };
  15823. // Virtual base class method to overwrite and implement in subclasses
  15824. // - t [0 .. 1]
  15825. THREE.Curve.prototype.getPoint = function ( t ) {
  15826. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  15827. return null;
  15828. };
  15829. // Get point at relative position in curve according to arc length
  15830. // - u [0 .. 1]
  15831. THREE.Curve.prototype.getPointAt = function ( u ) {
  15832. var t = this.getUtoTmapping( u );
  15833. return this.getPoint( t );
  15834. };
  15835. // Get sequence of points using getPoint( t )
  15836. THREE.Curve.prototype.getPoints = function ( divisions ) {
  15837. if ( ! divisions ) divisions = 5;
  15838. var d, pts = [];
  15839. for ( d = 0; d <= divisions; d ++ ) {
  15840. pts.push( this.getPoint( d / divisions ) );
  15841. }
  15842. return pts;
  15843. };
  15844. // Get sequence of points using getPointAt( u )
  15845. THREE.Curve.prototype.getSpacedPoints = function ( divisions ) {
  15846. if ( ! divisions ) divisions = 5;
  15847. var d, pts = [];
  15848. for ( d = 0; d <= divisions; d ++ ) {
  15849. pts.push( this.getPointAt( d / divisions ) );
  15850. }
  15851. return pts;
  15852. };
  15853. // Get total curve arc length
  15854. THREE.Curve.prototype.getLength = function () {
  15855. var lengths = this.getLengths();
  15856. return lengths[ lengths.length - 1 ];
  15857. };
  15858. // Get list of cumulative segment lengths
  15859. THREE.Curve.prototype.getLengths = function ( divisions ) {
  15860. if ( ! divisions ) divisions = (this.__arcLengthDivisions) ? (this.__arcLengthDivisions) : 200;
  15861. if ( this.cacheArcLengths
  15862. && ( this.cacheArcLengths.length === divisions + 1 )
  15863. && ! this.needsUpdate) {
  15864. //console.log( "cached", this.cacheArcLengths );
  15865. return this.cacheArcLengths;
  15866. }
  15867. this.needsUpdate = false;
  15868. var cache = [];
  15869. var current, last = this.getPoint( 0 );
  15870. var p, sum = 0;
  15871. cache.push( 0 );
  15872. for ( p = 1; p <= divisions; p ++ ) {
  15873. current = this.getPoint ( p / divisions );
  15874. sum += current.distanceTo( last );
  15875. cache.push( sum );
  15876. last = current;
  15877. }
  15878. this.cacheArcLengths = cache;
  15879. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  15880. };
  15881. THREE.Curve.prototype.updateArcLengths = function() {
  15882. this.needsUpdate = true;
  15883. this.getLengths();
  15884. };
  15885. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equi distance
  15886. THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
  15887. var arcLengths = this.getLengths();
  15888. var i = 0, il = arcLengths.length;
  15889. var targetArcLength; // The targeted u distance value to get
  15890. if ( distance ) {
  15891. targetArcLength = distance;
  15892. } else {
  15893. targetArcLength = u * arcLengths[ il - 1 ];
  15894. }
  15895. //var time = Date.now();
  15896. // binary search for the index with largest value smaller than target u distance
  15897. var low = 0, high = il - 1, comparison;
  15898. while ( low <= high ) {
  15899. 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
  15900. comparison = arcLengths[ i ] - targetArcLength;
  15901. if ( comparison < 0 ) {
  15902. low = i + 1;
  15903. } else if ( comparison > 0 ) {
  15904. high = i - 1;
  15905. } else {
  15906. high = i;
  15907. break;
  15908. // DONE
  15909. }
  15910. }
  15911. i = high;
  15912. //console.log('b' , i, low, high, Date.now()- time);
  15913. if ( arcLengths[ i ] === targetArcLength ) {
  15914. var t = i / ( il - 1 );
  15915. return t;
  15916. }
  15917. // we could get finer grain at lengths, or use simple interpolatation between two points
  15918. var lengthBefore = arcLengths[ i ];
  15919. var lengthAfter = arcLengths[ i + 1 ];
  15920. var segmentLength = lengthAfter - lengthBefore;
  15921. // determine where we are between the 'before' and 'after' points
  15922. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  15923. // add that fractional amount to t
  15924. var t = ( i + segmentFraction ) / ( il - 1 );
  15925. return t;
  15926. };
  15927. // Returns a unit vector tangent at t
  15928. // In case any sub curve does not implement its tangent derivation,
  15929. // 2 points a small delta apart will be used to find its gradient
  15930. // which seems to give a reasonable approximation
  15931. THREE.Curve.prototype.getTangent = function( t ) {
  15932. var delta = 0.0001;
  15933. var t1 = t - delta;
  15934. var t2 = t + delta;
  15935. // Capping in case of danger
  15936. if ( t1 < 0 ) t1 = 0;
  15937. if ( t2 > 1 ) t2 = 1;
  15938. var pt1 = this.getPoint( t1 );
  15939. var pt2 = this.getPoint( t2 );
  15940. var vec = pt2.clone().sub(pt1);
  15941. return vec.normalize();
  15942. };
  15943. THREE.Curve.prototype.getTangentAt = function ( u ) {
  15944. var t = this.getUtoTmapping( u );
  15945. return this.getTangent( t );
  15946. };
  15947. /**************************************************************
  15948. * Utils
  15949. **************************************************************/
  15950. THREE.Curve.Utils = {
  15951. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  15952. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  15953. },
  15954. // Puay Bing, thanks for helping with this derivative!
  15955. tangentCubicBezier: function (t, p0, p1, p2, p3 ) {
  15956. return - 3 * p0 * (1 - t) * (1 - t) +
  15957. 3 * p1 * (1 - t) * (1 - t) - 6 * t * p1 * (1 - t) +
  15958. 6 * t * p2 * (1 - t) - 3 * t * t * p2 +
  15959. 3 * t * t * p3;
  15960. },
  15961. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  15962. // To check if my formulas are correct
  15963. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  15964. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  15965. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  15966. var h11 = 3 * t * t - 2 * t; // t3 − t2
  15967. return h00 + h10 + h01 + h11;
  15968. },
  15969. // Catmull-Rom
  15970. interpolate: function( p0, p1, p2, p3, t ) {
  15971. var v0 = ( p2 - p0 ) * 0.5;
  15972. var v1 = ( p3 - p1 ) * 0.5;
  15973. var t2 = t * t;
  15974. var t3 = t * t2;
  15975. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  15976. }
  15977. };
  15978. // TODO: Transformation for Curves?
  15979. /**************************************************************
  15980. * 3D Curves
  15981. **************************************************************/
  15982. // A Factory method for creating new curve subclasses
  15983. THREE.Curve.create = function ( constructor, getPointFunc ) {
  15984. constructor.prototype = Object.create( THREE.Curve.prototype );
  15985. constructor.prototype.constructor = constructor;
  15986. constructor.prototype.getPoint = getPointFunc;
  15987. return constructor;
  15988. };
  15989. // File:src/extras/core/CurvePath.js
  15990. /**
  15991. * @author zz85 / http://www.lab4games.net/zz85/blog
  15992. *
  15993. **/
  15994. /**************************************************************
  15995. * Curved Path - a curve path is simply a array of connected
  15996. * curves, but retains the api of a curve
  15997. **************************************************************/
  15998. THREE.CurvePath = function () {
  15999. this.curves = [];
  16000. this.bends = [];
  16001. this.autoClose = false; // Automatically closes the path
  16002. };
  16003. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  16004. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  16005. THREE.CurvePath.prototype.add = function ( curve ) {
  16006. this.curves.push( curve );
  16007. };
  16008. THREE.CurvePath.prototype.checkConnection = function() {
  16009. // TODO
  16010. // If the ending of curve is not connected to the starting
  16011. // or the next curve, then, this is not a real path
  16012. };
  16013. THREE.CurvePath.prototype.closePath = function() {
  16014. // TODO Test
  16015. // and verify for vector3 (needs to implement equals)
  16016. // Add a line curve if start and end of lines are not connected
  16017. var startPoint = this.curves[0].getPoint(0);
  16018. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  16019. if (! startPoint.equals(endPoint)) {
  16020. this.curves.push( new THREE.LineCurve(endPoint, startPoint) );
  16021. }
  16022. };
  16023. // To get accurate point with reference to
  16024. // entire path distance at time t,
  16025. // following has to be done:
  16026. // 1. Length of each sub path have to be known
  16027. // 2. Locate and identify type of curve
  16028. // 3. Get t for the curve
  16029. // 4. Return curve.getPointAt(t')
  16030. THREE.CurvePath.prototype.getPoint = function( t ) {
  16031. var d = t * this.getLength();
  16032. var curveLengths = this.getCurveLengths();
  16033. var i = 0, diff, curve;
  16034. // To think about boundaries points.
  16035. while ( i < curveLengths.length ) {
  16036. if ( curveLengths[ i ] >= d ) {
  16037. diff = curveLengths[ i ] - d;
  16038. curve = this.curves[ i ];
  16039. var u = 1 - diff / curve.getLength();
  16040. return curve.getPointAt( u );
  16041. }
  16042. i ++;
  16043. }
  16044. return null;
  16045. // loop where sum != 0, sum > d , sum+1 <d
  16046. };
  16047. /*
  16048. THREE.CurvePath.prototype.getTangent = function( t ) {
  16049. };*/
  16050. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  16051. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  16052. // getPoint() depends on getLength
  16053. THREE.CurvePath.prototype.getLength = function() {
  16054. var lens = this.getCurveLengths();
  16055. return lens[ lens.length - 1 ];
  16056. };
  16057. // Compute lengths and cache them
  16058. // We cannot overwrite getLengths() because UtoT mapping uses it.
  16059. THREE.CurvePath.prototype.getCurveLengths = function() {
  16060. // We use cache values if curves and cache array are same length
  16061. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  16062. return this.cacheLengths;
  16063. }
  16064. // Get length of subsurve
  16065. // Push sums into cached array
  16066. var lengths = [], sums = 0;
  16067. var i, il = this.curves.length;
  16068. for ( i = 0; i < il; i ++ ) {
  16069. sums += this.curves[ i ].getLength();
  16070. lengths.push( sums );
  16071. }
  16072. this.cacheLengths = lengths;
  16073. return lengths;
  16074. };
  16075. // Returns min and max coordinates
  16076. THREE.CurvePath.prototype.getBoundingBox = function () {
  16077. var points = this.getPoints();
  16078. var maxX, maxY, maxZ;
  16079. var minX, minY, minZ;
  16080. maxX = maxY = Number.NEGATIVE_INFINITY;
  16081. minX = minY = Number.POSITIVE_INFINITY;
  16082. var p, i, il, sum;
  16083. var v3 = points[0] instanceof THREE.Vector3;
  16084. sum = v3 ? new THREE.Vector3() : new THREE.Vector2();
  16085. for ( i = 0, il = points.length; i < il; i ++ ) {
  16086. p = points[ i ];
  16087. if ( p.x > maxX ) maxX = p.x;
  16088. else if ( p.x < minX ) minX = p.x;
  16089. if ( p.y > maxY ) maxY = p.y;
  16090. else if ( p.y < minY ) minY = p.y;
  16091. if ( v3 ) {
  16092. if ( p.z > maxZ ) maxZ = p.z;
  16093. else if ( p.z < minZ ) minZ = p.z;
  16094. }
  16095. sum.add( p );
  16096. }
  16097. var ret = {
  16098. minX: minX,
  16099. minY: minY,
  16100. maxX: maxX,
  16101. maxY: maxY
  16102. };
  16103. if ( v3 ) {
  16104. ret.maxZ = maxZ;
  16105. ret.minZ = minZ;
  16106. }
  16107. return ret;
  16108. };
  16109. /**************************************************************
  16110. * Create Geometries Helpers
  16111. **************************************************************/
  16112. /// Generate geometry from path points (for Line or Points objects)
  16113. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  16114. var pts = this.getPoints( divisions, true );
  16115. return this.createGeometry( pts );
  16116. };
  16117. // Generate geometry from equidistance sampling along the path
  16118. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  16119. var pts = this.getSpacedPoints( divisions, true );
  16120. return this.createGeometry( pts );
  16121. };
  16122. THREE.CurvePath.prototype.createGeometry = function( points ) {
  16123. var geometry = new THREE.Geometry();
  16124. for ( var i = 0; i < points.length; i ++ ) {
  16125. geometry.vertices.push( new THREE.Vector3( points[ i ].x, points[ i ].y, points[ i ].z || 0) );
  16126. }
  16127. return geometry;
  16128. };
  16129. /**************************************************************
  16130. * Bend / Wrap Helper Methods
  16131. **************************************************************/
  16132. // Wrap path / Bend modifiers?
  16133. THREE.CurvePath.prototype.addWrapPath = function ( bendpath ) {
  16134. this.bends.push( bendpath );
  16135. };
  16136. THREE.CurvePath.prototype.getTransformedPoints = function( segments, bends ) {
  16137. var oldPts = this.getPoints( segments ); // getPoints getSpacedPoints
  16138. var i, il;
  16139. if ( ! bends ) {
  16140. bends = this.bends;
  16141. }
  16142. for ( i = 0, il = bends.length; i < il; i ++ ) {
  16143. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  16144. }
  16145. return oldPts;
  16146. };
  16147. THREE.CurvePath.prototype.getTransformedSpacedPoints = function( segments, bends ) {
  16148. var oldPts = this.getSpacedPoints( segments );
  16149. var i, il;
  16150. if ( ! bends ) {
  16151. bends = this.bends;
  16152. }
  16153. for ( i = 0, il = bends.length; i < il; i ++ ) {
  16154. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  16155. }
  16156. return oldPts;
  16157. };
  16158. // This returns getPoints() bend/wrapped around the contour of a path.
  16159. // Read http://www.planetclegg.com/projects/WarpingTextToSplines.html
  16160. THREE.CurvePath.prototype.getWrapPoints = function ( oldPts, path ) {
  16161. var bounds = this.getBoundingBox();
  16162. var i, il, p, oldX, oldY, xNorm;
  16163. for ( i = 0, il = oldPts.length; i < il; i ++ ) {
  16164. p = oldPts[ i ];
  16165. oldX = p.x;
  16166. oldY = p.y;
  16167. xNorm = oldX / bounds.maxX;
  16168. // If using actual distance, for length > path, requires line extrusions
  16169. //xNorm = path.getUtoTmapping(xNorm, oldX); // 3 styles. 1) wrap stretched. 2) wrap stretch by arc length 3) warp by actual distance
  16170. xNorm = path.getUtoTmapping( xNorm, oldX );
  16171. // check for out of bounds?
  16172. var pathPt = path.getPoint( xNorm );
  16173. var normal = path.getTangent( xNorm );
  16174. normal.set( - normal.y, normal.x ).multiplyScalar( oldY );
  16175. p.x = pathPt.x + normal.x;
  16176. p.y = pathPt.y + normal.y;
  16177. }
  16178. return oldPts;
  16179. };
  16180. // File:src/extras/core/Gyroscope.js
  16181. /**
  16182. * @author alteredq / http://alteredqualia.com/
  16183. */
  16184. THREE.Gyroscope = function () {
  16185. THREE.Object3D.call( this );
  16186. };
  16187. THREE.Gyroscope.prototype = Object.create( THREE.Object3D.prototype );
  16188. THREE.Gyroscope.prototype.constructor = THREE.Gyroscope;
  16189. THREE.Gyroscope.prototype.updateMatrixWorld = ( function () {
  16190. var translationObject = new THREE.Vector3();
  16191. var quaternionObject = new THREE.Quaternion();
  16192. var scaleObject = new THREE.Vector3();
  16193. var translationWorld = new THREE.Vector3();
  16194. var quaternionWorld = new THREE.Quaternion();
  16195. var scaleWorld = new THREE.Vector3();
  16196. return function ( force ) {
  16197. this.matrixAutoUpdate && this.updateMatrix();
  16198. // update matrixWorld
  16199. if ( this.matrixWorldNeedsUpdate || force ) {
  16200. if ( this.parent ) {
  16201. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  16202. this.matrixWorld.decompose( translationWorld, quaternionWorld, scaleWorld );
  16203. this.matrix.decompose( translationObject, quaternionObject, scaleObject );
  16204. this.matrixWorld.compose( translationWorld, quaternionObject, scaleWorld );
  16205. } else {
  16206. this.matrixWorld.copy( this.matrix );
  16207. }
  16208. this.matrixWorldNeedsUpdate = false;
  16209. force = true;
  16210. }
  16211. // update children
  16212. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  16213. this.children[ i ].updateMatrixWorld( force );
  16214. }
  16215. };
  16216. }() );
  16217. // File:src/extras/core/Path.js
  16218. /**
  16219. * @author zz85 / http://www.lab4games.net/zz85/blog
  16220. * Creates free form 2d path using series of points, lines or curves.
  16221. *
  16222. **/
  16223. THREE.Path = function ( points ) {
  16224. THREE.CurvePath.call(this);
  16225. this.actions = [];
  16226. if ( points ) {
  16227. this.fromPoints( points );
  16228. }
  16229. };
  16230. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  16231. THREE.Path.prototype.constructor = THREE.Path;
  16232. THREE.PathActions = {
  16233. MOVE_TO: 'moveTo',
  16234. LINE_TO: 'lineTo',
  16235. QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
  16236. BEZIER_CURVE_TO: 'bezierCurveTo', // Bezier cubic curve
  16237. CSPLINE_THRU: 'splineThru', // Catmull-rom spline
  16238. ARC: 'arc', // Circle
  16239. ELLIPSE: 'ellipse'
  16240. };
  16241. // TODO Clean up PATH API
  16242. // Create path using straight lines to connect all points
  16243. // - vectors: array of Vector2
  16244. THREE.Path.prototype.fromPoints = function ( vectors ) {
  16245. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  16246. for ( var v = 1, vlen = vectors.length; v < vlen; v ++ ) {
  16247. this.lineTo( vectors[ v ].x, vectors[ v ].y );
  16248. }
  16249. };
  16250. // startPath() endPath()?
  16251. THREE.Path.prototype.moveTo = function ( x, y ) {
  16252. var args = Array.prototype.slice.call( arguments );
  16253. this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
  16254. };
  16255. THREE.Path.prototype.lineTo = function ( x, y ) {
  16256. var args = Array.prototype.slice.call( arguments );
  16257. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16258. var x0 = lastargs[ lastargs.length - 2 ];
  16259. var y0 = lastargs[ lastargs.length - 1 ];
  16260. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  16261. this.curves.push( curve );
  16262. this.actions.push( { action: THREE.PathActions.LINE_TO, args: args } );
  16263. };
  16264. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  16265. var args = Array.prototype.slice.call( arguments );
  16266. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16267. var x0 = lastargs[ lastargs.length - 2 ];
  16268. var y0 = lastargs[ lastargs.length - 1 ];
  16269. var curve = new THREE.QuadraticBezierCurve( new THREE.Vector2( x0, y0 ),
  16270. new THREE.Vector2( aCPx, aCPy ),
  16271. new THREE.Vector2( aX, aY ) );
  16272. this.curves.push( curve );
  16273. this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args } );
  16274. };
  16275. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y,
  16276. aCP2x, aCP2y,
  16277. aX, aY ) {
  16278. var args = Array.prototype.slice.call( arguments );
  16279. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16280. var x0 = lastargs[ lastargs.length - 2 ];
  16281. var y0 = lastargs[ lastargs.length - 1 ];
  16282. var curve = new THREE.CubicBezierCurve( new THREE.Vector2( x0, y0 ),
  16283. new THREE.Vector2( aCP1x, aCP1y ),
  16284. new THREE.Vector2( aCP2x, aCP2y ),
  16285. new THREE.Vector2( aX, aY ) );
  16286. this.curves.push( curve );
  16287. this.actions.push( { action: THREE.PathActions.BEZIER_CURVE_TO, args: args } );
  16288. };
  16289. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  16290. var args = Array.prototype.slice.call( arguments );
  16291. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16292. var x0 = lastargs[ lastargs.length - 2 ];
  16293. var y0 = lastargs[ lastargs.length - 1 ];
  16294. //---
  16295. var npts = [ new THREE.Vector2( x0, y0 ) ];
  16296. Array.prototype.push.apply( npts, pts );
  16297. var curve = new THREE.SplineCurve( npts );
  16298. this.curves.push( curve );
  16299. this.actions.push( { action: THREE.PathActions.CSPLINE_THRU, args: args } );
  16300. };
  16301. // FUTURE: Change the API or follow canvas API?
  16302. THREE.Path.prototype.arc = function ( aX, aY, aRadius,
  16303. aStartAngle, aEndAngle, aClockwise ) {
  16304. var lastargs = this.actions[ this.actions.length - 1].args;
  16305. var x0 = lastargs[ lastargs.length - 2 ];
  16306. var y0 = lastargs[ lastargs.length - 1 ];
  16307. this.absarc(aX + x0, aY + y0, aRadius,
  16308. aStartAngle, aEndAngle, aClockwise );
  16309. };
  16310. THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
  16311. aStartAngle, aEndAngle, aClockwise ) {
  16312. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  16313. };
  16314. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius,
  16315. aStartAngle, aEndAngle, aClockwise ) {
  16316. var lastargs = this.actions[ this.actions.length - 1].args;
  16317. var x0 = lastargs[ lastargs.length - 2 ];
  16318. var y0 = lastargs[ lastargs.length - 1 ];
  16319. this.absellipse(aX + x0, aY + y0, xRadius, yRadius,
  16320. aStartAngle, aEndAngle, aClockwise );
  16321. };
  16322. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius,
  16323. aStartAngle, aEndAngle, aClockwise ) {
  16324. var args = Array.prototype.slice.call( arguments );
  16325. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius,
  16326. aStartAngle, aEndAngle, aClockwise );
  16327. this.curves.push( curve );
  16328. var lastPoint = curve.getPoint(1);
  16329. args.push(lastPoint.x);
  16330. args.push(lastPoint.y);
  16331. this.actions.push( { action: THREE.PathActions.ELLIPSE, args: args } );
  16332. };
  16333. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  16334. if ( ! divisions ) divisions = 40;
  16335. var points = [];
  16336. for ( var i = 0; i < divisions; i ++ ) {
  16337. points.push( this.getPoint( i / divisions ) );
  16338. //if( !this.getPoint( i / divisions ) ) throw "DIE";
  16339. }
  16340. // if ( closedPath ) {
  16341. //
  16342. // points.push( points[ 0 ] );
  16343. //
  16344. // }
  16345. return points;
  16346. };
  16347. /* Return an array of vectors based on contour of the path */
  16348. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  16349. if (this.useSpacedPoints) {
  16350. console.log('tata');
  16351. return this.getSpacedPoints( divisions, closedPath );
  16352. }
  16353. divisions = divisions || 12;
  16354. var points = [];
  16355. var i, il, item, action, args;
  16356. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  16357. laste, j,
  16358. t, tx, ty;
  16359. for ( i = 0, il = this.actions.length; i < il; i ++ ) {
  16360. item = this.actions[ i ];
  16361. action = item.action;
  16362. args = item.args;
  16363. switch ( action ) {
  16364. case THREE.PathActions.MOVE_TO:
  16365. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  16366. break;
  16367. case THREE.PathActions.LINE_TO:
  16368. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  16369. break;
  16370. case THREE.PathActions.QUADRATIC_CURVE_TO:
  16371. cpx = args[ 2 ];
  16372. cpy = args[ 3 ];
  16373. cpx1 = args[ 0 ];
  16374. cpy1 = args[ 1 ];
  16375. if ( points.length > 0 ) {
  16376. laste = points[ points.length - 1 ];
  16377. cpx0 = laste.x;
  16378. cpy0 = laste.y;
  16379. } else {
  16380. laste = this.actions[ i - 1 ].args;
  16381. cpx0 = laste[ laste.length - 2 ];
  16382. cpy0 = laste[ laste.length - 1 ];
  16383. }
  16384. for ( j = 1; j <= divisions; j ++ ) {
  16385. t = j / divisions;
  16386. tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  16387. ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  16388. points.push( new THREE.Vector2( tx, ty ) );
  16389. }
  16390. break;
  16391. case THREE.PathActions.BEZIER_CURVE_TO:
  16392. cpx = args[ 4 ];
  16393. cpy = args[ 5 ];
  16394. cpx1 = args[ 0 ];
  16395. cpy1 = args[ 1 ];
  16396. cpx2 = args[ 2 ];
  16397. cpy2 = args[ 3 ];
  16398. if ( points.length > 0 ) {
  16399. laste = points[ points.length - 1 ];
  16400. cpx0 = laste.x;
  16401. cpy0 = laste.y;
  16402. } else {
  16403. laste = this.actions[ i - 1 ].args;
  16404. cpx0 = laste[ laste.length - 2 ];
  16405. cpy0 = laste[ laste.length - 1 ];
  16406. }
  16407. for ( j = 1; j <= divisions; j ++ ) {
  16408. t = j / divisions;
  16409. tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  16410. ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  16411. points.push( new THREE.Vector2( tx, ty ) );
  16412. }
  16413. break;
  16414. case THREE.PathActions.CSPLINE_THRU:
  16415. laste = this.actions[ i - 1 ].args;
  16416. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  16417. var spts = [ last ];
  16418. var n = divisions * args[ 0 ].length;
  16419. spts = spts.concat( args[ 0 ] );
  16420. var spline = new THREE.SplineCurve( spts );
  16421. for ( j = 1; j <= n; j ++ ) {
  16422. points.push( spline.getPointAt( j / n ) ) ;
  16423. }
  16424. break;
  16425. case THREE.PathActions.ARC:
  16426. var aX = args[ 0 ], aY = args[ 1 ],
  16427. aRadius = args[ 2 ],
  16428. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  16429. aClockwise = !! args[ 5 ];
  16430. var deltaAngle = aEndAngle - aStartAngle;
  16431. var angle;
  16432. var tdivisions = divisions * 2;
  16433. for ( j = 1; j <= tdivisions; j ++ ) {
  16434. t = j / tdivisions;
  16435. if ( ! aClockwise ) {
  16436. t = 1 - t;
  16437. }
  16438. angle = aStartAngle + t * deltaAngle;
  16439. tx = aX + aRadius * Math.cos( angle );
  16440. ty = aY + aRadius * Math.sin( angle );
  16441. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  16442. points.push( new THREE.Vector2( tx, ty ) );
  16443. }
  16444. //console.log(points);
  16445. break;
  16446. case THREE.PathActions.ELLIPSE:
  16447. var aX = args[ 0 ], aY = args[ 1 ],
  16448. xRadius = args[ 2 ],
  16449. yRadius = args[ 3 ],
  16450. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  16451. aClockwise = !! args[ 6 ];
  16452. var deltaAngle = aEndAngle - aStartAngle;
  16453. var angle;
  16454. var tdivisions = divisions * 2;
  16455. for ( j = 1; j <= tdivisions; j ++ ) {
  16456. t = j / tdivisions;
  16457. if ( ! aClockwise ) {
  16458. t = 1 - t;
  16459. }
  16460. angle = aStartAngle + t * deltaAngle;
  16461. tx = aX + xRadius * Math.cos( angle );
  16462. ty = aY + yRadius * Math.sin( angle );
  16463. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  16464. points.push( new THREE.Vector2( tx, ty ) );
  16465. }
  16466. //console.log(points);
  16467. break;
  16468. } // end switch
  16469. }
  16470. // Normalize to remove the closing point by default.
  16471. var lastPoint = points[ points.length - 1];
  16472. var EPSILON = 0.0000000001;
  16473. if ( Math.abs(lastPoint.x - points[ 0 ].x) < EPSILON &&
  16474. Math.abs(lastPoint.y - points[ 0 ].y) < EPSILON)
  16475. points.splice( points.length - 1, 1);
  16476. if ( closedPath ) {
  16477. points.push( points[ 0 ] );
  16478. }
  16479. return points;
  16480. };
  16481. //
  16482. // Breaks path into shapes
  16483. //
  16484. // Assumptions (if parameter isCCW==true the opposite holds):
  16485. // - solid shapes are defined clockwise (CW)
  16486. // - holes are defined counterclockwise (CCW)
  16487. //
  16488. // If parameter noHoles==true:
  16489. // - all subPaths are regarded as solid shapes
  16490. // - definition order CW/CCW has no relevance
  16491. //
  16492. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  16493. function extractSubpaths( inActions ) {
  16494. var i, il, item, action, args;
  16495. var subPaths = [], lastPath = new THREE.Path();
  16496. for ( i = 0, il = inActions.length; i < il; i ++ ) {
  16497. item = inActions[ i ];
  16498. args = item.args;
  16499. action = item.action;
  16500. if ( action === THREE.PathActions.MOVE_TO ) {
  16501. if ( lastPath.actions.length !== 0 ) {
  16502. subPaths.push( lastPath );
  16503. lastPath = new THREE.Path();
  16504. }
  16505. }
  16506. lastPath[ action ].apply( lastPath, args );
  16507. }
  16508. if ( lastPath.actions.length !== 0 ) {
  16509. subPaths.push( lastPath );
  16510. }
  16511. // console.log(subPaths);
  16512. return subPaths;
  16513. }
  16514. function toShapesNoHoles( inSubpaths ) {
  16515. var shapes = [];
  16516. for ( var i = 0, il = inSubpaths.length; i < il; i ++ ) {
  16517. var tmpPath = inSubpaths[ i ];
  16518. var tmpShape = new THREE.Shape();
  16519. tmpShape.actions = tmpPath.actions;
  16520. tmpShape.curves = tmpPath.curves;
  16521. shapes.push( tmpShape );
  16522. }
  16523. //console.log("shape", shapes);
  16524. return shapes;
  16525. }
  16526. function isPointInsidePolygon( inPt, inPolygon ) {
  16527. var EPSILON = 0.0000000001;
  16528. var polyLen = inPolygon.length;
  16529. // inPt on polygon contour => immediate success or
  16530. // toggling of inside/outside at every single! intersection point of an edge
  16531. // with the horizontal line through inPt, left of inPt
  16532. // not counting lowerY endpoints of edges and whole edges on that line
  16533. var inside = false;
  16534. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  16535. var edgeLowPt = inPolygon[ p ];
  16536. var edgeHighPt = inPolygon[ q ];
  16537. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  16538. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  16539. if ( Math.abs(edgeDy) > EPSILON ) { // not parallel
  16540. if ( edgeDy < 0 ) {
  16541. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  16542. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  16543. }
  16544. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  16545. if ( inPt.y === edgeLowPt.y ) {
  16546. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  16547. // continue; // no intersection or edgeLowPt => doesn't count !!!
  16548. } else {
  16549. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  16550. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  16551. if ( perpEdge < 0 ) continue;
  16552. inside = ! inside; // true intersection left of inPt
  16553. }
  16554. } else { // parallel or colinear
  16555. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  16556. // egde lies on the same horizontal line as inPt
  16557. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  16558. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  16559. // continue;
  16560. }
  16561. }
  16562. return inside;
  16563. }
  16564. var subPaths = extractSubpaths( this.actions );
  16565. if ( subPaths.length === 0 ) return [];
  16566. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  16567. var solid, tmpPath, tmpShape, shapes = [];
  16568. if ( subPaths.length === 1) {
  16569. tmpPath = subPaths[0];
  16570. tmpShape = new THREE.Shape();
  16571. tmpShape.actions = tmpPath.actions;
  16572. tmpShape.curves = tmpPath.curves;
  16573. shapes.push( tmpShape );
  16574. return shapes;
  16575. }
  16576. var holesFirst = ! THREE.Shape.Utils.isClockWise( subPaths[ 0 ].getPoints() );
  16577. holesFirst = isCCW ? ! holesFirst : holesFirst;
  16578. // console.log("Holes first", holesFirst);
  16579. var betterShapeHoles = [];
  16580. var newShapes = [];
  16581. var newShapeHoles = [];
  16582. var mainIdx = 0;
  16583. var tmpPoints;
  16584. newShapes[mainIdx] = undefined;
  16585. newShapeHoles[mainIdx] = [];
  16586. var i, il;
  16587. for ( i = 0, il = subPaths.length; i < il; i ++ ) {
  16588. tmpPath = subPaths[ i ];
  16589. tmpPoints = tmpPath.getPoints();
  16590. solid = THREE.Shape.Utils.isClockWise( tmpPoints );
  16591. solid = isCCW ? ! solid : solid;
  16592. if ( solid ) {
  16593. if ( (! holesFirst ) && ( newShapes[mainIdx] ) ) mainIdx ++;
  16594. newShapes[mainIdx] = { s: new THREE.Shape(), p: tmpPoints };
  16595. newShapes[mainIdx].s.actions = tmpPath.actions;
  16596. newShapes[mainIdx].s.curves = tmpPath.curves;
  16597. if ( holesFirst ) mainIdx ++;
  16598. newShapeHoles[mainIdx] = [];
  16599. //console.log('cw', i);
  16600. } else {
  16601. newShapeHoles[mainIdx].push( { h: tmpPath, p: tmpPoints[0] } );
  16602. //console.log('ccw', i);
  16603. }
  16604. }
  16605. // only Holes? -> probably all Shapes with wrong orientation
  16606. if ( ! newShapes[0] ) return toShapesNoHoles( subPaths );
  16607. if ( newShapes.length > 1 ) {
  16608. var ambigious = false;
  16609. var toChange = [];
  16610. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  16611. betterShapeHoles[sIdx] = [];
  16612. }
  16613. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  16614. var sho = newShapeHoles[sIdx];
  16615. for (var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  16616. var ho = sho[hIdx];
  16617. var hole_unassigned = true;
  16618. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  16619. if ( isPointInsidePolygon( ho.p, newShapes[s2Idx].p ) ) {
  16620. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  16621. if ( hole_unassigned ) {
  16622. hole_unassigned = false;
  16623. betterShapeHoles[s2Idx].push( ho );
  16624. } else {
  16625. ambigious = true;
  16626. }
  16627. }
  16628. }
  16629. if ( hole_unassigned ) { betterShapeHoles[sIdx].push( ho ); }
  16630. }
  16631. }
  16632. // console.log("ambigious: ", ambigious);
  16633. if ( toChange.length > 0 ) {
  16634. // console.log("to change: ", toChange);
  16635. if (! ambigious) newShapeHoles = betterShapeHoles;
  16636. }
  16637. }
  16638. var tmpHoles, j, jl;
  16639. for ( i = 0, il = newShapes.length; i < il; i ++ ) {
  16640. tmpShape = newShapes[i].s;
  16641. shapes.push( tmpShape );
  16642. tmpHoles = newShapeHoles[i];
  16643. for ( j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  16644. tmpShape.holes.push( tmpHoles[j].h );
  16645. }
  16646. }
  16647. //console.log("shape", shapes);
  16648. return shapes;
  16649. };
  16650. // File:src/extras/core/Shape.js
  16651. /**
  16652. * @author zz85 / http://www.lab4games.net/zz85/blog
  16653. * Defines a 2d shape plane using paths.
  16654. **/
  16655. // STEP 1 Create a path.
  16656. // STEP 2 Turn path into shape.
  16657. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  16658. // STEP 3a - Extract points from each shape, turn to vertices
  16659. // STEP 3b - Triangulate each shape, add faces.
  16660. THREE.Shape = function () {
  16661. THREE.Path.apply( this, arguments );
  16662. this.holes = [];
  16663. };
  16664. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  16665. THREE.Shape.prototype.constructor = THREE.Shape;
  16666. // Convenience method to return ExtrudeGeometry
  16667. THREE.Shape.prototype.extrude = function ( options ) {
  16668. var extruded = new THREE.ExtrudeGeometry( this, options );
  16669. return extruded;
  16670. };
  16671. // Convenience method to return ShapeGeometry
  16672. THREE.Shape.prototype.makeGeometry = function ( options ) {
  16673. var geometry = new THREE.ShapeGeometry( this, options );
  16674. return geometry;
  16675. };
  16676. // Get points of holes
  16677. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  16678. var i, il = this.holes.length, holesPts = [];
  16679. for ( i = 0; i < il; i ++ ) {
  16680. holesPts[ i ] = this.holes[ i ].getTransformedPoints( divisions, this.bends );
  16681. }
  16682. return holesPts;
  16683. };
  16684. // Get points of holes (spaced by regular distance)
  16685. THREE.Shape.prototype.getSpacedPointsHoles = function ( divisions ) {
  16686. var i, il = this.holes.length, holesPts = [];
  16687. for ( i = 0; i < il; i ++ ) {
  16688. holesPts[ i ] = this.holes[ i ].getTransformedSpacedPoints( divisions, this.bends );
  16689. }
  16690. return holesPts;
  16691. };
  16692. // Get points of shape and holes (keypoints based on segments parameter)
  16693. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  16694. return {
  16695. shape: this.getTransformedPoints( divisions ),
  16696. holes: this.getPointsHoles( divisions )
  16697. };
  16698. };
  16699. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  16700. if (this.useSpacedPoints) {
  16701. return this.extractAllSpacedPoints(divisions);
  16702. }
  16703. return this.extractAllPoints(divisions);
  16704. };
  16705. //
  16706. // THREE.Shape.prototype.extractAllPointsWithBend = function ( divisions, bend ) {
  16707. //
  16708. // return {
  16709. //
  16710. // shape: this.transform( bend, divisions ),
  16711. // holes: this.getPointsHoles( divisions, bend )
  16712. //
  16713. // };
  16714. //
  16715. // };
  16716. // Get points of shape and holes (spaced by regular distance)
  16717. THREE.Shape.prototype.extractAllSpacedPoints = function ( divisions ) {
  16718. return {
  16719. shape: this.getTransformedSpacedPoints( divisions ),
  16720. holes: this.getSpacedPointsHoles( divisions )
  16721. };
  16722. };
  16723. /**************************************************************
  16724. * Utils
  16725. **************************************************************/
  16726. THREE.Shape.Utils = {
  16727. triangulateShape: function ( contour, holes ) {
  16728. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  16729. // inOtherPt needs to be colinear to the inSegment
  16730. if ( inSegPt1.x !== inSegPt2.x ) {
  16731. if ( inSegPt1.x < inSegPt2.x ) {
  16732. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  16733. } else {
  16734. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  16735. }
  16736. } else {
  16737. if ( inSegPt1.y < inSegPt2.y ) {
  16738. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  16739. } else {
  16740. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  16741. }
  16742. }
  16743. }
  16744. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  16745. var EPSILON = 0.0000000001;
  16746. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  16747. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  16748. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  16749. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  16750. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  16751. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  16752. if ( Math.abs(limit) > EPSILON ) { // not parallel
  16753. var perpSeg2;
  16754. if ( limit > 0 ) {
  16755. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  16756. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  16757. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  16758. } else {
  16759. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  16760. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  16761. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  16762. }
  16763. // i.e. to reduce rounding errors
  16764. // intersection at endpoint of segment#1?
  16765. if ( perpSeg2 === 0 ) {
  16766. if ( ( inExcludeAdjacentSegs ) &&
  16767. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  16768. return [ inSeg1Pt1 ];
  16769. }
  16770. if ( perpSeg2 === limit ) {
  16771. if ( ( inExcludeAdjacentSegs ) &&
  16772. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  16773. return [ inSeg1Pt2 ];
  16774. }
  16775. // intersection at endpoint of segment#2?
  16776. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  16777. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  16778. // return real intersection point
  16779. var factorSeg1 = perpSeg2 / limit;
  16780. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  16781. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  16782. } else { // parallel or colinear
  16783. if ( ( perpSeg1 !== 0 ) ||
  16784. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  16785. // they are collinear or degenerate
  16786. var seg1Pt = ( (seg1dx === 0) && (seg1dy === 0) ); // segment1 ist just a point?
  16787. var seg2Pt = ( (seg2dx === 0) && (seg2dy === 0) ); // segment2 ist just a point?
  16788. // both segments are points
  16789. if ( seg1Pt && seg2Pt ) {
  16790. if ( (inSeg1Pt1.x !== inSeg2Pt1.x) ||
  16791. (inSeg1Pt1.y !== inSeg2Pt1.y) ) return []; // they are distinct points
  16792. return [ inSeg1Pt1 ]; // they are the same point
  16793. }
  16794. // segment#1 is a single point
  16795. if ( seg1Pt ) {
  16796. if (! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  16797. return [ inSeg1Pt1 ];
  16798. }
  16799. // segment#2 is a single point
  16800. if ( seg2Pt ) {
  16801. if (! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  16802. return [ inSeg2Pt1 ];
  16803. }
  16804. // they are collinear segments, which might overlap
  16805. var seg1min, seg1max, seg1minVal, seg1maxVal;
  16806. var seg2min, seg2max, seg2minVal, seg2maxVal;
  16807. if (seg1dx !== 0) { // the segments are NOT on a vertical line
  16808. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  16809. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  16810. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  16811. } else {
  16812. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  16813. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  16814. }
  16815. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  16816. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  16817. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  16818. } else {
  16819. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  16820. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  16821. }
  16822. } else { // the segments are on a vertical line
  16823. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  16824. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  16825. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  16826. } else {
  16827. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  16828. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  16829. }
  16830. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  16831. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  16832. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  16833. } else {
  16834. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  16835. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  16836. }
  16837. }
  16838. if ( seg1minVal <= seg2minVal ) {
  16839. if ( seg1maxVal < seg2minVal ) return [];
  16840. if ( seg1maxVal === seg2minVal ) {
  16841. if ( inExcludeAdjacentSegs ) return [];
  16842. return [ seg2min ];
  16843. }
  16844. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  16845. return [ seg2min, seg2max ];
  16846. } else {
  16847. if ( seg1minVal > seg2maxVal ) return [];
  16848. if ( seg1minVal === seg2maxVal ) {
  16849. if ( inExcludeAdjacentSegs ) return [];
  16850. return [ seg1min ];
  16851. }
  16852. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  16853. return [ seg1min, seg2max ];
  16854. }
  16855. }
  16856. }
  16857. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  16858. // The order of legs is important
  16859. var EPSILON = 0.0000000001;
  16860. // translation of all points, so that Vertex is at (0,0)
  16861. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  16862. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  16863. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  16864. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  16865. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  16866. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  16867. if ( Math.abs(from2toAngle) > EPSILON ) { // angle != 180 deg.
  16868. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  16869. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  16870. if ( from2toAngle > 0 ) { // main angle < 180 deg.
  16871. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  16872. } else { // main angle > 180 deg.
  16873. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  16874. }
  16875. } else { // angle == 180 deg.
  16876. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  16877. return ( from2otherAngle > 0 );
  16878. }
  16879. }
  16880. function removeHoles( contour, holes ) {
  16881. var shape = contour.concat(); // work on this shape
  16882. var hole;
  16883. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  16884. // Check if hole point lies within angle around shape point
  16885. var lastShapeIdx = shape.length - 1;
  16886. var prevShapeIdx = inShapeIdx - 1;
  16887. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  16888. var nextShapeIdx = inShapeIdx + 1;
  16889. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  16890. var insideAngle = isPointInsideAngle( shape[inShapeIdx], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[inHoleIdx] );
  16891. if (! insideAngle ) {
  16892. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  16893. return false;
  16894. }
  16895. // Check if shape point lies within angle around hole point
  16896. var lastHoleIdx = hole.length - 1;
  16897. var prevHoleIdx = inHoleIdx - 1;
  16898. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  16899. var nextHoleIdx = inHoleIdx + 1;
  16900. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  16901. insideAngle = isPointInsideAngle( hole[inHoleIdx], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[inShapeIdx] );
  16902. if (! insideAngle ) {
  16903. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  16904. return false;
  16905. }
  16906. return true;
  16907. }
  16908. function intersectsShapeEdge( inShapePt, inHolePt ) {
  16909. // checks for intersections with shape edges
  16910. var sIdx, nextIdx, intersection;
  16911. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  16912. nextIdx = sIdx + 1; nextIdx %= shape.length;
  16913. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[sIdx], shape[nextIdx], true );
  16914. if ( intersection.length > 0 ) return true;
  16915. }
  16916. return false;
  16917. }
  16918. var indepHoles = [];
  16919. function intersectsHoleEdge( inShapePt, inHolePt ) {
  16920. // checks for intersections with hole edges
  16921. var ihIdx, chkHole,
  16922. hIdx, nextIdx, intersection;
  16923. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  16924. chkHole = holes[indepHoles[ihIdx]];
  16925. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  16926. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  16927. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[hIdx], chkHole[nextIdx], true );
  16928. if ( intersection.length > 0 ) return true;
  16929. }
  16930. }
  16931. return false;
  16932. }
  16933. var holeIndex, shapeIndex,
  16934. shapePt, holePt,
  16935. holeIdx, cutKey, failedCuts = [],
  16936. tmpShape1, tmpShape2,
  16937. tmpHole1, tmpHole2;
  16938. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  16939. indepHoles.push( h );
  16940. }
  16941. var minShapeIndex = 0;
  16942. var counter = indepHoles.length * 2;
  16943. while ( indepHoles.length > 0 ) {
  16944. counter --;
  16945. if ( counter < 0 ) {
  16946. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  16947. break;
  16948. }
  16949. // search for shape-vertex and hole-vertex,
  16950. // which can be connected without intersections
  16951. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  16952. shapePt = shape[ shapeIndex ];
  16953. holeIndex = - 1;
  16954. // search for hole which can be reached without intersections
  16955. for ( var h = 0; h < indepHoles.length; h ++ ) {
  16956. holeIdx = indepHoles[h];
  16957. // prevent multiple checks
  16958. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  16959. if ( failedCuts[cutKey] !== undefined ) continue;
  16960. hole = holes[holeIdx];
  16961. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  16962. holePt = hole[ h2 ];
  16963. if (! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  16964. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  16965. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  16966. holeIndex = h2;
  16967. indepHoles.splice(h, 1);
  16968. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  16969. tmpShape2 = shape.slice( shapeIndex );
  16970. tmpHole1 = hole.slice( holeIndex );
  16971. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  16972. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  16973. minShapeIndex = shapeIndex;
  16974. // Debug only, to show the selected cuts
  16975. // glob_CutLines.push( [ shapePt, holePt ] );
  16976. break;
  16977. }
  16978. if ( holeIndex >= 0 ) break; // hole-vertex found
  16979. failedCuts[cutKey] = true; // remember failure
  16980. }
  16981. if ( holeIndex >= 0 ) break; // hole-vertex found
  16982. }
  16983. }
  16984. return shape; /* shape with no holes */
  16985. }
  16986. var i, il, f, face,
  16987. key, index,
  16988. allPointsMap = {};
  16989. // 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.
  16990. var allpoints = contour.concat();
  16991. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  16992. Array.prototype.push.apply( allpoints, holes[h] );
  16993. }
  16994. //console.log( "allpoints",allpoints, allpoints.length );
  16995. // prepare all points map
  16996. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  16997. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  16998. if ( allPointsMap[ key ] !== undefined ) {
  16999. console.warn( "THREE.Shape: Duplicate point", key );
  17000. }
  17001. allPointsMap[ key ] = i;
  17002. }
  17003. // remove holes by cutting paths to holes and adding them to the shape
  17004. var shapeWithoutHoles = removeHoles( contour, holes );
  17005. var triangles = THREE.FontUtils.Triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  17006. //console.log( "triangles",triangles, triangles.length );
  17007. // check all face vertices against all points map
  17008. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  17009. face = triangles[ i ];
  17010. for ( f = 0; f < 3; f ++ ) {
  17011. key = face[ f ].x + ":" + face[ f ].y;
  17012. index = allPointsMap[ key ];
  17013. if ( index !== undefined ) {
  17014. face[ f ] = index;
  17015. }
  17016. }
  17017. }
  17018. return triangles.concat();
  17019. },
  17020. isClockWise: function ( pts ) {
  17021. return THREE.FontUtils.Triangulate.area( pts ) < 0;
  17022. },
  17023. // Bezier Curves formulas obtained from
  17024. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  17025. // Quad Bezier Functions
  17026. b2p0: function ( t, p ) {
  17027. var k = 1 - t;
  17028. return k * k * p;
  17029. },
  17030. b2p1: function ( t, p ) {
  17031. return 2 * ( 1 - t ) * t * p;
  17032. },
  17033. b2p2: function ( t, p ) {
  17034. return t * t * p;
  17035. },
  17036. b2: function ( t, p0, p1, p2 ) {
  17037. return this.b2p0( t, p0 ) + this.b2p1( t, p1 ) + this.b2p2( t, p2 );
  17038. },
  17039. // Cubic Bezier Functions
  17040. b3p0: function ( t, p ) {
  17041. var k = 1 - t;
  17042. return k * k * k * p;
  17043. },
  17044. b3p1: function ( t, p ) {
  17045. var k = 1 - t;
  17046. return 3 * k * k * t * p;
  17047. },
  17048. b3p2: function ( t, p ) {
  17049. var k = 1 - t;
  17050. return 3 * k * t * t * p;
  17051. },
  17052. b3p3: function ( t, p ) {
  17053. return t * t * t * p;
  17054. },
  17055. b3: function ( t, p0, p1, p2, p3 ) {
  17056. return this.b3p0( t, p0 ) + this.b3p1( t, p1 ) + this.b3p2( t, p2 ) + this.b3p3( t, p3 );
  17057. }
  17058. };
  17059. // File:src/extras/curves/LineCurve.js
  17060. /**************************************************************
  17061. * Line
  17062. **************************************************************/
  17063. THREE.LineCurve = function ( v1, v2 ) {
  17064. this.v1 = v1;
  17065. this.v2 = v2;
  17066. };
  17067. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  17068. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  17069. THREE.LineCurve.prototype.getPoint = function ( t ) {
  17070. var point = this.v2.clone().sub(this.v1);
  17071. point.multiplyScalar( t ).add( this.v1 );
  17072. return point;
  17073. };
  17074. // Line curve is linear, so we can overwrite default getPointAt
  17075. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  17076. return this.getPoint( u );
  17077. };
  17078. THREE.LineCurve.prototype.getTangent = function( t ) {
  17079. var tangent = this.v2.clone().sub(this.v1);
  17080. return tangent.normalize();
  17081. };
  17082. // File:src/extras/curves/QuadraticBezierCurve.js
  17083. /**************************************************************
  17084. * Quadratic Bezier curve
  17085. **************************************************************/
  17086. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  17087. this.v0 = v0;
  17088. this.v1 = v1;
  17089. this.v2 = v2;
  17090. };
  17091. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  17092. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  17093. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  17094. var vector = new THREE.Vector2();
  17095. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  17096. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  17097. return vector;
  17098. };
  17099. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  17100. var vector = new THREE.Vector2();
  17101. vector.x = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
  17102. vector.y = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
  17103. // returns unit vector
  17104. return vector.normalize();
  17105. };
  17106. // File:src/extras/curves/CubicBezierCurve.js
  17107. /**************************************************************
  17108. * Cubic Bezier curve
  17109. **************************************************************/
  17110. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  17111. this.v0 = v0;
  17112. this.v1 = v1;
  17113. this.v2 = v2;
  17114. this.v3 = v3;
  17115. };
  17116. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  17117. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  17118. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  17119. var tx, ty;
  17120. tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17121. ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17122. return new THREE.Vector2( tx, ty );
  17123. };
  17124. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  17125. var tx, ty;
  17126. tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17127. ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17128. var tangent = new THREE.Vector2( tx, ty );
  17129. tangent.normalize();
  17130. return tangent;
  17131. };
  17132. // File:src/extras/curves/SplineCurve.js
  17133. /**************************************************************
  17134. * Spline curve
  17135. **************************************************************/
  17136. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  17137. this.points = ( points == undefined ) ? [] : points;
  17138. };
  17139. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  17140. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  17141. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  17142. var points = this.points;
  17143. var point = ( points.length - 1 ) * t;
  17144. var intPoint = Math.floor( point );
  17145. var weight = point - intPoint;
  17146. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  17147. var point1 = points[ intPoint ];
  17148. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  17149. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  17150. var vector = new THREE.Vector2();
  17151. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17152. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17153. return vector;
  17154. };
  17155. // File:src/extras/curves/EllipseCurve.js
  17156. /**************************************************************
  17157. * Ellipse curve
  17158. **************************************************************/
  17159. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise ) {
  17160. this.aX = aX;
  17161. this.aY = aY;
  17162. this.xRadius = xRadius;
  17163. this.yRadius = yRadius;
  17164. this.aStartAngle = aStartAngle;
  17165. this.aEndAngle = aEndAngle;
  17166. this.aClockwise = aClockwise;
  17167. };
  17168. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  17169. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  17170. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  17171. var deltaAngle = this.aEndAngle - this.aStartAngle;
  17172. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  17173. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  17174. var angle;
  17175. if ( this.aClockwise === true ) {
  17176. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  17177. } else {
  17178. angle = this.aStartAngle + t * deltaAngle;
  17179. }
  17180. var vector = new THREE.Vector2();
  17181. vector.x = this.aX + this.xRadius * Math.cos( angle );
  17182. vector.y = this.aY + this.yRadius * Math.sin( angle );
  17183. return vector;
  17184. };
  17185. // File:src/extras/curves/ArcCurve.js
  17186. /**************************************************************
  17187. * Arc curve
  17188. **************************************************************/
  17189. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  17190. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  17191. };
  17192. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  17193. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  17194. // File:src/extras/curves/LineCurve3.js
  17195. /**************************************************************
  17196. * Line3D
  17197. **************************************************************/
  17198. THREE.LineCurve3 = THREE.Curve.create(
  17199. function ( v1, v2 ) {
  17200. this.v1 = v1;
  17201. this.v2 = v2;
  17202. },
  17203. function ( t ) {
  17204. var vector = new THREE.Vector3();
  17205. vector.subVectors( this.v2, this.v1 ); // diff
  17206. vector.multiplyScalar( t );
  17207. vector.add( this.v1 );
  17208. return vector;
  17209. }
  17210. );
  17211. // File:src/extras/curves/QuadraticBezierCurve3.js
  17212. /**************************************************************
  17213. * Quadratic Bezier 3D curve
  17214. **************************************************************/
  17215. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  17216. function ( v0, v1, v2 ) {
  17217. this.v0 = v0;
  17218. this.v1 = v1;
  17219. this.v2 = v2;
  17220. },
  17221. function ( t ) {
  17222. var vector = new THREE.Vector3();
  17223. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  17224. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  17225. vector.z = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
  17226. return vector;
  17227. }
  17228. );
  17229. // File:src/extras/curves/CubicBezierCurve3.js
  17230. /**************************************************************
  17231. * Cubic Bezier 3D curve
  17232. **************************************************************/
  17233. THREE.CubicBezierCurve3 = THREE.Curve.create(
  17234. function ( v0, v1, v2, v3 ) {
  17235. this.v0 = v0;
  17236. this.v1 = v1;
  17237. this.v2 = v2;
  17238. this.v3 = v3;
  17239. },
  17240. function ( t ) {
  17241. var vector = new THREE.Vector3();
  17242. vector.x = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17243. vector.y = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17244. vector.z = THREE.Shape.Utils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );
  17245. return vector;
  17246. }
  17247. );
  17248. // File:src/extras/curves/SplineCurve3.js
  17249. /**************************************************************
  17250. * Spline 3D curve
  17251. **************************************************************/
  17252. THREE.SplineCurve3 = THREE.Curve.create(
  17253. function ( points /* array of Vector3 */) {
  17254. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  17255. this.points = ( points == undefined ) ? [] : points;
  17256. },
  17257. function ( t ) {
  17258. var points = this.points;
  17259. var point = ( points.length - 1 ) * t;
  17260. var intPoint = Math.floor( point );
  17261. var weight = point - intPoint;
  17262. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  17263. var point1 = points[ intPoint ];
  17264. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  17265. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  17266. var vector = new THREE.Vector3();
  17267. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17268. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17269. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  17270. return vector;
  17271. }
  17272. );
  17273. // File:src/extras/curves/CatmullRomCurve3.js
  17274. /**
  17275. * @author zz85 https://github.com/zz85
  17276. *
  17277. * Centripetal CatmullRom Curve - which is useful for avoiding
  17278. * cusps and self-intersections in non-uniform catmull rom curves.
  17279. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  17280. *
  17281. * curve.type accepts centripetal(default), chordal and catmullrom
  17282. * curve.tension is used for catmullrom which defaults to 0.5
  17283. */
  17284. THREE.CatmullRomCurve3 = ( function() {
  17285. var
  17286. tmp = new THREE.Vector3(),
  17287. px = new CubicPoly(),
  17288. py = new CubicPoly(),
  17289. pz = new CubicPoly();
  17290. /*
  17291. Based on an optimized c++ solution in
  17292. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  17293. - http://ideone.com/NoEbVM
  17294. This CubicPoly class could be used for reusing some variables and calculations,
  17295. but for three.js curve use, it could be possible inlined and flatten into a single function call
  17296. which can be placed in CurveUtils.
  17297. */
  17298. function CubicPoly() {
  17299. }
  17300. /*
  17301. * Compute coefficients for a cubic polynomial
  17302. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  17303. * such that
  17304. * p(0) = x0, p(1) = x1
  17305. * and
  17306. * p'(0) = t0, p'(1) = t1.
  17307. */
  17308. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  17309. this.c0 = x0;
  17310. this.c1 = t0;
  17311. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  17312. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  17313. };
  17314. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  17315. // compute tangents when parameterized in [t1,t2]
  17316. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  17317. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  17318. // rescale tangents for parametrization in [0,1]
  17319. t1 *= dt1;
  17320. t2 *= dt1;
  17321. // initCubicPoly
  17322. this.init( x1, x2, t1, t2 );
  17323. };
  17324. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  17325. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  17326. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  17327. };
  17328. CubicPoly.prototype.calc = function( t ) {
  17329. var t2 = t * t;
  17330. var t3 = t2 * t;
  17331. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  17332. };
  17333. // Subclass Three.js curve
  17334. return THREE.Curve.create(
  17335. function ( p /* array of Vector3 */ ) {
  17336. this.points = p || [];
  17337. },
  17338. function ( t ) {
  17339. var points = this.points,
  17340. point, intPoint, weight, l;
  17341. l = points.length;
  17342. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  17343. point = ( l - 1 ) * t;
  17344. intPoint = Math.floor( point );
  17345. weight = point - intPoint;
  17346. if ( weight === 0 && intPoint === l - 1 ) {
  17347. intPoint = l - 2;
  17348. weight = 1;
  17349. }
  17350. var p0, p1, p2, p3;
  17351. if ( intPoint === 0 ) {
  17352. // extrapolate first point
  17353. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  17354. p0 = tmp;
  17355. } else {
  17356. p0 = points[ intPoint - 1 ];
  17357. }
  17358. p1 = points[ intPoint ];
  17359. p2 = points[ intPoint + 1 ];
  17360. if ( intPoint + 2 < l ) {
  17361. p3 = points[ intPoint + 2 ]
  17362. } else {
  17363. // extrapolate last point
  17364. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 2 ] );
  17365. p3 = tmp;
  17366. }
  17367. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  17368. // init Centripetal / Chordal Catmull-Rom
  17369. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  17370. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  17371. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  17372. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  17373. // safety check for repeated points
  17374. if ( dt1 < 1e-4 ) dt1 = 1.0;
  17375. if ( dt0 < 1e-4 ) dt0 = dt1;
  17376. if ( dt2 < 1e-4 ) dt2 = dt1;
  17377. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  17378. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  17379. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  17380. } else if ( this.type === 'catmullrom' ) {
  17381. var tension = this.tension !== undefined ? this.tension : 0.5;
  17382. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  17383. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  17384. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  17385. }
  17386. var v = new THREE.Vector3(
  17387. px.calc( weight ),
  17388. py.calc( weight ),
  17389. pz.calc( weight )
  17390. );
  17391. return v;
  17392. }
  17393. );
  17394. } )();
  17395. // File:src/extras/curves/ClosedSplineCurve3.js
  17396. /**************************************************************
  17397. * Closed Spline 3D curve
  17398. **************************************************************/
  17399. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  17400. function ( points /* array of Vector3 */) {
  17401. this.points = ( points == undefined ) ? [] : points;
  17402. },
  17403. function ( t ) {
  17404. var points = this.points;
  17405. var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
  17406. var intPoint = Math.floor( point );
  17407. var weight = point - intPoint;
  17408. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  17409. var point0 = points[ ( intPoint - 1 ) % points.length ];
  17410. var point1 = points[ ( intPoint ) % points.length ];
  17411. var point2 = points[ ( intPoint + 1 ) % points.length ];
  17412. var point3 = points[ ( intPoint + 2 ) % points.length ];
  17413. var vector = new THREE.Vector3();
  17414. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17415. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17416. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  17417. return vector;
  17418. }
  17419. );
  17420. // File:src/extras/animation/AnimationHandler.js
  17421. /**
  17422. * @author mikael emtinger / http://gomo.se/
  17423. */
  17424. THREE.AnimationHandler = {
  17425. LINEAR: 0,
  17426. CATMULLROM: 1,
  17427. CATMULLROM_FORWARD: 2,
  17428. //
  17429. add: function () { console.warn( 'THREE.AnimationHandler.add() has been deprecated.' ); },
  17430. get: function () { console.warn( 'THREE.AnimationHandler.get() has been deprecated.' ); },
  17431. remove: function () { console.warn( 'THREE.AnimationHandler.remove() has been deprecated.' ); },
  17432. //
  17433. animations: [],
  17434. init: function ( data ) {
  17435. if ( data.initialized === true ) return data;
  17436. // loop through all keys
  17437. for ( var h = 0; h < data.hierarchy.length; h ++ ) {
  17438. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17439. // remove minus times
  17440. if ( data.hierarchy[ h ].keys[ k ].time < 0 ) {
  17441. data.hierarchy[ h ].keys[ k ].time = 0;
  17442. }
  17443. // create quaternions
  17444. if ( data.hierarchy[ h ].keys[ k ].rot !== undefined &&
  17445. ! ( data.hierarchy[ h ].keys[ k ].rot instanceof THREE.Quaternion ) ) {
  17446. var quat = data.hierarchy[ h ].keys[ k ].rot;
  17447. data.hierarchy[ h ].keys[ k ].rot = new THREE.Quaternion().fromArray( quat );
  17448. }
  17449. }
  17450. // prepare morph target keys
  17451. if ( data.hierarchy[ h ].keys.length && data.hierarchy[ h ].keys[ 0 ].morphTargets !== undefined ) {
  17452. // get all used
  17453. var usedMorphTargets = {};
  17454. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17455. for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  17456. var morphTargetName = data.hierarchy[ h ].keys[ k ].morphTargets[ m ];
  17457. usedMorphTargets[ morphTargetName ] = - 1;
  17458. }
  17459. }
  17460. data.hierarchy[ h ].usedMorphTargets = usedMorphTargets;
  17461. // set all used on all frames
  17462. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17463. var influences = {};
  17464. for ( var morphTargetName in usedMorphTargets ) {
  17465. for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  17466. if ( data.hierarchy[ h ].keys[ k ].morphTargets[ m ] === morphTargetName ) {
  17467. influences[ morphTargetName ] = data.hierarchy[ h ].keys[ k ].morphTargetsInfluences[ m ];
  17468. break;
  17469. }
  17470. }
  17471. if ( m === data.hierarchy[ h ].keys[ k ].morphTargets.length ) {
  17472. influences[ morphTargetName ] = 0;
  17473. }
  17474. }
  17475. data.hierarchy[ h ].keys[ k ].morphTargetsInfluences = influences;
  17476. }
  17477. }
  17478. // remove all keys that are on the same time
  17479. for ( var k = 1; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17480. if ( data.hierarchy[ h ].keys[ k ].time === data.hierarchy[ h ].keys[ k - 1 ].time ) {
  17481. data.hierarchy[ h ].keys.splice( k, 1 );
  17482. k --;
  17483. }
  17484. }
  17485. // set index
  17486. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17487. data.hierarchy[ h ].keys[ k ].index = k;
  17488. }
  17489. }
  17490. data.initialized = true;
  17491. return data;
  17492. },
  17493. parse: function ( root ) {
  17494. var parseRecurseHierarchy = function ( root, hierarchy ) {
  17495. hierarchy.push( root );
  17496. for ( var c = 0; c < root.children.length; c ++ )
  17497. parseRecurseHierarchy( root.children[ c ], hierarchy );
  17498. };
  17499. // setup hierarchy
  17500. var hierarchy = [];
  17501. if ( root instanceof THREE.SkinnedMesh ) {
  17502. for ( var b = 0; b < root.skeleton.bones.length; b ++ ) {
  17503. hierarchy.push( root.skeleton.bones[ b ] );
  17504. }
  17505. } else {
  17506. parseRecurseHierarchy( root, hierarchy );
  17507. }
  17508. return hierarchy;
  17509. },
  17510. play: function ( animation ) {
  17511. if ( this.animations.indexOf( animation ) === - 1 ) {
  17512. this.animations.push( animation );
  17513. }
  17514. },
  17515. stop: function ( animation ) {
  17516. var index = this.animations.indexOf( animation );
  17517. if ( index !== - 1 ) {
  17518. this.animations.splice( index, 1 );
  17519. }
  17520. },
  17521. update: function ( deltaTimeMS ) {
  17522. for ( var i = 0; i < this.animations.length; i ++ ) {
  17523. this.animations[ i ].resetBlendWeights( );
  17524. }
  17525. for ( var i = 0; i < this.animations.length; i ++ ) {
  17526. this.animations[ i ].update( deltaTimeMS );
  17527. }
  17528. }
  17529. };
  17530. // File:src/extras/animation/Animation.js
  17531. /**
  17532. * @author mikael emtinger / http://gomo.se/
  17533. * @author mrdoob / http://mrdoob.com/
  17534. * @author alteredq / http://alteredqualia.com/
  17535. */
  17536. THREE.Animation = function ( root, data ) {
  17537. this.root = root;
  17538. this.data = THREE.AnimationHandler.init( data );
  17539. this.hierarchy = THREE.AnimationHandler.parse( root );
  17540. this.currentTime = 0;
  17541. this.timeScale = 1;
  17542. this.isPlaying = false;
  17543. this.loop = true;
  17544. this.weight = 0;
  17545. this.interpolationType = THREE.AnimationHandler.LINEAR;
  17546. };
  17547. THREE.Animation.prototype = {
  17548. constructor: THREE.Animation,
  17549. keyTypes: [ "pos", "rot", "scl" ],
  17550. play: function ( startTime, weight ) {
  17551. this.currentTime = startTime !== undefined ? startTime : 0;
  17552. this.weight = weight !== undefined ? weight : 1;
  17553. this.isPlaying = true;
  17554. this.reset();
  17555. THREE.AnimationHandler.play( this );
  17556. },
  17557. stop: function() {
  17558. this.isPlaying = false;
  17559. THREE.AnimationHandler.stop( this );
  17560. },
  17561. reset: function () {
  17562. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  17563. var object = this.hierarchy[ h ];
  17564. if ( object.animationCache === undefined ) {
  17565. object.animationCache = {
  17566. animations: {},
  17567. blending: {
  17568. positionWeight: 0.0,
  17569. quaternionWeight: 0.0,
  17570. scaleWeight: 0.0
  17571. }
  17572. };
  17573. }
  17574. var name = this.data.name;
  17575. var animations = object.animationCache.animations;
  17576. var animationCache = animations[ name ];
  17577. if ( animationCache === undefined ) {
  17578. animationCache = {
  17579. prevKey: { pos: 0, rot: 0, scl: 0 },
  17580. nextKey: { pos: 0, rot: 0, scl: 0 },
  17581. originalMatrix: object.matrix
  17582. };
  17583. animations[ name ] = animationCache;
  17584. }
  17585. // Get keys to match our current time
  17586. for ( var t = 0; t < 3; t ++ ) {
  17587. var type = this.keyTypes[ t ];
  17588. var prevKey = this.data.hierarchy[ h ].keys[ 0 ];
  17589. var nextKey = this.getNextKeyWith( type, h, 1 );
  17590. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  17591. prevKey = nextKey;
  17592. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  17593. }
  17594. animationCache.prevKey[ type ] = prevKey;
  17595. animationCache.nextKey[ type ] = nextKey;
  17596. }
  17597. }
  17598. },
  17599. resetBlendWeights: function () {
  17600. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  17601. var object = this.hierarchy[ h ];
  17602. var animationCache = object.animationCache;
  17603. if ( animationCache !== undefined ) {
  17604. var blending = animationCache.blending;
  17605. blending.positionWeight = 0.0;
  17606. blending.quaternionWeight = 0.0;
  17607. blending.scaleWeight = 0.0;
  17608. }
  17609. }
  17610. },
  17611. update: ( function() {
  17612. var points = [];
  17613. var target = new THREE.Vector3();
  17614. var newVector = new THREE.Vector3();
  17615. var newQuat = new THREE.Quaternion();
  17616. // Catmull-Rom spline
  17617. var interpolateCatmullRom = function ( points, scale ) {
  17618. var c = [], v3 = [],
  17619. point, intPoint, weight, w2, w3,
  17620. pa, pb, pc, pd;
  17621. point = ( points.length - 1 ) * scale;
  17622. intPoint = Math.floor( point );
  17623. weight = point - intPoint;
  17624. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  17625. c[ 1 ] = intPoint;
  17626. c[ 2 ] = intPoint > points.length - 2 ? intPoint : intPoint + 1;
  17627. c[ 3 ] = intPoint > points.length - 3 ? intPoint : intPoint + 2;
  17628. pa = points[ c[ 0 ] ];
  17629. pb = points[ c[ 1 ] ];
  17630. pc = points[ c[ 2 ] ];
  17631. pd = points[ c[ 3 ] ];
  17632. w2 = weight * weight;
  17633. w3 = weight * w2;
  17634. v3[ 0 ] = interpolate( pa[ 0 ], pb[ 0 ], pc[ 0 ], pd[ 0 ], weight, w2, w3 );
  17635. v3[ 1 ] = interpolate( pa[ 1 ], pb[ 1 ], pc[ 1 ], pd[ 1 ], weight, w2, w3 );
  17636. v3[ 2 ] = interpolate( pa[ 2 ], pb[ 2 ], pc[ 2 ], pd[ 2 ], weight, w2, w3 );
  17637. return v3;
  17638. };
  17639. var interpolate = function ( p0, p1, p2, p3, t, t2, t3 ) {
  17640. var v0 = ( p2 - p0 ) * 0.5,
  17641. v1 = ( p3 - p1 ) * 0.5;
  17642. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  17643. };
  17644. return function ( delta ) {
  17645. if ( this.isPlaying === false ) return;
  17646. this.currentTime += delta * this.timeScale;
  17647. if ( this.weight === 0 )
  17648. return;
  17649. //
  17650. var duration = this.data.length;
  17651. if ( this.currentTime > duration || this.currentTime < 0 ) {
  17652. if ( this.loop ) {
  17653. this.currentTime %= duration;
  17654. if ( this.currentTime < 0 )
  17655. this.currentTime += duration;
  17656. this.reset();
  17657. } else {
  17658. this.stop();
  17659. }
  17660. }
  17661. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  17662. var object = this.hierarchy[ h ];
  17663. var animationCache = object.animationCache.animations[this.data.name];
  17664. var blending = object.animationCache.blending;
  17665. // loop through pos/rot/scl
  17666. for ( var t = 0; t < 3; t ++ ) {
  17667. // get keys
  17668. var type = this.keyTypes[ t ];
  17669. var prevKey = animationCache.prevKey[ type ];
  17670. var nextKey = animationCache.nextKey[ type ];
  17671. if ( ( this.timeScale > 0 && nextKey.time <= this.currentTime ) ||
  17672. ( this.timeScale < 0 && prevKey.time >= this.currentTime ) ) {
  17673. prevKey = this.data.hierarchy[ h ].keys[ 0 ];
  17674. nextKey = this.getNextKeyWith( type, h, 1 );
  17675. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  17676. prevKey = nextKey;
  17677. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  17678. }
  17679. animationCache.prevKey[ type ] = prevKey;
  17680. animationCache.nextKey[ type ] = nextKey;
  17681. }
  17682. var scale = ( this.currentTime - prevKey.time ) / ( nextKey.time - prevKey.time );
  17683. var prevXYZ = prevKey[ type ];
  17684. var nextXYZ = nextKey[ type ];
  17685. if ( scale < 0 ) scale = 0;
  17686. if ( scale > 1 ) scale = 1;
  17687. // interpolate
  17688. if ( type === "pos" ) {
  17689. if ( this.interpolationType === THREE.AnimationHandler.LINEAR ) {
  17690. newVector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  17691. newVector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  17692. newVector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  17693. // blend
  17694. var proportionalWeight = this.weight / ( this.weight + blending.positionWeight );
  17695. object.position.lerp( newVector, proportionalWeight );
  17696. blending.positionWeight += this.weight;
  17697. } else if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  17698. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  17699. points[ 0 ] = this.getPrevKeyWith( "pos", h, prevKey.index - 1 )[ "pos" ];
  17700. points[ 1 ] = prevXYZ;
  17701. points[ 2 ] = nextXYZ;
  17702. points[ 3 ] = this.getNextKeyWith( "pos", h, nextKey.index + 1 )[ "pos" ];
  17703. scale = scale * 0.33 + 0.33;
  17704. var currentPoint = interpolateCatmullRom( points, scale );
  17705. var proportionalWeight = this.weight / ( this.weight + blending.positionWeight );
  17706. blending.positionWeight += this.weight;
  17707. // blend
  17708. var vector = object.position;
  17709. vector.x = vector.x + ( currentPoint[ 0 ] - vector.x ) * proportionalWeight;
  17710. vector.y = vector.y + ( currentPoint[ 1 ] - vector.y ) * proportionalWeight;
  17711. vector.z = vector.z + ( currentPoint[ 2 ] - vector.z ) * proportionalWeight;
  17712. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  17713. var forwardPoint = interpolateCatmullRom( points, scale * 1.01 );
  17714. target.set( forwardPoint[ 0 ], forwardPoint[ 1 ], forwardPoint[ 2 ] );
  17715. target.sub( vector );
  17716. target.y = 0;
  17717. target.normalize();
  17718. var angle = Math.atan2( target.x, target.z );
  17719. object.rotation.set( 0, angle, 0 );
  17720. }
  17721. }
  17722. } else if ( type === "rot" ) {
  17723. THREE.Quaternion.slerp( prevXYZ, nextXYZ, newQuat, scale );
  17724. // Avoid paying the cost of an additional slerp if we don't have to
  17725. if ( blending.quaternionWeight === 0 ) {
  17726. object.quaternion.copy(newQuat);
  17727. blending.quaternionWeight = this.weight;
  17728. } else {
  17729. var proportionalWeight = this.weight / ( this.weight + blending.quaternionWeight );
  17730. THREE.Quaternion.slerp( object.quaternion, newQuat, object.quaternion, proportionalWeight );
  17731. blending.quaternionWeight += this.weight;
  17732. }
  17733. } else if ( type === "scl" ) {
  17734. newVector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  17735. newVector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  17736. newVector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  17737. var proportionalWeight = this.weight / ( this.weight + blending.scaleWeight );
  17738. object.scale.lerp( newVector, proportionalWeight );
  17739. blending.scaleWeight += this.weight;
  17740. }
  17741. }
  17742. }
  17743. return true;
  17744. };
  17745. } )(),
  17746. getNextKeyWith: function ( type, h, key ) {
  17747. var keys = this.data.hierarchy[ h ].keys;
  17748. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  17749. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  17750. key = key < keys.length - 1 ? key : keys.length - 1;
  17751. } else {
  17752. key = key % keys.length;
  17753. }
  17754. for ( ; key < keys.length; key ++ ) {
  17755. if ( keys[ key ][ type ] !== undefined ) {
  17756. return keys[ key ];
  17757. }
  17758. }
  17759. return this.data.hierarchy[ h ].keys[ 0 ];
  17760. },
  17761. getPrevKeyWith: function ( type, h, key ) {
  17762. var keys = this.data.hierarchy[ h ].keys;
  17763. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  17764. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  17765. key = key > 0 ? key : 0;
  17766. } else {
  17767. key = key >= 0 ? key : key + keys.length;
  17768. }
  17769. for ( ; key >= 0; key -- ) {
  17770. if ( keys[ key ][ type ] !== undefined ) {
  17771. return keys[ key ];
  17772. }
  17773. }
  17774. return this.data.hierarchy[ h ].keys[ keys.length - 1 ];
  17775. }
  17776. };
  17777. // File:src/extras/animation/KeyFrameAnimation.js
  17778. /**
  17779. * @author mikael emtinger / http://gomo.se/
  17780. * @author mrdoob / http://mrdoob.com/
  17781. * @author alteredq / http://alteredqualia.com/
  17782. * @author khang duong
  17783. * @author erik kitson
  17784. */
  17785. THREE.KeyFrameAnimation = function ( data ) {
  17786. this.root = data.node;
  17787. this.data = THREE.AnimationHandler.init( data );
  17788. this.hierarchy = THREE.AnimationHandler.parse( this.root );
  17789. this.currentTime = 0;
  17790. this.timeScale = 0.001;
  17791. this.isPlaying = false;
  17792. this.isPaused = true;
  17793. this.loop = true;
  17794. // initialize to first keyframes
  17795. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  17796. var keys = this.data.hierarchy[h].keys,
  17797. sids = this.data.hierarchy[h].sids,
  17798. obj = this.hierarchy[h];
  17799. if ( keys.length && sids ) {
  17800. for ( var s = 0; s < sids.length; s ++ ) {
  17801. var sid = sids[ s ],
  17802. next = this.getNextKeyWith( sid, h, 0 );
  17803. if ( next ) {
  17804. next.apply( sid );
  17805. }
  17806. }
  17807. obj.matrixAutoUpdate = false;
  17808. this.data.hierarchy[h].node.updateMatrix();
  17809. obj.matrixWorldNeedsUpdate = true;
  17810. }
  17811. }
  17812. };
  17813. THREE.KeyFrameAnimation.prototype = {
  17814. constructor: THREE.KeyFrameAnimation,
  17815. play: function ( startTime ) {
  17816. this.currentTime = startTime !== undefined ? startTime : 0;
  17817. if ( this.isPlaying === false ) {
  17818. this.isPlaying = true;
  17819. // reset key cache
  17820. var h, hl = this.hierarchy.length,
  17821. object,
  17822. node;
  17823. for ( h = 0; h < hl; h ++ ) {
  17824. object = this.hierarchy[ h ];
  17825. node = this.data.hierarchy[ h ];
  17826. if ( node.animationCache === undefined ) {
  17827. node.animationCache = {};
  17828. node.animationCache.prevKey = null;
  17829. node.animationCache.nextKey = null;
  17830. node.animationCache.originalMatrix = object.matrix;
  17831. }
  17832. var keys = this.data.hierarchy[h].keys;
  17833. if (keys.length) {
  17834. node.animationCache.prevKey = keys[ 0 ];
  17835. node.animationCache.nextKey = keys[ 1 ];
  17836. this.startTime = Math.min( keys[0].time, this.startTime );
  17837. this.endTime = Math.max( keys[keys.length - 1].time, this.endTime );
  17838. }
  17839. }
  17840. this.update( 0 );
  17841. }
  17842. this.isPaused = false;
  17843. THREE.AnimationHandler.play( this );
  17844. },
  17845. stop: function () {
  17846. this.isPlaying = false;
  17847. this.isPaused = false;
  17848. THREE.AnimationHandler.stop( this );
  17849. // reset JIT matrix and remove cache
  17850. for ( var h = 0; h < this.data.hierarchy.length; h ++ ) {
  17851. var obj = this.hierarchy[ h ];
  17852. var node = this.data.hierarchy[ h ];
  17853. if ( node.animationCache !== undefined ) {
  17854. var original = node.animationCache.originalMatrix;
  17855. original.copy( obj.matrix );
  17856. obj.matrix = original;
  17857. delete node.animationCache;
  17858. }
  17859. }
  17860. },
  17861. update: function ( delta ) {
  17862. if ( this.isPlaying === false ) return;
  17863. this.currentTime += delta * this.timeScale;
  17864. //
  17865. var duration = this.data.length;
  17866. if ( this.loop === true && this.currentTime > duration ) {
  17867. this.currentTime %= duration;
  17868. }
  17869. this.currentTime = Math.min( this.currentTime, duration );
  17870. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  17871. var object = this.hierarchy[ h ];
  17872. var node = this.data.hierarchy[ h ];
  17873. var keys = node.keys,
  17874. animationCache = node.animationCache;
  17875. if ( keys.length ) {
  17876. var prevKey = animationCache.prevKey;
  17877. var nextKey = animationCache.nextKey;
  17878. if ( nextKey.time <= this.currentTime ) {
  17879. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  17880. prevKey = nextKey;
  17881. nextKey = keys[ prevKey.index + 1 ];
  17882. }
  17883. animationCache.prevKey = prevKey;
  17884. animationCache.nextKey = nextKey;
  17885. }
  17886. if ( nextKey.time >= this.currentTime ) {
  17887. prevKey.interpolate( nextKey, this.currentTime );
  17888. } else {
  17889. prevKey.interpolate( nextKey, nextKey.time );
  17890. }
  17891. this.data.hierarchy[ h ].node.updateMatrix();
  17892. object.matrixWorldNeedsUpdate = true;
  17893. }
  17894. }
  17895. },
  17896. getNextKeyWith: function ( sid, h, key ) {
  17897. var keys = this.data.hierarchy[ h ].keys;
  17898. key = key % keys.length;
  17899. for ( ; key < keys.length; key ++ ) {
  17900. if ( keys[ key ].hasTarget( sid ) ) {
  17901. return keys[ key ];
  17902. }
  17903. }
  17904. return keys[ 0 ];
  17905. },
  17906. getPrevKeyWith: function ( sid, h, key ) {
  17907. var keys = this.data.hierarchy[ h ].keys;
  17908. key = key >= 0 ? key : key + keys.length;
  17909. for ( ; key >= 0; key -- ) {
  17910. if ( keys[ key ].hasTarget( sid ) ) {
  17911. return keys[ key ];
  17912. }
  17913. }
  17914. return keys[ keys.length - 1 ];
  17915. }
  17916. };
  17917. // File:src/extras/animation/MorphAnimation.js
  17918. /**
  17919. * @author mrdoob / http://mrdoob.com
  17920. * @author willy-vvu / http://willy-vvu.github.io
  17921. */
  17922. THREE.MorphAnimation = function ( mesh ) {
  17923. this.mesh = mesh;
  17924. this.frames = mesh.morphTargetInfluences.length;
  17925. this.currentTime = 0;
  17926. this.duration = 1000;
  17927. this.loop = true;
  17928. this.lastFrame = 0;
  17929. this.currentFrame = 0;
  17930. this.isPlaying = false;
  17931. };
  17932. THREE.MorphAnimation.prototype = {
  17933. constructor: THREE.MorphAnimation,
  17934. play: function () {
  17935. this.isPlaying = true;
  17936. },
  17937. pause: function () {
  17938. this.isPlaying = false;
  17939. },
  17940. update: function ( delta ) {
  17941. if ( this.isPlaying === false ) return;
  17942. this.currentTime += delta;
  17943. if ( this.loop === true && this.currentTime > this.duration ) {
  17944. this.currentTime %= this.duration;
  17945. }
  17946. this.currentTime = Math.min( this.currentTime, this.duration );
  17947. var interpolation = this.duration / this.frames;
  17948. var frame = Math.floor( this.currentTime / interpolation );
  17949. var influences = this.mesh.morphTargetInfluences;
  17950. if ( frame !== this.currentFrame ) {
  17951. influences[ this.lastFrame ] = 0;
  17952. influences[ this.currentFrame ] = 1;
  17953. influences[ frame ] = 0;
  17954. this.lastFrame = this.currentFrame;
  17955. this.currentFrame = frame;
  17956. }
  17957. influences[ frame ] = ( this.currentTime % interpolation ) / interpolation;
  17958. influences[ this.lastFrame ] = 1 - influences[ frame ];
  17959. }
  17960. };
  17961. // File:src/extras/geometries/BoxGeometry.js
  17962. /**
  17963. * @author mrdoob / http://mrdoob.com/
  17964. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  17965. */
  17966. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  17967. THREE.Geometry.call( this );
  17968. this.type = 'BoxGeometry';
  17969. this.parameters = {
  17970. width: width,
  17971. height: height,
  17972. depth: depth,
  17973. widthSegments: widthSegments,
  17974. heightSegments: heightSegments,
  17975. depthSegments: depthSegments
  17976. };
  17977. this.widthSegments = widthSegments || 1;
  17978. this.heightSegments = heightSegments || 1;
  17979. this.depthSegments = depthSegments || 1;
  17980. var scope = this;
  17981. var width_half = width / 2;
  17982. var height_half = height / 2;
  17983. var depth_half = depth / 2;
  17984. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half ); // px
  17985. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half ); // nx
  17986. buildPlane( 'x', 'z', 1, 1, width, depth, height_half ); // py
  17987. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half ); // ny
  17988. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half ); // pz
  17989. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half ); // nz
  17990. function buildPlane( u, v, udir, vdir, width, height, depth ) {
  17991. var w, ix, iy,
  17992. gridX = scope.widthSegments,
  17993. gridY = scope.heightSegments,
  17994. width_half = width / 2,
  17995. height_half = height / 2,
  17996. offset = scope.vertices.length;
  17997. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  17998. w = 'z';
  17999. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  18000. w = 'y';
  18001. gridY = scope.depthSegments;
  18002. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  18003. w = 'x';
  18004. gridX = scope.depthSegments;
  18005. }
  18006. var gridX1 = gridX + 1,
  18007. gridY1 = gridY + 1,
  18008. segment_width = width / gridX,
  18009. segment_height = height / gridY,
  18010. normal = new THREE.Vector3();
  18011. normal[ w ] = depth > 0 ? 1 : - 1;
  18012. for ( iy = 0; iy < gridY1; iy ++ ) {
  18013. for ( ix = 0; ix < gridX1; ix ++ ) {
  18014. var vector = new THREE.Vector3();
  18015. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  18016. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  18017. vector[ w ] = depth;
  18018. scope.vertices.push( vector );
  18019. }
  18020. }
  18021. for ( iy = 0; iy < gridY; iy ++ ) {
  18022. for ( ix = 0; ix < gridX; ix ++ ) {
  18023. var a = ix + gridX1 * iy;
  18024. var b = ix + gridX1 * ( iy + 1 );
  18025. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  18026. var d = ( ix + 1 ) + gridX1 * iy;
  18027. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  18028. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  18029. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  18030. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  18031. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  18032. face.normal.copy( normal );
  18033. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18034. scope.faces.push( face );
  18035. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  18036. face = new THREE.Face3( b + offset, c + offset, d + offset );
  18037. face.normal.copy( normal );
  18038. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18039. scope.faces.push( face );
  18040. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  18041. }
  18042. }
  18043. }
  18044. this.mergeVertices();
  18045. };
  18046. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18047. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  18048. THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
  18049. // File:src/extras/geometries/CircleGeometry.js
  18050. /**
  18051. * @author hughes
  18052. */
  18053. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18054. THREE.Geometry.call( this );
  18055. this.type = 'CircleGeometry';
  18056. this.parameters = {
  18057. radius: radius,
  18058. segments: segments,
  18059. thetaStart: thetaStart,
  18060. thetaLength: thetaLength
  18061. };
  18062. radius = radius || 50;
  18063. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18064. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18065. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18066. var i, uvs = [],
  18067. center = new THREE.Vector3(), centerUV = new THREE.Vector2( 0.5, 0.5 );
  18068. this.vertices.push(center);
  18069. uvs.push( centerUV );
  18070. for ( i = 0; i <= segments; i ++ ) {
  18071. var vertex = new THREE.Vector3();
  18072. var segment = thetaStart + i / segments * thetaLength;
  18073. vertex.x = radius * Math.cos( segment );
  18074. vertex.y = radius * Math.sin( segment );
  18075. this.vertices.push( vertex );
  18076. uvs.push( new THREE.Vector2( ( vertex.x / radius + 1 ) / 2, ( vertex.y / radius + 1 ) / 2 ) );
  18077. }
  18078. var n = new THREE.Vector3( 0, 0, 1 );
  18079. for ( i = 1; i <= segments; i ++ ) {
  18080. this.faces.push( new THREE.Face3( i, i + 1, 0, [ n.clone(), n.clone(), n.clone() ] ) );
  18081. this.faceVertexUvs[ 0 ].push( [ uvs[ i ].clone(), uvs[ i + 1 ].clone(), centerUV.clone() ] );
  18082. }
  18083. this.computeFaceNormals();
  18084. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18085. };
  18086. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18087. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  18088. // File:src/extras/geometries/CircleBufferGeometry.js
  18089. /**
  18090. * @author benaadams / https://twitter.com/ben_a_adams
  18091. */
  18092. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18093. THREE.BufferGeometry.call( this );
  18094. this.type = 'CircleBufferGeometry';
  18095. this.parameters = {
  18096. radius: radius,
  18097. segments: segments,
  18098. thetaStart: thetaStart,
  18099. thetaLength: thetaLength
  18100. };
  18101. radius = radius || 50;
  18102. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18103. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18104. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18105. var vertices = segments + 2;
  18106. var positions = new Float32Array( vertices * 3 );
  18107. var normals = new Float32Array( vertices * 3 );
  18108. var uvs = new Float32Array( vertices * 2 );
  18109. // center data is already zero, but need to set a few extras
  18110. normals[3] = 1.0;
  18111. uvs[0] = 0.5;
  18112. uvs[1] = 0.5;
  18113. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s++, i += 3, ii += 2 ) {
  18114. var segment = thetaStart + s / segments * thetaLength;
  18115. positions[i] = radius * Math.cos( segment );
  18116. positions[i + 1] = radius * Math.sin( segment );
  18117. normals[i + 2] = 1; // normal z
  18118. uvs[ii] = ( positions[i] / radius + 1 ) / 2;
  18119. uvs[ii + 1] = ( positions[i + 1] / radius + 1 ) / 2;
  18120. }
  18121. var indices = [];
  18122. for ( var i = 1; i <= segments; i ++ ) {
  18123. indices.push( i );
  18124. indices.push( i + 1 );
  18125. indices.push( 0 );
  18126. }
  18127. this.addAttribute( 'index', new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  18128. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  18129. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  18130. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  18131. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18132. };
  18133. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18134. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  18135. // File:src/extras/geometries/CylinderGeometry.js
  18136. /**
  18137. * @author mrdoob / http://mrdoob.com/
  18138. */
  18139. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18140. THREE.Geometry.call( this );
  18141. this.type = 'CylinderGeometry';
  18142. this.parameters = {
  18143. radiusTop: radiusTop,
  18144. radiusBottom: radiusBottom,
  18145. height: height,
  18146. radialSegments: radialSegments,
  18147. heightSegments: heightSegments,
  18148. openEnded: openEnded,
  18149. thetaStart: thetaStart,
  18150. thetaLength: thetaLength
  18151. };
  18152. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  18153. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  18154. height = height !== undefined ? height : 100;
  18155. radialSegments = radialSegments || 8;
  18156. heightSegments = heightSegments || 1;
  18157. openEnded = openEnded !== undefined ? openEnded : false;
  18158. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18159. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  18160. var heightHalf = height / 2;
  18161. var x, y, vertices = [], uvs = [];
  18162. for ( y = 0; y <= heightSegments; y ++ ) {
  18163. var verticesRow = [];
  18164. var uvsRow = [];
  18165. var v = y / heightSegments;
  18166. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18167. for ( x = 0; x <= radialSegments; x ++ ) {
  18168. var u = x / radialSegments;
  18169. var vertex = new THREE.Vector3();
  18170. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  18171. vertex.y = - v * height + heightHalf;
  18172. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  18173. this.vertices.push( vertex );
  18174. verticesRow.push( this.vertices.length - 1 );
  18175. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  18176. }
  18177. vertices.push( verticesRow );
  18178. uvs.push( uvsRow );
  18179. }
  18180. var tanTheta = ( radiusBottom - radiusTop ) / height;
  18181. var na, nb;
  18182. for ( x = 0; x < radialSegments; x ++ ) {
  18183. if ( radiusTop !== 0 ) {
  18184. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  18185. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  18186. } else {
  18187. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  18188. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  18189. }
  18190. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  18191. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  18192. for ( y = 0; y < heightSegments; y ++ ) {
  18193. var v1 = vertices[ y ][ x ];
  18194. var v2 = vertices[ y + 1 ][ x ];
  18195. var v3 = vertices[ y + 1 ][ x + 1 ];
  18196. var v4 = vertices[ y ][ x + 1 ];
  18197. var n1 = na.clone();
  18198. var n2 = na.clone();
  18199. var n3 = nb.clone();
  18200. var n4 = nb.clone();
  18201. var uv1 = uvs[ y ][ x ].clone();
  18202. var uv2 = uvs[ y + 1 ][ x ].clone();
  18203. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  18204. var uv4 = uvs[ y ][ x + 1 ].clone();
  18205. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  18206. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  18207. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  18208. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  18209. }
  18210. }
  18211. // top cap
  18212. if ( openEnded === false && radiusTop > 0 ) {
  18213. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  18214. for ( x = 0; x < radialSegments; x ++ ) {
  18215. var v1 = vertices[ 0 ][ x ];
  18216. var v2 = vertices[ 0 ][ x + 1 ];
  18217. var v3 = this.vertices.length - 1;
  18218. var n1 = new THREE.Vector3( 0, 1, 0 );
  18219. var n2 = new THREE.Vector3( 0, 1, 0 );
  18220. var n3 = new THREE.Vector3( 0, 1, 0 );
  18221. var uv1 = uvs[ 0 ][ x ].clone();
  18222. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  18223. var uv3 = new THREE.Vector2( uv2.x, 0 );
  18224. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  18225. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18226. }
  18227. }
  18228. // bottom cap
  18229. if ( openEnded === false && radiusBottom > 0 ) {
  18230. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  18231. for ( x = 0; x < radialSegments; x ++ ) {
  18232. var v1 = vertices[ heightSegments ][ x + 1 ];
  18233. var v2 = vertices[ heightSegments ][ x ];
  18234. var v3 = this.vertices.length - 1;
  18235. var n1 = new THREE.Vector3( 0, - 1, 0 );
  18236. var n2 = new THREE.Vector3( 0, - 1, 0 );
  18237. var n3 = new THREE.Vector3( 0, - 1, 0 );
  18238. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  18239. var uv2 = uvs[ heightSegments ][ x ].clone();
  18240. var uv3 = new THREE.Vector2( uv2.x, 1 );
  18241. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  18242. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18243. }
  18244. }
  18245. this.computeFaceNormals();
  18246. };
  18247. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18248. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  18249. // File:src/extras/geometries/EdgesGeometry.js
  18250. /**
  18251. * @author WestLangley / http://github.com/WestLangley
  18252. */
  18253. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  18254. THREE.BufferGeometry.call( this );
  18255. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18256. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  18257. var edge = [ 0, 0 ], hash = {};
  18258. var sortFunction = function ( a, b ) { return a - b };
  18259. var keys = [ 'a', 'b', 'c' ];
  18260. var geometry2;
  18261. if ( geometry instanceof THREE.BufferGeometry ) {
  18262. geometry2 = new THREE.Geometry();
  18263. geometry2.fromBufferGeometry( geometry );
  18264. } else {
  18265. geometry2 = geometry.clone();
  18266. }
  18267. geometry2.mergeVertices();
  18268. geometry2.computeFaceNormals();
  18269. var vertices = geometry2.vertices;
  18270. var faces = geometry2.faces;
  18271. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18272. var face = faces[ i ];
  18273. for ( var j = 0; j < 3; j ++ ) {
  18274. edge[ 0 ] = face[ keys[ j ] ];
  18275. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  18276. edge.sort( sortFunction );
  18277. var key = edge.toString();
  18278. if ( hash[ key ] === undefined ) {
  18279. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  18280. } else {
  18281. hash[ key ].face2 = i;
  18282. }
  18283. }
  18284. }
  18285. var coords = [];
  18286. for ( var key in hash ) {
  18287. var h = hash[ key ];
  18288. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  18289. var vertex = vertices[ h.vert1 ];
  18290. coords.push( vertex.x );
  18291. coords.push( vertex.y );
  18292. coords.push( vertex.z );
  18293. vertex = vertices[ h.vert2 ];
  18294. coords.push( vertex.x );
  18295. coords.push( vertex.y );
  18296. coords.push( vertex.z );
  18297. }
  18298. }
  18299. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  18300. };
  18301. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18302. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  18303. // File:src/extras/geometries/ExtrudeGeometry.js
  18304. /**
  18305. * @author zz85 / http://www.lab4games.net/zz85/blog
  18306. *
  18307. * Creates extruded geometry from a path shape.
  18308. *
  18309. * parameters = {
  18310. *
  18311. * curveSegments: <int>, // number of points on the curves
  18312. * steps: <int>, // number of points for z-side extrusions / used for subdividing segements of extrude spline too
  18313. * amount: <int>, // Depth to extrude the shape
  18314. *
  18315. * bevelEnabled: <bool>, // turn on bevel
  18316. * bevelThickness: <float>, // how deep into the original shape bevel goes
  18317. * bevelSize: <float>, // how far from shape outline is bevel
  18318. * bevelSegments: <int>, // number of bevel layers
  18319. *
  18320. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  18321. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  18322. *
  18323. * uvGenerator: <Object> // object that provides UV generator functions
  18324. *
  18325. * }
  18326. **/
  18327. THREE.ExtrudeGeometry = function ( shapes, options ) {
  18328. if ( typeof( shapes ) === "undefined" ) {
  18329. shapes = [];
  18330. return;
  18331. }
  18332. THREE.Geometry.call( this );
  18333. this.type = 'ExtrudeGeometry';
  18334. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  18335. this.addShapeList( shapes, options );
  18336. this.computeFaceNormals();
  18337. // can't really use automatic vertex normals
  18338. // as then front and back sides get smoothed too
  18339. // should do separate smoothing just for sides
  18340. //this.computeVertexNormals();
  18341. //console.log( "took", ( Date.now() - startTime ) );
  18342. };
  18343. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18344. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  18345. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  18346. var sl = shapes.length;
  18347. for ( var s = 0; s < sl; s ++ ) {
  18348. var shape = shapes[ s ];
  18349. this.addShape( shape, options );
  18350. }
  18351. };
  18352. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  18353. var amount = options.amount !== undefined ? options.amount : 100;
  18354. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  18355. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  18356. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18357. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  18358. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18359. var steps = options.steps !== undefined ? options.steps : 1;
  18360. var extrudePath = options.extrudePath;
  18361. var extrudePts, extrudeByPath = false;
  18362. // Use default WorldUVGenerator if no UV generators are specified.
  18363. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  18364. var splineTube, binormal, normal, position2;
  18365. if ( extrudePath ) {
  18366. extrudePts = extrudePath.getSpacedPoints( steps );
  18367. extrudeByPath = true;
  18368. bevelEnabled = false; // bevels not supported for path extrusion
  18369. // SETUP TNB variables
  18370. // Reuse TNB from TubeGeomtry for now.
  18371. // TODO1 - have a .isClosed in spline?
  18372. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames(extrudePath, steps, false);
  18373. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18374. binormal = new THREE.Vector3();
  18375. normal = new THREE.Vector3();
  18376. position2 = new THREE.Vector3();
  18377. }
  18378. // Safeguards if bevels are not enabled
  18379. if ( ! bevelEnabled ) {
  18380. bevelSegments = 0;
  18381. bevelThickness = 0;
  18382. bevelSize = 0;
  18383. }
  18384. // Variables initalization
  18385. var ahole, h, hl; // looping of holes
  18386. var scope = this;
  18387. var shapesOffset = this.vertices.length;
  18388. var shapePoints = shape.extractPoints( curveSegments );
  18389. var vertices = shapePoints.shape;
  18390. var holes = shapePoints.holes;
  18391. var reverse = ! THREE.Shape.Utils.isClockWise( vertices ) ;
  18392. if ( reverse ) {
  18393. vertices = vertices.reverse();
  18394. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18395. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18396. ahole = holes[ h ];
  18397. if ( THREE.Shape.Utils.isClockWise( ahole ) ) {
  18398. holes[ h ] = ahole.reverse();
  18399. }
  18400. }
  18401. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  18402. }
  18403. var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
  18404. /* Vertices */
  18405. var contour = vertices; // vertices has all points but contour has only points of circumference
  18406. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18407. ahole = holes[ h ];
  18408. vertices = vertices.concat( ahole );
  18409. }
  18410. function scalePt2 ( pt, vec, size ) {
  18411. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  18412. return vec.clone().multiplyScalar( size ).add( pt );
  18413. }
  18414. var b, bs, t, z,
  18415. vert, vlen = vertices.length,
  18416. face, flen = faces.length;
  18417. // Find directions for point movement
  18418. function getBevelVec( inPt, inPrev, inNext ) {
  18419. var EPSILON = 0.0000000001;
  18420. // computes for inPt the corresponding point inPt' on a new contour
  18421. // shiftet by 1 unit (length of normalized vector) to the left
  18422. // if we walk along contour clockwise, this new contour is outside the old one
  18423. //
  18424. // inPt' is the intersection of the two lines parallel to the two
  18425. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18426. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  18427. // good reading for geometry algorithms (here: line-line intersection)
  18428. // http://geomalgorithms.com/a05-_intersect-1.html
  18429. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  18430. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  18431. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  18432. // check for colinear edges
  18433. var colinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18434. if ( Math.abs( colinear0 ) > EPSILON ) { // not colinear
  18435. // length of vectors for normalizing
  18436. var v_prev_len = Math.sqrt( v_prev_lensq );
  18437. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  18438. // shift adjacent points by unit vectors to the left
  18439. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  18440. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  18441. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  18442. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  18443. // scaling factor for v_prev to intersection point
  18444. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  18445. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  18446. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18447. // vector from inPt to intersection point
  18448. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  18449. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  18450. // Don't normalize!, otherwise sharp corners become ugly
  18451. // but prevent crazy spikes
  18452. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  18453. if ( v_trans_lensq <= 2 ) {
  18454. return new THREE.Vector2( v_trans_x, v_trans_y );
  18455. } else {
  18456. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  18457. }
  18458. } else { // handle special case of colinear edges
  18459. var direction_eq = false; // assumes: opposite
  18460. if ( v_prev_x > EPSILON ) {
  18461. if ( v_next_x > EPSILON ) { direction_eq = true; }
  18462. } else {
  18463. if ( v_prev_x < - EPSILON ) {
  18464. if ( v_next_x < - EPSILON ) { direction_eq = true; }
  18465. } else {
  18466. if ( Math.sign(v_prev_y) === Math.sign(v_next_y) ) { direction_eq = true; }
  18467. }
  18468. }
  18469. if ( direction_eq ) {
  18470. // console.log("Warning: lines are a straight sequence");
  18471. v_trans_x = - v_prev_y;
  18472. v_trans_y = v_prev_x;
  18473. shrink_by = Math.sqrt( v_prev_lensq );
  18474. } else {
  18475. // console.log("Warning: lines are a straight spike");
  18476. v_trans_x = v_prev_x;
  18477. v_trans_y = v_prev_y;
  18478. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  18479. }
  18480. }
  18481. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  18482. }
  18483. var contourMovements = [];
  18484. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18485. if ( j === il ) j = 0;
  18486. if ( k === il ) k = 0;
  18487. // (j)---(i)---(k)
  18488. // console.log('i,j,k', i, j , k)
  18489. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  18490. }
  18491. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  18492. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18493. ahole = holes[ h ];
  18494. oneHoleMovements = [];
  18495. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18496. if ( j === il ) j = 0;
  18497. if ( k === il ) k = 0;
  18498. // (j)---(i)---(k)
  18499. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  18500. }
  18501. holesMovements.push( oneHoleMovements );
  18502. verticesMovements = verticesMovements.concat( oneHoleMovements );
  18503. }
  18504. // Loop bevelSegments, 1 for the front, 1 for the back
  18505. for ( b = 0; b < bevelSegments; b ++ ) {
  18506. //for ( b = bevelSegments; b > 0; b -- ) {
  18507. t = b / bevelSegments;
  18508. z = bevelThickness * ( 1 - t );
  18509. //z = bevelThickness * t;
  18510. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ) ; // curved
  18511. //bs = bevelSize * t ; // linear
  18512. // contract shape
  18513. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18514. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18515. v( vert.x, vert.y, - z );
  18516. }
  18517. // expand holes
  18518. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18519. ahole = holes[ h ];
  18520. oneHoleMovements = holesMovements[ h ];
  18521. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18522. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18523. v( vert.x, vert.y, - z );
  18524. }
  18525. }
  18526. }
  18527. bs = bevelSize;
  18528. // Back facing vertices
  18529. for ( i = 0; i < vlen; i ++ ) {
  18530. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18531. if ( ! extrudeByPath ) {
  18532. v( vert.x, vert.y, 0 );
  18533. } else {
  18534. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18535. normal.copy( splineTube.normals[0] ).multiplyScalar(vert.x);
  18536. binormal.copy( splineTube.binormals[0] ).multiplyScalar(vert.y);
  18537. position2.copy( extrudePts[0] ).add(normal).add(binormal);
  18538. v( position2.x, position2.y, position2.z );
  18539. }
  18540. }
  18541. // Add stepped vertices...
  18542. // Including front facing vertices
  18543. var s;
  18544. for ( s = 1; s <= steps; s ++ ) {
  18545. for ( i = 0; i < vlen; i ++ ) {
  18546. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18547. if ( ! extrudeByPath ) {
  18548. v( vert.x, vert.y, amount / steps * s );
  18549. } else {
  18550. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18551. normal.copy( splineTube.normals[s] ).multiplyScalar( vert.x );
  18552. binormal.copy( splineTube.binormals[s] ).multiplyScalar( vert.y );
  18553. position2.copy( extrudePts[s] ).add( normal ).add( binormal );
  18554. v( position2.x, position2.y, position2.z );
  18555. }
  18556. }
  18557. }
  18558. // Add bevel segments planes
  18559. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18560. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  18561. t = b / bevelSegments;
  18562. z = bevelThickness * ( 1 - t );
  18563. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  18564. bs = bevelSize * Math.sin ( t * Math.PI / 2 ) ;
  18565. // contract shape
  18566. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18567. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18568. v( vert.x, vert.y, amount + z );
  18569. }
  18570. // expand holes
  18571. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18572. ahole = holes[ h ];
  18573. oneHoleMovements = holesMovements[ h ];
  18574. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18575. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18576. if ( ! extrudeByPath ) {
  18577. v( vert.x, vert.y, amount + z );
  18578. } else {
  18579. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  18580. }
  18581. }
  18582. }
  18583. }
  18584. /* Faces */
  18585. // Top and bottom faces
  18586. buildLidFaces();
  18587. // Sides faces
  18588. buildSideFaces();
  18589. ///// Internal functions
  18590. function buildLidFaces() {
  18591. if ( bevelEnabled ) {
  18592. var layer = 0 ; // steps + 1
  18593. var offset = vlen * layer;
  18594. // Bottom faces
  18595. for ( i = 0; i < flen; i ++ ) {
  18596. face = faces[ i ];
  18597. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  18598. }
  18599. layer = steps + bevelSegments * 2;
  18600. offset = vlen * layer;
  18601. // Top faces
  18602. for ( i = 0; i < flen; i ++ ) {
  18603. face = faces[ i ];
  18604. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  18605. }
  18606. } else {
  18607. // Bottom faces
  18608. for ( i = 0; i < flen; i ++ ) {
  18609. face = faces[ i ];
  18610. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  18611. }
  18612. // Top faces
  18613. for ( i = 0; i < flen; i ++ ) {
  18614. face = faces[ i ];
  18615. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  18616. }
  18617. }
  18618. }
  18619. // Create faces for the z-sides of the shape
  18620. function buildSideFaces() {
  18621. var layeroffset = 0;
  18622. sidewalls( contour, layeroffset );
  18623. layeroffset += contour.length;
  18624. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18625. ahole = holes[ h ];
  18626. sidewalls( ahole, layeroffset );
  18627. //, true
  18628. layeroffset += ahole.length;
  18629. }
  18630. }
  18631. function sidewalls( contour, layeroffset ) {
  18632. var j, k;
  18633. i = contour.length;
  18634. while ( -- i >= 0 ) {
  18635. j = i;
  18636. k = i - 1;
  18637. if ( k < 0 ) k = contour.length - 1;
  18638. //console.log('b', i,j, i-1, k,vertices.length);
  18639. var s = 0, sl = steps + bevelSegments * 2;
  18640. for ( s = 0; s < sl; s ++ ) {
  18641. var slen1 = vlen * s;
  18642. var slen2 = vlen * ( s + 1 );
  18643. var a = layeroffset + j + slen1,
  18644. b = layeroffset + k + slen1,
  18645. c = layeroffset + k + slen2,
  18646. d = layeroffset + j + slen2;
  18647. f4( a, b, c, d, contour, s, sl, j, k );
  18648. }
  18649. }
  18650. }
  18651. function v( x, y, z ) {
  18652. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  18653. }
  18654. function f3( a, b, c ) {
  18655. a += shapesOffset;
  18656. b += shapesOffset;
  18657. c += shapesOffset;
  18658. scope.faces.push( new THREE.Face3( a, b, c ) );
  18659. var uvs = uvgen.generateTopUV( scope, a, b, c );
  18660. scope.faceVertexUvs[ 0 ].push( uvs );
  18661. }
  18662. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  18663. a += shapesOffset;
  18664. b += shapesOffset;
  18665. c += shapesOffset;
  18666. d += shapesOffset;
  18667. scope.faces.push( new THREE.Face3( a, b, d ) );
  18668. scope.faces.push( new THREE.Face3( b, c, d ) );
  18669. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  18670. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  18671. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  18672. }
  18673. };
  18674. THREE.ExtrudeGeometry.WorldUVGenerator = {
  18675. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  18676. var vertices = geometry.vertices;
  18677. var a = vertices[ indexA ];
  18678. var b = vertices[ indexB ];
  18679. var c = vertices[ indexC ];
  18680. return [
  18681. new THREE.Vector2( a.x, a.y ),
  18682. new THREE.Vector2( b.x, b.y ),
  18683. new THREE.Vector2( c.x, c.y )
  18684. ];
  18685. },
  18686. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  18687. var vertices = geometry.vertices;
  18688. var a = vertices[ indexA ];
  18689. var b = vertices[ indexB ];
  18690. var c = vertices[ indexC ];
  18691. var d = vertices[ indexD ];
  18692. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  18693. return [
  18694. new THREE.Vector2( a.x, 1 - a.z ),
  18695. new THREE.Vector2( b.x, 1 - b.z ),
  18696. new THREE.Vector2( c.x, 1 - c.z ),
  18697. new THREE.Vector2( d.x, 1 - d.z )
  18698. ];
  18699. } else {
  18700. return [
  18701. new THREE.Vector2( a.y, 1 - a.z ),
  18702. new THREE.Vector2( b.y, 1 - b.z ),
  18703. new THREE.Vector2( c.y, 1 - c.z ),
  18704. new THREE.Vector2( d.y, 1 - d.z )
  18705. ];
  18706. }
  18707. }
  18708. };
  18709. // File:src/extras/geometries/ShapeGeometry.js
  18710. /**
  18711. * @author jonobr1 / http://jonobr1.com
  18712. *
  18713. * Creates a one-sided polygonal geometry from a path shape. Similar to
  18714. * ExtrudeGeometry.
  18715. *
  18716. * parameters = {
  18717. *
  18718. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  18719. *
  18720. * material: <int> // material index for front and back faces
  18721. * uvGenerator: <Object> // object that provides UV generator functions
  18722. *
  18723. * }
  18724. **/
  18725. THREE.ShapeGeometry = function ( shapes, options ) {
  18726. THREE.Geometry.call( this );
  18727. this.type = 'ShapeGeometry';
  18728. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  18729. this.addShapeList( shapes, options );
  18730. this.computeFaceNormals();
  18731. };
  18732. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18733. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  18734. /**
  18735. * Add an array of shapes to THREE.ShapeGeometry.
  18736. */
  18737. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  18738. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18739. this.addShape( shapes[ i ], options );
  18740. }
  18741. return this;
  18742. };
  18743. /**
  18744. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  18745. */
  18746. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  18747. if ( options === undefined ) options = {};
  18748. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18749. var material = options.material;
  18750. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  18751. //
  18752. var i, l, hole;
  18753. var shapesOffset = this.vertices.length;
  18754. var shapePoints = shape.extractPoints( curveSegments );
  18755. var vertices = shapePoints.shape;
  18756. var holes = shapePoints.holes;
  18757. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  18758. if ( reverse ) {
  18759. vertices = vertices.reverse();
  18760. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  18761. for ( i = 0, l = holes.length; i < l; i ++ ) {
  18762. hole = holes[ i ];
  18763. if ( THREE.Shape.Utils.isClockWise( hole ) ) {
  18764. holes[ i ] = hole.reverse();
  18765. }
  18766. }
  18767. reverse = false;
  18768. }
  18769. var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
  18770. // Vertices
  18771. var contour = vertices;
  18772. for ( i = 0, l = holes.length; i < l; i ++ ) {
  18773. hole = holes[ i ];
  18774. vertices = vertices.concat( hole );
  18775. }
  18776. //
  18777. var vert, vlen = vertices.length;
  18778. var face, flen = faces.length;
  18779. for ( i = 0; i < vlen; i ++ ) {
  18780. vert = vertices[ i ];
  18781. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  18782. }
  18783. for ( i = 0; i < flen; i ++ ) {
  18784. face = faces[ i ];
  18785. var a = face[ 0 ] + shapesOffset;
  18786. var b = face[ 1 ] + shapesOffset;
  18787. var c = face[ 2 ] + shapesOffset;
  18788. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  18789. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  18790. }
  18791. };
  18792. // File:src/extras/geometries/LatheGeometry.js
  18793. /**
  18794. * @author astrodud / http://astrodud.isgreat.org/
  18795. * @author zz85 / https://github.com/zz85
  18796. * @author bhouston / http://exocortex.com
  18797. */
  18798. // points - to create a closed torus, one must use a set of points
  18799. // like so: [ a, b, c, d, a ], see first is the same as last.
  18800. // segments - the number of circumference segments to create
  18801. // phiStart - the starting radian
  18802. // phiLength - the radian (0 to 2*PI) range of the lathed section
  18803. // 2*pi is a closed lathe, less than 2PI is a portion.
  18804. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  18805. THREE.Geometry.call( this );
  18806. this.type = 'LatheGeometry';
  18807. this.parameters = {
  18808. points: points,
  18809. segments: segments,
  18810. phiStart: phiStart,
  18811. phiLength: phiLength
  18812. };
  18813. segments = segments || 12;
  18814. phiStart = phiStart || 0;
  18815. phiLength = phiLength || 2 * Math.PI;
  18816. var inversePointLength = 1.0 / ( points.length - 1 );
  18817. var inverseSegments = 1.0 / segments;
  18818. for ( var i = 0, il = segments; i <= il; i ++ ) {
  18819. var phi = phiStart + i * inverseSegments * phiLength;
  18820. var c = Math.cos( phi ),
  18821. s = Math.sin( phi );
  18822. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  18823. var pt = points[ j ];
  18824. var vertex = new THREE.Vector3();
  18825. vertex.x = c * pt.x - s * pt.y;
  18826. vertex.y = s * pt.x + c * pt.y;
  18827. vertex.z = pt.z;
  18828. this.vertices.push( vertex );
  18829. }
  18830. }
  18831. var np = points.length;
  18832. for ( var i = 0, il = segments; i < il; i ++ ) {
  18833. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  18834. var base = j + np * i;
  18835. var a = base;
  18836. var b = base + np;
  18837. var c = base + 1 + np;
  18838. var d = base + 1;
  18839. var u0 = i * inverseSegments;
  18840. var v0 = j * inversePointLength;
  18841. var u1 = u0 + inverseSegments;
  18842. var v1 = v0 + inversePointLength;
  18843. this.faces.push( new THREE.Face3( a, b, d ) );
  18844. this.faceVertexUvs[ 0 ].push( [
  18845. new THREE.Vector2( u0, v0 ),
  18846. new THREE.Vector2( u1, v0 ),
  18847. new THREE.Vector2( u0, v1 )
  18848. ] );
  18849. this.faces.push( new THREE.Face3( b, c, d ) );
  18850. this.faceVertexUvs[ 0 ].push( [
  18851. new THREE.Vector2( u1, v0 ),
  18852. new THREE.Vector2( u1, v1 ),
  18853. new THREE.Vector2( u0, v1 )
  18854. ] );
  18855. }
  18856. }
  18857. this.mergeVertices();
  18858. this.computeFaceNormals();
  18859. this.computeVertexNormals();
  18860. };
  18861. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18862. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  18863. // File:src/extras/geometries/PlaneGeometry.js
  18864. /**
  18865. * @author mrdoob / http://mrdoob.com/
  18866. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  18867. */
  18868. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  18869. console.log( 'THREE.PlaneGeometry: Consider using THREE.PlaneBufferGeometry for lower memory footprint.' );
  18870. THREE.Geometry.call( this );
  18871. this.type = 'PlaneGeometry';
  18872. this.parameters = {
  18873. width: width,
  18874. height: height,
  18875. widthSegments: widthSegments,
  18876. heightSegments: heightSegments
  18877. };
  18878. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  18879. };
  18880. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18881. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  18882. // File:src/extras/geometries/PlaneBufferGeometry.js
  18883. /**
  18884. * @author mrdoob / http://mrdoob.com/
  18885. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  18886. */
  18887. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  18888. THREE.BufferGeometry.call( this );
  18889. this.type = 'PlaneBufferGeometry';
  18890. this.parameters = {
  18891. width: width,
  18892. height: height,
  18893. widthSegments: widthSegments,
  18894. heightSegments: heightSegments
  18895. };
  18896. var width_half = width / 2;
  18897. var height_half = height / 2;
  18898. var gridX = Math.floor( widthSegments ) || 1;
  18899. var gridY = Math.floor( heightSegments ) || 1;
  18900. var gridX1 = gridX + 1;
  18901. var gridY1 = gridY + 1;
  18902. var segment_width = width / gridX;
  18903. var segment_height = height / gridY;
  18904. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  18905. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  18906. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  18907. var offset = 0;
  18908. var offset2 = 0;
  18909. for ( var iy = 0; iy < gridY1; iy ++ ) {
  18910. var y = iy * segment_height - height_half;
  18911. for ( var ix = 0; ix < gridX1; ix ++ ) {
  18912. var x = ix * segment_width - width_half;
  18913. vertices[ offset ] = x;
  18914. vertices[ offset + 1 ] = - y;
  18915. normals[ offset + 2 ] = 1;
  18916. uvs[ offset2 ] = ix / gridX;
  18917. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  18918. offset += 3;
  18919. offset2 += 2;
  18920. }
  18921. }
  18922. offset = 0;
  18923. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  18924. for ( var iy = 0; iy < gridY; iy ++ ) {
  18925. for ( var ix = 0; ix < gridX; ix ++ ) {
  18926. var a = ix + gridX1 * iy;
  18927. var b = ix + gridX1 * ( iy + 1 );
  18928. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  18929. var d = ( ix + 1 ) + gridX1 * iy;
  18930. indices[ offset ] = a;
  18931. indices[ offset + 1 ] = b;
  18932. indices[ offset + 2 ] = d;
  18933. indices[ offset + 3 ] = b;
  18934. indices[ offset + 4 ] = c;
  18935. indices[ offset + 5 ] = d;
  18936. offset += 6;
  18937. }
  18938. }
  18939. this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
  18940. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  18941. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  18942. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  18943. };
  18944. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18945. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  18946. // File:src/extras/geometries/RingGeometry.js
  18947. /**
  18948. * @author Kaleb Murphy
  18949. */
  18950. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18951. THREE.Geometry.call( this );
  18952. this.type = 'RingGeometry';
  18953. this.parameters = {
  18954. innerRadius: innerRadius,
  18955. outerRadius: outerRadius,
  18956. thetaSegments: thetaSegments,
  18957. phiSegments: phiSegments,
  18958. thetaStart: thetaStart,
  18959. thetaLength: thetaLength
  18960. };
  18961. innerRadius = innerRadius || 0;
  18962. outerRadius = outerRadius || 50;
  18963. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18964. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18965. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  18966. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  18967. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  18968. for ( i = 0; i < phiSegments + 1; i ++ ) { // concentric circles inside ring
  18969. for ( o = 0; o < thetaSegments + 1; o ++ ) { // number of segments per circle
  18970. var vertex = new THREE.Vector3();
  18971. var segment = thetaStart + o / thetaSegments * thetaLength;
  18972. vertex.x = radius * Math.cos( segment );
  18973. vertex.y = radius * Math.sin( segment );
  18974. this.vertices.push( vertex );
  18975. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  18976. }
  18977. radius += radiusStep;
  18978. }
  18979. var n = new THREE.Vector3( 0, 0, 1 );
  18980. for ( i = 0; i < phiSegments; i ++ ) { // concentric circles inside ring
  18981. var thetaSegment = i * (thetaSegments + 1);
  18982. for ( o = 0; o < thetaSegments ; o ++ ) { // number of segments per circle
  18983. var segment = o + thetaSegment;
  18984. var v1 = segment;
  18985. var v2 = segment + thetaSegments + 1;
  18986. var v3 = segment + thetaSegments + 2;
  18987. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  18988. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ]);
  18989. v1 = segment;
  18990. v2 = segment + thetaSegments + 2;
  18991. v3 = segment + 1;
  18992. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  18993. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ]);
  18994. }
  18995. }
  18996. this.computeFaceNormals();
  18997. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18998. };
  18999. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19000. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  19001. // File:src/extras/geometries/SphereGeometry.js
  19002. /**
  19003. * @author mrdoob / http://mrdoob.com/
  19004. */
  19005. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19006. console.log( 'THREE.SphereGeometry: Consider using THREE.SphereBufferGeometry for lower memory footprint.' );
  19007. THREE.Geometry.call( this );
  19008. this.type = 'SphereGeometry';
  19009. this.parameters = {
  19010. radius: radius,
  19011. widthSegments: widthSegments,
  19012. heightSegments: heightSegments,
  19013. phiStart: phiStart,
  19014. phiLength: phiLength,
  19015. thetaStart: thetaStart,
  19016. thetaLength: thetaLength
  19017. };
  19018. radius = radius || 50;
  19019. widthSegments = Math.max( 2, Math.floor( widthSegments ) || 8 );
  19020. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19021. phiStart = phiStart !== undefined ? phiStart : 0;
  19022. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19023. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19024. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19025. var x, y, vertices = [], uvs = [];
  19026. for ( y = 0; y <= heightSegments; y ++ ) {
  19027. var verticesRow = [];
  19028. var uvsRow = [];
  19029. for ( x = 0; x <= widthSegments; x ++ ) {
  19030. var u = x / widthSegments;
  19031. var v = y / heightSegments;
  19032. var vertex = new THREE.Vector3();
  19033. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19034. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  19035. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19036. this.vertices.push( vertex );
  19037. verticesRow.push( this.vertices.length - 1 );
  19038. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  19039. }
  19040. vertices.push( verticesRow );
  19041. uvs.push( uvsRow );
  19042. }
  19043. for ( y = 0; y < heightSegments; y ++ ) {
  19044. for ( x = 0; x < widthSegments; x ++ ) {
  19045. var v1 = vertices[ y ][ x + 1 ];
  19046. var v2 = vertices[ y ][ x ];
  19047. var v3 = vertices[ y + 1 ][ x ];
  19048. var v4 = vertices[ y + 1 ][ x + 1 ];
  19049. var n1 = this.vertices[ v1 ].clone().normalize();
  19050. var n2 = this.vertices[ v2 ].clone().normalize();
  19051. var n3 = this.vertices[ v3 ].clone().normalize();
  19052. var n4 = this.vertices[ v4 ].clone().normalize();
  19053. var uv1 = uvs[ y ][ x + 1 ].clone();
  19054. var uv2 = uvs[ y ][ x ].clone();
  19055. var uv3 = uvs[ y + 1 ][ x ].clone();
  19056. var uv4 = uvs[ y + 1 ][ x + 1 ].clone();
  19057. if ( Math.abs( this.vertices[ v1 ].y ) === radius ) {
  19058. uv1.x = ( uv1.x + uv2.x ) / 2;
  19059. this.faces.push( new THREE.Face3( v1, v3, v4, [ n1, n3, n4 ] ) );
  19060. this.faceVertexUvs[ 0 ].push( [ uv1, uv3, uv4 ] );
  19061. } else if ( Math.abs( this.vertices[ v3 ].y ) === radius ) {
  19062. uv3.x = ( uv3.x + uv4.x ) / 2;
  19063. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  19064. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  19065. } else {
  19066. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  19067. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  19068. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  19069. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  19070. }
  19071. }
  19072. }
  19073. this.computeFaceNormals();
  19074. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19075. };
  19076. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19077. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  19078. // File:src/extras/geometries/SphereBufferGeometry.js
  19079. /**
  19080. * @author benaadams / https://twitter.com/ben_a_adams
  19081. * based on THREE.SphereGeometry
  19082. */
  19083. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19084. THREE.BufferGeometry.call( this );
  19085. this.type = 'SphereBufferGeometry';
  19086. this.parameters = {
  19087. radius: radius,
  19088. widthSegments: widthSegments,
  19089. heightSegments: heightSegments,
  19090. phiStart: phiStart,
  19091. phiLength: phiLength,
  19092. thetaStart: thetaStart,
  19093. thetaLength: thetaLength
  19094. };
  19095. radius = radius || 50;
  19096. widthSegments = Math.max( 2, Math.floor( widthSegments ) || 8 );
  19097. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19098. phiStart = phiStart !== undefined ? phiStart : 0;
  19099. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19100. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19101. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19102. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  19103. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  19104. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3);
  19105. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  19106. var index = 0, vertices = [], normal = new THREE.Vector3();
  19107. for ( var y = 0; y <= heightSegments; y ++ ) {
  19108. var verticesRow = [];
  19109. var v = y / heightSegments;
  19110. for ( var x = 0; x <= widthSegments; x ++ ) {
  19111. var u = x / widthSegments;
  19112. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19113. var py = radius * Math.cos( thetaStart + v * thetaLength );
  19114. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19115. normal.set( px, py, pz ).normalize();
  19116. positions.setXYZ( index, px, py, pz );
  19117. normals.setXYZ( index, normal.x, normal.y, normal.z );
  19118. uvs.setXY( index, u, 1 - v );
  19119. verticesRow.push( index );
  19120. index++;
  19121. }
  19122. vertices.push( verticesRow );
  19123. }
  19124. var indices = [];
  19125. for ( var y = 0; y < heightSegments; y ++ ) {
  19126. for ( var x = 0; x < widthSegments; x ++ ) {
  19127. var v1 = vertices[ y ][ x + 1 ];
  19128. var v2 = vertices[ y ][ x ];
  19129. var v3 = vertices[ y + 1 ][ x ];
  19130. var v4 = vertices[ y + 1 ][ x + 1 ];
  19131. if ( y !== 0 ) indices.push( v1, v2, v4 );
  19132. if ( y !== heightSegments - 1 ) indices.push( v2, v3, v4 );
  19133. }
  19134. }
  19135. this.addAttribute( 'index', new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  19136. this.addAttribute( 'position', positions );
  19137. this.addAttribute( 'normal', normals );
  19138. this.addAttribute( 'uv', uvs );
  19139. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19140. };
  19141. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19142. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  19143. // File:src/extras/geometries/TextGeometry.js
  19144. /**
  19145. * @author zz85 / http://www.lab4games.net/zz85/blog
  19146. * @author alteredq / http://alteredqualia.com/
  19147. *
  19148. * For creating 3D text geometry in three.js
  19149. *
  19150. * Text = 3D Text
  19151. *
  19152. * parameters = {
  19153. * size: <float>, // size of the text
  19154. * height: <float>, // thickness to extrude text
  19155. * curveSegments: <int>, // number of points on the curves
  19156. *
  19157. * font: <string>, // font name
  19158. * weight: <string>, // font weight (normal, bold)
  19159. * style: <string>, // font style (normal, italics)
  19160. *
  19161. * bevelEnabled: <bool>, // turn on bevel
  19162. * bevelThickness: <float>, // how deep into text bevel goes
  19163. * bevelSize: <float>, // how far from text outline is bevel
  19164. * }
  19165. *
  19166. */
  19167. /* Usage Examples
  19168. // TextGeometry wrapper
  19169. var text3d = new TextGeometry( text, options );
  19170. // Complete manner
  19171. var textShapes = THREE.FontUtils.generateShapes( text, options );
  19172. var text3d = new ExtrudeGeometry( textShapes, options );
  19173. */
  19174. THREE.TextGeometry = function ( text, parameters ) {
  19175. parameters = parameters || {};
  19176. var textShapes = THREE.FontUtils.generateShapes( text, parameters );
  19177. // translate parameters to ExtrudeGeometry API
  19178. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  19179. // defaults
  19180. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  19181. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  19182. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  19183. THREE.ExtrudeGeometry.call( this, textShapes, parameters );
  19184. this.type = 'TextGeometry';
  19185. };
  19186. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  19187. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  19188. // File:src/extras/geometries/TorusGeometry.js
  19189. /**
  19190. * @author oosmoxiecode
  19191. * @author mrdoob / http://mrdoob.com/
  19192. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  19193. */
  19194. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  19195. THREE.Geometry.call( this );
  19196. this.type = 'TorusGeometry';
  19197. this.parameters = {
  19198. radius: radius,
  19199. tube: tube,
  19200. radialSegments: radialSegments,
  19201. tubularSegments: tubularSegments,
  19202. arc: arc
  19203. };
  19204. radius = radius || 100;
  19205. tube = tube || 40;
  19206. radialSegments = radialSegments || 8;
  19207. tubularSegments = tubularSegments || 6;
  19208. arc = arc || Math.PI * 2;
  19209. var center = new THREE.Vector3(), uvs = [], normals = [];
  19210. for ( var j = 0; j <= radialSegments; j ++ ) {
  19211. for ( var i = 0; i <= tubularSegments; i ++ ) {
  19212. var u = i / tubularSegments * arc;
  19213. var v = j / radialSegments * Math.PI * 2;
  19214. center.x = radius * Math.cos( u );
  19215. center.y = radius * Math.sin( u );
  19216. var vertex = new THREE.Vector3();
  19217. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  19218. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  19219. vertex.z = tube * Math.sin( v );
  19220. this.vertices.push( vertex );
  19221. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  19222. normals.push( vertex.clone().sub( center ).normalize() );
  19223. }
  19224. }
  19225. for ( var j = 1; j <= radialSegments; j ++ ) {
  19226. for ( var i = 1; i <= tubularSegments; i ++ ) {
  19227. var a = ( tubularSegments + 1 ) * j + i - 1;
  19228. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  19229. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  19230. var d = ( tubularSegments + 1 ) * j + i;
  19231. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  19232. this.faces.push( face );
  19233. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  19234. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  19235. this.faces.push( face );
  19236. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  19237. }
  19238. }
  19239. this.computeFaceNormals();
  19240. };
  19241. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19242. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  19243. // File:src/extras/geometries/TorusKnotGeometry.js
  19244. /**
  19245. * @author oosmoxiecode
  19246. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  19247. */
  19248. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  19249. THREE.Geometry.call( this );
  19250. this.type = 'TorusKnotGeometry';
  19251. this.parameters = {
  19252. radius: radius,
  19253. tube: tube,
  19254. radialSegments: radialSegments,
  19255. tubularSegments: tubularSegments,
  19256. p: p,
  19257. q: q,
  19258. heightScale: heightScale
  19259. };
  19260. radius = radius || 100;
  19261. tube = tube || 40;
  19262. radialSegments = radialSegments || 64;
  19263. tubularSegments = tubularSegments || 8;
  19264. p = p || 2;
  19265. q = q || 3;
  19266. heightScale = heightScale || 1;
  19267. var grid = new Array( radialSegments );
  19268. var tang = new THREE.Vector3();
  19269. var n = new THREE.Vector3();
  19270. var bitan = new THREE.Vector3();
  19271. for ( var i = 0; i < radialSegments; ++ i ) {
  19272. grid[ i ] = new Array( tubularSegments );
  19273. var u = i / radialSegments * 2 * p * Math.PI;
  19274. var p1 = getPos( u, q, p, radius, heightScale );
  19275. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  19276. tang.subVectors( p2, p1 );
  19277. n.addVectors( p2, p1 );
  19278. bitan.crossVectors( tang, n );
  19279. n.crossVectors( bitan, tang );
  19280. bitan.normalize();
  19281. n.normalize();
  19282. for ( var j = 0; j < tubularSegments; ++ j ) {
  19283. var v = j / tubularSegments * 2 * Math.PI;
  19284. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  19285. var cy = tube * Math.sin( v );
  19286. var pos = new THREE.Vector3();
  19287. pos.x = p1.x + cx * n.x + cy * bitan.x;
  19288. pos.y = p1.y + cx * n.y + cy * bitan.y;
  19289. pos.z = p1.z + cx * n.z + cy * bitan.z;
  19290. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  19291. }
  19292. }
  19293. for ( var i = 0; i < radialSegments; ++ i ) {
  19294. for ( var j = 0; j < tubularSegments; ++ j ) {
  19295. var ip = ( i + 1 ) % radialSegments;
  19296. var jp = ( j + 1 ) % tubularSegments;
  19297. var a = grid[ i ][ j ];
  19298. var b = grid[ ip ][ j ];
  19299. var c = grid[ ip ][ jp ];
  19300. var d = grid[ i ][ jp ];
  19301. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  19302. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  19303. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  19304. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  19305. this.faces.push( new THREE.Face3( a, b, d ) );
  19306. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19307. this.faces.push( new THREE.Face3( b, c, d ) );
  19308. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19309. }
  19310. }
  19311. this.computeFaceNormals();
  19312. this.computeVertexNormals();
  19313. function getPos( u, in_q, in_p, radius, heightScale ) {
  19314. var cu = Math.cos( u );
  19315. var su = Math.sin( u );
  19316. var quOverP = in_q / in_p * u;
  19317. var cs = Math.cos( quOverP );
  19318. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  19319. var ty = radius * ( 2 + cs ) * su * 0.5;
  19320. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  19321. return new THREE.Vector3( tx, ty, tz );
  19322. }
  19323. };
  19324. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19325. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  19326. // File:src/extras/geometries/TubeGeometry.js
  19327. /**
  19328. * @author WestLangley / https://github.com/WestLangley
  19329. * @author zz85 / https://github.com/zz85
  19330. * @author miningold / https://github.com/miningold
  19331. * @author jonobr1 / https://github.com/jonobr1
  19332. *
  19333. * Modified from the TorusKnotGeometry by @oosmoxiecode
  19334. *
  19335. * Creates a tube which extrudes along a 3d spline
  19336. *
  19337. * Uses parallel transport frames as described in
  19338. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  19339. */
  19340. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  19341. THREE.Geometry.call( this );
  19342. this.type = 'TubeGeometry';
  19343. this.parameters = {
  19344. path: path,
  19345. segments: segments,
  19346. radius: radius,
  19347. radialSegments: radialSegments,
  19348. closed: closed
  19349. };
  19350. segments = segments || 64;
  19351. radius = radius || 1;
  19352. radialSegments = radialSegments || 8;
  19353. closed = closed || false;
  19354. taper = taper || THREE.TubeGeometry.NoTaper;
  19355. var grid = [];
  19356. var scope = this,
  19357. tangent,
  19358. normal,
  19359. binormal,
  19360. numpoints = segments + 1,
  19361. u, v, r,
  19362. cx, cy,
  19363. pos, pos2 = new THREE.Vector3(),
  19364. i, j,
  19365. ip, jp,
  19366. a, b, c, d,
  19367. uva, uvb, uvc, uvd;
  19368. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  19369. tangents = frames.tangents,
  19370. normals = frames.normals,
  19371. binormals = frames.binormals;
  19372. // proxy internals
  19373. this.tangents = tangents;
  19374. this.normals = normals;
  19375. this.binormals = binormals;
  19376. function vert( x, y, z ) {
  19377. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  19378. }
  19379. // consruct the grid
  19380. for ( i = 0; i < numpoints; i ++ ) {
  19381. grid[ i ] = [];
  19382. u = i / ( numpoints - 1 );
  19383. pos = path.getPointAt( u );
  19384. tangent = tangents[ i ];
  19385. normal = normals[ i ];
  19386. binormal = binormals[ i ];
  19387. r = radius * taper( u );
  19388. for ( j = 0; j < radialSegments; j ++ ) {
  19389. v = j / radialSegments * 2 * Math.PI;
  19390. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  19391. cy = r * Math.sin( v );
  19392. pos2.copy( pos );
  19393. pos2.x += cx * normal.x + cy * binormal.x;
  19394. pos2.y += cx * normal.y + cy * binormal.y;
  19395. pos2.z += cx * normal.z + cy * binormal.z;
  19396. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  19397. }
  19398. }
  19399. // construct the mesh
  19400. for ( i = 0; i < segments; i ++ ) {
  19401. for ( j = 0; j < radialSegments; j ++ ) {
  19402. ip = ( closed ) ? (i + 1) % segments : i + 1;
  19403. jp = (j + 1) % radialSegments;
  19404. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  19405. b = grid[ ip ][ j ];
  19406. c = grid[ ip ][ jp ];
  19407. d = grid[ i ][ jp ];
  19408. uva = new THREE.Vector2( i / segments, j / radialSegments );
  19409. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  19410. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  19411. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  19412. this.faces.push( new THREE.Face3( a, b, d ) );
  19413. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19414. this.faces.push( new THREE.Face3( b, c, d ) );
  19415. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19416. }
  19417. }
  19418. this.computeFaceNormals();
  19419. this.computeVertexNormals();
  19420. };
  19421. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19422. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  19423. THREE.TubeGeometry.NoTaper = function ( u ) {
  19424. return 1;
  19425. };
  19426. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  19427. return Math.sin( Math.PI * u );
  19428. };
  19429. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  19430. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  19431. var normal = new THREE.Vector3(),
  19432. tangents = [],
  19433. normals = [],
  19434. binormals = [],
  19435. vec = new THREE.Vector3(),
  19436. mat = new THREE.Matrix4(),
  19437. numpoints = segments + 1,
  19438. theta,
  19439. epsilon = 0.0001,
  19440. smallest,
  19441. tx, ty, tz,
  19442. i, u;
  19443. // expose internals
  19444. this.tangents = tangents;
  19445. this.normals = normals;
  19446. this.binormals = binormals;
  19447. // compute the tangent vectors for each segment on the path
  19448. for ( i = 0; i < numpoints; i ++ ) {
  19449. u = i / ( numpoints - 1 );
  19450. tangents[ i ] = path.getTangentAt( u );
  19451. tangents[ i ].normalize();
  19452. }
  19453. initialNormal3();
  19454. /*
  19455. function initialNormal1(lastBinormal) {
  19456. // fixed start binormal. Has dangers of 0 vectors
  19457. normals[ 0 ] = new THREE.Vector3();
  19458. binormals[ 0 ] = new THREE.Vector3();
  19459. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  19460. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  19461. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  19462. }
  19463. function initialNormal2() {
  19464. // This uses the Frenet-Serret formula for deriving binormal
  19465. var t2 = path.getTangentAt( epsilon );
  19466. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  19467. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  19468. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  19469. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  19470. }
  19471. */
  19472. function initialNormal3() {
  19473. // select an initial normal vector perpenicular to the first tangent vector,
  19474. // and in the direction of the smallest tangent xyz component
  19475. normals[ 0 ] = new THREE.Vector3();
  19476. binormals[ 0 ] = new THREE.Vector3();
  19477. smallest = Number.MAX_VALUE;
  19478. tx = Math.abs( tangents[ 0 ].x );
  19479. ty = Math.abs( tangents[ 0 ].y );
  19480. tz = Math.abs( tangents[ 0 ].z );
  19481. if ( tx <= smallest ) {
  19482. smallest = tx;
  19483. normal.set( 1, 0, 0 );
  19484. }
  19485. if ( ty <= smallest ) {
  19486. smallest = ty;
  19487. normal.set( 0, 1, 0 );
  19488. }
  19489. if ( tz <= smallest ) {
  19490. normal.set( 0, 0, 1 );
  19491. }
  19492. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  19493. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  19494. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  19495. }
  19496. // compute the slowly-varying normal and binormal vectors for each segment on the path
  19497. for ( i = 1; i < numpoints; i ++ ) {
  19498. normals[ i ] = normals[ i - 1 ].clone();
  19499. binormals[ i ] = binormals[ i - 1 ].clone();
  19500. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  19501. if ( vec.length() > epsilon ) {
  19502. vec.normalize();
  19503. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  19504. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  19505. }
  19506. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  19507. }
  19508. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  19509. if ( closed ) {
  19510. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  19511. theta /= ( numpoints - 1 );
  19512. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  19513. theta = - theta;
  19514. }
  19515. for ( i = 1; i < numpoints; i ++ ) {
  19516. // twist a little...
  19517. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  19518. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  19519. }
  19520. }
  19521. };
  19522. // File:src/extras/geometries/PolyhedronGeometry.js
  19523. /**
  19524. * @author clockworkgeek / https://github.com/clockworkgeek
  19525. * @author timothypratley / https://github.com/timothypratley
  19526. * @author WestLangley / http://github.com/WestLangley
  19527. */
  19528. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  19529. THREE.Geometry.call( this );
  19530. this.type = 'PolyhedronGeometry';
  19531. this.parameters = {
  19532. vertices: vertices,
  19533. indices: indices,
  19534. radius: radius,
  19535. detail: detail
  19536. };
  19537. radius = radius || 1;
  19538. detail = detail || 0;
  19539. var that = this;
  19540. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  19541. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  19542. }
  19543. var p = this.vertices;
  19544. var faces = [];
  19545. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  19546. var v1 = p[ indices[ i ] ];
  19547. var v2 = p[ indices[ i + 1 ] ];
  19548. var v3 = p[ indices[ i + 2 ] ];
  19549. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  19550. }
  19551. var centroid = new THREE.Vector3();
  19552. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  19553. subdivide( faces[ i ], detail );
  19554. }
  19555. // Handle case when face straddles the seam
  19556. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  19557. var uvs = this.faceVertexUvs[ 0 ][ i ];
  19558. var x0 = uvs[ 0 ].x;
  19559. var x1 = uvs[ 1 ].x;
  19560. var x2 = uvs[ 2 ].x;
  19561. var max = Math.max( x0, Math.max( x1, x2 ) );
  19562. var min = Math.min( x0, Math.min( x1, x2 ) );
  19563. if ( max > 0.9 && min < 0.1 ) { // 0.9 is somewhat arbitrary
  19564. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  19565. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  19566. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  19567. }
  19568. }
  19569. // Apply radius
  19570. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  19571. this.vertices[ i ].multiplyScalar( radius );
  19572. }
  19573. // Merge vertices
  19574. this.mergeVertices();
  19575. this.computeFaceNormals();
  19576. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19577. // Project vector onto sphere's surface
  19578. function prepare( vector ) {
  19579. var vertex = vector.normalize().clone();
  19580. vertex.index = that.vertices.push( vertex ) - 1;
  19581. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  19582. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  19583. var v = inclination( vector ) / Math.PI + 0.5;
  19584. vertex.uv = new THREE.Vector2( u, 1 - v );
  19585. return vertex;
  19586. }
  19587. // Approximate a curved face with recursively sub-divided triangles.
  19588. function make( v1, v2, v3 ) {
  19589. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  19590. that.faces.push( face );
  19591. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  19592. var azi = azimuth( centroid );
  19593. that.faceVertexUvs[ 0 ].push( [
  19594. correctUV( v1.uv, v1, azi ),
  19595. correctUV( v2.uv, v2, azi ),
  19596. correctUV( v3.uv, v3, azi )
  19597. ] );
  19598. }
  19599. // Analytically subdivide a face to the required detail level.
  19600. function subdivide( face, detail ) {
  19601. var cols = Math.pow(2, detail);
  19602. var a = prepare( that.vertices[ face.a ] );
  19603. var b = prepare( that.vertices[ face.b ] );
  19604. var c = prepare( that.vertices[ face.c ] );
  19605. var v = [];
  19606. // Construct all of the vertices for this subdivision.
  19607. for ( var i = 0 ; i <= cols; i ++ ) {
  19608. v[ i ] = [];
  19609. var aj = prepare( a.clone().lerp( c, i / cols ) );
  19610. var bj = prepare( b.clone().lerp( c, i / cols ) );
  19611. var rows = cols - i;
  19612. for ( var j = 0; j <= rows; j ++) {
  19613. if ( j === 0 && i === cols ) {
  19614. v[ i ][ j ] = aj;
  19615. } else {
  19616. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  19617. }
  19618. }
  19619. }
  19620. // Construct all of the faces.
  19621. for ( var i = 0; i < cols ; i ++ ) {
  19622. for ( var j = 0; j < 2 * (cols - i) - 1; j ++ ) {
  19623. var k = Math.floor( j / 2 );
  19624. if ( j % 2 === 0 ) {
  19625. make(
  19626. v[ i ][ k + 1],
  19627. v[ i + 1 ][ k ],
  19628. v[ i ][ k ]
  19629. );
  19630. } else {
  19631. make(
  19632. v[ i ][ k + 1 ],
  19633. v[ i + 1][ k + 1],
  19634. v[ i + 1 ][ k ]
  19635. );
  19636. }
  19637. }
  19638. }
  19639. }
  19640. // Angle around the Y axis, counter-clockwise when looking from above.
  19641. function azimuth( vector ) {
  19642. return Math.atan2( vector.z, - vector.x );
  19643. }
  19644. // Angle above the XZ plane.
  19645. function inclination( vector ) {
  19646. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  19647. }
  19648. // Texture fixing helper. Spheres have some odd behaviours.
  19649. function correctUV( uv, vector, azimuth ) {
  19650. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  19651. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  19652. return uv.clone();
  19653. }
  19654. };
  19655. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19656. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  19657. // File:src/extras/geometries/DodecahedronGeometry.js
  19658. /**
  19659. * @author Abe Pazos / https://hamoid.com
  19660. */
  19661. THREE.DodecahedronGeometry = function ( radius, detail ) {
  19662. this.parameters = {
  19663. radius: radius,
  19664. detail: detail
  19665. };
  19666. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  19667. var r = 1 / t;
  19668. var vertices = [
  19669. // (±1, ±1, ±1)
  19670. -1, -1, -1, -1, -1, 1,
  19671. -1, 1, -1, -1, 1, 1,
  19672. 1, -1, -1, 1, -1, 1,
  19673. 1, 1, -1, 1, 1, 1,
  19674. // (0, ±1/φ, ±φ)
  19675. 0, -r, -t, 0, -r, t,
  19676. 0, r, -t, 0, r, t,
  19677. // (±1/φ, ±φ, 0)
  19678. -r, -t, 0, -r, t, 0,
  19679. r, -t, 0, r, t, 0,
  19680. // (±φ, 0, ±1/φ)
  19681. -t, 0, -r, t, 0, -r,
  19682. -t, 0, r, t, 0, r
  19683. ];
  19684. var indices = [
  19685. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  19686. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  19687. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  19688. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  19689. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  19690. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  19691. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  19692. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  19693. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  19694. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  19695. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  19696. 1, 12, 14, 1, 14, 5, 1, 5, 9
  19697. ];
  19698. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  19699. };
  19700. THREE.DodecahedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19701. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  19702. // File:src/extras/geometries/IcosahedronGeometry.js
  19703. /**
  19704. * @author timothypratley / https://github.com/timothypratley
  19705. */
  19706. THREE.IcosahedronGeometry = function ( radius, detail ) {
  19707. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  19708. var vertices = [
  19709. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  19710. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  19711. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  19712. ];
  19713. var indices = [
  19714. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  19715. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  19716. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  19717. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  19718. ];
  19719. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  19720. this.type = 'IcosahedronGeometry';
  19721. this.parameters = {
  19722. radius: radius,
  19723. detail: detail
  19724. };
  19725. };
  19726. THREE.IcosahedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19727. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  19728. // File:src/extras/geometries/OctahedronGeometry.js
  19729. /**
  19730. * @author timothypratley / https://github.com/timothypratley
  19731. */
  19732. THREE.OctahedronGeometry = function ( radius, detail ) {
  19733. this.parameters = {
  19734. radius: radius,
  19735. detail: detail
  19736. };
  19737. var vertices = [
  19738. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0,- 1, 0, 0, 0, 1, 0, 0,- 1
  19739. ];
  19740. var indices = [
  19741. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  19742. ];
  19743. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  19744. this.type = 'OctahedronGeometry';
  19745. this.parameters = {
  19746. radius: radius,
  19747. detail: detail
  19748. };
  19749. };
  19750. THREE.OctahedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19751. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  19752. // File:src/extras/geometries/TetrahedronGeometry.js
  19753. /**
  19754. * @author timothypratley / https://github.com/timothypratley
  19755. */
  19756. THREE.TetrahedronGeometry = function ( radius, detail ) {
  19757. var vertices = [
  19758. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  19759. ];
  19760. var indices = [
  19761. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  19762. ];
  19763. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  19764. this.type = 'TetrahedronGeometry';
  19765. this.parameters = {
  19766. radius: radius,
  19767. detail: detail
  19768. };
  19769. };
  19770. THREE.TetrahedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19771. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  19772. // File:src/extras/geometries/ParametricGeometry.js
  19773. /**
  19774. * @author zz85 / https://github.com/zz85
  19775. * Parametric Surfaces Geometry
  19776. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  19777. *
  19778. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  19779. *
  19780. */
  19781. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  19782. THREE.Geometry.call( this );
  19783. this.type = 'ParametricGeometry';
  19784. this.parameters = {
  19785. func: func,
  19786. slices: slices,
  19787. stacks: stacks
  19788. };
  19789. var verts = this.vertices;
  19790. var faces = this.faces;
  19791. var uvs = this.faceVertexUvs[ 0 ];
  19792. var i, j, p;
  19793. var u, v;
  19794. var sliceCount = slices + 1;
  19795. for ( i = 0; i <= stacks; i ++ ) {
  19796. v = i / stacks;
  19797. for ( j = 0; j <= slices; j ++ ) {
  19798. u = j / slices;
  19799. p = func( u, v );
  19800. verts.push( p );
  19801. }
  19802. }
  19803. var a, b, c, d;
  19804. var uva, uvb, uvc, uvd;
  19805. for ( i = 0; i < stacks; i ++ ) {
  19806. for ( j = 0; j < slices; j ++ ) {
  19807. a = i * sliceCount + j;
  19808. b = i * sliceCount + j + 1;
  19809. c = (i + 1) * sliceCount + j + 1;
  19810. d = (i + 1) * sliceCount + j;
  19811. uva = new THREE.Vector2( j / slices, i / stacks );
  19812. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  19813. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  19814. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  19815. faces.push( new THREE.Face3( a, b, d ) );
  19816. uvs.push( [ uva, uvb, uvd ] );
  19817. faces.push( new THREE.Face3( b, c, d ) );
  19818. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  19819. }
  19820. }
  19821. // console.log(this);
  19822. // magic bullet
  19823. // var diff = this.mergeVertices();
  19824. // console.log('removed ', diff, ' vertices by merging');
  19825. this.computeFaceNormals();
  19826. this.computeVertexNormals();
  19827. };
  19828. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19829. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  19830. // File:src/extras/geometries/WireframeGeometry.js
  19831. /**
  19832. * @author mrdoob / http://mrdoob.com/
  19833. */
  19834. THREE.WireframeGeometry = function ( geometry ) {
  19835. THREE.BufferGeometry.call( this );
  19836. var edge = [ 0, 0 ], hash = {};
  19837. var sortFunction = function ( a, b ) { return a - b };
  19838. var keys = [ 'a', 'b', 'c' ];
  19839. if ( geometry instanceof THREE.Geometry ) {
  19840. var vertices = geometry.vertices;
  19841. var faces = geometry.faces;
  19842. var numEdges = 0;
  19843. // allocate maximal size
  19844. var edges = new Uint32Array( 6 * faces.length );
  19845. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  19846. var face = faces[ i ];
  19847. for ( var j = 0; j < 3; j ++ ) {
  19848. edge[ 0 ] = face[ keys[ j ] ];
  19849. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  19850. edge.sort( sortFunction );
  19851. var key = edge.toString();
  19852. if ( hash[ key ] === undefined ) {
  19853. edges[ 2 * numEdges ] = edge[ 0 ];
  19854. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  19855. hash[ key ] = true;
  19856. numEdges ++;
  19857. }
  19858. }
  19859. }
  19860. var coords = new Float32Array( numEdges * 2 * 3 );
  19861. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  19862. for ( var j = 0; j < 2; j ++ ) {
  19863. var vertex = vertices[ edges [ 2 * i + j] ];
  19864. var index = 6 * i + 3 * j;
  19865. coords[ index + 0 ] = vertex.x;
  19866. coords[ index + 1 ] = vertex.y;
  19867. coords[ index + 2 ] = vertex.z;
  19868. }
  19869. }
  19870. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  19871. } else if ( geometry instanceof THREE.BufferGeometry ) {
  19872. if ( geometry.attributes.index !== undefined ) { // Indexed BufferGeometry
  19873. var vertices = geometry.attributes.position;
  19874. var indices = geometry.attributes.index.array;
  19875. var drawcalls = geometry.drawcalls;
  19876. var numEdges = 0;
  19877. if ( drawcalls.length === 0 ) {
  19878. drawcalls = [ { count : indices.length, index : 0, start : 0 } ];
  19879. }
  19880. // allocate maximal size
  19881. var edges = new Uint32Array( 2 * indices.length );
  19882. for ( var o = 0, ol = drawcalls.length; o < ol; ++ o ) {
  19883. var start = drawcalls[ o ].start;
  19884. var count = drawcalls[ o ].count;
  19885. var index = drawcalls[ o ].index;
  19886. for ( var i = start, il = start + count; i < il; i += 3 ) {
  19887. for ( var j = 0; j < 3; j ++ ) {
  19888. edge[ 0 ] = index + indices[ i + j ];
  19889. edge[ 1 ] = index + indices[ i + ( j + 1 ) % 3 ];
  19890. edge.sort( sortFunction );
  19891. var key = edge.toString();
  19892. if ( hash[ key ] === undefined ) {
  19893. edges[ 2 * numEdges ] = edge[ 0 ];
  19894. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  19895. hash[ key ] = true;
  19896. numEdges ++;
  19897. }
  19898. }
  19899. }
  19900. }
  19901. var coords = new Float32Array( numEdges * 2 * 3 );
  19902. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  19903. for ( var j = 0; j < 2; j ++ ) {
  19904. var index = 6 * i + 3 * j;
  19905. var index2 = edges[2 * i + j];
  19906. coords[ index + 0 ] = vertices.getX( index2 );
  19907. coords[ index + 1 ] = vertices.getY( index2 );
  19908. coords[ index + 2 ] = vertices.getZ( index2 );
  19909. }
  19910. }
  19911. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  19912. } else { // non-indexed BufferGeometry
  19913. var vertices = geometry.attributes.position.array;
  19914. var numEdges = vertices.length / 3;
  19915. var numTris = numEdges / 3;
  19916. var coords = new Float32Array( numEdges * 2 * 3 );
  19917. for ( var i = 0, l = numTris; i < l; i ++ ) {
  19918. for ( var j = 0; j < 3; j ++ ) {
  19919. var index = 18 * i + 6 * j;
  19920. var index1 = 9 * i + 3 * j;
  19921. coords[ index + 0 ] = vertices[ index1 ];
  19922. coords[ index + 1 ] = vertices[ index1 + 1 ];
  19923. coords[ index + 2 ] = vertices[ index1 + 2 ];
  19924. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  19925. coords[ index + 3 ] = vertices[ index2 ];
  19926. coords[ index + 4 ] = vertices[ index2 + 1 ];
  19927. coords[ index + 5 ] = vertices[ index2 + 2 ];
  19928. }
  19929. }
  19930. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  19931. }
  19932. }
  19933. };
  19934. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19935. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  19936. // File:src/extras/helpers/AxisHelper.js
  19937. /**
  19938. * @author sroucheray / http://sroucheray.org/
  19939. * @author mrdoob / http://mrdoob.com/
  19940. */
  19941. THREE.AxisHelper = function ( size ) {
  19942. size = size || 1;
  19943. var vertices = new Float32Array( [
  19944. 0, 0, 0, size, 0, 0,
  19945. 0, 0, 0, 0, size, 0,
  19946. 0, 0, 0, 0, 0, size
  19947. ] );
  19948. var colors = new Float32Array( [
  19949. 1, 0, 0, 1, 0.6, 0,
  19950. 0, 1, 0, 0.6, 1, 0,
  19951. 0, 0, 1, 0, 0.6, 1
  19952. ] );
  19953. var geometry = new THREE.BufferGeometry();
  19954. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  19955. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  19956. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  19957. THREE.LineSegments.call( this, geometry, material );
  19958. };
  19959. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  19960. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  19961. // File:src/extras/helpers/ArrowHelper.js
  19962. /**
  19963. * @author WestLangley / http://github.com/WestLangley
  19964. * @author zz85 / http://github.com/zz85
  19965. * @author bhouston / http://exocortex.com
  19966. *
  19967. * Creates an arrow for visualizing directions
  19968. *
  19969. * Parameters:
  19970. * dir - Vector3
  19971. * origin - Vector3
  19972. * length - Number
  19973. * color - color in hex value
  19974. * headLength - Number
  19975. * headWidth - Number
  19976. */
  19977. THREE.ArrowHelper = ( function () {
  19978. var lineGeometry = new THREE.Geometry();
  19979. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  19980. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  19981. coneGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
  19982. return function ( dir, origin, length, color, headLength, headWidth ) {
  19983. // dir is assumed to be normalized
  19984. THREE.Object3D.call( this );
  19985. if ( color === undefined ) color = 0xffff00;
  19986. if ( length === undefined ) length = 1;
  19987. if ( headLength === undefined ) headLength = 0.2 * length;
  19988. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  19989. this.position.copy( origin );
  19990. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  19991. this.line.matrixAutoUpdate = false;
  19992. this.add( this.line );
  19993. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  19994. this.cone.matrixAutoUpdate = false;
  19995. this.add( this.cone );
  19996. this.setDirection( dir );
  19997. this.setLength( length, headLength, headWidth );
  19998. }
  19999. }() );
  20000. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  20001. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  20002. THREE.ArrowHelper.prototype.setDirection = ( function () {
  20003. var axis = new THREE.Vector3();
  20004. var radians;
  20005. return function ( dir ) {
  20006. // dir is assumed to be normalized
  20007. if ( dir.y > 0.99999 ) {
  20008. this.quaternion.set( 0, 0, 0, 1 );
  20009. } else if ( dir.y < - 0.99999 ) {
  20010. this.quaternion.set( 1, 0, 0, 0 );
  20011. } else {
  20012. axis.set( dir.z, 0, - dir.x ).normalize();
  20013. radians = Math.acos( dir.y );
  20014. this.quaternion.setFromAxisAngle( axis, radians );
  20015. }
  20016. };
  20017. }() );
  20018. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  20019. if ( headLength === undefined ) headLength = 0.2 * length;
  20020. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  20021. this.line.scale.set( 1, length - headLength, 1 );
  20022. this.line.updateMatrix();
  20023. this.cone.scale.set( headWidth, headLength, headWidth );
  20024. this.cone.position.y = length;
  20025. this.cone.updateMatrix();
  20026. };
  20027. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  20028. this.line.material.color.set( color );
  20029. this.cone.material.color.set( color );
  20030. };
  20031. // File:src/extras/helpers/BoxHelper.js
  20032. /**
  20033. * @author mrdoob / http://mrdoob.com/
  20034. */
  20035. THREE.BoxHelper = function ( object ) {
  20036. var geometry = new THREE.BufferGeometry();
  20037. geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( 72 ), 3 ) );
  20038. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  20039. if ( object !== undefined ) {
  20040. this.update( object );
  20041. }
  20042. };
  20043. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20044. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  20045. THREE.BoxHelper.prototype.update = function ( object ) {
  20046. var geometry = object.geometry;
  20047. if ( geometry.boundingBox === null ) {
  20048. geometry.computeBoundingBox();
  20049. }
  20050. var min = geometry.boundingBox.min;
  20051. var max = geometry.boundingBox.max;
  20052. /*
  20053. 5____4
  20054. 1/___0/|
  20055. | 6__|_7
  20056. 2/___3/
  20057. 0: max.x, max.y, max.z
  20058. 1: min.x, max.y, max.z
  20059. 2: min.x, min.y, max.z
  20060. 3: max.x, min.y, max.z
  20061. 4: max.x, max.y, min.z
  20062. 5: min.x, max.y, min.z
  20063. 6: min.x, min.y, min.z
  20064. 7: max.x, min.y, min.z
  20065. */
  20066. var vertices = this.geometry.attributes.position.array;
  20067. vertices[ 0 ] = max.x; vertices[ 1 ] = max.y; vertices[ 2 ] = max.z;
  20068. vertices[ 3 ] = min.x; vertices[ 4 ] = max.y; vertices[ 5 ] = max.z;
  20069. vertices[ 6 ] = min.x; vertices[ 7 ] = max.y; vertices[ 8 ] = max.z;
  20070. vertices[ 9 ] = min.x; vertices[ 10 ] = min.y; vertices[ 11 ] = max.z;
  20071. vertices[ 12 ] = min.x; vertices[ 13 ] = min.y; vertices[ 14 ] = max.z;
  20072. vertices[ 15 ] = max.x; vertices[ 16 ] = min.y; vertices[ 17 ] = max.z;
  20073. vertices[ 18 ] = max.x; vertices[ 19 ] = min.y; vertices[ 20 ] = max.z;
  20074. vertices[ 21 ] = max.x; vertices[ 22 ] = max.y; vertices[ 23 ] = max.z;
  20075. //
  20076. vertices[ 24 ] = max.x; vertices[ 25 ] = max.y; vertices[ 26 ] = min.z;
  20077. vertices[ 27 ] = min.x; vertices[ 28 ] = max.y; vertices[ 29 ] = min.z;
  20078. vertices[ 30 ] = min.x; vertices[ 31 ] = max.y; vertices[ 32 ] = min.z;
  20079. vertices[ 33 ] = min.x; vertices[ 34 ] = min.y; vertices[ 35 ] = min.z;
  20080. vertices[ 36 ] = min.x; vertices[ 37 ] = min.y; vertices[ 38 ] = min.z;
  20081. vertices[ 39 ] = max.x; vertices[ 40 ] = min.y; vertices[ 41 ] = min.z;
  20082. vertices[ 42 ] = max.x; vertices[ 43 ] = min.y; vertices[ 44 ] = min.z;
  20083. vertices[ 45 ] = max.x; vertices[ 46 ] = max.y; vertices[ 47 ] = min.z;
  20084. //
  20085. vertices[ 48 ] = max.x; vertices[ 49 ] = max.y; vertices[ 50 ] = max.z;
  20086. vertices[ 51 ] = max.x; vertices[ 52 ] = max.y; vertices[ 53 ] = min.z;
  20087. vertices[ 54 ] = min.x; vertices[ 55 ] = max.y; vertices[ 56 ] = max.z;
  20088. vertices[ 57 ] = min.x; vertices[ 58 ] = max.y; vertices[ 59 ] = min.z;
  20089. vertices[ 60 ] = min.x; vertices[ 61 ] = min.y; vertices[ 62 ] = max.z;
  20090. vertices[ 63 ] = min.x; vertices[ 64 ] = min.y; vertices[ 65 ] = min.z;
  20091. vertices[ 66 ] = max.x; vertices[ 67 ] = min.y; vertices[ 68 ] = max.z;
  20092. vertices[ 69 ] = max.x; vertices[ 70 ] = min.y; vertices[ 71 ] = min.z;
  20093. this.geometry.attributes.position.needsUpdate = true;
  20094. this.geometry.computeBoundingSphere();
  20095. this.matrix = object.matrixWorld;
  20096. this.matrixAutoUpdate = false;
  20097. };
  20098. // File:src/extras/helpers/BoundingBoxHelper.js
  20099. /**
  20100. * @author WestLangley / http://github.com/WestLangley
  20101. */
  20102. // a helper to show the world-axis-aligned bounding box for an object
  20103. THREE.BoundingBoxHelper = function ( object, hex ) {
  20104. var color = ( hex !== undefined ) ? hex : 0x888888;
  20105. this.object = object;
  20106. this.box = new THREE.Box3();
  20107. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  20108. };
  20109. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  20110. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  20111. THREE.BoundingBoxHelper.prototype.update = function () {
  20112. this.box.setFromObject( this.object );
  20113. this.box.size( this.scale );
  20114. this.box.center( this.position );
  20115. };
  20116. // File:src/extras/helpers/CameraHelper.js
  20117. /**
  20118. * @author alteredq / http://alteredqualia.com/
  20119. *
  20120. * - shows frustum, line of sight and up of the camera
  20121. * - suitable for fast updates
  20122. * - based on frustum visualization in lightgl.js shadowmap example
  20123. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  20124. */
  20125. THREE.CameraHelper = function ( camera ) {
  20126. var geometry = new THREE.Geometry();
  20127. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  20128. var pointMap = {};
  20129. // colors
  20130. var hexFrustum = 0xffaa00;
  20131. var hexCone = 0xff0000;
  20132. var hexUp = 0x00aaff;
  20133. var hexTarget = 0xffffff;
  20134. var hexCross = 0x333333;
  20135. // near
  20136. addLine( "n1", "n2", hexFrustum );
  20137. addLine( "n2", "n4", hexFrustum );
  20138. addLine( "n4", "n3", hexFrustum );
  20139. addLine( "n3", "n1", hexFrustum );
  20140. // far
  20141. addLine( "f1", "f2", hexFrustum );
  20142. addLine( "f2", "f4", hexFrustum );
  20143. addLine( "f4", "f3", hexFrustum );
  20144. addLine( "f3", "f1", hexFrustum );
  20145. // sides
  20146. addLine( "n1", "f1", hexFrustum );
  20147. addLine( "n2", "f2", hexFrustum );
  20148. addLine( "n3", "f3", hexFrustum );
  20149. addLine( "n4", "f4", hexFrustum );
  20150. // cone
  20151. addLine( "p", "n1", hexCone );
  20152. addLine( "p", "n2", hexCone );
  20153. addLine( "p", "n3", hexCone );
  20154. addLine( "p", "n4", hexCone );
  20155. // up
  20156. addLine( "u1", "u2", hexUp );
  20157. addLine( "u2", "u3", hexUp );
  20158. addLine( "u3", "u1", hexUp );
  20159. // target
  20160. addLine( "c", "t", hexTarget );
  20161. addLine( "p", "c", hexCross );
  20162. // cross
  20163. addLine( "cn1", "cn2", hexCross );
  20164. addLine( "cn3", "cn4", hexCross );
  20165. addLine( "cf1", "cf2", hexCross );
  20166. addLine( "cf3", "cf4", hexCross );
  20167. function addLine( a, b, hex ) {
  20168. addPoint( a, hex );
  20169. addPoint( b, hex );
  20170. }
  20171. function addPoint( id, hex ) {
  20172. geometry.vertices.push( new THREE.Vector3() );
  20173. geometry.colors.push( new THREE.Color( hex ) );
  20174. if ( pointMap[ id ] === undefined ) {
  20175. pointMap[ id ] = [];
  20176. }
  20177. pointMap[ id ].push( geometry.vertices.length - 1 );
  20178. }
  20179. THREE.LineSegments.call( this, geometry, material );
  20180. this.camera = camera;
  20181. this.matrix = camera.matrixWorld;
  20182. this.matrixAutoUpdate = false;
  20183. this.pointMap = pointMap;
  20184. this.update();
  20185. };
  20186. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20187. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  20188. THREE.CameraHelper.prototype.update = function () {
  20189. var geometry, pointMap;
  20190. var vector = new THREE.Vector3();
  20191. var camera = new THREE.Camera();
  20192. var setPoint = function ( point, x, y, z ) {
  20193. vector.set( x, y, z ).unproject( camera );
  20194. var points = pointMap[ point ];
  20195. if ( points !== undefined ) {
  20196. for ( var i = 0, il = points.length; i < il; i ++ ) {
  20197. geometry.vertices[ points[ i ] ].copy( vector );
  20198. }
  20199. }
  20200. };
  20201. return function () {
  20202. geometry = this.geometry;
  20203. pointMap = this.pointMap;
  20204. var w = 1, h = 1;
  20205. // we need just camera projection matrix
  20206. // world matrix must be identity
  20207. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  20208. // center / target
  20209. setPoint( "c", 0, 0, - 1 );
  20210. setPoint( "t", 0, 0, 1 );
  20211. // near
  20212. setPoint( "n1", - w, - h, - 1 );
  20213. setPoint( "n2", w, - h, - 1 );
  20214. setPoint( "n3", - w, h, - 1 );
  20215. setPoint( "n4", w, h, - 1 );
  20216. // far
  20217. setPoint( "f1", - w, - h, 1 );
  20218. setPoint( "f2", w, - h, 1 );
  20219. setPoint( "f3", - w, h, 1 );
  20220. setPoint( "f4", w, h, 1 );
  20221. // up
  20222. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  20223. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  20224. setPoint( "u3", 0, h * 2, - 1 );
  20225. // cross
  20226. setPoint( "cf1", - w, 0, 1 );
  20227. setPoint( "cf2", w, 0, 1 );
  20228. setPoint( "cf3", 0, - h, 1 );
  20229. setPoint( "cf4", 0, h, 1 );
  20230. setPoint( "cn1", - w, 0, - 1 );
  20231. setPoint( "cn2", w, 0, - 1 );
  20232. setPoint( "cn3", 0, - h, - 1 );
  20233. setPoint( "cn4", 0, h, - 1 );
  20234. geometry.verticesNeedUpdate = true;
  20235. };
  20236. }();
  20237. // File:src/extras/helpers/DirectionalLightHelper.js
  20238. /**
  20239. * @author alteredq / http://alteredqualia.com/
  20240. * @author mrdoob / http://mrdoob.com/
  20241. * @author WestLangley / http://github.com/WestLangley
  20242. */
  20243. THREE.DirectionalLightHelper = function ( light, size ) {
  20244. THREE.Object3D.call( this );
  20245. this.light = light;
  20246. this.light.updateMatrixWorld();
  20247. this.matrix = light.matrixWorld;
  20248. this.matrixAutoUpdate = false;
  20249. size = size || 1;
  20250. var geometry = new THREE.Geometry();
  20251. geometry.vertices.push(
  20252. new THREE.Vector3( - size, size, 0 ),
  20253. new THREE.Vector3( size, size, 0 ),
  20254. new THREE.Vector3( size, - size, 0 ),
  20255. new THREE.Vector3( - size, - size, 0 ),
  20256. new THREE.Vector3( - size, size, 0 )
  20257. );
  20258. var material = new THREE.LineBasicMaterial( { fog: false } );
  20259. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20260. this.lightPlane = new THREE.Line( geometry, material );
  20261. this.add( this.lightPlane );
  20262. geometry = new THREE.Geometry();
  20263. geometry.vertices.push(
  20264. new THREE.Vector3(),
  20265. new THREE.Vector3()
  20266. );
  20267. material = new THREE.LineBasicMaterial( { fog: false } );
  20268. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20269. this.targetLine = new THREE.Line( geometry, material );
  20270. this.add( this.targetLine );
  20271. this.update();
  20272. };
  20273. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  20274. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  20275. THREE.DirectionalLightHelper.prototype.dispose = function () {
  20276. this.lightPlane.geometry.dispose();
  20277. this.lightPlane.material.dispose();
  20278. this.targetLine.geometry.dispose();
  20279. this.targetLine.material.dispose();
  20280. };
  20281. THREE.DirectionalLightHelper.prototype.update = function () {
  20282. var v1 = new THREE.Vector3();
  20283. var v2 = new THREE.Vector3();
  20284. var v3 = new THREE.Vector3();
  20285. return function () {
  20286. v1.setFromMatrixPosition( this.light.matrixWorld );
  20287. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  20288. v3.subVectors( v2, v1 );
  20289. this.lightPlane.lookAt( v3 );
  20290. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20291. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  20292. this.targetLine.geometry.verticesNeedUpdate = true;
  20293. this.targetLine.material.color.copy( this.lightPlane.material.color );
  20294. };
  20295. }();
  20296. // File:src/extras/helpers/EdgesHelper.js
  20297. /**
  20298. * @author WestLangley / http://github.com/WestLangley
  20299. * @param object THREE.Mesh whose geometry will be used
  20300. * @param hex line color
  20301. * @param thresholdAngle the minimim angle (in degrees),
  20302. * between the face normals of adjacent faces,
  20303. * that is required to render an edge. A value of 10 means
  20304. * an edge is only rendered if the angle is at least 10 degrees.
  20305. */
  20306. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  20307. var color = ( hex !== undefined ) ? hex : 0xffffff;
  20308. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  20309. this.matrix = object.matrixWorld;
  20310. this.matrixAutoUpdate = false;
  20311. };
  20312. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20313. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  20314. // File:src/extras/helpers/FaceNormalsHelper.js
  20315. /**
  20316. * @author mrdoob / http://mrdoob.com/
  20317. * @author WestLangley / http://github.com/WestLangley
  20318. */
  20319. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  20320. this.object = object;
  20321. this.size = ( size !== undefined ) ? size : 1;
  20322. var color = ( hex !== undefined ) ? hex : 0xffff00;
  20323. var width = ( linewidth !== undefined ) ? linewidth : 1;
  20324. var geometry = new THREE.Geometry();
  20325. var faces = this.object.geometry.faces;
  20326. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20327. geometry.vertices.push( new THREE.Vector3(), new THREE.Vector3() );
  20328. }
  20329. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  20330. this.matrixAutoUpdate = false;
  20331. this.normalMatrix = new THREE.Matrix3();
  20332. this.update();
  20333. };
  20334. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20335. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  20336. THREE.FaceNormalsHelper.prototype.update = function () {
  20337. var vertices = this.geometry.vertices;
  20338. var object = this.object;
  20339. var objectVertices = object.geometry.vertices;
  20340. var objectFaces = object.geometry.faces;
  20341. var objectWorldMatrix = object.matrixWorld;
  20342. object.updateMatrixWorld( true );
  20343. this.normalMatrix.getNormalMatrix( objectWorldMatrix );
  20344. for ( var i = 0, i2 = 0, l = objectFaces.length; i < l; i ++, i2 += 2 ) {
  20345. var face = objectFaces[ i ];
  20346. vertices[ i2 ].copy( objectVertices[ face.a ] )
  20347. .add( objectVertices[ face.b ] )
  20348. .add( objectVertices[ face.c ] )
  20349. .divideScalar( 3 )
  20350. .applyMatrix4( objectWorldMatrix );
  20351. vertices[ i2 + 1 ].copy( face.normal )
  20352. .applyMatrix3( this.normalMatrix )
  20353. .normalize()
  20354. .multiplyScalar( this.size )
  20355. .add( vertices[ i2 ] );
  20356. }
  20357. this.geometry.verticesNeedUpdate = true;
  20358. return this;
  20359. };
  20360. // File:src/extras/helpers/GridHelper.js
  20361. /**
  20362. * @author mrdoob / http://mrdoob.com/
  20363. */
  20364. THREE.GridHelper = function ( size, step ) {
  20365. var geometry = new THREE.Geometry();
  20366. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  20367. this.color1 = new THREE.Color( 0x444444 );
  20368. this.color2 = new THREE.Color( 0x888888 );
  20369. for ( var i = - size; i <= size; i += step ) {
  20370. geometry.vertices.push(
  20371. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  20372. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  20373. );
  20374. var color = i === 0 ? this.color1 : this.color2;
  20375. geometry.colors.push( color, color, color, color );
  20376. }
  20377. THREE.LineSegments.call( this, geometry, material );
  20378. };
  20379. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20380. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  20381. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  20382. this.color1.set( colorCenterLine );
  20383. this.color2.set( colorGrid );
  20384. this.geometry.colorsNeedUpdate = true;
  20385. };
  20386. // File:src/extras/helpers/HemisphereLightHelper.js
  20387. /**
  20388. * @author alteredq / http://alteredqualia.com/
  20389. * @author mrdoob / http://mrdoob.com/
  20390. */
  20391. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  20392. THREE.Object3D.call( this );
  20393. this.light = light;
  20394. this.light.updateMatrixWorld();
  20395. this.matrix = light.matrixWorld;
  20396. this.matrixAutoUpdate = false;
  20397. this.colors = [ new THREE.Color(), new THREE.Color() ];
  20398. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  20399. geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
  20400. for ( var i = 0, il = 8; i < il; i ++ ) {
  20401. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  20402. }
  20403. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  20404. this.lightSphere = new THREE.Mesh( geometry, material );
  20405. this.add( this.lightSphere );
  20406. this.update();
  20407. };
  20408. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  20409. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  20410. THREE.HemisphereLightHelper.prototype.dispose = function () {
  20411. this.lightSphere.geometry.dispose();
  20412. this.lightSphere.material.dispose();
  20413. };
  20414. THREE.HemisphereLightHelper.prototype.update = function () {
  20415. var vector = new THREE.Vector3();
  20416. return function () {
  20417. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  20418. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  20419. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  20420. this.lightSphere.geometry.colorsNeedUpdate = true;
  20421. }
  20422. }();
  20423. // File:src/extras/helpers/PointLightHelper.js
  20424. /**
  20425. * @author alteredq / http://alteredqualia.com/
  20426. * @author mrdoob / http://mrdoob.com/
  20427. */
  20428. THREE.PointLightHelper = function ( light, sphereSize ) {
  20429. this.light = light;
  20430. this.light.updateMatrixWorld();
  20431. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  20432. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  20433. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20434. THREE.Mesh.call( this, geometry, material );
  20435. this.matrix = this.light.matrixWorld;
  20436. this.matrixAutoUpdate = false;
  20437. /*
  20438. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  20439. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  20440. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  20441. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  20442. var d = light.distance;
  20443. if ( d === 0.0 ) {
  20444. this.lightDistance.visible = false;
  20445. } else {
  20446. this.lightDistance.scale.set( d, d, d );
  20447. }
  20448. this.add( this.lightDistance );
  20449. */
  20450. };
  20451. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  20452. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  20453. THREE.PointLightHelper.prototype.dispose = function () {
  20454. this.geometry.dispose();
  20455. this.material.dispose();
  20456. };
  20457. THREE.PointLightHelper.prototype.update = function () {
  20458. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20459. /*
  20460. var d = this.light.distance;
  20461. if ( d === 0.0 ) {
  20462. this.lightDistance.visible = false;
  20463. } else {
  20464. this.lightDistance.visible = true;
  20465. this.lightDistance.scale.set( d, d, d );
  20466. }
  20467. */
  20468. };
  20469. // File:src/extras/helpers/SkeletonHelper.js
  20470. /**
  20471. * @author Sean Griffin / http://twitter.com/sgrif
  20472. * @author Michael Guerrero / http://realitymeltdown.com
  20473. * @author mrdoob / http://mrdoob.com/
  20474. * @author ikerr / http://verold.com
  20475. */
  20476. THREE.SkeletonHelper = function ( object ) {
  20477. this.bones = this.getBoneList( object );
  20478. var geometry = new THREE.DynamicGeometry();
  20479. for ( var i = 0; i < this.bones.length; i ++ ) {
  20480. var bone = this.bones[ i ];
  20481. if ( bone.parent instanceof THREE.Bone ) {
  20482. geometry.vertices.push( new THREE.Vector3() );
  20483. geometry.vertices.push( new THREE.Vector3() );
  20484. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  20485. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  20486. }
  20487. }
  20488. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  20489. THREE.LineSegments.call( this, geometry, material );
  20490. this.root = object;
  20491. this.matrix = object.matrixWorld;
  20492. this.matrixAutoUpdate = false;
  20493. this.update();
  20494. };
  20495. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20496. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  20497. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  20498. var boneList = [];
  20499. if ( object instanceof THREE.Bone ) {
  20500. boneList.push( object );
  20501. }
  20502. for ( var i = 0; i < object.children.length; i ++ ) {
  20503. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  20504. }
  20505. return boneList;
  20506. };
  20507. THREE.SkeletonHelper.prototype.update = function () {
  20508. var geometry = this.geometry;
  20509. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  20510. var boneMatrix = new THREE.Matrix4();
  20511. var j = 0;
  20512. for ( var i = 0; i < this.bones.length; i ++ ) {
  20513. var bone = this.bones[ i ];
  20514. if ( bone.parent instanceof THREE.Bone ) {
  20515. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  20516. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  20517. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  20518. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  20519. j += 2;
  20520. }
  20521. }
  20522. geometry.verticesNeedUpdate = true;
  20523. geometry.computeBoundingSphere();
  20524. };
  20525. // File:src/extras/helpers/SpotLightHelper.js
  20526. /**
  20527. * @author alteredq / http://alteredqualia.com/
  20528. * @author mrdoob / http://mrdoob.com/
  20529. * @author WestLangley / http://github.com/WestLangley
  20530. */
  20531. THREE.SpotLightHelper = function ( light ) {
  20532. THREE.Object3D.call( this );
  20533. this.light = light;
  20534. this.light.updateMatrixWorld();
  20535. this.matrix = light.matrixWorld;
  20536. this.matrixAutoUpdate = false;
  20537. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  20538. geometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
  20539. geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
  20540. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  20541. this.cone = new THREE.Mesh( geometry, material );
  20542. this.add( this.cone );
  20543. this.update();
  20544. };
  20545. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  20546. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  20547. THREE.SpotLightHelper.prototype.dispose = function () {
  20548. this.cone.geometry.dispose();
  20549. this.cone.material.dispose();
  20550. };
  20551. THREE.SpotLightHelper.prototype.update = function () {
  20552. var vector = new THREE.Vector3();
  20553. var vector2 = new THREE.Vector3();
  20554. return function () {
  20555. var coneLength = this.light.distance ? this.light.distance : 10000;
  20556. var coneWidth = coneLength * Math.tan( this.light.angle );
  20557. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  20558. vector.setFromMatrixPosition( this.light.matrixWorld );
  20559. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  20560. this.cone.lookAt( vector2.sub( vector ) );
  20561. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20562. };
  20563. }();
  20564. // File:src/extras/helpers/VertexNormalsHelper.js
  20565. /**
  20566. * @author mrdoob / http://mrdoob.com/
  20567. * @author WestLangley / http://github.com/WestLangley
  20568. */
  20569. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  20570. this.object = object;
  20571. this.size = ( size !== undefined ) ? size : 1;
  20572. var color = ( hex !== undefined ) ? hex : 0xff0000;
  20573. var width = ( linewidth !== undefined ) ? linewidth : 1;
  20574. var geometry = new THREE.Geometry();
  20575. var faces = object.geometry.faces;
  20576. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20577. var face = faces[ i ];
  20578. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  20579. geometry.vertices.push( new THREE.Vector3(), new THREE.Vector3() );
  20580. }
  20581. }
  20582. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  20583. this.matrixAutoUpdate = false;
  20584. this.normalMatrix = new THREE.Matrix3();
  20585. this.update();
  20586. };
  20587. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20588. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  20589. THREE.VertexNormalsHelper.prototype.update = ( function ( object ) {
  20590. var v1 = new THREE.Vector3();
  20591. return function( object ) {
  20592. var keys = [ 'a', 'b', 'c', 'd' ];
  20593. this.object.updateMatrixWorld( true );
  20594. this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
  20595. var vertices = this.geometry.vertices;
  20596. var verts = this.object.geometry.vertices;
  20597. var faces = this.object.geometry.faces;
  20598. var worldMatrix = this.object.matrixWorld;
  20599. var idx = 0;
  20600. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20601. var face = faces[ i ];
  20602. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  20603. var vertexId = face[ keys[ j ] ];
  20604. var vertex = verts[ vertexId ];
  20605. var normal = face.vertexNormals[ j ];
  20606. vertices[ idx ].copy( vertex ).applyMatrix4( worldMatrix );
  20607. v1.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size );
  20608. v1.add( vertices[ idx ] );
  20609. idx = idx + 1;
  20610. vertices[ idx ].copy( v1 );
  20611. idx = idx + 1;
  20612. }
  20613. }
  20614. this.geometry.verticesNeedUpdate = true;
  20615. return this;
  20616. }
  20617. }());
  20618. // File:src/extras/helpers/VertexTangentsHelper.js
  20619. /**
  20620. * @author mrdoob / http://mrdoob.com/
  20621. * @author WestLangley / http://github.com/WestLangley
  20622. */
  20623. THREE.VertexTangentsHelper = function ( object, size, hex, linewidth ) {
  20624. this.object = object;
  20625. this.size = ( size !== undefined ) ? size : 1;
  20626. var color = ( hex !== undefined ) ? hex : 0x0000ff;
  20627. var width = ( linewidth !== undefined ) ? linewidth : 1;
  20628. var geometry = new THREE.Geometry();
  20629. var faces = object.geometry.faces;
  20630. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20631. var face = faces[ i ];
  20632. for ( var j = 0, jl = face.vertexTangents.length; j < jl; j ++ ) {
  20633. geometry.vertices.push( new THREE.Vector3() );
  20634. geometry.vertices.push( new THREE.Vector3() );
  20635. }
  20636. }
  20637. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  20638. this.matrixAutoUpdate = false;
  20639. this.update();
  20640. };
  20641. THREE.VertexTangentsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20642. THREE.VertexTangentsHelper.prototype.constructor = THREE.VertexTangentsHelper;
  20643. THREE.VertexTangentsHelper.prototype.update = ( function ( object ) {
  20644. var v1 = new THREE.Vector3();
  20645. return function( object ) {
  20646. var keys = [ 'a', 'b', 'c', 'd' ];
  20647. this.object.updateMatrixWorld( true );
  20648. var vertices = this.geometry.vertices;
  20649. var verts = this.object.geometry.vertices;
  20650. var faces = this.object.geometry.faces;
  20651. var worldMatrix = this.object.matrixWorld;
  20652. var idx = 0;
  20653. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20654. var face = faces[ i ];
  20655. for ( var j = 0, jl = face.vertexTangents.length; j < jl; j ++ ) {
  20656. var vertexId = face[ keys[ j ] ];
  20657. var vertex = verts[ vertexId ];
  20658. var tangent = face.vertexTangents[ j ];
  20659. vertices[ idx ].copy( vertex ).applyMatrix4( worldMatrix );
  20660. v1.copy( tangent ).transformDirection( worldMatrix ).multiplyScalar( this.size );
  20661. v1.add( vertices[ idx ] );
  20662. idx = idx + 1;
  20663. vertices[ idx ].copy( v1 );
  20664. idx = idx + 1;
  20665. }
  20666. }
  20667. this.geometry.verticesNeedUpdate = true;
  20668. return this;
  20669. }
  20670. }());
  20671. // File:src/extras/helpers/WireframeHelper.js
  20672. /**
  20673. * @author mrdoob / http://mrdoob.com/
  20674. */
  20675. THREE.WireframeHelper = function ( object, hex ) {
  20676. var color = ( hex !== undefined ) ? hex : 0xffffff;
  20677. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  20678. this.matrix = object.matrixWorld;
  20679. this.matrixAutoUpdate = false;
  20680. };
  20681. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20682. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  20683. // File:src/extras/objects/ImmediateRenderObject.js
  20684. /**
  20685. * @author alteredq / http://alteredqualia.com/
  20686. */
  20687. THREE.ImmediateRenderObject = function () {
  20688. THREE.Object3D.call( this );
  20689. this.render = function ( renderCallback ) {};
  20690. };
  20691. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  20692. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  20693. // File:src/extras/objects/MorphBlendMesh.js
  20694. /**
  20695. * @author alteredq / http://alteredqualia.com/
  20696. */
  20697. THREE.MorphBlendMesh = function( geometry, material ) {
  20698. THREE.Mesh.call( this, geometry, material );
  20699. this.animationsMap = {};
  20700. this.animationsList = [];
  20701. // prepare default animation
  20702. // (all frames played together in 1 second)
  20703. var numFrames = this.geometry.morphTargets.length;
  20704. var name = "__default";
  20705. var startFrame = 0;
  20706. var endFrame = numFrames - 1;
  20707. var fps = numFrames / 1;
  20708. this.createAnimation( name, startFrame, endFrame, fps );
  20709. this.setAnimationWeight( name, 1 );
  20710. };
  20711. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  20712. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  20713. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  20714. var animation = {
  20715. startFrame: start,
  20716. endFrame: end,
  20717. length: end - start + 1,
  20718. fps: fps,
  20719. duration: ( end - start ) / fps,
  20720. lastFrame: 0,
  20721. currentFrame: 0,
  20722. active: false,
  20723. time: 0,
  20724. direction: 1,
  20725. weight: 1,
  20726. directionBackwards: false,
  20727. mirroredLoop: false
  20728. };
  20729. this.animationsMap[ name ] = animation;
  20730. this.animationsList.push( animation );
  20731. };
  20732. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  20733. var pattern = /([a-z]+)_?(\d+)/;
  20734. var firstAnimation, frameRanges = {};
  20735. var geometry = this.geometry;
  20736. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  20737. var morph = geometry.morphTargets[ i ];
  20738. var chunks = morph.name.match( pattern );
  20739. if ( chunks && chunks.length > 1 ) {
  20740. var name = chunks[ 1 ];
  20741. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  20742. var range = frameRanges[ name ];
  20743. if ( i < range.start ) range.start = i;
  20744. if ( i > range.end ) range.end = i;
  20745. if ( ! firstAnimation ) firstAnimation = name;
  20746. }
  20747. }
  20748. for ( var name in frameRanges ) {
  20749. var range = frameRanges[ name ];
  20750. this.createAnimation( name, range.start, range.end, fps );
  20751. }
  20752. this.firstAnimation = firstAnimation;
  20753. };
  20754. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  20755. var animation = this.animationsMap[ name ];
  20756. if ( animation ) {
  20757. animation.direction = 1;
  20758. animation.directionBackwards = false;
  20759. }
  20760. };
  20761. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  20762. var animation = this.animationsMap[ name ];
  20763. if ( animation ) {
  20764. animation.direction = - 1;
  20765. animation.directionBackwards = true;
  20766. }
  20767. };
  20768. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  20769. var animation = this.animationsMap[ name ];
  20770. if ( animation ) {
  20771. animation.fps = fps;
  20772. animation.duration = ( animation.end - animation.start ) / animation.fps;
  20773. }
  20774. };
  20775. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  20776. var animation = this.animationsMap[ name ];
  20777. if ( animation ) {
  20778. animation.duration = duration;
  20779. animation.fps = ( animation.end - animation.start ) / animation.duration;
  20780. }
  20781. };
  20782. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  20783. var animation = this.animationsMap[ name ];
  20784. if ( animation ) {
  20785. animation.weight = weight;
  20786. }
  20787. };
  20788. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  20789. var animation = this.animationsMap[ name ];
  20790. if ( animation ) {
  20791. animation.time = time;
  20792. }
  20793. };
  20794. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  20795. var time = 0;
  20796. var animation = this.animationsMap[ name ];
  20797. if ( animation ) {
  20798. time = animation.time;
  20799. }
  20800. return time;
  20801. };
  20802. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  20803. var duration = - 1;
  20804. var animation = this.animationsMap[ name ];
  20805. if ( animation ) {
  20806. duration = animation.duration;
  20807. }
  20808. return duration;
  20809. };
  20810. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  20811. var animation = this.animationsMap[ name ];
  20812. if ( animation ) {
  20813. animation.time = 0;
  20814. animation.active = true;
  20815. } else {
  20816. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  20817. }
  20818. };
  20819. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  20820. var animation = this.animationsMap[ name ];
  20821. if ( animation ) {
  20822. animation.active = false;
  20823. }
  20824. };
  20825. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  20826. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  20827. var animation = this.animationsList[ i ];
  20828. if ( ! animation.active ) continue;
  20829. var frameTime = animation.duration / animation.length;
  20830. animation.time += animation.direction * delta;
  20831. if ( animation.mirroredLoop ) {
  20832. if ( animation.time > animation.duration || animation.time < 0 ) {
  20833. animation.direction *= - 1;
  20834. if ( animation.time > animation.duration ) {
  20835. animation.time = animation.duration;
  20836. animation.directionBackwards = true;
  20837. }
  20838. if ( animation.time < 0 ) {
  20839. animation.time = 0;
  20840. animation.directionBackwards = false;
  20841. }
  20842. }
  20843. } else {
  20844. animation.time = animation.time % animation.duration;
  20845. if ( animation.time < 0 ) animation.time += animation.duration;
  20846. }
  20847. var keyframe = animation.startFrame + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  20848. var weight = animation.weight;
  20849. if ( keyframe !== animation.currentFrame ) {
  20850. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  20851. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  20852. this.morphTargetInfluences[ keyframe ] = 0;
  20853. animation.lastFrame = animation.currentFrame;
  20854. animation.currentFrame = keyframe;
  20855. }
  20856. var mix = ( animation.time % frameTime ) / frameTime;
  20857. if ( animation.directionBackwards ) mix = 1 - mix;
  20858. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  20859. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  20860. }
  20861. };
粤ICP备19079148号