three-math.js 126 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '69dev' };
  6. // browserify support
  7. if ( typeof module === 'object' ) {
  8. module.exports = THREE;
  9. }
  10. // GL STATE CONSTANTS
  11. THREE.CullFaceNone = 0;
  12. THREE.CullFaceBack = 1;
  13. THREE.CullFaceFront = 2;
  14. THREE.CullFaceFrontBack = 3;
  15. THREE.FrontFaceDirectionCW = 0;
  16. THREE.FrontFaceDirectionCCW = 1;
  17. // SHADOWING TYPES
  18. THREE.BasicShadowMap = 0;
  19. THREE.PCFShadowMap = 1;
  20. THREE.PCFSoftShadowMap = 2;
  21. // MATERIAL CONSTANTS
  22. // side
  23. THREE.FrontSide = 0;
  24. THREE.BackSide = 1;
  25. THREE.DoubleSide = 2;
  26. // shading
  27. THREE.NoShading = 0;
  28. THREE.FlatShading = 1;
  29. THREE.SmoothShading = 2;
  30. // colors
  31. THREE.NoColors = 0;
  32. THREE.FaceColors = 1;
  33. THREE.VertexColors = 2;
  34. // blending modes
  35. THREE.NoBlending = 0;
  36. THREE.NormalBlending = 1;
  37. THREE.AdditiveBlending = 2;
  38. THREE.SubtractiveBlending = 3;
  39. THREE.MultiplyBlending = 4;
  40. THREE.CustomBlending = 5;
  41. // custom blending equations
  42. // (numbers start from 100 not to clash with other
  43. // mappings to OpenGL constants defined in Texture.js)
  44. THREE.AddEquation = 100;
  45. THREE.SubtractEquation = 101;
  46. THREE.ReverseSubtractEquation = 102;
  47. // custom blending destination factors
  48. THREE.ZeroFactor = 200;
  49. THREE.OneFactor = 201;
  50. THREE.SrcColorFactor = 202;
  51. THREE.OneMinusSrcColorFactor = 203;
  52. THREE.SrcAlphaFactor = 204;
  53. THREE.OneMinusSrcAlphaFactor = 205;
  54. THREE.DstAlphaFactor = 206;
  55. THREE.OneMinusDstAlphaFactor = 207;
  56. // custom blending source factors
  57. //THREE.ZeroFactor = 200;
  58. //THREE.OneFactor = 201;
  59. //THREE.SrcAlphaFactor = 204;
  60. //THREE.OneMinusSrcAlphaFactor = 205;
  61. //THREE.DstAlphaFactor = 206;
  62. //THREE.OneMinusDstAlphaFactor = 207;
  63. THREE.DstColorFactor = 208;
  64. THREE.OneMinusDstColorFactor = 209;
  65. THREE.SrcAlphaSaturateFactor = 210;
  66. // TEXTURE CONSTANTS
  67. THREE.MultiplyOperation = 0;
  68. THREE.MixOperation = 1;
  69. THREE.AddOperation = 2;
  70. // Mapping modes
  71. THREE.UVMapping = function () {};
  72. THREE.CubeReflectionMapping = function () {};
  73. THREE.CubeRefractionMapping = function () {};
  74. THREE.SphericalReflectionMapping = function () {};
  75. THREE.SphericalRefractionMapping = function () {};
  76. // Wrapping modes
  77. THREE.RepeatWrapping = 1000;
  78. THREE.ClampToEdgeWrapping = 1001;
  79. THREE.MirroredRepeatWrapping = 1002;
  80. // Filters
  81. THREE.NearestFilter = 1003;
  82. THREE.NearestMipMapNearestFilter = 1004;
  83. THREE.NearestMipMapLinearFilter = 1005;
  84. THREE.LinearFilter = 1006;
  85. THREE.LinearMipMapNearestFilter = 1007;
  86. THREE.LinearMipMapLinearFilter = 1008;
  87. // Data types
  88. THREE.UnsignedByteType = 1009;
  89. THREE.ByteType = 1010;
  90. THREE.ShortType = 1011;
  91. THREE.UnsignedShortType = 1012;
  92. THREE.IntType = 1013;
  93. THREE.UnsignedIntType = 1014;
  94. THREE.FloatType = 1015;
  95. // Pixel types
  96. //THREE.UnsignedByteType = 1009;
  97. THREE.UnsignedShort4444Type = 1016;
  98. THREE.UnsignedShort5551Type = 1017;
  99. THREE.UnsignedShort565Type = 1018;
  100. // Pixel formats
  101. THREE.AlphaFormat = 1019;
  102. THREE.RGBFormat = 1020;
  103. THREE.RGBAFormat = 1021;
  104. THREE.LuminanceFormat = 1022;
  105. THREE.LuminanceAlphaFormat = 1023;
  106. // Compressed texture formats
  107. THREE.RGB_S3TC_DXT1_Format = 2001;
  108. THREE.RGBA_S3TC_DXT1_Format = 2002;
  109. THREE.RGBA_S3TC_DXT3_Format = 2003;
  110. THREE.RGBA_S3TC_DXT5_Format = 2004;
  111. /*
  112. // Potential future PVRTC compressed texture formats
  113. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  114. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  115. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  116. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  117. */
  118. // File:src/math/Color.js
  119. /**
  120. * @author mrdoob / http://mrdoob.com/
  121. */
  122. THREE.Color = function ( color ) {
  123. if ( arguments.length === 3 ) {
  124. return this.setRGB( arguments[ 0 ], arguments[ 1 ], arguments[ 2 ] );
  125. }
  126. return this.set( color )
  127. };
  128. THREE.Color.prototype = {
  129. constructor: THREE.Color,
  130. r: 1, g: 1, b: 1,
  131. set: function ( value ) {
  132. if ( value instanceof THREE.Color ) {
  133. this.copy( value );
  134. } else if ( typeof value === 'number' ) {
  135. this.setHex( value );
  136. } else if ( typeof value === 'string' ) {
  137. this.setStyle( value );
  138. }
  139. return this;
  140. },
  141. setHex: function ( hex ) {
  142. hex = Math.floor( hex );
  143. this.r = ( hex >> 16 & 255 ) / 255;
  144. this.g = ( hex >> 8 & 255 ) / 255;
  145. this.b = ( hex & 255 ) / 255;
  146. return this;
  147. },
  148. setRGB: function ( r, g, b ) {
  149. this.r = r;
  150. this.g = g;
  151. this.b = b;
  152. return this;
  153. },
  154. setHSL: function ( h, s, l ) {
  155. // h,s,l ranges are in 0.0 - 1.0
  156. if ( s === 0 ) {
  157. this.r = this.g = this.b = l;
  158. } else {
  159. var hue2rgb = function ( p, q, t ) {
  160. if ( t < 0 ) t += 1;
  161. if ( t > 1 ) t -= 1;
  162. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  163. if ( t < 1 / 2 ) return q;
  164. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  165. return p;
  166. };
  167. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  168. var q = ( 2 * l ) - p;
  169. this.r = hue2rgb( q, p, h + 1 / 3 );
  170. this.g = hue2rgb( q, p, h );
  171. this.b = hue2rgb( q, p, h - 1 / 3 );
  172. }
  173. return this;
  174. },
  175. setStyle: function ( style ) {
  176. // rgb(255,0,0)
  177. if ( /^rgb\((\d+), ?(\d+), ?(\d+)\)$/i.test( style ) ) {
  178. var color = /^rgb\((\d+), ?(\d+), ?(\d+)\)$/i.exec( style );
  179. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  180. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  181. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  182. return this;
  183. }
  184. // rgb(100%,0%,0%)
  185. if ( /^rgb\((\d+)\%, ?(\d+)\%, ?(\d+)\%\)$/i.test( style ) ) {
  186. var color = /^rgb\((\d+)\%, ?(\d+)\%, ?(\d+)\%\)$/i.exec( style );
  187. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  188. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  189. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  190. return this;
  191. }
  192. // #ff0000
  193. if ( /^\#([0-9a-f]{6})$/i.test( style ) ) {
  194. var color = /^\#([0-9a-f]{6})$/i.exec( style );
  195. this.setHex( parseInt( color[ 1 ], 16 ) );
  196. return this;
  197. }
  198. // #f00
  199. if ( /^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.test( style ) ) {
  200. var color = /^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec( style );
  201. this.setHex( parseInt( color[ 1 ] + color[ 1 ] + color[ 2 ] + color[ 2 ] + color[ 3 ] + color[ 3 ], 16 ) );
  202. return this;
  203. }
  204. // red
  205. if ( /^(\w+)$/i.test( style ) ) {
  206. this.setHex( THREE.ColorKeywords[ style ] );
  207. return this;
  208. }
  209. },
  210. copy: function ( color ) {
  211. this.r = color.r;
  212. this.g = color.g;
  213. this.b = color.b;
  214. return this;
  215. },
  216. copyGammaToLinear: function ( color ) {
  217. this.r = color.r * color.r;
  218. this.g = color.g * color.g;
  219. this.b = color.b * color.b;
  220. return this;
  221. },
  222. copyLinearToGamma: function ( color ) {
  223. this.r = Math.sqrt( color.r );
  224. this.g = Math.sqrt( color.g );
  225. this.b = Math.sqrt( color.b );
  226. return this;
  227. },
  228. convertGammaToLinear: function () {
  229. var r = this.r, g = this.g, b = this.b;
  230. this.r = r * r;
  231. this.g = g * g;
  232. this.b = b * b;
  233. return this;
  234. },
  235. convertLinearToGamma: function () {
  236. this.r = Math.sqrt( this.r );
  237. this.g = Math.sqrt( this.g );
  238. this.b = Math.sqrt( this.b );
  239. return this;
  240. },
  241. getHex: function () {
  242. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  243. },
  244. getHexString: function () {
  245. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  246. },
  247. getHSL: function ( optionalTarget ) {
  248. // h,s,l ranges are in 0.0 - 1.0
  249. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  250. var r = this.r, g = this.g, b = this.b;
  251. var max = Math.max( r, g, b );
  252. var min = Math.min( r, g, b );
  253. var hue, saturation;
  254. var lightness = ( min + max ) / 2.0;
  255. if ( min === max ) {
  256. hue = 0;
  257. saturation = 0;
  258. } else {
  259. var delta = max - min;
  260. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  261. switch ( max ) {
  262. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  263. case g: hue = ( b - r ) / delta + 2; break;
  264. case b: hue = ( r - g ) / delta + 4; break;
  265. }
  266. hue /= 6;
  267. }
  268. hsl.h = hue;
  269. hsl.s = saturation;
  270. hsl.l = lightness;
  271. return hsl;
  272. },
  273. getStyle: function () {
  274. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  275. },
  276. offsetHSL: function ( h, s, l ) {
  277. var hsl = this.getHSL();
  278. hsl.h += h; hsl.s += s; hsl.l += l;
  279. this.setHSL( hsl.h, hsl.s, hsl.l );
  280. return this;
  281. },
  282. add: function ( color ) {
  283. this.r += color.r;
  284. this.g += color.g;
  285. this.b += color.b;
  286. return this;
  287. },
  288. addColors: function ( color1, color2 ) {
  289. this.r = color1.r + color2.r;
  290. this.g = color1.g + color2.g;
  291. this.b = color1.b + color2.b;
  292. return this;
  293. },
  294. addScalar: function ( s ) {
  295. this.r += s;
  296. this.g += s;
  297. this.b += s;
  298. return this;
  299. },
  300. multiply: function ( color ) {
  301. this.r *= color.r;
  302. this.g *= color.g;
  303. this.b *= color.b;
  304. return this;
  305. },
  306. multiplyScalar: function ( s ) {
  307. this.r *= s;
  308. this.g *= s;
  309. this.b *= s;
  310. return this;
  311. },
  312. lerp: function ( color, alpha ) {
  313. this.r += ( color.r - this.r ) * alpha;
  314. this.g += ( color.g - this.g ) * alpha;
  315. this.b += ( color.b - this.b ) * alpha;
  316. return this;
  317. },
  318. equals: function ( c ) {
  319. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  320. },
  321. fromArray: function ( array ) {
  322. this.r = array[ 0 ];
  323. this.g = array[ 1 ];
  324. this.b = array[ 2 ];
  325. return this;
  326. },
  327. toArray: function () {
  328. return [ this.r, this.g, this.b ];
  329. },
  330. clone: function () {
  331. return new THREE.Color().setRGB( this.r, this.g, this.b );
  332. }
  333. };
  334. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  335. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  336. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  337. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  338. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  339. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  340. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  341. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  342. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  343. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  344. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  345. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  346. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  347. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  348. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  349. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  350. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  351. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  352. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  353. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  354. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  355. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  356. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  357. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  358. // File:src/math/Quaternion.js
  359. /**
  360. * @author mikael emtinger / http://gomo.se/
  361. * @author alteredq / http://alteredqualia.com/
  362. * @author WestLangley / http://github.com/WestLangley
  363. * @author bhouston / http://exocortex.com
  364. */
  365. THREE.Quaternion = function ( x, y, z, w ) {
  366. this._x = x || 0;
  367. this._y = y || 0;
  368. this._z = z || 0;
  369. this._w = ( w !== undefined ) ? w : 1;
  370. };
  371. THREE.Quaternion.prototype = {
  372. constructor: THREE.Quaternion,
  373. _x: 0,_y: 0, _z: 0, _w: 0,
  374. get x () {
  375. return this._x;
  376. },
  377. set x ( value ) {
  378. this._x = value;
  379. this.onChangeCallback();
  380. },
  381. get y () {
  382. return this._y;
  383. },
  384. set y ( value ) {
  385. this._y = value;
  386. this.onChangeCallback();
  387. },
  388. get z () {
  389. return this._z;
  390. },
  391. set z ( value ) {
  392. this._z = value;
  393. this.onChangeCallback();
  394. },
  395. get w () {
  396. return this._w;
  397. },
  398. set w ( value ) {
  399. this._w = value;
  400. this.onChangeCallback();
  401. },
  402. set: function ( x, y, z, w ) {
  403. this._x = x;
  404. this._y = y;
  405. this._z = z;
  406. this._w = w;
  407. this.onChangeCallback();
  408. return this;
  409. },
  410. copy: function ( quaternion ) {
  411. this._x = quaternion.x;
  412. this._y = quaternion.y;
  413. this._z = quaternion.z;
  414. this._w = quaternion.w;
  415. this.onChangeCallback();
  416. return this;
  417. },
  418. setFromEuler: function ( euler, update ) {
  419. if ( euler instanceof THREE.Euler === false ) {
  420. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  421. }
  422. // http://www.mathworks.com/matlabcentral/fileexchange/
  423. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  424. // content/SpinCalc.m
  425. var c1 = Math.cos( euler._x / 2 );
  426. var c2 = Math.cos( euler._y / 2 );
  427. var c3 = Math.cos( euler._z / 2 );
  428. var s1 = Math.sin( euler._x / 2 );
  429. var s2 = Math.sin( euler._y / 2 );
  430. var s3 = Math.sin( euler._z / 2 );
  431. if ( euler.order === 'XYZ' ) {
  432. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  433. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  434. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  435. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  436. } else if ( euler.order === 'YXZ' ) {
  437. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  438. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  439. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  440. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  441. } else if ( euler.order === 'ZXY' ) {
  442. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  443. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  444. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  445. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  446. } else if ( euler.order === 'ZYX' ) {
  447. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  448. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  449. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  450. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  451. } else if ( euler.order === 'YZX' ) {
  452. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  453. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  454. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  455. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  456. } else if ( euler.order === 'XZY' ) {
  457. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  458. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  459. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  460. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  461. }
  462. if ( update !== false ) this.onChangeCallback();
  463. return this;
  464. },
  465. setFromAxisAngle: function ( axis, angle ) {
  466. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  467. // assumes axis is normalized
  468. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  469. this._x = axis.x * s;
  470. this._y = axis.y * s;
  471. this._z = axis.z * s;
  472. this._w = Math.cos( halfAngle );
  473. this.onChangeCallback();
  474. return this;
  475. },
  476. setFromRotationMatrix: function ( m ) {
  477. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  478. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  479. var te = m.elements,
  480. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  481. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  482. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  483. trace = m11 + m22 + m33,
  484. s;
  485. if ( trace > 0 ) {
  486. s = 0.5 / Math.sqrt( trace + 1.0 );
  487. this._w = 0.25 / s;
  488. this._x = ( m32 - m23 ) * s;
  489. this._y = ( m13 - m31 ) * s;
  490. this._z = ( m21 - m12 ) * s;
  491. } else if ( m11 > m22 && m11 > m33 ) {
  492. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  493. this._w = ( m32 - m23 ) / s;
  494. this._x = 0.25 * s;
  495. this._y = ( m12 + m21 ) / s;
  496. this._z = ( m13 + m31 ) / s;
  497. } else if ( m22 > m33 ) {
  498. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  499. this._w = ( m13 - m31 ) / s;
  500. this._x = ( m12 + m21 ) / s;
  501. this._y = 0.25 * s;
  502. this._z = ( m23 + m32 ) / s;
  503. } else {
  504. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  505. this._w = ( m21 - m12 ) / s;
  506. this._x = ( m13 + m31 ) / s;
  507. this._y = ( m23 + m32 ) / s;
  508. this._z = 0.25 * s;
  509. }
  510. this.onChangeCallback();
  511. return this;
  512. },
  513. setFromUnitVectors: function () {
  514. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  515. // assumes direction vectors vFrom and vTo are normalized
  516. var v1, r;
  517. var EPS = 0.000001;
  518. return function ( vFrom, vTo ) {
  519. if ( v1 === undefined ) v1 = new THREE.Vector3();
  520. r = vFrom.dot( vTo ) + 1;
  521. if ( r < EPS ) {
  522. r = 0;
  523. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  524. v1.set( - vFrom.y, vFrom.x, 0 );
  525. } else {
  526. v1.set( 0, - vFrom.z, vFrom.y );
  527. }
  528. } else {
  529. v1.crossVectors( vFrom, vTo );
  530. }
  531. this._x = v1.x;
  532. this._y = v1.y;
  533. this._z = v1.z;
  534. this._w = r;
  535. this.normalize();
  536. return this;
  537. }
  538. }(),
  539. inverse: function () {
  540. this.conjugate().normalize();
  541. return this;
  542. },
  543. conjugate: function () {
  544. this._x *= - 1;
  545. this._y *= - 1;
  546. this._z *= - 1;
  547. this.onChangeCallback();
  548. return this;
  549. },
  550. dot: function ( v ) {
  551. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  552. },
  553. lengthSq: function () {
  554. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  555. },
  556. length: function () {
  557. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  558. },
  559. normalize: function () {
  560. var l = this.length();
  561. if ( l === 0 ) {
  562. this._x = 0;
  563. this._y = 0;
  564. this._z = 0;
  565. this._w = 1;
  566. } else {
  567. l = 1 / l;
  568. this._x = this._x * l;
  569. this._y = this._y * l;
  570. this._z = this._z * l;
  571. this._w = this._w * l;
  572. }
  573. this.onChangeCallback();
  574. return this;
  575. },
  576. multiply: function ( q, p ) {
  577. if ( p !== undefined ) {
  578. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  579. return this.multiplyQuaternions( q, p );
  580. }
  581. return this.multiplyQuaternions( this, q );
  582. },
  583. multiplyQuaternions: function ( a, b ) {
  584. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  585. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  586. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  587. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  588. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  589. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  590. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  591. this.onChangeCallback();
  592. return this;
  593. },
  594. multiplyVector3: function ( vector ) {
  595. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  596. return vector.applyQuaternion( this );
  597. },
  598. slerp: function ( qb, t ) {
  599. var x = this._x, y = this._y, z = this._z, w = this._w;
  600. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  601. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  602. if ( cosHalfTheta < 0 ) {
  603. this._w = - qb._w;
  604. this._x = - qb._x;
  605. this._y = - qb._y;
  606. this._z = - qb._z;
  607. cosHalfTheta = - cosHalfTheta;
  608. } else {
  609. this.copy( qb );
  610. }
  611. if ( cosHalfTheta >= 1.0 ) {
  612. this._w = w;
  613. this._x = x;
  614. this._y = y;
  615. this._z = z;
  616. return this;
  617. }
  618. var halfTheta = Math.acos( cosHalfTheta );
  619. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  620. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  621. this._w = 0.5 * ( w + this._w );
  622. this._x = 0.5 * ( x + this._x );
  623. this._y = 0.5 * ( y + this._y );
  624. this._z = 0.5 * ( z + this._z );
  625. return this;
  626. }
  627. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  628. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  629. this._w = ( w * ratioA + this._w * ratioB );
  630. this._x = ( x * ratioA + this._x * ratioB );
  631. this._y = ( y * ratioA + this._y * ratioB );
  632. this._z = ( z * ratioA + this._z * ratioB );
  633. this.onChangeCallback();
  634. return this;
  635. },
  636. equals: function ( quaternion ) {
  637. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  638. },
  639. fromArray: function ( array ) {
  640. this._x = array[ 0 ];
  641. this._y = array[ 1 ];
  642. this._z = array[ 2 ];
  643. this._w = array[ 3 ];
  644. this.onChangeCallback();
  645. return this;
  646. },
  647. toArray: function () {
  648. return [ this._x, this._y, this._z, this._w ];
  649. },
  650. onChange: function ( callback ) {
  651. this.onChangeCallback = callback;
  652. return this;
  653. },
  654. onChangeCallback: function () {},
  655. clone: function () {
  656. return new THREE.Quaternion( this._x, this._y, this._z, this._w );
  657. }
  658. };
  659. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  660. return qm.copy( qa ).slerp( qb, t );
  661. }
  662. // File:src/math/Vector2.js
  663. /**
  664. * @author mrdoob / http://mrdoob.com/
  665. * @author philogb / http://blog.thejit.org/
  666. * @author egraether / http://egraether.com/
  667. * @author zz85 / http://www.lab4games.net/zz85/blog
  668. */
  669. THREE.Vector2 = function ( x, y ) {
  670. this.x = x || 0;
  671. this.y = y || 0;
  672. };
  673. THREE.Vector2.prototype = {
  674. constructor: THREE.Vector2,
  675. set: function ( x, y ) {
  676. this.x = x;
  677. this.y = y;
  678. return this;
  679. },
  680. setX: function ( x ) {
  681. this.x = x;
  682. return this;
  683. },
  684. setY: function ( y ) {
  685. this.y = y;
  686. return this;
  687. },
  688. setComponent: function ( index, value ) {
  689. switch ( index ) {
  690. case 0: this.x = value; break;
  691. case 1: this.y = value; break;
  692. default: throw new Error( 'index is out of range: ' + index );
  693. }
  694. },
  695. getComponent: function ( index ) {
  696. switch ( index ) {
  697. case 0: return this.x;
  698. case 1: return this.y;
  699. default: throw new Error( 'index is out of range: ' + index );
  700. }
  701. },
  702. copy: function ( v ) {
  703. this.x = v.x;
  704. this.y = v.y;
  705. return this;
  706. },
  707. add: function ( v, w ) {
  708. if ( w !== undefined ) {
  709. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  710. return this.addVectors( v, w );
  711. }
  712. this.x += v.x;
  713. this.y += v.y;
  714. return this;
  715. },
  716. addVectors: function ( a, b ) {
  717. this.x = a.x + b.x;
  718. this.y = a.y + b.y;
  719. return this;
  720. },
  721. addScalar: function ( s ) {
  722. this.x += s;
  723. this.y += s;
  724. return this;
  725. },
  726. sub: function ( v, w ) {
  727. if ( w !== undefined ) {
  728. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  729. return this.subVectors( v, w );
  730. }
  731. this.x -= v.x;
  732. this.y -= v.y;
  733. return this;
  734. },
  735. subVectors: function ( a, b ) {
  736. this.x = a.x - b.x;
  737. this.y = a.y - b.y;
  738. return this;
  739. },
  740. multiply: function ( v ) {
  741. this.x *= v.x;
  742. this.y *= v.y;
  743. return this;
  744. },
  745. multiplyScalar: function ( s ) {
  746. this.x *= s;
  747. this.y *= s;
  748. return this;
  749. },
  750. divide: function ( v ) {
  751. this.x /= v.x;
  752. this.y /= v.y;
  753. return this;
  754. },
  755. divideScalar: function ( scalar ) {
  756. if ( scalar !== 0 ) {
  757. var invScalar = 1 / scalar;
  758. this.x *= invScalar;
  759. this.y *= invScalar;
  760. } else {
  761. this.x = 0;
  762. this.y = 0;
  763. }
  764. return this;
  765. },
  766. min: function ( v ) {
  767. if ( this.x > v.x ) {
  768. this.x = v.x;
  769. }
  770. if ( this.y > v.y ) {
  771. this.y = v.y;
  772. }
  773. return this;
  774. },
  775. max: function ( v ) {
  776. if ( this.x < v.x ) {
  777. this.x = v.x;
  778. }
  779. if ( this.y < v.y ) {
  780. this.y = v.y;
  781. }
  782. return this;
  783. },
  784. clamp: function ( min, max ) {
  785. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  786. if ( this.x < min.x ) {
  787. this.x = min.x;
  788. } else if ( this.x > max.x ) {
  789. this.x = max.x;
  790. }
  791. if ( this.y < min.y ) {
  792. this.y = min.y;
  793. } else if ( this.y > max.y ) {
  794. this.y = max.y;
  795. }
  796. return this;
  797. },
  798. clampScalar: ( function () {
  799. var min, max;
  800. return function ( minVal, maxVal ) {
  801. if ( min === undefined ) {
  802. min = new THREE.Vector2();
  803. max = new THREE.Vector2();
  804. }
  805. min.set( minVal, minVal );
  806. max.set( maxVal, maxVal );
  807. return this.clamp( min, max );
  808. };
  809. } )(),
  810. floor: function () {
  811. this.x = Math.floor( this.x );
  812. this.y = Math.floor( this.y );
  813. return this;
  814. },
  815. ceil: function () {
  816. this.x = Math.ceil( this.x );
  817. this.y = Math.ceil( this.y );
  818. return this;
  819. },
  820. round: function () {
  821. this.x = Math.round( this.x );
  822. this.y = Math.round( this.y );
  823. return this;
  824. },
  825. roundToZero: function () {
  826. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  827. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  828. return this;
  829. },
  830. negate: function () {
  831. this.x = - this.x;
  832. this.y = - this.y;
  833. return this;
  834. },
  835. dot: function ( v ) {
  836. return this.x * v.x + this.y * v.y;
  837. },
  838. lengthSq: function () {
  839. return this.x * this.x + this.y * this.y;
  840. },
  841. length: function () {
  842. return Math.sqrt( this.x * this.x + this.y * this.y );
  843. },
  844. normalize: function () {
  845. return this.divideScalar( this.length() );
  846. },
  847. distanceTo: function ( v ) {
  848. return Math.sqrt( this.distanceToSquared( v ) );
  849. },
  850. distanceToSquared: function ( v ) {
  851. var dx = this.x - v.x, dy = this.y - v.y;
  852. return dx * dx + dy * dy;
  853. },
  854. setLength: function ( l ) {
  855. var oldLength = this.length();
  856. if ( oldLength !== 0 && l !== oldLength ) {
  857. this.multiplyScalar( l / oldLength );
  858. }
  859. return this;
  860. },
  861. lerp: function ( v, alpha ) {
  862. this.x += ( v.x - this.x ) * alpha;
  863. this.y += ( v.y - this.y ) * alpha;
  864. return this;
  865. },
  866. equals: function ( v ) {
  867. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  868. },
  869. fromArray: function ( array ) {
  870. this.x = array[ 0 ];
  871. this.y = array[ 1 ];
  872. return this;
  873. },
  874. toArray: function () {
  875. return [ this.x, this.y ];
  876. },
  877. clone: function () {
  878. return new THREE.Vector2( this.x, this.y );
  879. }
  880. };
  881. // File:src/math/Vector3.js
  882. /**
  883. * @author mrdoob / http://mrdoob.com/
  884. * @author *kile / http://kile.stravaganza.org/
  885. * @author philogb / http://blog.thejit.org/
  886. * @author mikael emtinger / http://gomo.se/
  887. * @author egraether / http://egraether.com/
  888. * @author WestLangley / http://github.com/WestLangley
  889. */
  890. THREE.Vector3 = function ( x, y, z ) {
  891. this.x = x || 0;
  892. this.y = y || 0;
  893. this.z = z || 0;
  894. };
  895. THREE.Vector3.prototype = {
  896. constructor: THREE.Vector3,
  897. set: function ( x, y, z ) {
  898. this.x = x;
  899. this.y = y;
  900. this.z = z;
  901. return this;
  902. },
  903. setX: function ( x ) {
  904. this.x = x;
  905. return this;
  906. },
  907. setY: function ( y ) {
  908. this.y = y;
  909. return this;
  910. },
  911. setZ: function ( z ) {
  912. this.z = z;
  913. return this;
  914. },
  915. setComponent: function ( index, value ) {
  916. switch ( index ) {
  917. case 0: this.x = value; break;
  918. case 1: this.y = value; break;
  919. case 2: this.z = value; break;
  920. default: throw new Error( 'index is out of range: ' + index );
  921. }
  922. },
  923. getComponent: function ( index ) {
  924. switch ( index ) {
  925. case 0: return this.x;
  926. case 1: return this.y;
  927. case 2: return this.z;
  928. default: throw new Error( 'index is out of range: ' + index );
  929. }
  930. },
  931. copy: function ( v ) {
  932. this.x = v.x;
  933. this.y = v.y;
  934. this.z = v.z;
  935. return this;
  936. },
  937. add: function ( v, w ) {
  938. if ( w !== undefined ) {
  939. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  940. return this.addVectors( v, w );
  941. }
  942. this.x += v.x;
  943. this.y += v.y;
  944. this.z += v.z;
  945. return this;
  946. },
  947. addScalar: function ( s ) {
  948. this.x += s;
  949. this.y += s;
  950. this.z += s;
  951. return this;
  952. },
  953. addVectors: function ( a, b ) {
  954. this.x = a.x + b.x;
  955. this.y = a.y + b.y;
  956. this.z = a.z + b.z;
  957. return this;
  958. },
  959. sub: function ( v, w ) {
  960. if ( w !== undefined ) {
  961. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  962. return this.subVectors( v, w );
  963. }
  964. this.x -= v.x;
  965. this.y -= v.y;
  966. this.z -= v.z;
  967. return this;
  968. },
  969. subVectors: function ( a, b ) {
  970. this.x = a.x - b.x;
  971. this.y = a.y - b.y;
  972. this.z = a.z - b.z;
  973. return this;
  974. },
  975. multiply: function ( v, w ) {
  976. if ( w !== undefined ) {
  977. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  978. return this.multiplyVectors( v, w );
  979. }
  980. this.x *= v.x;
  981. this.y *= v.y;
  982. this.z *= v.z;
  983. return this;
  984. },
  985. multiplyScalar: function ( scalar ) {
  986. this.x *= scalar;
  987. this.y *= scalar;
  988. this.z *= scalar;
  989. return this;
  990. },
  991. multiplyVectors: function ( a, b ) {
  992. this.x = a.x * b.x;
  993. this.y = a.y * b.y;
  994. this.z = a.z * b.z;
  995. return this;
  996. },
  997. applyEuler: function () {
  998. var quaternion;
  999. return function ( euler ) {
  1000. if ( euler instanceof THREE.Euler === false ) {
  1001. console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  1002. }
  1003. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1004. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1005. return this;
  1006. };
  1007. }(),
  1008. applyAxisAngle: function () {
  1009. var quaternion;
  1010. return function ( axis, angle ) {
  1011. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1012. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1013. return this;
  1014. };
  1015. }(),
  1016. applyMatrix3: function ( m ) {
  1017. var x = this.x;
  1018. var y = this.y;
  1019. var z = this.z;
  1020. var e = m.elements;
  1021. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1022. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1023. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1024. return this;
  1025. },
  1026. applyMatrix4: function ( m ) {
  1027. // input: THREE.Matrix4 affine matrix
  1028. var x = this.x, y = this.y, z = this.z;
  1029. var e = m.elements;
  1030. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1031. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1032. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1033. return this;
  1034. },
  1035. applyProjection: function ( m ) {
  1036. // input: THREE.Matrix4 projection matrix
  1037. var x = this.x, y = this.y, z = this.z;
  1038. var e = m.elements;
  1039. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1040. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1041. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1042. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1043. return this;
  1044. },
  1045. applyQuaternion: function ( q ) {
  1046. var x = this.x;
  1047. var y = this.y;
  1048. var z = this.z;
  1049. var qx = q.x;
  1050. var qy = q.y;
  1051. var qz = q.z;
  1052. var qw = q.w;
  1053. // calculate quat * vector
  1054. var ix = qw * x + qy * z - qz * y;
  1055. var iy = qw * y + qz * x - qx * z;
  1056. var iz = qw * z + qx * y - qy * x;
  1057. var iw = - qx * x - qy * y - qz * z;
  1058. // calculate result * inverse quat
  1059. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1060. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1061. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1062. return this;
  1063. },
  1064. transformDirection: function ( m ) {
  1065. // input: THREE.Matrix4 affine matrix
  1066. // vector interpreted as a direction
  1067. var x = this.x, y = this.y, z = this.z;
  1068. var e = m.elements;
  1069. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1070. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1071. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1072. this.normalize();
  1073. return this;
  1074. },
  1075. divide: function ( v ) {
  1076. this.x /= v.x;
  1077. this.y /= v.y;
  1078. this.z /= v.z;
  1079. return this;
  1080. },
  1081. divideScalar: function ( scalar ) {
  1082. if ( scalar !== 0 ) {
  1083. var invScalar = 1 / scalar;
  1084. this.x *= invScalar;
  1085. this.y *= invScalar;
  1086. this.z *= invScalar;
  1087. } else {
  1088. this.x = 0;
  1089. this.y = 0;
  1090. this.z = 0;
  1091. }
  1092. return this;
  1093. },
  1094. min: function ( v ) {
  1095. if ( this.x > v.x ) {
  1096. this.x = v.x;
  1097. }
  1098. if ( this.y > v.y ) {
  1099. this.y = v.y;
  1100. }
  1101. if ( this.z > v.z ) {
  1102. this.z = v.z;
  1103. }
  1104. return this;
  1105. },
  1106. max: function ( v ) {
  1107. if ( this.x < v.x ) {
  1108. this.x = v.x;
  1109. }
  1110. if ( this.y < v.y ) {
  1111. this.y = v.y;
  1112. }
  1113. if ( this.z < v.z ) {
  1114. this.z = v.z;
  1115. }
  1116. return this;
  1117. },
  1118. clamp: function ( min, max ) {
  1119. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1120. if ( this.x < min.x ) {
  1121. this.x = min.x;
  1122. } else if ( this.x > max.x ) {
  1123. this.x = max.x;
  1124. }
  1125. if ( this.y < min.y ) {
  1126. this.y = min.y;
  1127. } else if ( this.y > max.y ) {
  1128. this.y = max.y;
  1129. }
  1130. if ( this.z < min.z ) {
  1131. this.z = min.z;
  1132. } else if ( this.z > max.z ) {
  1133. this.z = max.z;
  1134. }
  1135. return this;
  1136. },
  1137. clampScalar: ( function () {
  1138. var min, max;
  1139. return function ( minVal, maxVal ) {
  1140. if ( min === undefined ) {
  1141. min = new THREE.Vector3();
  1142. max = new THREE.Vector3();
  1143. }
  1144. min.set( minVal, minVal, minVal );
  1145. max.set( maxVal, maxVal, maxVal );
  1146. return this.clamp( min, max );
  1147. };
  1148. } )(),
  1149. floor: function () {
  1150. this.x = Math.floor( this.x );
  1151. this.y = Math.floor( this.y );
  1152. this.z = Math.floor( this.z );
  1153. return this;
  1154. },
  1155. ceil: function () {
  1156. this.x = Math.ceil( this.x );
  1157. this.y = Math.ceil( this.y );
  1158. this.z = Math.ceil( this.z );
  1159. return this;
  1160. },
  1161. round: function () {
  1162. this.x = Math.round( this.x );
  1163. this.y = Math.round( this.y );
  1164. this.z = Math.round( this.z );
  1165. return this;
  1166. },
  1167. roundToZero: function () {
  1168. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1169. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1170. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1171. return this;
  1172. },
  1173. negate: function () {
  1174. this.x = - this.x;
  1175. this.y = - this.y;
  1176. this.z = - this.z;
  1177. return this;
  1178. },
  1179. dot: function ( v ) {
  1180. return this.x * v.x + this.y * v.y + this.z * v.z;
  1181. },
  1182. lengthSq: function () {
  1183. return this.x * this.x + this.y * this.y + this.z * this.z;
  1184. },
  1185. length: function () {
  1186. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1187. },
  1188. lengthManhattan: function () {
  1189. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1190. },
  1191. normalize: function () {
  1192. return this.divideScalar( this.length() );
  1193. },
  1194. setLength: function ( l ) {
  1195. var oldLength = this.length();
  1196. if ( oldLength !== 0 && l !== oldLength ) {
  1197. this.multiplyScalar( l / oldLength );
  1198. }
  1199. return this;
  1200. },
  1201. lerp: function ( v, alpha ) {
  1202. this.x += ( v.x - this.x ) * alpha;
  1203. this.y += ( v.y - this.y ) * alpha;
  1204. this.z += ( v.z - this.z ) * alpha;
  1205. return this;
  1206. },
  1207. cross: function ( v, w ) {
  1208. if ( w !== undefined ) {
  1209. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1210. return this.crossVectors( v, w );
  1211. }
  1212. var x = this.x, y = this.y, z = this.z;
  1213. this.x = y * v.z - z * v.y;
  1214. this.y = z * v.x - x * v.z;
  1215. this.z = x * v.y - y * v.x;
  1216. return this;
  1217. },
  1218. crossVectors: function ( a, b ) {
  1219. var ax = a.x, ay = a.y, az = a.z;
  1220. var bx = b.x, by = b.y, bz = b.z;
  1221. this.x = ay * bz - az * by;
  1222. this.y = az * bx - ax * bz;
  1223. this.z = ax * by - ay * bx;
  1224. return this;
  1225. },
  1226. projectOnVector: function () {
  1227. var v1, dot;
  1228. return function ( vector ) {
  1229. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1230. v1.copy( vector ).normalize();
  1231. dot = this.dot( v1 );
  1232. return this.copy( v1 ).multiplyScalar( dot );
  1233. };
  1234. }(),
  1235. projectOnPlane: function () {
  1236. var v1;
  1237. return function ( planeNormal ) {
  1238. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1239. v1.copy( this ).projectOnVector( planeNormal );
  1240. return this.sub( v1 );
  1241. }
  1242. }(),
  1243. reflect: function () {
  1244. // reflect incident vector off plane orthogonal to normal
  1245. // normal is assumed to have unit length
  1246. var v1;
  1247. return function ( normal ) {
  1248. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1249. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1250. }
  1251. }(),
  1252. angleTo: function ( v ) {
  1253. var theta = this.dot( v ) / ( this.length() * v.length() );
  1254. // clamp, to handle numerical problems
  1255. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1256. },
  1257. distanceTo: function ( v ) {
  1258. return Math.sqrt( this.distanceToSquared( v ) );
  1259. },
  1260. distanceToSquared: function ( v ) {
  1261. var dx = this.x - v.x;
  1262. var dy = this.y - v.y;
  1263. var dz = this.z - v.z;
  1264. return dx * dx + dy * dy + dz * dz;
  1265. },
  1266. setEulerFromRotationMatrix: function ( m, order ) {
  1267. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  1268. },
  1269. setEulerFromQuaternion: function ( q, order ) {
  1270. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  1271. },
  1272. getPositionFromMatrix: function ( m ) {
  1273. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  1274. return this.setFromMatrixPosition( m );
  1275. },
  1276. getScaleFromMatrix: function ( m ) {
  1277. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  1278. return this.setFromMatrixScale( m );
  1279. },
  1280. getColumnFromMatrix: function ( index, matrix ) {
  1281. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  1282. return this.setFromMatrixColumn( index, matrix );
  1283. },
  1284. setFromMatrixPosition: function ( m ) {
  1285. this.x = m.elements[ 12 ];
  1286. this.y = m.elements[ 13 ];
  1287. this.z = m.elements[ 14 ];
  1288. return this;
  1289. },
  1290. setFromMatrixScale: function ( m ) {
  1291. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1292. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1293. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1294. this.x = sx;
  1295. this.y = sy;
  1296. this.z = sz;
  1297. return this;
  1298. },
  1299. setFromMatrixColumn: function ( index, matrix ) {
  1300. var offset = index * 4;
  1301. var me = matrix.elements;
  1302. this.x = me[ offset ];
  1303. this.y = me[ offset + 1 ];
  1304. this.z = me[ offset + 2 ];
  1305. return this;
  1306. },
  1307. equals: function ( v ) {
  1308. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1309. },
  1310. fromArray: function ( array ) {
  1311. this.x = array[ 0 ];
  1312. this.y = array[ 1 ];
  1313. this.z = array[ 2 ];
  1314. return this;
  1315. },
  1316. toArray: function () {
  1317. return [ this.x, this.y, this.z ];
  1318. },
  1319. clone: function () {
  1320. return new THREE.Vector3( this.x, this.y, this.z );
  1321. }
  1322. };
  1323. // File:src/math/Vector4.js
  1324. /**
  1325. * @author supereggbert / http://www.paulbrunt.co.uk/
  1326. * @author philogb / http://blog.thejit.org/
  1327. * @author mikael emtinger / http://gomo.se/
  1328. * @author egraether / http://egraether.com/
  1329. * @author WestLangley / http://github.com/WestLangley
  1330. */
  1331. THREE.Vector4 = function ( x, y, z, w ) {
  1332. this.x = x || 0;
  1333. this.y = y || 0;
  1334. this.z = z || 0;
  1335. this.w = ( w !== undefined ) ? w : 1;
  1336. };
  1337. THREE.Vector4.prototype = {
  1338. constructor: THREE.Vector4,
  1339. set: function ( x, y, z, w ) {
  1340. this.x = x;
  1341. this.y = y;
  1342. this.z = z;
  1343. this.w = w;
  1344. return this;
  1345. },
  1346. setX: function ( x ) {
  1347. this.x = x;
  1348. return this;
  1349. },
  1350. setY: function ( y ) {
  1351. this.y = y;
  1352. return this;
  1353. },
  1354. setZ: function ( z ) {
  1355. this.z = z;
  1356. return this;
  1357. },
  1358. setW: function ( w ) {
  1359. this.w = w;
  1360. return this;
  1361. },
  1362. setComponent: function ( index, value ) {
  1363. switch ( index ) {
  1364. case 0: this.x = value; break;
  1365. case 1: this.y = value; break;
  1366. case 2: this.z = value; break;
  1367. case 3: this.w = value; break;
  1368. default: throw new Error( 'index is out of range: ' + index );
  1369. }
  1370. },
  1371. getComponent: function ( index ) {
  1372. switch ( index ) {
  1373. case 0: return this.x;
  1374. case 1: return this.y;
  1375. case 2: return this.z;
  1376. case 3: return this.w;
  1377. default: throw new Error( 'index is out of range: ' + index );
  1378. }
  1379. },
  1380. copy: function ( v ) {
  1381. this.x = v.x;
  1382. this.y = v.y;
  1383. this.z = v.z;
  1384. this.w = ( v.w !== undefined ) ? v.w : 1;
  1385. return this;
  1386. },
  1387. add: function ( v, w ) {
  1388. if ( w !== undefined ) {
  1389. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1390. return this.addVectors( v, w );
  1391. }
  1392. this.x += v.x;
  1393. this.y += v.y;
  1394. this.z += v.z;
  1395. this.w += v.w;
  1396. return this;
  1397. },
  1398. addScalar: function ( s ) {
  1399. this.x += s;
  1400. this.y += s;
  1401. this.z += s;
  1402. this.w += s;
  1403. return this;
  1404. },
  1405. addVectors: function ( a, b ) {
  1406. this.x = a.x + b.x;
  1407. this.y = a.y + b.y;
  1408. this.z = a.z + b.z;
  1409. this.w = a.w + b.w;
  1410. return this;
  1411. },
  1412. sub: function ( v, w ) {
  1413. if ( w !== undefined ) {
  1414. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1415. return this.subVectors( v, w );
  1416. }
  1417. this.x -= v.x;
  1418. this.y -= v.y;
  1419. this.z -= v.z;
  1420. this.w -= v.w;
  1421. return this;
  1422. },
  1423. subVectors: function ( a, b ) {
  1424. this.x = a.x - b.x;
  1425. this.y = a.y - b.y;
  1426. this.z = a.z - b.z;
  1427. this.w = a.w - b.w;
  1428. return this;
  1429. },
  1430. multiplyScalar: function ( scalar ) {
  1431. this.x *= scalar;
  1432. this.y *= scalar;
  1433. this.z *= scalar;
  1434. this.w *= scalar;
  1435. return this;
  1436. },
  1437. applyMatrix4: function ( m ) {
  1438. var x = this.x;
  1439. var y = this.y;
  1440. var z = this.z;
  1441. var w = this.w;
  1442. var e = m.elements;
  1443. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1444. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1445. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1446. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1447. return this;
  1448. },
  1449. divideScalar: function ( scalar ) {
  1450. if ( scalar !== 0 ) {
  1451. var invScalar = 1 / scalar;
  1452. this.x *= invScalar;
  1453. this.y *= invScalar;
  1454. this.z *= invScalar;
  1455. this.w *= invScalar;
  1456. } else {
  1457. this.x = 0;
  1458. this.y = 0;
  1459. this.z = 0;
  1460. this.w = 1;
  1461. }
  1462. return this;
  1463. },
  1464. setAxisAngleFromQuaternion: function ( q ) {
  1465. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1466. // q is assumed to be normalized
  1467. this.w = 2 * Math.acos( q.w );
  1468. var s = Math.sqrt( 1 - q.w * q.w );
  1469. if ( s < 0.0001 ) {
  1470. this.x = 1;
  1471. this.y = 0;
  1472. this.z = 0;
  1473. } else {
  1474. this.x = q.x / s;
  1475. this.y = q.y / s;
  1476. this.z = q.z / s;
  1477. }
  1478. return this;
  1479. },
  1480. setAxisAngleFromRotationMatrix: function ( m ) {
  1481. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1482. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1483. var angle, x, y, z, // variables for result
  1484. epsilon = 0.01, // margin to allow for rounding errors
  1485. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1486. te = m.elements,
  1487. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1488. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1489. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1490. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1491. && ( Math.abs( m13 - m31 ) < epsilon )
  1492. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1493. // singularity found
  1494. // first check for identity matrix which must have +1 for all terms
  1495. // in leading diagonal and zero in other terms
  1496. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1497. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1498. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1499. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1500. // this singularity is identity matrix so angle = 0
  1501. this.set( 1, 0, 0, 0 );
  1502. return this; // zero angle, arbitrary axis
  1503. }
  1504. // otherwise this singularity is angle = 180
  1505. angle = Math.PI;
  1506. var xx = ( m11 + 1 ) / 2;
  1507. var yy = ( m22 + 1 ) / 2;
  1508. var zz = ( m33 + 1 ) / 2;
  1509. var xy = ( m12 + m21 ) / 4;
  1510. var xz = ( m13 + m31 ) / 4;
  1511. var yz = ( m23 + m32 ) / 4;
  1512. if ( ( xx > yy ) && ( xx > zz ) ) { // m11 is the largest diagonal term
  1513. if ( xx < epsilon ) {
  1514. x = 0;
  1515. y = 0.707106781;
  1516. z = 0.707106781;
  1517. } else {
  1518. x = Math.sqrt( xx );
  1519. y = xy / x;
  1520. z = xz / x;
  1521. }
  1522. } else if ( yy > zz ) { // m22 is the largest diagonal term
  1523. if ( yy < epsilon ) {
  1524. x = 0.707106781;
  1525. y = 0;
  1526. z = 0.707106781;
  1527. } else {
  1528. y = Math.sqrt( yy );
  1529. x = xy / y;
  1530. z = yz / y;
  1531. }
  1532. } else { // m33 is the largest diagonal term so base result on this
  1533. if ( zz < epsilon ) {
  1534. x = 0.707106781;
  1535. y = 0.707106781;
  1536. z = 0;
  1537. } else {
  1538. z = Math.sqrt( zz );
  1539. x = xz / z;
  1540. y = yz / z;
  1541. }
  1542. }
  1543. this.set( x, y, z, angle );
  1544. return this; // return 180 deg rotation
  1545. }
  1546. // as we have reached here there are no singularities so we can handle normally
  1547. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1548. + ( m13 - m31 ) * ( m13 - m31 )
  1549. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1550. if ( Math.abs( s ) < 0.001 ) s = 1;
  1551. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1552. // caught by singularity test above, but I've left it in just in case
  1553. this.x = ( m32 - m23 ) / s;
  1554. this.y = ( m13 - m31 ) / s;
  1555. this.z = ( m21 - m12 ) / s;
  1556. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1557. return this;
  1558. },
  1559. min: function ( v ) {
  1560. if ( this.x > v.x ) {
  1561. this.x = v.x;
  1562. }
  1563. if ( this.y > v.y ) {
  1564. this.y = v.y;
  1565. }
  1566. if ( this.z > v.z ) {
  1567. this.z = v.z;
  1568. }
  1569. if ( this.w > v.w ) {
  1570. this.w = v.w;
  1571. }
  1572. return this;
  1573. },
  1574. max: function ( v ) {
  1575. if ( this.x < v.x ) {
  1576. this.x = v.x;
  1577. }
  1578. if ( this.y < v.y ) {
  1579. this.y = v.y;
  1580. }
  1581. if ( this.z < v.z ) {
  1582. this.z = v.z;
  1583. }
  1584. if ( this.w < v.w ) {
  1585. this.w = v.w;
  1586. }
  1587. return this;
  1588. },
  1589. clamp: function ( min, max ) {
  1590. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1591. if ( this.x < min.x ) {
  1592. this.x = min.x;
  1593. } else if ( this.x > max.x ) {
  1594. this.x = max.x;
  1595. }
  1596. if ( this.y < min.y ) {
  1597. this.y = min.y;
  1598. } else if ( this.y > max.y ) {
  1599. this.y = max.y;
  1600. }
  1601. if ( this.z < min.z ) {
  1602. this.z = min.z;
  1603. } else if ( this.z > max.z ) {
  1604. this.z = max.z;
  1605. }
  1606. if ( this.w < min.w ) {
  1607. this.w = min.w;
  1608. } else if ( this.w > max.w ) {
  1609. this.w = max.w;
  1610. }
  1611. return this;
  1612. },
  1613. clampScalar: ( function () {
  1614. var min, max;
  1615. return function ( minVal, maxVal ) {
  1616. if ( min === undefined ) {
  1617. min = new THREE.Vector4();
  1618. max = new THREE.Vector4();
  1619. }
  1620. min.set( minVal, minVal, minVal, minVal );
  1621. max.set( maxVal, maxVal, maxVal, maxVal );
  1622. return this.clamp( min, max );
  1623. };
  1624. } )(),
  1625. floor: function () {
  1626. this.x = Math.floor( this.x );
  1627. this.y = Math.floor( this.y );
  1628. this.z = Math.floor( this.z );
  1629. this.w = Math.floor( this.w );
  1630. return this;
  1631. },
  1632. ceil: function () {
  1633. this.x = Math.ceil( this.x );
  1634. this.y = Math.ceil( this.y );
  1635. this.z = Math.ceil( this.z );
  1636. this.w = Math.ceil( this.w );
  1637. return this;
  1638. },
  1639. round: function () {
  1640. this.x = Math.round( this.x );
  1641. this.y = Math.round( this.y );
  1642. this.z = Math.round( this.z );
  1643. this.w = Math.round( this.w );
  1644. return this;
  1645. },
  1646. roundToZero: function () {
  1647. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1648. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1649. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1650. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1651. return this;
  1652. },
  1653. negate: function () {
  1654. this.x = - this.x;
  1655. this.y = - this.y;
  1656. this.z = - this.z;
  1657. this.w = - this.w;
  1658. return this;
  1659. },
  1660. dot: function ( v ) {
  1661. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1662. },
  1663. lengthSq: function () {
  1664. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1665. },
  1666. length: function () {
  1667. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1668. },
  1669. lengthManhattan: function () {
  1670. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1671. },
  1672. normalize: function () {
  1673. return this.divideScalar( this.length() );
  1674. },
  1675. setLength: function ( l ) {
  1676. var oldLength = this.length();
  1677. if ( oldLength !== 0 && l !== oldLength ) {
  1678. this.multiplyScalar( l / oldLength );
  1679. }
  1680. return this;
  1681. },
  1682. lerp: function ( v, alpha ) {
  1683. this.x += ( v.x - this.x ) * alpha;
  1684. this.y += ( v.y - this.y ) * alpha;
  1685. this.z += ( v.z - this.z ) * alpha;
  1686. this.w += ( v.w - this.w ) * alpha;
  1687. return this;
  1688. },
  1689. equals: function ( v ) {
  1690. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1691. },
  1692. fromArray: function ( array ) {
  1693. this.x = array[ 0 ];
  1694. this.y = array[ 1 ];
  1695. this.z = array[ 2 ];
  1696. this.w = array[ 3 ];
  1697. return this;
  1698. },
  1699. toArray: function () {
  1700. return [ this.x, this.y, this.z, this.w ];
  1701. },
  1702. clone: function () {
  1703. return new THREE.Vector4( this.x, this.y, this.z, this.w );
  1704. }
  1705. };
  1706. // File:src/math/Euler.js
  1707. /**
  1708. * @author mrdoob / http://mrdoob.com/
  1709. * @author WestLangley / http://github.com/WestLangley
  1710. * @author bhouston / http://exocortex.com
  1711. */
  1712. THREE.Euler = function ( x, y, z, order ) {
  1713. this._x = x || 0;
  1714. this._y = y || 0;
  1715. this._z = z || 0;
  1716. this._order = order || THREE.Euler.DefaultOrder;
  1717. };
  1718. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1719. THREE.Euler.DefaultOrder = 'XYZ';
  1720. THREE.Euler.prototype = {
  1721. constructor: THREE.Euler,
  1722. _x: 0, _y: 0, _z: 0, _order: THREE.Euler.DefaultOrder,
  1723. get x () {
  1724. return this._x;
  1725. },
  1726. set x ( value ) {
  1727. this._x = value;
  1728. this.onChangeCallback();
  1729. },
  1730. get y () {
  1731. return this._y;
  1732. },
  1733. set y ( value ) {
  1734. this._y = value;
  1735. this.onChangeCallback();
  1736. },
  1737. get z () {
  1738. return this._z;
  1739. },
  1740. set z ( value ) {
  1741. this._z = value;
  1742. this.onChangeCallback();
  1743. },
  1744. get order () {
  1745. return this._order;
  1746. },
  1747. set order ( value ) {
  1748. this._order = value;
  1749. this.onChangeCallback();
  1750. },
  1751. set: function ( x, y, z, order ) {
  1752. this._x = x;
  1753. this._y = y;
  1754. this._z = z;
  1755. this._order = order || this._order;
  1756. this.onChangeCallback();
  1757. return this;
  1758. },
  1759. copy: function ( euler ) {
  1760. this._x = euler._x;
  1761. this._y = euler._y;
  1762. this._z = euler._z;
  1763. this._order = euler._order;
  1764. this.onChangeCallback();
  1765. return this;
  1766. },
  1767. setFromRotationMatrix: function ( m, order ) {
  1768. var clamp = THREE.Math.clamp;
  1769. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1770. var te = m.elements;
  1771. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  1772. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  1773. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1774. order = order || this._order;
  1775. if ( order === 'XYZ' ) {
  1776. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  1777. if ( Math.abs( m13 ) < 0.99999 ) {
  1778. this._x = Math.atan2( - m23, m33 );
  1779. this._z = Math.atan2( - m12, m11 );
  1780. } else {
  1781. this._x = Math.atan2( m32, m22 );
  1782. this._z = 0;
  1783. }
  1784. } else if ( order === 'YXZ' ) {
  1785. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  1786. if ( Math.abs( m23 ) < 0.99999 ) {
  1787. this._y = Math.atan2( m13, m33 );
  1788. this._z = Math.atan2( m21, m22 );
  1789. } else {
  1790. this._y = Math.atan2( - m31, m11 );
  1791. this._z = 0;
  1792. }
  1793. } else if ( order === 'ZXY' ) {
  1794. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  1795. if ( Math.abs( m32 ) < 0.99999 ) {
  1796. this._y = Math.atan2( - m31, m33 );
  1797. this._z = Math.atan2( - m12, m22 );
  1798. } else {
  1799. this._y = 0;
  1800. this._z = Math.atan2( m21, m11 );
  1801. }
  1802. } else if ( order === 'ZYX' ) {
  1803. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  1804. if ( Math.abs( m31 ) < 0.99999 ) {
  1805. this._x = Math.atan2( m32, m33 );
  1806. this._z = Math.atan2( m21, m11 );
  1807. } else {
  1808. this._x = 0;
  1809. this._z = Math.atan2( - m12, m22 );
  1810. }
  1811. } else if ( order === 'YZX' ) {
  1812. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  1813. if ( Math.abs( m21 ) < 0.99999 ) {
  1814. this._x = Math.atan2( - m23, m22 );
  1815. this._y = Math.atan2( - m31, m11 );
  1816. } else {
  1817. this._x = 0;
  1818. this._y = Math.atan2( m13, m33 );
  1819. }
  1820. } else if ( order === 'XZY' ) {
  1821. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  1822. if ( Math.abs( m12 ) < 0.99999 ) {
  1823. this._x = Math.atan2( m32, m22 );
  1824. this._y = Math.atan2( m13, m11 );
  1825. } else {
  1826. this._x = Math.atan2( - m23, m33 );
  1827. this._y = 0;
  1828. }
  1829. } else {
  1830. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  1831. }
  1832. this._order = order;
  1833. this.onChangeCallback();
  1834. return this;
  1835. },
  1836. setFromQuaternion: function ( q, order, update ) {
  1837. var clamp = THREE.Math.clamp;
  1838. // q is assumed to be normalized
  1839. // http://www.mathworks.com/matlabcentral/fileexchange/20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/content/SpinCalc.m
  1840. var sqx = q.x * q.x;
  1841. var sqy = q.y * q.y;
  1842. var sqz = q.z * q.z;
  1843. var sqw = q.w * q.w;
  1844. order = order || this._order;
  1845. if ( order === 'XYZ' ) {
  1846. this._x = Math.atan2( 2 * ( q.x * q.w - q.y * q.z ), ( sqw - sqx - sqy + sqz ) );
  1847. this._y = Math.asin( clamp( 2 * ( q.x * q.z + q.y * q.w ), - 1, 1 ) );
  1848. this._z = Math.atan2( 2 * ( q.z * q.w - q.x * q.y ), ( sqw + sqx - sqy - sqz ) );
  1849. } else if ( order === 'YXZ' ) {
  1850. this._x = Math.asin( clamp( 2 * ( q.x * q.w - q.y * q.z ), - 1, 1 ) );
  1851. this._y = Math.atan2( 2 * ( q.x * q.z + q.y * q.w ), ( sqw - sqx - sqy + sqz ) );
  1852. this._z = Math.atan2( 2 * ( q.x * q.y + q.z * q.w ), ( sqw - sqx + sqy - sqz ) );
  1853. } else if ( order === 'ZXY' ) {
  1854. this._x = Math.asin( clamp( 2 * ( q.x * q.w + q.y * q.z ), - 1, 1 ) );
  1855. this._y = Math.atan2( 2 * ( q.y * q.w - q.z * q.x ), ( sqw - sqx - sqy + sqz ) );
  1856. this._z = Math.atan2( 2 * ( q.z * q.w - q.x * q.y ), ( sqw - sqx + sqy - sqz ) );
  1857. } else if ( order === 'ZYX' ) {
  1858. this._x = Math.atan2( 2 * ( q.x * q.w + q.z * q.y ), ( sqw - sqx - sqy + sqz ) );
  1859. this._y = Math.asin( clamp( 2 * ( q.y * q.w - q.x * q.z ), - 1, 1 ) );
  1860. this._z = Math.atan2( 2 * ( q.x * q.y + q.z * q.w ), ( sqw + sqx - sqy - sqz ) );
  1861. } else if ( order === 'YZX' ) {
  1862. this._x = Math.atan2( 2 * ( q.x * q.w - q.z * q.y ), ( sqw - sqx + sqy - sqz ) );
  1863. this._y = Math.atan2( 2 * ( q.y * q.w - q.x * q.z ), ( sqw + sqx - sqy - sqz ) );
  1864. this._z = Math.asin( clamp( 2 * ( q.x * q.y + q.z * q.w ), - 1, 1 ) );
  1865. } else if ( order === 'XZY' ) {
  1866. this._x = Math.atan2( 2 * ( q.x * q.w + q.y * q.z ), ( sqw - sqx + sqy - sqz ) );
  1867. this._y = Math.atan2( 2 * ( q.x * q.z + q.y * q.w ), ( sqw + sqx - sqy - sqz ) );
  1868. this._z = Math.asin( clamp( 2 * ( q.z * q.w - q.x * q.y ), - 1, 1 ) );
  1869. } else {
  1870. console.warn( 'THREE.Euler: .setFromQuaternion() given unsupported order: ' + order )
  1871. }
  1872. this._order = order;
  1873. if ( update !== false ) this.onChangeCallback();
  1874. return this;
  1875. },
  1876. reorder: function () {
  1877. // WARNING: this discards revolution information -bhouston
  1878. var q = new THREE.Quaternion();
  1879. return function ( newOrder ) {
  1880. q.setFromEuler( this );
  1881. this.setFromQuaternion( q, newOrder );
  1882. };
  1883. }(),
  1884. equals: function ( euler ) {
  1885. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  1886. },
  1887. fromArray: function ( array ) {
  1888. this._x = array[ 0 ];
  1889. this._y = array[ 1 ];
  1890. this._z = array[ 2 ];
  1891. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  1892. this.onChangeCallback();
  1893. return this;
  1894. },
  1895. toArray: function () {
  1896. return [ this._x, this._y, this._z, this._order ];
  1897. },
  1898. onChange: function ( callback ) {
  1899. this.onChangeCallback = callback;
  1900. return this;
  1901. },
  1902. onChangeCallback: function () {},
  1903. clone: function () {
  1904. return new THREE.Euler( this._x, this._y, this._z, this._order );
  1905. }
  1906. };
  1907. // File:src/math/Line3.js
  1908. /**
  1909. * @author bhouston / http://exocortex.com
  1910. */
  1911. THREE.Line3 = function ( start, end ) {
  1912. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  1913. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  1914. };
  1915. THREE.Line3.prototype = {
  1916. constructor: THREE.Line3,
  1917. set: function ( start, end ) {
  1918. this.start.copy( start );
  1919. this.end.copy( end );
  1920. return this;
  1921. },
  1922. copy: function ( line ) {
  1923. this.start.copy( line.start );
  1924. this.end.copy( line.end );
  1925. return this;
  1926. },
  1927. center: function ( optionalTarget ) {
  1928. var result = optionalTarget || new THREE.Vector3();
  1929. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  1930. },
  1931. delta: function ( optionalTarget ) {
  1932. var result = optionalTarget || new THREE.Vector3();
  1933. return result.subVectors( this.end, this.start );
  1934. },
  1935. distanceSq: function () {
  1936. return this.start.distanceToSquared( this.end );
  1937. },
  1938. distance: function () {
  1939. return this.start.distanceTo( this.end );
  1940. },
  1941. at: function ( t, optionalTarget ) {
  1942. var result = optionalTarget || new THREE.Vector3();
  1943. return this.delta( result ).multiplyScalar( t ).add( this.start );
  1944. },
  1945. closestPointToPointParameter: function () {
  1946. var startP = new THREE.Vector3();
  1947. var startEnd = new THREE.Vector3();
  1948. return function ( point, clampToLine ) {
  1949. startP.subVectors( point, this.start );
  1950. startEnd.subVectors( this.end, this.start );
  1951. var startEnd2 = startEnd.dot( startEnd );
  1952. var startEnd_startP = startEnd.dot( startP );
  1953. var t = startEnd_startP / startEnd2;
  1954. if ( clampToLine ) {
  1955. t = THREE.Math.clamp( t, 0, 1 );
  1956. }
  1957. return t;
  1958. };
  1959. }(),
  1960. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  1961. var t = this.closestPointToPointParameter( point, clampToLine );
  1962. var result = optionalTarget || new THREE.Vector3();
  1963. return this.delta( result ).multiplyScalar( t ).add( this.start );
  1964. },
  1965. applyMatrix4: function ( matrix ) {
  1966. this.start.applyMatrix4( matrix );
  1967. this.end.applyMatrix4( matrix );
  1968. return this;
  1969. },
  1970. equals: function ( line ) {
  1971. return line.start.equals( this.start ) && line.end.equals( this.end );
  1972. },
  1973. clone: function () {
  1974. return new THREE.Line3().copy( this );
  1975. }
  1976. };
  1977. // File:src/math/Box2.js
  1978. /**
  1979. * @author bhouston / http://exocortex.com
  1980. */
  1981. THREE.Box2 = function ( min, max ) {
  1982. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  1983. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  1984. };
  1985. THREE.Box2.prototype = {
  1986. constructor: THREE.Box2,
  1987. set: function ( min, max ) {
  1988. this.min.copy( min );
  1989. this.max.copy( max );
  1990. return this;
  1991. },
  1992. setFromPoints: function ( points ) {
  1993. this.makeEmpty();
  1994. for ( var i = 0, il = points.length; i < il; i ++ ) {
  1995. this.expandByPoint( points[ i ] )
  1996. }
  1997. return this;
  1998. },
  1999. setFromCenterAndSize: function () {
  2000. var v1 = new THREE.Vector2();
  2001. return function ( center, size ) {
  2002. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2003. this.min.copy( center ).sub( halfSize );
  2004. this.max.copy( center ).add( halfSize );
  2005. return this;
  2006. };
  2007. }(),
  2008. copy: function ( box ) {
  2009. this.min.copy( box.min );
  2010. this.max.copy( box.max );
  2011. return this;
  2012. },
  2013. makeEmpty: function () {
  2014. this.min.x = this.min.y = Infinity;
  2015. this.max.x = this.max.y = - Infinity;
  2016. return this;
  2017. },
  2018. empty: function () {
  2019. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2020. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2021. },
  2022. center: function ( optionalTarget ) {
  2023. var result = optionalTarget || new THREE.Vector2();
  2024. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2025. },
  2026. size: function ( optionalTarget ) {
  2027. var result = optionalTarget || new THREE.Vector2();
  2028. return result.subVectors( this.max, this.min );
  2029. },
  2030. expandByPoint: function ( point ) {
  2031. this.min.min( point );
  2032. this.max.max( point );
  2033. return this;
  2034. },
  2035. expandByVector: function ( vector ) {
  2036. this.min.sub( vector );
  2037. this.max.add( vector );
  2038. return this;
  2039. },
  2040. expandByScalar: function ( scalar ) {
  2041. this.min.addScalar( - scalar );
  2042. this.max.addScalar( scalar );
  2043. return this;
  2044. },
  2045. containsPoint: function ( point ) {
  2046. if ( point.x < this.min.x || point.x > this.max.x ||
  2047. point.y < this.min.y || point.y > this.max.y ) {
  2048. return false;
  2049. }
  2050. return true;
  2051. },
  2052. containsBox: function ( box ) {
  2053. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2054. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2055. return true;
  2056. }
  2057. return false;
  2058. },
  2059. getParameter: function ( point, optionalTarget ) {
  2060. // This can potentially have a divide by zero if the box
  2061. // has a size dimension of 0.
  2062. var result = optionalTarget || new THREE.Vector2();
  2063. return result.set(
  2064. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2065. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2066. );
  2067. },
  2068. isIntersectionBox: function ( box ) {
  2069. // using 6 splitting planes to rule out intersections.
  2070. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2071. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2072. return false;
  2073. }
  2074. return true;
  2075. },
  2076. clampPoint: function ( point, optionalTarget ) {
  2077. var result = optionalTarget || new THREE.Vector2();
  2078. return result.copy( point ).clamp( this.min, this.max );
  2079. },
  2080. distanceToPoint: function () {
  2081. var v1 = new THREE.Vector2();
  2082. return function ( point ) {
  2083. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2084. return clampedPoint.sub( point ).length();
  2085. };
  2086. }(),
  2087. intersect: function ( box ) {
  2088. this.min.max( box.min );
  2089. this.max.min( box.max );
  2090. return this;
  2091. },
  2092. union: function ( box ) {
  2093. this.min.min( box.min );
  2094. this.max.max( box.max );
  2095. return this;
  2096. },
  2097. translate: function ( offset ) {
  2098. this.min.add( offset );
  2099. this.max.add( offset );
  2100. return this;
  2101. },
  2102. equals: function ( box ) {
  2103. return box.min.equals( this.min ) && box.max.equals( this.max );
  2104. },
  2105. clone: function () {
  2106. return new THREE.Box2().copy( this );
  2107. }
  2108. };
  2109. // File:src/math/Box3.js
  2110. /**
  2111. * @author bhouston / http://exocortex.com
  2112. * @author WestLangley / http://github.com/WestLangley
  2113. */
  2114. THREE.Box3 = function ( min, max ) {
  2115. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2116. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2117. };
  2118. THREE.Box3.prototype = {
  2119. constructor: THREE.Box3,
  2120. set: function ( min, max ) {
  2121. this.min.copy( min );
  2122. this.max.copy( max );
  2123. return this;
  2124. },
  2125. setFromPoints: function ( points ) {
  2126. this.makeEmpty();
  2127. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2128. this.expandByPoint( points[ i ] )
  2129. }
  2130. return this;
  2131. },
  2132. setFromCenterAndSize: function () {
  2133. var v1 = new THREE.Vector3();
  2134. return function ( center, size ) {
  2135. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2136. this.min.copy( center ).sub( halfSize );
  2137. this.max.copy( center ).add( halfSize );
  2138. return this;
  2139. };
  2140. }(),
  2141. setFromObject: function () {
  2142. // Computes the world-axis-aligned bounding box of an object (including its children),
  2143. // accounting for both the object's, and childrens', world transforms
  2144. var v1 = new THREE.Vector3();
  2145. return function ( object ) {
  2146. var scope = this;
  2147. object.updateMatrixWorld( true );
  2148. this.makeEmpty();
  2149. object.traverse( function ( node ) {
  2150. if ( node.geometry !== undefined && node.geometry.vertices !== undefined ) {
  2151. var vertices = node.geometry.vertices;
  2152. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2153. v1.copy( vertices[ i ] );
  2154. v1.applyMatrix4( node.matrixWorld );
  2155. scope.expandByPoint( v1 );
  2156. }
  2157. }
  2158. } );
  2159. return this;
  2160. };
  2161. }(),
  2162. copy: function ( box ) {
  2163. this.min.copy( box.min );
  2164. this.max.copy( box.max );
  2165. return this;
  2166. },
  2167. makeEmpty: function () {
  2168. this.min.x = this.min.y = this.min.z = Infinity;
  2169. this.max.x = this.max.y = this.max.z = - Infinity;
  2170. return this;
  2171. },
  2172. empty: function () {
  2173. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2174. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2175. },
  2176. center: function ( optionalTarget ) {
  2177. var result = optionalTarget || new THREE.Vector3();
  2178. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2179. },
  2180. size: function ( optionalTarget ) {
  2181. var result = optionalTarget || new THREE.Vector3();
  2182. return result.subVectors( this.max, this.min );
  2183. },
  2184. expandByPoint: function ( point ) {
  2185. this.min.min( point );
  2186. this.max.max( point );
  2187. return this;
  2188. },
  2189. expandByVector: function ( vector ) {
  2190. this.min.sub( vector );
  2191. this.max.add( vector );
  2192. return this;
  2193. },
  2194. expandByScalar: function ( scalar ) {
  2195. this.min.addScalar( - scalar );
  2196. this.max.addScalar( scalar );
  2197. return this;
  2198. },
  2199. containsPoint: function ( point ) {
  2200. if ( point.x < this.min.x || point.x > this.max.x ||
  2201. point.y < this.min.y || point.y > this.max.y ||
  2202. point.z < this.min.z || point.z > this.max.z ) {
  2203. return false;
  2204. }
  2205. return true;
  2206. },
  2207. containsBox: function ( box ) {
  2208. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2209. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2210. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2211. return true;
  2212. }
  2213. return false;
  2214. },
  2215. getParameter: function ( point, optionalTarget ) {
  2216. // This can potentially have a divide by zero if the box
  2217. // has a size dimension of 0.
  2218. var result = optionalTarget || new THREE.Vector3();
  2219. return result.set(
  2220. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2221. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2222. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2223. );
  2224. },
  2225. isIntersectionBox: function ( box ) {
  2226. // using 6 splitting planes to rule out intersections.
  2227. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2228. box.max.y < this.min.y || box.min.y > this.max.y ||
  2229. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2230. return false;
  2231. }
  2232. return true;
  2233. },
  2234. clampPoint: function ( point, optionalTarget ) {
  2235. var result = optionalTarget || new THREE.Vector3();
  2236. return result.copy( point ).clamp( this.min, this.max );
  2237. },
  2238. distanceToPoint: function () {
  2239. var v1 = new THREE.Vector3();
  2240. return function ( point ) {
  2241. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2242. return clampedPoint.sub( point ).length();
  2243. };
  2244. }(),
  2245. getBoundingSphere: function () {
  2246. var v1 = new THREE.Vector3();
  2247. return function ( optionalTarget ) {
  2248. var result = optionalTarget || new THREE.Sphere();
  2249. result.center = this.center();
  2250. result.radius = this.size( v1 ).length() * 0.5;
  2251. return result;
  2252. };
  2253. }(),
  2254. intersect: function ( box ) {
  2255. this.min.max( box.min );
  2256. this.max.min( box.max );
  2257. return this;
  2258. },
  2259. union: function ( box ) {
  2260. this.min.min( box.min );
  2261. this.max.max( box.max );
  2262. return this;
  2263. },
  2264. applyMatrix4: function () {
  2265. var points = [
  2266. new THREE.Vector3(),
  2267. new THREE.Vector3(),
  2268. new THREE.Vector3(),
  2269. new THREE.Vector3(),
  2270. new THREE.Vector3(),
  2271. new THREE.Vector3(),
  2272. new THREE.Vector3(),
  2273. new THREE.Vector3()
  2274. ];
  2275. return function ( matrix ) {
  2276. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2277. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2278. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2279. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2280. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2281. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2282. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2283. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2284. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2285. this.makeEmpty();
  2286. this.setFromPoints( points );
  2287. return this;
  2288. };
  2289. }(),
  2290. translate: function ( offset ) {
  2291. this.min.add( offset );
  2292. this.max.add( offset );
  2293. return this;
  2294. },
  2295. equals: function ( box ) {
  2296. return box.min.equals( this.min ) && box.max.equals( this.max );
  2297. },
  2298. clone: function () {
  2299. return new THREE.Box3().copy( this );
  2300. }
  2301. };
  2302. // File:src/math/Matrix3.js
  2303. /**
  2304. * @author alteredq / http://alteredqualia.com/
  2305. * @author WestLangley / http://github.com/WestLangley
  2306. * @author bhouston / http://exocortex.com
  2307. */
  2308. THREE.Matrix3 = function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2309. this.elements = new Float32Array( 9 );
  2310. var te = this.elements;
  2311. te[ 0 ] = ( n11 !== undefined ) ? n11 : 1; te[ 3 ] = n12 || 0; te[ 6 ] = n13 || 0;
  2312. te[ 1 ] = n21 || 0; te[ 4 ] = ( n22 !== undefined ) ? n22 : 1; te[ 7 ] = n23 || 0;
  2313. te[ 2 ] = n31 || 0; te[ 5 ] = n32 || 0; te[ 8 ] = ( n33 !== undefined ) ? n33 : 1;
  2314. };
  2315. THREE.Matrix3.prototype = {
  2316. constructor: THREE.Matrix3,
  2317. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2318. var te = this.elements;
  2319. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2320. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2321. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2322. return this;
  2323. },
  2324. identity: function () {
  2325. this.set(
  2326. 1, 0, 0,
  2327. 0, 1, 0,
  2328. 0, 0, 1
  2329. );
  2330. return this;
  2331. },
  2332. copy: function ( m ) {
  2333. var me = m.elements;
  2334. this.set(
  2335. me[ 0 ], me[ 3 ], me[ 6 ],
  2336. me[ 1 ], me[ 4 ], me[ 7 ],
  2337. me[ 2 ], me[ 5 ], me[ 8 ]
  2338. );
  2339. return this;
  2340. },
  2341. multiplyVector3: function ( vector ) {
  2342. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  2343. return vector.applyMatrix3( this );
  2344. },
  2345. multiplyVector3Array: function ( a ) {
  2346. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2347. return this.applyToVector3Array( a );
  2348. },
  2349. applyToVector3Array: function () {
  2350. var v1 = new THREE.Vector3();
  2351. return function ( array, offset, length ) {
  2352. if ( offset === undefined ) offset = 0;
  2353. if ( length === undefined ) length = array.length;
  2354. for ( var i = 0, j = offset, il; i < length; i += 3, j += 3 ) {
  2355. v1.x = array[ j ];
  2356. v1.y = array[ j + 1 ];
  2357. v1.z = array[ j + 2 ];
  2358. v1.applyMatrix3( this );
  2359. array[ j ] = v1.x;
  2360. array[ j + 1 ] = v1.y;
  2361. array[ j + 2 ] = v1.z;
  2362. }
  2363. return array;
  2364. };
  2365. }(),
  2366. multiplyScalar: function ( s ) {
  2367. var te = this.elements;
  2368. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2369. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2370. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2371. return this;
  2372. },
  2373. determinant: function () {
  2374. var te = this.elements;
  2375. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2376. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2377. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2378. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2379. },
  2380. getInverse: function ( matrix, throwOnInvertible ) {
  2381. // input: THREE.Matrix4
  2382. // ( based on http://code.google.com/p/webgl-mjs/ )
  2383. var me = matrix.elements;
  2384. var te = this.elements;
  2385. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2386. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2387. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2388. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2389. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2390. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2391. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2392. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2393. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2394. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2395. // no inverse
  2396. if ( det === 0 ) {
  2397. var msg = "Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2398. if ( throwOnInvertible || false ) {
  2399. throw new Error( msg );
  2400. } else {
  2401. console.warn( msg );
  2402. }
  2403. this.identity();
  2404. return this;
  2405. }
  2406. this.multiplyScalar( 1.0 / det );
  2407. return this;
  2408. },
  2409. transpose: function () {
  2410. var tmp, m = this.elements;
  2411. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2412. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2413. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2414. return this;
  2415. },
  2416. flattenToArrayOffset: function ( array, offset ) {
  2417. var te = this.elements;
  2418. array[ offset ] = te[ 0 ];
  2419. array[ offset + 1 ] = te[ 1 ];
  2420. array[ offset + 2 ] = te[ 2 ];
  2421. array[ offset + 3 ] = te[ 3 ];
  2422. array[ offset + 4 ] = te[ 4 ];
  2423. array[ offset + 5 ] = te[ 5 ];
  2424. array[ offset + 6 ] = te[ 6 ];
  2425. array[ offset + 7 ] = te[ 7 ];
  2426. array[ offset + 8 ] = te[ 8 ];
  2427. return array;
  2428. },
  2429. getNormalMatrix: function ( m ) {
  2430. // input: THREE.Matrix4
  2431. this.getInverse( m ).transpose();
  2432. return this;
  2433. },
  2434. transposeIntoArray: function ( r ) {
  2435. var m = this.elements;
  2436. r[ 0 ] = m[ 0 ];
  2437. r[ 1 ] = m[ 3 ];
  2438. r[ 2 ] = m[ 6 ];
  2439. r[ 3 ] = m[ 1 ];
  2440. r[ 4 ] = m[ 4 ];
  2441. r[ 5 ] = m[ 7 ];
  2442. r[ 6 ] = m[ 2 ];
  2443. r[ 7 ] = m[ 5 ];
  2444. r[ 8 ] = m[ 8 ];
  2445. return this;
  2446. },
  2447. fromArray: function ( array ) {
  2448. this.elements.set( array );
  2449. return this;
  2450. },
  2451. toArray: function () {
  2452. var te = this.elements;
  2453. return [
  2454. te[ 0 ], te[ 1 ], te[ 2 ],
  2455. te[ 3 ], te[ 4 ], te[ 5 ],
  2456. te[ 6 ], te[ 7 ], te[ 8 ]
  2457. ];
  2458. },
  2459. clone: function () {
  2460. var te = this.elements;
  2461. return new THREE.Matrix3(
  2462. te[ 0 ], te[ 3 ], te[ 6 ],
  2463. te[ 1 ], te[ 4 ], te[ 7 ],
  2464. te[ 2 ], te[ 5 ], te[ 8 ]
  2465. );
  2466. }
  2467. };
  2468. // File:src/math/Matrix4.js
  2469. /**
  2470. * @author mrdoob / http://mrdoob.com/
  2471. * @author supereggbert / http://www.paulbrunt.co.uk/
  2472. * @author philogb / http://blog.thejit.org/
  2473. * @author jordi_ros / http://plattsoft.com
  2474. * @author D1plo1d / http://github.com/D1plo1d
  2475. * @author alteredq / http://alteredqualia.com/
  2476. * @author mikael emtinger / http://gomo.se/
  2477. * @author timknip / http://www.floorplanner.com/
  2478. * @author bhouston / http://exocortex.com
  2479. * @author WestLangley / http://github.com/WestLangley
  2480. */
  2481. THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2482. this.elements = new Float32Array( 16 );
  2483. // TODO: if n11 is undefined, then just set to identity, otherwise copy all other values into matrix
  2484. // we should not support semi specification of Matrix4, it is just weird.
  2485. var te = this.elements;
  2486. te[ 0 ] = ( n11 !== undefined ) ? n11 : 1; te[ 4 ] = n12 || 0; te[ 8 ] = n13 || 0; te[ 12 ] = n14 || 0;
  2487. te[ 1 ] = n21 || 0; te[ 5 ] = ( n22 !== undefined ) ? n22 : 1; te[ 9 ] = n23 || 0; te[ 13 ] = n24 || 0;
  2488. te[ 2 ] = n31 || 0; te[ 6 ] = n32 || 0; te[ 10 ] = ( n33 !== undefined ) ? n33 : 1; te[ 14 ] = n34 || 0;
  2489. te[ 3 ] = n41 || 0; te[ 7 ] = n42 || 0; te[ 11 ] = n43 || 0; te[ 15 ] = ( n44 !== undefined ) ? n44 : 1;
  2490. };
  2491. THREE.Matrix4.prototype = {
  2492. constructor: THREE.Matrix4,
  2493. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2494. var te = this.elements;
  2495. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2496. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2497. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2498. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2499. return this;
  2500. },
  2501. identity: function () {
  2502. this.set(
  2503. 1, 0, 0, 0,
  2504. 0, 1, 0, 0,
  2505. 0, 0, 1, 0,
  2506. 0, 0, 0, 1
  2507. );
  2508. return this;
  2509. },
  2510. copy: function ( m ) {
  2511. this.elements.set( m.elements );
  2512. return this;
  2513. },
  2514. extractPosition: function ( m ) {
  2515. console.warn( 'THREEMatrix4: .extractPosition() has been renamed to .copyPosition().' );
  2516. return this.copyPosition( m );
  2517. },
  2518. copyPosition: function ( m ) {
  2519. var te = this.elements;
  2520. var me = m.elements;
  2521. te[ 12 ] = me[ 12 ];
  2522. te[ 13 ] = me[ 13 ];
  2523. te[ 14 ] = me[ 14 ];
  2524. return this;
  2525. },
  2526. extractRotation: function () {
  2527. var v1 = new THREE.Vector3();
  2528. return function ( m ) {
  2529. var te = this.elements;
  2530. var me = m.elements;
  2531. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2532. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2533. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2534. te[ 0 ] = me[ 0 ] * scaleX;
  2535. te[ 1 ] = me[ 1 ] * scaleX;
  2536. te[ 2 ] = me[ 2 ] * scaleX;
  2537. te[ 4 ] = me[ 4 ] * scaleY;
  2538. te[ 5 ] = me[ 5 ] * scaleY;
  2539. te[ 6 ] = me[ 6 ] * scaleY;
  2540. te[ 8 ] = me[ 8 ] * scaleZ;
  2541. te[ 9 ] = me[ 9 ] * scaleZ;
  2542. te[ 10 ] = me[ 10 ] * scaleZ;
  2543. return this;
  2544. };
  2545. }(),
  2546. makeRotationFromEuler: function ( euler ) {
  2547. if ( euler instanceof THREE.Euler === false ) {
  2548. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2549. }
  2550. var te = this.elements;
  2551. var x = euler.x, y = euler.y, z = euler.z;
  2552. var a = Math.cos( x ), b = Math.sin( x );
  2553. var c = Math.cos( y ), d = Math.sin( y );
  2554. var e = Math.cos( z ), f = Math.sin( z );
  2555. if ( euler.order === 'XYZ' ) {
  2556. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2557. te[ 0 ] = c * e;
  2558. te[ 4 ] = - c * f;
  2559. te[ 8 ] = d;
  2560. te[ 1 ] = af + be * d;
  2561. te[ 5 ] = ae - bf * d;
  2562. te[ 9 ] = - b * c;
  2563. te[ 2 ] = bf - ae * d;
  2564. te[ 6 ] = be + af * d;
  2565. te[ 10 ] = a * c;
  2566. } else if ( euler.order === 'YXZ' ) {
  2567. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2568. te[ 0 ] = ce + df * b;
  2569. te[ 4 ] = de * b - cf;
  2570. te[ 8 ] = a * d;
  2571. te[ 1 ] = a * f;
  2572. te[ 5 ] = a * e;
  2573. te[ 9 ] = - b;
  2574. te[ 2 ] = cf * b - de;
  2575. te[ 6 ] = df + ce * b;
  2576. te[ 10 ] = a * c;
  2577. } else if ( euler.order === 'ZXY' ) {
  2578. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2579. te[ 0 ] = ce - df * b;
  2580. te[ 4 ] = - a * f;
  2581. te[ 8 ] = de + cf * b;
  2582. te[ 1 ] = cf + de * b;
  2583. te[ 5 ] = a * e;
  2584. te[ 9 ] = df - ce * b;
  2585. te[ 2 ] = - a * d;
  2586. te[ 6 ] = b;
  2587. te[ 10 ] = a * c;
  2588. } else if ( euler.order === 'ZYX' ) {
  2589. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2590. te[ 0 ] = c * e;
  2591. te[ 4 ] = be * d - af;
  2592. te[ 8 ] = ae * d + bf;
  2593. te[ 1 ] = c * f;
  2594. te[ 5 ] = bf * d + ae;
  2595. te[ 9 ] = af * d - be;
  2596. te[ 2 ] = - d;
  2597. te[ 6 ] = b * c;
  2598. te[ 10 ] = a * c;
  2599. } else if ( euler.order === 'YZX' ) {
  2600. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2601. te[ 0 ] = c * e;
  2602. te[ 4 ] = bd - ac * f;
  2603. te[ 8 ] = bc * f + ad;
  2604. te[ 1 ] = f;
  2605. te[ 5 ] = a * e;
  2606. te[ 9 ] = - b * e;
  2607. te[ 2 ] = - d * e;
  2608. te[ 6 ] = ad * f + bc;
  2609. te[ 10 ] = ac - bd * f;
  2610. } else if ( euler.order === 'XZY' ) {
  2611. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2612. te[ 0 ] = c * e;
  2613. te[ 4 ] = - f;
  2614. te[ 8 ] = d * e;
  2615. te[ 1 ] = ac * f + bd;
  2616. te[ 5 ] = a * e;
  2617. te[ 9 ] = ad * f - bc;
  2618. te[ 2 ] = bc * f - ad;
  2619. te[ 6 ] = b * e;
  2620. te[ 10 ] = bd * f + ac;
  2621. }
  2622. // last column
  2623. te[ 3 ] = 0;
  2624. te[ 7 ] = 0;
  2625. te[ 11 ] = 0;
  2626. // bottom row
  2627. te[ 12 ] = 0;
  2628. te[ 13 ] = 0;
  2629. te[ 14 ] = 0;
  2630. te[ 15 ] = 1;
  2631. return this;
  2632. },
  2633. setRotationFromQuaternion: function ( q ) {
  2634. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  2635. return this.makeRotationFromQuaternion( q );
  2636. },
  2637. makeRotationFromQuaternion: function ( q ) {
  2638. var te = this.elements;
  2639. var x = q.x, y = q.y, z = q.z, w = q.w;
  2640. var x2 = x + x, y2 = y + y, z2 = z + z;
  2641. var xx = x * x2, xy = x * y2, xz = x * z2;
  2642. var yy = y * y2, yz = y * z2, zz = z * z2;
  2643. var wx = w * x2, wy = w * y2, wz = w * z2;
  2644. te[ 0 ] = 1 - ( yy + zz );
  2645. te[ 4 ] = xy - wz;
  2646. te[ 8 ] = xz + wy;
  2647. te[ 1 ] = xy + wz;
  2648. te[ 5 ] = 1 - ( xx + zz );
  2649. te[ 9 ] = yz - wx;
  2650. te[ 2 ] = xz - wy;
  2651. te[ 6 ] = yz + wx;
  2652. te[ 10 ] = 1 - ( xx + yy );
  2653. // last column
  2654. te[ 3 ] = 0;
  2655. te[ 7 ] = 0;
  2656. te[ 11 ] = 0;
  2657. // bottom row
  2658. te[ 12 ] = 0;
  2659. te[ 13 ] = 0;
  2660. te[ 14 ] = 0;
  2661. te[ 15 ] = 1;
  2662. return this;
  2663. },
  2664. lookAt: function () {
  2665. var x = new THREE.Vector3();
  2666. var y = new THREE.Vector3();
  2667. var z = new THREE.Vector3();
  2668. return function ( eye, target, up ) {
  2669. var te = this.elements;
  2670. z.subVectors( eye, target ).normalize();
  2671. if ( z.length() === 0 ) {
  2672. z.z = 1;
  2673. }
  2674. x.crossVectors( up, z ).normalize();
  2675. if ( x.length() === 0 ) {
  2676. z.x += 0.0001;
  2677. x.crossVectors( up, z ).normalize();
  2678. }
  2679. y.crossVectors( z, x );
  2680. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2681. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2682. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2683. return this;
  2684. };
  2685. }(),
  2686. multiply: function ( m, n ) {
  2687. if ( n !== undefined ) {
  2688. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2689. return this.multiplyMatrices( m, n );
  2690. }
  2691. return this.multiplyMatrices( this, m );
  2692. },
  2693. multiplyMatrices: function ( a, b ) {
  2694. var ae = a.elements;
  2695. var be = b.elements;
  2696. var te = this.elements;
  2697. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2698. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2699. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2700. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2701. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2702. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2703. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2704. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2705. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2706. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2707. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2708. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2709. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2710. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2711. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2712. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2713. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2714. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2715. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2716. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2717. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2718. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2719. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2720. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2721. return this;
  2722. },
  2723. multiplyToArray: function ( a, b, r ) {
  2724. var te = this.elements;
  2725. this.multiplyMatrices( a, b );
  2726. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  2727. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  2728. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  2729. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  2730. return this;
  2731. },
  2732. multiplyScalar: function ( s ) {
  2733. var te = this.elements;
  2734. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2735. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2736. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2737. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2738. return this;
  2739. },
  2740. multiplyVector3: function ( vector ) {
  2741. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  2742. return vector.applyProjection( this );
  2743. },
  2744. multiplyVector4: function ( vector ) {
  2745. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  2746. return vector.applyMatrix4( this );
  2747. },
  2748. multiplyVector3Array: function ( a ) {
  2749. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2750. return this.applyToVector3Array( a );
  2751. },
  2752. applyToVector3Array: function () {
  2753. var v1 = new THREE.Vector3();
  2754. return function ( array, offset, length ) {
  2755. if ( offset === undefined ) offset = 0;
  2756. if ( length === undefined ) length = array.length;
  2757. for ( var i = 0, j = offset, il; i < length; i += 3, j += 3 ) {
  2758. v1.x = array[ j ];
  2759. v1.y = array[ j + 1 ];
  2760. v1.z = array[ j + 2 ];
  2761. v1.applyMatrix4( this );
  2762. array[ j ] = v1.x;
  2763. array[ j + 1 ] = v1.y;
  2764. array[ j + 2 ] = v1.z;
  2765. }
  2766. return array;
  2767. };
  2768. }(),
  2769. rotateAxis: function ( v ) {
  2770. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  2771. v.transformDirection( this );
  2772. },
  2773. crossVector: function ( vector ) {
  2774. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  2775. return vector.applyMatrix4( this );
  2776. },
  2777. determinant: function () {
  2778. var te = this.elements;
  2779. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  2780. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  2781. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  2782. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  2783. //TODO: make this more efficient
  2784. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  2785. return (
  2786. n41 * (
  2787. + n14 * n23 * n32
  2788. - n13 * n24 * n32
  2789. - n14 * n22 * n33
  2790. + n12 * n24 * n33
  2791. + n13 * n22 * n34
  2792. - n12 * n23 * n34
  2793. ) +
  2794. n42 * (
  2795. + n11 * n23 * n34
  2796. - n11 * n24 * n33
  2797. + n14 * n21 * n33
  2798. - n13 * n21 * n34
  2799. + n13 * n24 * n31
  2800. - n14 * n23 * n31
  2801. ) +
  2802. n43 * (
  2803. + n11 * n24 * n32
  2804. - n11 * n22 * n34
  2805. - n14 * n21 * n32
  2806. + n12 * n21 * n34
  2807. + n14 * n22 * n31
  2808. - n12 * n24 * n31
  2809. ) +
  2810. n44 * (
  2811. - n13 * n22 * n31
  2812. - n11 * n23 * n32
  2813. + n11 * n22 * n33
  2814. + n13 * n21 * n32
  2815. - n12 * n21 * n33
  2816. + n12 * n23 * n31
  2817. )
  2818. );
  2819. },
  2820. transpose: function () {
  2821. var te = this.elements;
  2822. var tmp;
  2823. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  2824. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  2825. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  2826. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  2827. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  2828. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  2829. return this;
  2830. },
  2831. flattenToArrayOffset: function ( array, offset ) {
  2832. var te = this.elements;
  2833. array[ offset ] = te[ 0 ];
  2834. array[ offset + 1 ] = te[ 1 ];
  2835. array[ offset + 2 ] = te[ 2 ];
  2836. array[ offset + 3 ] = te[ 3 ];
  2837. array[ offset + 4 ] = te[ 4 ];
  2838. array[ offset + 5 ] = te[ 5 ];
  2839. array[ offset + 6 ] = te[ 6 ];
  2840. array[ offset + 7 ] = te[ 7 ];
  2841. array[ offset + 8 ] = te[ 8 ];
  2842. array[ offset + 9 ] = te[ 9 ];
  2843. array[ offset + 10 ] = te[ 10 ];
  2844. array[ offset + 11 ] = te[ 11 ];
  2845. array[ offset + 12 ] = te[ 12 ];
  2846. array[ offset + 13 ] = te[ 13 ];
  2847. array[ offset + 14 ] = te[ 14 ];
  2848. array[ offset + 15 ] = te[ 15 ];
  2849. return array;
  2850. },
  2851. getPosition: function () {
  2852. var v1 = new THREE.Vector3();
  2853. return function () {
  2854. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  2855. var te = this.elements;
  2856. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  2857. };
  2858. }(),
  2859. setPosition: function ( v ) {
  2860. var te = this.elements;
  2861. te[ 12 ] = v.x;
  2862. te[ 13 ] = v.y;
  2863. te[ 14 ] = v.z;
  2864. return this;
  2865. },
  2866. getInverse: function ( m, throwOnInvertible ) {
  2867. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  2868. var te = this.elements;
  2869. var me = m.elements;
  2870. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  2871. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  2872. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  2873. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  2874. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  2875. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  2876. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  2877. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  2878. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  2879. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  2880. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  2881. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  2882. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  2883. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  2884. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  2885. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  2886. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  2887. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  2888. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  2889. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  2890. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  2891. if ( det == 0 ) {
  2892. var msg = "Matrix4.getInverse(): can't invert matrix, determinant is 0";
  2893. if ( throwOnInvertible || false ) {
  2894. throw new Error( msg );
  2895. } else {
  2896. console.warn( msg );
  2897. }
  2898. this.identity();
  2899. return this;
  2900. }
  2901. this.multiplyScalar( 1 / det );
  2902. return this;
  2903. },
  2904. translate: function ( v ) {
  2905. console.warn( 'THREE.Matrix4: .translate() has been removed.' );
  2906. },
  2907. rotateX: function ( angle ) {
  2908. console.warn( 'THREE.Matrix4: .rotateX() has been removed.' );
  2909. },
  2910. rotateY: function ( angle ) {
  2911. console.warn( 'THREE.Matrix4: .rotateY() has been removed.' );
  2912. },
  2913. rotateZ: function ( angle ) {
  2914. console.warn( 'THREE.Matrix4: .rotateZ() has been removed.' );
  2915. },
  2916. rotateByAxis: function ( axis, angle ) {
  2917. console.warn( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  2918. },
  2919. scale: function ( v ) {
  2920. var te = this.elements;
  2921. var x = v.x, y = v.y, z = v.z;
  2922. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  2923. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  2924. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  2925. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  2926. return this;
  2927. },
  2928. getMaxScaleOnAxis: function () {
  2929. var te = this.elements;
  2930. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  2931. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  2932. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  2933. return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
  2934. },
  2935. makeTranslation: function ( x, y, z ) {
  2936. this.set(
  2937. 1, 0, 0, x,
  2938. 0, 1, 0, y,
  2939. 0, 0, 1, z,
  2940. 0, 0, 0, 1
  2941. );
  2942. return this;
  2943. },
  2944. makeRotationX: function ( theta ) {
  2945. var c = Math.cos( theta ), s = Math.sin( theta );
  2946. this.set(
  2947. 1, 0, 0, 0,
  2948. 0, c, - s, 0,
  2949. 0, s, c, 0,
  2950. 0, 0, 0, 1
  2951. );
  2952. return this;
  2953. },
  2954. makeRotationY: function ( theta ) {
  2955. var c = Math.cos( theta ), s = Math.sin( theta );
  2956. this.set(
  2957. c, 0, s, 0,
  2958. 0, 1, 0, 0,
  2959. - s, 0, c, 0,
  2960. 0, 0, 0, 1
  2961. );
  2962. return this;
  2963. },
  2964. makeRotationZ: function ( theta ) {
  2965. var c = Math.cos( theta ), s = Math.sin( theta );
  2966. this.set(
  2967. c, - s, 0, 0,
  2968. s, c, 0, 0,
  2969. 0, 0, 1, 0,
  2970. 0, 0, 0, 1
  2971. );
  2972. return this;
  2973. },
  2974. makeRotationAxis: function ( axis, angle ) {
  2975. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  2976. var c = Math.cos( angle );
  2977. var s = Math.sin( angle );
  2978. var t = 1 - c;
  2979. var x = axis.x, y = axis.y, z = axis.z;
  2980. var tx = t * x, ty = t * y;
  2981. this.set(
  2982. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  2983. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  2984. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  2985. 0, 0, 0, 1
  2986. );
  2987. return this;
  2988. },
  2989. makeScale: function ( x, y, z ) {
  2990. this.set(
  2991. x, 0, 0, 0,
  2992. 0, y, 0, 0,
  2993. 0, 0, z, 0,
  2994. 0, 0, 0, 1
  2995. );
  2996. return this;
  2997. },
  2998. compose: function ( position, quaternion, scale ) {
  2999. this.makeRotationFromQuaternion( quaternion );
  3000. this.scale( scale );
  3001. this.setPosition( position );
  3002. return this;
  3003. },
  3004. decompose: function () {
  3005. var vector = new THREE.Vector3();
  3006. var matrix = new THREE.Matrix4();
  3007. return function ( position, quaternion, scale ) {
  3008. var te = this.elements;
  3009. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3010. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3011. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3012. // if determine is negative, we need to invert one scale
  3013. var det = this.determinant();
  3014. if ( det < 0 ) {
  3015. sx = - sx;
  3016. }
  3017. position.x = te[ 12 ];
  3018. position.y = te[ 13 ];
  3019. position.z = te[ 14 ];
  3020. // scale the rotation part
  3021. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3022. var invSX = 1 / sx;
  3023. var invSY = 1 / sy;
  3024. var invSZ = 1 / sz;
  3025. matrix.elements[ 0 ] *= invSX;
  3026. matrix.elements[ 1 ] *= invSX;
  3027. matrix.elements[ 2 ] *= invSX;
  3028. matrix.elements[ 4 ] *= invSY;
  3029. matrix.elements[ 5 ] *= invSY;
  3030. matrix.elements[ 6 ] *= invSY;
  3031. matrix.elements[ 8 ] *= invSZ;
  3032. matrix.elements[ 9 ] *= invSZ;
  3033. matrix.elements[ 10 ] *= invSZ;
  3034. quaternion.setFromRotationMatrix( matrix );
  3035. scale.x = sx;
  3036. scale.y = sy;
  3037. scale.z = sz;
  3038. return this;
  3039. };
  3040. }(),
  3041. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3042. var te = this.elements;
  3043. var x = 2 * near / ( right - left );
  3044. var y = 2 * near / ( top - bottom );
  3045. var a = ( right + left ) / ( right - left );
  3046. var b = ( top + bottom ) / ( top - bottom );
  3047. var c = - ( far + near ) / ( far - near );
  3048. var d = - 2 * far * near / ( far - near );
  3049. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3050. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3051. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3052. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3053. return this;
  3054. },
  3055. makePerspective: function ( fov, aspect, near, far ) {
  3056. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3057. var ymin = - ymax;
  3058. var xmin = ymin * aspect;
  3059. var xmax = ymax * aspect;
  3060. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3061. },
  3062. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3063. var te = this.elements;
  3064. var w = right - left;
  3065. var h = top - bottom;
  3066. var p = far - near;
  3067. var x = ( right + left ) / w;
  3068. var y = ( top + bottom ) / h;
  3069. var z = ( far + near ) / p;
  3070. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3071. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3072. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3073. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3074. return this;
  3075. },
  3076. fromArray: function ( array ) {
  3077. this.elements.set( array );
  3078. return this;
  3079. },
  3080. toArray: function () {
  3081. var te = this.elements;
  3082. return [
  3083. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3084. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3085. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3086. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3087. ];
  3088. },
  3089. clone: function () {
  3090. var te = this.elements;
  3091. return new THREE.Matrix4(
  3092. te[ 0 ], te[ 4 ], te[ 8 ], te[ 12 ],
  3093. te[ 1 ], te[ 5 ], te[ 9 ], te[ 13 ],
  3094. te[ 2 ], te[ 6 ], te[ 10 ], te[ 14 ],
  3095. te[ 3 ], te[ 7 ], te[ 11 ], te[ 15 ]
  3096. );
  3097. }
  3098. };
  3099. // File:src/math/Ray.js
  3100. /**
  3101. * @author bhouston / http://exocortex.com
  3102. */
  3103. THREE.Ray = function ( origin, direction ) {
  3104. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3105. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3106. };
  3107. THREE.Ray.prototype = {
  3108. constructor: THREE.Ray,
  3109. set: function ( origin, direction ) {
  3110. this.origin.copy( origin );
  3111. this.direction.copy( direction );
  3112. return this;
  3113. },
  3114. copy: function ( ray ) {
  3115. this.origin.copy( ray.origin );
  3116. this.direction.copy( ray.direction );
  3117. return this;
  3118. },
  3119. at: function ( t, optionalTarget ) {
  3120. var result = optionalTarget || new THREE.Vector3();
  3121. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3122. },
  3123. recast: function () {
  3124. var v1 = new THREE.Vector3();
  3125. return function ( t ) {
  3126. this.origin.copy( this.at( t, v1 ) );
  3127. return this;
  3128. };
  3129. }(),
  3130. closestPointToPoint: function ( point, optionalTarget ) {
  3131. var result = optionalTarget || new THREE.Vector3();
  3132. result.subVectors( point, this.origin );
  3133. var directionDistance = result.dot( this.direction );
  3134. if ( directionDistance < 0 ) {
  3135. return result.copy( this.origin );
  3136. }
  3137. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3138. },
  3139. distanceToPoint: function () {
  3140. var v1 = new THREE.Vector3();
  3141. return function ( point ) {
  3142. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3143. // point behind the ray
  3144. if ( directionDistance < 0 ) {
  3145. return this.origin.distanceTo( point );
  3146. }
  3147. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3148. return v1.distanceTo( point );
  3149. };
  3150. }(),
  3151. distanceSqToSegment: function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3152. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3153. // It returns the min distance between the ray and the segment
  3154. // defined by v0 and v1
  3155. // It can also set two optional targets :
  3156. // - The closest point on the ray
  3157. // - The closest point on the segment
  3158. var segCenter = v0.clone().add( v1 ).multiplyScalar( 0.5 );
  3159. var segDir = v1.clone().sub( v0 ).normalize();
  3160. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3161. var diff = this.origin.clone().sub( segCenter );
  3162. var a01 = - this.direction.dot( segDir );
  3163. var b0 = diff.dot( this.direction );
  3164. var b1 = - diff.dot( segDir );
  3165. var c = diff.lengthSq();
  3166. var det = Math.abs( 1 - a01 * a01 );
  3167. var s0, s1, sqrDist, extDet;
  3168. if ( det >= 0 ) {
  3169. // The ray and segment are not parallel.
  3170. s0 = a01 * b1 - b0;
  3171. s1 = a01 * b0 - b1;
  3172. extDet = segExtent * det;
  3173. if ( s0 >= 0 ) {
  3174. if ( s1 >= - extDet ) {
  3175. if ( s1 <= extDet ) {
  3176. // region 0
  3177. // Minimum at interior points of ray and segment.
  3178. var invDet = 1 / det;
  3179. s0 *= invDet;
  3180. s1 *= invDet;
  3181. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3182. } else {
  3183. // region 1
  3184. s1 = segExtent;
  3185. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3186. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3187. }
  3188. } else {
  3189. // region 5
  3190. s1 = - segExtent;
  3191. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3192. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3193. }
  3194. } else {
  3195. if ( s1 <= - extDet ) {
  3196. // region 4
  3197. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3198. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3199. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3200. } else if ( s1 <= extDet ) {
  3201. // region 3
  3202. s0 = 0;
  3203. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3204. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3205. } else {
  3206. // region 2
  3207. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3208. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3209. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3210. }
  3211. }
  3212. } else {
  3213. // Ray and segment are parallel.
  3214. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3215. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3216. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3217. }
  3218. if ( optionalPointOnRay ) {
  3219. optionalPointOnRay.copy( this.direction.clone().multiplyScalar( s0 ).add( this.origin ) );
  3220. }
  3221. if ( optionalPointOnSegment ) {
  3222. optionalPointOnSegment.copy( segDir.clone().multiplyScalar( s1 ).add( segCenter ) );
  3223. }
  3224. return sqrDist;
  3225. },
  3226. isIntersectionSphere: function ( sphere ) {
  3227. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3228. },
  3229. intersectSphere: function () {
  3230. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3231. var v1 = new THREE.Vector3();
  3232. return function ( sphere, optionalTarget ) {
  3233. v1.subVectors( sphere.center, this.origin );
  3234. var tca = v1.dot( this.direction );
  3235. var d2 = v1.dot( v1 ) - tca * tca;
  3236. var radius2 = sphere.radius * sphere.radius;
  3237. if ( d2 > radius2 ) return null;
  3238. var thc = Math.sqrt( radius2 - d2 );
  3239. // t0 = first intersect point - entrance on front of sphere
  3240. var t0 = tca - thc;
  3241. // t1 = second intersect point - exit point on back of sphere
  3242. var t1 = tca + thc;
  3243. // test to see if both t0 and t1 are behind the ray - if so, return null
  3244. if ( t0 < 0 && t1 < 0 ) return null;
  3245. // test to see if t0 is behind the ray:
  3246. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3247. // in order to always return an intersect point that is in front of the ray.
  3248. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3249. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3250. return this.at( t0, optionalTarget );
  3251. }
  3252. }(),
  3253. isIntersectionPlane: function ( plane ) {
  3254. // check if the ray lies on the plane first
  3255. var distToPoint = plane.distanceToPoint( this.origin );
  3256. if ( distToPoint === 0 ) {
  3257. return true;
  3258. }
  3259. var denominator = plane.normal.dot( this.direction );
  3260. if ( denominator * distToPoint < 0 ) {
  3261. return true;
  3262. }
  3263. // ray origin is behind the plane (and is pointing behind it)
  3264. return false;
  3265. },
  3266. distanceToPlane: function ( plane ) {
  3267. var denominator = plane.normal.dot( this.direction );
  3268. if ( denominator == 0 ) {
  3269. // line is coplanar, return origin
  3270. if ( plane.distanceToPoint( this.origin ) == 0 ) {
  3271. return 0;
  3272. }
  3273. // Null is preferable to undefined since undefined means.... it is undefined
  3274. return null;
  3275. }
  3276. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3277. // Return if the ray never intersects the plane
  3278. return t >= 0 ? t : null;
  3279. },
  3280. intersectPlane: function ( plane, optionalTarget ) {
  3281. var t = this.distanceToPlane( plane );
  3282. if ( t === null ) {
  3283. return null;
  3284. }
  3285. return this.at( t, optionalTarget );
  3286. },
  3287. isIntersectionBox: function () {
  3288. var v = new THREE.Vector3();
  3289. return function ( box ) {
  3290. return this.intersectBox( box, v ) !== null;
  3291. };
  3292. }(),
  3293. intersectBox: function ( box , optionalTarget ) {
  3294. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3295. var tmin,tmax,tymin,tymax,tzmin,tzmax;
  3296. var invdirx = 1 / this.direction.x,
  3297. invdiry = 1 / this.direction.y,
  3298. invdirz = 1 / this.direction.z;
  3299. var origin = this.origin;
  3300. if ( invdirx >= 0 ) {
  3301. tmin = ( box.min.x - origin.x ) * invdirx;
  3302. tmax = ( box.max.x - origin.x ) * invdirx;
  3303. } else {
  3304. tmin = ( box.max.x - origin.x ) * invdirx;
  3305. tmax = ( box.min.x - origin.x ) * invdirx;
  3306. }
  3307. if ( invdiry >= 0 ) {
  3308. tymin = ( box.min.y - origin.y ) * invdiry;
  3309. tymax = ( box.max.y - origin.y ) * invdiry;
  3310. } else {
  3311. tymin = ( box.max.y - origin.y ) * invdiry;
  3312. tymax = ( box.min.y - origin.y ) * invdiry;
  3313. }
  3314. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3315. // These lines also handle the case where tmin or tmax is NaN
  3316. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3317. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3318. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3319. if ( invdirz >= 0 ) {
  3320. tzmin = ( box.min.z - origin.z ) * invdirz;
  3321. tzmax = ( box.max.z - origin.z ) * invdirz;
  3322. } else {
  3323. tzmin = ( box.max.z - origin.z ) * invdirz;
  3324. tzmax = ( box.min.z - origin.z ) * invdirz;
  3325. }
  3326. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3327. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3328. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3329. //return point closest to the ray (positive side)
  3330. if ( tmax < 0 ) return null;
  3331. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3332. },
  3333. intersectTriangle: function () {
  3334. // Compute the offset origin, edges, and normal.
  3335. var diff = new THREE.Vector3();
  3336. var edge1 = new THREE.Vector3();
  3337. var edge2 = new THREE.Vector3();
  3338. var normal = new THREE.Vector3();
  3339. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3340. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3341. edge1.subVectors( b, a );
  3342. edge2.subVectors( c, a );
  3343. normal.crossVectors( edge1, edge2 );
  3344. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3345. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3346. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3347. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3348. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3349. var DdN = this.direction.dot( normal );
  3350. var sign;
  3351. if ( DdN > 0 ) {
  3352. if ( backfaceCulling ) return null;
  3353. sign = 1;
  3354. } else if ( DdN < 0 ) {
  3355. sign = - 1;
  3356. DdN = - DdN;
  3357. } else {
  3358. return null;
  3359. }
  3360. diff.subVectors( this.origin, a );
  3361. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3362. // b1 < 0, no intersection
  3363. if ( DdQxE2 < 0 ) {
  3364. return null;
  3365. }
  3366. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3367. // b2 < 0, no intersection
  3368. if ( DdE1xQ < 0 ) {
  3369. return null;
  3370. }
  3371. // b1+b2 > 1, no intersection
  3372. if ( DdQxE2 + DdE1xQ > DdN ) {
  3373. return null;
  3374. }
  3375. // Line intersects triangle, check if ray does.
  3376. var QdN = - sign * diff.dot( normal );
  3377. // t < 0, no intersection
  3378. if ( QdN < 0 ) {
  3379. return null;
  3380. }
  3381. // Ray intersects triangle.
  3382. return this.at( QdN / DdN, optionalTarget );
  3383. };
  3384. }(),
  3385. applyMatrix4: function ( matrix4 ) {
  3386. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3387. this.origin.applyMatrix4( matrix4 );
  3388. this.direction.sub( this.origin );
  3389. this.direction.normalize();
  3390. return this;
  3391. },
  3392. equals: function ( ray ) {
  3393. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3394. },
  3395. clone: function () {
  3396. return new THREE.Ray().copy( this );
  3397. }
  3398. };
  3399. // File:src/math/Sphere.js
  3400. /**
  3401. * @author bhouston / http://exocortex.com
  3402. * @author mrdoob / http://mrdoob.com/
  3403. */
  3404. THREE.Sphere = function ( center, radius ) {
  3405. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3406. this.radius = ( radius !== undefined ) ? radius : 0;
  3407. };
  3408. THREE.Sphere.prototype = {
  3409. constructor: THREE.Sphere,
  3410. set: function ( center, radius ) {
  3411. this.center.copy( center );
  3412. this.radius = radius;
  3413. return this;
  3414. },
  3415. setFromPoints: function () {
  3416. var box = new THREE.Box3();
  3417. return function ( points, optionalCenter ) {
  3418. var center = this.center;
  3419. if ( optionalCenter !== undefined ) {
  3420. center.copy( optionalCenter );
  3421. } else {
  3422. box.setFromPoints( points ).center( center );
  3423. }
  3424. var maxRadiusSq = 0;
  3425. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3426. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3427. }
  3428. this.radius = Math.sqrt( maxRadiusSq );
  3429. return this;
  3430. };
  3431. }(),
  3432. copy: function ( sphere ) {
  3433. this.center.copy( sphere.center );
  3434. this.radius = sphere.radius;
  3435. return this;
  3436. },
  3437. empty: function () {
  3438. return ( this.radius <= 0 );
  3439. },
  3440. containsPoint: function ( point ) {
  3441. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3442. },
  3443. distanceToPoint: function ( point ) {
  3444. return ( point.distanceTo( this.center ) - this.radius );
  3445. },
  3446. intersectsSphere: function ( sphere ) {
  3447. var radiusSum = this.radius + sphere.radius;
  3448. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3449. },
  3450. clampPoint: function ( point, optionalTarget ) {
  3451. var deltaLengthSq = this.center.distanceToSquared( point );
  3452. var result = optionalTarget || new THREE.Vector3();
  3453. result.copy( point );
  3454. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3455. result.sub( this.center ).normalize();
  3456. result.multiplyScalar( this.radius ).add( this.center );
  3457. }
  3458. return result;
  3459. },
  3460. getBoundingBox: function ( optionalTarget ) {
  3461. var box = optionalTarget || new THREE.Box3();
  3462. box.set( this.center, this.center );
  3463. box.expandByScalar( this.radius );
  3464. return box;
  3465. },
  3466. applyMatrix4: function ( matrix ) {
  3467. this.center.applyMatrix4( matrix );
  3468. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3469. return this;
  3470. },
  3471. translate: function ( offset ) {
  3472. this.center.add( offset );
  3473. return this;
  3474. },
  3475. equals: function ( sphere ) {
  3476. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3477. },
  3478. clone: function () {
  3479. return new THREE.Sphere().copy( this );
  3480. }
  3481. };
  3482. // File:src/math/Frustum.js
  3483. /**
  3484. * @author mrdoob / http://mrdoob.com/
  3485. * @author alteredq / http://alteredqualia.com/
  3486. * @author bhouston / http://exocortex.com
  3487. */
  3488. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3489. this.planes = [
  3490. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3491. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3492. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3493. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3494. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3495. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3496. ];
  3497. };
  3498. THREE.Frustum.prototype = {
  3499. constructor: THREE.Frustum,
  3500. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3501. var planes = this.planes;
  3502. planes[ 0 ].copy( p0 );
  3503. planes[ 1 ].copy( p1 );
  3504. planes[ 2 ].copy( p2 );
  3505. planes[ 3 ].copy( p3 );
  3506. planes[ 4 ].copy( p4 );
  3507. planes[ 5 ].copy( p5 );
  3508. return this;
  3509. },
  3510. copy: function ( frustum ) {
  3511. var planes = this.planes;
  3512. for ( var i = 0; i < 6; i ++ ) {
  3513. planes[ i ].copy( frustum.planes[ i ] );
  3514. }
  3515. return this;
  3516. },
  3517. setFromMatrix: function ( m ) {
  3518. var planes = this.planes;
  3519. var me = m.elements;
  3520. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3521. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3522. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3523. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3524. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3525. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3526. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3527. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3528. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3529. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3530. return this;
  3531. },
  3532. intersectsObject: function () {
  3533. var sphere = new THREE.Sphere();
  3534. return function ( object ) {
  3535. var geometry = object.geometry;
  3536. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3537. sphere.copy( geometry.boundingSphere );
  3538. sphere.applyMatrix4( object.matrixWorld );
  3539. return this.intersectsSphere( sphere );
  3540. };
  3541. }(),
  3542. intersectsSphere: function ( sphere ) {
  3543. var planes = this.planes;
  3544. var center = sphere.center;
  3545. var negRadius = - sphere.radius;
  3546. for ( var i = 0; i < 6; i ++ ) {
  3547. var distance = planes[ i ].distanceToPoint( center );
  3548. if ( distance < negRadius ) {
  3549. return false;
  3550. }
  3551. }
  3552. return true;
  3553. },
  3554. intersectsBox: function () {
  3555. var p1 = new THREE.Vector3(),
  3556. p2 = new THREE.Vector3();
  3557. return function ( box ) {
  3558. var planes = this.planes;
  3559. for ( var i = 0; i < 6 ; i ++ ) {
  3560. var plane = planes[ i ];
  3561. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3562. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3563. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3564. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3565. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3566. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3567. var d1 = plane.distanceToPoint( p1 );
  3568. var d2 = plane.distanceToPoint( p2 );
  3569. // if both outside plane, no intersection
  3570. if ( d1 < 0 && d2 < 0 ) {
  3571. return false;
  3572. }
  3573. }
  3574. return true;
  3575. };
  3576. }(),
  3577. containsPoint: function ( point ) {
  3578. var planes = this.planes;
  3579. for ( var i = 0; i < 6; i ++ ) {
  3580. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3581. return false;
  3582. }
  3583. }
  3584. return true;
  3585. },
  3586. clone: function () {
  3587. return new THREE.Frustum().copy( this );
  3588. }
  3589. };
  3590. // File:src/math/Plane.js
  3591. /**
  3592. * @author bhouston / http://exocortex.com
  3593. */
  3594. THREE.Plane = function ( normal, constant ) {
  3595. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3596. this.constant = ( constant !== undefined ) ? constant : 0;
  3597. };
  3598. THREE.Plane.prototype = {
  3599. constructor: THREE.Plane,
  3600. set: function ( normal, constant ) {
  3601. this.normal.copy( normal );
  3602. this.constant = constant;
  3603. return this;
  3604. },
  3605. setComponents: function ( x, y, z, w ) {
  3606. this.normal.set( x, y, z );
  3607. this.constant = w;
  3608. return this;
  3609. },
  3610. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3611. this.normal.copy( normal );
  3612. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3613. return this;
  3614. },
  3615. setFromCoplanarPoints: function () {
  3616. var v1 = new THREE.Vector3();
  3617. var v2 = new THREE.Vector3();
  3618. return function ( a, b, c ) {
  3619. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3620. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3621. this.setFromNormalAndCoplanarPoint( normal, a );
  3622. return this;
  3623. };
  3624. }(),
  3625. copy: function ( plane ) {
  3626. this.normal.copy( plane.normal );
  3627. this.constant = plane.constant;
  3628. return this;
  3629. },
  3630. normalize: function () {
  3631. // Note: will lead to a divide by zero if the plane is invalid.
  3632. var inverseNormalLength = 1.0 / this.normal.length();
  3633. this.normal.multiplyScalar( inverseNormalLength );
  3634. this.constant *= inverseNormalLength;
  3635. return this;
  3636. },
  3637. negate: function () {
  3638. this.constant *= - 1;
  3639. this.normal.negate();
  3640. return this;
  3641. },
  3642. distanceToPoint: function ( point ) {
  3643. return this.normal.dot( point ) + this.constant;
  3644. },
  3645. distanceToSphere: function ( sphere ) {
  3646. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3647. },
  3648. projectPoint: function ( point, optionalTarget ) {
  3649. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3650. },
  3651. orthoPoint: function ( point, optionalTarget ) {
  3652. var perpendicularMagnitude = this.distanceToPoint( point );
  3653. var result = optionalTarget || new THREE.Vector3();
  3654. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3655. },
  3656. isIntersectionLine: function ( line ) {
  3657. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3658. var startSign = this.distanceToPoint( line.start );
  3659. var endSign = this.distanceToPoint( line.end );
  3660. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3661. },
  3662. intersectLine: function () {
  3663. var v1 = new THREE.Vector3();
  3664. return function ( line, optionalTarget ) {
  3665. var result = optionalTarget || new THREE.Vector3();
  3666. var direction = line.delta( v1 );
  3667. var denominator = this.normal.dot( direction );
  3668. if ( denominator == 0 ) {
  3669. // line is coplanar, return origin
  3670. if ( this.distanceToPoint( line.start ) == 0 ) {
  3671. return result.copy( line.start );
  3672. }
  3673. // Unsure if this is the correct method to handle this case.
  3674. return undefined;
  3675. }
  3676. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3677. if ( t < 0 || t > 1 ) {
  3678. return undefined;
  3679. }
  3680. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  3681. };
  3682. }(),
  3683. coplanarPoint: function ( optionalTarget ) {
  3684. var result = optionalTarget || new THREE.Vector3();
  3685. return result.copy( this.normal ).multiplyScalar( - this.constant );
  3686. },
  3687. applyMatrix4: function () {
  3688. var v1 = new THREE.Vector3();
  3689. var v2 = new THREE.Vector3();
  3690. var m1 = new THREE.Matrix3();
  3691. return function ( matrix, optionalNormalMatrix ) {
  3692. // compute new normal based on theory here:
  3693. // http://www.songho.ca/opengl/gl_normaltransform.html
  3694. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  3695. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  3696. var newCoplanarPoint = this.coplanarPoint( v2 );
  3697. newCoplanarPoint.applyMatrix4( matrix );
  3698. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  3699. return this;
  3700. };
  3701. }(),
  3702. translate: function ( offset ) {
  3703. this.constant = this.constant - offset.dot( this.normal );
  3704. return this;
  3705. },
  3706. equals: function ( plane ) {
  3707. return plane.normal.equals( this.normal ) && ( plane.constant == this.constant );
  3708. },
  3709. clone: function () {
  3710. return new THREE.Plane().copy( this );
  3711. }
  3712. };
  3713. // File:src/math/Math.js
  3714. /**
  3715. * @author alteredq / http://alteredqualia.com/
  3716. * @author mrdoob / http://mrdoob.com/
  3717. */
  3718. THREE.Math = {
  3719. generateUUID: function () {
  3720. // http://www.broofa.com/Tools/Math.uuid.htm
  3721. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  3722. var uuid = new Array( 36 );
  3723. var rnd = 0, r;
  3724. return function () {
  3725. for ( var i = 0; i < 36; i ++ ) {
  3726. if ( i == 8 || i == 13 || i == 18 || i == 23 ) {
  3727. uuid[ i ] = '-';
  3728. } else if ( i == 14 ) {
  3729. uuid[ i ] = '4';
  3730. } else {
  3731. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  3732. r = rnd & 0xf;
  3733. rnd = rnd >> 4;
  3734. uuid[ i ] = chars[ ( i == 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  3735. }
  3736. }
  3737. return uuid.join( '' );
  3738. };
  3739. }(),
  3740. // Clamp value to range <a, b>
  3741. clamp: function ( x, a, b ) {
  3742. return ( x < a ) ? a : ( ( x > b ) ? b : x );
  3743. },
  3744. // Clamp value to range <a, inf)
  3745. clampBottom: function ( x, a ) {
  3746. return x < a ? a : x;
  3747. },
  3748. // Linear mapping from range <a1, a2> to range <b1, b2>
  3749. mapLinear: function ( x, a1, a2, b1, b2 ) {
  3750. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  3751. },
  3752. // http://en.wikipedia.org/wiki/Smoothstep
  3753. smoothstep: function ( x, min, max ) {
  3754. if ( x <= min ) return 0;
  3755. if ( x >= max ) return 1;
  3756. x = ( x - min ) / ( max - min );
  3757. return x * x * ( 3 - 2 * x );
  3758. },
  3759. smootherstep: function ( x, min, max ) {
  3760. if ( x <= min ) return 0;
  3761. if ( x >= max ) return 1;
  3762. x = ( x - min ) / ( max - min );
  3763. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  3764. },
  3765. // Random float from <0, 1> with 16 bits of randomness
  3766. // (standard Math.random() creates repetitive patterns when applied over larger space)
  3767. random16: function () {
  3768. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  3769. },
  3770. // Random integer from <low, high> interval
  3771. randInt: function ( low, high ) {
  3772. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  3773. },
  3774. // Random float from <low, high> interval
  3775. randFloat: function ( low, high ) {
  3776. return low + Math.random() * ( high - low );
  3777. },
  3778. // Random float from <-range/2, range/2> interval
  3779. randFloatSpread: function ( range ) {
  3780. return range * ( 0.5 - Math.random() );
  3781. },
  3782. sign: function ( x ) {
  3783. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : 0;
  3784. },
  3785. degToRad: function () {
  3786. var degreeToRadiansFactor = Math.PI / 180;
  3787. return function ( degrees ) {
  3788. return degrees * degreeToRadiansFactor;
  3789. };
  3790. }(),
  3791. radToDeg: function () {
  3792. var radianToDegreesFactor = 180 / Math.PI;
  3793. return function ( radians ) {
  3794. return radians * radianToDegreesFactor;
  3795. };
  3796. }(),
  3797. isPowerOfTwo: function ( value ) {
  3798. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  3799. }
  3800. };
  3801. // File:src/math/Spline.js
  3802. /**
  3803. * Spline from Tween.js, slightly optimized (and trashed)
  3804. * http://sole.github.com/tween.js/examples/05_spline.html
  3805. *
  3806. * @author mrdoob / http://mrdoob.com/
  3807. * @author alteredq / http://alteredqualia.com/
  3808. */
  3809. THREE.Spline = function ( points ) {
  3810. this.points = points;
  3811. var c = [], v3 = { x: 0, y: 0, z: 0 },
  3812. point, intPoint, weight, w2, w3,
  3813. pa, pb, pc, pd;
  3814. this.initFromArray = function ( a ) {
  3815. this.points = [];
  3816. for ( var i = 0; i < a.length; i ++ ) {
  3817. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  3818. }
  3819. };
  3820. this.getPoint = function ( k ) {
  3821. point = ( this.points.length - 1 ) * k;
  3822. intPoint = Math.floor( point );
  3823. weight = point - intPoint;
  3824. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  3825. c[ 1 ] = intPoint;
  3826. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  3827. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  3828. pa = this.points[ c[ 0 ] ];
  3829. pb = this.points[ c[ 1 ] ];
  3830. pc = this.points[ c[ 2 ] ];
  3831. pd = this.points[ c[ 3 ] ];
  3832. w2 = weight * weight;
  3833. w3 = weight * w2;
  3834. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  3835. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  3836. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  3837. return v3;
  3838. };
  3839. this.getControlPointsArray = function () {
  3840. var i, p, l = this.points.length,
  3841. coords = [];
  3842. for ( i = 0; i < l; i ++ ) {
  3843. p = this.points[ i ];
  3844. coords[ i ] = [ p.x, p.y, p.z ];
  3845. }
  3846. return coords;
  3847. };
  3848. // approximate length by summing linear segments
  3849. this.getLength = function ( nSubDivisions ) {
  3850. var i, index, nSamples, position,
  3851. point = 0, intPoint = 0, oldIntPoint = 0,
  3852. oldPosition = new THREE.Vector3(),
  3853. tmpVec = new THREE.Vector3(),
  3854. chunkLengths = [],
  3855. totalLength = 0;
  3856. // first point has 0 length
  3857. chunkLengths[ 0 ] = 0;
  3858. if ( ! nSubDivisions ) nSubDivisions = 100;
  3859. nSamples = this.points.length * nSubDivisions;
  3860. oldPosition.copy( this.points[ 0 ] );
  3861. for ( i = 1; i < nSamples; i ++ ) {
  3862. index = i / nSamples;
  3863. position = this.getPoint( index );
  3864. tmpVec.copy( position );
  3865. totalLength += tmpVec.distanceTo( oldPosition );
  3866. oldPosition.copy( position );
  3867. point = ( this.points.length - 1 ) * index;
  3868. intPoint = Math.floor( point );
  3869. if ( intPoint != oldIntPoint ) {
  3870. chunkLengths[ intPoint ] = totalLength;
  3871. oldIntPoint = intPoint;
  3872. }
  3873. }
  3874. // last point ends with total length
  3875. chunkLengths[ chunkLengths.length ] = totalLength;
  3876. return { chunks: chunkLengths, total: totalLength };
  3877. };
  3878. this.reparametrizeByArcLength = function ( samplingCoef ) {
  3879. var i, j,
  3880. index, indexCurrent, indexNext,
  3881. linearDistance, realDistance,
  3882. sampling, position,
  3883. newpoints = [],
  3884. tmpVec = new THREE.Vector3(),
  3885. sl = this.getLength();
  3886. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  3887. for ( i = 1; i < this.points.length; i ++ ) {
  3888. //tmpVec.copy( this.points[ i - 1 ] );
  3889. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  3890. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  3891. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  3892. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  3893. indexNext = i / ( this.points.length - 1 );
  3894. for ( j = 1; j < sampling - 1; j ++ ) {
  3895. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  3896. position = this.getPoint( index );
  3897. newpoints.push( tmpVec.copy( position ).clone() );
  3898. }
  3899. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  3900. }
  3901. this.points = newpoints;
  3902. };
  3903. // Catmull-Rom
  3904. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  3905. var v0 = ( p2 - p0 ) * 0.5,
  3906. v1 = ( p3 - p1 ) * 0.5;
  3907. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  3908. };
  3909. };
  3910. // File:src/math/Triangle.js
  3911. /**
  3912. * @author bhouston / http://exocortex.com
  3913. * @author mrdoob / http://mrdoob.com/
  3914. */
  3915. THREE.Triangle = function ( a, b, c ) {
  3916. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  3917. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  3918. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  3919. };
  3920. THREE.Triangle.normal = function () {
  3921. var v0 = new THREE.Vector3();
  3922. return function ( a, b, c, optionalTarget ) {
  3923. var result = optionalTarget || new THREE.Vector3();
  3924. result.subVectors( c, b );
  3925. v0.subVectors( a, b );
  3926. result.cross( v0 );
  3927. var resultLengthSq = result.lengthSq();
  3928. if ( resultLengthSq > 0 ) {
  3929. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  3930. }
  3931. return result.set( 0, 0, 0 );
  3932. };
  3933. }();
  3934. // static/instance method to calculate barycoordinates
  3935. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  3936. THREE.Triangle.barycoordFromPoint = function () {
  3937. var v0 = new THREE.Vector3();
  3938. var v1 = new THREE.Vector3();
  3939. var v2 = new THREE.Vector3();
  3940. return function ( point, a, b, c, optionalTarget ) {
  3941. v0.subVectors( c, a );
  3942. v1.subVectors( b, a );
  3943. v2.subVectors( point, a );
  3944. var dot00 = v0.dot( v0 );
  3945. var dot01 = v0.dot( v1 );
  3946. var dot02 = v0.dot( v2 );
  3947. var dot11 = v1.dot( v1 );
  3948. var dot12 = v1.dot( v2 );
  3949. var denom = ( dot00 * dot11 - dot01 * dot01 );
  3950. var result = optionalTarget || new THREE.Vector3();
  3951. // colinear or singular triangle
  3952. if ( denom == 0 ) {
  3953. // arbitrary location outside of triangle?
  3954. // not sure if this is the best idea, maybe should be returning undefined
  3955. return result.set( - 2, - 1, - 1 );
  3956. }
  3957. var invDenom = 1 / denom;
  3958. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  3959. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  3960. // barycoordinates must always sum to 1
  3961. return result.set( 1 - u - v, v, u );
  3962. };
  3963. }();
  3964. THREE.Triangle.containsPoint = function () {
  3965. var v1 = new THREE.Vector3();
  3966. return function ( point, a, b, c ) {
  3967. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  3968. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  3969. };
  3970. }();
  3971. THREE.Triangle.prototype = {
  3972. constructor: THREE.Triangle,
  3973. set: function ( a, b, c ) {
  3974. this.a.copy( a );
  3975. this.b.copy( b );
  3976. this.c.copy( c );
  3977. return this;
  3978. },
  3979. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  3980. this.a.copy( points[ i0 ] );
  3981. this.b.copy( points[ i1 ] );
  3982. this.c.copy( points[ i2 ] );
  3983. return this;
  3984. },
  3985. copy: function ( triangle ) {
  3986. this.a.copy( triangle.a );
  3987. this.b.copy( triangle.b );
  3988. this.c.copy( triangle.c );
  3989. return this;
  3990. },
  3991. area: function () {
  3992. var v0 = new THREE.Vector3();
  3993. var v1 = new THREE.Vector3();
  3994. return function () {
  3995. v0.subVectors( this.c, this.b );
  3996. v1.subVectors( this.a, this.b );
  3997. return v0.cross( v1 ).length() * 0.5;
  3998. };
  3999. }(),
  4000. midpoint: function ( optionalTarget ) {
  4001. var result = optionalTarget || new THREE.Vector3();
  4002. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4003. },
  4004. normal: function ( optionalTarget ) {
  4005. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4006. },
  4007. plane: function ( optionalTarget ) {
  4008. var result = optionalTarget || new THREE.Plane();
  4009. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4010. },
  4011. barycoordFromPoint: function ( point, optionalTarget ) {
  4012. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4013. },
  4014. containsPoint: function ( point ) {
  4015. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4016. },
  4017. equals: function ( triangle ) {
  4018. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4019. },
  4020. clone: function () {
  4021. return new THREE.Triangle().copy( this );
  4022. }
  4023. };