three-math.js 134 KB

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