ThreeCanvas.js 158 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954
  1. /**
  2. * @author mr.doob / http://mrdoob.com/
  3. */
  4. var THREE = THREE || { REVISION: '49dev' };
  5. if ( ! self.Int32Array ) {
  6. self.Int32Array = Array;
  7. self.Float32Array = Array;
  8. }
  9. // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
  10. // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
  11. // requestAnimationFrame polyfill by Erik Möller
  12. // fixes from Paul Irish and Tino Zijdel
  13. ( function () {
  14. var lastTime = 0;
  15. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  16. for ( var x = 0; x < vendors.length && !window.requestAnimationFrame; ++ x ) {
  17. window.requestAnimationFrame = window[ vendors[ x ] + 'RequestAnimationFrame' ];
  18. window.cancelAnimationFrame = window[ vendors[ x ] + 'CancelAnimationFrame' ] || window[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  19. }
  20. if ( !window.requestAnimationFrame ) {
  21. window.requestAnimationFrame = function ( callback, element ) {
  22. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  23. var id = window.setTimeout( function() { callback( currTime + timeToCall ); }, timeToCall );
  24. lastTime = currTime + timeToCall;
  25. return id;
  26. };
  27. }
  28. if ( !window.cancelAnimationFrame ) {
  29. window.cancelAnimationFrame = function ( id ) { clearTimeout( id ); };
  30. }
  31. }() );
  32. /**
  33. * @author mr.doob / http://mrdoob.com/
  34. */
  35. THREE.Color = function ( hex ) {
  36. if ( hex !== undefined ) this.setHex( hex );
  37. return this;
  38. };
  39. THREE.Color.prototype = {
  40. constructor: THREE.Color,
  41. r: 1, g: 1, b: 1,
  42. copy: function ( color ) {
  43. this.r = color.r;
  44. this.g = color.g;
  45. this.b = color.b;
  46. return this;
  47. },
  48. copyGammaToLinear: function ( color ) {
  49. this.r = color.r * color.r;
  50. this.g = color.g * color.g;
  51. this.b = color.b * color.b;
  52. return this;
  53. },
  54. copyLinearToGamma: function ( color ) {
  55. this.r = Math.sqrt( color.r );
  56. this.g = Math.sqrt( color.g );
  57. this.b = Math.sqrt( color.b );
  58. return this;
  59. },
  60. convertGammaToLinear: function () {
  61. var r = this.r, g = this.g, b = this.b;
  62. this.r = r * r;
  63. this.g = g * g;
  64. this.b = b * b;
  65. return this;
  66. },
  67. convertLinearToGamma: function () {
  68. this.r = Math.sqrt( this.r );
  69. this.g = Math.sqrt( this.g );
  70. this.b = Math.sqrt( this.b );
  71. return this;
  72. },
  73. setRGB: function ( r, g, b ) {
  74. this.r = r;
  75. this.g = g;
  76. this.b = b;
  77. return this;
  78. },
  79. setHSV: function ( h, s, v ) {
  80. // based on MochiKit implementation by Bob Ippolito
  81. // h,s,v ranges are < 0.0 - 1.0 >
  82. var i, f, p, q, t;
  83. if ( v === 0 ) {
  84. this.r = this.g = this.b = 0;
  85. } else {
  86. i = Math.floor( h * 6 );
  87. f = ( h * 6 ) - i;
  88. p = v * ( 1 - s );
  89. q = v * ( 1 - ( s * f ) );
  90. t = v * ( 1 - ( s * ( 1 - f ) ) );
  91. switch ( i ) {
  92. case 1: this.r = q; this.g = v; this.b = p; break;
  93. case 2: this.r = p; this.g = v; this.b = t; break;
  94. case 3: this.r = p; this.g = q; this.b = v; break;
  95. case 4: this.r = t; this.g = p; this.b = v; break;
  96. case 5: this.r = v; this.g = p; this.b = q; break;
  97. case 6: // fall through
  98. case 0: this.r = v; this.g = t; this.b = p; break;
  99. }
  100. }
  101. return this;
  102. },
  103. setHex: function ( hex ) {
  104. hex = Math.floor( hex );
  105. this.r = ( hex >> 16 & 255 ) / 255;
  106. this.g = ( hex >> 8 & 255 ) / 255;
  107. this.b = ( hex & 255 ) / 255;
  108. return this;
  109. },
  110. lerpSelf: function ( color, alpha ) {
  111. this.r += ( color.r - this.r ) * alpha;
  112. this.g += ( color.g - this.g ) * alpha;
  113. this.b += ( color.b - this.b ) * alpha;
  114. return this;
  115. },
  116. getHex: function () {
  117. return Math.floor( this.r * 255 ) << 16 ^ Math.floor( this.g * 255 ) << 8 ^ Math.floor( this.b * 255 );
  118. },
  119. getContextStyle: function () {
  120. return 'rgb(' + Math.floor( this.r * 255 ) + ',' + Math.floor( this.g * 255 ) + ',' + Math.floor( this.b * 255 ) + ')';
  121. },
  122. clone: function () {
  123. return new THREE.Color().setRGB( this.r, this.g, this.b );
  124. }
  125. };
  126. /**
  127. * @author mr.doob / http://mrdoob.com/
  128. * @author philogb / http://blog.thejit.org/
  129. * @author egraether / http://egraether.com/
  130. * @author zz85 / http://www.lab4games.net/zz85/blog
  131. */
  132. THREE.Vector2 = function ( x, y ) {
  133. this.x = x || 0;
  134. this.y = y || 0;
  135. };
  136. THREE.Vector2.prototype = {
  137. constructor: THREE.Vector2,
  138. set: function ( x, y ) {
  139. this.x = x;
  140. this.y = y;
  141. return this;
  142. },
  143. copy: function ( v ) {
  144. this.x = v.x;
  145. this.y = v.y;
  146. return this;
  147. },
  148. add: function ( a, b ) {
  149. this.x = a.x + b.x;
  150. this.y = a.y + b.y;
  151. return this;
  152. },
  153. addSelf: function ( v ) {
  154. this.x += v.x;
  155. this.y += v.y;
  156. return this;
  157. },
  158. sub: function ( a, b ) {
  159. this.x = a.x - b.x;
  160. this.y = a.y - b.y;
  161. return this;
  162. },
  163. subSelf: function ( v ) {
  164. this.x -= v.x;
  165. this.y -= v.y;
  166. return this;
  167. },
  168. multiplyScalar: function ( s ) {
  169. this.x *= s;
  170. this.y *= s;
  171. return this;
  172. },
  173. divideScalar: function ( s ) {
  174. if ( s ) {
  175. this.x /= s;
  176. this.y /= s;
  177. } else {
  178. this.set( 0, 0 );
  179. }
  180. return this;
  181. },
  182. negate: function() {
  183. return this.multiplyScalar( - 1 );
  184. },
  185. dot: function ( v ) {
  186. return this.x * v.x + this.y * v.y;
  187. },
  188. lengthSq: function () {
  189. return this.x * this.x + this.y * this.y;
  190. },
  191. length: function () {
  192. return Math.sqrt( this.lengthSq() );
  193. },
  194. normalize: function () {
  195. return this.divideScalar( this.length() );
  196. },
  197. distanceTo: function ( v ) {
  198. return Math.sqrt( this.distanceToSquared( v ) );
  199. },
  200. distanceToSquared: function ( v ) {
  201. var dx = this.x - v.x, dy = this.y - v.y;
  202. return dx * dx + dy * dy;
  203. },
  204. setLength: function ( l ) {
  205. return this.normalize().multiplyScalar( l );
  206. },
  207. lerpSelf: function ( v, alpha ) {
  208. this.x += ( v.x - this.x ) * alpha;
  209. this.y += ( v.y - this.y ) * alpha;
  210. return this;
  211. },
  212. equals: function( v ) {
  213. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  214. },
  215. isZero: function () {
  216. return ( this.lengthSq() < 0.0001 /* almostZero */ );
  217. },
  218. clone: function () {
  219. return new THREE.Vector2( this.x, this.y );
  220. }
  221. };
  222. /**
  223. * @author mr.doob / http://mrdoob.com/
  224. * @author kile / http://kile.stravaganza.org/
  225. * @author philogb / http://blog.thejit.org/
  226. * @author mikael emtinger / http://gomo.se/
  227. * @author egraether / http://egraether.com/
  228. */
  229. THREE.Vector3 = function ( x, y, z ) {
  230. this.x = x || 0;
  231. this.y = y || 0;
  232. this.z = z || 0;
  233. };
  234. THREE.Vector3.prototype = {
  235. constructor: THREE.Vector3,
  236. set: function ( x, y, z ) {
  237. this.x = x;
  238. this.y = y;
  239. this.z = z;
  240. return this;
  241. },
  242. setX: function ( x ) {
  243. this.x = x;
  244. return this;
  245. },
  246. setY: function ( y ) {
  247. this.y = y;
  248. return this;
  249. },
  250. setZ: function ( z ) {
  251. this.z = z;
  252. return this;
  253. },
  254. copy: function ( v ) {
  255. this.x = v.x;
  256. this.y = v.y;
  257. this.z = v.z;
  258. return this;
  259. },
  260. add: function ( a, b ) {
  261. this.x = a.x + b.x;
  262. this.y = a.y + b.y;
  263. this.z = a.z + b.z;
  264. return this;
  265. },
  266. addSelf: function ( v ) {
  267. this.x += v.x;
  268. this.y += v.y;
  269. this.z += v.z;
  270. return this;
  271. },
  272. addScalar: function ( s ) {
  273. this.x += s;
  274. this.y += s;
  275. this.z += s;
  276. return this;
  277. },
  278. sub: function ( a, b ) {
  279. this.x = a.x - b.x;
  280. this.y = a.y - b.y;
  281. this.z = a.z - b.z;
  282. return this;
  283. },
  284. subSelf: function ( v ) {
  285. this.x -= v.x;
  286. this.y -= v.y;
  287. this.z -= v.z;
  288. return this;
  289. },
  290. multiply: function ( a, b ) {
  291. this.x = a.x * b.x;
  292. this.y = a.y * b.y;
  293. this.z = a.z * b.z;
  294. return this;
  295. },
  296. multiplySelf: function ( v ) {
  297. this.x *= v.x;
  298. this.y *= v.y;
  299. this.z *= v.z;
  300. return this;
  301. },
  302. multiplyScalar: function ( s ) {
  303. this.x *= s;
  304. this.y *= s;
  305. this.z *= s;
  306. return this;
  307. },
  308. divideSelf: function ( v ) {
  309. this.x /= v.x;
  310. this.y /= v.y;
  311. this.z /= v.z;
  312. return this;
  313. },
  314. divideScalar: function ( s ) {
  315. if ( s ) {
  316. this.x /= s;
  317. this.y /= s;
  318. this.z /= s;
  319. } else {
  320. this.x = 0;
  321. this.y = 0;
  322. this.z = 0;
  323. }
  324. return this;
  325. },
  326. negate: function() {
  327. return this.multiplyScalar( - 1 );
  328. },
  329. dot: function ( v ) {
  330. return this.x * v.x + this.y * v.y + this.z * v.z;
  331. },
  332. lengthSq: function () {
  333. return this.x * this.x + this.y * this.y + this.z * this.z;
  334. },
  335. length: function () {
  336. return Math.sqrt( this.lengthSq() );
  337. },
  338. lengthManhattan: function () {
  339. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  340. },
  341. normalize: function () {
  342. return this.divideScalar( this.length() );
  343. },
  344. setLength: function ( l ) {
  345. return this.normalize().multiplyScalar( l );
  346. },
  347. lerpSelf: function ( v, alpha ) {
  348. this.x += ( v.x - this.x ) * alpha;
  349. this.y += ( v.y - this.y ) * alpha;
  350. this.z += ( v.z - this.z ) * alpha;
  351. return this;
  352. },
  353. cross: function ( a, b ) {
  354. this.x = a.y * b.z - a.z * b.y;
  355. this.y = a.z * b.x - a.x * b.z;
  356. this.z = a.x * b.y - a.y * b.x;
  357. return this;
  358. },
  359. crossSelf: function ( v ) {
  360. var x = this.x, y = this.y, z = this.z;
  361. this.x = y * v.z - z * v.y;
  362. this.y = z * v.x - x * v.z;
  363. this.z = x * v.y - y * v.x;
  364. return this;
  365. },
  366. distanceTo: function ( v ) {
  367. return Math.sqrt( this.distanceToSquared( v ) );
  368. },
  369. distanceToSquared: function ( v ) {
  370. return new THREE.Vector3().sub( this, v ).lengthSq();
  371. },
  372. getPositionFromMatrix: function ( m ) {
  373. this.x = m.elements[12];
  374. this.y = m.elements[13];
  375. this.z = m.elements[14];
  376. return this;
  377. },
  378. getRotationFromMatrix: function ( m, scale ) {
  379. var sx = scale ? scale.x : 1;
  380. var sy = scale ? scale.y : 1;
  381. var sz = scale ? scale.z : 1;
  382. var m11 = m.elements[0] / sx, m12 = m.elements[4] / sy, m13 = m.elements[8] / sz;
  383. var m21 = m.elements[1] / sx, m22 = m.elements[5] / sy, m23 = m.elements[9] / sz;
  384. var m33 = m.elements[10] / sz;
  385. this.y = Math.asin( m13 );
  386. var cosY = Math.cos( this.y );
  387. if ( Math.abs( cosY ) > 0.00001 ) {
  388. this.x = Math.atan2( - m23 / cosY, m33 / cosY );
  389. this.z = Math.atan2( - m12 / cosY, m11 / cosY );
  390. } else {
  391. this.x = 0;
  392. this.z = Math.atan2( m21, m22 );
  393. }
  394. return this;
  395. },
  396. /*
  397. // from http://www.mathworks.com/matlabcentral/fileexchange/20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/content/SpinCalc.m
  398. // order XYZ
  399. getEulerXYZFromQuaternion: function ( q ) {
  400. this.x = Math.atan2( 2 * ( q.x * q.w - q.y * q.z ), ( q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z ) );
  401. this.y = Math.asin( 2 * ( q.x * q.z + q.y * q.w ) );
  402. this.z = Math.atan2( 2 * ( q.z * q.w - q.x * q.y ), ( q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z ) );
  403. },
  404. // from http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm
  405. // order YZX (assuming heading == y, attitude == z, bank == x)
  406. getEulerYZXFromQuaternion: function ( q ) {
  407. var sqw = q.w * q.w;
  408. var sqx = q.x * q.x;
  409. var sqy = q.y * q.y;
  410. var sqz = q.z * q.z;
  411. var unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
  412. var test = q.x * q.y + q.z * q.w;
  413. if ( test > 0.499 * unit ) { // singularity at north pole
  414. this.y = 2 * Math.atan2( q.x, q.w );
  415. this.z = Math.PI / 2;
  416. this.x = 0;
  417. return;
  418. }
  419. if ( test < -0.499 * unit ) { // singularity at south pole
  420. this.y = -2 * Math.atan2( q.x, q.w );
  421. this.z = -Math.PI / 2;
  422. this.x = 0;
  423. return;
  424. }
  425. this.y = Math.atan2( 2 * q.y * q.w - 2 * q.x * q.z, sqx - sqy - sqz + sqw );
  426. this.z = Math.asin( 2 * test / unit );
  427. this.x = Math.atan2( 2 * q.x * q.w - 2 * q.y * q.z, -sqx + sqy - sqz + sqw );
  428. },
  429. */
  430. getScaleFromMatrix: function ( m ) {
  431. var sx = this.set( m.elements[0], m.elements[1], m.elements[2] ).length();
  432. var sy = this.set( m.elements[4], m.elements[5], m.elements[6] ).length();
  433. var sz = this.set( m.elements[8], m.elements[9], m.elements[10] ).length();
  434. this.x = sx;
  435. this.y = sy;
  436. this.z = sz;
  437. },
  438. equals: function ( v ) {
  439. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  440. },
  441. isZero: function () {
  442. return ( this.lengthSq() < 0.0001 /* almostZero */ );
  443. },
  444. clone: function () {
  445. return new THREE.Vector3( this.x, this.y, this.z );
  446. }
  447. };
  448. /**
  449. * @author supereggbert / http://www.paulbrunt.co.uk/
  450. * @author philogb / http://blog.thejit.org/
  451. * @author mikael emtinger / http://gomo.se/
  452. * @author egraether / http://egraether.com/
  453. */
  454. THREE.Vector4 = function ( x, y, z, w ) {
  455. this.x = x || 0;
  456. this.y = y || 0;
  457. this.z = z || 0;
  458. this.w = ( w !== undefined ) ? w : 1;
  459. };
  460. THREE.Vector4.prototype = {
  461. constructor: THREE.Vector4,
  462. set: function ( x, y, z, w ) {
  463. this.x = x;
  464. this.y = y;
  465. this.z = z;
  466. this.w = w;
  467. return this;
  468. },
  469. copy: function ( v ) {
  470. this.x = v.x;
  471. this.y = v.y;
  472. this.z = v.z;
  473. this.w = ( v.w !== undefined ) ? v.w : 1;
  474. return this;
  475. },
  476. add: function ( a, b ) {
  477. this.x = a.x + b.x;
  478. this.y = a.y + b.y;
  479. this.z = a.z + b.z;
  480. this.w = a.w + b.w;
  481. return this;
  482. },
  483. addSelf: function ( v ) {
  484. this.x += v.x;
  485. this.y += v.y;
  486. this.z += v.z;
  487. this.w += v.w;
  488. return this;
  489. },
  490. sub: function ( a, b ) {
  491. this.x = a.x - b.x;
  492. this.y = a.y - b.y;
  493. this.z = a.z - b.z;
  494. this.w = a.w - b.w;
  495. return this;
  496. },
  497. subSelf: function ( v ) {
  498. this.x -= v.x;
  499. this.y -= v.y;
  500. this.z -= v.z;
  501. this.w -= v.w;
  502. return this;
  503. },
  504. multiplyScalar: function ( s ) {
  505. this.x *= s;
  506. this.y *= s;
  507. this.z *= s;
  508. this.w *= s;
  509. return this;
  510. },
  511. divideScalar: function ( s ) {
  512. if ( s ) {
  513. this.x /= s;
  514. this.y /= s;
  515. this.z /= s;
  516. this.w /= s;
  517. } else {
  518. this.x = 0;
  519. this.y = 0;
  520. this.z = 0;
  521. this.w = 1;
  522. }
  523. return this;
  524. },
  525. negate: function() {
  526. return this.multiplyScalar( -1 );
  527. },
  528. dot: function ( v ) {
  529. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  530. },
  531. lengthSq: function () {
  532. return this.dot( this );
  533. },
  534. length: function () {
  535. return Math.sqrt( this.lengthSq() );
  536. },
  537. normalize: function () {
  538. return this.divideScalar( this.length() );
  539. },
  540. setLength: function ( l ) {
  541. return this.normalize().multiplyScalar( l );
  542. },
  543. lerpSelf: function ( v, alpha ) {
  544. this.x += ( v.x - this.x ) * alpha;
  545. this.y += ( v.y - this.y ) * alpha;
  546. this.z += ( v.z - this.z ) * alpha;
  547. this.w += ( v.w - this.w ) * alpha;
  548. return this;
  549. },
  550. clone: function () {
  551. return new THREE.Vector4( this.x, this.y, this.z, this.w );
  552. }
  553. };
  554. /**
  555. * @author mrdoob / http://mrdoob.com/
  556. * @author alteredq / http://alteredqualia.com/
  557. */
  558. THREE.Frustum = function ( ) {
  559. this.planes = [
  560. new THREE.Vector4(),
  561. new THREE.Vector4(),
  562. new THREE.Vector4(),
  563. new THREE.Vector4(),
  564. new THREE.Vector4(),
  565. new THREE.Vector4()
  566. ];
  567. };
  568. THREE.Frustum.prototype.setFromMatrix = function ( m ) {
  569. var i, plane,
  570. planes = this.planes;
  571. var me = m.elements;
  572. var me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3];
  573. var me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7];
  574. var me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11];
  575. var me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15];
  576. planes[ 0 ].set( me3 - me0, me7 - me4, me11 - me8, me15 - me12 );
  577. planes[ 1 ].set( me3 + me0, me7 + me4, me11 + me8, me15 + me12 );
  578. planes[ 2 ].set( me3 + me1, me7 + me5, me11 + me9, me15 + me13 );
  579. planes[ 3 ].set( me3 - me1, me7 - me5, me11 - me9, me15 - me13 );
  580. planes[ 4 ].set( me3 - me2, me7 - me6, me11 - me10, me15 - me14 );
  581. planes[ 5 ].set( me3 + me2, me7 + me6, me11 + me10, me15 + me14 );
  582. for ( i = 0; i < 6; i ++ ) {
  583. plane = planes[ i ];
  584. plane.divideScalar( Math.sqrt( plane.x * plane.x + plane.y * plane.y + plane.z * plane.z ) );
  585. }
  586. };
  587. THREE.Frustum.prototype.contains = function ( object ) {
  588. var distance,
  589. planes = this.planes,
  590. matrix = object.matrixWorld,
  591. me = matrix.elements,
  592. scale = THREE.Frustum.__v1.set( matrix.getColumnX().length(), matrix.getColumnY().length(), matrix.getColumnZ().length() ),
  593. radius = - object.geometry.boundingSphere.radius * Math.max( scale.x, Math.max( scale.y, scale.z ) );
  594. for ( var i = 0; i < 6; i ++ ) {
  595. distance = planes[ i ].x * me[12] + planes[ i ].y * me[13] + planes[ i ].z * me[14] + planes[ i ].w;
  596. if ( distance <= radius ) return false;
  597. }
  598. return true;
  599. };
  600. THREE.Frustum.__v1 = new THREE.Vector3();
  601. /**
  602. * @author mr.doob / http://mrdoob.com/
  603. */
  604. THREE.Ray = function ( origin, direction ) {
  605. this.origin = origin || new THREE.Vector3();
  606. this.direction = direction || new THREE.Vector3();
  607. var precision = 0.0001;
  608. this.setPrecision = function ( value ) {
  609. precision = value;
  610. };
  611. var a = new THREE.Vector3();
  612. var b = new THREE.Vector3();
  613. var c = new THREE.Vector3();
  614. var d = new THREE.Vector3();
  615. var originCopy = new THREE.Vector3();
  616. var directionCopy = new THREE.Vector3();
  617. var vector = new THREE.Vector3();
  618. var normal = new THREE.Vector3();
  619. var intersectPoint = new THREE.Vector3()
  620. this.intersectObject = function ( object ) {
  621. var intersect, intersects = [];
  622. if ( object instanceof THREE.Particle ) {
  623. var distance = distanceFromIntersection( this.origin, this.direction, object.matrixWorld.getPosition() );
  624. if ( distance > object.scale.x ) {
  625. return [];
  626. }
  627. intersect = {
  628. distance: distance,
  629. point: object.position,
  630. face: null,
  631. object: object
  632. };
  633. intersects.push( intersect );
  634. } else if ( object instanceof THREE.Mesh ) {
  635. // Checking boundingSphere
  636. var distance = distanceFromIntersection( this.origin, this.direction, object.matrixWorld.getPosition() );
  637. var scale = THREE.Frustum.__v1.set( object.matrixWorld.getColumnX().length(), object.matrixWorld.getColumnY().length(), object.matrixWorld.getColumnZ().length() );
  638. if ( distance > object.geometry.boundingSphere.radius * Math.max( scale.x, Math.max( scale.y, scale.z ) ) ) {
  639. return intersects;
  640. }
  641. // Checking faces
  642. var f, fl, face, dot, scalar,
  643. geometry = object.geometry,
  644. vertices = geometry.vertices,
  645. objMatrix;
  646. object.matrixRotationWorld.extractRotation( object.matrixWorld );
  647. for ( f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
  648. face = geometry.faces[ f ];
  649. originCopy.copy( this.origin );
  650. directionCopy.copy( this.direction );
  651. objMatrix = object.matrixWorld;
  652. // determine if ray intersects the plane of the face
  653. // note: this works regardless of the direction of the face normal
  654. vector = objMatrix.multiplyVector3( vector.copy( face.centroid ) ).subSelf( originCopy );
  655. normal = object.matrixRotationWorld.multiplyVector3( normal.copy( face.normal ) );
  656. dot = directionCopy.dot( normal );
  657. // bail if ray and plane are parallel
  658. if ( Math.abs( dot ) < precision ) continue;
  659. // calc distance to plane
  660. scalar = normal.dot( vector ) / dot;
  661. // if negative distance, then plane is behind ray
  662. if ( scalar < 0 ) continue;
  663. if ( object.doubleSided || ( object.flipSided ? dot > 0 : dot < 0 ) ) {
  664. intersectPoint.add( originCopy, directionCopy.multiplyScalar( scalar ) );
  665. if ( face instanceof THREE.Face3 ) {
  666. a = objMatrix.multiplyVector3( a.copy( vertices[ face.a ] ) );
  667. b = objMatrix.multiplyVector3( b.copy( vertices[ face.b ] ) );
  668. c = objMatrix.multiplyVector3( c.copy( vertices[ face.c ] ) );
  669. if ( pointInFace3( intersectPoint, a, b, c ) ) {
  670. intersect = {
  671. distance: originCopy.distanceTo( intersectPoint ),
  672. point: intersectPoint.clone(),
  673. face: face,
  674. object: object
  675. };
  676. intersects.push( intersect );
  677. }
  678. } else if ( face instanceof THREE.Face4 ) {
  679. a = objMatrix.multiplyVector3( a.copy( vertices[ face.a ] ) );
  680. b = objMatrix.multiplyVector3( b.copy( vertices[ face.b ] ) );
  681. c = objMatrix.multiplyVector3( c.copy( vertices[ face.c ] ) );
  682. d = objMatrix.multiplyVector3( d.copy( vertices[ face.d ] ) );
  683. if ( pointInFace3( intersectPoint, a, b, d ) || pointInFace3( intersectPoint, b, c, d ) ) {
  684. intersect = {
  685. distance: originCopy.distanceTo( intersectPoint ),
  686. point: intersectPoint.clone(),
  687. face: face,
  688. object: object
  689. };
  690. intersects.push( intersect );
  691. }
  692. }
  693. }
  694. }
  695. }
  696. return intersects;
  697. }
  698. this.intersectObjects = function ( objects ) {
  699. var intersects = [];
  700. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  701. Array.prototype.push.apply( intersects, this.intersectObject( objects[ i ] ) );
  702. }
  703. intersects.sort( function ( a, b ) { return a.distance - b.distance; } );
  704. return intersects;
  705. };
  706. var v0 = new THREE.Vector3(), v1 = new THREE.Vector3(), v2 = new THREE.Vector3();
  707. var dot, intersect, distance;
  708. function distanceFromIntersection( origin, direction, position ) {
  709. v0.sub( position, origin );
  710. dot = v0.dot( direction );
  711. intersect = v1.add( origin, v2.copy( direction ).multiplyScalar( dot ) );
  712. distance = position.distanceTo( intersect );
  713. return distance;
  714. }
  715. // http://www.blackpawn.com/texts/pointinpoly/default.html
  716. var dot00, dot01, dot02, dot11, dot12, invDenom, u, v;
  717. function pointInFace3( p, a, b, c ) {
  718. v0.sub( c, a );
  719. v1.sub( b, a );
  720. v2.sub( p, a );
  721. dot00 = v0.dot( v0 );
  722. dot01 = v0.dot( v1 );
  723. dot02 = v0.dot( v2 );
  724. dot11 = v1.dot( v1 );
  725. dot12 = v1.dot( v2 );
  726. invDenom = 1 / ( dot00 * dot11 - dot01 * dot01 );
  727. u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  728. v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  729. return ( u >= 0 ) && ( v >= 0 ) && ( u + v < 1 );
  730. }
  731. };
  732. /**
  733. * @author mr.doob / http://mrdoob.com/
  734. */
  735. THREE.Rectangle = function () {
  736. var _left, _top, _right, _bottom,
  737. _width, _height, _isEmpty = true;
  738. function resize() {
  739. _width = _right - _left;
  740. _height = _bottom - _top;
  741. }
  742. this.getX = function () {
  743. return _left;
  744. };
  745. this.getY = function () {
  746. return _top;
  747. };
  748. this.getWidth = function () {
  749. return _width;
  750. };
  751. this.getHeight = function () {
  752. return _height;
  753. };
  754. this.getLeft = function() {
  755. return _left;
  756. };
  757. this.getTop = function() {
  758. return _top;
  759. };
  760. this.getRight = function() {
  761. return _right;
  762. };
  763. this.getBottom = function() {
  764. return _bottom;
  765. };
  766. this.set = function ( left, top, right, bottom ) {
  767. _isEmpty = false;
  768. _left = left; _top = top;
  769. _right = right; _bottom = bottom;
  770. resize();
  771. };
  772. this.addPoint = function ( x, y ) {
  773. if ( _isEmpty ) {
  774. _isEmpty = false;
  775. _left = x; _top = y;
  776. _right = x; _bottom = y;
  777. resize();
  778. } else {
  779. _left = _left < x ? _left : x; // Math.min( _left, x );
  780. _top = _top < y ? _top : y; // Math.min( _top, y );
  781. _right = _right > x ? _right : x; // Math.max( _right, x );
  782. _bottom = _bottom > y ? _bottom : y; // Math.max( _bottom, y );
  783. resize();
  784. }
  785. };
  786. this.add3Points = function ( x1, y1, x2, y2, x3, y3 ) {
  787. if (_isEmpty) {
  788. _isEmpty = false;
  789. _left = x1 < x2 ? ( x1 < x3 ? x1 : x3 ) : ( x2 < x3 ? x2 : x3 );
  790. _top = y1 < y2 ? ( y1 < y3 ? y1 : y3 ) : ( y2 < y3 ? y2 : y3 );
  791. _right = x1 > x2 ? ( x1 > x3 ? x1 : x3 ) : ( x2 > x3 ? x2 : x3 );
  792. _bottom = y1 > y2 ? ( y1 > y3 ? y1 : y3 ) : ( y2 > y3 ? y2 : y3 );
  793. resize();
  794. } else {
  795. _left = x1 < x2 ? ( x1 < x3 ? ( x1 < _left ? x1 : _left ) : ( x3 < _left ? x3 : _left ) ) : ( x2 < x3 ? ( x2 < _left ? x2 : _left ) : ( x3 < _left ? x3 : _left ) );
  796. _top = y1 < y2 ? ( y1 < y3 ? ( y1 < _top ? y1 : _top ) : ( y3 < _top ? y3 : _top ) ) : ( y2 < y3 ? ( y2 < _top ? y2 : _top ) : ( y3 < _top ? y3 : _top ) );
  797. _right = x1 > x2 ? ( x1 > x3 ? ( x1 > _right ? x1 : _right ) : ( x3 > _right ? x3 : _right ) ) : ( x2 > x3 ? ( x2 > _right ? x2 : _right ) : ( x3 > _right ? x3 : _right ) );
  798. _bottom = y1 > y2 ? ( y1 > y3 ? ( y1 > _bottom ? y1 : _bottom ) : ( y3 > _bottom ? y3 : _bottom ) ) : ( y2 > y3 ? ( y2 > _bottom ? y2 : _bottom ) : ( y3 > _bottom ? y3 : _bottom ) );
  799. resize();
  800. };
  801. };
  802. this.addRectangle = function ( r ) {
  803. if ( _isEmpty ) {
  804. _isEmpty = false;
  805. _left = r.getLeft(); _top = r.getTop();
  806. _right = r.getRight(); _bottom = r.getBottom();
  807. resize();
  808. } else {
  809. _left = _left < r.getLeft() ? _left : r.getLeft(); // Math.min(_left, r.getLeft() );
  810. _top = _top < r.getTop() ? _top : r.getTop(); // Math.min(_top, r.getTop() );
  811. _right = _right > r.getRight() ? _right : r.getRight(); // Math.max(_right, r.getRight() );
  812. _bottom = _bottom > r.getBottom() ? _bottom : r.getBottom(); // Math.max(_bottom, r.getBottom() );
  813. resize();
  814. }
  815. };
  816. this.inflate = function ( v ) {
  817. _left -= v; _top -= v;
  818. _right += v; _bottom += v;
  819. resize();
  820. };
  821. this.minSelf = function ( r ) {
  822. _left = _left > r.getLeft() ? _left : r.getLeft(); // Math.max( _left, r.getLeft() );
  823. _top = _top > r.getTop() ? _top : r.getTop(); // Math.max( _top, r.getTop() );
  824. _right = _right < r.getRight() ? _right : r.getRight(); // Math.min( _right, r.getRight() );
  825. _bottom = _bottom < r.getBottom() ? _bottom : r.getBottom(); // Math.min( _bottom, r.getBottom() );
  826. resize();
  827. };
  828. this.intersects = function ( r ) {
  829. // http://gamemath.com/2011/09/detecting-whether-two-boxes-overlap/
  830. if ( _right < r.getLeft() ) return false;
  831. if ( _left > r.getRight() ) return false;
  832. if ( _bottom < r.getTop() ) return false;
  833. if ( _top > r.getBottom() ) return false;
  834. return true;
  835. };
  836. this.empty = function () {
  837. _isEmpty = true;
  838. _left = 0; _top = 0;
  839. _right = 0; _bottom = 0;
  840. resize();
  841. };
  842. this.isEmpty = function () {
  843. return _isEmpty;
  844. };
  845. };
  846. /**
  847. * @author alteredq / http://alteredqualia.com/
  848. */
  849. THREE.Math = {
  850. // Clamp value to range <a, b>
  851. clamp: function ( x, a, b ) {
  852. return ( x < a ) ? a : ( ( x > b ) ? b : x );
  853. },
  854. // Clamp value to range <a, inf)
  855. clampBottom: function ( x, a ) {
  856. return x < a ? a : x;
  857. },
  858. // Linear mapping from range <a1, a2> to range <b1, b2>
  859. mapLinear: function ( x, a1, a2, b1, b2 ) {
  860. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  861. },
  862. // Random float from <0, 1> with 16 bits of randomness
  863. // (standard Math.random() creates repetitive patterns when applied over larger space)
  864. random16: function () {
  865. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  866. },
  867. // Random integer from <low, high> interval
  868. randInt: function ( low, high ) {
  869. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  870. },
  871. // Random float from <low, high> interval
  872. randFloat: function ( low, high ) {
  873. return low + Math.random() * ( high - low );
  874. },
  875. // Random float from <-range/2, range/2> interval
  876. randFloatSpread: function ( range ) {
  877. return range * ( 0.5 - Math.random() );
  878. },
  879. sign: function ( x ) {
  880. return ( x < 0 ) ? -1 : ( ( x > 0 ) ? 1 : 0 );
  881. }
  882. };
  883. /**
  884. * @author alteredq / http://alteredqualia.com/
  885. */
  886. THREE.Matrix3 = function () {
  887. this.elements = new Float32Array(9);
  888. };
  889. THREE.Matrix3.prototype = {
  890. constructor: THREE.Matrix3,
  891. getInverse: function ( matrix ) {
  892. // input: THREE.Matrix4
  893. // ( based on http://code.google.com/p/webgl-mjs/ )
  894. var me = matrix.elements;
  895. var a11 = me[10] * me[5] - me[6] * me[9];
  896. var a21 = - me[10] * me[1] + me[2] * me[9];
  897. var a31 = me[6] * me[1] - me[2] * me[5];
  898. var a12 = - me[10] * me[4] + me[6] * me[8];
  899. var a22 = me[10] * me[0] - me[2] * me[8];
  900. var a32 = - me[6] * me[0] + me[2] * me[4];
  901. var a13 = me[9] * me[4] - me[5] * me[8];
  902. var a23 = - me[9] * me[0] + me[1] * me[8];
  903. var a33 = me[5] * me[0] - me[1] * me[4];
  904. var det = me[0] * a11 + me[1] * a12 + me[2] * a13;
  905. // no inverse
  906. if ( det === 0 ) {
  907. console.warn( "Matrix3.getInverse(): determinant == 0" );
  908. }
  909. var idet = 1.0 / det;
  910. var m = this.elements;
  911. m[ 0 ] = idet * a11; m[ 1 ] = idet * a21; m[ 2 ] = idet * a31;
  912. m[ 3 ] = idet * a12; m[ 4 ] = idet * a22; m[ 5 ] = idet * a32;
  913. m[ 6 ] = idet * a13; m[ 7 ] = idet * a23; m[ 8 ] = idet * a33;
  914. return this;
  915. },
  916. transpose: function () {
  917. var tmp, m = this.elements;
  918. tmp = m[1]; m[1] = m[3]; m[3] = tmp;
  919. tmp = m[2]; m[2] = m[6]; m[6] = tmp;
  920. tmp = m[5]; m[5] = m[7]; m[7] = tmp;
  921. return this;
  922. },
  923. transposeIntoArray: function ( r ) {
  924. var m = this.m;
  925. r[ 0 ] = m[ 0 ];
  926. r[ 1 ] = m[ 3 ];
  927. r[ 2 ] = m[ 6 ];
  928. r[ 3 ] = m[ 1 ];
  929. r[ 4 ] = m[ 4 ];
  930. r[ 5 ] = m[ 7 ];
  931. r[ 6 ] = m[ 2 ];
  932. r[ 7 ] = m[ 5 ];
  933. r[ 8 ] = m[ 8 ];
  934. return this;
  935. }
  936. };
  937. /**
  938. * @author mr.doob / http://mrdoob.com/
  939. * @author supereggbert / http://www.paulbrunt.co.uk/
  940. * @author philogb / http://blog.thejit.org/
  941. * @author jordi_ros / http://plattsoft.com
  942. * @author D1plo1d / http://github.com/D1plo1d
  943. * @author alteredq / http://alteredqualia.com/
  944. * @author mikael emtinger / http://gomo.se/
  945. * @author timknip / http://www.floorplanner.com/
  946. */
  947. THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  948. this.elements = new Float32Array(16);
  949. this.set(
  950. ( n11 !== undefined ) ? n11 : 1, n12 || 0, n13 || 0, n14 || 0,
  951. n21 || 0, ( n22 !== undefined ) ? n22 : 1, n23 || 0, n24 || 0,
  952. n31 || 0, n32 || 0, ( n33 !== undefined ) ? n33 : 1, n34 || 0,
  953. n41 || 0, n42 || 0, n43 || 0, ( n44 !== undefined ) ? n44 : 1
  954. );
  955. };
  956. THREE.Matrix4.prototype = {
  957. constructor: THREE.Matrix4,
  958. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  959. var te = this.elements;
  960. te[0] = n11; te[4] = n12; te[8] = n13; te[12] = n14;
  961. te[1] = n21; te[5] = n22; te[9] = n23; te[13] = n24;
  962. te[2] = n31; te[6] = n32; te[10] = n33; te[14] = n34;
  963. te[3] = n41; te[7] = n42; te[11] = n43; te[15] = n44;
  964. return this;
  965. },
  966. identity: function () {
  967. this.set(
  968. 1, 0, 0, 0,
  969. 0, 1, 0, 0,
  970. 0, 0, 1, 0,
  971. 0, 0, 0, 1
  972. );
  973. return this;
  974. },
  975. copy: function ( m ) {
  976. var me = m.elements;
  977. this.set(
  978. me[0], me[4], me[8], me[12],
  979. me[1], me[5], me[9], me[13],
  980. me[2], me[6], me[10], me[14],
  981. me[3], me[7], me[11], me[15]
  982. );
  983. return this;
  984. },
  985. lookAt: function ( eye, target, up ) {
  986. var te = this.elements;
  987. var x = THREE.Matrix4.__v1;
  988. var y = THREE.Matrix4.__v2;
  989. var z = THREE.Matrix4.__v3;
  990. z.sub( eye, target ).normalize();
  991. if ( z.length() === 0 ) {
  992. z.z = 1;
  993. }
  994. x.cross( up, z ).normalize();
  995. if ( x.length() === 0 ) {
  996. z.x += 0.0001;
  997. x.cross( up, z ).normalize();
  998. }
  999. y.cross( z, x );
  1000. te[0] = x.x; te[4] = y.x; te[8] = z.x;
  1001. te[1] = x.y; te[5] = y.y; te[9] = z.y;
  1002. te[2] = x.z; te[6] = y.z; te[10] = z.z;
  1003. return this;
  1004. },
  1005. multiply: function ( a, b ) {
  1006. var ae = a.elements,
  1007. be = b.elements,
  1008. te = this.elements;
  1009. var a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
  1010. var a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
  1011. var a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
  1012. var a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
  1013. var b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
  1014. var b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
  1015. var b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
  1016. var b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
  1017. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  1018. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  1019. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  1020. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  1021. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  1022. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  1023. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  1024. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  1025. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  1026. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  1027. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  1028. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  1029. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  1030. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  1031. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  1032. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  1033. return this;
  1034. },
  1035. multiplySelf: function ( m ) {
  1036. return this.multiply( this, m );
  1037. },
  1038. multiplyToArray: function ( a, b, r ) {
  1039. var te = this.elements;
  1040. this.multiply( a, b );
  1041. r[ 0 ] = te[0]; r[ 1 ] = te[1]; r[ 2 ] = te[2]; r[ 3 ] = te[3];
  1042. r[ 4 ] = te[4]; r[ 5 ] = te[5]; r[ 6 ] = te[6]; r[ 7 ] = te[7];
  1043. r[ 8 ] = te[8]; r[ 9 ] = te[9]; r[ 10 ] = te[10]; r[ 11 ] = te[11];
  1044. r[ 12 ] = te[12]; r[ 13 ] = te[13]; r[ 14 ] = te[14]; r[ 15 ] = te[15];
  1045. return this;
  1046. },
  1047. multiplyScalar: function ( s ) {
  1048. var te = this.elements;
  1049. te[0] *= s; te[4] *= s; te[8] *= s; te[12] *= s;
  1050. te[1] *= s; te[5] *= s; te[9] *= s; te[13] *= s;
  1051. te[2] *= s; te[6] *= s; te[10] *= s; te[14] *= s;
  1052. te[3] *= s; te[7] *= s; te[11] *= s; te[15] *= s;
  1053. return this;
  1054. },
  1055. multiplyVector3: function ( v ) {
  1056. var te = this.elements;
  1057. var vx = v.x, vy = v.y, vz = v.z;
  1058. var d = 1 / ( te[3] * vx + te[7] * vy + te[11] * vz + te[15] );
  1059. v.x = ( te[0] * vx + te[4] * vy + te[8] * vz + te[12] ) * d;
  1060. v.y = ( te[1] * vx + te[5] * vy + te[9] * vz + te[13] ) * d;
  1061. v.z = ( te[2] * vx + te[6] * vy + te[10] * vz + te[14] ) * d;
  1062. return v;
  1063. },
  1064. multiplyVector4: function ( v ) {
  1065. var te = this.elements;
  1066. var vx = v.x, vy = v.y, vz = v.z, vw = v.w;
  1067. v.x = te[0] * vx + te[4] * vy + te[8] * vz + te[12] * vw;
  1068. v.y = te[1] * vx + te[5] * vy + te[9] * vz + te[13] * vw;
  1069. v.z = te[2] * vx + te[6] * vy + te[10] * vz + te[14] * vw;
  1070. v.w = te[3] * vx + te[7] * vy + te[11] * vz + te[15] * vw;
  1071. return v;
  1072. },
  1073. rotateAxis: function ( v ) {
  1074. var te = this.elements;
  1075. var vx = v.x, vy = v.y, vz = v.z;
  1076. v.x = vx * te[0] + vy * te[4] + vz * te[8];
  1077. v.y = vx * te[1] + vy * te[5] + vz * te[9];
  1078. v.z = vx * te[2] + vy * te[6] + vz * te[10];
  1079. v.normalize();
  1080. return v;
  1081. },
  1082. crossVector: function ( a ) {
  1083. var te = this.elements;
  1084. var v = new THREE.Vector4();
  1085. v.x = te[0] * a.x + te[4] * a.y + te[8] * a.z + te[12] * a.w;
  1086. v.y = te[1] * a.x + te[5] * a.y + te[9] * a.z + te[13] * a.w;
  1087. v.z = te[2] * a.x + te[6] * a.y + te[10] * a.z + te[14] * a.w;
  1088. v.w = ( a.w ) ? te[3] * a.x + te[7] * a.y + te[11] * a.z + te[15] * a.w : 1;
  1089. return v;
  1090. },
  1091. determinant: function () {
  1092. var te = this.elements;
  1093. var n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12];
  1094. var n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13];
  1095. var n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14];
  1096. var n41 = te[3], n42 = te[7], n43 = te[11], n44 = te[15];
  1097. //TODO: make this more efficient
  1098. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  1099. return (
  1100. n14 * n23 * n32 * n41-
  1101. n13 * n24 * n32 * n41-
  1102. n14 * n22 * n33 * n41+
  1103. n12 * n24 * n33 * n41+
  1104. n13 * n22 * n34 * n41-
  1105. n12 * n23 * n34 * n41-
  1106. n14 * n23 * n31 * n42+
  1107. n13 * n24 * n31 * n42+
  1108. n14 * n21 * n33 * n42-
  1109. n11 * n24 * n33 * n42-
  1110. n13 * n21 * n34 * n42+
  1111. n11 * n23 * n34 * n42+
  1112. n14 * n22 * n31 * n43-
  1113. n12 * n24 * n31 * n43-
  1114. n14 * n21 * n32 * n43+
  1115. n11 * n24 * n32 * n43+
  1116. n12 * n21 * n34 * n43-
  1117. n11 * n22 * n34 * n43-
  1118. n13 * n22 * n31 * n44+
  1119. n12 * n23 * n31 * n44+
  1120. n13 * n21 * n32 * n44-
  1121. n11 * n23 * n32 * n44-
  1122. n12 * n21 * n33 * n44+
  1123. n11 * n22 * n33 * n44
  1124. );
  1125. },
  1126. transpose: function () {
  1127. var te = this.elements;
  1128. var tmp;
  1129. tmp = te[1]; te[1] = te[4]; te[4] = tmp;
  1130. tmp = te[2]; te[2] = te[8]; te[8] = tmp;
  1131. tmp = te[6]; te[6] = te[9]; te[9] = tmp;
  1132. tmp = te[3]; te[3] = te[12]; te[12] = tmp;
  1133. tmp = te[7]; te[7] = te[13]; te[13] = tmp;
  1134. tmp = te[11]; te[11] = te[14]; te[14] = tmp;
  1135. return this;
  1136. },
  1137. flattenToArray: function ( flat ) {
  1138. var te = this.elements;
  1139. flat[ 0 ] = te[0]; flat[ 1 ] = te[1]; flat[ 2 ] = te[2]; flat[ 3 ] = te[3];
  1140. flat[ 4 ] = te[4]; flat[ 5 ] = te[5]; flat[ 6 ] = te[6]; flat[ 7 ] = te[7];
  1141. flat[ 8 ] = te[8]; flat[ 9 ] = te[9]; flat[ 10 ] = te[10]; flat[ 11 ] = te[11];
  1142. flat[ 12 ] = te[12]; flat[ 13 ] = te[13]; flat[ 14 ] = te[14]; flat[ 15 ] = te[15];
  1143. return flat;
  1144. },
  1145. flattenToArrayOffset: function( flat, offset ) {
  1146. var te = this.elements;
  1147. flat[ offset ] = te[0];
  1148. flat[ offset + 1 ] = te[1];
  1149. flat[ offset + 2 ] = te[2];
  1150. flat[ offset + 3 ] = te[3];
  1151. flat[ offset + 4 ] = te[4];
  1152. flat[ offset + 5 ] = te[5];
  1153. flat[ offset + 6 ] = te[6];
  1154. flat[ offset + 7 ] = te[7];
  1155. flat[ offset + 8 ] = te[8];
  1156. flat[ offset + 9 ] = te[9];
  1157. flat[ offset + 10 ] = te[10];
  1158. flat[ offset + 11 ] = te[11];
  1159. flat[ offset + 12 ] = te[12];
  1160. flat[ offset + 13 ] = te[13];
  1161. flat[ offset + 14 ] = te[14];
  1162. flat[ offset + 15 ] = te[15];
  1163. return flat;
  1164. },
  1165. getPosition: function () {
  1166. var te = this.elements;
  1167. return THREE.Matrix4.__v1.set( te[12], te[13], te[14] );
  1168. },
  1169. setPosition: function ( v ) {
  1170. var te = this.elements;
  1171. te[12] = v.x;
  1172. te[13] = v.y;
  1173. te[14] = v.z;
  1174. return this;
  1175. },
  1176. getColumnX: function () {
  1177. var te = this.elements;
  1178. return THREE.Matrix4.__v1.set( te[0], te[1], te[2] );
  1179. },
  1180. getColumnY: function () {
  1181. var te = this.elements;
  1182. return THREE.Matrix4.__v1.set( te[4], te[5], te[6] );
  1183. },
  1184. getColumnZ: function() {
  1185. var te = this.elements;
  1186. return THREE.Matrix4.__v1.set( te[8], te[9], te[10] );
  1187. },
  1188. getInverse: function ( m ) {
  1189. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  1190. var te = this.elements;
  1191. var me = m.elements;
  1192. var n11 = me[0], n12 = me[4], n13 = me[8], n14 = me[12];
  1193. var n21 = me[1], n22 = me[5], n23 = me[9], n24 = me[13];
  1194. var n31 = me[2], n32 = me[6], n33 = me[10], n34 = me[14];
  1195. var n41 = me[3], n42 = me[7], n43 = me[11], n44 = me[15];
  1196. te[0] = n23*n34*n42 - n24*n33*n42 + n24*n32*n43 - n22*n34*n43 - n23*n32*n44 + n22*n33*n44;
  1197. te[4] = n14*n33*n42 - n13*n34*n42 - n14*n32*n43 + n12*n34*n43 + n13*n32*n44 - n12*n33*n44;
  1198. te[8] = n13*n24*n42 - n14*n23*n42 + n14*n22*n43 - n12*n24*n43 - n13*n22*n44 + n12*n23*n44;
  1199. te[12] = n14*n23*n32 - n13*n24*n32 - n14*n22*n33 + n12*n24*n33 + n13*n22*n34 - n12*n23*n34;
  1200. te[1] = n24*n33*n41 - n23*n34*n41 - n24*n31*n43 + n21*n34*n43 + n23*n31*n44 - n21*n33*n44;
  1201. te[5] = n13*n34*n41 - n14*n33*n41 + n14*n31*n43 - n11*n34*n43 - n13*n31*n44 + n11*n33*n44;
  1202. te[9] = n14*n23*n41 - n13*n24*n41 - n14*n21*n43 + n11*n24*n43 + n13*n21*n44 - n11*n23*n44;
  1203. te[13] = n13*n24*n31 - n14*n23*n31 + n14*n21*n33 - n11*n24*n33 - n13*n21*n34 + n11*n23*n34;
  1204. te[2] = n22*n34*n41 - n24*n32*n41 + n24*n31*n42 - n21*n34*n42 - n22*n31*n44 + n21*n32*n44;
  1205. te[6] = n14*n32*n41 - n12*n34*n41 - n14*n31*n42 + n11*n34*n42 + n12*n31*n44 - n11*n32*n44;
  1206. te[10] = n12*n24*n41 - n14*n22*n41 + n14*n21*n42 - n11*n24*n42 - n12*n21*n44 + n11*n22*n44;
  1207. te[14] = n14*n22*n31 - n12*n24*n31 - n14*n21*n32 + n11*n24*n32 + n12*n21*n34 - n11*n22*n34;
  1208. te[3] = n23*n32*n41 - n22*n33*n41 - n23*n31*n42 + n21*n33*n42 + n22*n31*n43 - n21*n32*n43;
  1209. te[7] = n12*n33*n41 - n13*n32*n41 + n13*n31*n42 - n11*n33*n42 - n12*n31*n43 + n11*n32*n43;
  1210. te[11] = n13*n22*n41 - n12*n23*n41 - n13*n21*n42 + n11*n23*n42 + n12*n21*n43 - n11*n22*n43;
  1211. te[15] = n12*n23*n31 - n13*n22*n31 + n13*n21*n32 - n11*n23*n32 - n12*n21*n33 + n11*n22*n33;
  1212. this.multiplyScalar( 1 / m.determinant() );
  1213. return this;
  1214. },
  1215. setRotationFromEuler: function( v, order ) {
  1216. var te = this.elements;
  1217. var x = v.x, y = v.y, z = v.z;
  1218. var a = Math.cos( x ), b = Math.sin( x );
  1219. var c = Math.cos( y ), d = Math.sin( y );
  1220. var e = Math.cos( z ), f = Math.sin( z );
  1221. switch ( order ) {
  1222. case 'YXZ':
  1223. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  1224. te[0] = ce + df * b;
  1225. te[4] = de * b - cf;
  1226. te[8] = a * d;
  1227. te[1] = a * f;
  1228. te[5] = a * e;
  1229. te[9] = - b;
  1230. te[2] = cf * b - de;
  1231. te[6] = df + ce * b;
  1232. te[10] = a * c;
  1233. break;
  1234. case 'ZXY':
  1235. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  1236. te[0] = ce - df * b;
  1237. te[4] = - a * f;
  1238. te[8] = de + cf * b;
  1239. te[1] = cf + de * b;
  1240. te[5] = a * e;
  1241. te[9] = df - ce * b;
  1242. te[2] = - a * d;
  1243. te[6] = b;
  1244. te[10] = a * c;
  1245. break;
  1246. case 'ZYX':
  1247. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  1248. te[0] = c * e;
  1249. te[4] = be * d - af;
  1250. te[8] = ae * d + bf;
  1251. te[1] = c * f;
  1252. te[5] = bf * d + ae;
  1253. te[9] = af * d - be;
  1254. te[2] = - d;
  1255. te[6] = b * c;
  1256. te[10] = a * c;
  1257. break;
  1258. case 'YZX':
  1259. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  1260. te[0] = c * e;
  1261. te[4] = bd - ac * f;
  1262. te[8] = bc * f + ad;
  1263. te[1] = f;
  1264. te[5] = a * e;
  1265. te[9] = - b * e;
  1266. te[2] = - d * e;
  1267. te[6] = ad * f + bc;
  1268. te[10] = ac - bd * f;
  1269. break;
  1270. case 'XZY':
  1271. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  1272. te[0] = c * e;
  1273. te[4] = - f;
  1274. te[8] = d * e;
  1275. te[1] = ac * f + bd;
  1276. te[5] = a * e;
  1277. te[9] = ad * f - bc;
  1278. te[2] = bc * f - ad;
  1279. te[6] = b * e;
  1280. te[10] = bd * f + ac;
  1281. break;
  1282. default: // 'XYZ'
  1283. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  1284. te[0] = c * e;
  1285. te[4] = - c * f;
  1286. te[8] = d;
  1287. te[1] = af + be * d;
  1288. te[5] = ae - bf * d;
  1289. te[9] = - b * c;
  1290. te[2] = bf - ae * d;
  1291. te[6] = be + af * d;
  1292. te[10] = a * c;
  1293. break;
  1294. }
  1295. return this;
  1296. },
  1297. setRotationFromQuaternion: function( q ) {
  1298. var te = this.elements;
  1299. var x = q.x, y = q.y, z = q.z, w = q.w;
  1300. var x2 = x + x, y2 = y + y, z2 = z + z;
  1301. var xx = x * x2, xy = x * y2, xz = x * z2;
  1302. var yy = y * y2, yz = y * z2, zz = z * z2;
  1303. var wx = w * x2, wy = w * y2, wz = w * z2;
  1304. te[0] = 1 - ( yy + zz );
  1305. te[4] = xy - wz;
  1306. te[8] = xz + wy;
  1307. te[1] = xy + wz;
  1308. te[5] = 1 - ( xx + zz );
  1309. te[9] = yz - wx;
  1310. te[2] = xz - wy;
  1311. te[6] = yz + wx;
  1312. te[10] = 1 - ( xx + yy );
  1313. return this;
  1314. },
  1315. compose: function ( translation, rotation, scale ) {
  1316. var te = this.elements;
  1317. var mRotation = THREE.Matrix4.__m1;
  1318. var mScale = THREE.Matrix4.__m2;
  1319. mRotation.identity();
  1320. mRotation.setRotationFromQuaternion( rotation );
  1321. mScale.makeScale( scale.x, scale.y, scale.z );
  1322. this.multiply( mRotation, mScale );
  1323. te[12] = translation.x;
  1324. te[13] = translation.y;
  1325. te[14] = translation.z;
  1326. return this;
  1327. },
  1328. decompose: function ( translation, rotation, scale ) {
  1329. // grab the axis vectors
  1330. var te = this.elements;
  1331. var x = THREE.Matrix4.__v1;
  1332. var y = THREE.Matrix4.__v2;
  1333. var z = THREE.Matrix4.__v3;
  1334. x.set( te[0], te[1], te[2] );
  1335. y.set( te[4], te[5], te[6] );
  1336. z.set( te[8], te[9], te[10] );
  1337. translation = ( translation instanceof THREE.Vector3 ) ? translation : new THREE.Vector3();
  1338. rotation = ( rotation instanceof THREE.Quaternion ) ? rotation : new THREE.Quaternion();
  1339. scale = ( scale instanceof THREE.Vector3 ) ? scale : new THREE.Vector3();
  1340. scale.x = x.length();
  1341. scale.y = y.length();
  1342. scale.z = z.length();
  1343. translation.x = te[12];
  1344. translation.y = te[13];
  1345. translation.z = te[14];
  1346. // scale the rotation part
  1347. var matrix = THREE.Matrix4.__m1;
  1348. matrix.copy( this );
  1349. matrix.elements[0] /= scale.x;
  1350. matrix.elements[1] /= scale.x;
  1351. matrix.elements[2] /= scale.x;
  1352. matrix.elements[4] /= scale.y;
  1353. matrix.elements[5] /= scale.y;
  1354. matrix.elements[6] /= scale.y;
  1355. matrix.elements[8] /= scale.z;
  1356. matrix.elements[9] /= scale.z;
  1357. matrix.elements[10] /= scale.z;
  1358. rotation.setFromRotationMatrix( matrix );
  1359. return [ translation, rotation, scale ];
  1360. },
  1361. extractPosition: function ( m ) {
  1362. var te = this.elements;
  1363. var me = m.elements;
  1364. te[12] = me[12];
  1365. te[13] = me[13];
  1366. te[14] = me[14];
  1367. return this;
  1368. },
  1369. extractRotation: function ( m ) {
  1370. var te = this.elements;
  1371. var me = m.elements;
  1372. var vector = THREE.Matrix4.__v1;
  1373. var scaleX = 1 / vector.set( me[0], me[1], me[2] ).length();
  1374. var scaleY = 1 / vector.set( me[4], me[5], me[6] ).length();
  1375. var scaleZ = 1 / vector.set( me[8], me[9], me[10] ).length();
  1376. te[0] = me[0] * scaleX;
  1377. te[1] = me[1] * scaleX;
  1378. te[2] = me[2] * scaleX;
  1379. te[4] = me[4] * scaleY;
  1380. te[5] = me[5] * scaleY;
  1381. te[6] = me[6] * scaleY;
  1382. te[8] = me[8] * scaleZ;
  1383. te[9] = me[9] * scaleZ;
  1384. te[10] = me[10] * scaleZ;
  1385. return this;
  1386. },
  1387. //
  1388. translate: function ( v ) {
  1389. var te = this.elements;
  1390. var x = v.x, y = v.y, z = v.z;
  1391. te[12] = te[0] * x + te[4] * y + te[8] * z + te[12];
  1392. te[13] = te[1] * x + te[5] * y + te[9] * z + te[13];
  1393. te[14] = te[2] * x + te[6] * y + te[10] * z + te[14];
  1394. te[15] = te[3] * x + te[7] * y + te[11] * z + te[15];
  1395. return this;
  1396. },
  1397. rotateX: function ( angle ) {
  1398. var te = this.elements;
  1399. var m12 = te[4];
  1400. var m22 = te[5];
  1401. var m32 = te[6];
  1402. var m42 = te[7];
  1403. var m13 = te[8];
  1404. var m23 = te[9];
  1405. var m33 = te[10];
  1406. var m43 = te[11];
  1407. var c = Math.cos( angle );
  1408. var s = Math.sin( angle );
  1409. te[4] = c * m12 + s * m13;
  1410. te[5] = c * m22 + s * m23;
  1411. te[6] = c * m32 + s * m33;
  1412. te[7] = c * m42 + s * m43;
  1413. te[8] = c * m13 - s * m12;
  1414. te[9] = c * m23 - s * m22;
  1415. te[10] = c * m33 - s * m32;
  1416. te[11] = c * m43 - s * m42;
  1417. return this;
  1418. },
  1419. rotateY: function ( angle ) {
  1420. var te = this.elements;
  1421. var m11 = te[0];
  1422. var m21 = te[1];
  1423. var m31 = te[2];
  1424. var m41 = te[3];
  1425. var m13 = te[8];
  1426. var m23 = te[9];
  1427. var m33 = te[10];
  1428. var m43 = te[11];
  1429. var c = Math.cos( angle );
  1430. var s = Math.sin( angle );
  1431. te[0] = c * m11 - s * m13;
  1432. te[1] = c * m21 - s * m23;
  1433. te[2] = c * m31 - s * m33;
  1434. te[3] = c * m41 - s * m43;
  1435. te[8] = c * m13 + s * m11;
  1436. te[9] = c * m23 + s * m21;
  1437. te[10] = c * m33 + s * m31;
  1438. te[11] = c * m43 + s * m41;
  1439. return this;
  1440. },
  1441. rotateZ: function ( angle ) {
  1442. var te = this.elements;
  1443. var m11 = te[0];
  1444. var m21 = te[1];
  1445. var m31 = te[2];
  1446. var m41 = te[3];
  1447. var m12 = te[4];
  1448. var m22 = te[5];
  1449. var m32 = te[6];
  1450. var m42 = te[7];
  1451. var c = Math.cos( angle );
  1452. var s = Math.sin( angle );
  1453. te[0] = c * m11 + s * m12;
  1454. te[1] = c * m21 + s * m22;
  1455. te[2] = c * m31 + s * m32;
  1456. te[3] = c * m41 + s * m42;
  1457. te[4] = c * m12 - s * m11;
  1458. te[5] = c * m22 - s * m21;
  1459. te[6] = c * m32 - s * m31;
  1460. te[7] = c * m42 - s * m41;
  1461. return this;
  1462. },
  1463. rotateByAxis: function ( axis, angle ) {
  1464. var te = this.elements;
  1465. // optimize by checking axis
  1466. if ( axis.x === 1 && axis.y === 0 && axis.z === 0 ) {
  1467. return this.rotateX( angle );
  1468. } else if ( axis.x === 0 && axis.y === 1 && axis.z === 0 ) {
  1469. return this.rotateY( angle );
  1470. } else if ( axis.x === 0 && axis.y === 0 && axis.z === 1 ) {
  1471. return this.rotateZ( angle );
  1472. }
  1473. var x = axis.x, y = axis.y, z = axis.z;
  1474. var n = Math.sqrt(x * x + y * y + z * z);
  1475. x /= n;
  1476. y /= n;
  1477. z /= n;
  1478. var xx = x * x, yy = y * y, zz = z * z;
  1479. var c = Math.cos( angle );
  1480. var s = Math.sin( angle );
  1481. var oneMinusCosine = 1 - c;
  1482. var xy = x * y * oneMinusCosine;
  1483. var xz = x * z * oneMinusCosine;
  1484. var yz = y * z * oneMinusCosine;
  1485. var xs = x * s;
  1486. var ys = y * s;
  1487. var zs = z * s;
  1488. var r11 = xx + (1 - xx) * c;
  1489. var r21 = xy + zs;
  1490. var r31 = xz - ys;
  1491. var r12 = xy - zs;
  1492. var r22 = yy + (1 - yy) * c;
  1493. var r32 = yz + xs;
  1494. var r13 = xz + ys;
  1495. var r23 = yz - xs;
  1496. var r33 = zz + (1 - zz) * c;
  1497. var m11 = te[0], m21 = te[1], m31 = te[2], m41 = te[3];
  1498. var m12 = te[4], m22 = te[5], m32 = te[6], m42 = te[7];
  1499. var m13 = te[8], m23 = te[9], m33 = te[10], m43 = te[11];
  1500. var m14 = te[12], m24 = te[13], m34 = te[14], m44 = te[15];
  1501. te[0] = r11 * m11 + r21 * m12 + r31 * m13;
  1502. te[1] = r11 * m21 + r21 * m22 + r31 * m23;
  1503. te[2] = r11 * m31 + r21 * m32 + r31 * m33;
  1504. te[3] = r11 * m41 + r21 * m42 + r31 * m43;
  1505. te[4] = r12 * m11 + r22 * m12 + r32 * m13;
  1506. te[5] = r12 * m21 + r22 * m22 + r32 * m23;
  1507. te[6] = r12 * m31 + r22 * m32 + r32 * m33;
  1508. te[7] = r12 * m41 + r22 * m42 + r32 * m43;
  1509. te[8] = r13 * m11 + r23 * m12 + r33 * m13;
  1510. te[9] = r13 * m21 + r23 * m22 + r33 * m23;
  1511. te[10] = r13 * m31 + r23 * m32 + r33 * m33;
  1512. te[11] = r13 * m41 + r23 * m42 + r33 * m43;
  1513. return this;
  1514. },
  1515. scale: function ( v ) {
  1516. var te = this.elements;
  1517. var x = v.x, y = v.y, z = v.z;
  1518. te[0] *= x; te[4] *= y; te[8] *= z;
  1519. te[1] *= x; te[5] *= y; te[9] *= z;
  1520. te[2] *= x; te[6] *= y; te[10] *= z;
  1521. te[3] *= x; te[7] *= y; te[11] *= z;
  1522. return this;
  1523. },
  1524. //
  1525. makeTranslation: function ( x, y, z ) {
  1526. this.set(
  1527. 1, 0, 0, x,
  1528. 0, 1, 0, y,
  1529. 0, 0, 1, z,
  1530. 0, 0, 0, 1
  1531. );
  1532. return this;
  1533. },
  1534. makeRotationX: function ( theta ) {
  1535. var c = Math.cos( theta ), s = Math.sin( theta );
  1536. this.set(
  1537. 1, 0, 0, 0,
  1538. 0, c, -s, 0,
  1539. 0, s, c, 0,
  1540. 0, 0, 0, 1
  1541. );
  1542. return this;
  1543. },
  1544. makeRotationY: function ( theta ) {
  1545. var c = Math.cos( theta ), s = Math.sin( theta );
  1546. this.set(
  1547. c, 0, s, 0,
  1548. 0, 1, 0, 0,
  1549. -s, 0, c, 0,
  1550. 0, 0, 0, 1
  1551. );
  1552. return this;
  1553. },
  1554. makeRotationZ: function ( theta ) {
  1555. var c = Math.cos( theta ), s = Math.sin( theta );
  1556. this.set(
  1557. c, -s, 0, 0,
  1558. s, c, 0, 0,
  1559. 0, 0, 1, 0,
  1560. 0, 0, 0, 1
  1561. );
  1562. return this;
  1563. },
  1564. makeRotationAxis: function ( axis, angle ) {
  1565. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  1566. var c = Math.cos( angle );
  1567. var s = Math.sin( angle );
  1568. var t = 1 - c;
  1569. var x = axis.x, y = axis.y, z = axis.z;
  1570. var tx = t * x, ty = t * y;
  1571. this.set(
  1572. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  1573. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  1574. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  1575. 0, 0, 0, 1
  1576. );
  1577. return this;
  1578. },
  1579. makeScale: function ( x, y, z ) {
  1580. this.set(
  1581. x, 0, 0, 0,
  1582. 0, y, 0, 0,
  1583. 0, 0, z, 0,
  1584. 0, 0, 0, 1
  1585. );
  1586. return this;
  1587. },
  1588. makeFrustum: function ( left, right, bottom, top, near, far ) {
  1589. var te = this.elements;
  1590. var x = 2 * near / ( right - left );
  1591. var y = 2 * near / ( top - bottom );
  1592. var a = ( right + left ) / ( right - left );
  1593. var b = ( top + bottom ) / ( top - bottom );
  1594. var c = - ( far + near ) / ( far - near );
  1595. var d = - 2 * far * near / ( far - near );
  1596. te[0] = x; te[4] = 0; te[8] = a; te[12] = 0;
  1597. te[1] = 0; te[5] = y; te[9] = b; te[13] = 0;
  1598. te[2] = 0; te[6] = 0; te[10] = c; te[14] = d;
  1599. te[3] = 0; te[7] = 0; te[11] = - 1; te[15] = 0;
  1600. return this;
  1601. },
  1602. makePerspective: function ( fov, aspect, near, far ) {
  1603. var ymax = near * Math.tan( fov * Math.PI / 360 );
  1604. var ymin = - ymax;
  1605. var xmin = ymin * aspect;
  1606. var xmax = ymax * aspect;
  1607. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  1608. },
  1609. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  1610. var te = this.elements;
  1611. var w = right - left;
  1612. var h = top - bottom;
  1613. var p = far - near;
  1614. var x = ( right + left ) / w;
  1615. var y = ( top + bottom ) / h;
  1616. var z = ( far + near ) / p;
  1617. te[0] = 2 / w; te[4] = 0; te[8] = 0; te[12] = -x;
  1618. te[1] = 0; te[5] = 2 / h; te[9] = 0; te[13] = -y;
  1619. te[2] = 0; te[6] = 0; te[10] = -2 / p; te[14] = -z;
  1620. te[3] = 0; te[7] = 0; te[11] = 0; te[15] = 1;
  1621. return this;
  1622. },
  1623. clone: function () {
  1624. var te = this.elements;
  1625. return new THREE.Matrix4(
  1626. te[0], te[4], te[8], te[12],
  1627. te[1], te[5], te[9], te[13],
  1628. te[2], te[6], te[10], te[14],
  1629. te[3], te[7], te[11], te[15]
  1630. );
  1631. }
  1632. };
  1633. THREE.Matrix4.__v1 = new THREE.Vector3();
  1634. THREE.Matrix4.__v2 = new THREE.Vector3();
  1635. THREE.Matrix4.__v3 = new THREE.Vector3();
  1636. THREE.Matrix4.__m1 = new THREE.Matrix4();
  1637. THREE.Matrix4.__m2 = new THREE.Matrix4();
  1638. /**
  1639. * @author mr.doob / http://mrdoob.com/
  1640. * @author mikael emtinger / http://gomo.se/
  1641. * @author alteredq / http://alteredqualia.com/
  1642. */
  1643. THREE.Object3D = function () {
  1644. this.id = THREE.Object3DCount ++;
  1645. this.name = '';
  1646. this.parent = undefined;
  1647. this.children = [];
  1648. this.up = new THREE.Vector3( 0, 1, 0 );
  1649. this.position = new THREE.Vector3();
  1650. this.rotation = new THREE.Vector3();
  1651. this.eulerOrder = 'XYZ';
  1652. this.scale = new THREE.Vector3( 1, 1, 1 );
  1653. this.doubleSided = false;
  1654. this.flipSided = false;
  1655. this.renderDepth = null;
  1656. this.rotationAutoUpdate = true;
  1657. this.matrix = new THREE.Matrix4();
  1658. this.matrixWorld = new THREE.Matrix4();
  1659. this.matrixRotationWorld = new THREE.Matrix4();
  1660. this.matrixAutoUpdate = true;
  1661. this.matrixWorldNeedsUpdate = true;
  1662. this.quaternion = new THREE.Quaternion();
  1663. this.useQuaternion = false;
  1664. this.boundRadius = 0.0;
  1665. this.boundRadiusScale = 1.0;
  1666. this.visible = true;
  1667. this.castShadow = false;
  1668. this.receiveShadow = false;
  1669. this.frustumCulled = true;
  1670. this._vector = new THREE.Vector3();
  1671. };
  1672. THREE.Object3D.prototype = {
  1673. constructor: THREE.Object3D,
  1674. applyMatrix: function ( matrix ) {
  1675. this.matrix.multiply( matrix, this.matrix );
  1676. this.scale.getScaleFromMatrix( this.matrix );
  1677. this.rotation.getRotationFromMatrix( this.matrix, this.scale );
  1678. this.position.getPositionFromMatrix( this.matrix );
  1679. },
  1680. translate: function ( distance, axis ) {
  1681. this.matrix.rotateAxis( axis );
  1682. this.position.addSelf( axis.multiplyScalar( distance ) );
  1683. },
  1684. translateX: function ( distance ) {
  1685. this.translate( distance, this._vector.set( 1, 0, 0 ) );
  1686. },
  1687. translateY: function ( distance ) {
  1688. this.translate( distance, this._vector.set( 0, 1, 0 ) );
  1689. },
  1690. translateZ: function ( distance ) {
  1691. this.translate( distance, this._vector.set( 0, 0, 1 ) );
  1692. },
  1693. lookAt: function ( vector ) {
  1694. // TODO: Add hierarchy support.
  1695. this.matrix.lookAt( vector, this.position, this.up );
  1696. if ( this.rotationAutoUpdate ) {
  1697. this.rotation.getRotationFromMatrix( this.matrix );
  1698. }
  1699. },
  1700. add: function ( object ) {
  1701. if ( object === this ) {
  1702. console.warn( 'THREE.Object3D.add: An object can\'t be added as a child of itself.' );
  1703. return;
  1704. }
  1705. if ( object instanceof THREE.Object3D ) { // && this.children.indexOf( object ) === - 1
  1706. if ( object.parent !== undefined ) {
  1707. object.parent.remove( object );
  1708. }
  1709. object.parent = this;
  1710. this.children.push( object );
  1711. // add to scene
  1712. var scene = this;
  1713. while ( scene.parent !== undefined ) {
  1714. scene = scene.parent;
  1715. }
  1716. if ( scene !== undefined && scene instanceof THREE.Scene ) {
  1717. scene.__addObject( object );
  1718. }
  1719. }
  1720. },
  1721. remove: function ( object ) {
  1722. var index = this.children.indexOf( object );
  1723. if ( index !== - 1 ) {
  1724. object.parent = undefined;
  1725. this.children.splice( index, 1 );
  1726. // remove from scene
  1727. var scene = this;
  1728. while ( scene.parent !== undefined ) {
  1729. scene = scene.parent;
  1730. }
  1731. if ( scene !== undefined && scene instanceof THREE.Scene ) {
  1732. scene.__removeObject( object );
  1733. }
  1734. }
  1735. },
  1736. getChildByName: function ( name, recursive ) {
  1737. var c, cl, child;
  1738. for ( c = 0, cl = this.children.length; c < cl; c ++ ) {
  1739. child = this.children[ c ];
  1740. if ( child.name === name ) {
  1741. return child;
  1742. }
  1743. if ( recursive ) {
  1744. child = child.getChildByName( name, recursive );
  1745. if ( child !== undefined ) {
  1746. return child;
  1747. }
  1748. }
  1749. }
  1750. return undefined;
  1751. },
  1752. updateMatrix: function () {
  1753. this.matrix.setPosition( this.position );
  1754. if ( this.useQuaternion ) {
  1755. this.matrix.setRotationFromQuaternion( this.quaternion );
  1756. } else {
  1757. this.matrix.setRotationFromEuler( this.rotation, this.eulerOrder );
  1758. }
  1759. if ( this.scale.x !== 1 || this.scale.y !== 1 || this.scale.z !== 1 ) {
  1760. this.matrix.scale( this.scale );
  1761. this.boundRadiusScale = Math.max( this.scale.x, Math.max( this.scale.y, this.scale.z ) );
  1762. }
  1763. this.matrixWorldNeedsUpdate = true;
  1764. },
  1765. updateMatrixWorld: function ( force ) {
  1766. this.matrixAutoUpdate && this.updateMatrix();
  1767. // update matrixWorld
  1768. if ( this.matrixWorldNeedsUpdate || force ) {
  1769. if ( this.parent ) {
  1770. this.matrixWorld.multiply( this.parent.matrixWorld, this.matrix );
  1771. } else {
  1772. this.matrixWorld.copy( this.matrix );
  1773. }
  1774. this.matrixWorldNeedsUpdate = false;
  1775. force = true;
  1776. }
  1777. // update children
  1778. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  1779. this.children[ i ].updateMatrixWorld( force );
  1780. }
  1781. }
  1782. };
  1783. THREE.Object3DCount = 0;
  1784. /**
  1785. * @author mr.doob / http://mrdoob.com/
  1786. * @author supereggbert / http://www.paulbrunt.co.uk/
  1787. * @author julianwa / https://github.com/julianwa
  1788. */
  1789. THREE.Projector = function() {
  1790. var _object, _objectCount, _objectPool = [],
  1791. _vertex, _vertexCount, _vertexPool = [],
  1792. _face, _face3Count, _face3Pool = [], _face4Count, _face4Pool = [],
  1793. _line, _lineCount, _linePool = [],
  1794. _particle, _particleCount, _particlePool = [],
  1795. _renderData = { objects: [], sprites: [], lights: [], elements: [] },
  1796. _vector3 = new THREE.Vector3(),
  1797. _vector4 = new THREE.Vector4(),
  1798. _projScreenMatrix = new THREE.Matrix4(),
  1799. _projScreenobjectMatrixWorld = new THREE.Matrix4(),
  1800. _frustum = new THREE.Frustum(),
  1801. _clippedVertex1PositionScreen = new THREE.Vector4(),
  1802. _clippedVertex2PositionScreen = new THREE.Vector4(),
  1803. _face3VertexNormals;
  1804. this.projectVector = function ( vector, camera ) {
  1805. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  1806. _projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );
  1807. _projScreenMatrix.multiplyVector3( vector );
  1808. return vector;
  1809. };
  1810. this.unprojectVector = function ( vector, camera ) {
  1811. camera.projectionMatrixInverse.getInverse( camera.projectionMatrix );
  1812. _projScreenMatrix.multiply( camera.matrixWorld, camera.projectionMatrixInverse );
  1813. _projScreenMatrix.multiplyVector3( vector );
  1814. return vector;
  1815. };
  1816. this.pickingRay = function ( vector, camera ) {
  1817. var end, ray, t;
  1818. // set two vectors with opposing z values
  1819. vector.z = -1.0;
  1820. end = new THREE.Vector3( vector.x, vector.y, 1.0 );
  1821. this.unprojectVector( vector, camera );
  1822. this.unprojectVector( end, camera );
  1823. // find direction from vector to end
  1824. end.subSelf( vector ).normalize();
  1825. return new THREE.Ray( vector, end );
  1826. };
  1827. this.projectGraph = function ( root, sort ) {
  1828. _objectCount = 0;
  1829. _renderData.objects.length = 0;
  1830. _renderData.sprites.length = 0;
  1831. _renderData.lights.length = 0;
  1832. var projectObject = function ( object ) {
  1833. if ( object.visible === false ) return;
  1834. if ( ( object instanceof THREE.Mesh || object instanceof THREE.Line ) &&
  1835. ( object.frustumCulled === false || _frustum.contains( object ) ) ) {
  1836. _vector3.copy( object.matrixWorld.getPosition() );
  1837. _projScreenMatrix.multiplyVector3( _vector3 );
  1838. _object = getNextObjectInPool();
  1839. _object.object = object;
  1840. _object.z = _vector3.z;
  1841. _renderData.objects.push( _object );
  1842. } else if ( object instanceof THREE.Sprite || object instanceof THREE.Particle ) {
  1843. _vector3.copy( object.matrixWorld.getPosition() );
  1844. _projScreenMatrix.multiplyVector3( _vector3 );
  1845. _object = getNextObjectInPool();
  1846. _object.object = object;
  1847. _object.z = _vector3.z;
  1848. _renderData.sprites.push( _object );
  1849. } else if ( object instanceof THREE.Light ) {
  1850. _renderData.lights.push( object );
  1851. }
  1852. for ( var c = 0, cl = object.children.length; c < cl; c ++ ) {
  1853. projectObject( object.children[ c ] );
  1854. }
  1855. };
  1856. projectObject( root );
  1857. sort && _renderData.objects.sort( painterSort );
  1858. return _renderData;
  1859. };
  1860. this.projectScene = function ( scene, camera, sort ) {
  1861. var near = camera.near, far = camera.far, visible = false,
  1862. o, ol, v, vl, f, fl, n, nl, c, cl, u, ul, object,
  1863. objectMatrixWorld, objectMatrixWorldRotation,
  1864. geometry, geometryMaterials, vertices, vertex, vertexPositionScreen,
  1865. faces, face, faceVertexNormals, normal, faceVertexUvs, uvs,
  1866. v1, v2, v3, v4;
  1867. _face3Count = 0;
  1868. _face4Count = 0;
  1869. _lineCount = 0;
  1870. _particleCount = 0;
  1871. _renderData.elements.length = 0;
  1872. if ( camera.parent === undefined ) {
  1873. console.warn( 'DEPRECATED: Camera hasn\'t been added to a Scene. Adding it...' );
  1874. scene.add( camera );
  1875. }
  1876. scene.updateMatrixWorld();
  1877. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  1878. _projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );
  1879. _frustum.setFromMatrix( _projScreenMatrix );
  1880. _renderData = this.projectGraph( scene, false );
  1881. for ( o = 0, ol = _renderData.objects.length; o < ol; o++ ) {
  1882. object = _renderData.objects[ o ].object;
  1883. objectMatrixWorld = object.matrixWorld;
  1884. _vertexCount = 0;
  1885. if ( object instanceof THREE.Mesh ) {
  1886. geometry = object.geometry;
  1887. geometryMaterials = object.geometry.materials;
  1888. vertices = geometry.vertices;
  1889. faces = geometry.faces;
  1890. faceVertexUvs = geometry.faceVertexUvs;
  1891. objectMatrixWorldRotation = object.matrixRotationWorld.extractRotation( objectMatrixWorld );
  1892. for ( v = 0, vl = vertices.length; v < vl; v ++ ) {
  1893. _vertex = getNextVertexInPool();
  1894. _vertex.positionWorld.copy( vertices[ v ] );
  1895. objectMatrixWorld.multiplyVector3( _vertex.positionWorld );
  1896. _vertex.positionScreen.copy( _vertex.positionWorld );
  1897. _projScreenMatrix.multiplyVector4( _vertex.positionScreen );
  1898. _vertex.positionScreen.x /= _vertex.positionScreen.w;
  1899. _vertex.positionScreen.y /= _vertex.positionScreen.w;
  1900. _vertex.visible = _vertex.positionScreen.z > near && _vertex.positionScreen.z < far;
  1901. }
  1902. for ( f = 0, fl = faces.length; f < fl; f ++ ) {
  1903. face = faces[ f ];
  1904. if ( face instanceof THREE.Face3 ) {
  1905. v1 = _vertexPool[ face.a ];
  1906. v2 = _vertexPool[ face.b ];
  1907. v3 = _vertexPool[ face.c ];
  1908. if ( v1.visible && v2.visible && v3.visible ) {
  1909. visible = ( ( v3.positionScreen.x - v1.positionScreen.x ) * ( v2.positionScreen.y - v1.positionScreen.y ) -
  1910. ( v3.positionScreen.y - v1.positionScreen.y ) * ( v2.positionScreen.x - v1.positionScreen.x ) ) < 0;
  1911. if ( object.doubleSided || visible != object.flipSided ) {
  1912. _face = getNextFace3InPool();
  1913. _face.v1.copy( v1 );
  1914. _face.v2.copy( v2 );
  1915. _face.v3.copy( v3 );
  1916. } else {
  1917. continue;
  1918. }
  1919. } else {
  1920. continue;
  1921. }
  1922. } else if ( face instanceof THREE.Face4 ) {
  1923. v1 = _vertexPool[ face.a ];
  1924. v2 = _vertexPool[ face.b ];
  1925. v3 = _vertexPool[ face.c ];
  1926. v4 = _vertexPool[ face.d ];
  1927. if ( v1.visible && v2.visible && v3.visible && v4.visible ) {
  1928. visible = ( v4.positionScreen.x - v1.positionScreen.x ) * ( v2.positionScreen.y - v1.positionScreen.y ) -
  1929. ( v4.positionScreen.y - v1.positionScreen.y ) * ( v2.positionScreen.x - v1.positionScreen.x ) < 0 ||
  1930. ( v2.positionScreen.x - v3.positionScreen.x ) * ( v4.positionScreen.y - v3.positionScreen.y ) -
  1931. ( v2.positionScreen.y - v3.positionScreen.y ) * ( v4.positionScreen.x - v3.positionScreen.x ) < 0;
  1932. if ( object.doubleSided || visible != object.flipSided ) {
  1933. _face = getNextFace4InPool();
  1934. _face.v1.copy( v1 );
  1935. _face.v2.copy( v2 );
  1936. _face.v3.copy( v3 );
  1937. _face.v4.copy( v4 );
  1938. } else {
  1939. continue;
  1940. }
  1941. } else {
  1942. continue;
  1943. }
  1944. }
  1945. _face.normalWorld.copy( face.normal );
  1946. if ( !visible && ( object.flipSided || object.doubleSided ) ) _face.normalWorld.negate();
  1947. objectMatrixWorldRotation.multiplyVector3( _face.normalWorld );
  1948. _face.centroidWorld.copy( face.centroid );
  1949. objectMatrixWorld.multiplyVector3( _face.centroidWorld );
  1950. _face.centroidScreen.copy( _face.centroidWorld );
  1951. _projScreenMatrix.multiplyVector3( _face.centroidScreen );
  1952. faceVertexNormals = face.vertexNormals;
  1953. for ( n = 0, nl = faceVertexNormals.length; n < nl; n ++ ) {
  1954. normal = _face.vertexNormalsWorld[ n ];
  1955. normal.copy( faceVertexNormals[ n ] );
  1956. if ( !visible && ( object.flipSided || object.doubleSided ) ) normal.negate();
  1957. objectMatrixWorldRotation.multiplyVector3( normal );
  1958. }
  1959. for ( c = 0, cl = faceVertexUvs.length; c < cl; c ++ ) {
  1960. uvs = faceVertexUvs[ c ][ f ];
  1961. if ( !uvs ) continue;
  1962. for ( u = 0, ul = uvs.length; u < ul; u ++ ) {
  1963. _face.uvs[ c ][ u ] = uvs[ u ];
  1964. }
  1965. }
  1966. _face.material = object.material;
  1967. _face.faceMaterial = face.materialIndex !== null ? geometryMaterials[ face.materialIndex ] : null;
  1968. _face.z = _face.centroidScreen.z;
  1969. _renderData.elements.push( _face );
  1970. }
  1971. } else if ( object instanceof THREE.Line ) {
  1972. _projScreenobjectMatrixWorld.multiply( _projScreenMatrix, objectMatrixWorld );
  1973. vertices = object.geometry.vertices;
  1974. v1 = getNextVertexInPool();
  1975. v1.positionScreen.copy( vertices[ 0 ] );
  1976. _projScreenobjectMatrixWorld.multiplyVector4( v1.positionScreen );
  1977. // Handle LineStrip and LinePieces
  1978. var step = object.type === THREE.LinePieces ? 2 : 1;
  1979. for ( v = 1, vl = vertices.length; v < vl; v ++ ) {
  1980. v1 = getNextVertexInPool();
  1981. v1.positionScreen.copy( vertices[ v ] );
  1982. _projScreenobjectMatrixWorld.multiplyVector4( v1.positionScreen );
  1983. if ( ( v + 1 ) % step > 0 ) continue;
  1984. v2 = _vertexPool[ _vertexCount - 2 ];
  1985. _clippedVertex1PositionScreen.copy( v1.positionScreen );
  1986. _clippedVertex2PositionScreen.copy( v2.positionScreen );
  1987. if ( clipLine( _clippedVertex1PositionScreen, _clippedVertex2PositionScreen ) ) {
  1988. // Perform the perspective divide
  1989. _clippedVertex1PositionScreen.multiplyScalar( 1 / _clippedVertex1PositionScreen.w );
  1990. _clippedVertex2PositionScreen.multiplyScalar( 1 / _clippedVertex2PositionScreen.w );
  1991. _line = getNextLineInPool();
  1992. _line.v1.positionScreen.copy( _clippedVertex1PositionScreen );
  1993. _line.v2.positionScreen.copy( _clippedVertex2PositionScreen );
  1994. _line.z = Math.max( _clippedVertex1PositionScreen.z, _clippedVertex2PositionScreen.z );
  1995. _line.material = object.material;
  1996. _renderData.elements.push( _line );
  1997. }
  1998. }
  1999. }
  2000. }
  2001. for ( o = 0, ol = _renderData.sprites.length; o < ol; o++ ) {
  2002. object = _renderData.sprites[ o ].object;
  2003. objectMatrixWorld = object.matrixWorld;
  2004. if ( object instanceof THREE.Particle ) {
  2005. _vector4.set( objectMatrixWorld.elements[12], objectMatrixWorld.elements[13], objectMatrixWorld.elements[14], 1 );
  2006. _projScreenMatrix.multiplyVector4( _vector4 );
  2007. _vector4.z /= _vector4.w;
  2008. if ( _vector4.z > 0 && _vector4.z < 1 ) {
  2009. _particle = getNextParticleInPool();
  2010. _particle.x = _vector4.x / _vector4.w;
  2011. _particle.y = _vector4.y / _vector4.w;
  2012. _particle.z = _vector4.z;
  2013. _particle.rotation = object.rotation.z;
  2014. _particle.scale.x = object.scale.x * Math.abs( _particle.x - ( _vector4.x + camera.projectionMatrix.elements[0] ) / ( _vector4.w + camera.projectionMatrix.elements[12] ) );
  2015. _particle.scale.y = object.scale.y * Math.abs( _particle.y - ( _vector4.y + camera.projectionMatrix.elements[5] ) / ( _vector4.w + camera.projectionMatrix.elements[13] ) );
  2016. _particle.material = object.material;
  2017. _renderData.elements.push( _particle );
  2018. }
  2019. }
  2020. }
  2021. sort && _renderData.elements.sort( painterSort );
  2022. return _renderData;
  2023. };
  2024. // Pools
  2025. function getNextObjectInPool() {
  2026. var object = _objectPool[ _objectCount ] = _objectPool[ _objectCount ] || new THREE.RenderableObject();
  2027. _objectCount ++;
  2028. return object;
  2029. }
  2030. function getNextVertexInPool() {
  2031. var vertex = _vertexPool[ _vertexCount ] = _vertexPool[ _vertexCount ] || new THREE.RenderableVertex();
  2032. _vertexCount ++;
  2033. return vertex;
  2034. }
  2035. function getNextFace3InPool() {
  2036. var face = _face3Pool[ _face3Count ] = _face3Pool[ _face3Count ] || new THREE.RenderableFace3();
  2037. _face3Count ++;
  2038. return face;
  2039. }
  2040. function getNextFace4InPool() {
  2041. var face = _face4Pool[ _face4Count ] = _face4Pool[ _face4Count ] || new THREE.RenderableFace4();
  2042. _face4Count ++;
  2043. return face;
  2044. }
  2045. function getNextLineInPool() {
  2046. var line = _linePool[ _lineCount ] = _linePool[ _lineCount ] || new THREE.RenderableLine();
  2047. _lineCount ++;
  2048. return line;
  2049. }
  2050. function getNextParticleInPool() {
  2051. var particle = _particlePool[ _particleCount ] = _particlePool[ _particleCount ] || new THREE.RenderableParticle();
  2052. _particleCount ++;
  2053. return particle;
  2054. }
  2055. //
  2056. function painterSort( a, b ) {
  2057. return b.z - a.z;
  2058. }
  2059. function clipLine( s1, s2 ) {
  2060. var alpha1 = 0, alpha2 = 1,
  2061. // Calculate the boundary coordinate of each vertex for the near and far clip planes,
  2062. // Z = -1 and Z = +1, respectively.
  2063. bc1near = s1.z + s1.w,
  2064. bc2near = s2.z + s2.w,
  2065. bc1far = - s1.z + s1.w,
  2066. bc2far = - s2.z + s2.w;
  2067. if ( bc1near >= 0 && bc2near >= 0 && bc1far >= 0 && bc2far >= 0 ) {
  2068. // Both vertices lie entirely within all clip planes.
  2069. return true;
  2070. } else if ( ( bc1near < 0 && bc2near < 0) || (bc1far < 0 && bc2far < 0 ) ) {
  2071. // Both vertices lie entirely outside one of the clip planes.
  2072. return false;
  2073. } else {
  2074. // The line segment spans at least one clip plane.
  2075. if ( bc1near < 0 ) {
  2076. // v1 lies outside the near plane, v2 inside
  2077. alpha1 = Math.max( alpha1, bc1near / ( bc1near - bc2near ) );
  2078. } else if ( bc2near < 0 ) {
  2079. // v2 lies outside the near plane, v1 inside
  2080. alpha2 = Math.min( alpha2, bc1near / ( bc1near - bc2near ) );
  2081. }
  2082. if ( bc1far < 0 ) {
  2083. // v1 lies outside the far plane, v2 inside
  2084. alpha1 = Math.max( alpha1, bc1far / ( bc1far - bc2far ) );
  2085. } else if ( bc2far < 0 ) {
  2086. // v2 lies outside the far plane, v2 inside
  2087. alpha2 = Math.min( alpha2, bc1far / ( bc1far - bc2far ) );
  2088. }
  2089. if ( alpha2 < alpha1 ) {
  2090. // The line segment spans two boundaries, but is outside both of them.
  2091. // (This can't happen when we're only clipping against just near/far but good
  2092. // to leave the check here for future usage if other clip planes are added.)
  2093. return false;
  2094. } else {
  2095. // Update the s1 and s2 vertices to match the clipped line segment.
  2096. s1.lerpSelf( s2, alpha1 );
  2097. s2.lerpSelf( s1, 1 - alpha2 );
  2098. return true;
  2099. }
  2100. }
  2101. }
  2102. };
  2103. /**
  2104. * @author mikael emtinger / http://gomo.se/
  2105. * @author alteredq / http://alteredqualia.com/
  2106. */
  2107. THREE.Quaternion = function( x, y, z, w ) {
  2108. this.x = x || 0;
  2109. this.y = y || 0;
  2110. this.z = z || 0;
  2111. this.w = ( w !== undefined ) ? w : 1;
  2112. };
  2113. THREE.Quaternion.prototype = {
  2114. constructor: THREE.Quaternion,
  2115. set: function ( x, y, z, w ) {
  2116. this.x = x;
  2117. this.y = y;
  2118. this.z = z;
  2119. this.w = w;
  2120. return this;
  2121. },
  2122. copy: function ( q ) {
  2123. this.x = q.x;
  2124. this.y = q.y;
  2125. this.z = q.z;
  2126. this.w = q.w;
  2127. return this;
  2128. },
  2129. setFromEuler: function ( vector ) {
  2130. var c = Math.PI / 360, // 0.5 * Math.PI / 360, // 0.5 is an optimization
  2131. x = vector.x * c,
  2132. y = vector.y * c,
  2133. z = vector.z * c,
  2134. c1 = Math.cos( y ),
  2135. s1 = Math.sin( y ),
  2136. c2 = Math.cos( -z ),
  2137. s2 = Math.sin( -z ),
  2138. c3 = Math.cos( x ),
  2139. s3 = Math.sin( x ),
  2140. c1c2 = c1 * c2,
  2141. s1s2 = s1 * s2;
  2142. this.w = c1c2 * c3 - s1s2 * s3;
  2143. this.x = c1c2 * s3 + s1s2 * c3;
  2144. this.y = s1 * c2 * c3 + c1 * s2 * s3;
  2145. this.z = c1 * s2 * c3 - s1 * c2 * s3;
  2146. return this;
  2147. },
  2148. setFromAxisAngle: function ( axis, angle ) {
  2149. // from http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2150. // axis have to be normalized
  2151. var halfAngle = angle / 2,
  2152. s = Math.sin( halfAngle );
  2153. this.x = axis.x * s;
  2154. this.y = axis.y * s;
  2155. this.z = axis.z * s;
  2156. this.w = Math.cos( halfAngle );
  2157. return this;
  2158. },
  2159. setFromRotationMatrix: function ( m ) {
  2160. // Adapted from: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2161. function copySign( a, b ) {
  2162. return b < 0 ? -Math.abs( a ) : Math.abs( a );
  2163. }
  2164. var absQ = Math.pow( m.determinant(), 1.0 / 3.0 );
  2165. this.w = Math.sqrt( Math.max( 0, absQ + m.elements[0] + m.elements[5] + m.elements[10] ) ) / 2;
  2166. this.x = Math.sqrt( Math.max( 0, absQ + m.elements[0] - m.elements[5] - m.elements[10] ) ) / 2;
  2167. this.y = Math.sqrt( Math.max( 0, absQ - m.elements[0] + m.elements[5] - m.elements[10] ) ) / 2;
  2168. this.z = Math.sqrt( Math.max( 0, absQ - m.elements[0] - m.elements[5] + m.elements[10] ) ) / 2;
  2169. this.x = copySign( this.x, ( m.elements[6] - m.elements[9] ) );
  2170. this.y = copySign( this.y, ( m.elements[8] - m.elements[2] ) );
  2171. this.z = copySign( this.z, ( m.elements[1] - m.elements[4] ) );
  2172. this.normalize();
  2173. return this;
  2174. },
  2175. calculateW : function () {
  2176. this.w = - Math.sqrt( Math.abs( 1.0 - this.x * this.x - this.y * this.y - this.z * this.z ) );
  2177. return this;
  2178. },
  2179. inverse: function () {
  2180. this.x *= -1;
  2181. this.y *= -1;
  2182. this.z *= -1;
  2183. return this;
  2184. },
  2185. length: function () {
  2186. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2187. },
  2188. normalize: function () {
  2189. var l = Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2190. if ( l === 0 ) {
  2191. this.x = 0;
  2192. this.y = 0;
  2193. this.z = 0;
  2194. this.w = 0;
  2195. } else {
  2196. l = 1 / l;
  2197. this.x = this.x * l;
  2198. this.y = this.y * l;
  2199. this.z = this.z * l;
  2200. this.w = this.w * l;
  2201. }
  2202. return this;
  2203. },
  2204. multiply: function ( a, b ) {
  2205. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2206. this.x = a.x * b.w + a.y * b.z - a.z * b.y + a.w * b.x;
  2207. this.y = -a.x * b.z + a.y * b.w + a.z * b.x + a.w * b.y;
  2208. this.z = a.x * b.y - a.y * b.x + a.z * b.w + a.w * b.z;
  2209. this.w = -a.x * b.x - a.y * b.y - a.z * b.z + a.w * b.w;
  2210. return this;
  2211. },
  2212. multiplySelf: function ( b ) {
  2213. var qax = this.x, qay = this.y, qaz = this.z, qaw = this.w,
  2214. qbx = b.x, qby = b.y, qbz = b.z, qbw = b.w;
  2215. this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2216. this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2217. this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2218. this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2219. return this;
  2220. },
  2221. multiplyVector3: function ( vector, dest ) {
  2222. if ( !dest ) { dest = vector; }
  2223. var x = vector.x, y = vector.y, z = vector.z,
  2224. qx = this.x, qy = this.y, qz = this.z, qw = this.w;
  2225. // calculate quat * vector
  2226. var ix = qw * x + qy * z - qz * y,
  2227. iy = qw * y + qz * x - qx * z,
  2228. iz = qw * z + qx * y - qy * x,
  2229. iw = -qx * x - qy * y - qz * z;
  2230. // calculate result * inverse quat
  2231. dest.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  2232. dest.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  2233. dest.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  2234. return dest;
  2235. },
  2236. clone: function () {
  2237. return new THREE.Quaternion( this.x, this.y, this.z, this.w );
  2238. }
  2239. }
  2240. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  2241. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2242. var cosHalfTheta = qa.w * qb.w + qa.x * qb.x + qa.y * qb.y + qa.z * qb.z;
  2243. if (cosHalfTheta < 0) {
  2244. qm.w = -qb.w; qm.x = -qb.x; qm.y = -qb.y; qm.z = -qb.z;
  2245. cosHalfTheta = -cosHalfTheta;
  2246. } else {
  2247. qm.copy(qb);
  2248. }
  2249. if ( Math.abs( cosHalfTheta ) >= 1.0 ) {
  2250. qm.w = qa.w; qm.x = qa.x; qm.y = qa.y; qm.z = qa.z;
  2251. return qm;
  2252. }
  2253. var halfTheta = Math.acos( cosHalfTheta ),
  2254. sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  2255. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  2256. qm.w = 0.5 * ( qa.w + qb.w );
  2257. qm.x = 0.5 * ( qa.x + qb.x );
  2258. qm.y = 0.5 * ( qa.y + qb.y );
  2259. qm.z = 0.5 * ( qa.z + qb.z );
  2260. return qm;
  2261. }
  2262. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  2263. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  2264. qm.w = ( qa.w * ratioA + qm.w * ratioB );
  2265. qm.x = ( qa.x * ratioA + qm.x * ratioB );
  2266. qm.y = ( qa.y * ratioA + qm.y * ratioB );
  2267. qm.z = ( qa.z * ratioA + qm.z * ratioB );
  2268. return qm;
  2269. }
  2270. /**
  2271. * @author mr.doob / http://mrdoob.com/
  2272. */
  2273. THREE.Vertex = THREE.Vector3;
  2274. /**
  2275. * @author mr.doob / http://mrdoob.com/
  2276. * @author alteredq / http://alteredqualia.com/
  2277. */
  2278. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  2279. this.a = a;
  2280. this.b = b;
  2281. this.c = c;
  2282. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  2283. this.vertexNormals = normal instanceof Array ? normal : [ ];
  2284. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  2285. this.vertexColors = color instanceof Array ? color : [];
  2286. this.vertexTangents = [];
  2287. this.materialIndex = materialIndex;
  2288. this.centroid = new THREE.Vector3();
  2289. };
  2290. THREE.Face3.prototype = {
  2291. constructor: THREE.Face3,
  2292. clone: function () {
  2293. var face = new THREE.Face3( this.a, this.b, this.c );
  2294. face.normal.copy( this.normal );
  2295. face.color.copy( this.color );
  2296. face.centroid.copy( this.centroid );
  2297. face.materialIndex = this.materialIndex;
  2298. var i, il;
  2299. for ( i = 0, il = this.vertexNormals.length; i < il; i ++ ) face.vertexNormals[ i ] = this.vertexNormals[ i ].clone();
  2300. for ( i = 0, il = this.vertexColors.length; i < il; i ++ ) face.vertexColors[ i ] = this.vertexColors[ i ].clone();
  2301. for ( i = 0, il = this.vertexTangents.length; i < il; i ++ ) face.vertexTangents[ i ] = this.vertexTangents[ i ].clone();
  2302. return face;
  2303. }
  2304. };
  2305. /**
  2306. * @author mr.doob / http://mrdoob.com/
  2307. * @author alteredq / http://alteredqualia.com/
  2308. */
  2309. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  2310. this.a = a;
  2311. this.b = b;
  2312. this.c = c;
  2313. this.d = d;
  2314. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  2315. this.vertexNormals = normal instanceof Array ? normal : [ ];
  2316. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  2317. this.vertexColors = color instanceof Array ? color : [];
  2318. this.vertexTangents = [];
  2319. this.materialIndex = materialIndex;
  2320. this.centroid = new THREE.Vector3();
  2321. };
  2322. THREE.Face4.prototype = {
  2323. constructor: THREE.Face4,
  2324. clone: function () {
  2325. var face = new THREE.Face4( this.a, this.b, this.c, this.d );
  2326. face.normal.copy( this.normal );
  2327. face.color.copy( this.color );
  2328. face.centroid.copy( this.centroid );
  2329. face.materialIndex = this.materialIndex;
  2330. var i, il;
  2331. for ( i = 0, il = this.vertexNormals.length; i < il; i ++ ) face.vertexNormals[ i ] = this.vertexNormals[ i ].clone();
  2332. for ( i = 0, il = this.vertexColors.length; i < il; i ++ ) face.vertexColors[ i ] = this.vertexColors[ i ].clone();
  2333. for ( i = 0, il = this.vertexTangents.length; i < il; i ++ ) face.vertexTangents[ i ] = this.vertexTangents[ i ].clone();
  2334. return face;
  2335. }
  2336. };
  2337. /**
  2338. * @author mr.doob / http://mrdoob.com/
  2339. */
  2340. THREE.UV = function ( u, v ) {
  2341. this.u = u || 0;
  2342. this.v = v || 0;
  2343. };
  2344. THREE.UV.prototype = {
  2345. constructor: THREE.UV,
  2346. set: function ( u, v ) {
  2347. this.u = u;
  2348. this.v = v;
  2349. return this;
  2350. },
  2351. copy: function ( uv ) {
  2352. this.u = uv.u;
  2353. this.v = uv.v;
  2354. return this;
  2355. },
  2356. lerpSelf: function ( uv, alpha ) {
  2357. this.u += ( uv.u - this.u ) * alpha;
  2358. this.v += ( uv.v - this.v ) * alpha;
  2359. return this;
  2360. },
  2361. clone: function () {
  2362. return new THREE.UV( this.u, this.v );
  2363. }
  2364. };
  2365. /**
  2366. * @author mr.doob / http://mrdoob.com/
  2367. * @author kile / http://kile.stravaganza.org/
  2368. * @author alteredq / http://alteredqualia.com/
  2369. * @author mikael emtinger / http://gomo.se/
  2370. * @author zz85 / http://www.lab4games.net/zz85/blog
  2371. */
  2372. THREE.Geometry = function () {
  2373. this.id = THREE.GeometryCount ++;
  2374. this.vertices = [];
  2375. this.colors = []; // one-to-one vertex colors, used in ParticleSystem, Line and Ribbon
  2376. this.materials = [];
  2377. this.faces = [];
  2378. this.faceUvs = [[]];
  2379. this.faceVertexUvs = [[]];
  2380. this.morphTargets = [];
  2381. this.morphColors = [];
  2382. this.morphNormals = [];
  2383. this.skinWeights = [];
  2384. this.skinIndices = [];
  2385. this.boundingBox = null;
  2386. this.boundingSphere = null;
  2387. this.hasTangents = false;
  2388. this.dynamic = false; // unless set to true the *Arrays will be deleted once sent to a buffer.
  2389. };
  2390. THREE.Geometry.prototype = {
  2391. constructor : THREE.Geometry,
  2392. applyMatrix: function ( matrix ) {
  2393. var matrixRotation = new THREE.Matrix4();
  2394. matrixRotation.extractRotation( matrix );
  2395. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  2396. var vertex = this.vertices[ i ];
  2397. matrix.multiplyVector3( vertex );
  2398. }
  2399. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  2400. var face = this.faces[ i ];
  2401. matrixRotation.multiplyVector3( face.normal );
  2402. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  2403. matrixRotation.multiplyVector3( face.vertexNormals[ j ] );
  2404. }
  2405. matrix.multiplyVector3( face.centroid );
  2406. }
  2407. },
  2408. computeCentroids: function () {
  2409. var f, fl, face;
  2410. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2411. face = this.faces[ f ];
  2412. face.centroid.set( 0, 0, 0 );
  2413. if ( face instanceof THREE.Face3 ) {
  2414. face.centroid.addSelf( this.vertices[ face.a ] );
  2415. face.centroid.addSelf( this.vertices[ face.b ] );
  2416. face.centroid.addSelf( this.vertices[ face.c ] );
  2417. face.centroid.divideScalar( 3 );
  2418. } else if ( face instanceof THREE.Face4 ) {
  2419. face.centroid.addSelf( this.vertices[ face.a ] );
  2420. face.centroid.addSelf( this.vertices[ face.b ] );
  2421. face.centroid.addSelf( this.vertices[ face.c ] );
  2422. face.centroid.addSelf( this.vertices[ face.d ] );
  2423. face.centroid.divideScalar( 4 );
  2424. }
  2425. }
  2426. },
  2427. computeFaceNormals: function () {
  2428. var n, nl, v, vl, vertex, f, fl, face, vA, vB, vC,
  2429. cb = new THREE.Vector3(), ab = new THREE.Vector3();
  2430. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2431. face = this.faces[ f ];
  2432. vA = this.vertices[ face.a ];
  2433. vB = this.vertices[ face.b ];
  2434. vC = this.vertices[ face.c ];
  2435. cb.sub( vC, vB );
  2436. ab.sub( vA, vB );
  2437. cb.crossSelf( ab );
  2438. if ( !cb.isZero() ) {
  2439. cb.normalize();
  2440. }
  2441. face.normal.copy( cb );
  2442. }
  2443. },
  2444. computeVertexNormals: function () {
  2445. var v, vl, f, fl, face, vertices;
  2446. // create internal buffers for reuse when calling this method repeatedly
  2447. // (otherwise memory allocation / deallocation every frame is big resource hog)
  2448. if ( this.__tmpVertices === undefined ) {
  2449. this.__tmpVertices = new Array( this.vertices.length );
  2450. vertices = this.__tmpVertices;
  2451. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  2452. vertices[ v ] = new THREE.Vector3();
  2453. }
  2454. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2455. face = this.faces[ f ];
  2456. if ( face instanceof THREE.Face3 ) {
  2457. face.vertexNormals = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  2458. } else if ( face instanceof THREE.Face4 ) {
  2459. face.vertexNormals = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  2460. }
  2461. }
  2462. } else {
  2463. vertices = this.__tmpVertices;
  2464. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  2465. vertices[ v ].set( 0, 0, 0 );
  2466. }
  2467. }
  2468. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2469. face = this.faces[ f ];
  2470. if ( face instanceof THREE.Face3 ) {
  2471. vertices[ face.a ].addSelf( face.normal );
  2472. vertices[ face.b ].addSelf( face.normal );
  2473. vertices[ face.c ].addSelf( face.normal );
  2474. } else if ( face instanceof THREE.Face4 ) {
  2475. vertices[ face.a ].addSelf( face.normal );
  2476. vertices[ face.b ].addSelf( face.normal );
  2477. vertices[ face.c ].addSelf( face.normal );
  2478. vertices[ face.d ].addSelf( face.normal );
  2479. }
  2480. }
  2481. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  2482. vertices[ v ].normalize();
  2483. }
  2484. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2485. face = this.faces[ f ];
  2486. if ( face instanceof THREE.Face3 ) {
  2487. face.vertexNormals[ 0 ].copy( vertices[ face.a ] );
  2488. face.vertexNormals[ 1 ].copy( vertices[ face.b ] );
  2489. face.vertexNormals[ 2 ].copy( vertices[ face.c ] );
  2490. } else if ( face instanceof THREE.Face4 ) {
  2491. face.vertexNormals[ 0 ].copy( vertices[ face.a ] );
  2492. face.vertexNormals[ 1 ].copy( vertices[ face.b ] );
  2493. face.vertexNormals[ 2 ].copy( vertices[ face.c ] );
  2494. face.vertexNormals[ 3 ].copy( vertices[ face.d ] );
  2495. }
  2496. }
  2497. },
  2498. computeMorphNormals: function () {
  2499. var i, il, f, fl, face;
  2500. // save original normals
  2501. // - create temp variables on first access
  2502. // otherwise just copy (for faster repeated calls)
  2503. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2504. face = this.faces[ f ];
  2505. if ( ! face.__originalFaceNormal ) {
  2506. face.__originalFaceNormal = face.normal.clone();
  2507. } else {
  2508. face.__originalFaceNormal.copy( face.normal );
  2509. }
  2510. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  2511. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  2512. if ( ! face.__originalVertexNormals[ i ] ) {
  2513. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  2514. } else {
  2515. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  2516. }
  2517. }
  2518. }
  2519. // use temp geometry to compute face and vertex normals for each morph
  2520. var tmpGeo = new THREE.Geometry();
  2521. tmpGeo.faces = this.faces;
  2522. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  2523. // create on first access
  2524. if ( ! this.morphNormals[ i ] ) {
  2525. this.morphNormals[ i ] = {};
  2526. this.morphNormals[ i ].faceNormals = [];
  2527. this.morphNormals[ i ].vertexNormals = [];
  2528. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  2529. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  2530. var faceNormal, vertexNormals;
  2531. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2532. face = this.faces[ f ];
  2533. faceNormal = new THREE.Vector3();
  2534. if ( face instanceof THREE.Face3 ) {
  2535. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  2536. } else {
  2537. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3(), d: new THREE.Vector3() };
  2538. }
  2539. dstNormalsFace.push( faceNormal );
  2540. dstNormalsVertex.push( vertexNormals );
  2541. }
  2542. }
  2543. var morphNormals = this.morphNormals[ i ];
  2544. // set vertices to morph target
  2545. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  2546. // compute morph normals
  2547. tmpGeo.computeFaceNormals();
  2548. tmpGeo.computeVertexNormals();
  2549. // store morph normals
  2550. var faceNormal, vertexNormals;
  2551. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2552. face = this.faces[ f ];
  2553. faceNormal = morphNormals.faceNormals[ f ];
  2554. vertexNormals = morphNormals.vertexNormals[ f ];
  2555. faceNormal.copy( face.normal );
  2556. if ( face instanceof THREE.Face3 ) {
  2557. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  2558. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  2559. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  2560. } else {
  2561. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  2562. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  2563. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  2564. vertexNormals.d.copy( face.vertexNormals[ 3 ] );
  2565. }
  2566. }
  2567. }
  2568. // restore original normals
  2569. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2570. face = this.faces[ f ];
  2571. face.normal = face.__originalFaceNormal;
  2572. face.vertexNormals = face.__originalVertexNormals;
  2573. }
  2574. },
  2575. computeTangents: function () {
  2576. // based on http://www.terathon.com/code/tangent.html
  2577. // tangents go to vertices
  2578. var f, fl, v, vl, i, il, vertexIndex,
  2579. face, uv, vA, vB, vC, uvA, uvB, uvC,
  2580. x1, x2, y1, y2, z1, z2,
  2581. s1, s2, t1, t2, r, t, test,
  2582. tan1 = [], tan2 = [],
  2583. sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
  2584. tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(),
  2585. n = new THREE.Vector3(), w;
  2586. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  2587. tan1[ v ] = new THREE.Vector3();
  2588. tan2[ v ] = new THREE.Vector3();
  2589. }
  2590. function handleTriangle( context, a, b, c, ua, ub, uc ) {
  2591. vA = context.vertices[ a ];
  2592. vB = context.vertices[ b ];
  2593. vC = context.vertices[ c ];
  2594. uvA = uv[ ua ];
  2595. uvB = uv[ ub ];
  2596. uvC = uv[ uc ];
  2597. x1 = vB.x - vA.x;
  2598. x2 = vC.x - vA.x;
  2599. y1 = vB.y - vA.y;
  2600. y2 = vC.y - vA.y;
  2601. z1 = vB.z - vA.z;
  2602. z2 = vC.z - vA.z;
  2603. s1 = uvB.u - uvA.u;
  2604. s2 = uvC.u - uvA.u;
  2605. t1 = uvB.v - uvA.v;
  2606. t2 = uvC.v - uvA.v;
  2607. r = 1.0 / ( s1 * t2 - s2 * t1 );
  2608. sdir.set( ( t2 * x1 - t1 * x2 ) * r,
  2609. ( t2 * y1 - t1 * y2 ) * r,
  2610. ( t2 * z1 - t1 * z2 ) * r );
  2611. tdir.set( ( s1 * x2 - s2 * x1 ) * r,
  2612. ( s1 * y2 - s2 * y1 ) * r,
  2613. ( s1 * z2 - s2 * z1 ) * r );
  2614. tan1[ a ].addSelf( sdir );
  2615. tan1[ b ].addSelf( sdir );
  2616. tan1[ c ].addSelf( sdir );
  2617. tan2[ a ].addSelf( tdir );
  2618. tan2[ b ].addSelf( tdir );
  2619. tan2[ c ].addSelf( tdir );
  2620. }
  2621. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2622. face = this.faces[ f ];
  2623. uv = this.faceVertexUvs[ 0 ][ f ]; // use UV layer 0 for tangents
  2624. if ( face instanceof THREE.Face3 ) {
  2625. handleTriangle( this, face.a, face.b, face.c, 0, 1, 2 );
  2626. } else if ( face instanceof THREE.Face4 ) {
  2627. handleTriangle( this, face.a, face.b, face.d, 0, 1, 3 );
  2628. handleTriangle( this, face.b, face.c, face.d, 1, 2, 3 );
  2629. }
  2630. }
  2631. var faceIndex = [ 'a', 'b', 'c', 'd' ];
  2632. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2633. face = this.faces[ f ];
  2634. for ( i = 0; i < face.vertexNormals.length; i++ ) {
  2635. n.copy( face.vertexNormals[ i ] );
  2636. vertexIndex = face[ faceIndex[ i ] ];
  2637. t = tan1[ vertexIndex ];
  2638. // Gram-Schmidt orthogonalize
  2639. tmp.copy( t );
  2640. tmp.subSelf( n.multiplyScalar( n.dot( t ) ) ).normalize();
  2641. // Calculate handedness
  2642. tmp2.cross( face.vertexNormals[ i ], t );
  2643. test = tmp2.dot( tan2[ vertexIndex ] );
  2644. w = (test < 0.0) ? -1.0 : 1.0;
  2645. face.vertexTangents[ i ] = new THREE.Vector4( tmp.x, tmp.y, tmp.z, w );
  2646. }
  2647. }
  2648. this.hasTangents = true;
  2649. },
  2650. computeBoundingBox: function () {
  2651. if ( ! this.boundingBox ) {
  2652. this.boundingBox = { min: new THREE.Vector3(), max: new THREE.Vector3() };
  2653. }
  2654. if ( this.vertices.length > 0 ) {
  2655. var position, firstPosition = this.vertices[ 0 ];
  2656. this.boundingBox.min.copy( firstPosition );
  2657. this.boundingBox.max.copy( firstPosition );
  2658. var min = this.boundingBox.min,
  2659. max = this.boundingBox.max;
  2660. for ( var v = 1, vl = this.vertices.length; v < vl; v ++ ) {
  2661. position = this.vertices[ v ];
  2662. if ( position.x < min.x ) {
  2663. min.x = position.x;
  2664. } else if ( position.x > max.x ) {
  2665. max.x = position.x;
  2666. }
  2667. if ( position.y < min.y ) {
  2668. min.y = position.y;
  2669. } else if ( position.y > max.y ) {
  2670. max.y = position.y;
  2671. }
  2672. if ( position.z < min.z ) {
  2673. min.z = position.z;
  2674. } else if ( position.z > max.z ) {
  2675. max.z = position.z;
  2676. }
  2677. }
  2678. } else {
  2679. this.boundingBox.min.set( 0, 0, 0 );
  2680. this.boundingBox.max.set( 0, 0, 0 );
  2681. }
  2682. },
  2683. computeBoundingSphere: function () {
  2684. if ( ! this.boundingSphere ) this.boundingSphere = { radius: 0 };
  2685. var radius, maxRadius = 0;
  2686. for ( var v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  2687. radius = this.vertices[ v ].length();
  2688. if ( radius > maxRadius ) maxRadius = radius;
  2689. }
  2690. this.boundingSphere.radius = maxRadius;
  2691. },
  2692. /*
  2693. * Checks for duplicate vertices with hashmap.
  2694. * Duplicated vertices are removed
  2695. * and faces' vertices are updated.
  2696. */
  2697. mergeVertices: function() {
  2698. var verticesMap = {}; // Hashmap for looking up vertice by position coordinates (and making sure they are unique)
  2699. var unique = [], changes = [];
  2700. var v, key;
  2701. var precisionPoints = 4; // number of decimal points, eg. 4 for epsilon of 0.0001
  2702. var precision = Math.pow( 10, precisionPoints );
  2703. var i,il, face;
  2704. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  2705. v = this.vertices[ i ];
  2706. key = [ Math.round( v.x * precision ), Math.round( v.y * precision ), Math.round( v.z * precision ) ].join( '_' );
  2707. if ( verticesMap[ key ] === undefined ) {
  2708. verticesMap[ key ] = i;
  2709. unique.push( this.vertices[ i ] );
  2710. changes[ i ] = unique.length - 1;
  2711. } else {
  2712. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  2713. changes[ i ] = changes[ verticesMap[ key ] ];
  2714. }
  2715. };
  2716. // Start to patch face indices
  2717. for( i = 0, il = this.faces.length; i < il; i ++ ) {
  2718. face = this.faces[ i ];
  2719. if ( face instanceof THREE.Face3 ) {
  2720. face.a = changes[ face.a ];
  2721. face.b = changes[ face.b ];
  2722. face.c = changes[ face.c ];
  2723. } else if ( face instanceof THREE.Face4 ) {
  2724. face.a = changes[ face.a ];
  2725. face.b = changes[ face.b ];
  2726. face.c = changes[ face.c ];
  2727. face.d = changes[ face.d ];
  2728. }
  2729. }
  2730. // Use unique set of vertices
  2731. this.vertices = unique;
  2732. }
  2733. };
  2734. THREE.GeometryCount = 0;
  2735. /**
  2736. * @author mr.doob / http://mrdoob.com/
  2737. * @author mikael emtinger / http://gomo.se/
  2738. */
  2739. THREE.Camera = function () {
  2740. THREE.Object3D.call( this );
  2741. this.matrixWorldInverse = new THREE.Matrix4();
  2742. this.projectionMatrix = new THREE.Matrix4();
  2743. this.projectionMatrixInverse = new THREE.Matrix4();
  2744. };
  2745. THREE.Camera.prototype = new THREE.Object3D();
  2746. THREE.Camera.prototype.constructor = THREE.Camera;
  2747. THREE.Camera.prototype.lookAt = function ( vector ) {
  2748. // TODO: Add hierarchy support.
  2749. this.matrix.lookAt( this.position, vector, this.up );
  2750. if ( this.rotationAutoUpdate ) {
  2751. this.rotation.getRotationFromMatrix( this.matrix );
  2752. }
  2753. };
  2754. /**
  2755. * @author alteredq / http://alteredqualia.com/
  2756. */
  2757. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  2758. THREE.Camera.call( this );
  2759. this.left = left;
  2760. this.right = right;
  2761. this.top = top;
  2762. this.bottom = bottom;
  2763. this.near = ( near !== undefined ) ? near : 0.1;
  2764. this.far = ( far !== undefined ) ? far : 2000;
  2765. this.updateProjectionMatrix();
  2766. };
  2767. THREE.OrthographicCamera.prototype = new THREE.Camera();
  2768. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  2769. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  2770. this.projectionMatrix.makeOrthographic( this.left, this.right, this.top, this.bottom, this.near, this.far );
  2771. };
  2772. /**
  2773. * @author mr.doob / http://mrdoob.com/
  2774. * @author greggman / http://games.greggman.com/
  2775. * @author zz85 / http://www.lab4games.net/zz85/blog
  2776. */
  2777. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  2778. THREE.Camera.call( this );
  2779. this.fov = fov !== undefined ? fov : 50;
  2780. this.aspect = aspect !== undefined ? aspect : 1;
  2781. this.near = near !== undefined ? near : 0.1;
  2782. this.far = far !== undefined ? far : 2000;
  2783. this.updateProjectionMatrix();
  2784. };
  2785. THREE.PerspectiveCamera.prototype = new THREE.Camera();
  2786. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  2787. /**
  2788. * Uses Focal Length (in mm) to estimate and set FOV
  2789. * 35mm (fullframe) camera is used if frame size is not specified;
  2790. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  2791. */
  2792. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  2793. frameHeight = frameHeight !== undefined ? frameHeight : 24;
  2794. this.fov = 2 * Math.atan( frameHeight / ( focalLength * 2 ) ) * ( 180 / Math.PI );
  2795. this.updateProjectionMatrix();
  2796. }
  2797. /**
  2798. * Sets an offset in a larger frustum. This is useful for multi-window or
  2799. * multi-monitor/multi-machine setups.
  2800. *
  2801. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  2802. * the monitors are in grid like this
  2803. *
  2804. * +---+---+---+
  2805. * | A | B | C |
  2806. * +---+---+---+
  2807. * | D | E | F |
  2808. * +---+---+---+
  2809. *
  2810. * then for each monitor you would call it like this
  2811. *
  2812. * var w = 1920;
  2813. * var h = 1080;
  2814. * var fullWidth = w * 3;
  2815. * var fullHeight = h * 2;
  2816. *
  2817. * --A--
  2818. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  2819. * --B--
  2820. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  2821. * --C--
  2822. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  2823. * --D--
  2824. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  2825. * --E--
  2826. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  2827. * --F--
  2828. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  2829. *
  2830. * Note there is no reason monitors have to be the same size or in a grid.
  2831. */
  2832. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  2833. this.fullWidth = fullWidth;
  2834. this.fullHeight = fullHeight;
  2835. this.x = x;
  2836. this.y = y;
  2837. this.width = width;
  2838. this.height = height;
  2839. this.updateProjectionMatrix();
  2840. };
  2841. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  2842. if ( this.fullWidth ) {
  2843. var aspect = this.fullWidth / this.fullHeight;
  2844. var top = Math.tan( this.fov * Math.PI / 360 ) * this.near;
  2845. var bottom = -top;
  2846. var left = aspect * bottom;
  2847. var right = aspect * top;
  2848. var width = Math.abs( right - left );
  2849. var height = Math.abs( top - bottom );
  2850. this.projectionMatrix.makeFrustum(
  2851. left + this.x * width / this.fullWidth,
  2852. left + ( this.x + this.width ) * width / this.fullWidth,
  2853. top - ( this.y + this.height ) * height / this.fullHeight,
  2854. top - this.y * height / this.fullHeight,
  2855. this.near,
  2856. this.far
  2857. );
  2858. } else {
  2859. this.projectionMatrix.makePerspective( this.fov, this.aspect, this.near, this.far );
  2860. }
  2861. };
  2862. /**
  2863. * @author mr.doob / http://mrdoob.com/
  2864. * @author alteredq / http://alteredqualia.com/
  2865. */
  2866. THREE.Light = function ( hex ) {
  2867. THREE.Object3D.call( this );
  2868. this.color = new THREE.Color( hex );
  2869. };
  2870. THREE.Light.prototype = new THREE.Object3D();
  2871. THREE.Light.prototype.constructor = THREE.Light;
  2872. THREE.Light.prototype.supr = THREE.Object3D.prototype;
  2873. /**
  2874. * @author mr.doob / http://mrdoob.com/
  2875. */
  2876. THREE.AmbientLight = function ( hex ) {
  2877. THREE.Light.call( this, hex );
  2878. };
  2879. THREE.AmbientLight.prototype = new THREE.Light();
  2880. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  2881. /**
  2882. * @author mr.doob / http://mrdoob.com/
  2883. * @author alteredq / http://alteredqualia.com/
  2884. */
  2885. THREE.DirectionalLight = function ( hex, intensity, distance ) {
  2886. THREE.Light.call( this, hex );
  2887. this.position = new THREE.Vector3( 0, 1, 0 );
  2888. this.target = new THREE.Object3D();
  2889. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  2890. this.distance = ( distance !== undefined ) ? distance : 0;
  2891. this.castShadow = false;
  2892. this.onlyShadow = false;
  2893. //
  2894. this.shadowCameraNear = 50;
  2895. this.shadowCameraFar = 5000;
  2896. this.shadowCameraLeft = -500;
  2897. this.shadowCameraRight = 500;
  2898. this.shadowCameraTop = 500;
  2899. this.shadowCameraBottom = -500;
  2900. this.shadowCameraVisible = false;
  2901. this.shadowBias = 0;
  2902. this.shadowDarkness = 0.5;
  2903. this.shadowMapWidth = 512;
  2904. this.shadowMapHeight = 512;
  2905. //
  2906. this.shadowCascade = false;
  2907. this.shadowCascadeOffset = new THREE.Vector3( 0, 0, -1000 );
  2908. this.shadowCascadeCount = 2;
  2909. this.shadowCascadeBias = [ 0, 0, 0 ];
  2910. this.shadowCascadeWidth = [ 512, 512, 512 ];
  2911. this.shadowCascadeHeight = [ 512, 512, 512 ];
  2912. this.shadowCascadeNearZ = [ -1.000, 0.990, 0.998 ];
  2913. this.shadowCascadeFarZ = [ 0.990, 0.998, 1.000 ];
  2914. this.shadowCascadeArray = [];
  2915. //
  2916. this.shadowMap = null;
  2917. this.shadowMapSize = null;
  2918. this.shadowCamera = null;
  2919. this.shadowMatrix = null;
  2920. };
  2921. THREE.DirectionalLight.prototype = new THREE.Light();
  2922. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  2923. /**
  2924. * @author mr.doob / http://mrdoob.com/
  2925. */
  2926. THREE.PointLight = function ( hex, intensity, distance ) {
  2927. THREE.Light.call( this, hex );
  2928. this.position = new THREE.Vector3( 0, 0, 0 );
  2929. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  2930. this.distance = ( distance !== undefined ) ? distance : 0;
  2931. };
  2932. THREE.PointLight.prototype = new THREE.Light();
  2933. THREE.PointLight.prototype.constructor = THREE.PointLight;
  2934. /**
  2935. * @author mr.doob / http://mrdoob.com/
  2936. * @author alteredq / http://alteredqualia.com/
  2937. */
  2938. THREE.Material = function ( parameters ) {
  2939. parameters = parameters || {};
  2940. this.id = THREE.MaterialCount ++;
  2941. this.name = '';
  2942. this.opacity = parameters.opacity !== undefined ? parameters.opacity : 1;
  2943. this.transparent = parameters.transparent !== undefined ? parameters.transparent : false;
  2944. this.blending = parameters.blending !== undefined ? parameters.blending : THREE.NormalBlending;
  2945. this.blendSrc = parameters.blendSrc !== undefined ? parameters.blendSrc : THREE.SrcAlphaFactor;
  2946. this.blendDst = parameters.blendDst !== undefined ? parameters.blendDst : THREE.OneMinusSrcAlphaFactor;
  2947. this.blendEquation = parameters.blendEquation !== undefined ? parameters.blendEquation : THREE.AddEquation;
  2948. this.depthTest = parameters.depthTest !== undefined ? parameters.depthTest : true;
  2949. this.depthWrite = parameters.depthWrite !== undefined ? parameters.depthWrite : true;
  2950. this.polygonOffset = parameters.polygonOffset !== undefined ? parameters.polygonOffset : false;
  2951. this.polygonOffsetFactor = parameters.polygonOffsetFactor !== undefined ? parameters.polygonOffsetFactor : 0;
  2952. this.polygonOffsetUnits = parameters.polygonOffsetUnits !== undefined ? parameters.polygonOffsetUnits : 0;
  2953. this.alphaTest = parameters.alphaTest !== undefined ? parameters.alphaTest : 0;
  2954. this.overdraw = parameters.overdraw !== undefined ? parameters.overdraw : false; // Boolean for fixing antialiasing gaps in CanvasRenderer
  2955. this.needsUpdate = true;
  2956. }
  2957. THREE.MaterialCount = 0;
  2958. // shading
  2959. THREE.NoShading = 0;
  2960. THREE.FlatShading = 1;
  2961. THREE.SmoothShading = 2;
  2962. // colors
  2963. THREE.NoColors = 0;
  2964. THREE.FaceColors = 1;
  2965. THREE.VertexColors = 2;
  2966. // blending modes
  2967. THREE.NoBlending = 0;
  2968. THREE.NormalBlending = 1;
  2969. THREE.AdditiveBlending = 2;
  2970. THREE.SubtractiveBlending = 3;
  2971. THREE.MultiplyBlending = 4;
  2972. THREE.AdditiveAlphaBlending = 5;
  2973. THREE.CustomBlending = 6;
  2974. // custom blending equations
  2975. // (numbers start from 100 not to clash with other
  2976. // mappings to OpenGL constants defined in Texture.js)
  2977. THREE.AddEquation = 100;
  2978. THREE.SubtractEquation = 101;
  2979. THREE.ReverseSubtractEquation = 102;
  2980. // custom blending destination factors
  2981. THREE.ZeroFactor = 200;
  2982. THREE.OneFactor = 201;
  2983. THREE.SrcColorFactor = 202;
  2984. THREE.OneMinusSrcColorFactor = 203;
  2985. THREE.SrcAlphaFactor = 204;
  2986. THREE.OneMinusSrcAlphaFactor = 205;
  2987. THREE.DstAlphaFactor = 206;
  2988. THREE.OneMinusDstAlphaFactor = 207;
  2989. // custom blending source factors
  2990. //THREE.ZeroFactor = 200;
  2991. //THREE.OneFactor = 201;
  2992. //THREE.SrcAlphaFactor = 204;
  2993. //THREE.OneMinusSrcAlphaFactor = 205;
  2994. //THREE.DstAlphaFactor = 206;
  2995. //THREE.OneMinusDstAlphaFactor = 207;
  2996. THREE.DstColorFactor = 208;
  2997. THREE.OneMinusDstColorFactor = 209;
  2998. THREE.SrcAlphaSaturateFactor = 210;
  2999. /**
  3000. * @author mr.doob / http://mrdoob.com/
  3001. * @author alteredq / http://alteredqualia.com/
  3002. *
  3003. * parameters = {
  3004. * color: <hex>,
  3005. * opacity: <float>,
  3006. *
  3007. * blending: THREE.NormalBlending,
  3008. * depthTest: <bool>,
  3009. *
  3010. * linewidth: <float>,
  3011. * linecap: "round",
  3012. * linejoin: "round",
  3013. *
  3014. * vertexColors: <bool>
  3015. *
  3016. * fog: <bool>
  3017. * }
  3018. */
  3019. THREE.LineBasicMaterial = function ( parameters ) {
  3020. THREE.Material.call( this, parameters );
  3021. parameters = parameters || {};
  3022. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3023. this.linewidth = parameters.linewidth !== undefined ? parameters.linewidth : 1;
  3024. this.linecap = parameters.linecap !== undefined ? parameters.linecap : 'round';
  3025. this.linejoin = parameters.linejoin !== undefined ? parameters.linejoin : 'round';
  3026. this.vertexColors = parameters.vertexColors ? parameters.vertexColors : false;
  3027. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3028. };
  3029. THREE.LineBasicMaterial.prototype = new THREE.Material();
  3030. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  3031. /**
  3032. * @author mr.doob / http://mrdoob.com/
  3033. * @author alteredq / http://alteredqualia.com/
  3034. *
  3035. * parameters = {
  3036. * color: <hex>,
  3037. * opacity: <float>,
  3038. * map: new THREE.Texture( <Image> ),
  3039. *
  3040. * lightMap: new THREE.Texture( <Image> ),
  3041. *
  3042. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  3043. * combine: THREE.Multiply,
  3044. * reflectivity: <float>,
  3045. * refractionRatio: <float>,
  3046. *
  3047. * shading: THREE.SmoothShading,
  3048. * blending: THREE.NormalBlending,
  3049. * depthTest: <bool>,
  3050. *
  3051. * wireframe: <boolean>,
  3052. * wireframeLinewidth: <float>,
  3053. *
  3054. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  3055. *
  3056. * skinning: <bool>,
  3057. * morphTargets: <bool>,
  3058. *
  3059. * fog: <bool>
  3060. * }
  3061. */
  3062. THREE.MeshBasicMaterial = function ( parameters ) {
  3063. THREE.Material.call( this, parameters );
  3064. parameters = parameters || {};
  3065. // color property represents emissive for MeshBasicMaterial
  3066. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3067. this.map = parameters.map !== undefined ? parameters.map : null;
  3068. this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null;
  3069. this.envMap = parameters.envMap !== undefined ? parameters.envMap : null;
  3070. this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation;
  3071. this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1;
  3072. this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98;
  3073. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3074. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
  3075. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3076. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3077. this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round';
  3078. this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round';
  3079. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors;
  3080. this.skinning = parameters.skinning !== undefined ? parameters.skinning : false;
  3081. this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false;
  3082. };
  3083. THREE.MeshBasicMaterial.prototype = new THREE.Material();
  3084. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  3085. /**
  3086. * @author mr.doob / http://mrdoob.com/
  3087. * @author alteredq / http://alteredqualia.com/
  3088. *
  3089. * parameters = {
  3090. * color: <hex>,
  3091. * ambient: <hex>,
  3092. * emissive: <hex>,
  3093. * opacity: <float>,
  3094. *
  3095. * map: new THREE.Texture( <Image> ),
  3096. *
  3097. * lightMap: new THREE.Texture( <Image> ),
  3098. *
  3099. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  3100. * combine: THREE.Multiply,
  3101. * reflectivity: <float>,
  3102. * refractionRatio: <float>,
  3103. *
  3104. * shading: THREE.SmoothShading,
  3105. * blending: THREE.NormalBlending,
  3106. * depthTest: <bool>,
  3107. *
  3108. * wireframe: <boolean>,
  3109. * wireframeLinewidth: <float>,
  3110. *
  3111. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  3112. *
  3113. * skinning: <bool>,
  3114. * morphTargets: <bool>,
  3115. * morphNormals: <bool>,
  3116. *
  3117. * fog: <bool>
  3118. * }
  3119. */
  3120. THREE.MeshLambertMaterial = function ( parameters ) {
  3121. THREE.Material.call( this, parameters );
  3122. parameters = parameters || {};
  3123. // color property represents diffuse for MeshLambertMaterial
  3124. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3125. this.ambient = parameters.ambient !== undefined ? new THREE.Color( parameters.ambient ) : new THREE.Color( 0xffffff );
  3126. this.emissive = parameters.emissive !== undefined ? new THREE.Color( parameters.emissive ) : new THREE.Color( 0x000000 );
  3127. this.wrapAround = parameters.wrapAround !== undefined ? parameters.wrapAround: false;
  3128. this.wrapRGB = new THREE.Vector3( 1, 1, 1 );
  3129. this.map = parameters.map !== undefined ? parameters.map : null;
  3130. this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null;
  3131. this.envMap = parameters.envMap !== undefined ? parameters.envMap : null;
  3132. this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation;
  3133. this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1;
  3134. this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98;
  3135. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3136. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
  3137. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3138. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3139. this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round';
  3140. this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round';
  3141. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors;
  3142. this.skinning = parameters.skinning !== undefined ? parameters.skinning : false;
  3143. this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false;
  3144. this.morphNormals = parameters.morphNormals !== undefined ? parameters.morphNormals : false;
  3145. };
  3146. THREE.MeshLambertMaterial.prototype = new THREE.Material();
  3147. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  3148. /**
  3149. * @author mr.doob / http://mrdoob.com/
  3150. * @author alteredq / http://alteredqualia.com/
  3151. *
  3152. * parameters = {
  3153. * color: <hex>,
  3154. * ambient: <hex>,
  3155. * emissive: <hex>,
  3156. * specular: <hex>,
  3157. * shininess: <float>,
  3158. * opacity: <float>,
  3159. *
  3160. * map: new THREE.Texture( <Image> ),
  3161. *
  3162. * lightMap: new THREE.Texture( <Image> ),
  3163. *
  3164. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  3165. * combine: THREE.Multiply,
  3166. * reflectivity: <float>,
  3167. * refractionRatio: <float>,
  3168. *
  3169. * shading: THREE.SmoothShading,
  3170. * blending: THREE.NormalBlending,
  3171. * depthTest: <bool>,
  3172. *
  3173. * wireframe: <boolean>,
  3174. * wireframeLinewidth: <float>,
  3175. *
  3176. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  3177. *
  3178. * skinning: <bool>,
  3179. * morphTargets: <bool>,
  3180. * morphNormals: <bool>,
  3181. *
  3182. * fog: <bool>
  3183. * }
  3184. */
  3185. THREE.MeshPhongMaterial = function ( parameters ) {
  3186. THREE.Material.call( this, parameters );
  3187. parameters = parameters || {};
  3188. // color property represents diffuse for MeshPhongMaterial
  3189. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3190. this.ambient = parameters.ambient !== undefined ? new THREE.Color( parameters.ambient ) : new THREE.Color( 0xffffff );
  3191. this.emissive = parameters.emissive !== undefined ? new THREE.Color( parameters.emissive ) : new THREE.Color( 0x000000 );
  3192. this.specular = parameters.specular !== undefined ? new THREE.Color( parameters.specular ) : new THREE.Color( 0x111111 );
  3193. this.shininess = parameters.shininess !== undefined ? parameters.shininess : 30;
  3194. this.metal = parameters.metal !== undefined ? parameters.metal : false;
  3195. this.perPixel = parameters.perPixel !== undefined ? parameters.perPixel : false;
  3196. this.wrapAround = parameters.wrapAround !== undefined ? parameters.wrapAround: false;
  3197. this.wrapRGB = new THREE.Vector3( 1, 1, 1 );
  3198. this.map = parameters.map !== undefined ? parameters.map : null;
  3199. this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null;
  3200. this.envMap = parameters.envMap !== undefined ? parameters.envMap : null;
  3201. this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation;
  3202. this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1;
  3203. this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98;
  3204. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3205. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
  3206. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3207. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3208. this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round';
  3209. this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round';
  3210. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors;
  3211. this.skinning = parameters.skinning !== undefined ? parameters.skinning : false;
  3212. this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false;
  3213. this.morphNormals = parameters.morphNormals !== undefined ? parameters.morphNormals : false;
  3214. };
  3215. THREE.MeshPhongMaterial.prototype = new THREE.Material();
  3216. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  3217. /**
  3218. * @author mr.doob / http://mrdoob.com/
  3219. * @author alteredq / http://alteredqualia.com/
  3220. *
  3221. * parameters = {
  3222. * opacity: <float>,
  3223. * blending: THREE.NormalBlending,
  3224. * depthTest: <bool>,
  3225. * wireframe: <boolean>,
  3226. * wireframeLinewidth: <float>
  3227. * }
  3228. */
  3229. THREE.MeshDepthMaterial = function ( parameters ) {
  3230. THREE.Material.call( this, parameters );
  3231. parameters = parameters || {};
  3232. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading; // doesn't really apply here, normals are not used
  3233. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3234. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3235. };
  3236. THREE.MeshDepthMaterial.prototype = new THREE.Material();
  3237. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  3238. /**
  3239. * @author mr.doob / http://mrdoob.com/
  3240. *
  3241. * parameters = {
  3242. * opacity: <float>,
  3243. * shading: THREE.FlatShading,
  3244. * blending: THREE.NormalBlending,
  3245. * depthTest: <bool>,
  3246. * wireframe: <boolean>,
  3247. * wireframeLinewidth: <float>
  3248. * }
  3249. */
  3250. THREE.MeshNormalMaterial = function ( parameters ) {
  3251. THREE.Material.call( this, parameters );
  3252. parameters = parameters || {};
  3253. this.shading = parameters.shading ? parameters.shading : THREE.FlatShading;
  3254. this.wireframe = parameters.wireframe ? parameters.wireframe : false;
  3255. this.wireframeLinewidth = parameters.wireframeLinewidth ? parameters.wireframeLinewidth : 1;
  3256. };
  3257. THREE.MeshNormalMaterial.prototype = new THREE.Material();
  3258. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  3259. /**
  3260. * @author mr.doob / http://mrdoob.com/
  3261. */
  3262. THREE.MeshFaceMaterial = function () {
  3263. };
  3264. /**
  3265. * @author mr.doob / http://mrdoob.com/
  3266. * @author alteredq / http://alteredqualia.com/
  3267. *
  3268. * parameters = {
  3269. * color: <hex>,
  3270. * opacity: <float>,
  3271. * map: new THREE.Texture( <Image> ),
  3272. *
  3273. * size: <float>,
  3274. *
  3275. * blending: THREE.NormalBlending,
  3276. * depthTest: <bool>,
  3277. *
  3278. * vertexColors: <bool>,
  3279. *
  3280. * fog: <bool>
  3281. * }
  3282. */
  3283. THREE.ParticleBasicMaterial = function ( parameters ) {
  3284. THREE.Material.call( this, parameters );
  3285. parameters = parameters || {};
  3286. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3287. this.map = parameters.map !== undefined ? parameters.map : null;
  3288. this.size = parameters.size !== undefined ? parameters.size : 1;
  3289. this.sizeAttenuation = parameters.sizeAttenuation !== undefined ? parameters.sizeAttenuation : true;
  3290. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : false;
  3291. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3292. };
  3293. THREE.ParticleBasicMaterial.prototype = new THREE.Material();
  3294. THREE.ParticleBasicMaterial.prototype.constructor = THREE.ParticleBasicMaterial;
  3295. /**
  3296. * @author mr.doob / http://mrdoob.com/
  3297. *
  3298. * parameters = {
  3299. * color: <hex>,
  3300. * program: <function>,
  3301. * opacity: <float>,
  3302. * blending: THREE.NormalBlending
  3303. * }
  3304. */
  3305. THREE.ParticleCanvasMaterial = function ( parameters ) {
  3306. THREE.Material.call( this, parameters );
  3307. parameters = parameters || {};
  3308. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3309. this.program = parameters.program !== undefined ? parameters.program : function ( context, color ) {};
  3310. };
  3311. THREE.ParticleCanvasMaterial.prototype = new THREE.Material();
  3312. THREE.ParticleCanvasMaterial.prototype.constructor = THREE.ParticleCanvasMaterial;
  3313. /**
  3314. * @author mr.doob / http://mrdoob.com/
  3315. * @author alteredq / http://alteredqualia.com/
  3316. * @author szimek / https://github.com/szimek/
  3317. */
  3318. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type ) {
  3319. this.id = THREE.TextureCount ++;
  3320. this.image = image;
  3321. this.mapping = mapping !== undefined ? mapping : new THREE.UVMapping();
  3322. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  3323. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  3324. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  3325. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  3326. this.format = format !== undefined ? format : THREE.RGBAFormat;
  3327. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  3328. this.offset = new THREE.Vector2( 0, 0 );
  3329. this.repeat = new THREE.Vector2( 1, 1 );
  3330. this.generateMipmaps = true;
  3331. this.premultiplyAlpha = false;
  3332. this.needsUpdate = false;
  3333. this.onUpdate = null;
  3334. };
  3335. THREE.Texture.prototype = {
  3336. constructor: THREE.Texture,
  3337. clone: function () {
  3338. var clonedTexture = new THREE.Texture( this.image, this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter, this.format, this.type );
  3339. clonedTexture.offset.copy( this.offset );
  3340. clonedTexture.repeat.copy( this.repeat );
  3341. return clonedTexture;
  3342. }
  3343. };
  3344. THREE.TextureCount = 0;
  3345. THREE.MultiplyOperation = 0;
  3346. THREE.MixOperation = 1;
  3347. // Mapping modes
  3348. THREE.UVMapping = function () {};
  3349. THREE.CubeReflectionMapping = function () {};
  3350. THREE.CubeRefractionMapping = function () {};
  3351. THREE.SphericalReflectionMapping = function () {};
  3352. THREE.SphericalRefractionMapping = function () {};
  3353. // Wrapping modes
  3354. THREE.RepeatWrapping = 0;
  3355. THREE.ClampToEdgeWrapping = 1;
  3356. THREE.MirroredRepeatWrapping = 2;
  3357. // Filters
  3358. THREE.NearestFilter = 3;
  3359. THREE.NearestMipMapNearestFilter = 4;
  3360. THREE.NearestMipMapLinearFilter = 5;
  3361. THREE.LinearFilter = 6;
  3362. THREE.LinearMipMapNearestFilter = 7;
  3363. THREE.LinearMipMapLinearFilter = 8;
  3364. // Types
  3365. THREE.ByteType = 9;
  3366. THREE.UnsignedByteType = 10;
  3367. THREE.ShortType = 11;
  3368. THREE.UnsignedShortType = 12;
  3369. THREE.IntType = 13;
  3370. THREE.UnsignedIntType = 14;
  3371. THREE.FloatType = 15;
  3372. // Formats
  3373. THREE.AlphaFormat = 16;
  3374. THREE.RGBFormat = 17;
  3375. THREE.RGBAFormat = 18;
  3376. THREE.LuminanceFormat = 19;
  3377. THREE.LuminanceAlphaFormat = 20;
  3378. /**
  3379. * @author alteredq / http://alteredqualia.com/
  3380. */
  3381. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter ) {
  3382. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type );
  3383. this.image = { data: data, width: width, height: height };
  3384. };
  3385. THREE.DataTexture.prototype = new THREE.Texture();
  3386. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  3387. THREE.DataTexture.prototype.clone = function () {
  3388. var clonedTexture = new THREE.DataTexture( this.image.data, this.image.width, this.image.height, this.format, this.type, this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter );
  3389. clonedTexture.offset.copy( this.offset );
  3390. clonedTexture.repeat.copy( this.repeat );
  3391. return clonedTexture;
  3392. };
  3393. /**
  3394. * @author mr.doob / http://mrdoob.com/
  3395. */
  3396. THREE.Particle = function ( material ) {
  3397. THREE.Object3D.call( this );
  3398. this.material = material;
  3399. };
  3400. THREE.Particle.prototype = new THREE.Object3D();
  3401. THREE.Particle.prototype.constructor = THREE.Particle;
  3402. /**
  3403. * @author mr.doob / http://mrdoob.com/
  3404. */
  3405. THREE.Line = function ( geometry, material, type ) {
  3406. THREE.Object3D.call( this );
  3407. this.geometry = geometry;
  3408. this.material = ( material !== undefined ) ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  3409. this.type = ( type !== undefined ) ? type : THREE.LineStrip;
  3410. if ( this.geometry ) {
  3411. if ( ! this.geometry.boundingSphere ) {
  3412. this.geometry.computeBoundingSphere();
  3413. }
  3414. }
  3415. };
  3416. THREE.LineStrip = 0;
  3417. THREE.LinePieces = 1;
  3418. THREE.Line.prototype = new THREE.Object3D();
  3419. THREE.Line.prototype.constructor = THREE.Line;
  3420. /**
  3421. * @author mr.doob / http://mrdoob.com/
  3422. * @author alteredq / http://alteredqualia.com/
  3423. * @author mikael emtinger / http://gomo.se/
  3424. */
  3425. THREE.Mesh = function ( geometry, material ) {
  3426. THREE.Object3D.call( this );
  3427. this.geometry = geometry;
  3428. this.material = ( material !== undefined ) ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, wireframe: true } );
  3429. if ( this.geometry ) {
  3430. // calc bound radius
  3431. if( ! this.geometry.boundingSphere ) {
  3432. this.geometry.computeBoundingSphere();
  3433. }
  3434. this.boundRadius = geometry.boundingSphere.radius;
  3435. // setup morph targets
  3436. if( this.geometry.morphTargets.length ) {
  3437. this.morphTargetBase = -1;
  3438. this.morphTargetForcedOrder = [];
  3439. this.morphTargetInfluences = [];
  3440. this.morphTargetDictionary = {};
  3441. for( var m = 0; m < this.geometry.morphTargets.length; m ++ ) {
  3442. this.morphTargetInfluences.push( 0 );
  3443. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  3444. }
  3445. }
  3446. }
  3447. }
  3448. THREE.Mesh.prototype = new THREE.Object3D();
  3449. THREE.Mesh.prototype.constructor = THREE.Mesh;
  3450. THREE.Mesh.prototype.supr = THREE.Object3D.prototype;
  3451. /*
  3452. * Get Morph Target Index by Name
  3453. */
  3454. THREE.Mesh.prototype.getMorphTargetIndexByName = function( name ) {
  3455. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  3456. return this.morphTargetDictionary[ name ];
  3457. }
  3458. console.log( "THREE.Mesh.getMorphTargetIndexByName: morph target " + name + " does not exist. Returning 0." );
  3459. return 0;
  3460. }
  3461. /**
  3462. * @author mikael emtinger / http://gomo.se/
  3463. * @author alteredq / http://alteredqualia.com/
  3464. */
  3465. THREE.Bone = function( belongsToSkin ) {
  3466. THREE.Object3D.call( this );
  3467. this.skin = belongsToSkin;
  3468. this.skinMatrix = new THREE.Matrix4();
  3469. };
  3470. THREE.Bone.prototype = new THREE.Object3D();
  3471. THREE.Bone.prototype.constructor = THREE.Bone;
  3472. THREE.Bone.prototype.supr = THREE.Object3D.prototype;
  3473. THREE.Bone.prototype.update = function( parentSkinMatrix, forceUpdate ) {
  3474. // update local
  3475. if ( this.matrixAutoUpdate ) {
  3476. forceUpdate |= this.updateMatrix();
  3477. }
  3478. // update skin matrix
  3479. if ( forceUpdate || this.matrixWorldNeedsUpdate ) {
  3480. if( parentSkinMatrix ) {
  3481. this.skinMatrix.multiply( parentSkinMatrix, this.matrix );
  3482. } else {
  3483. this.skinMatrix.copy( this.matrix );
  3484. }
  3485. this.matrixWorldNeedsUpdate = false;
  3486. forceUpdate = true;
  3487. }
  3488. // update children
  3489. var child, i, l = this.children.length;
  3490. for ( i = 0; i < l; i ++ ) {
  3491. this.children[ i ].update( this.skinMatrix, forceUpdate );
  3492. }
  3493. };
  3494. /**
  3495. * @author mikael emtinger / http://gomo.se/
  3496. */
  3497. THREE.Sprite = function ( parameters ) {
  3498. THREE.Object3D.call( this );
  3499. this.color = ( parameters.color !== undefined ) ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3500. this.map = ( parameters.map !== undefined ) ? parameters.map : new THREE.Texture();
  3501. this.blending = ( parameters.blending !== undefined ) ? parameters.blending : THREE.NormalBlending;
  3502. this.blendSrc = parameters.blendSrc !== undefined ? parameters.blendSrc : THREE.SrcAlphaFactor;
  3503. this.blendDst = parameters.blendDst !== undefined ? parameters.blendDst : THREE.OneMinusSrcAlphaFactor;
  3504. this.blendEquation = parameters.blendEquation !== undefined ? parameters.blendEquation : THREE.AddEquation;
  3505. this.useScreenCoordinates = ( parameters.useScreenCoordinates !== undefined ) ? parameters.useScreenCoordinates : true;
  3506. this.mergeWith3D = ( parameters.mergeWith3D !== undefined ) ? parameters.mergeWith3D : !this.useScreenCoordinates;
  3507. this.affectedByDistance = ( parameters.affectedByDistance !== undefined ) ? parameters.affectedByDistance : !this.useScreenCoordinates;
  3508. this.scaleByViewport = ( parameters.scaleByViewport !== undefined ) ? parameters.scaleByViewport : !this.affectedByDistance;
  3509. this.alignment = ( parameters.alignment instanceof THREE.Vector2 ) ? parameters.alignment : THREE.SpriteAlignment.center;
  3510. this.rotation3d = this.rotation;
  3511. this.rotation = 0;
  3512. this.opacity = 1;
  3513. this.uvOffset = new THREE.Vector2( 0, 0 );
  3514. this.uvScale = new THREE.Vector2( 1, 1 );
  3515. };
  3516. THREE.Sprite.prototype = new THREE.Object3D();
  3517. THREE.Sprite.prototype.constructor = THREE.Sprite;
  3518. /*
  3519. * Custom update matrix
  3520. */
  3521. THREE.Sprite.prototype.updateMatrix = function () {
  3522. this.matrix.setPosition( this.position );
  3523. this.rotation3d.set( 0, 0, this.rotation );
  3524. this.matrix.setRotationFromEuler( this.rotation3d );
  3525. if ( this.scale.x !== 1 || this.scale.y !== 1 ) {
  3526. this.matrix.scale( this.scale );
  3527. this.boundRadiusScale = Math.max( this.scale.x, this.scale.y );
  3528. }
  3529. this.matrixWorldNeedsUpdate = true;
  3530. };
  3531. /*
  3532. * Alignment
  3533. */
  3534. THREE.SpriteAlignment = {};
  3535. THREE.SpriteAlignment.topLeft = new THREE.Vector2( 1, -1 );
  3536. THREE.SpriteAlignment.topCenter = new THREE.Vector2( 0, -1 );
  3537. THREE.SpriteAlignment.topRight = new THREE.Vector2( -1, -1 );
  3538. THREE.SpriteAlignment.centerLeft = new THREE.Vector2( 1, 0 );
  3539. THREE.SpriteAlignment.center = new THREE.Vector2( 0, 0 );
  3540. THREE.SpriteAlignment.centerRight = new THREE.Vector2( -1, 0 );
  3541. THREE.SpriteAlignment.bottomLeft = new THREE.Vector2( 1, 1 );
  3542. THREE.SpriteAlignment.bottomCenter = new THREE.Vector2( 0, 1 );
  3543. THREE.SpriteAlignment.bottomRight = new THREE.Vector2( -1, 1 );
  3544. /**
  3545. * @author mr.doob / http://mrdoob.com/
  3546. */
  3547. THREE.Scene = function () {
  3548. THREE.Object3D.call( this );
  3549. this.fog = null;
  3550. this.overrideMaterial = null;
  3551. this.matrixAutoUpdate = false;
  3552. this.__objects = [];
  3553. this.__lights = [];
  3554. this.__objectsAdded = [];
  3555. this.__objectsRemoved = [];
  3556. };
  3557. THREE.Scene.prototype = new THREE.Object3D();
  3558. THREE.Scene.prototype.constructor = THREE.Scene;
  3559. THREE.Scene.prototype.__addObject = function ( object ) {
  3560. if ( object instanceof THREE.Light ) {
  3561. if ( this.__lights.indexOf( object ) === - 1 ) {
  3562. this.__lights.push( object );
  3563. }
  3564. } else if ( !( object instanceof THREE.Camera || object instanceof THREE.Bone ) ) {
  3565. if ( this.__objects.indexOf( object ) === - 1 ) {
  3566. this.__objects.push( object );
  3567. this.__objectsAdded.push( object );
  3568. // check if previously removed
  3569. var i = this.__objectsRemoved.indexOf( object );
  3570. if ( i !== -1 ) {
  3571. this.__objectsRemoved.splice( i, 1 );
  3572. }
  3573. }
  3574. }
  3575. for ( var c = 0; c < object.children.length; c ++ ) {
  3576. this.__addObject( object.children[ c ] );
  3577. }
  3578. };
  3579. THREE.Scene.prototype.__removeObject = function ( object ) {
  3580. if ( object instanceof THREE.Light ) {
  3581. var i = this.__lights.indexOf( object );
  3582. if ( i !== -1 ) {
  3583. this.__lights.splice( i, 1 );
  3584. }
  3585. } else if ( !( object instanceof THREE.Camera ) ) {
  3586. var i = this.__objects.indexOf( object );
  3587. if( i !== -1 ) {
  3588. this.__objects.splice( i, 1 );
  3589. this.__objectsRemoved.push( object );
  3590. // check if previously added
  3591. var ai = this.__objectsAdded.indexOf( object );
  3592. if ( ai !== -1 ) {
  3593. this.__objectsAdded.splice( ai, 1 );
  3594. }
  3595. }
  3596. }
  3597. for ( var c = 0; c < object.children.length; c ++ ) {
  3598. this.__removeObject( object.children[ c ] );
  3599. }
  3600. };
  3601. /**
  3602. * @author mr.doob / http://mrdoob.com/
  3603. */
  3604. THREE.CanvasRenderer = function ( parameters ) {
  3605. console.log( 'THREE.CanvasRenderer', THREE.REVISION );
  3606. parameters = parameters || {};
  3607. var _this = this,
  3608. _renderData, _elements, _lights,
  3609. _projector = new THREE.Projector(),
  3610. _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  3611. _canvasWidth, _canvasHeight, _canvasWidthHalf, _canvasHeightHalf,
  3612. _context = _canvas.getContext( '2d' ),
  3613. _clearColor = new THREE.Color( 0x000000 ),
  3614. _clearOpacity = 0,
  3615. _contextGlobalAlpha = 1,
  3616. _contextGlobalCompositeOperation = 0,
  3617. _contextStrokeStyle = null,
  3618. _contextFillStyle = null,
  3619. _contextLineWidth = null,
  3620. _contextLineCap = null,
  3621. _contextLineJoin = null,
  3622. _v1, _v2, _v3, _v4,
  3623. _v5 = new THREE.RenderableVertex(),
  3624. _v6 = new THREE.RenderableVertex(),
  3625. _v1x, _v1y, _v2x, _v2y, _v3x, _v3y,
  3626. _v4x, _v4y, _v5x, _v5y, _v6x, _v6y,
  3627. _color = new THREE.Color(),
  3628. _color1 = new THREE.Color(),
  3629. _color2 = new THREE.Color(),
  3630. _color3 = new THREE.Color(),
  3631. _color4 = new THREE.Color(),
  3632. _patterns = [], _imagedatas = [],
  3633. _near, _far,
  3634. _image, _uvs,
  3635. _uv1x, _uv1y, _uv2x, _uv2y, _uv3x, _uv3y,
  3636. _clipRect = new THREE.Rectangle(),
  3637. _clearRect = new THREE.Rectangle(),
  3638. _bboxRect = new THREE.Rectangle(),
  3639. _enableLighting = false,
  3640. _ambientLight = new THREE.Color(),
  3641. _directionalLights = new THREE.Color(),
  3642. _pointLights = new THREE.Color(),
  3643. _pi2 = Math.PI * 2,
  3644. _vector3 = new THREE.Vector3(), // Needed for PointLight
  3645. _pixelMap, _pixelMapContext, _pixelMapImage, _pixelMapData,
  3646. _gradientMap, _gradientMapContext, _gradientMapQuality = 16;
  3647. _pixelMap = document.createElement( 'canvas' );
  3648. _pixelMap.width = _pixelMap.height = 2;
  3649. _pixelMapContext = _pixelMap.getContext( '2d' );
  3650. _pixelMapContext.fillStyle = 'rgba(0,0,0,1)';
  3651. _pixelMapContext.fillRect( 0, 0, 2, 2 );
  3652. _pixelMapImage = _pixelMapContext.getImageData( 0, 0, 2, 2 );
  3653. _pixelMapData = _pixelMapImage.data;
  3654. _gradientMap = document.createElement( 'canvas' );
  3655. _gradientMap.width = _gradientMap.height = _gradientMapQuality;
  3656. _gradientMapContext = _gradientMap.getContext( '2d' );
  3657. _gradientMapContext.translate( - _gradientMapQuality / 2, - _gradientMapQuality / 2 );
  3658. _gradientMapContext.scale( _gradientMapQuality, _gradientMapQuality );
  3659. _gradientMapQuality --; // Fix UVs
  3660. this.domElement = _canvas;
  3661. this.autoClear = true;
  3662. this.sortObjects = true;
  3663. this.sortElements = true;
  3664. this.info = {
  3665. render: {
  3666. vertices: 0,
  3667. faces: 0
  3668. }
  3669. }
  3670. this.setSize = function ( width, height ) {
  3671. _canvasWidth = width;
  3672. _canvasHeight = height;
  3673. _canvasWidthHalf = Math.floor( _canvasWidth / 2 );
  3674. _canvasHeightHalf = Math.floor( _canvasHeight / 2 );
  3675. _canvas.width = _canvasWidth;
  3676. _canvas.height = _canvasHeight;
  3677. _clipRect.set( - _canvasWidthHalf, - _canvasHeightHalf, _canvasWidthHalf, _canvasHeightHalf );
  3678. _clearRect.set( - _canvasWidthHalf, - _canvasHeightHalf, _canvasWidthHalf, _canvasHeightHalf );
  3679. _contextGlobalAlpha = 1;
  3680. _contextGlobalCompositeOperation = 0;
  3681. _contextStrokeStyle = null;
  3682. _contextFillStyle = null;
  3683. _contextLineWidth = null;
  3684. _contextLineCap = null;
  3685. _contextLineJoin = null;
  3686. };
  3687. this.setClearColor = function ( color, opacity ) {
  3688. _clearColor.copy( color );
  3689. _clearOpacity = opacity !== undefined ? opacity : 1;
  3690. _clearRect.set( - _canvasWidthHalf, - _canvasHeightHalf, _canvasWidthHalf, _canvasHeightHalf );
  3691. };
  3692. this.setClearColorHex = function ( hex, opacity ) {
  3693. _clearColor.setHex( hex );
  3694. _clearOpacity = opacity !== undefined ? opacity : 1;
  3695. _clearRect.set( - _canvasWidthHalf, - _canvasHeightHalf, _canvasWidthHalf, _canvasHeightHalf );
  3696. };
  3697. this.clear = function () {
  3698. _context.setTransform( 1, 0, 0, - 1, _canvasWidthHalf, _canvasHeightHalf );
  3699. if ( !_clearRect.isEmpty() ) {
  3700. _clearRect.minSelf( _clipRect );
  3701. _clearRect.inflate( 2 );
  3702. if ( _clearOpacity < 1 ) {
  3703. _context.clearRect( Math.floor( _clearRect.getX() ), Math.floor( _clearRect.getY() ), Math.floor( _clearRect.getWidth() ), Math.floor( _clearRect.getHeight() ) );
  3704. }
  3705. if ( _clearOpacity > 0 ) {
  3706. setBlending( THREE.NormalBlending );
  3707. setOpacity( 1 );
  3708. setFillStyle( 'rgba(' + Math.floor( _clearColor.r * 255 ) + ',' + Math.floor( _clearColor.g * 255 ) + ',' + Math.floor( _clearColor.b * 255 ) + ',' + _clearOpacity + ')' );
  3709. _context.fillRect( Math.floor( _clearRect.getX() ), Math.floor( _clearRect.getY() ), Math.floor( _clearRect.getWidth() ), Math.floor( _clearRect.getHeight() ) );
  3710. }
  3711. _clearRect.empty();
  3712. }
  3713. };
  3714. this.render = function ( scene, camera ) {
  3715. var e, el, element, material;
  3716. this.autoClear ? this.clear() : _context.setTransform( 1, 0, 0, - 1, _canvasWidthHalf, _canvasHeightHalf );
  3717. _this.info.render.vertices = 0;
  3718. _this.info.render.faces = 0;
  3719. _renderData = _projector.projectScene( scene, camera, this.sortElements );
  3720. _elements = _renderData.elements;
  3721. _lights = _renderData.lights;
  3722. /* DEBUG
  3723. _context.fillStyle = 'rgba( 0, 255, 255, 0.5 )';
  3724. _context.fillRect( _clipRect.getX(), _clipRect.getY(), _clipRect.getWidth(), _clipRect.getHeight() );
  3725. */
  3726. _enableLighting = _lights.length > 0;
  3727. if ( _enableLighting ) {
  3728. calculateLights( _lights );
  3729. }
  3730. for ( e = 0, el = _elements.length; e < el; e++ ) {
  3731. element = _elements[ e ];
  3732. material = element.material;
  3733. material = material instanceof THREE.MeshFaceMaterial ? element.faceMaterial : material;
  3734. if ( material == null || material.opacity == 0 ) continue;
  3735. _bboxRect.empty();
  3736. if ( element instanceof THREE.RenderableParticle ) {
  3737. _v1 = element;
  3738. _v1.x *= _canvasWidthHalf; _v1.y *= _canvasHeightHalf;
  3739. renderParticle( _v1, element, material, scene );
  3740. } else if ( element instanceof THREE.RenderableLine ) {
  3741. _v1 = element.v1; _v2 = element.v2;
  3742. _v1.positionScreen.x *= _canvasWidthHalf; _v1.positionScreen.y *= _canvasHeightHalf;
  3743. _v2.positionScreen.x *= _canvasWidthHalf; _v2.positionScreen.y *= _canvasHeightHalf;
  3744. _bboxRect.addPoint( _v1.positionScreen.x, _v1.positionScreen.y );
  3745. _bboxRect.addPoint( _v2.positionScreen.x, _v2.positionScreen.y );
  3746. if ( _clipRect.intersects( _bboxRect ) ) {
  3747. renderLine( _v1, _v2, element, material, scene );
  3748. }
  3749. } else if ( element instanceof THREE.RenderableFace3 ) {
  3750. _v1 = element.v1; _v2 = element.v2; _v3 = element.v3;
  3751. _v1.positionScreen.x *= _canvasWidthHalf; _v1.positionScreen.y *= _canvasHeightHalf;
  3752. _v2.positionScreen.x *= _canvasWidthHalf; _v2.positionScreen.y *= _canvasHeightHalf;
  3753. _v3.positionScreen.x *= _canvasWidthHalf; _v3.positionScreen.y *= _canvasHeightHalf;
  3754. if ( material.overdraw ) {
  3755. expand( _v1.positionScreen, _v2.positionScreen );
  3756. expand( _v2.positionScreen, _v3.positionScreen );
  3757. expand( _v3.positionScreen, _v1.positionScreen );
  3758. }
  3759. _bboxRect.add3Points( _v1.positionScreen.x, _v1.positionScreen.y,
  3760. _v2.positionScreen.x, _v2.positionScreen.y,
  3761. _v3.positionScreen.x, _v3.positionScreen.y );
  3762. if ( _clipRect.intersects( _bboxRect ) ) {
  3763. renderFace3( _v1, _v2, _v3, 0, 1, 2, element, material, scene );
  3764. }
  3765. } else if ( element instanceof THREE.RenderableFace4 ) {
  3766. _v1 = element.v1; _v2 = element.v2; _v3 = element.v3; _v4 = element.v4;
  3767. _v1.positionScreen.x *= _canvasWidthHalf; _v1.positionScreen.y *= _canvasHeightHalf;
  3768. _v2.positionScreen.x *= _canvasWidthHalf; _v2.positionScreen.y *= _canvasHeightHalf;
  3769. _v3.positionScreen.x *= _canvasWidthHalf; _v3.positionScreen.y *= _canvasHeightHalf;
  3770. _v4.positionScreen.x *= _canvasWidthHalf; _v4.positionScreen.y *= _canvasHeightHalf;
  3771. _v5.positionScreen.copy( _v2.positionScreen );
  3772. _v6.positionScreen.copy( _v4.positionScreen );
  3773. if ( material.overdraw ) {
  3774. expand( _v1.positionScreen, _v2.positionScreen );
  3775. expand( _v2.positionScreen, _v4.positionScreen );
  3776. expand( _v4.positionScreen, _v1.positionScreen );
  3777. expand( _v3.positionScreen, _v5.positionScreen );
  3778. expand( _v3.positionScreen, _v6.positionScreen );
  3779. }
  3780. _bboxRect.addPoint( _v1.positionScreen.x, _v1.positionScreen.y );
  3781. _bboxRect.addPoint( _v2.positionScreen.x, _v2.positionScreen.y );
  3782. _bboxRect.addPoint( _v3.positionScreen.x, _v3.positionScreen.y );
  3783. _bboxRect.addPoint( _v4.positionScreen.x, _v4.positionScreen.y );
  3784. if ( _clipRect.intersects( _bboxRect ) ) {
  3785. renderFace4( _v1, _v2, _v3, _v4, _v5, _v6, element, material, scene );
  3786. }
  3787. }
  3788. /*
  3789. _context.lineWidth = 1;
  3790. _context.strokeStyle = 'rgba( 0, 255, 0, 0.5 )';
  3791. _context.strokeRect( _bboxRect.getX(), _bboxRect.getY(), _bboxRect.getWidth(), _bboxRect.getHeight() );
  3792. */
  3793. _clearRect.addRectangle( _bboxRect );
  3794. }
  3795. /* DEBUG
  3796. _context.lineWidth = 1;
  3797. _context.strokeStyle = 'rgba( 255, 0, 0, 0.5 )';
  3798. _context.strokeRect( _clearRect.getX(), _clearRect.getY(), _clearRect.getWidth(), _clearRect.getHeight() );
  3799. */
  3800. _context.setTransform( 1, 0, 0, 1, 0, 0 );
  3801. //
  3802. function calculateLights( lights ) {
  3803. var l, ll, light, lightColor;
  3804. _ambientLight.setRGB( 0, 0, 0 );
  3805. _directionalLights.setRGB( 0, 0, 0 );
  3806. _pointLights.setRGB( 0, 0, 0 );
  3807. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  3808. light = lights[ l ];
  3809. lightColor = light.color;
  3810. if ( light instanceof THREE.AmbientLight ) {
  3811. _ambientLight.r += lightColor.r;
  3812. _ambientLight.g += lightColor.g;
  3813. _ambientLight.b += lightColor.b;
  3814. } else if ( light instanceof THREE.DirectionalLight ) {
  3815. // for particles
  3816. _directionalLights.r += lightColor.r;
  3817. _directionalLights.g += lightColor.g;
  3818. _directionalLights.b += lightColor.b;
  3819. } else if ( light instanceof THREE.PointLight ) {
  3820. // for particles
  3821. _pointLights.r += lightColor.r;
  3822. _pointLights.g += lightColor.g;
  3823. _pointLights.b += lightColor.b;
  3824. }
  3825. }
  3826. }
  3827. function calculateLight( lights, position, normal, color ) {
  3828. var l, ll, light, lightColor, lightPosition, amount;
  3829. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  3830. light = lights[ l ];
  3831. lightColor = light.color;
  3832. if ( light instanceof THREE.DirectionalLight ) {
  3833. lightPosition = light.matrixWorld.getPosition();
  3834. amount = normal.dot( lightPosition );
  3835. if ( amount <= 0 ) continue;
  3836. amount *= light.intensity;
  3837. color.r += lightColor.r * amount;
  3838. color.g += lightColor.g * amount;
  3839. color.b += lightColor.b * amount;
  3840. } else if ( light instanceof THREE.PointLight ) {
  3841. lightPosition = light.matrixWorld.getPosition();
  3842. amount = normal.dot( _vector3.sub( lightPosition, position ).normalize() );
  3843. if ( amount <= 0 ) continue;
  3844. amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( lightPosition ) / light.distance, 1 );
  3845. if ( amount == 0 ) continue;
  3846. amount *= light.intensity;
  3847. color.r += lightColor.r * amount;
  3848. color.g += lightColor.g * amount;
  3849. color.b += lightColor.b * amount;
  3850. }
  3851. }
  3852. }
  3853. function renderParticle ( v1, element, material, scene ) {
  3854. setOpacity( material.opacity );
  3855. setBlending( material.blending );
  3856. var width, height, scaleX, scaleY,
  3857. bitmap, bitmapWidth, bitmapHeight;
  3858. if ( material instanceof THREE.ParticleBasicMaterial ) {
  3859. if ( material.map ) {
  3860. bitmap = material.map.image;
  3861. bitmapWidth = bitmap.width >> 1;
  3862. bitmapHeight = bitmap.height >> 1;
  3863. scaleX = element.scale.x * _canvasWidthHalf;
  3864. scaleY = element.scale.y * _canvasHeightHalf;
  3865. width = scaleX * bitmapWidth;
  3866. height = scaleY * bitmapHeight;
  3867. // TODO: Rotations break this...
  3868. _bboxRect.set( v1.x - width, v1.y - height, v1.x + width, v1.y + height );
  3869. if ( !_clipRect.intersects( _bboxRect ) ) {
  3870. return;
  3871. }
  3872. _context.save();
  3873. _context.translate( v1.x, v1.y );
  3874. _context.rotate( - element.rotation );
  3875. _context.scale( scaleX, - scaleY );
  3876. _context.translate( - bitmapWidth, - bitmapHeight );
  3877. _context.drawImage( bitmap, 0, 0 );
  3878. _context.restore();
  3879. }
  3880. /* DEBUG
  3881. _context.beginPath();
  3882. _context.moveTo( v1.x - 10, v1.y );
  3883. _context.lineTo( v1.x + 10, v1.y );
  3884. _context.moveTo( v1.x, v1.y - 10 );
  3885. _context.lineTo( v1.x, v1.y + 10 );
  3886. _context.closePath();
  3887. _context.strokeStyle = 'rgb(255,255,0)';
  3888. _context.stroke();
  3889. */
  3890. } else if ( material instanceof THREE.ParticleCanvasMaterial ) {
  3891. width = element.scale.x * _canvasWidthHalf;
  3892. height = element.scale.y * _canvasHeightHalf;
  3893. _bboxRect.set( v1.x - width, v1.y - height, v1.x + width, v1.y + height );
  3894. if ( !_clipRect.intersects( _bboxRect ) ) {
  3895. return;
  3896. }
  3897. setStrokeStyle( material.color.getContextStyle() );
  3898. setFillStyle( material.color.getContextStyle() );
  3899. _context.save();
  3900. _context.translate( v1.x, v1.y );
  3901. _context.rotate( - element.rotation );
  3902. _context.scale( width, height );
  3903. material.program( _context );
  3904. _context.restore();
  3905. }
  3906. }
  3907. function renderLine( v1, v2, element, material, scene ) {
  3908. setOpacity( material.opacity );
  3909. setBlending( material.blending );
  3910. _context.beginPath();
  3911. _context.moveTo( v1.positionScreen.x, v1.positionScreen.y );
  3912. _context.lineTo( v2.positionScreen.x, v2.positionScreen.y );
  3913. _context.closePath();
  3914. if ( material instanceof THREE.LineBasicMaterial ) {
  3915. setLineWidth( material.linewidth );
  3916. setLineCap( material.linecap );
  3917. setLineJoin( material.linejoin );
  3918. setStrokeStyle( material.color.getContextStyle() );
  3919. _context.stroke();
  3920. _bboxRect.inflate( material.linewidth * 2 );
  3921. }
  3922. }
  3923. function renderFace3( v1, v2, v3, uv1, uv2, uv3, element, material, scene ) {
  3924. _this.info.render.vertices += 3;
  3925. _this.info.render.faces ++;
  3926. setOpacity( material.opacity );
  3927. setBlending( material.blending );
  3928. _v1x = v1.positionScreen.x; _v1y = v1.positionScreen.y;
  3929. _v2x = v2.positionScreen.x; _v2y = v2.positionScreen.y;
  3930. _v3x = v3.positionScreen.x; _v3y = v3.positionScreen.y;
  3931. drawTriangle( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y );
  3932. if ( material instanceof THREE.MeshBasicMaterial ) {
  3933. if ( material.map/* && !material.wireframe*/ ) {
  3934. if ( material.map.mapping instanceof THREE.UVMapping ) {
  3935. _uvs = element.uvs[ 0 ];
  3936. patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uvs[ uv1 ].u, _uvs[ uv1 ].v, _uvs[ uv2 ].u, _uvs[ uv2 ].v, _uvs[ uv3 ].u, _uvs[ uv3 ].v, material.map );
  3937. }
  3938. } else if ( material.envMap ) {
  3939. if ( material.envMap.mapping instanceof THREE.SphericalReflectionMapping ) {
  3940. var cameraMatrix = camera.matrixWorldInverse;
  3941. _vector3.copy( element.vertexNormalsWorld[ uv1 ] );
  3942. _uv1x = ( _vector3.x * cameraMatrix.elements[0] + _vector3.y * cameraMatrix.elements[4] + _vector3.z * cameraMatrix.elements[8] ) * 0.5 + 0.5;
  3943. _uv1y = - ( _vector3.x * cameraMatrix.elements[1] + _vector3.y * cameraMatrix.elements[5] + _vector3.z * cameraMatrix.elements[9] ) * 0.5 + 0.5;
  3944. _vector3.copy( element.vertexNormalsWorld[ uv2 ] );
  3945. _uv2x = ( _vector3.x * cameraMatrix.elements[0] + _vector3.y * cameraMatrix.elements[4] + _vector3.z * cameraMatrix.elements[8] ) * 0.5 + 0.5;
  3946. _uv2y = - ( _vector3.x * cameraMatrix.elements[1] + _vector3.y * cameraMatrix.elements[5] + _vector3.z * cameraMatrix.elements[9] ) * 0.5 + 0.5;
  3947. _vector3.copy( element.vertexNormalsWorld[ uv3 ] );
  3948. _uv3x = ( _vector3.x * cameraMatrix.elements[0] + _vector3.y * cameraMatrix.elements[4] + _vector3.z * cameraMatrix.elements[8] ) * 0.5 + 0.5;
  3949. _uv3y = - ( _vector3.x * cameraMatrix.elements[1] + _vector3.y * cameraMatrix.elements[5] + _vector3.z * cameraMatrix.elements[9] ) * 0.5 + 0.5;
  3950. patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uv1x, _uv1y, _uv2x, _uv2y, _uv3x, _uv3y, material.envMap );
  3951. }/* else if ( material.envMap.mapping == THREE.SphericalRefractionMapping ) {
  3952. }*/
  3953. } else {
  3954. material.wireframe ? strokePath( material.color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( material.color );
  3955. }
  3956. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  3957. if ( material.map && !material.wireframe ) {
  3958. if ( material.map.mapping instanceof THREE.UVMapping ) {
  3959. _uvs = element.uvs[ 0 ];
  3960. patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uvs[ uv1 ].u, _uvs[ uv1 ].v, _uvs[ uv2 ].u, _uvs[ uv2 ].v, _uvs[ uv3 ].u, _uvs[ uv3 ].v, material.map );
  3961. }
  3962. setBlending( THREE.SubtractiveBlending );
  3963. }
  3964. if ( _enableLighting ) {
  3965. if ( !material.wireframe && material.shading == THREE.SmoothShading && element.vertexNormalsWorld.length == 3 ) {
  3966. _color1.r = _color2.r = _color3.r = _ambientLight.r;
  3967. _color1.g = _color2.g = _color3.g = _ambientLight.g;
  3968. _color1.b = _color2.b = _color3.b = _ambientLight.b;
  3969. calculateLight( _lights, element.v1.positionWorld, element.vertexNormalsWorld[ 0 ], _color1 );
  3970. calculateLight( _lights, element.v2.positionWorld, element.vertexNormalsWorld[ 1 ], _color2 );
  3971. calculateLight( _lights, element.v3.positionWorld, element.vertexNormalsWorld[ 2 ], _color3 );
  3972. _color1.r = Math.max( 0, Math.min( material.color.r * _color1.r, 1 ) );
  3973. _color1.g = Math.max( 0, Math.min( material.color.g * _color1.g, 1 ) );
  3974. _color1.b = Math.max( 0, Math.min( material.color.b * _color1.b, 1 ) );
  3975. _color2.r = Math.max( 0, Math.min( material.color.r * _color2.r, 1 ) );
  3976. _color2.g = Math.max( 0, Math.min( material.color.g * _color2.g, 1 ) );
  3977. _color2.b = Math.max( 0, Math.min( material.color.b * _color2.b, 1 ) );
  3978. _color3.r = Math.max( 0, Math.min( material.color.r * _color3.r, 1 ) );
  3979. _color3.g = Math.max( 0, Math.min( material.color.g * _color3.g, 1 ) );
  3980. _color3.b = Math.max( 0, Math.min( material.color.b * _color3.b, 1 ) );
  3981. _color4.r = ( _color2.r + _color3.r ) * 0.5;
  3982. _color4.g = ( _color2.g + _color3.g ) * 0.5;
  3983. _color4.b = ( _color2.b + _color3.b ) * 0.5;
  3984. _image = getGradientTexture( _color1, _color2, _color3, _color4 );
  3985. clipImage( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, 0, 0, 1, 0, 0, 1, _image );
  3986. } else {
  3987. _color.r = _ambientLight.r;
  3988. _color.g = _ambientLight.g;
  3989. _color.b = _ambientLight.b;
  3990. calculateLight( _lights, element.centroidWorld, element.normalWorld, _color );
  3991. _color.r = Math.max( 0, Math.min( material.color.r * _color.r, 1 ) );
  3992. _color.g = Math.max( 0, Math.min( material.color.g * _color.g, 1 ) );
  3993. _color.b = Math.max( 0, Math.min( material.color.b * _color.b, 1 ) );
  3994. material.wireframe ? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( _color );
  3995. }
  3996. } else {
  3997. material.wireframe ? strokePath( material.color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( material.color );
  3998. }
  3999. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  4000. _near = camera.near;
  4001. _far = camera.far;
  4002. _color1.r = _color1.g = _color1.b = 1 - smoothstep( v1.positionScreen.z, _near, _far );
  4003. _color2.r = _color2.g = _color2.b = 1 - smoothstep( v2.positionScreen.z, _near, _far );
  4004. _color3.r = _color3.g = _color3.b = 1 - smoothstep( v3.positionScreen.z, _near, _far );
  4005. _color4.r = ( _color2.r + _color3.r ) * 0.5;
  4006. _color4.g = ( _color2.g + _color3.g ) * 0.5;
  4007. _color4.b = ( _color2.b + _color3.b ) * 0.5;
  4008. _image = getGradientTexture( _color1, _color2, _color3, _color4 );
  4009. clipImage( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, 0, 0, 1, 0, 0, 1, _image );
  4010. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  4011. _color.r = normalToComponent( element.normalWorld.x );
  4012. _color.g = normalToComponent( element.normalWorld.y );
  4013. _color.b = normalToComponent( element.normalWorld.z );
  4014. material.wireframe ? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( _color );
  4015. }
  4016. }
  4017. function renderFace4( v1, v2, v3, v4, v5, v6, element, material, scene ) {
  4018. _this.info.render.vertices += 4;
  4019. _this.info.render.faces ++;
  4020. setOpacity( material.opacity );
  4021. setBlending( material.blending );
  4022. if ( material.map || material.envMap ) {
  4023. // Let renderFace3() handle this
  4024. renderFace3( v1, v2, v4, 0, 1, 3, element, material, scene );
  4025. renderFace3( v5, v3, v6, 1, 2, 3, element, material, scene );
  4026. return;
  4027. }
  4028. _v1x = v1.positionScreen.x; _v1y = v1.positionScreen.y;
  4029. _v2x = v2.positionScreen.x; _v2y = v2.positionScreen.y;
  4030. _v3x = v3.positionScreen.x; _v3y = v3.positionScreen.y;
  4031. _v4x = v4.positionScreen.x; _v4y = v4.positionScreen.y;
  4032. _v5x = v5.positionScreen.x; _v5y = v5.positionScreen.y;
  4033. _v6x = v6.positionScreen.x; _v6y = v6.positionScreen.y;
  4034. if ( material instanceof THREE.MeshBasicMaterial ) {
  4035. drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y );
  4036. material.wireframe ? strokePath( material.color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( material.color );
  4037. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  4038. if ( _enableLighting ) {
  4039. if ( !material.wireframe && material.shading == THREE.SmoothShading && element.vertexNormalsWorld.length == 4 ) {
  4040. _color1.r = _color2.r = _color3.r = _color4.r = _ambientLight.r;
  4041. _color1.g = _color2.g = _color3.g = _color4.g = _ambientLight.g;
  4042. _color1.b = _color2.b = _color3.b = _color4.b = _ambientLight.b;
  4043. calculateLight( _lights, element.v1.positionWorld, element.vertexNormalsWorld[ 0 ], _color1 );
  4044. calculateLight( _lights, element.v2.positionWorld, element.vertexNormalsWorld[ 1 ], _color2 );
  4045. calculateLight( _lights, element.v4.positionWorld, element.vertexNormalsWorld[ 3 ], _color3 );
  4046. calculateLight( _lights, element.v3.positionWorld, element.vertexNormalsWorld[ 2 ], _color4 );
  4047. _color1.r = Math.max( 0, Math.min( material.color.r * _color1.r, 1 ) );
  4048. _color1.g = Math.max( 0, Math.min( material.color.g * _color1.g, 1 ) );
  4049. _color1.b = Math.max( 0, Math.min( material.color.b * _color1.b, 1 ) );
  4050. _color2.r = Math.max( 0, Math.min( material.color.r * _color2.r, 1 ) );
  4051. _color2.g = Math.max( 0, Math.min( material.color.g * _color2.g, 1 ) );
  4052. _color2.b = Math.max( 0, Math.min( material.color.b * _color2.b, 1 ) );
  4053. _color3.r = Math.max( 0, Math.min( material.color.r * _color3.r, 1 ) );
  4054. _color3.g = Math.max( 0, Math.min( material.color.g * _color3.g, 1 ) );
  4055. _color3.b = Math.max( 0, Math.min( material.color.b * _color3.b, 1 ) );
  4056. _color4.r = Math.max( 0, Math.min( material.color.r * _color4.r, 1 ) );
  4057. _color4.g = Math.max( 0, Math.min( material.color.g * _color4.g, 1 ) );
  4058. _color4.b = Math.max( 0, Math.min( material.color.b * _color4.b, 1 ) );
  4059. _image = getGradientTexture( _color1, _color2, _color3, _color4 );
  4060. // TODO: UVs are incorrect, v4->v3?
  4061. drawTriangle( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y );
  4062. clipImage( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y, 0, 0, 1, 0, 0, 1, _image );
  4063. drawTriangle( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y );
  4064. clipImage( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y, 1, 0, 1, 1, 0, 1, _image );
  4065. } else {
  4066. _color.r = _ambientLight.r;
  4067. _color.g = _ambientLight.g;
  4068. _color.b = _ambientLight.b;
  4069. calculateLight( _lights, element.centroidWorld, element.normalWorld, _color );
  4070. _color.r = Math.max( 0, Math.min( material.color.r * _color.r, 1 ) );
  4071. _color.g = Math.max( 0, Math.min( material.color.g * _color.g, 1 ) );
  4072. _color.b = Math.max( 0, Math.min( material.color.b * _color.b, 1 ) );
  4073. drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y );
  4074. material.wireframe ? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( _color );
  4075. }
  4076. } else {
  4077. drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y );
  4078. material.wireframe ? strokePath( material.color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( material.color );
  4079. }
  4080. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  4081. _color.r = normalToComponent( element.normalWorld.x );
  4082. _color.g = normalToComponent( element.normalWorld.y );
  4083. _color.b = normalToComponent( element.normalWorld.z );
  4084. drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y );
  4085. material.wireframe ? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( _color );
  4086. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  4087. _near = camera.near;
  4088. _far = camera.far;
  4089. _color1.r = _color1.g = _color1.b = 1 - smoothstep( v1.positionScreen.z, _near, _far );
  4090. _color2.r = _color2.g = _color2.b = 1 - smoothstep( v2.positionScreen.z, _near, _far );
  4091. _color3.r = _color3.g = _color3.b = 1 - smoothstep( v4.positionScreen.z, _near, _far );
  4092. _color4.r = _color4.g = _color4.b = 1 - smoothstep( v3.positionScreen.z, _near, _far );
  4093. _image = getGradientTexture( _color1, _color2, _color3, _color4 );
  4094. // TODO: UVs are incorrect, v4->v3?
  4095. drawTriangle( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y );
  4096. clipImage( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y, 0, 0, 1, 0, 0, 1, _image );
  4097. drawTriangle( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y );
  4098. clipImage( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y, 1, 0, 1, 1, 0, 1, _image );
  4099. }
  4100. }
  4101. //
  4102. function drawTriangle( x0, y0, x1, y1, x2, y2 ) {
  4103. _context.beginPath();
  4104. _context.moveTo( x0, y0 );
  4105. _context.lineTo( x1, y1 );
  4106. _context.lineTo( x2, y2 );
  4107. _context.lineTo( x0, y0 );
  4108. _context.closePath();
  4109. }
  4110. function drawQuad( x0, y0, x1, y1, x2, y2, x3, y3 ) {
  4111. _context.beginPath();
  4112. _context.moveTo( x0, y0 );
  4113. _context.lineTo( x1, y1 );
  4114. _context.lineTo( x2, y2 );
  4115. _context.lineTo( x3, y3 );
  4116. _context.lineTo( x0, y0 );
  4117. _context.closePath();
  4118. }
  4119. function strokePath( color, linewidth, linecap, linejoin ) {
  4120. setLineWidth( linewidth );
  4121. setLineCap( linecap );
  4122. setLineJoin( linejoin );
  4123. setStrokeStyle( color.getContextStyle() );
  4124. _context.stroke();
  4125. _bboxRect.inflate( linewidth * 2 );
  4126. }
  4127. function fillPath( color ) {
  4128. setFillStyle( color.getContextStyle() );
  4129. _context.fill();
  4130. }
  4131. function patternPath( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, texture ) {
  4132. if ( texture.image.width == 0 ) return;
  4133. if ( texture.needsUpdate == true || _patterns[ texture.id ] == undefined ) {
  4134. var repeatX = texture.wrapS == THREE.RepeatWrapping;
  4135. var repeatY = texture.wrapT == THREE.RepeatWrapping;
  4136. _patterns[ texture.id ] = _context.createPattern( texture.image, repeatX && repeatY ? 'repeat' : repeatX && !repeatY ? 'repeat-x' : !repeatX && repeatY ? 'repeat-y' : 'no-repeat' );
  4137. texture.needsUpdate = false;
  4138. }
  4139. setFillStyle( _patterns[ texture.id ] );
  4140. // http://extremelysatisfactorytotalitarianism.com/blog/?p=2120
  4141. var a, b, c, d, e, f, det, idet,
  4142. offsetX = texture.offset.x / texture.repeat.x,
  4143. offsetY = texture.offset.y / texture.repeat.y,
  4144. width = texture.image.width * texture.repeat.x,
  4145. height = texture.image.height * texture.repeat.y;
  4146. u0 = ( u0 + offsetX ) * width;
  4147. v0 = ( v0 + offsetY ) * height;
  4148. u1 = ( u1 + offsetX ) * width;
  4149. v1 = ( v1 + offsetY ) * height;
  4150. u2 = ( u2 + offsetX ) * width;
  4151. v2 = ( v2 + offsetY ) * height;
  4152. x1 -= x0; y1 -= y0;
  4153. x2 -= x0; y2 -= y0;
  4154. u1 -= u0; v1 -= v0;
  4155. u2 -= u0; v2 -= v0;
  4156. det = u1 * v2 - u2 * v1;
  4157. if ( det == 0 ) {
  4158. if ( _imagedatas[ texture.id ] === undefined ) {
  4159. var canvas = document.createElement( 'canvas' )
  4160. canvas.width = texture.image.width;
  4161. canvas.height = texture.image.height;
  4162. var context = canvas.getContext( '2d' );
  4163. context.drawImage( texture.image, 0, 0 );
  4164. _imagedatas[ texture.id ] = context.getImageData( 0, 0, texture.image.width, texture.image.height ).data;
  4165. // variables cannot be deleted in ES5 strict mode
  4166. //delete canvas;
  4167. }
  4168. var data = _imagedatas[ texture.id ];
  4169. var index = ( Math.floor( u0 ) + Math.floor( v0 ) * texture.image.width ) * 4;
  4170. _color.setRGB( data[ index ] / 255, data[ index + 1 ] / 255, data[ index + 2 ] / 255 );
  4171. fillPath( _color );
  4172. return;
  4173. }
  4174. idet = 1 / det;
  4175. a = ( v2 * x1 - v1 * x2 ) * idet;
  4176. b = ( v2 * y1 - v1 * y2 ) * idet;
  4177. c = ( u1 * x2 - u2 * x1 ) * idet;
  4178. d = ( u1 * y2 - u2 * y1 ) * idet;
  4179. e = x0 - a * u0 - c * v0;
  4180. f = y0 - b * u0 - d * v0;
  4181. _context.save();
  4182. _context.transform( a, b, c, d, e, f );
  4183. _context.fill();
  4184. _context.restore();
  4185. }
  4186. function clipImage( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, image ) {
  4187. // http://extremelysatisfactorytotalitarianism.com/blog/?p=2120
  4188. var a, b, c, d, e, f, det, idet,
  4189. width = image.width - 1,
  4190. height = image.height - 1;
  4191. u0 *= width; v0 *= height;
  4192. u1 *= width; v1 *= height;
  4193. u2 *= width; v2 *= height;
  4194. x1 -= x0; y1 -= y0;
  4195. x2 -= x0; y2 -= y0;
  4196. u1 -= u0; v1 -= v0;
  4197. u2 -= u0; v2 -= v0;
  4198. det = u1 * v2 - u2 * v1;
  4199. idet = 1 / det;
  4200. a = ( v2 * x1 - v1 * x2 ) * idet;
  4201. b = ( v2 * y1 - v1 * y2 ) * idet;
  4202. c = ( u1 * x2 - u2 * x1 ) * idet;
  4203. d = ( u1 * y2 - u2 * y1 ) * idet;
  4204. e = x0 - a * u0 - c * v0;
  4205. f = y0 - b * u0 - d * v0;
  4206. _context.save();
  4207. _context.transform( a, b, c, d, e, f );
  4208. _context.clip();
  4209. _context.drawImage( image, 0, 0 );
  4210. _context.restore();
  4211. }
  4212. function getGradientTexture( color1, color2, color3, color4 ) {
  4213. // http://mrdoob.com/blog/post/710
  4214. var c1r = ~~ ( color1.r * 255 ), c1g = ~~ ( color1.g * 255 ), c1b = ~~ ( color1.b * 255 ),
  4215. c2r = ~~ ( color2.r * 255 ), c2g = ~~ ( color2.g * 255 ), c2b = ~~ ( color2.b * 255 ),
  4216. c3r = ~~ ( color3.r * 255 ), c3g = ~~ ( color3.g * 255 ), c3b = ~~ ( color3.b * 255 ),
  4217. c4r = ~~ ( color4.r * 255 ), c4g = ~~ ( color4.g * 255 ), c4b = ~~ ( color4.b * 255 );
  4218. _pixelMapData[ 0 ] = c1r < 0 ? 0 : c1r > 255 ? 255 : c1r;
  4219. _pixelMapData[ 1 ] = c1g < 0 ? 0 : c1g > 255 ? 255 : c1g;
  4220. _pixelMapData[ 2 ] = c1b < 0 ? 0 : c1b > 255 ? 255 : c1b;
  4221. _pixelMapData[ 4 ] = c2r < 0 ? 0 : c2r > 255 ? 255 : c2r;
  4222. _pixelMapData[ 5 ] = c2g < 0 ? 0 : c2g > 255 ? 255 : c2g;
  4223. _pixelMapData[ 6 ] = c2b < 0 ? 0 : c2b > 255 ? 255 : c2b;
  4224. _pixelMapData[ 8 ] = c3r < 0 ? 0 : c3r > 255 ? 255 : c3r;
  4225. _pixelMapData[ 9 ] = c3g < 0 ? 0 : c3g > 255 ? 255 : c3g;
  4226. _pixelMapData[ 10 ] = c3b < 0 ? 0 : c3b > 255 ? 255 : c3b;
  4227. _pixelMapData[ 12 ] = c4r < 0 ? 0 : c4r > 255 ? 255 : c4r;
  4228. _pixelMapData[ 13 ] = c4g < 0 ? 0 : c4g > 255 ? 255 : c4g;
  4229. _pixelMapData[ 14 ] = c4b < 0 ? 0 : c4b > 255 ? 255 : c4b;
  4230. _pixelMapContext.putImageData( _pixelMapImage, 0, 0 );
  4231. _gradientMapContext.drawImage( _pixelMap, 0, 0 );
  4232. return _gradientMap;
  4233. }
  4234. function smoothstep( value, min, max ) {
  4235. var x = ( value - min ) / ( max - min );
  4236. return x * x * ( 3 - 2 * x );
  4237. }
  4238. function normalToComponent( normal ) {
  4239. var component = ( normal + 1 ) * 0.5;
  4240. return component < 0 ? 0 : ( component > 1 ? 1 : component );
  4241. }
  4242. // Hide anti-alias gaps
  4243. function expand( v1, v2 ) {
  4244. var x = v2.x - v1.x, y = v2.y - v1.y,
  4245. det = x * x + y * y, idet;
  4246. if ( det == 0 ) return;
  4247. idet = 1 / Math.sqrt( det );
  4248. x *= idet; y *= idet;
  4249. v2.x += x; v2.y += y;
  4250. v1.x -= x; v1.y -= y;
  4251. }
  4252. };
  4253. // Context cached methods.
  4254. function setOpacity( value ) {
  4255. if ( _contextGlobalAlpha != value ) {
  4256. _context.globalAlpha = _contextGlobalAlpha = value;
  4257. }
  4258. }
  4259. function setBlending( value ) {
  4260. if ( _contextGlobalCompositeOperation != value ) {
  4261. switch ( value ) {
  4262. case THREE.NormalBlending:
  4263. _context.globalCompositeOperation = 'source-over';
  4264. break;
  4265. case THREE.AdditiveBlending:
  4266. _context.globalCompositeOperation = 'lighter';
  4267. break;
  4268. case THREE.SubtractiveBlending:
  4269. _context.globalCompositeOperation = 'darker';
  4270. break;
  4271. }
  4272. _contextGlobalCompositeOperation = value;
  4273. }
  4274. }
  4275. function setLineWidth( value ) {
  4276. if ( _contextLineWidth != value ) {
  4277. _context.lineWidth = _contextLineWidth = value;
  4278. }
  4279. }
  4280. function setLineCap( value ) {
  4281. // "butt", "round", "square"
  4282. if ( _contextLineCap != value ) {
  4283. _context.lineCap = _contextLineCap = value;
  4284. }
  4285. }
  4286. function setLineJoin( value ) {
  4287. // "round", "bevel", "miter"
  4288. if ( _contextLineJoin != value ) {
  4289. _context.lineJoin = _contextLineJoin = value;
  4290. }
  4291. }
  4292. function setStrokeStyle( style ) {
  4293. if ( _contextStrokeStyle != style ) {
  4294. _context.strokeStyle = _contextStrokeStyle = style;
  4295. }
  4296. }
  4297. function setFillStyle( style ) {
  4298. if ( _contextFillStyle != style ) {
  4299. _context.fillStyle = _contextFillStyle = style;
  4300. }
  4301. }
  4302. };
  4303. /**
  4304. * @author mr.doob / http://mrdoob.com/
  4305. */
  4306. THREE.RenderableVertex = function () {
  4307. this.positionWorld = new THREE.Vector3();
  4308. this.positionScreen = new THREE.Vector4();
  4309. this.visible = true;
  4310. };
  4311. THREE.RenderableVertex.prototype.copy = function ( vertex ) {
  4312. this.positionWorld.copy( vertex.positionWorld );
  4313. this.positionScreen.copy( vertex.positionScreen );
  4314. }
  4315. /**
  4316. * @author mr.doob / http://mrdoob.com/
  4317. */
  4318. THREE.RenderableFace3 = function () {
  4319. this.v1 = new THREE.RenderableVertex();
  4320. this.v2 = new THREE.RenderableVertex();
  4321. this.v3 = new THREE.RenderableVertex();
  4322. this.centroidWorld = new THREE.Vector3();
  4323. this.centroidScreen = new THREE.Vector3();
  4324. this.normalWorld = new THREE.Vector3();
  4325. this.vertexNormalsWorld = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  4326. this.material = null;
  4327. this.faceMaterial = null;
  4328. this.uvs = [[]];
  4329. this.z = null;
  4330. };
  4331. /**
  4332. * @author mr.doob / http://mrdoob.com/
  4333. */
  4334. THREE.RenderableFace4 = function () {
  4335. this.v1 = new THREE.RenderableVertex();
  4336. this.v2 = new THREE.RenderableVertex();
  4337. this.v3 = new THREE.RenderableVertex();
  4338. this.v4 = new THREE.RenderableVertex();
  4339. this.centroidWorld = new THREE.Vector3();
  4340. this.centroidScreen = new THREE.Vector3();
  4341. this.normalWorld = new THREE.Vector3();
  4342. this.vertexNormalsWorld = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  4343. this.material = null;
  4344. this.faceMaterial = null;
  4345. this.uvs = [[]];
  4346. this.z = null;
  4347. };
  4348. /**
  4349. * @author mr.doob / http://mrdoob.com/
  4350. */
  4351. THREE.RenderableObject = function () {
  4352. this.object = null;
  4353. this.z = null;
  4354. };
  4355. /**
  4356. * @author mr.doob / http://mrdoob.com/
  4357. */
  4358. THREE.RenderableParticle = function () {
  4359. this.x = null;
  4360. this.y = null;
  4361. this.z = null;
  4362. this.rotation = null;
  4363. this.scale = new THREE.Vector2();
  4364. this.material = null;
  4365. };
  4366. /**
  4367. * @author mr.doob / http://mrdoob.com/
  4368. */
  4369. THREE.RenderableLine = function () {
  4370. this.z = null;
  4371. this.v1 = new THREE.RenderableVertex();
  4372. this.v2 = new THREE.RenderableVertex();
  4373. this.material = null;
  4374. };
粤ICP备19079148号