ThreeDOM.js 163 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100
  1. <<<<<<< HEAD
  2. /**
  3. * @author mr.doob / http://mrdoob.com/
  4. */
  5. var THREE = THREE || { REVISION: '49dev' };
  6. if ( ! self.Int32Array ) {
  7. self.Int32Array = Array;
  8. self.Float32Array = Array;
  9. }
  10. // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
  11. // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
  12. // requestAnimationFrame polyfill by Erik Möller
  13. // fixes from Paul Irish and Tino Zijdel
  14. ( function () {
  15. var lastTime = 0;
  16. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  17. for ( var x = 0; x < vendors.length && !window.requestAnimationFrame; ++ x ) {
  18. window.requestAnimationFrame = window[ vendors[ x ] + 'RequestAnimationFrame' ];
  19. window.cancelAnimationFrame = window[ vendors[ x ] + 'CancelAnimationFrame' ] || window[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  20. }
  21. if ( !window.requestAnimationFrame ) {
  22. window.requestAnimationFrame = function ( callback, element ) {
  23. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  24. var id = window.setTimeout( function() { callback( currTime + timeToCall ); }, timeToCall );
  25. lastTime = currTime + timeToCall;
  26. return id;
  27. };
  28. }
  29. if ( !window.cancelAnimationFrame ) {
  30. window.cancelAnimationFrame = function ( id ) { clearTimeout( id ); };
  31. }
  32. }() );
  33. /**
  34. * @author mr.doob / http://mrdoob.com/
  35. */
  36. THREE.Color = function ( hex ) {
  37. if ( hex !== undefined ) this.setHex( hex );
  38. return this;
  39. };
  40. THREE.Color.prototype = {
  41. constructor: THREE.Color,
  42. r: 1, g: 1, b: 1,
  43. copy: function ( color ) {
  44. this.r = color.r;
  45. this.g = color.g;
  46. this.b = color.b;
  47. return this;
  48. },
  49. copyGammaToLinear: function ( color ) {
  50. this.r = color.r * color.r;
  51. this.g = color.g * color.g;
  52. this.b = color.b * color.b;
  53. return this;
  54. },
  55. copyLinearToGamma: function ( color ) {
  56. this.r = Math.sqrt( color.r );
  57. this.g = Math.sqrt( color.g );
  58. this.b = Math.sqrt( color.b );
  59. return this;
  60. },
  61. convertGammaToLinear: function () {
  62. var r = this.r, g = this.g, b = this.b;
  63. this.r = r * r;
  64. this.g = g * g;
  65. this.b = b * b;
  66. return this;
  67. },
  68. convertLinearToGamma: function () {
  69. this.r = Math.sqrt( this.r );
  70. this.g = Math.sqrt( this.g );
  71. this.b = Math.sqrt( this.b );
  72. return this;
  73. },
  74. setRGB: function ( r, g, b ) {
  75. this.r = r;
  76. this.g = g;
  77. this.b = b;
  78. return this;
  79. },
  80. setHSV: function ( h, s, v ) {
  81. // based on MochiKit implementation by Bob Ippolito
  82. // h,s,v ranges are < 0.0 - 1.0 >
  83. var i, f, p, q, t;
  84. if ( v === 0 ) {
  85. this.r = this.g = this.b = 0;
  86. } else {
  87. i = Math.floor( h * 6 );
  88. f = ( h * 6 ) - i;
  89. p = v * ( 1 - s );
  90. q = v * ( 1 - ( s * f ) );
  91. t = v * ( 1 - ( s * ( 1 - f ) ) );
  92. switch ( i ) {
  93. case 1: this.r = q; this.g = v; this.b = p; break;
  94. case 2: this.r = p; this.g = v; this.b = t; break;
  95. case 3: this.r = p; this.g = q; this.b = v; break;
  96. case 4: this.r = t; this.g = p; this.b = v; break;
  97. case 5: this.r = v; this.g = p; this.b = q; break;
  98. case 6: // fall through
  99. case 0: this.r = v; this.g = t; this.b = p; break;
  100. }
  101. }
  102. return this;
  103. },
  104. setHex: function ( hex ) {
  105. hex = Math.floor( hex );
  106. this.r = ( hex >> 16 & 255 ) / 255;
  107. this.g = ( hex >> 8 & 255 ) / 255;
  108. this.b = ( hex & 255 ) / 255;
  109. return this;
  110. },
  111. lerpSelf: function ( color, alpha ) {
  112. this.r += ( color.r - this.r ) * alpha;
  113. this.g += ( color.g - this.g ) * alpha;
  114. this.b += ( color.b - this.b ) * alpha;
  115. return this;
  116. },
  117. getHex: function () {
  118. return Math.floor( this.r * 255 ) << 16 ^ Math.floor( this.g * 255 ) << 8 ^ Math.floor( this.b * 255 );
  119. },
  120. getContextStyle: function () {
  121. return 'rgb(' + Math.floor( this.r * 255 ) + ',' + Math.floor( this.g * 255 ) + ',' + Math.floor( this.b * 255 ) + ')';
  122. },
  123. clone: function () {
  124. return new THREE.Color().setRGB( this.r, this.g, this.b );
  125. }
  126. };
  127. /**
  128. * @author mr.doob / http://mrdoob.com/
  129. * @author philogb / http://blog.thejit.org/
  130. * @author egraether / http://egraether.com/
  131. * @author zz85 / http://www.lab4games.net/zz85/blog
  132. */
  133. THREE.Vector2 = function ( x, y ) {
  134. this.x = x || 0;
  135. this.y = y || 0;
  136. };
  137. THREE.Vector2.prototype = {
  138. constructor: THREE.Vector2,
  139. set: function ( x, y ) {
  140. this.x = x;
  141. this.y = y;
  142. return this;
  143. },
  144. copy: function ( v ) {
  145. this.x = v.x;
  146. this.y = v.y;
  147. return this;
  148. },
  149. add: function ( a, b ) {
  150. this.x = a.x + b.x;
  151. this.y = a.y + b.y;
  152. return this;
  153. },
  154. addSelf: function ( v ) {
  155. this.x += v.x;
  156. this.y += v.y;
  157. return this;
  158. },
  159. sub: function ( a, b ) {
  160. this.x = a.x - b.x;
  161. this.y = a.y - b.y;
  162. return this;
  163. },
  164. subSelf: function ( v ) {
  165. this.x -= v.x;
  166. this.y -= v.y;
  167. return this;
  168. },
  169. multiplyScalar: function ( s ) {
  170. this.x *= s;
  171. this.y *= s;
  172. return this;
  173. },
  174. divideScalar: function ( s ) {
  175. if ( s ) {
  176. this.x /= s;
  177. this.y /= s;
  178. } else {
  179. this.set( 0, 0 );
  180. }
  181. return this;
  182. },
  183. negate: function() {
  184. return this.multiplyScalar( - 1 );
  185. },
  186. dot: function ( v ) {
  187. return this.x * v.x + this.y * v.y;
  188. },
  189. lengthSq: function () {
  190. return this.x * this.x + this.y * this.y;
  191. },
  192. length: function () {
  193. return Math.sqrt( this.lengthSq() );
  194. },
  195. normalize: function () {
  196. return this.divideScalar( this.length() );
  197. },
  198. distanceTo: function ( v ) {
  199. return Math.sqrt( this.distanceToSquared( v ) );
  200. },
  201. distanceToSquared: function ( v ) {
  202. var dx = this.x - v.x, dy = this.y - v.y;
  203. return dx * dx + dy * dy;
  204. },
  205. setLength: function ( l ) {
  206. return this.normalize().multiplyScalar( l );
  207. },
  208. lerpSelf: function ( v, alpha ) {
  209. this.x += ( v.x - this.x ) * alpha;
  210. this.y += ( v.y - this.y ) * alpha;
  211. return this;
  212. },
  213. equals: function( v ) {
  214. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  215. },
  216. isZero: function () {
  217. return ( this.lengthSq() < 0.0001 /* almostZero */ );
  218. },
  219. clone: function () {
  220. return new THREE.Vector2( this.x, this.y );
  221. }
  222. };
  223. /**
  224. * @author mr.doob / http://mrdoob.com/
  225. * @author kile / http://kile.stravaganza.org/
  226. * @author philogb / http://blog.thejit.org/
  227. * @author mikael emtinger / http://gomo.se/
  228. * @author egraether / http://egraether.com/
  229. */
  230. THREE.Vector3 = function ( x, y, z ) {
  231. this.x = x || 0;
  232. this.y = y || 0;
  233. this.z = z || 0;
  234. };
  235. THREE.Vector3.prototype = {
  236. constructor: THREE.Vector3,
  237. set: function ( x, y, z ) {
  238. this.x = x;
  239. this.y = y;
  240. this.z = z;
  241. return this;
  242. },
  243. setX: function ( x ) {
  244. this.x = x;
  245. return this;
  246. },
  247. setY: function ( y ) {
  248. this.y = y;
  249. return this;
  250. },
  251. setZ: function ( z ) {
  252. this.z = z;
  253. return this;
  254. },
  255. copy: function ( v ) {
  256. this.x = v.x;
  257. this.y = v.y;
  258. this.z = v.z;
  259. return this;
  260. },
  261. add: function ( a, b ) {
  262. this.x = a.x + b.x;
  263. this.y = a.y + b.y;
  264. this.z = a.z + b.z;
  265. return this;
  266. },
  267. addSelf: function ( v ) {
  268. this.x += v.x;
  269. this.y += v.y;
  270. this.z += v.z;
  271. return this;
  272. },
  273. addScalar: function ( s ) {
  274. this.x += s;
  275. this.y += s;
  276. this.z += s;
  277. return this;
  278. },
  279. sub: function ( a, b ) {
  280. this.x = a.x - b.x;
  281. this.y = a.y - b.y;
  282. this.z = a.z - b.z;
  283. return this;
  284. },
  285. subSelf: function ( v ) {
  286. this.x -= v.x;
  287. this.y -= v.y;
  288. this.z -= v.z;
  289. return this;
  290. },
  291. multiply: function ( a, b ) {
  292. this.x = a.x * b.x;
  293. this.y = a.y * b.y;
  294. this.z = a.z * b.z;
  295. return this;
  296. },
  297. multiplySelf: function ( v ) {
  298. this.x *= v.x;
  299. this.y *= v.y;
  300. this.z *= v.z;
  301. return this;
  302. },
  303. multiplyScalar: function ( s ) {
  304. this.x *= s;
  305. this.y *= s;
  306. this.z *= s;
  307. return this;
  308. },
  309. divideSelf: function ( v ) {
  310. this.x /= v.x;
  311. this.y /= v.y;
  312. this.z /= v.z;
  313. return this;
  314. },
  315. divideScalar: function ( s ) {
  316. if ( s ) {
  317. this.x /= s;
  318. this.y /= s;
  319. this.z /= s;
  320. } else {
  321. this.x = 0;
  322. this.y = 0;
  323. this.z = 0;
  324. }
  325. return this;
  326. },
  327. negate: function() {
  328. return this.multiplyScalar( - 1 );
  329. },
  330. dot: function ( v ) {
  331. return this.x * v.x + this.y * v.y + this.z * v.z;
  332. },
  333. lengthSq: function () {
  334. return this.x * this.x + this.y * this.y + this.z * this.z;
  335. },
  336. length: function () {
  337. return Math.sqrt( this.lengthSq() );
  338. },
  339. lengthManhattan: function () {
  340. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  341. },
  342. normalize: function () {
  343. return this.divideScalar( this.length() );
  344. },
  345. setLength: function ( l ) {
  346. return this.normalize().multiplyScalar( l );
  347. },
  348. lerpSelf: function ( v, alpha ) {
  349. this.x += ( v.x - this.x ) * alpha;
  350. this.y += ( v.y - this.y ) * alpha;
  351. this.z += ( v.z - this.z ) * alpha;
  352. return this;
  353. },
  354. cross: function ( a, b ) {
  355. this.x = a.y * b.z - a.z * b.y;
  356. this.y = a.z * b.x - a.x * b.z;
  357. this.z = a.x * b.y - a.y * b.x;
  358. return this;
  359. },
  360. crossSelf: function ( v ) {
  361. var x = this.x, y = this.y, z = this.z;
  362. this.x = y * v.z - z * v.y;
  363. this.y = z * v.x - x * v.z;
  364. this.z = x * v.y - y * v.x;
  365. return this;
  366. },
  367. distanceTo: function ( v ) {
  368. return Math.sqrt( this.distanceToSquared( v ) );
  369. },
  370. distanceToSquared: function ( v ) {
  371. return new THREE.Vector3().sub( this, v ).lengthSq();
  372. },
  373. getPositionFromMatrix: function ( m ) {
  374. this.x = m.elements[12];
  375. this.y = m.elements[13];
  376. this.z = m.elements[14];
  377. return this;
  378. },
  379. getRotationFromMatrix: function ( m, scale ) {
  380. var sx = scale ? scale.x : 1;
  381. var sy = scale ? scale.y : 1;
  382. var sz = scale ? scale.z : 1;
  383. var m11 = m.elements[0] / sx, m12 = m.elements[4] / sy, m13 = m.elements[8] / sz;
  384. var m21 = m.elements[1] / sx, m22 = m.elements[5] / sy, m23 = m.elements[9] / sz;
  385. var m33 = m.elements[10] / sz;
  386. this.y = Math.asin( m13 );
  387. var cosY = Math.cos( this.y );
  388. if ( Math.abs( cosY ) > 0.00001 ) {
  389. this.x = Math.atan2( - m23 / cosY, m33 / cosY );
  390. this.z = Math.atan2( - m12 / cosY, m11 / cosY );
  391. } else {
  392. this.x = 0;
  393. this.z = Math.atan2( m21, m22 );
  394. }
  395. return this;
  396. },
  397. /*
  398. // from http://www.mathworks.com/matlabcentral/fileexchange/20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/content/SpinCalc.m
  399. // order XYZ
  400. getEulerXYZFromQuaternion: function ( q ) {
  401. this.x = Math.atan2( 2 * ( q.x * q.w - q.y * q.z ), ( q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z ) );
  402. this.y = Math.asin( 2 * ( q.x * q.z + q.y * q.w ) );
  403. this.z = Math.atan2( 2 * ( q.z * q.w - q.x * q.y ), ( q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z ) );
  404. },
  405. // from http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm
  406. // order YZX (assuming heading == y, attitude == z, bank == x)
  407. getEulerYZXFromQuaternion: function ( q ) {
  408. var sqw = q.w * q.w;
  409. var sqx = q.x * q.x;
  410. var sqy = q.y * q.y;
  411. var sqz = q.z * q.z;
  412. var unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
  413. var test = q.x * q.y + q.z * q.w;
  414. if ( test > 0.499 * unit ) { // singularity at north pole
  415. this.y = 2 * Math.atan2( q.x, q.w );
  416. this.z = Math.PI / 2;
  417. this.x = 0;
  418. return;
  419. }
  420. if ( test < -0.499 * unit ) { // singularity at south pole
  421. this.y = -2 * Math.atan2( q.x, q.w );
  422. this.z = -Math.PI / 2;
  423. this.x = 0;
  424. return;
  425. }
  426. this.y = Math.atan2( 2 * q.y * q.w - 2 * q.x * q.z, sqx - sqy - sqz + sqw );
  427. this.z = Math.asin( 2 * test / unit );
  428. this.x = Math.atan2( 2 * q.x * q.w - 2 * q.y * q.z, -sqx + sqy - sqz + sqw );
  429. },
  430. */
  431. getScaleFromMatrix: function ( m ) {
  432. var sx = this.set( m.elements[0], m.elements[1], m.elements[2] ).length();
  433. var sy = this.set( m.elements[4], m.elements[5], m.elements[6] ).length();
  434. var sz = this.set( m.elements[8], m.elements[9], m.elements[10] ).length();
  435. this.x = sx;
  436. this.y = sy;
  437. this.z = sz;
  438. },
  439. equals: function ( v ) {
  440. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  441. },
  442. isZero: function () {
  443. return ( this.lengthSq() < 0.0001 /* almostZero */ );
  444. },
  445. clone: function () {
  446. return new THREE.Vector3( this.x, this.y, this.z );
  447. }
  448. };
  449. /**
  450. * @author supereggbert / http://www.paulbrunt.co.uk/
  451. * @author philogb / http://blog.thejit.org/
  452. * @author mikael emtinger / http://gomo.se/
  453. * @author egraether / http://egraether.com/
  454. */
  455. THREE.Vector4 = function ( x, y, z, w ) {
  456. this.x = x || 0;
  457. this.y = y || 0;
  458. this.z = z || 0;
  459. this.w = ( w !== undefined ) ? w : 1;
  460. };
  461. THREE.Vector4.prototype = {
  462. constructor: THREE.Vector4,
  463. set: function ( x, y, z, w ) {
  464. this.x = x;
  465. this.y = y;
  466. this.z = z;
  467. this.w = w;
  468. return this;
  469. },
  470. copy: function ( v ) {
  471. this.x = v.x;
  472. this.y = v.y;
  473. this.z = v.z;
  474. this.w = ( v.w !== undefined ) ? v.w : 1;
  475. return this;
  476. },
  477. add: function ( a, b ) {
  478. this.x = a.x + b.x;
  479. this.y = a.y + b.y;
  480. this.z = a.z + b.z;
  481. this.w = a.w + b.w;
  482. return this;
  483. },
  484. addSelf: function ( v ) {
  485. this.x += v.x;
  486. this.y += v.y;
  487. this.z += v.z;
  488. this.w += v.w;
  489. return this;
  490. },
  491. sub: function ( a, b ) {
  492. this.x = a.x - b.x;
  493. this.y = a.y - b.y;
  494. this.z = a.z - b.z;
  495. this.w = a.w - b.w;
  496. return this;
  497. },
  498. subSelf: function ( v ) {
  499. this.x -= v.x;
  500. this.y -= v.y;
  501. this.z -= v.z;
  502. this.w -= v.w;
  503. return this;
  504. },
  505. multiplyScalar: function ( s ) {
  506. this.x *= s;
  507. this.y *= s;
  508. this.z *= s;
  509. this.w *= s;
  510. return this;
  511. },
  512. divideScalar: function ( s ) {
  513. if ( s ) {
  514. this.x /= s;
  515. this.y /= s;
  516. this.z /= s;
  517. this.w /= s;
  518. } else {
  519. this.x = 0;
  520. this.y = 0;
  521. this.z = 0;
  522. this.w = 1;
  523. }
  524. return this;
  525. },
  526. negate: function() {
  527. return this.multiplyScalar( -1 );
  528. },
  529. dot: function ( v ) {
  530. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  531. },
  532. lengthSq: function () {
  533. return this.dot( this );
  534. },
  535. length: function () {
  536. return Math.sqrt( this.lengthSq() );
  537. },
  538. normalize: function () {
  539. return this.divideScalar( this.length() );
  540. },
  541. setLength: function ( l ) {
  542. return this.normalize().multiplyScalar( l );
  543. },
  544. lerpSelf: function ( v, alpha ) {
  545. this.x += ( v.x - this.x ) * alpha;
  546. this.y += ( v.y - this.y ) * alpha;
  547. this.z += ( v.z - this.z ) * alpha;
  548. this.w += ( v.w - this.w ) * alpha;
  549. return this;
  550. },
  551. clone: function () {
  552. return new THREE.Vector4( this.x, this.y, this.z, this.w );
  553. }
  554. };
  555. /**
  556. * @author mrdoob / http://mrdoob.com/
  557. * @author alteredq / http://alteredqualia.com/
  558. */
  559. THREE.Frustum = function ( ) {
  560. this.planes = [
  561. new THREE.Vector4(),
  562. new THREE.Vector4(),
  563. new THREE.Vector4(),
  564. new THREE.Vector4(),
  565. new THREE.Vector4(),
  566. new THREE.Vector4()
  567. ];
  568. };
  569. THREE.Frustum.prototype.setFromMatrix = function ( m ) {
  570. var i, plane, planes = this.planes;
  571. var me = m.elements;
  572. var me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3];
  573. var me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7];
  574. var me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11];
  575. var me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15];
  576. planes[ 0 ].set( me3 - me0, me7 - me4, me11 - me8, me15 - me12 );
  577. planes[ 1 ].set( me3 + me0, me7 + me4, me11 + me8, me15 + me12 );
  578. planes[ 2 ].set( me3 + me1, me7 + me5, me11 + me9, me15 + me13 );
  579. planes[ 3 ].set( me3 - me1, me7 - me5, me11 - me9, me15 - me13 );
  580. planes[ 4 ].set( me3 - me2, me7 - me6, me11 - me10, me15 - me14 );
  581. planes[ 5 ].set( me3 + me2, me7 + me6, me11 + me10, me15 + me14 );
  582. for ( i = 0; i < 6; i ++ ) {
  583. plane = planes[ i ];
  584. plane.divideScalar( Math.sqrt( plane.x * plane.x + plane.y * plane.y + plane.z * plane.z ) );
  585. }
  586. };
  587. THREE.Frustum.prototype.contains = function ( object ) {
  588. var distance,
  589. planes = this.planes,
  590. matrix = object.matrixWorld,
  591. me = matrix.elements,
  592. radius = - object.geometry.boundingSphere.radius * matrix.getMaxScaleOnAxis();
  593. for ( var i = 0; i < 6; i ++ ) {
  594. distance = planes[ i ].x * me[12] + planes[ i ].y * me[13] + planes[ i ].z * me[14] + planes[ i ].w;
  595. if ( distance <= radius ) return false;
  596. }
  597. return true;
  598. };
  599. THREE.Frustum.__v1 = new THREE.Vector3();
  600. /**
  601. * @author mr.doob / http://mrdoob.com/
  602. */
  603. THREE.Ray = function ( origin, direction ) {
  604. this.origin = origin || new THREE.Vector3();
  605. this.direction = direction || new THREE.Vector3();
  606. var precision = 0.0001;
  607. this.setPrecision = function ( value ) {
  608. precision = value;
  609. };
  610. var a = new THREE.Vector3();
  611. var b = new THREE.Vector3();
  612. var c = new THREE.Vector3();
  613. var d = new THREE.Vector3();
  614. var originCopy = new THREE.Vector3();
  615. var directionCopy = new THREE.Vector3();
  616. var vector = new THREE.Vector3();
  617. var normal = new THREE.Vector3();
  618. var intersectPoint = new THREE.Vector3()
  619. this.intersectObject = function ( object ) {
  620. var intersect, intersects = [];
  621. if ( object instanceof THREE.Particle ) {
  622. var distance = distanceFromIntersection( this.origin, this.direction, object.matrixWorld.getPosition() );
  623. if ( distance > object.scale.x ) {
  624. return [];
  625. }
  626. intersect = {
  627. distance: distance,
  628. point: object.position,
  629. face: null,
  630. object: object
  631. };
  632. intersects.push( intersect );
  633. } else if ( object instanceof THREE.Mesh ) {
  634. // Checking boundingSphere
  635. var distance = distanceFromIntersection( this.origin, this.direction, object.matrixWorld.getPosition() );
  636. var scale = THREE.Frustum.__v1.set( object.matrixWorld.getColumnX().length(), object.matrixWorld.getColumnY().length(), object.matrixWorld.getColumnZ().length() );
  637. if ( distance > object.geometry.boundingSphere.radius * Math.max( scale.x, Math.max( scale.y, scale.z ) ) ) {
  638. return intersects;
  639. }
  640. // Checking faces
  641. var f, fl, face, dot, scalar,
  642. geometry = object.geometry,
  643. vertices = geometry.vertices,
  644. objMatrix;
  645. object.matrixRotationWorld.extractRotation( object.matrixWorld );
  646. for ( f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
  647. face = geometry.faces[ f ];
  648. originCopy.copy( this.origin );
  649. directionCopy.copy( this.direction );
  650. objMatrix = object.matrixWorld;
  651. // determine if ray intersects the plane of the face
  652. // note: this works regardless of the direction of the face normal
  653. vector = objMatrix.multiplyVector3( vector.copy( face.centroid ) ).subSelf( originCopy );
  654. normal = object.matrixRotationWorld.multiplyVector3( normal.copy( face.normal ) );
  655. dot = directionCopy.dot( normal );
  656. // bail if ray and plane are parallel
  657. if ( Math.abs( dot ) < precision ) continue;
  658. // calc distance to plane
  659. scalar = normal.dot( vector ) / dot;
  660. // if negative distance, then plane is behind ray
  661. if ( scalar < 0 ) continue;
  662. if ( object.doubleSided || ( object.flipSided ? dot > 0 : dot < 0 ) ) {
  663. intersectPoint.add( originCopy, directionCopy.multiplyScalar( scalar ) );
  664. if ( face instanceof THREE.Face3 ) {
  665. a = objMatrix.multiplyVector3( a.copy( vertices[ face.a ] ) );
  666. b = objMatrix.multiplyVector3( b.copy( vertices[ face.b ] ) );
  667. c = objMatrix.multiplyVector3( c.copy( vertices[ face.c ] ) );
  668. if ( pointInFace3( intersectPoint, a, b, c ) ) {
  669. intersect = {
  670. distance: originCopy.distanceTo( intersectPoint ),
  671. point: intersectPoint.clone(),
  672. face: face,
  673. object: object
  674. };
  675. intersects.push( intersect );
  676. }
  677. } else if ( face instanceof THREE.Face4 ) {
  678. a = objMatrix.multiplyVector3( a.copy( vertices[ face.a ] ) );
  679. b = objMatrix.multiplyVector3( b.copy( vertices[ face.b ] ) );
  680. c = objMatrix.multiplyVector3( c.copy( vertices[ face.c ] ) );
  681. d = objMatrix.multiplyVector3( d.copy( vertices[ face.d ] ) );
  682. if ( pointInFace3( intersectPoint, a, b, d ) || pointInFace3( intersectPoint, b, c, d ) ) {
  683. intersect = {
  684. distance: originCopy.distanceTo( intersectPoint ),
  685. point: intersectPoint.clone(),
  686. face: face,
  687. object: object
  688. };
  689. intersects.push( intersect );
  690. }
  691. }
  692. }
  693. }
  694. }
  695. return intersects;
  696. }
  697. this.intersectObjects = function ( objects ) {
  698. var intersects = [];
  699. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  700. Array.prototype.push.apply( intersects, this.intersectObject( objects[ i ] ) );
  701. }
  702. intersects.sort( function ( a, b ) { return a.distance - b.distance; } );
  703. return intersects;
  704. };
  705. var v0 = new THREE.Vector3(), v1 = new THREE.Vector3(), v2 = new THREE.Vector3();
  706. var dot, intersect, distance;
  707. function distanceFromIntersection( origin, direction, position ) {
  708. v0.sub( position, origin );
  709. dot = v0.dot( direction );
  710. intersect = v1.add( origin, v2.copy( direction ).multiplyScalar( dot ) );
  711. distance = position.distanceTo( intersect );
  712. return distance;
  713. }
  714. // http://www.blackpawn.com/texts/pointinpoly/default.html
  715. var dot00, dot01, dot02, dot11, dot12, invDenom, u, v;
  716. function pointInFace3( p, a, b, c ) {
  717. v0.sub( c, a );
  718. v1.sub( b, a );
  719. v2.sub( p, a );
  720. dot00 = v0.dot( v0 );
  721. dot01 = v0.dot( v1 );
  722. dot02 = v0.dot( v2 );
  723. dot11 = v1.dot( v1 );
  724. dot12 = v1.dot( v2 );
  725. invDenom = 1 / ( dot00 * dot11 - dot01 * dot01 );
  726. u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  727. v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  728. return ( u >= 0 ) && ( v >= 0 ) && ( u + v < 1 );
  729. }
  730. };
  731. /**
  732. * @author mr.doob / http://mrdoob.com/
  733. */
  734. THREE.Rectangle = function () {
  735. var _left, _top, _right, _bottom,
  736. _width, _height, _isEmpty = true;
  737. function resize() {
  738. _width = _right - _left;
  739. _height = _bottom - _top;
  740. }
  741. this.getX = function () {
  742. return _left;
  743. };
  744. this.getY = function () {
  745. return _top;
  746. };
  747. this.getWidth = function () {
  748. return _width;
  749. };
  750. this.getHeight = function () {
  751. return _height;
  752. };
  753. this.getLeft = function() {
  754. return _left;
  755. };
  756. this.getTop = function() {
  757. return _top;
  758. };
  759. this.getRight = function() {
  760. return _right;
  761. };
  762. this.getBottom = function() {
  763. return _bottom;
  764. };
  765. this.set = function ( left, top, right, bottom ) {
  766. _isEmpty = false;
  767. _left = left; _top = top;
  768. _right = right; _bottom = bottom;
  769. resize();
  770. };
  771. this.addPoint = function ( x, y ) {
  772. if ( _isEmpty ) {
  773. _isEmpty = false;
  774. _left = x; _top = y;
  775. _right = x; _bottom = y;
  776. resize();
  777. } else {
  778. _left = _left < x ? _left : x; // Math.min( _left, x );
  779. _top = _top < y ? _top : y; // Math.min( _top, y );
  780. _right = _right > x ? _right : x; // Math.max( _right, x );
  781. _bottom = _bottom > y ? _bottom : y; // Math.max( _bottom, y );
  782. resize();
  783. }
  784. };
  785. this.add3Points = function ( x1, y1, x2, y2, x3, y3 ) {
  786. if (_isEmpty) {
  787. _isEmpty = false;
  788. _left = x1 < x2 ? ( x1 < x3 ? x1 : x3 ) : ( x2 < x3 ? x2 : x3 );
  789. _top = y1 < y2 ? ( y1 < y3 ? y1 : y3 ) : ( y2 < y3 ? y2 : y3 );
  790. _right = x1 > x2 ? ( x1 > x3 ? x1 : x3 ) : ( x2 > x3 ? x2 : x3 );
  791. _bottom = y1 > y2 ? ( y1 > y3 ? y1 : y3 ) : ( y2 > y3 ? y2 : y3 );
  792. resize();
  793. } else {
  794. _left = x1 < x2 ? ( x1 < x3 ? ( x1 < _left ? x1 : _left ) : ( x3 < _left ? x3 : _left ) ) : ( x2 < x3 ? ( x2 < _left ? x2 : _left ) : ( x3 < _left ? x3 : _left ) );
  795. _top = y1 < y2 ? ( y1 < y3 ? ( y1 < _top ? y1 : _top ) : ( y3 < _top ? y3 : _top ) ) : ( y2 < y3 ? ( y2 < _top ? y2 : _top ) : ( y3 < _top ? y3 : _top ) );
  796. _right = x1 > x2 ? ( x1 > x3 ? ( x1 > _right ? x1 : _right ) : ( x3 > _right ? x3 : _right ) ) : ( x2 > x3 ? ( x2 > _right ? x2 : _right ) : ( x3 > _right ? x3 : _right ) );
  797. _bottom = y1 > y2 ? ( y1 > y3 ? ( y1 > _bottom ? y1 : _bottom ) : ( y3 > _bottom ? y3 : _bottom ) ) : ( y2 > y3 ? ( y2 > _bottom ? y2 : _bottom ) : ( y3 > _bottom ? y3 : _bottom ) );
  798. resize();
  799. };
  800. };
  801. this.addRectangle = function ( r ) {
  802. if ( _isEmpty ) {
  803. _isEmpty = false;
  804. _left = r.getLeft(); _top = r.getTop();
  805. _right = r.getRight(); _bottom = r.getBottom();
  806. resize();
  807. } else {
  808. _left = _left < r.getLeft() ? _left : r.getLeft(); // Math.min(_left, r.getLeft() );
  809. _top = _top < r.getTop() ? _top : r.getTop(); // Math.min(_top, r.getTop() );
  810. _right = _right > r.getRight() ? _right : r.getRight(); // Math.max(_right, r.getRight() );
  811. _bottom = _bottom > r.getBottom() ? _bottom : r.getBottom(); // Math.max(_bottom, r.getBottom() );
  812. resize();
  813. }
  814. };
  815. this.inflate = function ( v ) {
  816. _left -= v; _top -= v;
  817. _right += v; _bottom += v;
  818. resize();
  819. };
  820. this.minSelf = function ( r ) {
  821. _left = _left > r.getLeft() ? _left : r.getLeft(); // Math.max( _left, r.getLeft() );
  822. _top = _top > r.getTop() ? _top : r.getTop(); // Math.max( _top, r.getTop() );
  823. _right = _right < r.getRight() ? _right : r.getRight(); // Math.min( _right, r.getRight() );
  824. _bottom = _bottom < r.getBottom() ? _bottom : r.getBottom(); // Math.min( _bottom, r.getBottom() );
  825. resize();
  826. };
  827. this.intersects = function ( r ) {
  828. // http://gamemath.com/2011/09/detecting-whether-two-boxes-overlap/
  829. if ( _right < r.getLeft() ) return false;
  830. if ( _left > r.getRight() ) return false;
  831. if ( _bottom < r.getTop() ) return false;
  832. if ( _top > r.getBottom() ) return false;
  833. return true;
  834. };
  835. this.empty = function () {
  836. _isEmpty = true;
  837. _left = 0; _top = 0;
  838. _right = 0; _bottom = 0;
  839. resize();
  840. };
  841. this.isEmpty = function () {
  842. return _isEmpty;
  843. };
  844. };
  845. /**
  846. * @author alteredq / http://alteredqualia.com/
  847. */
  848. THREE.Math = {
  849. // Clamp value to range <a, b>
  850. clamp: function ( x, a, b ) {
  851. return ( x < a ) ? a : ( ( x > b ) ? b : x );
  852. },
  853. // Clamp value to range <a, inf)
  854. clampBottom: function ( x, a ) {
  855. return x < a ? a : x;
  856. },
  857. // Linear mapping from range <a1, a2> to range <b1, b2>
  858. mapLinear: function ( x, a1, a2, b1, b2 ) {
  859. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  860. },
  861. // Random float from <0, 1> with 16 bits of randomness
  862. // (standard Math.random() creates repetitive patterns when applied over larger space)
  863. random16: function () {
  864. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  865. },
  866. // Random integer from <low, high> interval
  867. randInt: function ( low, high ) {
  868. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  869. },
  870. // Random float from <low, high> interval
  871. randFloat: function ( low, high ) {
  872. return low + Math.random() * ( high - low );
  873. },
  874. // Random float from <-range/2, range/2> interval
  875. randFloatSpread: function ( range ) {
  876. return range * ( 0.5 - Math.random() );
  877. },
  878. sign: function ( x ) {
  879. return ( x < 0 ) ? -1 : ( ( x > 0 ) ? 1 : 0 );
  880. }
  881. };
  882. /**
  883. * @author alteredq / http://alteredqualia.com/
  884. */
  885. THREE.Matrix3 = function () {
  886. this.elements = new Float32Array(9);
  887. };
  888. THREE.Matrix3.prototype = {
  889. constructor: THREE.Matrix3,
  890. getInverse: function ( matrix ) {
  891. // input: THREE.Matrix4
  892. // ( based on http://code.google.com/p/webgl-mjs/ )
  893. var me = matrix.elements;
  894. var a11 = me[10] * me[5] - me[6] * me[9];
  895. var a21 = - me[10] * me[1] + me[2] * me[9];
  896. var a31 = me[6] * me[1] - me[2] * me[5];
  897. var a12 = - me[10] * me[4] + me[6] * me[8];
  898. var a22 = me[10] * me[0] - me[2] * me[8];
  899. var a32 = - me[6] * me[0] + me[2] * me[4];
  900. var a13 = me[9] * me[4] - me[5] * me[8];
  901. var a23 = - me[9] * me[0] + me[1] * me[8];
  902. var a33 = me[5] * me[0] - me[1] * me[4];
  903. var det = me[0] * a11 + me[1] * a12 + me[2] * a13;
  904. // no inverse
  905. if ( det === 0 ) {
  906. console.warn( "Matrix3.getInverse(): determinant == 0" );
  907. }
  908. var idet = 1.0 / det;
  909. var m = this.elements;
  910. m[ 0 ] = idet * a11; m[ 1 ] = idet * a21; m[ 2 ] = idet * a31;
  911. m[ 3 ] = idet * a12; m[ 4 ] = idet * a22; m[ 5 ] = idet * a32;
  912. m[ 6 ] = idet * a13; m[ 7 ] = idet * a23; m[ 8 ] = idet * a33;
  913. return this;
  914. },
  915. transpose: function () {
  916. var tmp, m = this.elements;
  917. tmp = m[1]; m[1] = m[3]; m[3] = tmp;
  918. tmp = m[2]; m[2] = m[6]; m[6] = tmp;
  919. tmp = m[5]; m[5] = m[7]; m[7] = tmp;
  920. return this;
  921. },
  922. transposeIntoArray: function ( r ) {
  923. var m = this.m;
  924. r[ 0 ] = m[ 0 ];
  925. r[ 1 ] = m[ 3 ];
  926. r[ 2 ] = m[ 6 ];
  927. r[ 3 ] = m[ 1 ];
  928. r[ 4 ] = m[ 4 ];
  929. r[ 5 ] = m[ 7 ];
  930. r[ 6 ] = m[ 2 ];
  931. r[ 7 ] = m[ 5 ];
  932. r[ 8 ] = m[ 8 ];
  933. return this;
  934. }
  935. };
  936. /**
  937. * @author mr.doob / http://mrdoob.com/
  938. * @author supereggbert / http://www.paulbrunt.co.uk/
  939. * @author philogb / http://blog.thejit.org/
  940. * @author jordi_ros / http://plattsoft.com
  941. * @author D1plo1d / http://github.com/D1plo1d
  942. * @author alteredq / http://alteredqualia.com/
  943. * @author mikael emtinger / http://gomo.se/
  944. * @author timknip / http://www.floorplanner.com/
  945. */
  946. THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  947. this.elements = new Float32Array(16);
  948. this.set(
  949. ( n11 !== undefined ) ? n11 : 1, n12 || 0, n13 || 0, n14 || 0,
  950. n21 || 0, ( n22 !== undefined ) ? n22 : 1, n23 || 0, n24 || 0,
  951. n31 || 0, n32 || 0, ( n33 !== undefined ) ? n33 : 1, n34 || 0,
  952. n41 || 0, n42 || 0, n43 || 0, ( n44 !== undefined ) ? n44 : 1
  953. );
  954. };
  955. THREE.Matrix4.prototype = {
  956. constructor: THREE.Matrix4,
  957. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  958. var te = this.elements;
  959. te[0] = n11; te[4] = n12; te[8] = n13; te[12] = n14;
  960. te[1] = n21; te[5] = n22; te[9] = n23; te[13] = n24;
  961. te[2] = n31; te[6] = n32; te[10] = n33; te[14] = n34;
  962. te[3] = n41; te[7] = n42; te[11] = n43; te[15] = n44;
  963. return this;
  964. },
  965. identity: function () {
  966. this.set(
  967. 1, 0, 0, 0,
  968. 0, 1, 0, 0,
  969. 0, 0, 1, 0,
  970. 0, 0, 0, 1
  971. );
  972. return this;
  973. },
  974. copy: function ( m ) {
  975. var me = m.elements;
  976. this.set(
  977. me[0], me[4], me[8], me[12],
  978. me[1], me[5], me[9], me[13],
  979. me[2], me[6], me[10], me[14],
  980. me[3], me[7], me[11], me[15]
  981. );
  982. return this;
  983. },
  984. lookAt: function ( eye, target, up ) {
  985. var te = this.elements;
  986. var x = THREE.Matrix4.__v1;
  987. var y = THREE.Matrix4.__v2;
  988. var z = THREE.Matrix4.__v3;
  989. z.sub( eye, target ).normalize();
  990. if ( z.length() === 0 ) {
  991. z.z = 1;
  992. }
  993. x.cross( up, z ).normalize();
  994. if ( x.length() === 0 ) {
  995. z.x += 0.0001;
  996. x.cross( up, z ).normalize();
  997. }
  998. y.cross( z, x );
  999. te[0] = x.x; te[4] = y.x; te[8] = z.x;
  1000. te[1] = x.y; te[5] = y.y; te[9] = z.y;
  1001. te[2] = x.z; te[6] = y.z; te[10] = z.z;
  1002. return this;
  1003. },
  1004. multiply: function ( a, b ) {
  1005. var ae = a.elements,
  1006. be = b.elements,
  1007. te = this.elements;
  1008. var a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
  1009. var a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
  1010. var a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
  1011. var a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
  1012. var b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
  1013. var b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
  1014. var b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
  1015. var b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
  1016. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  1017. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  1018. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  1019. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  1020. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  1021. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  1022. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  1023. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  1024. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  1025. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  1026. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  1027. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  1028. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  1029. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  1030. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  1031. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  1032. return this;
  1033. },
  1034. multiplySelf: function ( m ) {
  1035. return this.multiply( this, m );
  1036. },
  1037. multiplyToArray: function ( a, b, r ) {
  1038. var te = this.elements;
  1039. this.multiply( a, b );
  1040. r[ 0 ] = te[0]; r[ 1 ] = te[1]; r[ 2 ] = te[2]; r[ 3 ] = te[3];
  1041. r[ 4 ] = te[4]; r[ 5 ] = te[5]; r[ 6 ] = te[6]; r[ 7 ] = te[7];
  1042. r[ 8 ] = te[8]; r[ 9 ] = te[9]; r[ 10 ] = te[10]; r[ 11 ] = te[11];
  1043. r[ 12 ] = te[12]; r[ 13 ] = te[13]; r[ 14 ] = te[14]; r[ 15 ] = te[15];
  1044. return this;
  1045. },
  1046. multiplyScalar: function ( s ) {
  1047. var te = this.elements;
  1048. te[0] *= s; te[4] *= s; te[8] *= s; te[12] *= s;
  1049. te[1] *= s; te[5] *= s; te[9] *= s; te[13] *= s;
  1050. te[2] *= s; te[6] *= s; te[10] *= s; te[14] *= s;
  1051. te[3] *= s; te[7] *= s; te[11] *= s; te[15] *= s;
  1052. return this;
  1053. },
  1054. multiplyVector3: function ( v ) {
  1055. var te = this.elements;
  1056. var vx = v.x, vy = v.y, vz = v.z;
  1057. var d = 1 / ( te[3] * vx + te[7] * vy + te[11] * vz + te[15] );
  1058. v.x = ( te[0] * vx + te[4] * vy + te[8] * vz + te[12] ) * d;
  1059. v.y = ( te[1] * vx + te[5] * vy + te[9] * vz + te[13] ) * d;
  1060. v.z = ( te[2] * vx + te[6] * vy + te[10] * vz + te[14] ) * d;
  1061. return v;
  1062. },
  1063. multiplyVector4: function ( v ) {
  1064. var te = this.elements;
  1065. var vx = v.x, vy = v.y, vz = v.z, vw = v.w;
  1066. v.x = te[0] * vx + te[4] * vy + te[8] * vz + te[12] * vw;
  1067. v.y = te[1] * vx + te[5] * vy + te[9] * vz + te[13] * vw;
  1068. v.z = te[2] * vx + te[6] * vy + te[10] * vz + te[14] * vw;
  1069. v.w = te[3] * vx + te[7] * vy + te[11] * vz + te[15] * vw;
  1070. return v;
  1071. },
  1072. rotateAxis: function ( v ) {
  1073. var te = this.elements;
  1074. var vx = v.x, vy = v.y, vz = v.z;
  1075. v.x = vx * te[0] + vy * te[4] + vz * te[8];
  1076. v.y = vx * te[1] + vy * te[5] + vz * te[9];
  1077. v.z = vx * te[2] + vy * te[6] + vz * te[10];
  1078. v.normalize();
  1079. return v;
  1080. },
  1081. crossVector: function ( a ) {
  1082. var te = this.elements;
  1083. var v = new THREE.Vector4();
  1084. v.x = te[0] * a.x + te[4] * a.y + te[8] * a.z + te[12] * a.w;
  1085. v.y = te[1] * a.x + te[5] * a.y + te[9] * a.z + te[13] * a.w;
  1086. v.z = te[2] * a.x + te[6] * a.y + te[10] * a.z + te[14] * a.w;
  1087. v.w = ( a.w ) ? te[3] * a.x + te[7] * a.y + te[11] * a.z + te[15] * a.w : 1;
  1088. return v;
  1089. },
  1090. determinant: function () {
  1091. var te = this.elements;
  1092. var n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12];
  1093. var n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13];
  1094. var n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14];
  1095. var n41 = te[3], n42 = te[7], n43 = te[11], n44 = te[15];
  1096. //TODO: make this more efficient
  1097. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  1098. return (
  1099. n14 * n23 * n32 * n41-
  1100. n13 * n24 * n32 * n41-
  1101. n14 * n22 * n33 * n41+
  1102. n12 * n24 * n33 * n41+
  1103. n13 * n22 * n34 * n41-
  1104. n12 * n23 * n34 * n41-
  1105. n14 * n23 * n31 * n42+
  1106. n13 * n24 * n31 * n42+
  1107. n14 * n21 * n33 * n42-
  1108. n11 * n24 * n33 * n42-
  1109. n13 * n21 * n34 * n42+
  1110. n11 * n23 * n34 * n42+
  1111. n14 * n22 * n31 * n43-
  1112. n12 * n24 * n31 * n43-
  1113. n14 * n21 * n32 * n43+
  1114. n11 * n24 * n32 * n43+
  1115. n12 * n21 * n34 * n43-
  1116. n11 * n22 * n34 * n43-
  1117. n13 * n22 * n31 * n44+
  1118. n12 * n23 * n31 * n44+
  1119. n13 * n21 * n32 * n44-
  1120. n11 * n23 * n32 * n44-
  1121. n12 * n21 * n33 * n44+
  1122. n11 * n22 * n33 * n44
  1123. );
  1124. },
  1125. transpose: function () {
  1126. var te = this.elements;
  1127. var tmp;
  1128. tmp = te[1]; te[1] = te[4]; te[4] = tmp;
  1129. tmp = te[2]; te[2] = te[8]; te[8] = tmp;
  1130. tmp = te[6]; te[6] = te[9]; te[9] = tmp;
  1131. tmp = te[3]; te[3] = te[12]; te[12] = tmp;
  1132. tmp = te[7]; te[7] = te[13]; te[13] = tmp;
  1133. tmp = te[11]; te[11] = te[14]; te[14] = tmp;
  1134. return this;
  1135. },
  1136. flattenToArray: function ( flat ) {
  1137. var te = this.elements;
  1138. flat[ 0 ] = te[0]; flat[ 1 ] = te[1]; flat[ 2 ] = te[2]; flat[ 3 ] = te[3];
  1139. flat[ 4 ] = te[4]; flat[ 5 ] = te[5]; flat[ 6 ] = te[6]; flat[ 7 ] = te[7];
  1140. flat[ 8 ] = te[8]; flat[ 9 ] = te[9]; flat[ 10 ] = te[10]; flat[ 11 ] = te[11];
  1141. flat[ 12 ] = te[12]; flat[ 13 ] = te[13]; flat[ 14 ] = te[14]; flat[ 15 ] = te[15];
  1142. return flat;
  1143. },
  1144. flattenToArrayOffset: function( flat, offset ) {
  1145. var te = this.elements;
  1146. flat[ offset ] = te[0];
  1147. flat[ offset + 1 ] = te[1];
  1148. flat[ offset + 2 ] = te[2];
  1149. flat[ offset + 3 ] = te[3];
  1150. flat[ offset + 4 ] = te[4];
  1151. flat[ offset + 5 ] = te[5];
  1152. flat[ offset + 6 ] = te[6];
  1153. flat[ offset + 7 ] = te[7];
  1154. flat[ offset + 8 ] = te[8];
  1155. flat[ offset + 9 ] = te[9];
  1156. flat[ offset + 10 ] = te[10];
  1157. flat[ offset + 11 ] = te[11];
  1158. flat[ offset + 12 ] = te[12];
  1159. flat[ offset + 13 ] = te[13];
  1160. flat[ offset + 14 ] = te[14];
  1161. flat[ offset + 15 ] = te[15];
  1162. return flat;
  1163. },
  1164. getPosition: function () {
  1165. var te = this.elements;
  1166. return THREE.Matrix4.__v1.set( te[12], te[13], te[14] );
  1167. },
  1168. setPosition: function ( v ) {
  1169. var te = this.elements;
  1170. te[12] = v.x;
  1171. te[13] = v.y;
  1172. te[14] = v.z;
  1173. return this;
  1174. },
  1175. getColumnX: function () {
  1176. var te = this.elements;
  1177. return THREE.Matrix4.__v1.set( te[0], te[1], te[2] );
  1178. },
  1179. getColumnY: function () {
  1180. var te = this.elements;
  1181. return THREE.Matrix4.__v1.set( te[4], te[5], te[6] );
  1182. },
  1183. getColumnZ: function() {
  1184. var te = this.elements;
  1185. return THREE.Matrix4.__v1.set( te[8], te[9], te[10] );
  1186. },
  1187. getInverse: function ( m ) {
  1188. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  1189. var te = this.elements;
  1190. var me = m.elements;
  1191. var n11 = me[0], n12 = me[4], n13 = me[8], n14 = me[12];
  1192. var n21 = me[1], n22 = me[5], n23 = me[9], n24 = me[13];
  1193. var n31 = me[2], n32 = me[6], n33 = me[10], n34 = me[14];
  1194. var n41 = me[3], n42 = me[7], n43 = me[11], n44 = me[15];
  1195. te[0] = n23*n34*n42 - n24*n33*n42 + n24*n32*n43 - n22*n34*n43 - n23*n32*n44 + n22*n33*n44;
  1196. te[4] = n14*n33*n42 - n13*n34*n42 - n14*n32*n43 + n12*n34*n43 + n13*n32*n44 - n12*n33*n44;
  1197. te[8] = n13*n24*n42 - n14*n23*n42 + n14*n22*n43 - n12*n24*n43 - n13*n22*n44 + n12*n23*n44;
  1198. te[12] = n14*n23*n32 - n13*n24*n32 - n14*n22*n33 + n12*n24*n33 + n13*n22*n34 - n12*n23*n34;
  1199. te[1] = n24*n33*n41 - n23*n34*n41 - n24*n31*n43 + n21*n34*n43 + n23*n31*n44 - n21*n33*n44;
  1200. te[5] = n13*n34*n41 - n14*n33*n41 + n14*n31*n43 - n11*n34*n43 - n13*n31*n44 + n11*n33*n44;
  1201. te[9] = n14*n23*n41 - n13*n24*n41 - n14*n21*n43 + n11*n24*n43 + n13*n21*n44 - n11*n23*n44;
  1202. te[13] = n13*n24*n31 - n14*n23*n31 + n14*n21*n33 - n11*n24*n33 - n13*n21*n34 + n11*n23*n34;
  1203. te[2] = n22*n34*n41 - n24*n32*n41 + n24*n31*n42 - n21*n34*n42 - n22*n31*n44 + n21*n32*n44;
  1204. te[6] = n14*n32*n41 - n12*n34*n41 - n14*n31*n42 + n11*n34*n42 + n12*n31*n44 - n11*n32*n44;
  1205. te[10] = n12*n24*n41 - n14*n22*n41 + n14*n21*n42 - n11*n24*n42 - n12*n21*n44 + n11*n22*n44;
  1206. te[14] = n14*n22*n31 - n12*n24*n31 - n14*n21*n32 + n11*n24*n32 + n12*n21*n34 - n11*n22*n34;
  1207. te[3] = n23*n32*n41 - n22*n33*n41 - n23*n31*n42 + n21*n33*n42 + n22*n31*n43 - n21*n32*n43;
  1208. te[7] = n12*n33*n41 - n13*n32*n41 + n13*n31*n42 - n11*n33*n42 - n12*n31*n43 + n11*n32*n43;
  1209. te[11] = n13*n22*n41 - n12*n23*n41 - n13*n21*n42 + n11*n23*n42 + n12*n21*n43 - n11*n22*n43;
  1210. te[15] = n12*n23*n31 - n13*n22*n31 + n13*n21*n32 - n11*n23*n32 - n12*n21*n33 + n11*n22*n33;
  1211. this.multiplyScalar( 1 / m.determinant() );
  1212. return this;
  1213. },
  1214. setRotationFromEuler: function( v, order ) {
  1215. var te = this.elements;
  1216. var x = v.x, y = v.y, z = v.z;
  1217. var a = Math.cos( x ), b = Math.sin( x );
  1218. var c = Math.cos( y ), d = Math.sin( y );
  1219. var e = Math.cos( z ), f = Math.sin( z );
  1220. switch ( order ) {
  1221. case 'YXZ':
  1222. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  1223. te[0] = ce + df * b;
  1224. te[4] = de * b - cf;
  1225. te[8] = a * d;
  1226. te[1] = a * f;
  1227. te[5] = a * e;
  1228. te[9] = - b;
  1229. te[2] = cf * b - de;
  1230. te[6] = df + ce * b;
  1231. te[10] = a * c;
  1232. break;
  1233. case 'ZXY':
  1234. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  1235. te[0] = ce - df * b;
  1236. te[4] = - a * f;
  1237. te[8] = de + cf * b;
  1238. te[1] = cf + de * b;
  1239. te[5] = a * e;
  1240. te[9] = df - ce * b;
  1241. te[2] = - a * d;
  1242. te[6] = b;
  1243. te[10] = a * c;
  1244. break;
  1245. case 'ZYX':
  1246. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  1247. te[0] = c * e;
  1248. te[4] = be * d - af;
  1249. te[8] = ae * d + bf;
  1250. te[1] = c * f;
  1251. te[5] = bf * d + ae;
  1252. te[9] = af * d - be;
  1253. te[2] = - d;
  1254. te[6] = b * c;
  1255. te[10] = a * c;
  1256. break;
  1257. case 'YZX':
  1258. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  1259. te[0] = c * e;
  1260. te[4] = bd - ac * f;
  1261. te[8] = bc * f + ad;
  1262. te[1] = f;
  1263. te[5] = a * e;
  1264. te[9] = - b * e;
  1265. te[2] = - d * e;
  1266. te[6] = ad * f + bc;
  1267. te[10] = ac - bd * f;
  1268. break;
  1269. case 'XZY':
  1270. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  1271. te[0] = c * e;
  1272. te[4] = - f;
  1273. te[8] = d * e;
  1274. te[1] = ac * f + bd;
  1275. te[5] = a * e;
  1276. te[9] = ad * f - bc;
  1277. te[2] = bc * f - ad;
  1278. te[6] = b * e;
  1279. te[10] = bd * f + ac;
  1280. break;
  1281. default: // 'XYZ'
  1282. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  1283. te[0] = c * e;
  1284. te[4] = - c * f;
  1285. te[8] = d;
  1286. te[1] = af + be * d;
  1287. te[5] = ae - bf * d;
  1288. te[9] = - b * c;
  1289. te[2] = bf - ae * d;
  1290. te[6] = be + af * d;
  1291. te[10] = a * c;
  1292. break;
  1293. }
  1294. return this;
  1295. },
  1296. setRotationFromQuaternion: function( q ) {
  1297. var te = this.elements;
  1298. var x = q.x, y = q.y, z = q.z, w = q.w;
  1299. var x2 = x + x, y2 = y + y, z2 = z + z;
  1300. var xx = x * x2, xy = x * y2, xz = x * z2;
  1301. var yy = y * y2, yz = y * z2, zz = z * z2;
  1302. var wx = w * x2, wy = w * y2, wz = w * z2;
  1303. te[0] = 1 - ( yy + zz );
  1304. te[4] = xy - wz;
  1305. te[8] = xz + wy;
  1306. te[1] = xy + wz;
  1307. te[5] = 1 - ( xx + zz );
  1308. te[9] = yz - wx;
  1309. te[2] = xz - wy;
  1310. te[6] = yz + wx;
  1311. te[10] = 1 - ( xx + yy );
  1312. return this;
  1313. },
  1314. compose: function ( translation, rotation, scale ) {
  1315. var te = this.elements;
  1316. var mRotation = THREE.Matrix4.__m1;
  1317. var mScale = THREE.Matrix4.__m2;
  1318. mRotation.identity();
  1319. mRotation.setRotationFromQuaternion( rotation );
  1320. mScale.makeScale( scale.x, scale.y, scale.z );
  1321. this.multiply( mRotation, mScale );
  1322. te[12] = translation.x;
  1323. te[13] = translation.y;
  1324. te[14] = translation.z;
  1325. return this;
  1326. },
  1327. decompose: function ( translation, rotation, scale ) {
  1328. // grab the axis vectors
  1329. var te = this.elements;
  1330. var x = THREE.Matrix4.__v1;
  1331. var y = THREE.Matrix4.__v2;
  1332. var z = THREE.Matrix4.__v3;
  1333. x.set( te[0], te[1], te[2] );
  1334. y.set( te[4], te[5], te[6] );
  1335. z.set( te[8], te[9], te[10] );
  1336. translation = ( translation instanceof THREE.Vector3 ) ? translation : new THREE.Vector3();
  1337. rotation = ( rotation instanceof THREE.Quaternion ) ? rotation : new THREE.Quaternion();
  1338. scale = ( scale instanceof THREE.Vector3 ) ? scale : new THREE.Vector3();
  1339. scale.x = x.length();
  1340. scale.y = y.length();
  1341. scale.z = z.length();
  1342. translation.x = te[12];
  1343. translation.y = te[13];
  1344. translation.z = te[14];
  1345. // scale the rotation part
  1346. var matrix = THREE.Matrix4.__m1;
  1347. matrix.copy( this );
  1348. matrix.elements[0] /= scale.x;
  1349. matrix.elements[1] /= scale.x;
  1350. matrix.elements[2] /= scale.x;
  1351. matrix.elements[4] /= scale.y;
  1352. matrix.elements[5] /= scale.y;
  1353. matrix.elements[6] /= scale.y;
  1354. matrix.elements[8] /= scale.z;
  1355. matrix.elements[9] /= scale.z;
  1356. matrix.elements[10] /= scale.z;
  1357. rotation.setFromRotationMatrix( matrix );
  1358. return [ translation, rotation, scale ];
  1359. },
  1360. extractPosition: function ( m ) {
  1361. var te = this.elements;
  1362. var me = m.elements;
  1363. te[12] = me[12];
  1364. te[13] = me[13];
  1365. te[14] = me[14];
  1366. return this;
  1367. },
  1368. extractRotation: function ( m ) {
  1369. var te = this.elements;
  1370. var me = m.elements;
  1371. var vector = THREE.Matrix4.__v1;
  1372. var scaleX = 1 / vector.set( me[0], me[1], me[2] ).length();
  1373. var scaleY = 1 / vector.set( me[4], me[5], me[6] ).length();
  1374. var scaleZ = 1 / vector.set( me[8], me[9], me[10] ).length();
  1375. te[0] = me[0] * scaleX;
  1376. te[1] = me[1] * scaleX;
  1377. te[2] = me[2] * scaleX;
  1378. te[4] = me[4] * scaleY;
  1379. te[5] = me[5] * scaleY;
  1380. te[6] = me[6] * scaleY;
  1381. te[8] = me[8] * scaleZ;
  1382. te[9] = me[9] * scaleZ;
  1383. te[10] = me[10] * scaleZ;
  1384. return this;
  1385. },
  1386. //
  1387. translate: function ( v ) {
  1388. var te = this.elements;
  1389. var x = v.x, y = v.y, z = v.z;
  1390. te[12] = te[0] * x + te[4] * y + te[8] * z + te[12];
  1391. te[13] = te[1] * x + te[5] * y + te[9] * z + te[13];
  1392. te[14] = te[2] * x + te[6] * y + te[10] * z + te[14];
  1393. te[15] = te[3] * x + te[7] * y + te[11] * z + te[15];
  1394. return this;
  1395. },
  1396. rotateX: function ( angle ) {
  1397. var te = this.elements;
  1398. var m12 = te[4];
  1399. var m22 = te[5];
  1400. var m32 = te[6];
  1401. var m42 = te[7];
  1402. var m13 = te[8];
  1403. var m23 = te[9];
  1404. var m33 = te[10];
  1405. var m43 = te[11];
  1406. var c = Math.cos( angle );
  1407. var s = Math.sin( angle );
  1408. te[4] = c * m12 + s * m13;
  1409. te[5] = c * m22 + s * m23;
  1410. te[6] = c * m32 + s * m33;
  1411. te[7] = c * m42 + s * m43;
  1412. te[8] = c * m13 - s * m12;
  1413. te[9] = c * m23 - s * m22;
  1414. te[10] = c * m33 - s * m32;
  1415. te[11] = c * m43 - s * m42;
  1416. return this;
  1417. },
  1418. rotateY: function ( angle ) {
  1419. var te = this.elements;
  1420. var m11 = te[0];
  1421. var m21 = te[1];
  1422. var m31 = te[2];
  1423. var m41 = te[3];
  1424. var m13 = te[8];
  1425. var m23 = te[9];
  1426. var m33 = te[10];
  1427. var m43 = te[11];
  1428. var c = Math.cos( angle );
  1429. var s = Math.sin( angle );
  1430. te[0] = c * m11 - s * m13;
  1431. te[1] = c * m21 - s * m23;
  1432. te[2] = c * m31 - s * m33;
  1433. te[3] = c * m41 - s * m43;
  1434. te[8] = c * m13 + s * m11;
  1435. te[9] = c * m23 + s * m21;
  1436. te[10] = c * m33 + s * m31;
  1437. te[11] = c * m43 + s * m41;
  1438. return this;
  1439. },
  1440. rotateZ: function ( angle ) {
  1441. var te = this.elements;
  1442. var m11 = te[0];
  1443. var m21 = te[1];
  1444. var m31 = te[2];
  1445. var m41 = te[3];
  1446. var m12 = te[4];
  1447. var m22 = te[5];
  1448. var m32 = te[6];
  1449. var m42 = te[7];
  1450. var c = Math.cos( angle );
  1451. var s = Math.sin( angle );
  1452. te[0] = c * m11 + s * m12;
  1453. te[1] = c * m21 + s * m22;
  1454. te[2] = c * m31 + s * m32;
  1455. te[3] = c * m41 + s * m42;
  1456. te[4] = c * m12 - s * m11;
  1457. te[5] = c * m22 - s * m21;
  1458. te[6] = c * m32 - s * m31;
  1459. te[7] = c * m42 - s * m41;
  1460. return this;
  1461. },
  1462. rotateByAxis: function ( axis, angle ) {
  1463. var te = this.elements;
  1464. // optimize by checking axis
  1465. if ( axis.x === 1 && axis.y === 0 && axis.z === 0 ) {
  1466. return this.rotateX( angle );
  1467. } else if ( axis.x === 0 && axis.y === 1 && axis.z === 0 ) {
  1468. return this.rotateY( angle );
  1469. } else if ( axis.x === 0 && axis.y === 0 && axis.z === 1 ) {
  1470. return this.rotateZ( angle );
  1471. }
  1472. var x = axis.x, y = axis.y, z = axis.z;
  1473. var n = Math.sqrt(x * x + y * y + z * z);
  1474. x /= n;
  1475. y /= n;
  1476. z /= n;
  1477. var xx = x * x, yy = y * y, zz = z * z;
  1478. var c = Math.cos( angle );
  1479. var s = Math.sin( angle );
  1480. var oneMinusCosine = 1 - c;
  1481. var xy = x * y * oneMinusCosine;
  1482. var xz = x * z * oneMinusCosine;
  1483. var yz = y * z * oneMinusCosine;
  1484. var xs = x * s;
  1485. var ys = y * s;
  1486. var zs = z * s;
  1487. var r11 = xx + (1 - xx) * c;
  1488. var r21 = xy + zs;
  1489. var r31 = xz - ys;
  1490. var r12 = xy - zs;
  1491. var r22 = yy + (1 - yy) * c;
  1492. var r32 = yz + xs;
  1493. var r13 = xz + ys;
  1494. var r23 = yz - xs;
  1495. var r33 = zz + (1 - zz) * c;
  1496. var m11 = te[0], m21 = te[1], m31 = te[2], m41 = te[3];
  1497. var m12 = te[4], m22 = te[5], m32 = te[6], m42 = te[7];
  1498. var m13 = te[8], m23 = te[9], m33 = te[10], m43 = te[11];
  1499. var m14 = te[12], m24 = te[13], m34 = te[14], m44 = te[15];
  1500. te[0] = r11 * m11 + r21 * m12 + r31 * m13;
  1501. te[1] = r11 * m21 + r21 * m22 + r31 * m23;
  1502. te[2] = r11 * m31 + r21 * m32 + r31 * m33;
  1503. te[3] = r11 * m41 + r21 * m42 + r31 * m43;
  1504. te[4] = r12 * m11 + r22 * m12 + r32 * m13;
  1505. te[5] = r12 * m21 + r22 * m22 + r32 * m23;
  1506. te[6] = r12 * m31 + r22 * m32 + r32 * m33;
  1507. te[7] = r12 * m41 + r22 * m42 + r32 * m43;
  1508. te[8] = r13 * m11 + r23 * m12 + r33 * m13;
  1509. te[9] = r13 * m21 + r23 * m22 + r33 * m23;
  1510. te[10] = r13 * m31 + r23 * m32 + r33 * m33;
  1511. te[11] = r13 * m41 + r23 * m42 + r33 * m43;
  1512. return this;
  1513. },
  1514. scale: function ( v ) {
  1515. var te = this.elements;
  1516. var x = v.x, y = v.y, z = v.z;
  1517. te[0] *= x; te[4] *= y; te[8] *= z;
  1518. te[1] *= x; te[5] *= y; te[9] *= z;
  1519. te[2] *= x; te[6] *= y; te[10] *= z;
  1520. te[3] *= x; te[7] *= y; te[11] *= z;
  1521. return this;
  1522. },
  1523. getMaxScaleOnAxis: function () {
  1524. var te = this.elements;
  1525. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  1526. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  1527. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  1528. return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
  1529. },
  1530. //
  1531. makeTranslation: function ( x, y, z ) {
  1532. this.set(
  1533. 1, 0, 0, x,
  1534. 0, 1, 0, y,
  1535. 0, 0, 1, z,
  1536. 0, 0, 0, 1
  1537. );
  1538. return this;
  1539. },
  1540. makeRotationX: function ( theta ) {
  1541. var c = Math.cos( theta ), s = Math.sin( theta );
  1542. this.set(
  1543. 1, 0, 0, 0,
  1544. 0, c, -s, 0,
  1545. 0, s, c, 0,
  1546. 0, 0, 0, 1
  1547. );
  1548. return this;
  1549. },
  1550. makeRotationY: function ( theta ) {
  1551. var c = Math.cos( theta ), s = Math.sin( theta );
  1552. this.set(
  1553. c, 0, s, 0,
  1554. 0, 1, 0, 0,
  1555. -s, 0, c, 0,
  1556. 0, 0, 0, 1
  1557. );
  1558. return this;
  1559. },
  1560. makeRotationZ: function ( theta ) {
  1561. var c = Math.cos( theta ), s = Math.sin( theta );
  1562. this.set(
  1563. c, -s, 0, 0,
  1564. s, c, 0, 0,
  1565. 0, 0, 1, 0,
  1566. 0, 0, 0, 1
  1567. );
  1568. return this;
  1569. },
  1570. makeRotationAxis: function ( axis, angle ) {
  1571. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  1572. var c = Math.cos( angle );
  1573. var s = Math.sin( angle );
  1574. var t = 1 - c;
  1575. var x = axis.x, y = axis.y, z = axis.z;
  1576. var tx = t * x, ty = t * y;
  1577. this.set(
  1578. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  1579. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  1580. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  1581. 0, 0, 0, 1
  1582. );
  1583. return this;
  1584. },
  1585. makeScale: function ( x, y, z ) {
  1586. this.set(
  1587. x, 0, 0, 0,
  1588. 0, y, 0, 0,
  1589. 0, 0, z, 0,
  1590. 0, 0, 0, 1
  1591. );
  1592. return this;
  1593. },
  1594. makeFrustum: function ( left, right, bottom, top, near, far ) {
  1595. var te = this.elements;
  1596. var x = 2 * near / ( right - left );
  1597. var y = 2 * near / ( top - bottom );
  1598. var a = ( right + left ) / ( right - left );
  1599. var b = ( top + bottom ) / ( top - bottom );
  1600. var c = - ( far + near ) / ( far - near );
  1601. var d = - 2 * far * near / ( far - near );
  1602. te[0] = x; te[4] = 0; te[8] = a; te[12] = 0;
  1603. te[1] = 0; te[5] = y; te[9] = b; te[13] = 0;
  1604. te[2] = 0; te[6] = 0; te[10] = c; te[14] = d;
  1605. te[3] = 0; te[7] = 0; te[11] = - 1; te[15] = 0;
  1606. return this;
  1607. },
  1608. makePerspective: function ( fov, aspect, near, far ) {
  1609. var ymax = near * Math.tan( fov * Math.PI / 360 );
  1610. var ymin = - ymax;
  1611. var xmin = ymin * aspect;
  1612. var xmax = ymax * aspect;
  1613. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  1614. },
  1615. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  1616. var te = this.elements;
  1617. var w = right - left;
  1618. var h = top - bottom;
  1619. var p = far - near;
  1620. var x = ( right + left ) / w;
  1621. var y = ( top + bottom ) / h;
  1622. var z = ( far + near ) / p;
  1623. te[0] = 2 / w; te[4] = 0; te[8] = 0; te[12] = -x;
  1624. te[1] = 0; te[5] = 2 / h; te[9] = 0; te[13] = -y;
  1625. te[2] = 0; te[6] = 0; te[10] = -2 / p; te[14] = -z;
  1626. te[3] = 0; te[7] = 0; te[11] = 0; te[15] = 1;
  1627. return this;
  1628. },
  1629. clone: function () {
  1630. var te = this.elements;
  1631. return new THREE.Matrix4(
  1632. te[0], te[4], te[8], te[12],
  1633. te[1], te[5], te[9], te[13],
  1634. te[2], te[6], te[10], te[14],
  1635. te[3], te[7], te[11], te[15]
  1636. );
  1637. }
  1638. };
  1639. THREE.Matrix4.__v1 = new THREE.Vector3();
  1640. THREE.Matrix4.__v2 = new THREE.Vector3();
  1641. THREE.Matrix4.__v3 = new THREE.Vector3();
  1642. THREE.Matrix4.__m1 = new THREE.Matrix4();
  1643. THREE.Matrix4.__m2 = new THREE.Matrix4();
  1644. /**
  1645. * @author mr.doob / http://mrdoob.com/
  1646. * @author mikael emtinger / http://gomo.se/
  1647. * @author alteredq / http://alteredqualia.com/
  1648. */
  1649. THREE.Object3D = function () {
  1650. this.id = THREE.Object3DCount ++;
  1651. this.name = '';
  1652. this.parent = undefined;
  1653. this.children = [];
  1654. this.up = new THREE.Vector3( 0, 1, 0 );
  1655. this.position = new THREE.Vector3();
  1656. this.rotation = new THREE.Vector3();
  1657. this.eulerOrder = 'XYZ';
  1658. this.scale = new THREE.Vector3( 1, 1, 1 );
  1659. this.doubleSided = false;
  1660. this.flipSided = false;
  1661. this.renderDepth = null;
  1662. this.rotationAutoUpdate = true;
  1663. this.matrix = new THREE.Matrix4();
  1664. this.matrixWorld = new THREE.Matrix4();
  1665. this.matrixRotationWorld = new THREE.Matrix4();
  1666. this.matrixAutoUpdate = true;
  1667. this.matrixWorldNeedsUpdate = true;
  1668. this.quaternion = new THREE.Quaternion();
  1669. this.useQuaternion = false;
  1670. this.boundRadius = 0.0;
  1671. this.boundRadiusScale = 1.0;
  1672. this.visible = true;
  1673. this.castShadow = false;
  1674. this.receiveShadow = false;
  1675. this.frustumCulled = true;
  1676. this._vector = new THREE.Vector3();
  1677. };
  1678. THREE.Object3D.prototype = {
  1679. constructor: THREE.Object3D,
  1680. applyMatrix: function ( matrix ) {
  1681. this.matrix.multiply( matrix, this.matrix );
  1682. this.scale.getScaleFromMatrix( this.matrix );
  1683. this.rotation.getRotationFromMatrix( this.matrix, this.scale );
  1684. this.position.getPositionFromMatrix( this.matrix );
  1685. },
  1686. translate: function ( distance, axis ) {
  1687. this.matrix.rotateAxis( axis );
  1688. this.position.addSelf( axis.multiplyScalar( distance ) );
  1689. },
  1690. translateX: function ( distance ) {
  1691. this.translate( distance, this._vector.set( 1, 0, 0 ) );
  1692. },
  1693. translateY: function ( distance ) {
  1694. this.translate( distance, this._vector.set( 0, 1, 0 ) );
  1695. },
  1696. translateZ: function ( distance ) {
  1697. this.translate( distance, this._vector.set( 0, 0, 1 ) );
  1698. },
  1699. lookAt: function ( vector ) {
  1700. // TODO: Add hierarchy support.
  1701. this.matrix.lookAt( vector, this.position, this.up );
  1702. if ( this.rotationAutoUpdate ) {
  1703. this.rotation.getRotationFromMatrix( this.matrix );
  1704. }
  1705. },
  1706. add: function ( object ) {
  1707. if ( object === this ) {
  1708. console.warn( 'THREE.Object3D.add: An object can\'t be added as a child of itself.' );
  1709. return;
  1710. }
  1711. if ( object instanceof THREE.Object3D ) { // && this.children.indexOf( object ) === - 1
  1712. if ( object.parent !== undefined ) {
  1713. object.parent.remove( object );
  1714. }
  1715. object.parent = this;
  1716. this.children.push( object );
  1717. // add to scene
  1718. var scene = this;
  1719. while ( scene.parent !== undefined ) {
  1720. scene = scene.parent;
  1721. }
  1722. if ( scene !== undefined && scene instanceof THREE.Scene ) {
  1723. scene.__addObject( object );
  1724. }
  1725. }
  1726. },
  1727. remove: function ( object ) {
  1728. var index = this.children.indexOf( object );
  1729. if ( index !== - 1 ) {
  1730. object.parent = undefined;
  1731. this.children.splice( index, 1 );
  1732. // remove from scene
  1733. var scene = this;
  1734. while ( scene.parent !== undefined ) {
  1735. scene = scene.parent;
  1736. }
  1737. if ( scene !== undefined && scene instanceof THREE.Scene ) {
  1738. scene.__removeObject( object );
  1739. }
  1740. }
  1741. },
  1742. getChildByName: function ( name, recursive ) {
  1743. var c, cl, child;
  1744. for ( c = 0, cl = this.children.length; c < cl; c ++ ) {
  1745. child = this.children[ c ];
  1746. if ( child.name === name ) {
  1747. return child;
  1748. }
  1749. if ( recursive ) {
  1750. child = child.getChildByName( name, recursive );
  1751. if ( child !== undefined ) {
  1752. return child;
  1753. }
  1754. }
  1755. }
  1756. return undefined;
  1757. },
  1758. updateMatrix: function () {
  1759. this.matrix.setPosition( this.position );
  1760. if ( this.useQuaternion ) {
  1761. this.matrix.setRotationFromQuaternion( this.quaternion );
  1762. } else {
  1763. this.matrix.setRotationFromEuler( this.rotation, this.eulerOrder );
  1764. }
  1765. if ( this.scale.x !== 1 || this.scale.y !== 1 || this.scale.z !== 1 ) {
  1766. this.matrix.scale( this.scale );
  1767. this.boundRadiusScale = Math.max( this.scale.x, Math.max( this.scale.y, this.scale.z ) );
  1768. }
  1769. this.matrixWorldNeedsUpdate = true;
  1770. },
  1771. updateMatrixWorld: function ( force ) {
  1772. this.matrixAutoUpdate && this.updateMatrix();
  1773. // update matrixWorld
  1774. if ( this.matrixWorldNeedsUpdate || force ) {
  1775. if ( this.parent ) {
  1776. this.matrixWorld.multiply( this.parent.matrixWorld, this.matrix );
  1777. } else {
  1778. this.matrixWorld.copy( this.matrix );
  1779. }
  1780. this.matrixWorldNeedsUpdate = false;
  1781. force = true;
  1782. }
  1783. // update children
  1784. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  1785. this.children[ i ].updateMatrixWorld( force );
  1786. }
  1787. }
  1788. };
  1789. THREE.Object3DCount = 0;
  1790. /**
  1791. * @author mr.doob / http://mrdoob.com/
  1792. * @author supereggbert / http://www.paulbrunt.co.uk/
  1793. * @author julianwa / https://github.com/julianwa
  1794. */
  1795. THREE.Projector = function() {
  1796. var _object, _objectCount, _objectPool = [],
  1797. _vertex, _vertexCount, _vertexPool = [],
  1798. _face, _face3Count, _face3Pool = [], _face4Count, _face4Pool = [],
  1799. _line, _lineCount, _linePool = [],
  1800. _particle, _particleCount, _particlePool = [],
  1801. _renderData = { objects: [], sprites: [], lights: [], elements: [] },
  1802. _vector3 = new THREE.Vector3(),
  1803. _vector4 = new THREE.Vector4(),
  1804. _projScreenMatrix = new THREE.Matrix4(),
  1805. _projScreenobjectMatrixWorld = new THREE.Matrix4(),
  1806. _frustum = new THREE.Frustum(),
  1807. _clippedVertex1PositionScreen = new THREE.Vector4(),
  1808. _clippedVertex2PositionScreen = new THREE.Vector4(),
  1809. _face3VertexNormals;
  1810. this.projectVector = function ( vector, camera ) {
  1811. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  1812. _projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );
  1813. _projScreenMatrix.multiplyVector3( vector );
  1814. return vector;
  1815. };
  1816. this.unprojectVector = function ( vector, camera ) {
  1817. camera.projectionMatrixInverse.getInverse( camera.projectionMatrix );
  1818. _projScreenMatrix.multiply( camera.matrixWorld, camera.projectionMatrixInverse );
  1819. _projScreenMatrix.multiplyVector3( vector );
  1820. return vector;
  1821. };
  1822. this.pickingRay = function ( vector, camera ) {
  1823. var end, ray, t;
  1824. // set two vectors with opposing z values
  1825. vector.z = -1.0;
  1826. end = new THREE.Vector3( vector.x, vector.y, 1.0 );
  1827. this.unprojectVector( vector, camera );
  1828. this.unprojectVector( end, camera );
  1829. // find direction from vector to end
  1830. end.subSelf( vector ).normalize();
  1831. return new THREE.Ray( vector, end );
  1832. };
  1833. this.projectGraph = function ( root, sort ) {
  1834. _objectCount = 0;
  1835. _renderData.objects.length = 0;
  1836. _renderData.sprites.length = 0;
  1837. _renderData.lights.length = 0;
  1838. var projectObject = function ( object ) {
  1839. if ( object.visible === false ) return;
  1840. if ( ( object instanceof THREE.Mesh || object instanceof THREE.Line ) &&
  1841. ( object.frustumCulled === false || _frustum.contains( object ) ) ) {
  1842. _vector3.copy( object.matrixWorld.getPosition() );
  1843. _projScreenMatrix.multiplyVector3( _vector3 );
  1844. _object = getNextObjectInPool();
  1845. _object.object = object;
  1846. _object.z = _vector3.z;
  1847. _renderData.objects.push( _object );
  1848. } else if ( object instanceof THREE.Sprite || object instanceof THREE.Particle ) {
  1849. _vector3.copy( object.matrixWorld.getPosition() );
  1850. _projScreenMatrix.multiplyVector3( _vector3 );
  1851. _object = getNextObjectInPool();
  1852. _object.object = object;
  1853. _object.z = _vector3.z;
  1854. _renderData.sprites.push( _object );
  1855. } else if ( object instanceof THREE.Light ) {
  1856. _renderData.lights.push( object );
  1857. }
  1858. for ( var c = 0, cl = object.children.length; c < cl; c ++ ) {
  1859. projectObject( object.children[ c ] );
  1860. }
  1861. };
  1862. projectObject( root );
  1863. sort && _renderData.objects.sort( painterSort );
  1864. return _renderData;
  1865. };
  1866. this.projectScene = function ( scene, camera, sort ) {
  1867. var near = camera.near, far = camera.far, visible = false,
  1868. o, ol, v, vl, f, fl, n, nl, c, cl, u, ul, object,
  1869. objectMatrixWorld, objectMatrixWorldRotation,
  1870. geometry, geometryMaterials, vertices, vertex, vertexPositionScreen,
  1871. faces, face, faceVertexNormals, normal, faceVertexUvs, uvs,
  1872. v1, v2, v3, v4;
  1873. _face3Count = 0;
  1874. _face4Count = 0;
  1875. _lineCount = 0;
  1876. _particleCount = 0;
  1877. _renderData.elements.length = 0;
  1878. if ( camera.parent === undefined ) {
  1879. console.warn( 'DEPRECATED: Camera hasn\'t been added to a Scene. Adding it...' );
  1880. scene.add( camera );
  1881. }
  1882. scene.updateMatrixWorld();
  1883. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  1884. _projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );
  1885. _frustum.setFromMatrix( _projScreenMatrix );
  1886. _renderData = this.projectGraph( scene, false );
  1887. for ( o = 0, ol = _renderData.objects.length; o < ol; o++ ) {
  1888. object = _renderData.objects[ o ].object;
  1889. objectMatrixWorld = object.matrixWorld;
  1890. _vertexCount = 0;
  1891. if ( object instanceof THREE.Mesh ) {
  1892. geometry = object.geometry;
  1893. geometryMaterials = object.geometry.materials;
  1894. vertices = geometry.vertices;
  1895. faces = geometry.faces;
  1896. faceVertexUvs = geometry.faceVertexUvs;
  1897. objectMatrixWorldRotation = object.matrixRotationWorld.extractRotation( objectMatrixWorld );
  1898. for ( v = 0, vl = vertices.length; v < vl; v ++ ) {
  1899. _vertex = getNextVertexInPool();
  1900. _vertex.positionWorld.copy( vertices[ v ] );
  1901. objectMatrixWorld.multiplyVector3( _vertex.positionWorld );
  1902. _vertex.positionScreen.copy( _vertex.positionWorld );
  1903. _projScreenMatrix.multiplyVector4( _vertex.positionScreen );
  1904. _vertex.positionScreen.x /= _vertex.positionScreen.w;
  1905. _vertex.positionScreen.y /= _vertex.positionScreen.w;
  1906. _vertex.visible = _vertex.positionScreen.z > near && _vertex.positionScreen.z < far;
  1907. }
  1908. for ( f = 0, fl = faces.length; f < fl; f ++ ) {
  1909. face = faces[ f ];
  1910. if ( face instanceof THREE.Face3 ) {
  1911. v1 = _vertexPool[ face.a ];
  1912. v2 = _vertexPool[ face.b ];
  1913. v3 = _vertexPool[ face.c ];
  1914. if ( v1.visible && v2.visible && v3.visible ) {
  1915. visible = ( ( v3.positionScreen.x - v1.positionScreen.x ) * ( v2.positionScreen.y - v1.positionScreen.y ) -
  1916. ( v3.positionScreen.y - v1.positionScreen.y ) * ( v2.positionScreen.x - v1.positionScreen.x ) ) < 0;
  1917. if ( object.doubleSided || visible != object.flipSided ) {
  1918. _face = getNextFace3InPool();
  1919. _face.v1.copy( v1 );
  1920. _face.v2.copy( v2 );
  1921. _face.v3.copy( v3 );
  1922. } else {
  1923. continue;
  1924. }
  1925. } else {
  1926. continue;
  1927. }
  1928. } else if ( face instanceof THREE.Face4 ) {
  1929. v1 = _vertexPool[ face.a ];
  1930. v2 = _vertexPool[ face.b ];
  1931. v3 = _vertexPool[ face.c ];
  1932. v4 = _vertexPool[ face.d ];
  1933. if ( v1.visible && v2.visible && v3.visible && v4.visible ) {
  1934. visible = ( v4.positionScreen.x - v1.positionScreen.x ) * ( v2.positionScreen.y - v1.positionScreen.y ) -
  1935. ( v4.positionScreen.y - v1.positionScreen.y ) * ( v2.positionScreen.x - v1.positionScreen.x ) < 0 ||
  1936. ( v2.positionScreen.x - v3.positionScreen.x ) * ( v4.positionScreen.y - v3.positionScreen.y ) -
  1937. ( v2.positionScreen.y - v3.positionScreen.y ) * ( v4.positionScreen.x - v3.positionScreen.x ) < 0;
  1938. if ( object.doubleSided || visible != object.flipSided ) {
  1939. _face = getNextFace4InPool();
  1940. _face.v1.copy( v1 );
  1941. _face.v2.copy( v2 );
  1942. _face.v3.copy( v3 );
  1943. _face.v4.copy( v4 );
  1944. } else {
  1945. continue;
  1946. }
  1947. } else {
  1948. continue;
  1949. }
  1950. }
  1951. _face.normalWorld.copy( face.normal );
  1952. if ( !visible && ( object.flipSided || object.doubleSided ) ) _face.normalWorld.negate();
  1953. objectMatrixWorldRotation.multiplyVector3( _face.normalWorld );
  1954. _face.centroidWorld.copy( face.centroid );
  1955. objectMatrixWorld.multiplyVector3( _face.centroidWorld );
  1956. _face.centroidScreen.copy( _face.centroidWorld );
  1957. _projScreenMatrix.multiplyVector3( _face.centroidScreen );
  1958. faceVertexNormals = face.vertexNormals;
  1959. for ( n = 0, nl = faceVertexNormals.length; n < nl; n ++ ) {
  1960. normal = _face.vertexNormalsWorld[ n ];
  1961. normal.copy( faceVertexNormals[ n ] );
  1962. if ( !visible && ( object.flipSided || object.doubleSided ) ) normal.negate();
  1963. objectMatrixWorldRotation.multiplyVector3( normal );
  1964. }
  1965. for ( c = 0, cl = faceVertexUvs.length; c < cl; c ++ ) {
  1966. uvs = faceVertexUvs[ c ][ f ];
  1967. if ( !uvs ) continue;
  1968. for ( u = 0, ul = uvs.length; u < ul; u ++ ) {
  1969. _face.uvs[ c ][ u ] = uvs[ u ];
  1970. }
  1971. }
  1972. _face.material = object.material;
  1973. _face.faceMaterial = face.materialIndex !== null ? geometryMaterials[ face.materialIndex ] : null;
  1974. _face.z = _face.centroidScreen.z;
  1975. _renderData.elements.push( _face );
  1976. }
  1977. } else if ( object instanceof THREE.Line ) {
  1978. _projScreenobjectMatrixWorld.multiply( _projScreenMatrix, objectMatrixWorld );
  1979. vertices = object.geometry.vertices;
  1980. v1 = getNextVertexInPool();
  1981. v1.positionScreen.copy( vertices[ 0 ] );
  1982. _projScreenobjectMatrixWorld.multiplyVector4( v1.positionScreen );
  1983. // Handle LineStrip and LinePieces
  1984. var step = object.type === THREE.LinePieces ? 2 : 1;
  1985. for ( v = 1, vl = vertices.length; v < vl; v ++ ) {
  1986. v1 = getNextVertexInPool();
  1987. v1.positionScreen.copy( vertices[ v ] );
  1988. _projScreenobjectMatrixWorld.multiplyVector4( v1.positionScreen );
  1989. if ( ( v + 1 ) % step > 0 ) continue;
  1990. v2 = _vertexPool[ _vertexCount - 2 ];
  1991. _clippedVertex1PositionScreen.copy( v1.positionScreen );
  1992. _clippedVertex2PositionScreen.copy( v2.positionScreen );
  1993. if ( clipLine( _clippedVertex1PositionScreen, _clippedVertex2PositionScreen ) ) {
  1994. // Perform the perspective divide
  1995. _clippedVertex1PositionScreen.multiplyScalar( 1 / _clippedVertex1PositionScreen.w );
  1996. _clippedVertex2PositionScreen.multiplyScalar( 1 / _clippedVertex2PositionScreen.w );
  1997. _line = getNextLineInPool();
  1998. _line.v1.positionScreen.copy( _clippedVertex1PositionScreen );
  1999. _line.v2.positionScreen.copy( _clippedVertex2PositionScreen );
  2000. _line.z = Math.max( _clippedVertex1PositionScreen.z, _clippedVertex2PositionScreen.z );
  2001. _line.material = object.material;
  2002. _renderData.elements.push( _line );
  2003. }
  2004. }
  2005. }
  2006. }
  2007. for ( o = 0, ol = _renderData.sprites.length; o < ol; o++ ) {
  2008. object = _renderData.sprites[ o ].object;
  2009. objectMatrixWorld = object.matrixWorld;
  2010. if ( object instanceof THREE.Particle ) {
  2011. _vector4.set( objectMatrixWorld.elements[12], objectMatrixWorld.elements[13], objectMatrixWorld.elements[14], 1 );
  2012. _projScreenMatrix.multiplyVector4( _vector4 );
  2013. _vector4.z /= _vector4.w;
  2014. if ( _vector4.z > 0 && _vector4.z < 1 ) {
  2015. _particle = getNextParticleInPool();
  2016. _particle.x = _vector4.x / _vector4.w;
  2017. _particle.y = _vector4.y / _vector4.w;
  2018. _particle.z = _vector4.z;
  2019. _particle.rotation = object.rotation.z;
  2020. _particle.scale.x = object.scale.x * Math.abs( _particle.x - ( _vector4.x + camera.projectionMatrix.elements[0] ) / ( _vector4.w + camera.projectionMatrix.elements[12] ) );
  2021. _particle.scale.y = object.scale.y * Math.abs( _particle.y - ( _vector4.y + camera.projectionMatrix.elements[5] ) / ( _vector4.w + camera.projectionMatrix.elements[13] ) );
  2022. _particle.material = object.material;
  2023. _renderData.elements.push( _particle );
  2024. }
  2025. }
  2026. }
  2027. sort && _renderData.elements.sort( painterSort );
  2028. return _renderData;
  2029. };
  2030. // Pools
  2031. function getNextObjectInPool() {
  2032. var object = _objectPool[ _objectCount ] = _objectPool[ _objectCount ] || new THREE.RenderableObject();
  2033. _objectCount ++;
  2034. return object;
  2035. }
  2036. function getNextVertexInPool() {
  2037. var vertex = _vertexPool[ _vertexCount ] = _vertexPool[ _vertexCount ] || new THREE.RenderableVertex();
  2038. _vertexCount ++;
  2039. return vertex;
  2040. }
  2041. function getNextFace3InPool() {
  2042. var face = _face3Pool[ _face3Count ] = _face3Pool[ _face3Count ] || new THREE.RenderableFace3();
  2043. _face3Count ++;
  2044. return face;
  2045. }
  2046. function getNextFace4InPool() {
  2047. var face = _face4Pool[ _face4Count ] = _face4Pool[ _face4Count ] || new THREE.RenderableFace4();
  2048. _face4Count ++;
  2049. return face;
  2050. }
  2051. function getNextLineInPool() {
  2052. var line = _linePool[ _lineCount ] = _linePool[ _lineCount ] || new THREE.RenderableLine();
  2053. _lineCount ++;
  2054. return line;
  2055. }
  2056. function getNextParticleInPool() {
  2057. var particle = _particlePool[ _particleCount ] = _particlePool[ _particleCount ] || new THREE.RenderableParticle();
  2058. _particleCount ++;
  2059. return particle;
  2060. }
  2061. //
  2062. function painterSort( a, b ) {
  2063. return b.z - a.z;
  2064. }
  2065. function clipLine( s1, s2 ) {
  2066. var alpha1 = 0, alpha2 = 1,
  2067. // Calculate the boundary coordinate of each vertex for the near and far clip planes,
  2068. // Z = -1 and Z = +1, respectively.
  2069. bc1near = s1.z + s1.w,
  2070. bc2near = s2.z + s2.w,
  2071. bc1far = - s1.z + s1.w,
  2072. bc2far = - s2.z + s2.w;
  2073. if ( bc1near >= 0 && bc2near >= 0 && bc1far >= 0 && bc2far >= 0 ) {
  2074. // Both vertices lie entirely within all clip planes.
  2075. return true;
  2076. } else if ( ( bc1near < 0 && bc2near < 0) || (bc1far < 0 && bc2far < 0 ) ) {
  2077. // Both vertices lie entirely outside one of the clip planes.
  2078. return false;
  2079. } else {
  2080. // The line segment spans at least one clip plane.
  2081. if ( bc1near < 0 ) {
  2082. // v1 lies outside the near plane, v2 inside
  2083. alpha1 = Math.max( alpha1, bc1near / ( bc1near - bc2near ) );
  2084. } else if ( bc2near < 0 ) {
  2085. // v2 lies outside the near plane, v1 inside
  2086. alpha2 = Math.min( alpha2, bc1near / ( bc1near - bc2near ) );
  2087. }
  2088. if ( bc1far < 0 ) {
  2089. // v1 lies outside the far plane, v2 inside
  2090. alpha1 = Math.max( alpha1, bc1far / ( bc1far - bc2far ) );
  2091. } else if ( bc2far < 0 ) {
  2092. // v2 lies outside the far plane, v2 inside
  2093. alpha2 = Math.min( alpha2, bc1far / ( bc1far - bc2far ) );
  2094. }
  2095. if ( alpha2 < alpha1 ) {
  2096. // The line segment spans two boundaries, but is outside both of them.
  2097. // (This can't happen when we're only clipping against just near/far but good
  2098. // to leave the check here for future usage if other clip planes are added.)
  2099. return false;
  2100. } else {
  2101. // Update the s1 and s2 vertices to match the clipped line segment.
  2102. s1.lerpSelf( s2, alpha1 );
  2103. s2.lerpSelf( s1, 1 - alpha2 );
  2104. return true;
  2105. }
  2106. }
  2107. }
  2108. };
  2109. /**
  2110. * @author mikael emtinger / http://gomo.se/
  2111. * @author alteredq / http://alteredqualia.com/
  2112. */
  2113. THREE.Quaternion = function( x, y, z, w ) {
  2114. this.x = x || 0;
  2115. this.y = y || 0;
  2116. this.z = z || 0;
  2117. this.w = ( w !== undefined ) ? w : 1;
  2118. };
  2119. THREE.Quaternion.prototype = {
  2120. constructor: THREE.Quaternion,
  2121. set: function ( x, y, z, w ) {
  2122. this.x = x;
  2123. this.y = y;
  2124. this.z = z;
  2125. this.w = w;
  2126. return this;
  2127. },
  2128. copy: function ( q ) {
  2129. this.x = q.x;
  2130. this.y = q.y;
  2131. this.z = q.z;
  2132. this.w = q.w;
  2133. return this;
  2134. },
  2135. setFromEuler: function ( vector ) {
  2136. var c = Math.PI / 360, // 0.5 * Math.PI / 360, // 0.5 is an optimization
  2137. x = vector.x * c,
  2138. y = vector.y * c,
  2139. z = vector.z * c,
  2140. c1 = Math.cos( y ),
  2141. s1 = Math.sin( y ),
  2142. c2 = Math.cos( -z ),
  2143. s2 = Math.sin( -z ),
  2144. c3 = Math.cos( x ),
  2145. s3 = Math.sin( x ),
  2146. c1c2 = c1 * c2,
  2147. s1s2 = s1 * s2;
  2148. this.w = c1c2 * c3 - s1s2 * s3;
  2149. this.x = c1c2 * s3 + s1s2 * c3;
  2150. this.y = s1 * c2 * c3 + c1 * s2 * s3;
  2151. this.z = c1 * s2 * c3 - s1 * c2 * s3;
  2152. return this;
  2153. },
  2154. setFromAxisAngle: function ( axis, angle ) {
  2155. // from http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2156. // axis have to be normalized
  2157. var halfAngle = angle / 2,
  2158. s = Math.sin( halfAngle );
  2159. this.x = axis.x * s;
  2160. this.y = axis.y * s;
  2161. this.z = axis.z * s;
  2162. this.w = Math.cos( halfAngle );
  2163. return this;
  2164. },
  2165. setFromRotationMatrix: function ( m ) {
  2166. // Adapted from: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2167. function copySign( a, b ) {
  2168. return b < 0 ? -Math.abs( a ) : Math.abs( a );
  2169. }
  2170. var absQ = Math.pow( m.determinant(), 1.0 / 3.0 );
  2171. this.w = Math.sqrt( Math.max( 0, absQ + m.elements[0] + m.elements[5] + m.elements[10] ) ) / 2;
  2172. this.x = Math.sqrt( Math.max( 0, absQ + m.elements[0] - m.elements[5] - m.elements[10] ) ) / 2;
  2173. this.y = Math.sqrt( Math.max( 0, absQ - m.elements[0] + m.elements[5] - m.elements[10] ) ) / 2;
  2174. this.z = Math.sqrt( Math.max( 0, absQ - m.elements[0] - m.elements[5] + m.elements[10] ) ) / 2;
  2175. this.x = copySign( this.x, ( m.elements[6] - m.elements[9] ) );
  2176. this.y = copySign( this.y, ( m.elements[8] - m.elements[2] ) );
  2177. this.z = copySign( this.z, ( m.elements[1] - m.elements[4] ) );
  2178. this.normalize();
  2179. return this;
  2180. },
  2181. calculateW : function () {
  2182. this.w = - Math.sqrt( Math.abs( 1.0 - this.x * this.x - this.y * this.y - this.z * this.z ) );
  2183. return this;
  2184. },
  2185. inverse: function () {
  2186. this.x *= -1;
  2187. this.y *= -1;
  2188. this.z *= -1;
  2189. return this;
  2190. },
  2191. length: function () {
  2192. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2193. },
  2194. normalize: function () {
  2195. var l = Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2196. if ( l === 0 ) {
  2197. this.x = 0;
  2198. this.y = 0;
  2199. this.z = 0;
  2200. this.w = 0;
  2201. } else {
  2202. l = 1 / l;
  2203. this.x = this.x * l;
  2204. this.y = this.y * l;
  2205. this.z = this.z * l;
  2206. this.w = this.w * l;
  2207. }
  2208. return this;
  2209. },
  2210. multiply: function ( a, b ) {
  2211. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2212. this.x = a.x * b.w + a.y * b.z - a.z * b.y + a.w * b.x;
  2213. this.y = -a.x * b.z + a.y * b.w + a.z * b.x + a.w * b.y;
  2214. this.z = a.x * b.y - a.y * b.x + a.z * b.w + a.w * b.z;
  2215. this.w = -a.x * b.x - a.y * b.y - a.z * b.z + a.w * b.w;
  2216. return this;
  2217. },
  2218. multiplySelf: function ( b ) {
  2219. var qax = this.x, qay = this.y, qaz = this.z, qaw = this.w,
  2220. qbx = b.x, qby = b.y, qbz = b.z, qbw = b.w;
  2221. this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2222. this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2223. this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2224. this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2225. return this;
  2226. },
  2227. multiplyVector3: function ( vector, dest ) {
  2228. if ( !dest ) { dest = vector; }
  2229. var x = vector.x, y = vector.y, z = vector.z,
  2230. qx = this.x, qy = this.y, qz = this.z, qw = this.w;
  2231. // calculate quat * vector
  2232. var ix = qw * x + qy * z - qz * y,
  2233. iy = qw * y + qz * x - qx * z,
  2234. iz = qw * z + qx * y - qy * x,
  2235. iw = -qx * x - qy * y - qz * z;
  2236. // calculate result * inverse quat
  2237. dest.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  2238. dest.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  2239. dest.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  2240. return dest;
  2241. },
  2242. clone: function () {
  2243. return new THREE.Quaternion( this.x, this.y, this.z, this.w );
  2244. }
  2245. }
  2246. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  2247. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2248. var cosHalfTheta = qa.w * qb.w + qa.x * qb.x + qa.y * qb.y + qa.z * qb.z;
  2249. if (cosHalfTheta < 0) {
  2250. qm.w = -qb.w; qm.x = -qb.x; qm.y = -qb.y; qm.z = -qb.z;
  2251. cosHalfTheta = -cosHalfTheta;
  2252. } else {
  2253. qm.copy(qb);
  2254. }
  2255. if ( Math.abs( cosHalfTheta ) >= 1.0 ) {
  2256. qm.w = qa.w; qm.x = qa.x; qm.y = qa.y; qm.z = qa.z;
  2257. return qm;
  2258. }
  2259. var halfTheta = Math.acos( cosHalfTheta ),
  2260. sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  2261. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  2262. qm.w = 0.5 * ( qa.w + qb.w );
  2263. qm.x = 0.5 * ( qa.x + qb.x );
  2264. qm.y = 0.5 * ( qa.y + qb.y );
  2265. qm.z = 0.5 * ( qa.z + qb.z );
  2266. return qm;
  2267. }
  2268. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  2269. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  2270. qm.w = ( qa.w * ratioA + qm.w * ratioB );
  2271. qm.x = ( qa.x * ratioA + qm.x * ratioB );
  2272. qm.y = ( qa.y * ratioA + qm.y * ratioB );
  2273. qm.z = ( qa.z * ratioA + qm.z * ratioB );
  2274. return qm;
  2275. }
  2276. /**
  2277. * @author mr.doob / http://mrdoob.com/
  2278. */
  2279. THREE.Vertex = function () {
  2280. console.warn( 'THREE.Vertex has been DEPRECATED. Use THREE.Vector3 instead.')
  2281. };
  2282. /**
  2283. * @author mr.doob / http://mrdoob.com/
  2284. * @author alteredq / http://alteredqualia.com/
  2285. */
  2286. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  2287. this.a = a;
  2288. this.b = b;
  2289. this.c = c;
  2290. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  2291. this.vertexNormals = normal instanceof Array ? normal : [ ];
  2292. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  2293. this.vertexColors = color instanceof Array ? color : [];
  2294. this.vertexTangents = [];
  2295. this.materialIndex = materialIndex;
  2296. this.centroid = new THREE.Vector3();
  2297. };
  2298. THREE.Face3.prototype = {
  2299. constructor: THREE.Face3,
  2300. clone: function () {
  2301. var face = new THREE.Face3( this.a, this.b, this.c );
  2302. face.normal.copy( this.normal );
  2303. face.color.copy( this.color );
  2304. face.centroid.copy( this.centroid );
  2305. face.materialIndex = this.materialIndex;
  2306. var i, il;
  2307. for ( i = 0, il = this.vertexNormals.length; i < il; i ++ ) face.vertexNormals[ i ] = this.vertexNormals[ i ].clone();
  2308. for ( i = 0, il = this.vertexColors.length; i < il; i ++ ) face.vertexColors[ i ] = this.vertexColors[ i ].clone();
  2309. for ( i = 0, il = this.vertexTangents.length; i < il; i ++ ) face.vertexTangents[ i ] = this.vertexTangents[ i ].clone();
  2310. return face;
  2311. }
  2312. };
  2313. /**
  2314. * @author mr.doob / http://mrdoob.com/
  2315. * @author alteredq / http://alteredqualia.com/
  2316. */
  2317. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  2318. this.a = a;
  2319. this.b = b;
  2320. this.c = c;
  2321. this.d = d;
  2322. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  2323. this.vertexNormals = normal instanceof Array ? normal : [ ];
  2324. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  2325. this.vertexColors = color instanceof Array ? color : [];
  2326. this.vertexTangents = [];
  2327. this.materialIndex = materialIndex;
  2328. this.centroid = new THREE.Vector3();
  2329. };
  2330. THREE.Face4.prototype = {
  2331. constructor: THREE.Face4,
  2332. clone: function () {
  2333. var face = new THREE.Face4( this.a, this.b, this.c, this.d );
  2334. face.normal.copy( this.normal );
  2335. face.color.copy( this.color );
  2336. face.centroid.copy( this.centroid );
  2337. face.materialIndex = this.materialIndex;
  2338. var i, il;
  2339. for ( i = 0, il = this.vertexNormals.length; i < il; i ++ ) face.vertexNormals[ i ] = this.vertexNormals[ i ].clone();
  2340. for ( i = 0, il = this.vertexColors.length; i < il; i ++ ) face.vertexColors[ i ] = this.vertexColors[ i ].clone();
  2341. for ( i = 0, il = this.vertexTangents.length; i < il; i ++ ) face.vertexTangents[ i ] = this.vertexTangents[ i ].clone();
  2342. return face;
  2343. }
  2344. };
  2345. /**
  2346. * @author mr.doob / http://mrdoob.com/
  2347. */
  2348. THREE.UV = function ( u, v ) {
  2349. this.u = u || 0;
  2350. this.v = v || 0;
  2351. };
  2352. THREE.UV.prototype = {
  2353. constructor: THREE.UV,
  2354. set: function ( u, v ) {
  2355. this.u = u;
  2356. this.v = v;
  2357. return this;
  2358. },
  2359. copy: function ( uv ) {
  2360. this.u = uv.u;
  2361. this.v = uv.v;
  2362. return this;
  2363. },
  2364. lerpSelf: function ( uv, alpha ) {
  2365. this.u += ( uv.u - this.u ) * alpha;
  2366. this.v += ( uv.v - this.v ) * alpha;
  2367. return this;
  2368. },
  2369. clone: function () {
  2370. return new THREE.UV( this.u, this.v );
  2371. }
  2372. };
  2373. /**
  2374. * @author mr.doob / http://mrdoob.com/
  2375. * @author mikael emtinger / http://gomo.se/
  2376. */
  2377. THREE.Camera = function () {
  2378. THREE.Object3D.call( this );
  2379. this.matrixWorldInverse = new THREE.Matrix4();
  2380. this.projectionMatrix = new THREE.Matrix4();
  2381. this.projectionMatrixInverse = new THREE.Matrix4();
  2382. };
  2383. THREE.Camera.prototype = new THREE.Object3D();
  2384. THREE.Camera.prototype.constructor = THREE.Camera;
  2385. THREE.Camera.prototype.lookAt = function ( vector ) {
  2386. // TODO: Add hierarchy support.
  2387. this.matrix.lookAt( this.position, vector, this.up );
  2388. if ( this.rotationAutoUpdate ) {
  2389. this.rotation.getRotationFromMatrix( this.matrix );
  2390. }
  2391. };
  2392. /**
  2393. * @author alteredq / http://alteredqualia.com/
  2394. */
  2395. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  2396. THREE.Camera.call( this );
  2397. this.left = left;
  2398. this.right = right;
  2399. this.top = top;
  2400. this.bottom = bottom;
  2401. this.near = ( near !== undefined ) ? near : 0.1;
  2402. this.far = ( far !== undefined ) ? far : 2000;
  2403. this.updateProjectionMatrix();
  2404. };
  2405. THREE.OrthographicCamera.prototype = new THREE.Camera();
  2406. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  2407. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  2408. this.projectionMatrix.makeOrthographic( this.left, this.right, this.top, this.bottom, this.near, this.far );
  2409. };
  2410. /**
  2411. * @author mr.doob / http://mrdoob.com/
  2412. * @author greggman / http://games.greggman.com/
  2413. * @author zz85 / http://www.lab4games.net/zz85/blog
  2414. */
  2415. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  2416. THREE.Camera.call( this );
  2417. this.fov = fov !== undefined ? fov : 50;
  2418. this.aspect = aspect !== undefined ? aspect : 1;
  2419. this.near = near !== undefined ? near : 0.1;
  2420. this.far = far !== undefined ? far : 2000;
  2421. this.updateProjectionMatrix();
  2422. };
  2423. THREE.PerspectiveCamera.prototype = new THREE.Camera();
  2424. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  2425. /**
  2426. * Uses Focal Length (in mm) to estimate and set FOV
  2427. * 35mm (fullframe) camera is used if frame size is not specified;
  2428. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  2429. */
  2430. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  2431. frameHeight = frameHeight !== undefined ? frameHeight : 24;
  2432. this.fov = 2 * Math.atan( frameHeight / ( focalLength * 2 ) ) * ( 180 / Math.PI );
  2433. this.updateProjectionMatrix();
  2434. }
  2435. /**
  2436. * Sets an offset in a larger frustum. This is useful for multi-window or
  2437. * multi-monitor/multi-machine setups.
  2438. *
  2439. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  2440. * the monitors are in grid like this
  2441. *
  2442. * +---+---+---+
  2443. * | A | B | C |
  2444. * +---+---+---+
  2445. * | D | E | F |
  2446. * +---+---+---+
  2447. *
  2448. * then for each monitor you would call it like this
  2449. *
  2450. * var w = 1920;
  2451. * var h = 1080;
  2452. * var fullWidth = w * 3;
  2453. * var fullHeight = h * 2;
  2454. *
  2455. * --A--
  2456. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  2457. * --B--
  2458. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  2459. * --C--
  2460. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  2461. * --D--
  2462. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  2463. * --E--
  2464. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  2465. * --F--
  2466. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  2467. *
  2468. * Note there is no reason monitors have to be the same size or in a grid.
  2469. */
  2470. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  2471. this.fullWidth = fullWidth;
  2472. this.fullHeight = fullHeight;
  2473. this.x = x;
  2474. this.y = y;
  2475. this.width = width;
  2476. this.height = height;
  2477. this.updateProjectionMatrix();
  2478. };
  2479. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  2480. if ( this.fullWidth ) {
  2481. var aspect = this.fullWidth / this.fullHeight;
  2482. var top = Math.tan( this.fov * Math.PI / 360 ) * this.near;
  2483. var bottom = -top;
  2484. var left = aspect * bottom;
  2485. var right = aspect * top;
  2486. var width = Math.abs( right - left );
  2487. var height = Math.abs( top - bottom );
  2488. this.projectionMatrix.makeFrustum(
  2489. left + this.x * width / this.fullWidth,
  2490. left + ( this.x + this.width ) * width / this.fullWidth,
  2491. top - ( this.y + this.height ) * height / this.fullHeight,
  2492. top - this.y * height / this.fullHeight,
  2493. this.near,
  2494. this.far
  2495. );
  2496. } else {
  2497. this.projectionMatrix.makePerspective( this.fov, this.aspect, this.near, this.far );
  2498. }
  2499. };
  2500. /**
  2501. * @author mr.doob / http://mrdoob.com/
  2502. * @author alteredq / http://alteredqualia.com/
  2503. */
  2504. THREE.Light = function ( hex ) {
  2505. THREE.Object3D.call( this );
  2506. this.color = new THREE.Color( hex );
  2507. };
  2508. THREE.Light.prototype = new THREE.Object3D();
  2509. THREE.Light.prototype.constructor = THREE.Light;
  2510. THREE.Light.prototype.supr = THREE.Object3D.prototype;
  2511. /**
  2512. * @author mr.doob / http://mrdoob.com/
  2513. * @author alteredq / http://alteredqualia.com/
  2514. */
  2515. THREE.Material = function ( parameters ) {
  2516. parameters = parameters || {};
  2517. this.id = THREE.MaterialCount ++;
  2518. this.name = '';
  2519. this.opacity = parameters.opacity !== undefined ? parameters.opacity : 1;
  2520. this.transparent = parameters.transparent !== undefined ? parameters.transparent : false;
  2521. this.blending = parameters.blending !== undefined ? parameters.blending : THREE.NormalBlending;
  2522. this.blendSrc = parameters.blendSrc !== undefined ? parameters.blendSrc : THREE.SrcAlphaFactor;
  2523. this.blendDst = parameters.blendDst !== undefined ? parameters.blendDst : THREE.OneMinusSrcAlphaFactor;
  2524. this.blendEquation = parameters.blendEquation !== undefined ? parameters.blendEquation : THREE.AddEquation;
  2525. this.depthTest = parameters.depthTest !== undefined ? parameters.depthTest : true;
  2526. this.depthWrite = parameters.depthWrite !== undefined ? parameters.depthWrite : true;
  2527. this.polygonOffset = parameters.polygonOffset !== undefined ? parameters.polygonOffset : false;
  2528. this.polygonOffsetFactor = parameters.polygonOffsetFactor !== undefined ? parameters.polygonOffsetFactor : 0;
  2529. this.polygonOffsetUnits = parameters.polygonOffsetUnits !== undefined ? parameters.polygonOffsetUnits : 0;
  2530. this.alphaTest = parameters.alphaTest !== undefined ? parameters.alphaTest : 0;
  2531. this.overdraw = parameters.overdraw !== undefined ? parameters.overdraw : false; // Boolean for fixing antialiasing gaps in CanvasRenderer
  2532. this.needsUpdate = true;
  2533. }
  2534. THREE.MaterialCount = 0;
  2535. // shading
  2536. THREE.NoShading = 0;
  2537. THREE.FlatShading = 1;
  2538. THREE.SmoothShading = 2;
  2539. // colors
  2540. THREE.NoColors = 0;
  2541. THREE.FaceColors = 1;
  2542. THREE.VertexColors = 2;
  2543. // blending modes
  2544. THREE.NoBlending = 0;
  2545. THREE.NormalBlending = 1;
  2546. THREE.AdditiveBlending = 2;
  2547. THREE.SubtractiveBlending = 3;
  2548. THREE.MultiplyBlending = 4;
  2549. THREE.AdditiveAlphaBlending = 5;
  2550. THREE.CustomBlending = 6;
  2551. // custom blending equations
  2552. // (numbers start from 100 not to clash with other
  2553. // mappings to OpenGL constants defined in Texture.js)
  2554. THREE.AddEquation = 100;
  2555. THREE.SubtractEquation = 101;
  2556. THREE.ReverseSubtractEquation = 102;
  2557. // custom blending destination factors
  2558. THREE.ZeroFactor = 200;
  2559. THREE.OneFactor = 201;
  2560. THREE.SrcColorFactor = 202;
  2561. THREE.OneMinusSrcColorFactor = 203;
  2562. THREE.SrcAlphaFactor = 204;
  2563. THREE.OneMinusSrcAlphaFactor = 205;
  2564. THREE.DstAlphaFactor = 206;
  2565. THREE.OneMinusDstAlphaFactor = 207;
  2566. // custom blending source factors
  2567. //THREE.ZeroFactor = 200;
  2568. //THREE.OneFactor = 201;
  2569. //THREE.SrcAlphaFactor = 204;
  2570. //THREE.OneMinusSrcAlphaFactor = 205;
  2571. //THREE.DstAlphaFactor = 206;
  2572. //THREE.OneMinusDstAlphaFactor = 207;
  2573. THREE.DstColorFactor = 208;
  2574. THREE.OneMinusDstColorFactor = 209;
  2575. THREE.SrcAlphaSaturateFactor = 210;
  2576. /**
  2577. * @author mr.doob / http://mrdoob.com/
  2578. * @author alteredq / http://alteredqualia.com/
  2579. *
  2580. * parameters = {
  2581. * color: <hex>,
  2582. * opacity: <float>,
  2583. *
  2584. * blending: THREE.NormalBlending,
  2585. * depthTest: <bool>,
  2586. *
  2587. * linewidth: <float>,
  2588. * linecap: "round",
  2589. * linejoin: "round",
  2590. *
  2591. * vertexColors: <bool>
  2592. *
  2593. * fog: <bool>
  2594. * }
  2595. */
  2596. THREE.LineBasicMaterial = function ( parameters ) {
  2597. THREE.Material.call( this, parameters );
  2598. parameters = parameters || {};
  2599. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  2600. this.linewidth = parameters.linewidth !== undefined ? parameters.linewidth : 1;
  2601. this.linecap = parameters.linecap !== undefined ? parameters.linecap : 'round';
  2602. this.linejoin = parameters.linejoin !== undefined ? parameters.linejoin : 'round';
  2603. this.vertexColors = parameters.vertexColors ? parameters.vertexColors : false;
  2604. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  2605. };
  2606. THREE.LineBasicMaterial.prototype = new THREE.Material();
  2607. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  2608. /**
  2609. * @author mr.doob / http://mrdoob.com/
  2610. * @author alteredq / http://alteredqualia.com/
  2611. *
  2612. * parameters = {
  2613. * color: <hex>,
  2614. * opacity: <float>,
  2615. * map: new THREE.Texture( <Image> ),
  2616. *
  2617. * lightMap: new THREE.Texture( <Image> ),
  2618. *
  2619. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  2620. * combine: THREE.Multiply,
  2621. * reflectivity: <float>,
  2622. * refractionRatio: <float>,
  2623. *
  2624. * shading: THREE.SmoothShading,
  2625. * blending: THREE.NormalBlending,
  2626. * depthTest: <bool>,
  2627. *
  2628. * wireframe: <boolean>,
  2629. * wireframeLinewidth: <float>,
  2630. *
  2631. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  2632. *
  2633. * skinning: <bool>,
  2634. * morphTargets: <bool>,
  2635. *
  2636. * fog: <bool>
  2637. * }
  2638. */
  2639. THREE.MeshBasicMaterial = function ( parameters ) {
  2640. THREE.Material.call( this, parameters );
  2641. parameters = parameters || {};
  2642. // color property represents emissive for MeshBasicMaterial
  2643. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  2644. this.map = parameters.map !== undefined ? parameters.map : null;
  2645. this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null;
  2646. this.envMap = parameters.envMap !== undefined ? parameters.envMap : null;
  2647. this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation;
  2648. this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1;
  2649. this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98;
  2650. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  2651. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
  2652. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  2653. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  2654. this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round';
  2655. this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round';
  2656. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors;
  2657. this.skinning = parameters.skinning !== undefined ? parameters.skinning : false;
  2658. this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false;
  2659. };
  2660. THREE.MeshBasicMaterial.prototype = new THREE.Material();
  2661. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  2662. /**
  2663. * @author mr.doob / http://mrdoob.com/
  2664. * @author alteredq / http://alteredqualia.com/
  2665. *
  2666. * parameters = {
  2667. * color: <hex>,
  2668. * opacity: <float>,
  2669. * map: new THREE.Texture( <Image> ),
  2670. *
  2671. * size: <float>,
  2672. *
  2673. * blending: THREE.NormalBlending,
  2674. * depthTest: <bool>,
  2675. *
  2676. * vertexColors: <bool>,
  2677. *
  2678. * fog: <bool>
  2679. * }
  2680. */
  2681. THREE.ParticleBasicMaterial = function ( parameters ) {
  2682. THREE.Material.call( this, parameters );
  2683. parameters = parameters || {};
  2684. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  2685. this.map = parameters.map !== undefined ? parameters.map : null;
  2686. this.size = parameters.size !== undefined ? parameters.size : 1;
  2687. this.sizeAttenuation = parameters.sizeAttenuation !== undefined ? parameters.sizeAttenuation : true;
  2688. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : false;
  2689. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  2690. };
  2691. THREE.ParticleBasicMaterial.prototype = new THREE.Material();
  2692. THREE.ParticleBasicMaterial.prototype.constructor = THREE.ParticleBasicMaterial;
  2693. /**
  2694. * @author mr.doob / http://mrdoob.com/
  2695. */
  2696. THREE.ParticleDOMMaterial = function ( domElement ) {
  2697. THREE.Material.call( this );
  2698. this.domElement = domElement;
  2699. };
  2700. /**
  2701. * @author mr.doob / http://mrdoob.com/
  2702. * @author alteredq / http://alteredqualia.com/
  2703. * @author szimek / https://github.com/szimek/
  2704. */
  2705. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type ) {
  2706. this.id = THREE.TextureCount ++;
  2707. this.image = image;
  2708. this.mapping = mapping !== undefined ? mapping : new THREE.UVMapping();
  2709. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  2710. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  2711. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  2712. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  2713. this.format = format !== undefined ? format : THREE.RGBAFormat;
  2714. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  2715. this.offset = new THREE.Vector2( 0, 0 );
  2716. this.repeat = new THREE.Vector2( 1, 1 );
  2717. this.generateMipmaps = true;
  2718. this.premultiplyAlpha = false;
  2719. this.needsUpdate = false;
  2720. this.onUpdate = null;
  2721. };
  2722. THREE.Texture.prototype = {
  2723. constructor: THREE.Texture,
  2724. clone: function () {
  2725. var clonedTexture = new THREE.Texture( this.image, this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter, this.format, this.type );
  2726. clonedTexture.offset.copy( this.offset );
  2727. clonedTexture.repeat.copy( this.repeat );
  2728. return clonedTexture;
  2729. }
  2730. };
  2731. THREE.TextureCount = 0;
  2732. THREE.MultiplyOperation = 0;
  2733. THREE.MixOperation = 1;
  2734. // Mapping modes
  2735. THREE.UVMapping = function () {};
  2736. THREE.CubeReflectionMapping = function () {};
  2737. THREE.CubeRefractionMapping = function () {};
  2738. THREE.SphericalReflectionMapping = function () {};
  2739. THREE.SphericalRefractionMapping = function () {};
  2740. // Wrapping modes
  2741. THREE.RepeatWrapping = 0;
  2742. THREE.ClampToEdgeWrapping = 1;
  2743. THREE.MirroredRepeatWrapping = 2;
  2744. // Filters
  2745. THREE.NearestFilter = 3;
  2746. THREE.NearestMipMapNearestFilter = 4;
  2747. THREE.NearestMipMapLinearFilter = 5;
  2748. THREE.LinearFilter = 6;
  2749. THREE.LinearMipMapNearestFilter = 7;
  2750. THREE.LinearMipMapLinearFilter = 8;
  2751. // Types
  2752. THREE.ByteType = 9;
  2753. THREE.UnsignedByteType = 10;
  2754. THREE.ShortType = 11;
  2755. THREE.UnsignedShortType = 12;
  2756. THREE.IntType = 13;
  2757. THREE.UnsignedIntType = 14;
  2758. THREE.FloatType = 15;
  2759. // Formats
  2760. THREE.AlphaFormat = 16;
  2761. THREE.RGBFormat = 17;
  2762. THREE.RGBAFormat = 18;
  2763. THREE.LuminanceFormat = 19;
  2764. THREE.LuminanceAlphaFormat = 20;
  2765. /**
  2766. * @author alteredq / http://alteredqualia.com/
  2767. */
  2768. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter ) {
  2769. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type );
  2770. this.image = { data: data, width: width, height: height };
  2771. };
  2772. THREE.DataTexture.prototype = new THREE.Texture();
  2773. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  2774. THREE.DataTexture.prototype.clone = function () {
  2775. var clonedTexture = new THREE.DataTexture( this.image.data, this.image.width, this.image.height, this.format, this.type, this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter );
  2776. clonedTexture.offset.copy( this.offset );
  2777. clonedTexture.repeat.copy( this.repeat );
  2778. return clonedTexture;
  2779. };
  2780. /**
  2781. * @author mr.doob / http://mrdoob.com/
  2782. */
  2783. THREE.Particle = function ( material ) {
  2784. THREE.Object3D.call( this );
  2785. this.material = material;
  2786. };
  2787. THREE.Particle.prototype = new THREE.Object3D();
  2788. THREE.Particle.prototype.constructor = THREE.Particle;
  2789. /**
  2790. * @author mr.doob / http://mrdoob.com/
  2791. * @author alteredq / http://alteredqualia.com/
  2792. * @author mikael emtinger / http://gomo.se/
  2793. */
  2794. THREE.Mesh = function ( geometry, material ) {
  2795. THREE.Object3D.call( this );
  2796. this.geometry = geometry;
  2797. this.material = ( material !== undefined ) ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, wireframe: true } );
  2798. if ( this.geometry ) {
  2799. // calc bound radius
  2800. if( ! this.geometry.boundingSphere ) {
  2801. this.geometry.computeBoundingSphere();
  2802. }
  2803. this.boundRadius = geometry.boundingSphere.radius;
  2804. // setup morph targets
  2805. if( this.geometry.morphTargets.length ) {
  2806. this.morphTargetBase = -1;
  2807. this.morphTargetForcedOrder = [];
  2808. this.morphTargetInfluences = [];
  2809. this.morphTargetDictionary = {};
  2810. for( var m = 0; m < this.geometry.morphTargets.length; m ++ ) {
  2811. this.morphTargetInfluences.push( 0 );
  2812. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  2813. }
  2814. }
  2815. }
  2816. }
  2817. THREE.Mesh.prototype = new THREE.Object3D();
  2818. THREE.Mesh.prototype.constructor = THREE.Mesh;
  2819. THREE.Mesh.prototype.supr = THREE.Object3D.prototype;
  2820. /*
  2821. * Get Morph Target Index by Name
  2822. */
  2823. THREE.Mesh.prototype.getMorphTargetIndexByName = function( name ) {
  2824. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  2825. return this.morphTargetDictionary[ name ];
  2826. }
  2827. console.log( "THREE.Mesh.getMorphTargetIndexByName: morph target " + name + " does not exist. Returning 0." );
  2828. return 0;
  2829. }
  2830. /**
  2831. * @author mr.doob / http://mrdoob.com/
  2832. */
  2833. THREE.Line = function ( geometry, material, type ) {
  2834. THREE.Object3D.call( this );
  2835. this.geometry = geometry;
  2836. this.material = ( material !== undefined ) ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  2837. this.type = ( type !== undefined ) ? type : THREE.LineStrip;
  2838. if ( this.geometry ) {
  2839. if ( ! this.geometry.boundingSphere ) {
  2840. this.geometry.computeBoundingSphere();
  2841. }
  2842. }
  2843. };
  2844. THREE.LineStrip = 0;
  2845. THREE.LinePieces = 1;
  2846. THREE.Line.prototype = new THREE.Object3D();
  2847. THREE.Line.prototype.constructor = THREE.Line;
  2848. /**
  2849. * @author mikael emtinger / http://gomo.se/
  2850. * @author alteredq / http://alteredqualia.com/
  2851. */
  2852. THREE.Bone = function( belongsToSkin ) {
  2853. THREE.Object3D.call( this );
  2854. this.skin = belongsToSkin;
  2855. this.skinMatrix = new THREE.Matrix4();
  2856. };
  2857. THREE.Bone.prototype = new THREE.Object3D();
  2858. THREE.Bone.prototype.constructor = THREE.Bone;
  2859. THREE.Bone.prototype.supr = THREE.Object3D.prototype;
  2860. THREE.Bone.prototype.update = function( parentSkinMatrix, forceUpdate ) {
  2861. // update local
  2862. if ( this.matrixAutoUpdate ) {
  2863. forceUpdate |= this.updateMatrix();
  2864. }
  2865. // update skin matrix
  2866. if ( forceUpdate || this.matrixWorldNeedsUpdate ) {
  2867. if( parentSkinMatrix ) {
  2868. this.skinMatrix.multiply( parentSkinMatrix, this.matrix );
  2869. } else {
  2870. this.skinMatrix.copy( this.matrix );
  2871. }
  2872. this.matrixWorldNeedsUpdate = false;
  2873. forceUpdate = true;
  2874. }
  2875. // update children
  2876. var child, i, l = this.children.length;
  2877. for ( i = 0; i < l; i ++ ) {
  2878. this.children[ i ].update( this.skinMatrix, forceUpdate );
  2879. }
  2880. };
  2881. /**
  2882. * @author mikael emtinger / http://gomo.se/
  2883. */
  2884. THREE.Sprite = function ( parameters ) {
  2885. THREE.Object3D.call( this );
  2886. this.color = ( parameters.color !== undefined ) ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  2887. this.map = ( parameters.map !== undefined ) ? parameters.map : new THREE.Texture();
  2888. this.blending = ( parameters.blending !== undefined ) ? parameters.blending : THREE.NormalBlending;
  2889. this.blendSrc = parameters.blendSrc !== undefined ? parameters.blendSrc : THREE.SrcAlphaFactor;
  2890. this.blendDst = parameters.blendDst !== undefined ? parameters.blendDst : THREE.OneMinusSrcAlphaFactor;
  2891. this.blendEquation = parameters.blendEquation !== undefined ? parameters.blendEquation : THREE.AddEquation;
  2892. this.useScreenCoordinates = ( parameters.useScreenCoordinates !== undefined ) ? parameters.useScreenCoordinates : true;
  2893. this.mergeWith3D = ( parameters.mergeWith3D !== undefined ) ? parameters.mergeWith3D : !this.useScreenCoordinates;
  2894. this.affectedByDistance = ( parameters.affectedByDistance !== undefined ) ? parameters.affectedByDistance : !this.useScreenCoordinates;
  2895. this.scaleByViewport = ( parameters.scaleByViewport !== undefined ) ? parameters.scaleByViewport : !this.affectedByDistance;
  2896. this.alignment = ( parameters.alignment instanceof THREE.Vector2 ) ? parameters.alignment : THREE.SpriteAlignment.center;
  2897. this.rotation3d = this.rotation;
  2898. this.rotation = 0;
  2899. this.opacity = 1;
  2900. this.uvOffset = new THREE.Vector2( 0, 0 );
  2901. this.uvScale = new THREE.Vector2( 1, 1 );
  2902. };
  2903. THREE.Sprite.prototype = new THREE.Object3D();
  2904. THREE.Sprite.prototype.constructor = THREE.Sprite;
  2905. /*
  2906. * Custom update matrix
  2907. */
  2908. THREE.Sprite.prototype.updateMatrix = function () {
  2909. this.matrix.setPosition( this.position );
  2910. this.rotation3d.set( 0, 0, this.rotation );
  2911. this.matrix.setRotationFromEuler( this.rotation3d );
  2912. if ( this.scale.x !== 1 || this.scale.y !== 1 ) {
  2913. this.matrix.scale( this.scale );
  2914. this.boundRadiusScale = Math.max( this.scale.x, this.scale.y );
  2915. }
  2916. this.matrixWorldNeedsUpdate = true;
  2917. };
  2918. /*
  2919. * Alignment
  2920. */
  2921. THREE.SpriteAlignment = {};
  2922. THREE.SpriteAlignment.topLeft = new THREE.Vector2( 1, -1 );
  2923. THREE.SpriteAlignment.topCenter = new THREE.Vector2( 0, -1 );
  2924. THREE.SpriteAlignment.topRight = new THREE.Vector2( -1, -1 );
  2925. THREE.SpriteAlignment.centerLeft = new THREE.Vector2( 1, 0 );
  2926. THREE.SpriteAlignment.center = new THREE.Vector2( 0, 0 );
  2927. THREE.SpriteAlignment.centerRight = new THREE.Vector2( -1, 0 );
  2928. THREE.SpriteAlignment.bottomLeft = new THREE.Vector2( 1, 1 );
  2929. THREE.SpriteAlignment.bottomCenter = new THREE.Vector2( 0, 1 );
  2930. THREE.SpriteAlignment.bottomRight = new THREE.Vector2( -1, 1 );
  2931. /**
  2932. * @author mr.doob / http://mrdoob.com/
  2933. */
  2934. THREE.Scene = function () {
  2935. THREE.Object3D.call( this );
  2936. this.fog = null;
  2937. this.overrideMaterial = null;
  2938. this.matrixAutoUpdate = false;
  2939. this.__objects = [];
  2940. this.__lights = [];
  2941. this.__objectsAdded = [];
  2942. this.__objectsRemoved = [];
  2943. };
  2944. THREE.Scene.prototype = new THREE.Object3D();
  2945. THREE.Scene.prototype.constructor = THREE.Scene;
  2946. THREE.Scene.prototype.__addObject = function ( object ) {
  2947. if ( object instanceof THREE.Light ) {
  2948. if ( this.__lights.indexOf( object ) === - 1 ) {
  2949. this.__lights.push( object );
  2950. }
  2951. } else if ( !( object instanceof THREE.Camera || object instanceof THREE.Bone ) ) {
  2952. if ( this.__objects.indexOf( object ) === - 1 ) {
  2953. this.__objects.push( object );
  2954. this.__objectsAdded.push( object );
  2955. // check if previously removed
  2956. var i = this.__objectsRemoved.indexOf( object );
  2957. if ( i !== -1 ) {
  2958. this.__objectsRemoved.splice( i, 1 );
  2959. }
  2960. }
  2961. }
  2962. for ( var c = 0; c < object.children.length; c ++ ) {
  2963. this.__addObject( object.children[ c ] );
  2964. }
  2965. };
  2966. THREE.Scene.prototype.__removeObject = function ( object ) {
  2967. if ( object instanceof THREE.Light ) {
  2968. var i = this.__lights.indexOf( object );
  2969. if ( i !== -1 ) {
  2970. this.__lights.splice( i, 1 );
  2971. }
  2972. } else if ( !( object instanceof THREE.Camera ) ) {
  2973. var i = this.__objects.indexOf( object );
  2974. if( i !== -1 ) {
  2975. this.__objects.splice( i, 1 );
  2976. this.__objectsRemoved.push( object );
  2977. // check if previously added
  2978. var ai = this.__objectsAdded.indexOf( object );
  2979. if ( ai !== -1 ) {
  2980. this.__objectsAdded.splice( ai, 1 );
  2981. }
  2982. }
  2983. }
  2984. for ( var c = 0; c < object.children.length; c ++ ) {
  2985. this.__removeObject( object.children[ c ] );
  2986. }
  2987. };
  2988. /**
  2989. * @author mr.doob / http://mrdoob.com/
  2990. */
  2991. THREE.DOMRenderer = function () {
  2992. console.log( 'THREE.DOMRenderer', THREE.REVISION );
  2993. var _renderData, _elements,
  2994. _width, _height, _widthHalf, _heightHalf, _transformProp,
  2995. _projector = new THREE.Projector();
  2996. var getSupportedProp = function ( proparray ) {
  2997. var root = document.documentElement
  2998. for ( var i = 0; i < proparray.length; i ++ ) {
  2999. if ( typeof root.style[ proparray[ i ] ] === "string" ) {
  3000. return proparray[i];
  3001. }
  3002. }
  3003. return null;
  3004. };
  3005. _transformProp = getSupportedProp( [ 'transform', 'MozTransform', 'WebkitTransform', 'msTransform', 'OTransform' ] );
  3006. this.domElement = document.createElement( 'div' );
  3007. this.setSize = function ( width, height ) {
  3008. _width = width;
  3009. _height = height;
  3010. _widthHalf = _width / 2;
  3011. _heightHalf = _height / 2;
  3012. };
  3013. this.render = function ( scene, camera ) {
  3014. var e, el, m, ml, element, material, dom, v1x, v1y;
  3015. _renderData = _projector.projectScene( scene, camera );
  3016. _elements = _renderData.elements;
  3017. for ( e = 0, el = _elements.length; e < el; e ++ ) {
  3018. element = _elements[ e ];
  3019. if ( element instanceof THREE.RenderableParticle && element.material instanceof THREE.ParticleDOMMaterial ) {
  3020. dom = element.material.domElement;
  3021. v1x = element.x * _widthHalf + _widthHalf - ( dom.offsetWidth >> 1 );
  3022. v1y = element.y * _heightHalf + _heightHalf - ( dom.offsetHeight >> 1 );
  3023. dom.style.left = v1x + 'px';
  3024. dom.style.top = v1y + 'px';
  3025. dom.style.zIndex = Math.abs( Math.floor( ( 1 - element.z ) * camera.far / camera.near ) )
  3026. if ( _transformProp ) {
  3027. var scaleX = element.scale.x * _widthHalf;
  3028. var scaleY = element.scale.y * _heightHalf;
  3029. var scaleVal = "scale(" + scaleX + "," + scaleY + ")";
  3030. dom.style[ _transformProp ] = scaleVal;
  3031. }
  3032. }
  3033. }
  3034. };
  3035. };
  3036. /**
  3037. * @author mr.doob / http://mrdoob.com/
  3038. */
  3039. THREE.RenderableParticle = function () {
  3040. this.x = null;
  3041. this.y = null;
  3042. this.z = null;
  3043. this.rotation = null;
  3044. this.scale = new THREE.Vector2();
  3045. this.material = null;
  3046. };
  3047. /**
  3048. * @author mr.doob / http://mrdoob.com/
  3049. */
  3050. THREE.RenderableVertex = function () {
  3051. this.positionWorld = new THREE.Vector3();
  3052. this.positionScreen = new THREE.Vector4();
  3053. this.visible = true;
  3054. };
  3055. THREE.RenderableVertex.prototype.copy = function ( vertex ) {
  3056. this.positionWorld.copy( vertex.positionWorld );
  3057. this.positionScreen.copy( vertex.positionScreen );
  3058. }
  3059. /**
  3060. * @author mr.doob / http://mrdoob.com/
  3061. */
  3062. THREE.RenderableFace3 = function () {
  3063. this.v1 = new THREE.RenderableVertex();
  3064. this.v2 = new THREE.RenderableVertex();
  3065. this.v3 = new THREE.RenderableVertex();
  3066. this.centroidWorld = new THREE.Vector3();
  3067. this.centroidScreen = new THREE.Vector3();
  3068. this.normalWorld = new THREE.Vector3();
  3069. this.vertexNormalsWorld = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  3070. this.material = null;
  3071. this.faceMaterial = null;
  3072. this.uvs = [[]];
  3073. this.z = null;
  3074. };
  3075. /**
  3076. * @author mr.doob / http://mrdoob.com/
  3077. */
  3078. THREE.RenderableFace4 = function () {
  3079. this.v1 = new THREE.RenderableVertex();
  3080. this.v2 = new THREE.RenderableVertex();
  3081. this.v3 = new THREE.RenderableVertex();
  3082. this.v4 = new THREE.RenderableVertex();
  3083. this.centroidWorld = new THREE.Vector3();
  3084. this.centroidScreen = new THREE.Vector3();
  3085. this.normalWorld = new THREE.Vector3();
  3086. this.vertexNormalsWorld = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  3087. this.material = null;
  3088. this.faceMaterial = null;
  3089. this.uvs = [[]];
  3090. this.z = null;
  3091. };
  3092. /**
  3093. * @author mr.doob / http://mrdoob.com/
  3094. */
  3095. THREE.RenderableObject = function () {
  3096. this.object = null;
  3097. this.z = null;
  3098. };
  3099. /**
  3100. * @author mr.doob / http://mrdoob.com/
  3101. */
  3102. THREE.RenderableParticle = function () {
  3103. this.x = null;
  3104. this.y = null;
  3105. this.z = null;
  3106. this.rotation = null;
  3107. this.scale = new THREE.Vector2();
  3108. this.material = null;
  3109. };
  3110. /**
  3111. * @author mr.doob / http://mrdoob.com/
  3112. */
  3113. THREE.RenderableLine = function () {
  3114. this.z = null;
  3115. this.v1 = new THREE.RenderableVertex();
  3116. this.v2 = new THREE.RenderableVertex();
  3117. this.material = null;
  3118. };
  3119. =======
  3120. // ThreeDOM.js - http://github.com/mrdoob/three.js
  3121. 'use strict';var THREE=THREE||{REVISION:"49dev"};self.Int32Array||(self.Int32Array=Array,self.Float32Array=Array);
  3122. (function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;c<b.length&&!window.requestAnimationFrame;++c){window.requestAnimationFrame=window[b[c]+"RequestAnimationFrame"];window.cancelAnimationFrame=window[b[c]+"CancelAnimationFrame"]||window[b[c]+"CancelRequestAnimationFrame"]}if(!window.requestAnimationFrame)window.requestAnimationFrame=function(b){var c=Date.now(),f=Math.max(0,16-(c-a)),g=window.setTimeout(function(){b(c+f)},f);a=c+f;return g};if(!window.cancelAnimationFrame)window.cancelAnimationFrame=
  3123. function(a){clearTimeout(a)}})();THREE.Color=function(a){a!==void 0&&this.setHex(a);return this};
  3124. THREE.Color.prototype={constructor:THREE.Color,r:1,g:1,b:1,copy:function(a){this.r=a.r;this.g=a.g;this.b=a.b;return this},copyGammaToLinear:function(a){this.r=a.r*a.r;this.g=a.g*a.g;this.b=a.b*a.b;return this},copyLinearToGamma:function(a){this.r=Math.sqrt(a.r);this.g=Math.sqrt(a.g);this.b=Math.sqrt(a.b);return this},convertGammaToLinear:function(){var a=this.r,b=this.g,c=this.b;this.r=a*a;this.g=b*b;this.b=c*c;return this},convertLinearToGamma:function(){this.r=Math.sqrt(this.r);this.g=Math.sqrt(this.g);
  3125. this.b=Math.sqrt(this.b);return this},setRGB:function(a,b,c){this.r=a;this.g=b;this.b=c;return this},setHSV:function(a,b,c){var d,e,f;if(c===0)this.r=this.g=this.b=0;else{d=Math.floor(a*6);e=a*6-d;a=c*(1-b);f=c*(1-b*e);b=c*(1-b*(1-e));switch(d){case 1:this.r=f;this.g=c;this.b=a;break;case 2:this.r=a;this.g=c;this.b=b;break;case 3:this.r=a;this.g=f;this.b=c;break;case 4:this.r=b;this.g=a;this.b=c;break;case 5:this.r=c;this.g=a;this.b=f;break;case 6:case 0:this.r=c;this.g=b;this.b=a}}return this},setHex:function(a){a=
  3126. Math.floor(a);this.r=(a>>16&255)/255;this.g=(a>>8&255)/255;this.b=(a&255)/255;return this},lerpSelf:function(a,b){this.r=this.r+(a.r-this.r)*b;this.g=this.g+(a.g-this.g)*b;this.b=this.b+(a.b-this.b)*b;return this},getHex:function(){return Math.floor(this.r*255)<<16^Math.floor(this.g*255)<<8^Math.floor(this.b*255)},getContextStyle:function(){return"rgb("+Math.floor(this.r*255)+","+Math.floor(this.g*255)+","+Math.floor(this.b*255)+")"},clone:function(){return(new THREE.Color).setRGB(this.r,this.g,this.b)}};
  3127. THREE.Vector2=function(a,b){this.x=a||0;this.y=b||0};
  3128. THREE.Vector2.prototype={constructor:THREE.Vector2,set:function(a,b){this.x=a;this.y=b;return this},copy:function(a){this.x=a.x;this.y=a.y;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},addSelf:function(a){this.x=this.x+a.x;this.y=this.y+a.y;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this},subSelf:function(a){this.x=this.x-a.x;this.y=this.y-a.y;return this},multiplyScalar:function(a){this.x=this.x*a;this.y=this.y*a;return this},divideScalar:function(a){if(a){this.x=
  3129. this.x/a;this.y=this.y/a}else this.set(0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,a=this.y-a.y;return b*b+a*a},setLength:function(a){return this.normalize().multiplyScalar(a)},
  3130. lerpSelf:function(a,b){this.x=this.x+(a.x-this.x)*b;this.y=this.y+(a.y-this.y)*b;return this},equals:function(a){return a.x===this.x&&a.y===this.y},isZero:function(){return this.lengthSq()<1.0E-4},clone:function(){return new THREE.Vector2(this.x,this.y)}};THREE.Vector3=function(a,b,c){this.x=a||0;this.y=b||0;this.z=c||0};
  3131. THREE.Vector3.prototype={constructor:THREE.Vector3,set:function(a,b,c){this.x=a;this.y=b;this.z=c;return this},setX:function(a){this.x=a;return this},setY:function(a){this.y=a;return this},setZ:function(a){this.z=a;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},addSelf:function(a){this.x=this.x+a.x;this.y=this.y+a.y;this.z=this.z+a.z;return this},addScalar:function(a){this.x=this.x+a;this.y=this.y+
  3132. a;this.z=this.z+a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x=this.x-a.x;this.y=this.y-a.y;this.z=this.z-a.z;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x=this.x*a.x;this.y=this.y*a.y;this.z=this.z*a.z;return this},multiplyScalar:function(a){this.x=this.x*a;this.y=this.y*a;this.z=this.z*a;return this},divideSelf:function(a){this.x=this.x/a.x;this.y=
  3133. this.y/a.y;this.z=this.z/a.z;return this},divideScalar:function(a){if(a){this.x=this.x/a;this.y=this.y/a;this.z=this.z/a}else this.z=this.y=this.x=0;return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},normalize:function(){return this.divideScalar(this.length())},
  3134. setLength:function(a){return this.normalize().multiplyScalar(a)},lerpSelf:function(a,b){this.x=this.x+(a.x-this.x)*b;this.y=this.y+(a.y-this.y)*b;this.z=this.z+(a.z-this.z)*b;return this},cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,c=this.y,d=this.z;this.x=c*a.z-d*a.y;this.y=d*a.x-b*a.z;this.z=b*a.y-c*a.x;return this},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){return(new THREE.Vector3).sub(this,
  3135. a).lengthSq()},getPositionFromMatrix:function(a){this.x=a.elements[12];this.y=a.elements[13];this.z=a.elements[14];return this},getRotationFromMatrix:function(a,b){var c=b?b.x:1,d=b?b.y:1,e=b?b.z:1,f=a.elements[0]/c,g=a.elements[4]/d,c=a.elements[1]/c,d=a.elements[5]/d,i=a.elements[9]/e,k=a.elements[10]/e;this.y=Math.asin(a.elements[8]/e);e=Math.cos(this.y);if(Math.abs(e)>1.0E-5){this.x=Math.atan2(-i/e,k/e);this.z=Math.atan2(-g/e,f/e)}else{this.x=0;this.z=Math.atan2(c,d)}return this},getScaleFromMatrix:function(a){var b=
  3136. this.set(a.elements[0],a.elements[1],a.elements[2]).length(),c=this.set(a.elements[4],a.elements[5],a.elements[6]).length(),a=this.set(a.elements[8],a.elements[9],a.elements[10]).length();this.x=b;this.y=c;this.z=a},equals:function(a){return a.x===this.x&&a.y===this.y&&a.z===this.z},isZero:function(){return this.lengthSq()<1.0E-4},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)}};THREE.Vector4=function(a,b,c,d){this.x=a||0;this.y=b||0;this.z=c||0;this.w=d!==void 0?d:1};
  3137. THREE.Vector4.prototype={constructor:THREE.Vector4,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w!==void 0?a.w:1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x=this.x+a.x;this.y=this.y+a.y;this.z=this.z+a.z;this.w=this.w+a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x=
  3138. this.x-a.x;this.y=this.y-a.y;this.z=this.z-a.z;this.w=this.w-a.w;return this},multiplyScalar:function(a){this.x=this.x*a;this.y=this.y*a;this.z=this.z*a;this.w=this.w*a;return this},divideScalar:function(a){if(a){this.x=this.x/a;this.y=this.y/a;this.z=this.z/a;this.w=this.w/a}else{this.z=this.y=this.x=0;this.w=1}return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z+this.w*a.w},lengthSq:function(){return this.dot(this)},length:function(){return Math.sqrt(this.lengthSq())},
  3139. normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},lerpSelf:function(a,b){this.x=this.x+(a.x-this.x)*b;this.y=this.y+(a.y-this.y)*b;this.z=this.z+(a.z-this.z)*b;this.w=this.w+(a.w-this.w)*b;return this},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)}};THREE.Frustum=function(){this.planes=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4]};
  3140. THREE.Frustum.prototype.setFromMatrix=function(a){var b,c=this.planes,d=a.elements,a=d[0];b=d[1];var e=d[2],f=d[3],g=d[4],i=d[5],k=d[6],j=d[7],h=d[8],m=d[9],l=d[10],n=d[11],p=d[12],o=d[13],q=d[14],d=d[15];c[0].set(f-a,j-g,n-h,d-p);c[1].set(f+a,j+g,n+h,d+p);c[2].set(f+b,j+i,n+m,d+o);c[3].set(f-b,j-i,n-m,d-o);c[4].set(f-e,j-k,n-l,d-q);c[5].set(f+e,j+k,n+l,d+q);for(a=0;a<6;a++){b=c[a];b.divideScalar(Math.sqrt(b.x*b.x+b.y*b.y+b.z*b.z))}};
  3141. THREE.Frustum.prototype.contains=function(a){for(var b=this.planes,c=a.matrixWorld,d=c.elements,c=-a.geometry.boundingSphere.radius*c.getMaxScaleOnAxis(),e=0;e<6;e++){a=b[e].x*d[12]+b[e].y*d[13]+b[e].z*d[14]+b[e].w;if(a<=c)return false}return true};THREE.Frustum.__v1=new THREE.Vector3;
  3142. THREE.Ray=function(a,b){function c(a,b,c){p.sub(c,a);r=p.dot(b);x=o.add(a,q.copy(b).multiplyScalar(r));return D=c.distanceTo(x)}function d(a,b,c,d){p.sub(d,b);o.sub(c,b);q.sub(a,b);E=p.dot(p);s=p.dot(o);y=p.dot(q);t=o.dot(o);z=o.dot(q);H=1/(E*t-s*s);K=(t*y-s*z)*H;F=(E*z-s*y)*H;return K>=0&&F>=0&&K+F<1}this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3;var e=1.0E-4;this.setPrecision=function(a){e=a};var f=new THREE.Vector3,g=new THREE.Vector3,i=new THREE.Vector3,k=new THREE.Vector3,
  3143. j=new THREE.Vector3,h=new THREE.Vector3,m=new THREE.Vector3,l=new THREE.Vector3,n=new THREE.Vector3;this.intersectObject=function(a){var b,p=[];if(a instanceof THREE.Particle){var o=c(this.origin,this.direction,a.matrixWorld.getPosition());if(o>a.scale.x)return[];b={distance:o,point:a.position,face:null,object:a};p.push(b)}else if(a instanceof THREE.Mesh){var o=c(this.origin,this.direction,a.matrixWorld.getPosition()),q=THREE.Frustum.__v1.set(a.matrixWorld.getColumnX().length(),a.matrixWorld.getColumnY().length(),
  3144. a.matrixWorld.getColumnZ().length());if(o>a.geometry.boundingSphere.radius*Math.max(q.x,Math.max(q.y,q.z)))return p;var r,s,t=a.geometry,B=t.vertices,v;a.matrixRotationWorld.extractRotation(a.matrixWorld);o=0;for(q=t.faces.length;o<q;o++){b=t.faces[o];j.copy(this.origin);h.copy(this.direction);v=a.matrixWorld;m=v.multiplyVector3(m.copy(b.centroid)).subSelf(j);l=a.matrixRotationWorld.multiplyVector3(l.copy(b.normal));r=h.dot(l);if(!(Math.abs(r)<e)){s=l.dot(m)/r;if(!(s<0)&&(a.doubleSided||(a.flipSided?
  3145. r>0:r<0))){n.add(j,h.multiplyScalar(s));if(b instanceof THREE.Face3){f=v.multiplyVector3(f.copy(B[b.a]));g=v.multiplyVector3(g.copy(B[b.b]));i=v.multiplyVector3(i.copy(B[b.c]));if(d(n,f,g,i)){b={distance:j.distanceTo(n),point:n.clone(),face:b,object:a};p.push(b)}}else if(b instanceof THREE.Face4){f=v.multiplyVector3(f.copy(B[b.a]));g=v.multiplyVector3(g.copy(B[b.b]));i=v.multiplyVector3(i.copy(B[b.c]));k=v.multiplyVector3(k.copy(B[b.d]));if(d(n,f,g,k)||d(n,g,i,k)){b={distance:j.distanceTo(n),point:n.clone(),
  3146. face:b,object:a};p.push(b)}}}}}}return p};this.intersectObjects=function(a){for(var b=[],c=0,d=a.length;c<d;c++)Array.prototype.push.apply(b,this.intersectObject(a[c]));b.sort(function(a,b){return a.distance-b.distance});return b};var p=new THREE.Vector3,o=new THREE.Vector3,q=new THREE.Vector3,r,x,D,E,s,y,t,z,H,K,F};
  3147. THREE.Rectangle=function(){function a(){f=d-b;g=e-c}var b,c,d,e,f,g,i=true;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return f};this.getHeight=function(){return g};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,h,m){i=false;b=f;c=g;d=h;e=m;a()};this.addPoint=function(f,g){if(i){i=false;b=f;c=g;d=f;e=g}else{b=b<f?b:f;c=c<g?c:g;d=d>f?d:f;e=e>g?
  3148. e:g}a()};this.add3Points=function(f,g,h,m,l,n){if(i){i=false;b=f<h?f<l?f:l:h<l?h:l;c=g<m?g<n?g:n:m<n?m:n;d=f>h?f>l?f:l:h>l?h:l;e=g>m?g>n?g:n:m>n?m:n}else{b=f<h?f<l?f<b?f:b:l<b?l:b:h<l?h<b?h:b:l<b?l:b;c=g<m?g<n?g<c?g:c:n<c?n:c:m<n?m<c?m:c:n<c?n:c;d=f>h?f>l?f>d?f:d:l>d?l:d:h>l?h>d?h:d:l>d?l:d;e=g>m?g>n?g>e?g:e:n>e?n:e:m>n?m>e?m:e:n>e?n:e}a()};this.addRectangle=function(f){if(i){i=false;b=f.getLeft();c=f.getTop();d=f.getRight();e=f.getBottom()}else{b=b<f.getLeft()?b:f.getLeft();c=c<f.getTop()?c:f.getTop();
  3149. d=d>f.getRight()?d:f.getRight();e=e>f.getBottom()?e:f.getBottom()}a()};this.inflate=function(f){b=b-f;c=c-f;d=d+f;e=e+f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.intersects=function(a){return d<a.getLeft()||b>a.getRight()||e<a.getTop()||c>a.getBottom()?false:true};this.empty=function(){i=true;e=d=c=b=0;a()};this.isEmpty=function(){return i}};
  3150. THREE.Math={clamp:function(a,b,c){return a<b?b:a>c?c:a},clampBottom:function(a,b){return a<b?b:a},mapLinear:function(a,b,c,d,e){return d+(a-b)*(e-d)/(c-b)},random16:function(){return(65280*Math.random()+255*Math.random())/65535},randInt:function(a,b){return a+Math.floor(Math.random()*(b-a+1))},randFloat:function(a,b){return a+Math.random()*(b-a)},randFloatSpread:function(a){return a*(0.5-Math.random())},sign:function(a){return a<0?-1:a>0?1:0}};THREE.Matrix3=function(){this.elements=new Float32Array(9)};
  3151. THREE.Matrix3.prototype={constructor:THREE.Matrix3,getInverse:function(a){var b=a.elements,a=b[10]*b[5]-b[6]*b[9],c=-b[10]*b[1]+b[2]*b[9],d=b[6]*b[1]-b[2]*b[5],e=-b[10]*b[4]+b[6]*b[8],f=b[10]*b[0]-b[2]*b[8],g=-b[6]*b[0]+b[2]*b[4],i=b[9]*b[4]-b[5]*b[8],k=-b[9]*b[0]+b[1]*b[8],j=b[5]*b[0]-b[1]*b[4],b=b[0]*a+b[1]*e+b[2]*i;b===0&&console.warn("Matrix3.getInverse(): determinant == 0");var b=1/b,h=this.elements;h[0]=b*a;h[1]=b*c;h[2]=b*d;h[3]=b*e;h[4]=b*f;h[5]=b*g;h[6]=b*i;h[7]=b*k;h[8]=b*j;return this},
  3152. transpose:function(){var a,b=this.elements;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};THREE.Matrix4=function(a,b,c,d,e,f,g,i,k,j,h,m,l,n,p,o){this.elements=new Float32Array(16);this.set(a!==void 0?a:1,b||0,c||0,d||0,e||0,f!==void 0?f:1,g||0,i||0,k||0,j||0,h!==void 0?h:1,m||0,l||0,n||0,p||0,o!==void 0?o:1)};
  3153. THREE.Matrix4.prototype={constructor:THREE.Matrix4,set:function(a,b,c,d,e,f,g,i,k,j,h,m,l,n,p,o){var q=this.elements;q[0]=a;q[4]=b;q[8]=c;q[12]=d;q[1]=e;q[5]=f;q[9]=g;q[13]=i;q[2]=k;q[6]=j;q[10]=h;q[14]=m;q[3]=l;q[7]=n;q[11]=p;q[15]=o;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(a){a=a.elements;this.set(a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15]);return this},lookAt:function(a,b,c){var d=this.elements,
  3154. e=THREE.Matrix4.__v1,f=THREE.Matrix4.__v2,g=THREE.Matrix4.__v3;g.sub(a,b).normalize();if(g.length()===0)g.z=1;e.cross(c,g).normalize();if(e.length()===0){g.x=g.x+1.0E-4;e.cross(c,g).normalize()}f.cross(g,e);d[0]=e.x;d[4]=f.x;d[8]=g.x;d[1]=e.y;d[5]=f.y;d[9]=g.y;d[2]=e.z;d[6]=f.z;d[10]=g.z;return this},multiply:function(a,b){var c=a.elements,d=b.elements,e=this.elements,f=c[0],g=c[4],i=c[8],k=c[12],j=c[1],h=c[5],m=c[9],l=c[13],n=c[2],p=c[6],o=c[10],q=c[14],r=c[3],x=c[7],D=c[11],c=c[15],E=d[0],s=d[4],
  3155. y=d[8],t=d[12],z=d[1],H=d[5],K=d[9],F=d[13],J=d[2],P=d[6],Q=d[10],R=d[14],S=d[3],T=d[7],L=d[11],d=d[15];e[0]=f*E+g*z+i*J+k*S;e[4]=f*s+g*H+i*P+k*T;e[8]=f*y+g*K+i*Q+k*L;e[12]=f*t+g*F+i*R+k*d;e[1]=j*E+h*z+m*J+l*S;e[5]=j*s+h*H+m*P+l*T;e[9]=j*y+h*K+m*Q+l*L;e[13]=j*t+h*F+m*R+l*d;e[2]=n*E+p*z+o*J+q*S;e[6]=n*s+p*H+o*P+q*T;e[10]=n*y+p*K+o*Q+q*L;e[14]=n*t+p*F+o*R+q*d;e[3]=r*E+x*z+D*J+c*S;e[7]=r*s+x*H+D*P+c*T;e[11]=r*y+x*K+D*Q+c*L;e[15]=r*t+x*F+D*R+c*d;return this},multiplySelf:function(a){return this.multiply(this,
  3156. a)},multiplyToArray:function(a,b,c){var d=this.elements;this.multiply(a,b);c[0]=d[0];c[1]=d[1];c[2]=d[2];c[3]=d[3];c[4]=d[4];c[5]=d[5];c[6]=d[6];c[7]=d[7];c[8]=d[8];c[9]=d[9];c[10]=d[10];c[11]=d[11];c[12]=d[12];c[13]=d[13];c[14]=d[14];c[15]=d[15];return this},multiplyScalar:function(a){var b=this.elements;b[0]=b[0]*a;b[4]=b[4]*a;b[8]=b[8]*a;b[12]=b[12]*a;b[1]=b[1]*a;b[5]=b[5]*a;b[9]=b[9]*a;b[13]=b[13]*a;b[2]=b[2]*a;b[6]=b[6]*a;b[10]=b[10]*a;b[14]=b[14]*a;b[3]=b[3]*a;b[7]=b[7]*a;b[11]=b[11]*a;b[15]=
  3157. b[15]*a;return this},multiplyVector3:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,f=1/(b[3]*c+b[7]*d+b[11]*e+b[15]);a.x=(b[0]*c+b[4]*d+b[8]*e+b[12])*f;a.y=(b[1]*c+b[5]*d+b[9]*e+b[13])*f;a.z=(b[2]*c+b[6]*d+b[10]*e+b[14])*f;return a},multiplyVector4:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,f=a.w;a.x=b[0]*c+b[4]*d+b[8]*e+b[12]*f;a.y=b[1]*c+b[5]*d+b[9]*e+b[13]*f;a.z=b[2]*c+b[6]*d+b[10]*e+b[14]*f;a.w=b[3]*c+b[7]*d+b[11]*e+b[15]*f;return a},rotateAxis:function(a){var b=this.elements,c=a.x,
  3158. d=a.y,e=a.z;a.x=c*b[0]+d*b[4]+e*b[8];a.y=c*b[1]+d*b[5]+e*b[9];a.z=c*b[2]+d*b[6]+e*b[10];a.normalize();return a},crossVector:function(a){var b=this.elements,c=new THREE.Vector4;c.x=b[0]*a.x+b[4]*a.y+b[8]*a.z+b[12]*a.w;c.y=b[1]*a.x+b[5]*a.y+b[9]*a.z+b[13]*a.w;c.z=b[2]*a.x+b[6]*a.y+b[10]*a.z+b[14]*a.w;c.w=a.w?b[3]*a.x+b[7]*a.y+b[11]*a.z+b[15]*a.w:1;return c},determinant:function(){var a=this.elements,b=a[0],c=a[4],d=a[8],e=a[12],f=a[1],g=a[5],i=a[9],k=a[13],j=a[2],h=a[6],m=a[10],l=a[14],n=a[3],p=a[7],
  3159. o=a[11],a=a[15];return e*i*h*n-d*k*h*n-e*g*m*n+c*k*m*n+d*g*l*n-c*i*l*n-e*i*j*p+d*k*j*p+e*f*m*p-b*k*m*p-d*f*l*p+b*i*l*p+e*g*j*o-c*k*j*o-e*f*h*o+b*k*h*o+c*f*l*o-b*g*l*o-d*g*j*a+c*i*j*a+d*f*h*a-b*i*h*a-c*f*m*a+b*g*m*a},transpose:function(){var a=this.elements,b;b=a[1];a[1]=a[4];a[4]=b;b=a[2];a[2]=a[8];a[8]=b;b=a[6];a[6]=a[9];a[9]=b;b=a[3];a[3]=a[12];a[12]=b;b=a[7];a[7]=a[13];a[13]=b;b=a[11];a[11]=a[14];a[14]=b;return this},flattenToArray:function(a){var b=this.elements;a[0]=b[0];a[1]=b[1];a[2]=b[2];
  3160. a[3]=b[3];a[4]=b[4];a[5]=b[5];a[6]=b[6];a[7]=b[7];a[8]=b[8];a[9]=b[9];a[10]=b[10];a[11]=b[11];a[12]=b[12];a[13]=b[13];a[14]=b[14];a[15]=b[15];return a},flattenToArrayOffset:function(a,b){var c=this.elements;a[b]=c[0];a[b+1]=c[1];a[b+2]=c[2];a[b+3]=c[3];a[b+4]=c[4];a[b+5]=c[5];a[b+6]=c[6];a[b+7]=c[7];a[b+8]=c[8];a[b+9]=c[9];a[b+10]=c[10];a[b+11]=c[11];a[b+12]=c[12];a[b+13]=c[13];a[b+14]=c[14];a[b+15]=c[15];return a},getPosition:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[12],a[13],
  3161. a[14])},setPosition:function(a){var b=this.elements;b[12]=a.x;b[13]=a.y;b[14]=a.z;return this},getColumnX:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[0],a[1],a[2])},getColumnY:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[4],a[5],a[6])},getColumnZ:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[8],a[9],a[10])},getInverse:function(a){var b=this.elements,c=a.elements,d=c[0],e=c[4],f=c[8],g=c[12],i=c[1],k=c[5],j=c[9],h=c[13],m=c[2],l=c[6],n=c[10],p=
  3162. c[14],o=c[3],q=c[7],r=c[11],c=c[15];b[0]=j*p*q-h*n*q+h*l*r-k*p*r-j*l*c+k*n*c;b[4]=g*n*q-f*p*q-g*l*r+e*p*r+f*l*c-e*n*c;b[8]=f*h*q-g*j*q+g*k*r-e*h*r-f*k*c+e*j*c;b[12]=g*j*l-f*h*l-g*k*n+e*h*n+f*k*p-e*j*p;b[1]=h*n*o-j*p*o-h*m*r+i*p*r+j*m*c-i*n*c;b[5]=f*p*o-g*n*o+g*m*r-d*p*r-f*m*c+d*n*c;b[9]=g*j*o-f*h*o-g*i*r+d*h*r+f*i*c-d*j*c;b[13]=f*h*m-g*j*m+g*i*n-d*h*n-f*i*p+d*j*p;b[2]=k*p*o-h*l*o+h*m*q-i*p*q-k*m*c+i*l*c;b[6]=g*l*o-e*p*o-g*m*q+d*p*q+e*m*c-d*l*c;b[10]=e*h*o-g*k*o+g*i*q-d*h*q-e*i*c+d*k*c;b[14]=g*k*m-
  3163. e*h*m-g*i*l+d*h*l+e*i*p-d*k*p;b[3]=j*l*o-k*n*o-j*m*q+i*n*q+k*m*r-i*l*r;b[7]=e*n*o-f*l*o+f*m*q-d*n*q-e*m*r+d*l*r;b[11]=f*k*o-e*j*o-f*i*q+d*j*q+e*i*r-d*k*r;b[15]=e*j*m-f*k*m+f*i*l-d*j*l-e*i*n+d*k*n;this.multiplyScalar(1/a.determinant());return this},setRotationFromEuler:function(a,b){var c=this.elements,d=a.x,e=a.y,f=a.z,g=Math.cos(d),d=Math.sin(d),i=Math.cos(e),e=Math.sin(e),k=Math.cos(f),f=Math.sin(f);switch(b){case "YXZ":var j=i*k,h=i*f,m=e*k,l=e*f;c[0]=j+l*d;c[4]=m*d-h;c[8]=g*e;c[1]=g*f;c[5]=g*
  3164. k;c[9]=-d;c[2]=h*d-m;c[6]=l+j*d;c[10]=g*i;break;case "ZXY":j=i*k;h=i*f;m=e*k;l=e*f;c[0]=j-l*d;c[4]=-g*f;c[8]=m+h*d;c[1]=h+m*d;c[5]=g*k;c[9]=l-j*d;c[2]=-g*e;c[6]=d;c[10]=g*i;break;case "ZYX":j=g*k;h=g*f;m=d*k;l=d*f;c[0]=i*k;c[4]=m*e-h;c[8]=j*e+l;c[1]=i*f;c[5]=l*e+j;c[9]=h*e-m;c[2]=-e;c[6]=d*i;c[10]=g*i;break;case "YZX":j=g*i;h=g*e;m=d*i;l=d*e;c[0]=i*k;c[4]=l-j*f;c[8]=m*f+h;c[1]=f;c[5]=g*k;c[9]=-d*k;c[2]=-e*k;c[6]=h*f+m;c[10]=j-l*f;break;case "XZY":j=g*i;h=g*e;m=d*i;l=d*e;c[0]=i*k;c[4]=-f;c[8]=e*k;
  3165. c[1]=j*f+l;c[5]=g*k;c[9]=h*f-m;c[2]=m*f-h;c[6]=d*k;c[10]=l*f+j;break;default:j=g*k;h=g*f;m=d*k;l=d*f;c[0]=i*k;c[4]=-i*f;c[8]=e;c[1]=h+m*e;c[5]=j-l*e;c[9]=-d*i;c[2]=l-j*e;c[6]=m+h*e;c[10]=g*i}return this},setRotationFromQuaternion:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,f=a.w,g=c+c,i=d+d,k=e+e,a=c*g,j=c*i,c=c*k,h=d*i,d=d*k,e=e*k,g=f*g,i=f*i,f=f*k;b[0]=1-(h+e);b[4]=j-f;b[8]=c+i;b[1]=j+f;b[5]=1-(a+e);b[9]=d-g;b[2]=c-i;b[6]=d+g;b[10]=1-(a+h);return this},compose:function(a,b,c){var d=this.elements,
  3166. e=THREE.Matrix4.__m1,f=THREE.Matrix4.__m2;e.identity();e.setRotationFromQuaternion(b);f.makeScale(c.x,c.y,c.z);this.multiply(e,f);d[12]=a.x;d[13]=a.y;d[14]=a.z;return this},decompose:function(a,b,c){var d=this.elements,e=THREE.Matrix4.__v1,f=THREE.Matrix4.__v2,g=THREE.Matrix4.__v3;e.set(d[0],d[1],d[2]);f.set(d[4],d[5],d[6]);g.set(d[8],d[9],d[10]);a=a instanceof THREE.Vector3?a:new THREE.Vector3;b=b instanceof THREE.Quaternion?b:new THREE.Quaternion;c=c instanceof THREE.Vector3?c:new THREE.Vector3;
  3167. c.x=e.length();c.y=f.length();c.z=g.length();a.x=d[12];a.y=d[13];a.z=d[14];d=THREE.Matrix4.__m1;d.copy(this);d.elements[0]=d.elements[0]/c.x;d.elements[1]=d.elements[1]/c.x;d.elements[2]=d.elements[2]/c.x;d.elements[4]=d.elements[4]/c.y;d.elements[5]=d.elements[5]/c.y;d.elements[6]=d.elements[6]/c.y;d.elements[8]=d.elements[8]/c.z;d.elements[9]=d.elements[9]/c.z;d.elements[10]=d.elements[10]/c.z;b.setFromRotationMatrix(d);return[a,b,c]},extractPosition:function(a){var b=this.elements,a=a.elements;
  3168. b[12]=a[12];b[13]=a[13];b[14]=a[14];return this},extractRotation:function(a){var b=this.elements,a=a.elements,c=THREE.Matrix4.__v1,d=1/c.set(a[0],a[1],a[2]).length(),e=1/c.set(a[4],a[5],a[6]).length(),c=1/c.set(a[8],a[9],a[10]).length();b[0]=a[0]*d;b[1]=a[1]*d;b[2]=a[2]*d;b[4]=a[4]*e;b[5]=a[5]*e;b[6]=a[6]*e;b[8]=a[8]*c;b[9]=a[9]*c;b[10]=a[10]*c;return this},translate:function(a){var b=this.elements,c=a.x,d=a.y,a=a.z;b[12]=b[0]*c+b[4]*d+b[8]*a+b[12];b[13]=b[1]*c+b[5]*d+b[9]*a+b[13];b[14]=b[2]*c+b[6]*
  3169. d+b[10]*a+b[14];b[15]=b[3]*c+b[7]*d+b[11]*a+b[15];return this},rotateX:function(a){var b=this.elements,c=b[4],d=b[5],e=b[6],f=b[7],g=b[8],i=b[9],k=b[10],j=b[11],h=Math.cos(a),a=Math.sin(a);b[4]=h*c+a*g;b[5]=h*d+a*i;b[6]=h*e+a*k;b[7]=h*f+a*j;b[8]=h*g-a*c;b[9]=h*i-a*d;b[10]=h*k-a*e;b[11]=h*j-a*f;return this},rotateY:function(a){var b=this.elements,c=b[0],d=b[1],e=b[2],f=b[3],g=b[8],i=b[9],k=b[10],j=b[11],h=Math.cos(a),a=Math.sin(a);b[0]=h*c-a*g;b[1]=h*d-a*i;b[2]=h*e-a*k;b[3]=h*f-a*j;b[8]=h*g+a*c;b[9]=
  3170. h*i+a*d;b[10]=h*k+a*e;b[11]=h*j+a*f;return this},rotateZ:function(a){var b=this.elements,c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],i=b[5],k=b[6],j=b[7],h=Math.cos(a),a=Math.sin(a);b[0]=h*c+a*g;b[1]=h*d+a*i;b[2]=h*e+a*k;b[3]=h*f+a*j;b[4]=h*g-a*c;b[5]=h*i-a*d;b[6]=h*k-a*e;b[7]=h*j-a*f;return this},rotateByAxis:function(a,b){var c=this.elements;if(a.x===1&&a.y===0&&a.z===0)return this.rotateX(b);if(a.x===0&&a.y===1&&a.z===0)return this.rotateY(b);if(a.x===0&&a.y===0&&a.z===1)return this.rotateZ(b);var d=a.x,
  3171. e=a.y,f=a.z,g=Math.sqrt(d*d+e*e+f*f),d=d/g,e=e/g,f=f/g,g=d*d,i=e*e,k=f*f,j=Math.cos(b),h=Math.sin(b),m=1-j,l=d*e*m,n=d*f*m,m=e*f*m,d=d*h,p=e*h,h=f*h,f=g+(1-g)*j,g=l+h,e=n-p,l=l-h,i=i+(1-i)*j,h=m+d,n=n+p,m=m-d,k=k+(1-k)*j,j=c[0],d=c[1],p=c[2],o=c[3],q=c[4],r=c[5],x=c[6],D=c[7],E=c[8],s=c[9],y=c[10],t=c[11];c[0]=f*j+g*q+e*E;c[1]=f*d+g*r+e*s;c[2]=f*p+g*x+e*y;c[3]=f*o+g*D+e*t;c[4]=l*j+i*q+h*E;c[5]=l*d+i*r+h*s;c[6]=l*p+i*x+h*y;c[7]=l*o+i*D+h*t;c[8]=n*j+m*q+k*E;c[9]=n*d+m*r+k*s;c[10]=n*p+m*x+k*y;c[11]=
  3172. n*o+m*D+k*t;return this},scale:function(a){var b=this.elements,c=a.x,d=a.y,a=a.z;b[0]=b[0]*c;b[4]=b[4]*d;b[8]=b[8]*a;b[1]=b[1]*c;b[5]=b[5]*d;b[9]=b[9]*a;b[2]=b[2]*c;b[6]=b[6]*d;b[10]=b[10]*a;b[3]=b[3]*c;b[7]=b[7]*d;b[11]=b[11]*a;return this},getMaxScaleOnAxis:function(){var a=this.elements;return Math.sqrt(Math.max(a[0]*a[0]+a[1]*a[1]+a[2]*a[2],Math.max(a[4]*a[4]+a[5]*a[5]+a[6]*a[6],a[8]*a[8]+a[9]*a[9]+a[10]*a[10])))},makeTranslation:function(a,b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this},
  3173. makeRotationX:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(1,0,0,0,0,b,-a,0,0,a,b,0,0,0,0,1);return this},makeRotationY:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,0,a,0,0,1,0,0,-a,0,b,0,0,0,0,1);return this},makeRotationZ:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,-a,0,0,a,b,0,0,0,0,1,0,0,0,0,1);return this},makeRotationAxis:function(a,b){var c=Math.cos(b),d=Math.sin(b),e=1-c,f=a.x,g=a.y,i=a.z,k=e*f,j=e*g;this.set(k*f+c,k*g-d*i,k*i+d*g,0,k*g+d*i,j*g+c,j*i-d*f,0,k*i-
  3174. d*g,j*i+d*f,e*i*i+c,0,0,0,0,1);return this},makeScale:function(a,b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},makeFrustum:function(a,b,c,d,e,f){var g=this.elements;g[0]=2*e/(b-a);g[4]=0;g[8]=(b+a)/(b-a);g[12]=0;g[1]=0;g[5]=2*e/(d-c);g[9]=(d+c)/(d-c);g[13]=0;g[2]=0;g[6]=0;g[10]=-(f+e)/(f-e);g[14]=-2*f*e/(f-e);g[3]=0;g[7]=0;g[11]=-1;g[15]=0;return this},makePerspective:function(a,b,c,d){var a=c*Math.tan(a*Math.PI/360),e=-a;return this.makeFrustum(e*b,a*b,e,a,c,d)},makeOrthographic:function(a,
  3175. b,c,d,e,f){var g=this.elements,i=b-a,k=c-d,j=f-e;g[0]=2/i;g[4]=0;g[8]=0;g[12]=-((b+a)/i);g[1]=0;g[5]=2/k;g[9]=0;g[13]=-((c+d)/k);g[2]=0;g[6]=0;g[10]=-2/j;g[14]=-((f+e)/j);g[3]=0;g[7]=0;g[11]=0;g[15]=1;return this},clone:function(){var a=this.elements;return new THREE.Matrix4(a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15])}};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;THREE.Matrix4.__m1=new THREE.Matrix4;
  3176. THREE.Matrix4.__m2=new THREE.Matrix4;
  3177. THREE.Object3D=function(){this.id=THREE.Object3DCount++;this.name="";this.parent=void 0;this.children=[];this.up=new THREE.Vector3(0,1,0);this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.eulerOrder="XYZ";this.scale=new THREE.Vector3(1,1,1);this.flipSided=this.doubleSided=false;this.renderDepth=null;this.rotationAutoUpdate=true;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixRotationWorld=new THREE.Matrix4;this.matrixWorldNeedsUpdate=this.matrixAutoUpdate=
  3178. true;this.quaternion=new THREE.Quaternion;this.useQuaternion=false;this.boundRadius=0;this.boundRadiusScale=1;this.visible=true;this.receiveShadow=this.castShadow=false;this.frustumCulled=true;this._vector=new THREE.Vector3};
  3179. THREE.Object3D.prototype={constructor:THREE.Object3D,applyMatrix:function(a){this.matrix.multiply(a,this.matrix);this.scale.getScaleFromMatrix(this.matrix);this.rotation.getRotationFromMatrix(this.matrix,this.scale);this.position.getPositionFromMatrix(this.matrix)},translate:function(a,b){this.matrix.rotateAxis(b);this.position.addSelf(b.multiplyScalar(a))},translateX:function(a){this.translate(a,this._vector.set(1,0,0))},translateY:function(a){this.translate(a,this._vector.set(0,1,0))},translateZ:function(a){this.translate(a,
  3180. this._vector.set(0,0,1))},lookAt:function(a){this.matrix.lookAt(a,this.position,this.up);this.rotationAutoUpdate&&this.rotation.getRotationFromMatrix(this.matrix)},add:function(a){if(a===this)console.warn("THREE.Object3D.add: An object can't be added as a child of itself.");else if(a instanceof THREE.Object3D){a.parent!==void 0&&a.parent.remove(a);a.parent=this;this.children.push(a);for(var b=this;b.parent!==void 0;)b=b.parent;b!==void 0&&b instanceof THREE.Scene&&b.__addObject(a)}},remove:function(a){var b=
  3181. this.children.indexOf(a);if(b!==-1){a.parent=void 0;this.children.splice(b,1);for(b=this;b.parent!==void 0;)b=b.parent;b!==void 0&&b instanceof THREE.Scene&&b.__removeObject(a)}},getChildByName:function(a,b){var c,d,e;c=0;for(d=this.children.length;c<d;c++){e=this.children[c];if(e.name===a)return e;if(b){e=e.getChildByName(a,b);if(e!==void 0)return e}}},updateMatrix:function(){this.matrix.setPosition(this.position);this.useQuaternion?this.matrix.setRotationFromQuaternion(this.quaternion):this.matrix.setRotationFromEuler(this.rotation,
  3182. this.eulerOrder);if(this.scale.x!==1||this.scale.y!==1||this.scale.z!==1){this.matrix.scale(this.scale);this.boundRadiusScale=Math.max(this.scale.x,Math.max(this.scale.y,this.scale.z))}this.matrixWorldNeedsUpdate=true},updateMatrixWorld:function(a){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||a){this.parent?this.matrixWorld.multiply(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);this.matrixWorldNeedsUpdate=false;a=true}for(var b=0,c=this.children.length;b<
  3183. c;b++)this.children[b].updateMatrixWorld(a)}};THREE.Object3DCount=0;
  3184. THREE.Projector=function(){function a(){var a=g[f]=g[f]||new THREE.RenderableObject;f++;return a}function b(){var a=j[k]=j[k]||new THREE.RenderableVertex;k++;return a}function c(a,b){return b.z-a.z}function d(a,b){var c=0,d=1,e=a.z+a.w,f=b.z+b.w,g=-a.z+a.w,h=-b.z+b.w;if(e>=0&&f>=0&&g>=0&&h>=0)return true;if(e<0&&f<0||g<0&&h<0)return false;e<0?c=Math.max(c,e/(e-f)):f<0&&(d=Math.min(d,e/(e-f)));g<0?c=Math.max(c,g/(g-h)):h<0&&(d=Math.min(d,g/(g-h)));if(d<c)return false;a.lerpSelf(b,c);b.lerpSelf(a,1-
  3185. d);return true}var e,f,g=[],i,k,j=[],h,m,l=[],n,p=[],o,q,r=[],x,D,E=[],s={objects:[],sprites:[],lights:[],elements:[]},y=new THREE.Vector3,t=new THREE.Vector4,z=new THREE.Matrix4,H=new THREE.Matrix4,K=new THREE.Frustum,F=new THREE.Vector4,J=new THREE.Vector4;this.projectVector=function(a,b){b.matrixWorldInverse.getInverse(b.matrixWorld);z.multiply(b.projectionMatrix,b.matrixWorldInverse);z.multiplyVector3(a);return a};this.unprojectVector=function(a,b){b.projectionMatrixInverse.getInverse(b.projectionMatrix);
  3186. z.multiply(b.matrixWorld,b.projectionMatrixInverse);z.multiplyVector3(a);return a};this.pickingRay=function(a,b){var c;a.z=-1;c=new THREE.Vector3(a.x,a.y,1);this.unprojectVector(a,b);this.unprojectVector(c,b);c.subSelf(a).normalize();return new THREE.Ray(a,c)};this.projectGraph=function(b,d){f=0;s.objects.length=0;s.sprites.length=0;s.lights.length=0;var g=function(b){if(b.visible!==false){if((b instanceof THREE.Mesh||b instanceof THREE.Line)&&(b.frustumCulled===false||K.contains(b))){y.copy(b.matrixWorld.getPosition());
  3187. z.multiplyVector3(y);e=a();e.object=b;e.z=y.z;s.objects.push(e)}else if(b instanceof THREE.Sprite||b instanceof THREE.Particle){y.copy(b.matrixWorld.getPosition());z.multiplyVector3(y);e=a();e.object=b;e.z=y.z;s.sprites.push(e)}else b instanceof THREE.Light&&s.lights.push(b);for(var c=0,d=b.children.length;c<d;c++)g(b.children[c])}};g(b);d&&s.objects.sort(c);return s};this.projectScene=function(a,e,f){var g=e.near,y=e.far,L=false,U,B,v,I,u,C,A,G,w,M,N,V,W,X,O;D=q=n=m=0;s.elements.length=0;if(e.parent===
  3188. void 0){console.warn("DEPRECATED: Camera hasn't been added to a Scene. Adding it...");a.add(e)}a.updateMatrixWorld();e.matrixWorldInverse.getInverse(e.matrixWorld);z.multiply(e.projectionMatrix,e.matrixWorldInverse);K.setFromMatrix(z);s=this.projectGraph(a,false);a=0;for(U=s.objects.length;a<U;a++){w=s.objects[a].object;M=w.matrixWorld;k=0;if(w instanceof THREE.Mesh){N=w.geometry;V=w.geometry.materials;I=N.vertices;W=N.faces;X=N.faceVertexUvs;N=w.matrixRotationWorld.extractRotation(M);B=0;for(v=I.length;B<
  3189. v;B++){i=b();i.positionWorld.copy(I[B]);M.multiplyVector3(i.positionWorld);i.positionScreen.copy(i.positionWorld);z.multiplyVector4(i.positionScreen);i.positionScreen.x=i.positionScreen.x/i.positionScreen.w;i.positionScreen.y=i.positionScreen.y/i.positionScreen.w;i.visible=i.positionScreen.z>g&&i.positionScreen.z<y}I=0;for(B=W.length;I<B;I++){v=W[I];if(v instanceof THREE.Face3){u=j[v.a];C=j[v.b];A=j[v.c];if(u.visible&&C.visible&&A.visible){L=(A.positionScreen.x-u.positionScreen.x)*(C.positionScreen.y-
  3190. u.positionScreen.y)-(A.positionScreen.y-u.positionScreen.y)*(C.positionScreen.x-u.positionScreen.x)<0;if(w.doubleSided||L!=w.flipSided){G=l[m]=l[m]||new THREE.RenderableFace3;m++;h=G;h.v1.copy(u);h.v2.copy(C);h.v3.copy(A)}else continue}else continue}else if(v instanceof THREE.Face4){u=j[v.a];C=j[v.b];A=j[v.c];G=j[v.d];if(u.visible&&C.visible&&A.visible&&G.visible){L=(G.positionScreen.x-u.positionScreen.x)*(C.positionScreen.y-u.positionScreen.y)-(G.positionScreen.y-u.positionScreen.y)*(C.positionScreen.x-
  3191. u.positionScreen.x)<0||(C.positionScreen.x-A.positionScreen.x)*(G.positionScreen.y-A.positionScreen.y)-(C.positionScreen.y-A.positionScreen.y)*(G.positionScreen.x-A.positionScreen.x)<0;if(w.doubleSided||L!=w.flipSided){O=p[n]=p[n]||new THREE.RenderableFace4;n++;h=O;h.v1.copy(u);h.v2.copy(C);h.v3.copy(A);h.v4.copy(G)}else continue}else continue}h.normalWorld.copy(v.normal);!L&&(w.flipSided||w.doubleSided)&&h.normalWorld.negate();N.multiplyVector3(h.normalWorld);h.centroidWorld.copy(v.centroid);M.multiplyVector3(h.centroidWorld);
  3192. h.centroidScreen.copy(h.centroidWorld);z.multiplyVector3(h.centroidScreen);A=v.vertexNormals;u=0;for(C=A.length;u<C;u++){G=h.vertexNormalsWorld[u];G.copy(A[u]);!L&&(w.flipSided||w.doubleSided)&&G.negate();N.multiplyVector3(G)}u=0;for(C=X.length;u<C;u++)if(O=X[u][I]){A=0;for(G=O.length;A<G;A++)h.uvs[u][A]=O[A]}h.material=w.material;h.faceMaterial=v.materialIndex!==null?V[v.materialIndex]:null;h.z=h.centroidScreen.z;s.elements.push(h)}}else if(w instanceof THREE.Line){H.multiply(z,M);I=w.geometry.vertices;
  3193. u=b();u.positionScreen.copy(I[0]);H.multiplyVector4(u.positionScreen);M=w.type===THREE.LinePieces?2:1;B=1;for(v=I.length;B<v;B++){u=b();u.positionScreen.copy(I[B]);H.multiplyVector4(u.positionScreen);if(!((B+1)%M>0)){C=j[k-2];F.copy(u.positionScreen);J.copy(C.positionScreen);if(d(F,J)){F.multiplyScalar(1/F.w);J.multiplyScalar(1/J.w);V=r[q]=r[q]||new THREE.RenderableLine;q++;o=V;o.v1.positionScreen.copy(F);o.v2.positionScreen.copy(J);o.z=Math.max(F.z,J.z);o.material=w.material;s.elements.push(o)}}}}}a=
  3194. 0;for(U=s.sprites.length;a<U;a++){w=s.sprites[a].object;M=w.matrixWorld;if(w instanceof THREE.Particle){t.set(M.elements[12],M.elements[13],M.elements[14],1);z.multiplyVector4(t);t.z=t.z/t.w;if(t.z>0&&t.z<1){g=E[D]=E[D]||new THREE.RenderableParticle;D++;x=g;x.x=t.x/t.w;x.y=t.y/t.w;x.z=t.z;x.rotation=w.rotation.z;x.scale.x=w.scale.x*Math.abs(x.x-(t.x+e.projectionMatrix.elements[0])/(t.w+e.projectionMatrix.elements[12]));x.scale.y=w.scale.y*Math.abs(x.y-(t.y+e.projectionMatrix.elements[5])/(t.w+e.projectionMatrix.elements[13]));
  3195. x.material=w.material;s.elements.push(x)}}}f&&s.elements.sort(c);return s}};THREE.Quaternion=function(a,b,c,d){this.x=a||0;this.y=b||0;this.z=c||0;this.w=d!==void 0?d:1};
  3196. THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=Math.PI/360,c=a.x*b,d=a.y*b,e=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-e),e=Math.sin(-e),f=Math.cos(c),c=Math.sin(c),g=a*b,i=d*e;this.w=g*f-i*c;this.x=g*c+i*f;this.y=d*b*f+a*e*c;this.z=a*e*f-d*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c);
  3197. this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},setFromRotationMatrix:function(a){var b=Math.pow(a.determinant(),1/3);this.w=Math.sqrt(Math.max(0,b+a.elements[0]+a.elements[5]+a.elements[10]))/2;this.x=Math.sqrt(Math.max(0,b+a.elements[0]-a.elements[5]-a.elements[10]))/2;this.y=Math.sqrt(Math.max(0,b-a.elements[0]+a.elements[5]-a.elements[10]))/2;this.z=Math.sqrt(Math.max(0,b-a.elements[0]-a.elements[5]+a.elements[10]))/2;this.x=a.elements[6]-a.elements[9]<0?-Math.abs(this.x):
  3198. Math.abs(this.x);this.y=a.elements[8]-a.elements[2]<0?-Math.abs(this.y):Math.abs(this.y);this.z=a.elements[1]-a.elements[4]<0?-Math.abs(this.z):Math.abs(this.z);this.normalize();return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x=this.x*-1;this.y=this.y*-1;this.z=this.z*-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=
  3199. Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);if(a===0)this.w=this.z=this.y=this.x=0;else{a=1/a;this.x=this.x*a;this.y=this.y*a;this.z=this.z*a;this.w=this.w*a}return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,f=a.x,g=a.y,i=a.z,a=a.w;this.x=b*a+e*f+c*i-d*g;this.y=
  3200. c*a+e*g+d*f-b*i;this.z=d*a+e*i+b*g-c*f;this.w=e*a-b*f-c*g-d*i;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,f=this.x,g=this.y,i=this.z,k=this.w,j=k*c+g*e-i*d,h=k*d+i*c-f*e,m=k*e+f*d-g*c,c=-f*c-g*d-i*e;b.x=j*k+c*-f+h*-i-m*-g;b.y=h*k+c*-g+m*-f-j*-i;b.z=m*k+c*-i+j*-g-h*-f;return b},clone:function(){return new THREE.Quaternion(this.x,this.y,this.z,this.w)}};
  3201. THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;if(e<0){c.w=-b.w;c.x=-b.x;c.y=-b.y;c.z=-b.z;e=-e}else c.copy(b);if(Math.abs(e)>=1){c.w=a.w;c.x=a.x;c.y=a.y;c.z=a.z;return c}var f=Math.acos(e),e=Math.sqrt(1-e*e);if(Math.abs(e)<0.0010){c.w=0.5*(a.w+b.w);c.x=0.5*(a.x+b.x);c.y=0.5*(a.y+b.y);c.z=0.5*(a.z+b.z);return c}b=Math.sin((1-d)*f)/e;d=Math.sin(d*f)/e;c.w=a.w*b+c.w*d;c.x=a.x*b+c.x*d;c.y=a.y*b+c.y*d;c.z=a.z*b+c.z*d;return c};THREE.Vertex=function(){console.warn("THREE.Vertex has been DEPRECATED. Use THREE.Vector3 instead.")};
  3202. THREE.Face3=function(a,b,c,d,e,f){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=e instanceof THREE.Color?e:new THREE.Color;this.vertexColors=e instanceof Array?e:[];this.vertexTangents=[];this.materialIndex=f;this.centroid=new THREE.Vector3};
  3203. THREE.Face3.prototype={constructor:THREE.Face3,clone:function(){var a=new THREE.Face3(this.a,this.b,this.c);a.normal.copy(this.normal);a.color.copy(this.color);a.centroid.copy(this.centroid);a.materialIndex=this.materialIndex;var b,c;b=0;for(c=this.vertexNormals.length;b<c;b++)a.vertexNormals[b]=this.vertexNormals[b].clone();b=0;for(c=this.vertexColors.length;b<c;b++)a.vertexColors[b]=this.vertexColors[b].clone();b=0;for(c=this.vertexTangents.length;b<c;b++)a.vertexTangents[b]=this.vertexTangents[b].clone();
  3204. return a}};THREE.Face4=function(a,b,c,d,e,f,g){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.color=f instanceof THREE.Color?f:new THREE.Color;this.vertexColors=f instanceof Array?f:[];this.vertexTangents=[];this.materialIndex=g;this.centroid=new THREE.Vector3};
  3205. THREE.Face4.prototype={constructor:THREE.Face4,clone:function(){var a=new THREE.Face4(this.a,this.b,this.c,this.d);a.normal.copy(this.normal);a.color.copy(this.color);a.centroid.copy(this.centroid);a.materialIndex=this.materialIndex;var b,c;b=0;for(c=this.vertexNormals.length;b<c;b++)a.vertexNormals[b]=this.vertexNormals[b].clone();b=0;for(c=this.vertexColors.length;b<c;b++)a.vertexColors[b]=this.vertexColors[b].clone();b=0;for(c=this.vertexTangents.length;b<c;b++)a.vertexTangents[b]=this.vertexTangents[b].clone();
  3206. return a}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};THREE.UV.prototype={constructor:THREE.UV,set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.u=a.u;this.v=a.v;return this},lerpSelf:function(a,b){this.u=this.u+(a.u-this.u)*b;this.v=this.v+(a.v-this.v)*b;return this},clone:function(){return new THREE.UV(this.u,this.v)}};
  3207. THREE.Camera=function(){THREE.Object3D.call(this);this.matrixWorldInverse=new THREE.Matrix4;this.projectionMatrix=new THREE.Matrix4;this.projectionMatrixInverse=new THREE.Matrix4};THREE.Camera.prototype=new THREE.Object3D;THREE.Camera.prototype.constructor=THREE.Camera;THREE.Camera.prototype.lookAt=function(a){this.matrix.lookAt(this.position,a,this.up);this.rotationAutoUpdate&&this.rotation.getRotationFromMatrix(this.matrix)};
  3208. THREE.OrthographicCamera=function(a,b,c,d,e,f){THREE.Camera.call(this);this.left=a;this.right=b;this.top=c;this.bottom=d;this.near=e!==void 0?e:0.1;this.far=f!==void 0?f:2E3;this.updateProjectionMatrix()};THREE.OrthographicCamera.prototype=new THREE.Camera;THREE.OrthographicCamera.prototype.constructor=THREE.OrthographicCamera;THREE.OrthographicCamera.prototype.updateProjectionMatrix=function(){this.projectionMatrix.makeOrthographic(this.left,this.right,this.top,this.bottom,this.near,this.far)};
  3209. THREE.PerspectiveCamera=function(a,b,c,d){THREE.Camera.call(this);this.fov=a!==void 0?a:50;this.aspect=b!==void 0?b:1;this.near=c!==void 0?c:0.1;this.far=d!==void 0?d:2E3;this.updateProjectionMatrix()};THREE.PerspectiveCamera.prototype=new THREE.Camera;THREE.PerspectiveCamera.prototype.constructor=THREE.PerspectiveCamera;THREE.PerspectiveCamera.prototype.setLens=function(a,b){this.fov=2*Math.atan((b!==void 0?b:24)/(a*2))*(180/Math.PI);this.updateProjectionMatrix()};
  3210. THREE.PerspectiveCamera.prototype.setViewOffset=function(a,b,c,d,e,f){this.fullWidth=a;this.fullHeight=b;this.x=c;this.y=d;this.width=e;this.height=f;this.updateProjectionMatrix()};
  3211. THREE.PerspectiveCamera.prototype.updateProjectionMatrix=function(){if(this.fullWidth){var a=this.fullWidth/this.fullHeight,b=Math.tan(this.fov*Math.PI/360)*this.near,c=-b,d=a*c,a=Math.abs(a*b-d),c=Math.abs(b-c);this.projectionMatrix.makeFrustum(d+this.x*a/this.fullWidth,d+(this.x+this.width)*a/this.fullWidth,b-(this.y+this.height)*c/this.fullHeight,b-this.y*c/this.fullHeight,this.near,this.far)}else this.projectionMatrix.makePerspective(this.fov,this.aspect,this.near,this.far)};
  3212. THREE.Light=function(a){THREE.Object3D.call(this);this.color=new THREE.Color(a)};THREE.Light.prototype=new THREE.Object3D;THREE.Light.prototype.constructor=THREE.Light;THREE.Light.prototype.supr=THREE.Object3D.prototype;THREE.Loader=function(a){this.statusDomElement=(this.showStatus=a)?THREE.Loader.prototype.addStatusElement():null;this.onLoadStart=function(){};this.onLoadProgress=function(){};this.onLoadComplete=function(){}};
  3213. THREE.Loader.prototype={constructor:THREE.Loader,crossOrigin:"anonymous",addStatusElement:function(){var a=document.createElement("div");a.style.position="absolute";a.style.right="0px";a.style.top="0px";a.style.fontSize="0.8em";a.style.textAlign="left";a.style.background="rgba(0,0,0,0.25)";a.style.color="#fff";a.style.width="120px";a.style.padding="0.5em 0.5em 0.5em 0.5em";a.style.zIndex=1E3;a.innerHTML="Loading ...";return a},updateProgress:function(a){var b="Loaded ",b=a.total?b+((100*a.loaded/
  3214. a.total).toFixed(0)+"%"):b+((a.loaded/1E3).toFixed(2)+" KB");this.statusDomElement.innerHTML=b},extractUrlBase:function(a){a=a.split("/");a.pop();return(a.length<1?".":a.join("/"))+"/"},initMaterials:function(a,b,c){a.materials=[];for(var d=0;d<b.length;++d)a.materials[d]=THREE.Loader.prototype.createMaterial(b[d],c)},hasNormals:function(a){var b,c,d=a.materials.length;for(c=0;c<d;c++){b=a.materials[c];if(b instanceof THREE.ShaderMaterial)return true}return false},createMaterial:function(a,b){function c(a){a=
  3215. Math.log(a)/Math.LN2;return Math.floor(a)==a}function d(a){a=Math.log(a)/Math.LN2;return Math.pow(2,Math.round(a))}function e(a,b){var e=new Image;e.onload=function(){if(!c(this.width)||!c(this.height)){var b=d(this.width),e=d(this.height);a.image.width=b;a.image.height=e;a.image.getContext("2d").drawImage(this,0,0,b,e)}else a.image=this;a.needsUpdate=true};e.crossOrigin=i.crossOrigin;e.src=b}function f(a,c,d,f,g,h){var i=document.createElement("canvas");a[c]=new THREE.Texture(i);a[c].sourceFile=
  3216. d;if(f){a[c].repeat.set(f[0],f[1]);if(f[0]!=1)a[c].wrapS=THREE.RepeatWrapping;if(f[1]!=1)a[c].wrapT=THREE.RepeatWrapping}g&&a[c].offset.set(g[0],g[1]);if(h){f={repeat:THREE.RepeatWrapping,mirror:THREE.MirroredRepeatWrapping};if(f[h[0]]!==void 0)a[c].wrapS=f[h[0]];if(f[h[1]]!==void 0)a[c].wrapT=f[h[1]]}e(a[c],b+"/"+d)}function g(a){return(a[0]*255<<16)+(a[1]*255<<8)+a[2]*255}var i=this,k="MeshLambertMaterial",j={color:15658734,opacity:1,map:null,lightMap:null,normalMap:null,wireframe:a.wireframe};
  3217. if(a.shading){var h=a.shading.toLowerCase();h==="phong"?k="MeshPhongMaterial":h==="basic"&&(k="MeshBasicMaterial")}if(a.blending!==void 0&&THREE[a.blending]!==void 0)j.blending=THREE[a.blending];if(a.transparent!==void 0||a.opacity<1)j.transparent=a.transparent;if(a.depthTest!==void 0)j.depthTest=a.depthTest;if(a.depthWrite!==void 0)j.depthWrite=a.depthWrite;if(a.vertexColors!==void 0)if(a.vertexColors=="face")j.vertexColors=THREE.FaceColors;else if(a.vertexColors)j.vertexColors=THREE.VertexColors;
  3218. if(a.colorDiffuse)j.color=g(a.colorDiffuse);else if(a.DbgColor)j.color=a.DbgColor;if(a.colorSpecular)j.specular=g(a.colorSpecular);if(a.colorAmbient)j.ambient=g(a.colorAmbient);if(a.transparency)j.opacity=a.transparency;if(a.specularCoef)j.shininess=a.specularCoef;a.mapDiffuse&&b&&f(j,"map",a.mapDiffuse,a.mapDiffuseRepeat,a.mapDiffuseOffset,a.mapDiffuseWrap);a.mapLight&&b&&f(j,"lightMap",a.mapLight,a.mapLightRepeat,a.mapLightOffset,a.mapLightWrap);a.mapNormal&&b&&f(j,"normalMap",a.mapNormal,a.mapNormalRepeat,
  3219. a.mapNormalOffset,a.mapNormalWrap);a.mapSpecular&&b&&f(j,"specularMap",a.mapSpecular,a.mapSpecularRepeat,a.mapSpecularOffset,a.mapSpecularWrap);if(a.mapNormal){k=THREE.ShaderUtils.lib.normal;h=THREE.UniformsUtils.clone(k.uniforms);h.tNormal.texture=j.normalMap;if(a.mapNormalFactor)h.uNormalScale.value=a.mapNormalFactor;if(j.map){h.tDiffuse.texture=j.map;h.enableDiffuse.value=true}if(j.specularMap){h.tSpecular.texture=j.specularMap;h.enableSpecular.value=true}if(j.lightMap){h.tAO.texture=j.lightMap;
  3220. h.enableAO.value=true}h.uDiffuseColor.value.setHex(j.color);h.uSpecularColor.value.setHex(j.specular);h.uAmbientColor.value.setHex(j.ambient);h.uShininess.value=j.shininess;if(j.opacity!==void 0)h.uOpacity.value=j.opacity;j=new THREE.ShaderMaterial({fragmentShader:k.fragmentShader,vertexShader:k.vertexShader,uniforms:h,lights:true,fog:true})}else j=new THREE[k](j);if(a.DbgName!==void 0)j.name=a.DbgName;return j}};
  3221. THREE.Material=function(a){a=a||{};this.id=THREE.MaterialCount++;this.name="";this.opacity=a.opacity!==void 0?a.opacity:1;this.transparent=a.transparent!==void 0?a.transparent:false;this.blending=a.blending!==void 0?a.blending:THREE.NormalBlending;this.blendSrc=a.blendSrc!==void 0?a.blendSrc:THREE.SrcAlphaFactor;this.blendDst=a.blendDst!==void 0?a.blendDst:THREE.OneMinusSrcAlphaFactor;this.blendEquation=a.blendEquation!==void 0?a.blendEquation:THREE.AddEquation;this.depthTest=a.depthTest!==void 0?
  3222. a.depthTest:true;this.depthWrite=a.depthWrite!==void 0?a.depthWrite:true;this.polygonOffset=a.polygonOffset!==void 0?a.polygonOffset:false;this.polygonOffsetFactor=a.polygonOffsetFactor!==void 0?a.polygonOffsetFactor:0;this.polygonOffsetUnits=a.polygonOffsetUnits!==void 0?a.polygonOffsetUnits:0;this.alphaTest=a.alphaTest!==void 0?a.alphaTest:0;this.overdraw=a.overdraw!==void 0?a.overdraw:false;this.needsUpdate=this.visible=true};THREE.MaterialCount=0;THREE.NoShading=0;THREE.FlatShading=1;
  3223. THREE.SmoothShading=2;THREE.NoColors=0;THREE.FaceColors=1;THREE.VertexColors=2;THREE.NoBlending=0;THREE.NormalBlending=1;THREE.AdditiveBlending=2;THREE.SubtractiveBlending=3;THREE.MultiplyBlending=4;THREE.AdditiveAlphaBlending=5;THREE.CustomBlending=6;THREE.AddEquation=100;THREE.SubtractEquation=101;THREE.ReverseSubtractEquation=102;THREE.ZeroFactor=200;THREE.OneFactor=201;THREE.SrcColorFactor=202;THREE.OneMinusSrcColorFactor=203;THREE.SrcAlphaFactor=204;THREE.OneMinusSrcAlphaFactor=205;
  3224. THREE.DstAlphaFactor=206;THREE.OneMinusDstAlphaFactor=207;THREE.DstColorFactor=208;THREE.OneMinusDstColorFactor=209;THREE.SrcAlphaSaturateFactor=210;
  3225. THREE.LineBasicMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.linewidth=a.linewidth!==void 0?a.linewidth:1;this.linecap=a.linecap!==void 0?a.linecap:"round";this.linejoin=a.linejoin!==void 0?a.linejoin:"round";this.vertexColors=a.vertexColors?a.vertexColors:false;this.fog=a.fog!==void 0?a.fog:true};THREE.LineBasicMaterial.prototype=new THREE.Material;THREE.LineBasicMaterial.prototype.constructor=THREE.LineBasicMaterial;
  3226. THREE.MeshBasicMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.map=a.map!==void 0?a.map:null;this.lightMap=a.lightMap!==void 0?a.lightMap:null;this.envMap=a.envMap!==void 0?a.envMap:null;this.combine=a.combine!==void 0?a.combine:THREE.MultiplyOperation;this.reflectivity=a.reflectivity!==void 0?a.reflectivity:1;this.refractionRatio=a.refractionRatio!==void 0?a.refractionRatio:0.98;this.fog=a.fog!==void 0?a.fog:
  3227. true;this.shading=a.shading!==void 0?a.shading:THREE.SmoothShading;this.wireframe=a.wireframe!==void 0?a.wireframe:false;this.wireframeLinewidth=a.wireframeLinewidth!==void 0?a.wireframeLinewidth:1;this.wireframeLinecap=a.wireframeLinecap!==void 0?a.wireframeLinecap:"round";this.wireframeLinejoin=a.wireframeLinejoin!==void 0?a.wireframeLinejoin:"round";this.vertexColors=a.vertexColors!==void 0?a.vertexColors:THREE.NoColors;this.skinning=a.skinning!==void 0?a.skinning:false;this.morphTargets=a.morphTargets!==
  3228. void 0?a.morphTargets:false};THREE.MeshBasicMaterial.prototype=new THREE.Material;THREE.MeshBasicMaterial.prototype.constructor=THREE.MeshBasicMaterial;
  3229. THREE.ParticleBasicMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.map=a.map!==void 0?a.map:null;this.size=a.size!==void 0?a.size:1;this.sizeAttenuation=a.sizeAttenuation!==void 0?a.sizeAttenuation:true;this.vertexColors=a.vertexColors!==void 0?a.vertexColors:false;this.fog=a.fog!==void 0?a.fog:true};THREE.ParticleBasicMaterial.prototype=new THREE.Material;
  3230. THREE.ParticleBasicMaterial.prototype.constructor=THREE.ParticleBasicMaterial;THREE.ParticleDOMMaterial=function(a){THREE.Material.call(this);this.domElement=a};
  3231. THREE.Texture=function(a,b,c,d,e,f,g,i){this.id=THREE.TextureCount++;this.image=a;this.mapping=b!==void 0?b:new THREE.UVMapping;this.wrapS=c!==void 0?c:THREE.ClampToEdgeWrapping;this.wrapT=d!==void 0?d:THREE.ClampToEdgeWrapping;this.magFilter=e!==void 0?e:THREE.LinearFilter;this.minFilter=f!==void 0?f:THREE.LinearMipMapLinearFilter;this.format=g!==void 0?g:THREE.RGBAFormat;this.type=i!==void 0?i:THREE.UnsignedByteType;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.generateMipmaps=
  3232. true;this.needsUpdate=this.premultiplyAlpha=false;this.onUpdate=null};THREE.Texture.prototype={constructor:THREE.Texture,clone:function(){var a=new THREE.Texture(this.image,this.mapping,this.wrapS,this.wrapT,this.magFilter,this.minFilter,this.format,this.type);a.offset.copy(this.offset);a.repeat.copy(this.repeat);return a}};THREE.TextureCount=0;THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.UVMapping=function(){};THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};
  3233. THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.ByteType=9;THREE.UnsignedByteType=10;THREE.ShortType=11;THREE.UnsignedShortType=12;THREE.IntType=13;THREE.UnsignedIntType=14;THREE.FloatType=15;
  3234. THREE.AlphaFormat=16;THREE.RGBFormat=17;THREE.RGBAFormat=18;THREE.LuminanceFormat=19;THREE.LuminanceAlphaFormat=20;THREE.DataTexture=function(a,b,c,d,e,f,g,i,k,j){THREE.Texture.call(this,null,f,g,i,k,j,d,e);this.image={data:a,width:b,height:c}};THREE.DataTexture.prototype=new THREE.Texture;THREE.DataTexture.prototype.constructor=THREE.DataTexture;
  3235. THREE.DataTexture.prototype.clone=function(){var a=new THREE.DataTexture(this.image.data,this.image.width,this.image.height,this.format,this.type,this.mapping,this.wrapS,this.wrapT,this.magFilter,this.minFilter);a.offset.copy(this.offset);a.repeat.copy(this.repeat);return a};THREE.Particle=function(a){THREE.Object3D.call(this);this.material=a};THREE.Particle.prototype=new THREE.Object3D;THREE.Particle.prototype.constructor=THREE.Particle;
  3236. THREE.Mesh=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.material=b!==void 0?b:new THREE.MeshBasicMaterial({color:Math.random()*16777215,wireframe:true});if(this.geometry){this.geometry.boundingSphere||this.geometry.computeBoundingSphere();this.boundRadius=a.boundingSphere.radius;if(this.geometry.morphTargets.length){this.morphTargetBase=-1;this.morphTargetForcedOrder=[];this.morphTargetInfluences=[];this.morphTargetDictionary={};for(var c=0;c<this.geometry.morphTargets.length;c++){this.morphTargetInfluences.push(0);
  3237. this.morphTargetDictionary[this.geometry.morphTargets[c].name]=c}}}};THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;THREE.Mesh.prototype.supr=THREE.Object3D.prototype;THREE.Mesh.prototype.getMorphTargetIndexByName=function(a){if(this.morphTargetDictionary[a]!==void 0)return this.morphTargetDictionary[a];console.log("THREE.Mesh.getMorphTargetIndexByName: morph target "+a+" does not exist. Returning 0.");return 0};
  3238. THREE.Line=function(a,b,c){THREE.Object3D.call(this);this.geometry=a;this.material=b!==void 0?b:new THREE.LineBasicMaterial({color:Math.random()*16777215});this.type=c!==void 0?c:THREE.LineStrip;this.geometry&&(this.geometry.boundingSphere||this.geometry.computeBoundingSphere())};THREE.LineStrip=0;THREE.LinePieces=1;THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;THREE.Bone=function(a){THREE.Object3D.call(this);this.skin=a;this.skinMatrix=new THREE.Matrix4};
  3239. THREE.Bone.prototype=new THREE.Object3D;THREE.Bone.prototype.constructor=THREE.Bone;THREE.Bone.prototype.supr=THREE.Object3D.prototype;THREE.Bone.prototype.update=function(a,b){this.matrixAutoUpdate&&(b=b|this.updateMatrix());if(b||this.matrixWorldNeedsUpdate){a?this.skinMatrix.multiply(a,this.matrix):this.skinMatrix.copy(this.matrix);this.matrixWorldNeedsUpdate=false;b=true}var c,d=this.children.length;for(c=0;c<d;c++)this.children[c].update(this.skinMatrix,b)};
  3240. THREE.Sprite=function(a){THREE.Object3D.call(this);this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.map=a.map!==void 0?a.map:new THREE.Texture;this.blending=a.blending!==void 0?a.blending:THREE.NormalBlending;this.blendSrc=a.blendSrc!==void 0?a.blendSrc:THREE.SrcAlphaFactor;this.blendDst=a.blendDst!==void 0?a.blendDst:THREE.OneMinusSrcAlphaFactor;this.blendEquation=a.blendEquation!==void 0?a.blendEquation:THREE.AddEquation;this.useScreenCoordinates=a.useScreenCoordinates!==
  3241. void 0?a.useScreenCoordinates:true;this.mergeWith3D=a.mergeWith3D!==void 0?a.mergeWith3D:!this.useScreenCoordinates;this.affectedByDistance=a.affectedByDistance!==void 0?a.affectedByDistance:!this.useScreenCoordinates;this.scaleByViewport=a.scaleByViewport!==void 0?a.scaleByViewport:!this.affectedByDistance;this.alignment=a.alignment instanceof THREE.Vector2?a.alignment:THREE.SpriteAlignment.center;this.rotation3d=this.rotation;this.rotation=0;this.opacity=1;this.uvOffset=new THREE.Vector2(0,0);this.uvScale=
  3242. new THREE.Vector2(1,1)};THREE.Sprite.prototype=new THREE.Object3D;THREE.Sprite.prototype.constructor=THREE.Sprite;THREE.Sprite.prototype.updateMatrix=function(){this.matrix.setPosition(this.position);this.rotation3d.set(0,0,this.rotation);this.matrix.setRotationFromEuler(this.rotation3d);if(this.scale.x!==1||this.scale.y!==1){this.matrix.scale(this.scale);this.boundRadiusScale=Math.max(this.scale.x,this.scale.y)}this.matrixWorldNeedsUpdate=true};THREE.SpriteAlignment={};
  3243. THREE.SpriteAlignment.topLeft=new THREE.Vector2(1,-1);THREE.SpriteAlignment.topCenter=new THREE.Vector2(0,-1);THREE.SpriteAlignment.topRight=new THREE.Vector2(-1,-1);THREE.SpriteAlignment.centerLeft=new THREE.Vector2(1,0);THREE.SpriteAlignment.center=new THREE.Vector2(0,0);THREE.SpriteAlignment.centerRight=new THREE.Vector2(-1,0);THREE.SpriteAlignment.bottomLeft=new THREE.Vector2(1,1);THREE.SpriteAlignment.bottomCenter=new THREE.Vector2(0,1);
  3244. THREE.SpriteAlignment.bottomRight=new THREE.Vector2(-1,1);THREE.Scene=function(){THREE.Object3D.call(this);this.overrideMaterial=this.fog=null;this.matrixAutoUpdate=false;this.__objects=[];this.__lights=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;
  3245. THREE.Scene.prototype.__addObject=function(a){if(a instanceof THREE.Light)this.__lights.indexOf(a)===-1&&this.__lights.push(a);else if(!(a instanceof THREE.Camera||a instanceof THREE.Bone)&&this.__objects.indexOf(a)===-1){this.__objects.push(a);this.__objectsAdded.push(a);var b=this.__objectsRemoved.indexOf(a);b!==-1&&this.__objectsRemoved.splice(b,1)}for(b=0;b<a.children.length;b++)this.__addObject(a.children[b])};
  3246. THREE.Scene.prototype.__removeObject=function(a){if(a instanceof THREE.Light){var b=this.__lights.indexOf(a);b!==-1&&this.__lights.splice(b,1)}else if(!(a instanceof THREE.Camera)){b=this.__objects.indexOf(a);if(b!==-1){this.__objects.splice(b,1);this.__objectsRemoved.push(a);b=this.__objectsAdded.indexOf(a);b!==-1&&this.__objectsAdded.splice(b,1)}}for(b=0;b<a.children.length;b++)this.__removeObject(a.children[b])};
  3247. THREE.DOMRenderer=function(){console.log("THREE.DOMRenderer",THREE.REVISION);var a,b,c,d,e,f,g,i=new THREE.Projector;g=function(a){for(var b=document.documentElement,c=0;c<a.length;c++)if(typeof b.style[a[c]]==="string")return a[c];return null}(["transform","MozTransform","WebkitTransform","msTransform","OTransform"]);this.domElement=document.createElement("div");this.setSize=function(a,b){c=a;d=b;e=c/2;f=d/2};this.render=function(c,d){var h,m,l,n,p,o;a=i.projectScene(c,d);b=a.elements;h=0;for(m=
  3248. b.length;h<m;h++){l=b[h];if(l instanceof THREE.RenderableParticle&&l.material instanceof THREE.ParticleDOMMaterial){n=l.material.domElement;p=l.x*e+e-(n.offsetWidth>>1);o=l.y*f+f-(n.offsetHeight>>1);n.style.left=p+"px";n.style.top=o+"px";n.style.zIndex=Math.abs(Math.floor((1-l.z)*d.far/d.near));g&&(n.style[g]="scale("+l.scale.x*e+","+l.scale.y*f+")")}}}};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};
  3249. THREE.RenderableVertex=function(){this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.visible=true};THREE.RenderableVertex.prototype.copy=function(a){this.positionWorld.copy(a.positionWorld);this.positionScreen.copy(a.positionScreen)};
  3250. THREE.RenderableFace3=function(){this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.v3=new THREE.RenderableVertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterial=this.material=null;this.uvs=[[]];this.z=null};
  3251. THREE.RenderableFace4=function(){this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.v3=new THREE.RenderableVertex;this.v4=new THREE.RenderableVertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterial=this.material=null;this.uvs=[[]];this.z=null};THREE.RenderableObject=function(){this.z=this.object=null};
  3252. THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.material=null};
  3253. >>>>>>> dev