ThreeSVG.js 232 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537
  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 kile / http://kile.stravaganza.org/
  2376. * @author alteredq / http://alteredqualia.com/
  2377. * @author mikael emtinger / http://gomo.se/
  2378. * @author zz85 / http://www.lab4games.net/zz85/blog
  2379. */
  2380. THREE.Geometry = function () {
  2381. this.id = THREE.GeometryCount ++;
  2382. this.vertices = [];
  2383. this.colors = []; // one-to-one vertex colors, used in ParticleSystem, Line and Ribbon
  2384. this.materials = [];
  2385. this.faces = [];
  2386. this.faceUvs = [[]];
  2387. this.faceVertexUvs = [[]];
  2388. this.morphTargets = [];
  2389. this.morphColors = [];
  2390. this.morphNormals = [];
  2391. this.skinWeights = [];
  2392. this.skinIndices = [];
  2393. this.boundingBox = null;
  2394. this.boundingSphere = null;
  2395. this.hasTangents = false;
  2396. this.dynamic = false; // unless set to true the *Arrays will be deleted once sent to a buffer.
  2397. };
  2398. THREE.Geometry.prototype = {
  2399. constructor : THREE.Geometry,
  2400. applyMatrix: function ( matrix ) {
  2401. var matrixRotation = new THREE.Matrix4();
  2402. matrixRotation.extractRotation( matrix );
  2403. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  2404. var vertex = this.vertices[ i ];
  2405. matrix.multiplyVector3( vertex );
  2406. }
  2407. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  2408. var face = this.faces[ i ];
  2409. matrixRotation.multiplyVector3( face.normal );
  2410. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  2411. matrixRotation.multiplyVector3( face.vertexNormals[ j ] );
  2412. }
  2413. matrix.multiplyVector3( face.centroid );
  2414. }
  2415. },
  2416. computeCentroids: function () {
  2417. var f, fl, face;
  2418. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2419. face = this.faces[ f ];
  2420. face.centroid.set( 0, 0, 0 );
  2421. if ( face instanceof THREE.Face3 ) {
  2422. face.centroid.addSelf( this.vertices[ face.a ] );
  2423. face.centroid.addSelf( this.vertices[ face.b ] );
  2424. face.centroid.addSelf( this.vertices[ face.c ] );
  2425. face.centroid.divideScalar( 3 );
  2426. } else if ( face instanceof THREE.Face4 ) {
  2427. face.centroid.addSelf( this.vertices[ face.a ] );
  2428. face.centroid.addSelf( this.vertices[ face.b ] );
  2429. face.centroid.addSelf( this.vertices[ face.c ] );
  2430. face.centroid.addSelf( this.vertices[ face.d ] );
  2431. face.centroid.divideScalar( 4 );
  2432. }
  2433. }
  2434. },
  2435. computeFaceNormals: function () {
  2436. var n, nl, v, vl, vertex, f, fl, face, vA, vB, vC,
  2437. cb = new THREE.Vector3(), ab = new THREE.Vector3();
  2438. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2439. face = this.faces[ f ];
  2440. vA = this.vertices[ face.a ];
  2441. vB = this.vertices[ face.b ];
  2442. vC = this.vertices[ face.c ];
  2443. cb.sub( vC, vB );
  2444. ab.sub( vA, vB );
  2445. cb.crossSelf( ab );
  2446. if ( !cb.isZero() ) {
  2447. cb.normalize();
  2448. }
  2449. face.normal.copy( cb );
  2450. }
  2451. },
  2452. computeVertexNormals: function () {
  2453. var v, vl, f, fl, face, vertices;
  2454. // create internal buffers for reuse when calling this method repeatedly
  2455. // (otherwise memory allocation / deallocation every frame is big resource hog)
  2456. if ( this.__tmpVertices === undefined ) {
  2457. this.__tmpVertices = new Array( this.vertices.length );
  2458. vertices = this.__tmpVertices;
  2459. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  2460. vertices[ v ] = new THREE.Vector3();
  2461. }
  2462. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2463. face = this.faces[ f ];
  2464. if ( face instanceof THREE.Face3 ) {
  2465. face.vertexNormals = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  2466. } else if ( face instanceof THREE.Face4 ) {
  2467. face.vertexNormals = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  2468. }
  2469. }
  2470. } else {
  2471. vertices = this.__tmpVertices;
  2472. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  2473. vertices[ v ].set( 0, 0, 0 );
  2474. }
  2475. }
  2476. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2477. face = this.faces[ f ];
  2478. if ( face instanceof THREE.Face3 ) {
  2479. vertices[ face.a ].addSelf( face.normal );
  2480. vertices[ face.b ].addSelf( face.normal );
  2481. vertices[ face.c ].addSelf( face.normal );
  2482. } else if ( face instanceof THREE.Face4 ) {
  2483. vertices[ face.a ].addSelf( face.normal );
  2484. vertices[ face.b ].addSelf( face.normal );
  2485. vertices[ face.c ].addSelf( face.normal );
  2486. vertices[ face.d ].addSelf( face.normal );
  2487. }
  2488. }
  2489. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  2490. vertices[ v ].normalize();
  2491. }
  2492. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2493. face = this.faces[ f ];
  2494. if ( face instanceof THREE.Face3 ) {
  2495. face.vertexNormals[ 0 ].copy( vertices[ face.a ] );
  2496. face.vertexNormals[ 1 ].copy( vertices[ face.b ] );
  2497. face.vertexNormals[ 2 ].copy( vertices[ face.c ] );
  2498. } else if ( face instanceof THREE.Face4 ) {
  2499. face.vertexNormals[ 0 ].copy( vertices[ face.a ] );
  2500. face.vertexNormals[ 1 ].copy( vertices[ face.b ] );
  2501. face.vertexNormals[ 2 ].copy( vertices[ face.c ] );
  2502. face.vertexNormals[ 3 ].copy( vertices[ face.d ] );
  2503. }
  2504. }
  2505. },
  2506. computeMorphNormals: function () {
  2507. var i, il, f, fl, face;
  2508. // save original normals
  2509. // - create temp variables on first access
  2510. // otherwise just copy (for faster repeated calls)
  2511. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2512. face = this.faces[ f ];
  2513. if ( ! face.__originalFaceNormal ) {
  2514. face.__originalFaceNormal = face.normal.clone();
  2515. } else {
  2516. face.__originalFaceNormal.copy( face.normal );
  2517. }
  2518. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  2519. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  2520. if ( ! face.__originalVertexNormals[ i ] ) {
  2521. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  2522. } else {
  2523. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  2524. }
  2525. }
  2526. }
  2527. // use temp geometry to compute face and vertex normals for each morph
  2528. var tmpGeo = new THREE.Geometry();
  2529. tmpGeo.faces = this.faces;
  2530. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  2531. // create on first access
  2532. if ( ! this.morphNormals[ i ] ) {
  2533. this.morphNormals[ i ] = {};
  2534. this.morphNormals[ i ].faceNormals = [];
  2535. this.morphNormals[ i ].vertexNormals = [];
  2536. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  2537. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  2538. var faceNormal, vertexNormals;
  2539. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2540. face = this.faces[ f ];
  2541. faceNormal = new THREE.Vector3();
  2542. if ( face instanceof THREE.Face3 ) {
  2543. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  2544. } else {
  2545. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3(), d: new THREE.Vector3() };
  2546. }
  2547. dstNormalsFace.push( faceNormal );
  2548. dstNormalsVertex.push( vertexNormals );
  2549. }
  2550. }
  2551. var morphNormals = this.morphNormals[ i ];
  2552. // set vertices to morph target
  2553. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  2554. // compute morph normals
  2555. tmpGeo.computeFaceNormals();
  2556. tmpGeo.computeVertexNormals();
  2557. // store morph normals
  2558. var faceNormal, vertexNormals;
  2559. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2560. face = this.faces[ f ];
  2561. faceNormal = morphNormals.faceNormals[ f ];
  2562. vertexNormals = morphNormals.vertexNormals[ f ];
  2563. faceNormal.copy( face.normal );
  2564. if ( face instanceof THREE.Face3 ) {
  2565. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  2566. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  2567. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  2568. } else {
  2569. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  2570. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  2571. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  2572. vertexNormals.d.copy( face.vertexNormals[ 3 ] );
  2573. }
  2574. }
  2575. }
  2576. // restore original normals
  2577. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2578. face = this.faces[ f ];
  2579. face.normal = face.__originalFaceNormal;
  2580. face.vertexNormals = face.__originalVertexNormals;
  2581. }
  2582. },
  2583. computeTangents: function () {
  2584. // based on http://www.terathon.com/code/tangent.html
  2585. // tangents go to vertices
  2586. var f, fl, v, vl, i, il, vertexIndex,
  2587. face, uv, vA, vB, vC, uvA, uvB, uvC,
  2588. x1, x2, y1, y2, z1, z2,
  2589. s1, s2, t1, t2, r, t, test,
  2590. tan1 = [], tan2 = [],
  2591. sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
  2592. tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(),
  2593. n = new THREE.Vector3(), w;
  2594. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  2595. tan1[ v ] = new THREE.Vector3();
  2596. tan2[ v ] = new THREE.Vector3();
  2597. }
  2598. function handleTriangle( context, a, b, c, ua, ub, uc ) {
  2599. vA = context.vertices[ a ];
  2600. vB = context.vertices[ b ];
  2601. vC = context.vertices[ c ];
  2602. uvA = uv[ ua ];
  2603. uvB = uv[ ub ];
  2604. uvC = uv[ uc ];
  2605. x1 = vB.x - vA.x;
  2606. x2 = vC.x - vA.x;
  2607. y1 = vB.y - vA.y;
  2608. y2 = vC.y - vA.y;
  2609. z1 = vB.z - vA.z;
  2610. z2 = vC.z - vA.z;
  2611. s1 = uvB.u - uvA.u;
  2612. s2 = uvC.u - uvA.u;
  2613. t1 = uvB.v - uvA.v;
  2614. t2 = uvC.v - uvA.v;
  2615. r = 1.0 / ( s1 * t2 - s2 * t1 );
  2616. sdir.set( ( t2 * x1 - t1 * x2 ) * r,
  2617. ( t2 * y1 - t1 * y2 ) * r,
  2618. ( t2 * z1 - t1 * z2 ) * r );
  2619. tdir.set( ( s1 * x2 - s2 * x1 ) * r,
  2620. ( s1 * y2 - s2 * y1 ) * r,
  2621. ( s1 * z2 - s2 * z1 ) * r );
  2622. tan1[ a ].addSelf( sdir );
  2623. tan1[ b ].addSelf( sdir );
  2624. tan1[ c ].addSelf( sdir );
  2625. tan2[ a ].addSelf( tdir );
  2626. tan2[ b ].addSelf( tdir );
  2627. tan2[ c ].addSelf( tdir );
  2628. }
  2629. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2630. face = this.faces[ f ];
  2631. uv = this.faceVertexUvs[ 0 ][ f ]; // use UV layer 0 for tangents
  2632. if ( face instanceof THREE.Face3 ) {
  2633. handleTriangle( this, face.a, face.b, face.c, 0, 1, 2 );
  2634. } else if ( face instanceof THREE.Face4 ) {
  2635. handleTriangle( this, face.a, face.b, face.d, 0, 1, 3 );
  2636. handleTriangle( this, face.b, face.c, face.d, 1, 2, 3 );
  2637. }
  2638. }
  2639. var faceIndex = [ 'a', 'b', 'c', 'd' ];
  2640. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2641. face = this.faces[ f ];
  2642. for ( i = 0; i < face.vertexNormals.length; i++ ) {
  2643. n.copy( face.vertexNormals[ i ] );
  2644. vertexIndex = face[ faceIndex[ i ] ];
  2645. t = tan1[ vertexIndex ];
  2646. // Gram-Schmidt orthogonalize
  2647. tmp.copy( t );
  2648. tmp.subSelf( n.multiplyScalar( n.dot( t ) ) ).normalize();
  2649. // Calculate handedness
  2650. tmp2.cross( face.vertexNormals[ i ], t );
  2651. test = tmp2.dot( tan2[ vertexIndex ] );
  2652. w = (test < 0.0) ? -1.0 : 1.0;
  2653. face.vertexTangents[ i ] = new THREE.Vector4( tmp.x, tmp.y, tmp.z, w );
  2654. }
  2655. }
  2656. this.hasTangents = true;
  2657. },
  2658. computeBoundingBox: function () {
  2659. if ( ! this.boundingBox ) {
  2660. this.boundingBox = { min: new THREE.Vector3(), max: new THREE.Vector3() };
  2661. }
  2662. if ( this.vertices.length > 0 ) {
  2663. var position, firstPosition = this.vertices[ 0 ];
  2664. this.boundingBox.min.copy( firstPosition );
  2665. this.boundingBox.max.copy( firstPosition );
  2666. var min = this.boundingBox.min,
  2667. max = this.boundingBox.max;
  2668. for ( var v = 1, vl = this.vertices.length; v < vl; v ++ ) {
  2669. position = this.vertices[ v ];
  2670. if ( position.x < min.x ) {
  2671. min.x = position.x;
  2672. } else if ( position.x > max.x ) {
  2673. max.x = position.x;
  2674. }
  2675. if ( position.y < min.y ) {
  2676. min.y = position.y;
  2677. } else if ( position.y > max.y ) {
  2678. max.y = position.y;
  2679. }
  2680. if ( position.z < min.z ) {
  2681. min.z = position.z;
  2682. } else if ( position.z > max.z ) {
  2683. max.z = position.z;
  2684. }
  2685. }
  2686. } else {
  2687. this.boundingBox.min.set( 0, 0, 0 );
  2688. this.boundingBox.max.set( 0, 0, 0 );
  2689. }
  2690. },
  2691. computeBoundingSphere: function () {
  2692. if ( ! this.boundingSphere ) this.boundingSphere = { radius: 0 };
  2693. var radius, maxRadius = 0;
  2694. for ( var v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  2695. radius = this.vertices[ v ].length();
  2696. if ( radius > maxRadius ) maxRadius = radius;
  2697. }
  2698. this.boundingSphere.radius = maxRadius;
  2699. },
  2700. /*
  2701. * Checks for duplicate vertices with hashmap.
  2702. * Duplicated vertices are removed
  2703. * and faces' vertices are updated.
  2704. */
  2705. mergeVertices: function() {
  2706. var verticesMap = {}; // Hashmap for looking up vertice by position coordinates (and making sure they are unique)
  2707. var unique = [], changes = [];
  2708. var v, key;
  2709. var precisionPoints = 4; // number of decimal points, eg. 4 for epsilon of 0.0001
  2710. var precision = Math.pow( 10, precisionPoints );
  2711. var i,il, face;
  2712. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  2713. v = this.vertices[ i ];
  2714. key = [ Math.round( v.x * precision ), Math.round( v.y * precision ), Math.round( v.z * precision ) ].join( '_' );
  2715. if ( verticesMap[ key ] === undefined ) {
  2716. verticesMap[ key ] = i;
  2717. unique.push( this.vertices[ i ] );
  2718. changes[ i ] = unique.length - 1;
  2719. } else {
  2720. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  2721. changes[ i ] = changes[ verticesMap[ key ] ];
  2722. }
  2723. };
  2724. // Start to patch face indices
  2725. for( i = 0, il = this.faces.length; i < il; i ++ ) {
  2726. face = this.faces[ i ];
  2727. if ( face instanceof THREE.Face3 ) {
  2728. face.a = changes[ face.a ];
  2729. face.b = changes[ face.b ];
  2730. face.c = changes[ face.c ];
  2731. } else if ( face instanceof THREE.Face4 ) {
  2732. face.a = changes[ face.a ];
  2733. face.b = changes[ face.b ];
  2734. face.c = changes[ face.c ];
  2735. face.d = changes[ face.d ];
  2736. }
  2737. }
  2738. // Use unique set of vertices
  2739. this.vertices = unique;
  2740. }
  2741. };
  2742. THREE.GeometryCount = 0;
  2743. /**
  2744. * @author mr.doob / http://mrdoob.com/
  2745. * @author mikael emtinger / http://gomo.se/
  2746. */
  2747. THREE.Camera = function () {
  2748. THREE.Object3D.call( this );
  2749. this.matrixWorldInverse = new THREE.Matrix4();
  2750. this.projectionMatrix = new THREE.Matrix4();
  2751. this.projectionMatrixInverse = new THREE.Matrix4();
  2752. };
  2753. THREE.Camera.prototype = new THREE.Object3D();
  2754. THREE.Camera.prototype.constructor = THREE.Camera;
  2755. THREE.Camera.prototype.lookAt = function ( vector ) {
  2756. // TODO: Add hierarchy support.
  2757. this.matrix.lookAt( this.position, vector, this.up );
  2758. if ( this.rotationAutoUpdate ) {
  2759. this.rotation.getRotationFromMatrix( this.matrix );
  2760. }
  2761. };
  2762. /**
  2763. * @author alteredq / http://alteredqualia.com/
  2764. */
  2765. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  2766. THREE.Camera.call( this );
  2767. this.left = left;
  2768. this.right = right;
  2769. this.top = top;
  2770. this.bottom = bottom;
  2771. this.near = ( near !== undefined ) ? near : 0.1;
  2772. this.far = ( far !== undefined ) ? far : 2000;
  2773. this.updateProjectionMatrix();
  2774. };
  2775. THREE.OrthographicCamera.prototype = new THREE.Camera();
  2776. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  2777. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  2778. this.projectionMatrix.makeOrthographic( this.left, this.right, this.top, this.bottom, this.near, this.far );
  2779. };
  2780. /**
  2781. * @author mr.doob / http://mrdoob.com/
  2782. * @author greggman / http://games.greggman.com/
  2783. * @author zz85 / http://www.lab4games.net/zz85/blog
  2784. */
  2785. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  2786. THREE.Camera.call( this );
  2787. this.fov = fov !== undefined ? fov : 50;
  2788. this.aspect = aspect !== undefined ? aspect : 1;
  2789. this.near = near !== undefined ? near : 0.1;
  2790. this.far = far !== undefined ? far : 2000;
  2791. this.updateProjectionMatrix();
  2792. };
  2793. THREE.PerspectiveCamera.prototype = new THREE.Camera();
  2794. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  2795. /**
  2796. * Uses Focal Length (in mm) to estimate and set FOV
  2797. * 35mm (fullframe) camera is used if frame size is not specified;
  2798. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  2799. */
  2800. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  2801. frameHeight = frameHeight !== undefined ? frameHeight : 24;
  2802. this.fov = 2 * Math.atan( frameHeight / ( focalLength * 2 ) ) * ( 180 / Math.PI );
  2803. this.updateProjectionMatrix();
  2804. }
  2805. /**
  2806. * Sets an offset in a larger frustum. This is useful for multi-window or
  2807. * multi-monitor/multi-machine setups.
  2808. *
  2809. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  2810. * the monitors are in grid like this
  2811. *
  2812. * +---+---+---+
  2813. * | A | B | C |
  2814. * +---+---+---+
  2815. * | D | E | F |
  2816. * +---+---+---+
  2817. *
  2818. * then for each monitor you would call it like this
  2819. *
  2820. * var w = 1920;
  2821. * var h = 1080;
  2822. * var fullWidth = w * 3;
  2823. * var fullHeight = h * 2;
  2824. *
  2825. * --A--
  2826. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  2827. * --B--
  2828. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  2829. * --C--
  2830. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  2831. * --D--
  2832. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  2833. * --E--
  2834. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  2835. * --F--
  2836. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  2837. *
  2838. * Note there is no reason monitors have to be the same size or in a grid.
  2839. */
  2840. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  2841. this.fullWidth = fullWidth;
  2842. this.fullHeight = fullHeight;
  2843. this.x = x;
  2844. this.y = y;
  2845. this.width = width;
  2846. this.height = height;
  2847. this.updateProjectionMatrix();
  2848. };
  2849. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  2850. if ( this.fullWidth ) {
  2851. var aspect = this.fullWidth / this.fullHeight;
  2852. var top = Math.tan( this.fov * Math.PI / 360 ) * this.near;
  2853. var bottom = -top;
  2854. var left = aspect * bottom;
  2855. var right = aspect * top;
  2856. var width = Math.abs( right - left );
  2857. var height = Math.abs( top - bottom );
  2858. this.projectionMatrix.makeFrustum(
  2859. left + this.x * width / this.fullWidth,
  2860. left + ( this.x + this.width ) * width / this.fullWidth,
  2861. top - ( this.y + this.height ) * height / this.fullHeight,
  2862. top - this.y * height / this.fullHeight,
  2863. this.near,
  2864. this.far
  2865. );
  2866. } else {
  2867. this.projectionMatrix.makePerspective( this.fov, this.aspect, this.near, this.far );
  2868. }
  2869. };
  2870. /**
  2871. * @author mr.doob / http://mrdoob.com/
  2872. * @author alteredq / http://alteredqualia.com/
  2873. */
  2874. THREE.Light = function ( hex ) {
  2875. THREE.Object3D.call( this );
  2876. this.color = new THREE.Color( hex );
  2877. };
  2878. THREE.Light.prototype = new THREE.Object3D();
  2879. THREE.Light.prototype.constructor = THREE.Light;
  2880. THREE.Light.prototype.supr = THREE.Object3D.prototype;
  2881. /**
  2882. * @author mr.doob / http://mrdoob.com/
  2883. */
  2884. THREE.AmbientLight = function ( hex ) {
  2885. THREE.Light.call( this, hex );
  2886. };
  2887. THREE.AmbientLight.prototype = new THREE.Light();
  2888. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  2889. /**
  2890. * @author mr.doob / http://mrdoob.com/
  2891. * @author alteredq / http://alteredqualia.com/
  2892. */
  2893. THREE.DirectionalLight = function ( hex, intensity, distance ) {
  2894. THREE.Light.call( this, hex );
  2895. this.position = new THREE.Vector3( 0, 1, 0 );
  2896. this.target = new THREE.Object3D();
  2897. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  2898. this.distance = ( distance !== undefined ) ? distance : 0;
  2899. this.castShadow = false;
  2900. this.onlyShadow = false;
  2901. //
  2902. this.shadowCameraNear = 50;
  2903. this.shadowCameraFar = 5000;
  2904. this.shadowCameraLeft = -500;
  2905. this.shadowCameraRight = 500;
  2906. this.shadowCameraTop = 500;
  2907. this.shadowCameraBottom = -500;
  2908. this.shadowCameraVisible = false;
  2909. this.shadowBias = 0;
  2910. this.shadowDarkness = 0.5;
  2911. this.shadowMapWidth = 512;
  2912. this.shadowMapHeight = 512;
  2913. //
  2914. this.shadowCascade = false;
  2915. this.shadowCascadeOffset = new THREE.Vector3( 0, 0, -1000 );
  2916. this.shadowCascadeCount = 2;
  2917. this.shadowCascadeBias = [ 0, 0, 0 ];
  2918. this.shadowCascadeWidth = [ 512, 512, 512 ];
  2919. this.shadowCascadeHeight = [ 512, 512, 512 ];
  2920. this.shadowCascadeNearZ = [ -1.000, 0.990, 0.998 ];
  2921. this.shadowCascadeFarZ = [ 0.990, 0.998, 1.000 ];
  2922. this.shadowCascadeArray = [];
  2923. //
  2924. this.shadowMap = null;
  2925. this.shadowMapSize = null;
  2926. this.shadowCamera = null;
  2927. this.shadowMatrix = null;
  2928. };
  2929. THREE.DirectionalLight.prototype = new THREE.Light();
  2930. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  2931. /**
  2932. * @author mr.doob / http://mrdoob.com/
  2933. */
  2934. THREE.PointLight = function ( hex, intensity, distance ) {
  2935. THREE.Light.call( this, hex );
  2936. this.position = new THREE.Vector3( 0, 0, 0 );
  2937. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  2938. this.distance = ( distance !== undefined ) ? distance : 0;
  2939. };
  2940. THREE.PointLight.prototype = new THREE.Light();
  2941. THREE.PointLight.prototype.constructor = THREE.PointLight;
  2942. /**
  2943. * @author mr.doob / http://mrdoob.com/
  2944. * @author alteredq / http://alteredqualia.com/
  2945. */
  2946. THREE.Material = function ( parameters ) {
  2947. parameters = parameters || {};
  2948. this.id = THREE.MaterialCount ++;
  2949. this.name = '';
  2950. this.opacity = parameters.opacity !== undefined ? parameters.opacity : 1;
  2951. this.transparent = parameters.transparent !== undefined ? parameters.transparent : false;
  2952. this.blending = parameters.blending !== undefined ? parameters.blending : THREE.NormalBlending;
  2953. this.blendSrc = parameters.blendSrc !== undefined ? parameters.blendSrc : THREE.SrcAlphaFactor;
  2954. this.blendDst = parameters.blendDst !== undefined ? parameters.blendDst : THREE.OneMinusSrcAlphaFactor;
  2955. this.blendEquation = parameters.blendEquation !== undefined ? parameters.blendEquation : THREE.AddEquation;
  2956. this.depthTest = parameters.depthTest !== undefined ? parameters.depthTest : true;
  2957. this.depthWrite = parameters.depthWrite !== undefined ? parameters.depthWrite : true;
  2958. this.polygonOffset = parameters.polygonOffset !== undefined ? parameters.polygonOffset : false;
  2959. this.polygonOffsetFactor = parameters.polygonOffsetFactor !== undefined ? parameters.polygonOffsetFactor : 0;
  2960. this.polygonOffsetUnits = parameters.polygonOffsetUnits !== undefined ? parameters.polygonOffsetUnits : 0;
  2961. this.alphaTest = parameters.alphaTest !== undefined ? parameters.alphaTest : 0;
  2962. this.overdraw = parameters.overdraw !== undefined ? parameters.overdraw : false; // Boolean for fixing antialiasing gaps in CanvasRenderer
  2963. this.needsUpdate = true;
  2964. }
  2965. THREE.MaterialCount = 0;
  2966. // shading
  2967. THREE.NoShading = 0;
  2968. THREE.FlatShading = 1;
  2969. THREE.SmoothShading = 2;
  2970. // colors
  2971. THREE.NoColors = 0;
  2972. THREE.FaceColors = 1;
  2973. THREE.VertexColors = 2;
  2974. // blending modes
  2975. THREE.NoBlending = 0;
  2976. THREE.NormalBlending = 1;
  2977. THREE.AdditiveBlending = 2;
  2978. THREE.SubtractiveBlending = 3;
  2979. THREE.MultiplyBlending = 4;
  2980. THREE.AdditiveAlphaBlending = 5;
  2981. THREE.CustomBlending = 6;
  2982. // custom blending equations
  2983. // (numbers start from 100 not to clash with other
  2984. // mappings to OpenGL constants defined in Texture.js)
  2985. THREE.AddEquation = 100;
  2986. THREE.SubtractEquation = 101;
  2987. THREE.ReverseSubtractEquation = 102;
  2988. // custom blending destination factors
  2989. THREE.ZeroFactor = 200;
  2990. THREE.OneFactor = 201;
  2991. THREE.SrcColorFactor = 202;
  2992. THREE.OneMinusSrcColorFactor = 203;
  2993. THREE.SrcAlphaFactor = 204;
  2994. THREE.OneMinusSrcAlphaFactor = 205;
  2995. THREE.DstAlphaFactor = 206;
  2996. THREE.OneMinusDstAlphaFactor = 207;
  2997. // custom blending source factors
  2998. //THREE.ZeroFactor = 200;
  2999. //THREE.OneFactor = 201;
  3000. //THREE.SrcAlphaFactor = 204;
  3001. //THREE.OneMinusSrcAlphaFactor = 205;
  3002. //THREE.DstAlphaFactor = 206;
  3003. //THREE.OneMinusDstAlphaFactor = 207;
  3004. THREE.DstColorFactor = 208;
  3005. THREE.OneMinusDstColorFactor = 209;
  3006. THREE.SrcAlphaSaturateFactor = 210;
  3007. /**
  3008. * @author mr.doob / http://mrdoob.com/
  3009. * @author alteredq / http://alteredqualia.com/
  3010. *
  3011. * parameters = {
  3012. * color: <hex>,
  3013. * opacity: <float>,
  3014. *
  3015. * blending: THREE.NormalBlending,
  3016. * depthTest: <bool>,
  3017. *
  3018. * linewidth: <float>,
  3019. * linecap: "round",
  3020. * linejoin: "round",
  3021. *
  3022. * vertexColors: <bool>
  3023. *
  3024. * fog: <bool>
  3025. * }
  3026. */
  3027. THREE.LineBasicMaterial = function ( parameters ) {
  3028. THREE.Material.call( this, parameters );
  3029. parameters = parameters || {};
  3030. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3031. this.linewidth = parameters.linewidth !== undefined ? parameters.linewidth : 1;
  3032. this.linecap = parameters.linecap !== undefined ? parameters.linecap : 'round';
  3033. this.linejoin = parameters.linejoin !== undefined ? parameters.linejoin : 'round';
  3034. this.vertexColors = parameters.vertexColors ? parameters.vertexColors : false;
  3035. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3036. };
  3037. THREE.LineBasicMaterial.prototype = new THREE.Material();
  3038. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  3039. /**
  3040. * @author mr.doob / http://mrdoob.com/
  3041. * @author alteredq / http://alteredqualia.com/
  3042. *
  3043. * parameters = {
  3044. * color: <hex>,
  3045. * opacity: <float>,
  3046. * map: new THREE.Texture( <Image> ),
  3047. *
  3048. * lightMap: new THREE.Texture( <Image> ),
  3049. *
  3050. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  3051. * combine: THREE.Multiply,
  3052. * reflectivity: <float>,
  3053. * refractionRatio: <float>,
  3054. *
  3055. * shading: THREE.SmoothShading,
  3056. * blending: THREE.NormalBlending,
  3057. * depthTest: <bool>,
  3058. *
  3059. * wireframe: <boolean>,
  3060. * wireframeLinewidth: <float>,
  3061. *
  3062. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  3063. *
  3064. * skinning: <bool>,
  3065. * morphTargets: <bool>,
  3066. *
  3067. * fog: <bool>
  3068. * }
  3069. */
  3070. THREE.MeshBasicMaterial = function ( parameters ) {
  3071. THREE.Material.call( this, parameters );
  3072. parameters = parameters || {};
  3073. // color property represents emissive for MeshBasicMaterial
  3074. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3075. this.map = parameters.map !== undefined ? parameters.map : null;
  3076. this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null;
  3077. this.envMap = parameters.envMap !== undefined ? parameters.envMap : null;
  3078. this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation;
  3079. this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1;
  3080. this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98;
  3081. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3082. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
  3083. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3084. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3085. this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round';
  3086. this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round';
  3087. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors;
  3088. this.skinning = parameters.skinning !== undefined ? parameters.skinning : false;
  3089. this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false;
  3090. };
  3091. THREE.MeshBasicMaterial.prototype = new THREE.Material();
  3092. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  3093. /**
  3094. * @author mr.doob / http://mrdoob.com/
  3095. * @author alteredq / http://alteredqualia.com/
  3096. *
  3097. * parameters = {
  3098. * color: <hex>,
  3099. * ambient: <hex>,
  3100. * emissive: <hex>,
  3101. * opacity: <float>,
  3102. *
  3103. * map: new THREE.Texture( <Image> ),
  3104. *
  3105. * lightMap: new THREE.Texture( <Image> ),
  3106. *
  3107. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  3108. * combine: THREE.Multiply,
  3109. * reflectivity: <float>,
  3110. * refractionRatio: <float>,
  3111. *
  3112. * shading: THREE.SmoothShading,
  3113. * blending: THREE.NormalBlending,
  3114. * depthTest: <bool>,
  3115. *
  3116. * wireframe: <boolean>,
  3117. * wireframeLinewidth: <float>,
  3118. *
  3119. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  3120. *
  3121. * skinning: <bool>,
  3122. * morphTargets: <bool>,
  3123. * morphNormals: <bool>,
  3124. *
  3125. * fog: <bool>
  3126. * }
  3127. */
  3128. THREE.MeshLambertMaterial = function ( parameters ) {
  3129. THREE.Material.call( this, parameters );
  3130. parameters = parameters || {};
  3131. // color property represents diffuse for MeshLambertMaterial
  3132. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3133. this.ambient = parameters.ambient !== undefined ? new THREE.Color( parameters.ambient ) : new THREE.Color( 0xffffff );
  3134. this.emissive = parameters.emissive !== undefined ? new THREE.Color( parameters.emissive ) : new THREE.Color( 0x000000 );
  3135. this.wrapAround = parameters.wrapAround !== undefined ? parameters.wrapAround: false;
  3136. this.wrapRGB = new THREE.Vector3( 1, 1, 1 );
  3137. this.map = parameters.map !== undefined ? parameters.map : null;
  3138. this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null;
  3139. this.envMap = parameters.envMap !== undefined ? parameters.envMap : null;
  3140. this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation;
  3141. this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1;
  3142. this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98;
  3143. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3144. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
  3145. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3146. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3147. this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round';
  3148. this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round';
  3149. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors;
  3150. this.skinning = parameters.skinning !== undefined ? parameters.skinning : false;
  3151. this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false;
  3152. this.morphNormals = parameters.morphNormals !== undefined ? parameters.morphNormals : false;
  3153. };
  3154. THREE.MeshLambertMaterial.prototype = new THREE.Material();
  3155. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  3156. /**
  3157. * @author mr.doob / http://mrdoob.com/
  3158. * @author alteredq / http://alteredqualia.com/
  3159. *
  3160. * parameters = {
  3161. * color: <hex>,
  3162. * ambient: <hex>,
  3163. * emissive: <hex>,
  3164. * specular: <hex>,
  3165. * shininess: <float>,
  3166. * opacity: <float>,
  3167. *
  3168. * map: new THREE.Texture( <Image> ),
  3169. *
  3170. * lightMap: new THREE.Texture( <Image> ),
  3171. *
  3172. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  3173. * combine: THREE.Multiply,
  3174. * reflectivity: <float>,
  3175. * refractionRatio: <float>,
  3176. *
  3177. * shading: THREE.SmoothShading,
  3178. * blending: THREE.NormalBlending,
  3179. * depthTest: <bool>,
  3180. *
  3181. * wireframe: <boolean>,
  3182. * wireframeLinewidth: <float>,
  3183. *
  3184. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  3185. *
  3186. * skinning: <bool>,
  3187. * morphTargets: <bool>,
  3188. * morphNormals: <bool>,
  3189. *
  3190. * fog: <bool>
  3191. * }
  3192. */
  3193. THREE.MeshPhongMaterial = function ( parameters ) {
  3194. THREE.Material.call( this, parameters );
  3195. parameters = parameters || {};
  3196. // color property represents diffuse for MeshPhongMaterial
  3197. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3198. this.ambient = parameters.ambient !== undefined ? new THREE.Color( parameters.ambient ) : new THREE.Color( 0xffffff );
  3199. this.emissive = parameters.emissive !== undefined ? new THREE.Color( parameters.emissive ) : new THREE.Color( 0x000000 );
  3200. this.specular = parameters.specular !== undefined ? new THREE.Color( parameters.specular ) : new THREE.Color( 0x111111 );
  3201. this.shininess = parameters.shininess !== undefined ? parameters.shininess : 30;
  3202. this.metal = parameters.metal !== undefined ? parameters.metal : false;
  3203. this.perPixel = parameters.perPixel !== undefined ? parameters.perPixel : false;
  3204. this.wrapAround = parameters.wrapAround !== undefined ? parameters.wrapAround: false;
  3205. this.wrapRGB = new THREE.Vector3( 1, 1, 1 );
  3206. this.map = parameters.map !== undefined ? parameters.map : null;
  3207. this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null;
  3208. this.envMap = parameters.envMap !== undefined ? parameters.envMap : null;
  3209. this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation;
  3210. this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1;
  3211. this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98;
  3212. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3213. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
  3214. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3215. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3216. this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round';
  3217. this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round';
  3218. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors;
  3219. this.skinning = parameters.skinning !== undefined ? parameters.skinning : false;
  3220. this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false;
  3221. this.morphNormals = parameters.morphNormals !== undefined ? parameters.morphNormals : false;
  3222. };
  3223. THREE.MeshPhongMaterial.prototype = new THREE.Material();
  3224. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  3225. /**
  3226. * @author mr.doob / http://mrdoob.com/
  3227. * @author alteredq / http://alteredqualia.com/
  3228. *
  3229. * parameters = {
  3230. * opacity: <float>,
  3231. * blending: THREE.NormalBlending,
  3232. * depthTest: <bool>,
  3233. * wireframe: <boolean>,
  3234. * wireframeLinewidth: <float>
  3235. * }
  3236. */
  3237. THREE.MeshDepthMaterial = function ( parameters ) {
  3238. THREE.Material.call( this, parameters );
  3239. parameters = parameters || {};
  3240. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading; // doesn't really apply here, normals are not used
  3241. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3242. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3243. };
  3244. THREE.MeshDepthMaterial.prototype = new THREE.Material();
  3245. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  3246. /**
  3247. * @author mr.doob / http://mrdoob.com/
  3248. *
  3249. * parameters = {
  3250. * opacity: <float>,
  3251. * shading: THREE.FlatShading,
  3252. * blending: THREE.NormalBlending,
  3253. * depthTest: <bool>,
  3254. * wireframe: <boolean>,
  3255. * wireframeLinewidth: <float>
  3256. * }
  3257. */
  3258. THREE.MeshNormalMaterial = function ( parameters ) {
  3259. THREE.Material.call( this, parameters );
  3260. parameters = parameters || {};
  3261. this.shading = parameters.shading ? parameters.shading : THREE.FlatShading;
  3262. this.wireframe = parameters.wireframe ? parameters.wireframe : false;
  3263. this.wireframeLinewidth = parameters.wireframeLinewidth ? parameters.wireframeLinewidth : 1;
  3264. };
  3265. THREE.MeshNormalMaterial.prototype = new THREE.Material();
  3266. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  3267. /**
  3268. * @author mr.doob / http://mrdoob.com/
  3269. */
  3270. THREE.MeshFaceMaterial = function () {
  3271. };
  3272. /**
  3273. * @author mr.doob / http://mrdoob.com/
  3274. * @author alteredq / http://alteredqualia.com/
  3275. *
  3276. * parameters = {
  3277. * color: <hex>,
  3278. * opacity: <float>,
  3279. * map: new THREE.Texture( <Image> ),
  3280. *
  3281. * size: <float>,
  3282. *
  3283. * blending: THREE.NormalBlending,
  3284. * depthTest: <bool>,
  3285. *
  3286. * vertexColors: <bool>,
  3287. *
  3288. * fog: <bool>
  3289. * }
  3290. */
  3291. THREE.ParticleBasicMaterial = function ( parameters ) {
  3292. THREE.Material.call( this, parameters );
  3293. parameters = parameters || {};
  3294. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3295. this.map = parameters.map !== undefined ? parameters.map : null;
  3296. this.size = parameters.size !== undefined ? parameters.size : 1;
  3297. this.sizeAttenuation = parameters.sizeAttenuation !== undefined ? parameters.sizeAttenuation : true;
  3298. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : false;
  3299. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3300. };
  3301. THREE.ParticleBasicMaterial.prototype = new THREE.Material();
  3302. THREE.ParticleBasicMaterial.prototype.constructor = THREE.ParticleBasicMaterial;
  3303. /**
  3304. * @author mr.doob / http://mrdoob.com/
  3305. * @author alteredq / http://alteredqualia.com/
  3306. * @author szimek / https://github.com/szimek/
  3307. */
  3308. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type ) {
  3309. this.id = THREE.TextureCount ++;
  3310. this.image = image;
  3311. this.mapping = mapping !== undefined ? mapping : new THREE.UVMapping();
  3312. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  3313. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  3314. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  3315. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  3316. this.format = format !== undefined ? format : THREE.RGBAFormat;
  3317. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  3318. this.offset = new THREE.Vector2( 0, 0 );
  3319. this.repeat = new THREE.Vector2( 1, 1 );
  3320. this.generateMipmaps = true;
  3321. this.premultiplyAlpha = false;
  3322. this.needsUpdate = false;
  3323. this.onUpdate = null;
  3324. };
  3325. THREE.Texture.prototype = {
  3326. constructor: THREE.Texture,
  3327. clone: function () {
  3328. var clonedTexture = new THREE.Texture( this.image, this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter, this.format, this.type );
  3329. clonedTexture.offset.copy( this.offset );
  3330. clonedTexture.repeat.copy( this.repeat );
  3331. return clonedTexture;
  3332. }
  3333. };
  3334. THREE.TextureCount = 0;
  3335. THREE.MultiplyOperation = 0;
  3336. THREE.MixOperation = 1;
  3337. // Mapping modes
  3338. THREE.UVMapping = function () {};
  3339. THREE.CubeReflectionMapping = function () {};
  3340. THREE.CubeRefractionMapping = function () {};
  3341. THREE.SphericalReflectionMapping = function () {};
  3342. THREE.SphericalRefractionMapping = function () {};
  3343. // Wrapping modes
  3344. THREE.RepeatWrapping = 0;
  3345. THREE.ClampToEdgeWrapping = 1;
  3346. THREE.MirroredRepeatWrapping = 2;
  3347. // Filters
  3348. THREE.NearestFilter = 3;
  3349. THREE.NearestMipMapNearestFilter = 4;
  3350. THREE.NearestMipMapLinearFilter = 5;
  3351. THREE.LinearFilter = 6;
  3352. THREE.LinearMipMapNearestFilter = 7;
  3353. THREE.LinearMipMapLinearFilter = 8;
  3354. // Types
  3355. THREE.ByteType = 9;
  3356. THREE.UnsignedByteType = 10;
  3357. THREE.ShortType = 11;
  3358. THREE.UnsignedShortType = 12;
  3359. THREE.IntType = 13;
  3360. THREE.UnsignedIntType = 14;
  3361. THREE.FloatType = 15;
  3362. // Formats
  3363. THREE.AlphaFormat = 16;
  3364. THREE.RGBFormat = 17;
  3365. THREE.RGBAFormat = 18;
  3366. THREE.LuminanceFormat = 19;
  3367. THREE.LuminanceAlphaFormat = 20;
  3368. /**
  3369. * @author alteredq / http://alteredqualia.com/
  3370. */
  3371. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter ) {
  3372. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type );
  3373. this.image = { data: data, width: width, height: height };
  3374. };
  3375. THREE.DataTexture.prototype = new THREE.Texture();
  3376. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  3377. THREE.DataTexture.prototype.clone = function () {
  3378. 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 );
  3379. clonedTexture.offset.copy( this.offset );
  3380. clonedTexture.repeat.copy( this.repeat );
  3381. return clonedTexture;
  3382. };
  3383. /**
  3384. * @author mr.doob / http://mrdoob.com/
  3385. */
  3386. THREE.Particle = function ( material ) {
  3387. THREE.Object3D.call( this );
  3388. this.material = material;
  3389. };
  3390. THREE.Particle.prototype = new THREE.Object3D();
  3391. THREE.Particle.prototype.constructor = THREE.Particle;
  3392. /**
  3393. * @author mr.doob / http://mrdoob.com/
  3394. */
  3395. THREE.Line = function ( geometry, material, type ) {
  3396. THREE.Object3D.call( this );
  3397. this.geometry = geometry;
  3398. this.material = ( material !== undefined ) ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  3399. this.type = ( type !== undefined ) ? type : THREE.LineStrip;
  3400. if ( this.geometry ) {
  3401. if ( ! this.geometry.boundingSphere ) {
  3402. this.geometry.computeBoundingSphere();
  3403. }
  3404. }
  3405. };
  3406. THREE.LineStrip = 0;
  3407. THREE.LinePieces = 1;
  3408. THREE.Line.prototype = new THREE.Object3D();
  3409. THREE.Line.prototype.constructor = THREE.Line;
  3410. /**
  3411. * @author mr.doob / http://mrdoob.com/
  3412. * @author alteredq / http://alteredqualia.com/
  3413. * @author mikael emtinger / http://gomo.se/
  3414. */
  3415. THREE.Mesh = function ( geometry, material ) {
  3416. THREE.Object3D.call( this );
  3417. this.geometry = geometry;
  3418. this.material = ( material !== undefined ) ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, wireframe: true } );
  3419. if ( this.geometry ) {
  3420. // calc bound radius
  3421. if( ! this.geometry.boundingSphere ) {
  3422. this.geometry.computeBoundingSphere();
  3423. }
  3424. this.boundRadius = geometry.boundingSphere.radius;
  3425. // setup morph targets
  3426. if( this.geometry.morphTargets.length ) {
  3427. this.morphTargetBase = -1;
  3428. this.morphTargetForcedOrder = [];
  3429. this.morphTargetInfluences = [];
  3430. this.morphTargetDictionary = {};
  3431. for( var m = 0; m < this.geometry.morphTargets.length; m ++ ) {
  3432. this.morphTargetInfluences.push( 0 );
  3433. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  3434. }
  3435. }
  3436. }
  3437. }
  3438. THREE.Mesh.prototype = new THREE.Object3D();
  3439. THREE.Mesh.prototype.constructor = THREE.Mesh;
  3440. THREE.Mesh.prototype.supr = THREE.Object3D.prototype;
  3441. /*
  3442. * Get Morph Target Index by Name
  3443. */
  3444. THREE.Mesh.prototype.getMorphTargetIndexByName = function( name ) {
  3445. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  3446. return this.morphTargetDictionary[ name ];
  3447. }
  3448. console.log( "THREE.Mesh.getMorphTargetIndexByName: morph target " + name + " does not exist. Returning 0." );
  3449. return 0;
  3450. }
  3451. /**
  3452. * @author mikael emtinger / http://gomo.se/
  3453. * @author alteredq / http://alteredqualia.com/
  3454. */
  3455. THREE.Bone = function( belongsToSkin ) {
  3456. THREE.Object3D.call( this );
  3457. this.skin = belongsToSkin;
  3458. this.skinMatrix = new THREE.Matrix4();
  3459. };
  3460. THREE.Bone.prototype = new THREE.Object3D();
  3461. THREE.Bone.prototype.constructor = THREE.Bone;
  3462. THREE.Bone.prototype.supr = THREE.Object3D.prototype;
  3463. THREE.Bone.prototype.update = function( parentSkinMatrix, forceUpdate ) {
  3464. // update local
  3465. if ( this.matrixAutoUpdate ) {
  3466. forceUpdate |= this.updateMatrix();
  3467. }
  3468. // update skin matrix
  3469. if ( forceUpdate || this.matrixWorldNeedsUpdate ) {
  3470. if( parentSkinMatrix ) {
  3471. this.skinMatrix.multiply( parentSkinMatrix, this.matrix );
  3472. } else {
  3473. this.skinMatrix.copy( this.matrix );
  3474. }
  3475. this.matrixWorldNeedsUpdate = false;
  3476. forceUpdate = true;
  3477. }
  3478. // update children
  3479. var child, i, l = this.children.length;
  3480. for ( i = 0; i < l; i ++ ) {
  3481. this.children[ i ].update( this.skinMatrix, forceUpdate );
  3482. }
  3483. };
  3484. /**
  3485. * @author mikael emtinger / http://gomo.se/
  3486. */
  3487. THREE.Sprite = function ( parameters ) {
  3488. THREE.Object3D.call( this );
  3489. this.color = ( parameters.color !== undefined ) ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3490. this.map = ( parameters.map !== undefined ) ? parameters.map : new THREE.Texture();
  3491. this.blending = ( parameters.blending !== undefined ) ? parameters.blending : THREE.NormalBlending;
  3492. this.blendSrc = parameters.blendSrc !== undefined ? parameters.blendSrc : THREE.SrcAlphaFactor;
  3493. this.blendDst = parameters.blendDst !== undefined ? parameters.blendDst : THREE.OneMinusSrcAlphaFactor;
  3494. this.blendEquation = parameters.blendEquation !== undefined ? parameters.blendEquation : THREE.AddEquation;
  3495. this.useScreenCoordinates = ( parameters.useScreenCoordinates !== undefined ) ? parameters.useScreenCoordinates : true;
  3496. this.mergeWith3D = ( parameters.mergeWith3D !== undefined ) ? parameters.mergeWith3D : !this.useScreenCoordinates;
  3497. this.affectedByDistance = ( parameters.affectedByDistance !== undefined ) ? parameters.affectedByDistance : !this.useScreenCoordinates;
  3498. this.scaleByViewport = ( parameters.scaleByViewport !== undefined ) ? parameters.scaleByViewport : !this.affectedByDistance;
  3499. this.alignment = ( parameters.alignment instanceof THREE.Vector2 ) ? parameters.alignment : THREE.SpriteAlignment.center;
  3500. this.rotation3d = this.rotation;
  3501. this.rotation = 0;
  3502. this.opacity = 1;
  3503. this.uvOffset = new THREE.Vector2( 0, 0 );
  3504. this.uvScale = new THREE.Vector2( 1, 1 );
  3505. };
  3506. THREE.Sprite.prototype = new THREE.Object3D();
  3507. THREE.Sprite.prototype.constructor = THREE.Sprite;
  3508. /*
  3509. * Custom update matrix
  3510. */
  3511. THREE.Sprite.prototype.updateMatrix = function () {
  3512. this.matrix.setPosition( this.position );
  3513. this.rotation3d.set( 0, 0, this.rotation );
  3514. this.matrix.setRotationFromEuler( this.rotation3d );
  3515. if ( this.scale.x !== 1 || this.scale.y !== 1 ) {
  3516. this.matrix.scale( this.scale );
  3517. this.boundRadiusScale = Math.max( this.scale.x, this.scale.y );
  3518. }
  3519. this.matrixWorldNeedsUpdate = true;
  3520. };
  3521. /*
  3522. * Alignment
  3523. */
  3524. THREE.SpriteAlignment = {};
  3525. THREE.SpriteAlignment.topLeft = new THREE.Vector2( 1, -1 );
  3526. THREE.SpriteAlignment.topCenter = new THREE.Vector2( 0, -1 );
  3527. THREE.SpriteAlignment.topRight = new THREE.Vector2( -1, -1 );
  3528. THREE.SpriteAlignment.centerLeft = new THREE.Vector2( 1, 0 );
  3529. THREE.SpriteAlignment.center = new THREE.Vector2( 0, 0 );
  3530. THREE.SpriteAlignment.centerRight = new THREE.Vector2( -1, 0 );
  3531. THREE.SpriteAlignment.bottomLeft = new THREE.Vector2( 1, 1 );
  3532. THREE.SpriteAlignment.bottomCenter = new THREE.Vector2( 0, 1 );
  3533. THREE.SpriteAlignment.bottomRight = new THREE.Vector2( -1, 1 );
  3534. /**
  3535. * @author mr.doob / http://mrdoob.com/
  3536. */
  3537. THREE.Scene = function () {
  3538. THREE.Object3D.call( this );
  3539. this.fog = null;
  3540. this.overrideMaterial = null;
  3541. this.matrixAutoUpdate = false;
  3542. this.__objects = [];
  3543. this.__lights = [];
  3544. this.__objectsAdded = [];
  3545. this.__objectsRemoved = [];
  3546. };
  3547. THREE.Scene.prototype = new THREE.Object3D();
  3548. THREE.Scene.prototype.constructor = THREE.Scene;
  3549. THREE.Scene.prototype.__addObject = function ( object ) {
  3550. if ( object instanceof THREE.Light ) {
  3551. if ( this.__lights.indexOf( object ) === - 1 ) {
  3552. this.__lights.push( object );
  3553. }
  3554. } else if ( !( object instanceof THREE.Camera || object instanceof THREE.Bone ) ) {
  3555. if ( this.__objects.indexOf( object ) === - 1 ) {
  3556. this.__objects.push( object );
  3557. this.__objectsAdded.push( object );
  3558. // check if previously removed
  3559. var i = this.__objectsRemoved.indexOf( object );
  3560. if ( i !== -1 ) {
  3561. this.__objectsRemoved.splice( i, 1 );
  3562. }
  3563. }
  3564. }
  3565. for ( var c = 0; c < object.children.length; c ++ ) {
  3566. this.__addObject( object.children[ c ] );
  3567. }
  3568. };
  3569. THREE.Scene.prototype.__removeObject = function ( object ) {
  3570. if ( object instanceof THREE.Light ) {
  3571. var i = this.__lights.indexOf( object );
  3572. if ( i !== -1 ) {
  3573. this.__lights.splice( i, 1 );
  3574. }
  3575. } else if ( !( object instanceof THREE.Camera ) ) {
  3576. var i = this.__objects.indexOf( object );
  3577. if( i !== -1 ) {
  3578. this.__objects.splice( i, 1 );
  3579. this.__objectsRemoved.push( object );
  3580. // check if previously added
  3581. var ai = this.__objectsAdded.indexOf( object );
  3582. if ( ai !== -1 ) {
  3583. this.__objectsAdded.splice( ai, 1 );
  3584. }
  3585. }
  3586. }
  3587. for ( var c = 0; c < object.children.length; c ++ ) {
  3588. this.__removeObject( object.children[ c ] );
  3589. }
  3590. };
  3591. /**
  3592. * @author mr.doob / http://mrdoob.com/
  3593. */
  3594. THREE.SVGRenderer = function () {
  3595. console.log( 'THREE.SVGRenderer', THREE.REVISION );
  3596. var _this = this,
  3597. _renderData, _elements, _lights,
  3598. _projector = new THREE.Projector(),
  3599. _svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'),
  3600. _svgWidth, _svgHeight, _svgWidthHalf, _svgHeightHalf,
  3601. _v1, _v2, _v3, _v4,
  3602. _clipRect = new THREE.Rectangle(),
  3603. _bboxRect = new THREE.Rectangle(),
  3604. _enableLighting = false,
  3605. _color = new THREE.Color(),
  3606. _ambientLight = new THREE.Color(),
  3607. _directionalLights = new THREE.Color(),
  3608. _pointLights = new THREE.Color(),
  3609. _w, // z-buffer to w-buffer
  3610. _vector3 = new THREE.Vector3(), // Needed for PointLight
  3611. _svgPathPool = [], _svgCirclePool = [], _svgLinePool = [],
  3612. _svgNode, _pathCount, _circleCount, _lineCount,
  3613. _quality = 1;
  3614. this.domElement = _svg;
  3615. this.autoClear = true;
  3616. this.sortObjects = true;
  3617. this.sortElements = true;
  3618. this.info = {
  3619. render: {
  3620. vertices: 0,
  3621. faces: 0
  3622. }
  3623. }
  3624. this.setQuality = function( quality ) {
  3625. switch(quality) {
  3626. case "high": _quality = 1; break;
  3627. case "low": _quality = 0; break;
  3628. }
  3629. };
  3630. this.setSize = function( width, height ) {
  3631. _svgWidth = width; _svgHeight = height;
  3632. _svgWidthHalf = _svgWidth / 2; _svgHeightHalf = _svgHeight / 2;
  3633. _svg.setAttribute( 'viewBox', ( - _svgWidthHalf ) + ' ' + ( - _svgHeightHalf ) + ' ' + _svgWidth + ' ' + _svgHeight );
  3634. _svg.setAttribute( 'width', _svgWidth );
  3635. _svg.setAttribute( 'height', _svgHeight );
  3636. _clipRect.set( - _svgWidthHalf, - _svgHeightHalf, _svgWidthHalf, _svgHeightHalf );
  3637. };
  3638. this.clear = function () {
  3639. while ( _svg.childNodes.length > 0 ) {
  3640. _svg.removeChild( _svg.childNodes[ 0 ] );
  3641. }
  3642. };
  3643. this.render = function ( scene, camera ) {
  3644. var e, el, element, material;
  3645. this.autoClear && this.clear();
  3646. _this.info.render.vertices = 0;
  3647. _this.info.render.faces = 0;
  3648. _renderData = _projector.projectScene( scene, camera, this.sortElements );
  3649. _elements = _renderData.elements;
  3650. _lights = _renderData.lights;
  3651. _pathCount = 0; _circleCount = 0; _lineCount = 0;
  3652. _enableLighting = _lights.length > 0;
  3653. if ( _enableLighting ) {
  3654. calculateLights( _lights );
  3655. }
  3656. for ( e = 0, el = _elements.length; e < el; e ++ ) {
  3657. element = _elements[ e ];
  3658. material = element.material;
  3659. material = material instanceof THREE.MeshFaceMaterial ? element.faceMaterial : material;
  3660. if ( material == null || material.opacity == 0 ) continue;
  3661. _bboxRect.empty();
  3662. if ( element instanceof THREE.RenderableParticle ) {
  3663. _v1 = element;
  3664. _v1.x *= _svgWidthHalf; _v1.y *= -_svgHeightHalf;
  3665. renderParticle( _v1, element, material, scene );
  3666. } else if ( element instanceof THREE.RenderableLine ) {
  3667. _v1 = element.v1; _v2 = element.v2;
  3668. _v1.positionScreen.x *= _svgWidthHalf; _v1.positionScreen.y *= - _svgHeightHalf;
  3669. _v2.positionScreen.x *= _svgWidthHalf; _v2.positionScreen.y *= - _svgHeightHalf;
  3670. _bboxRect.addPoint( _v1.positionScreen.x, _v1.positionScreen.y );
  3671. _bboxRect.addPoint( _v2.positionScreen.x, _v2.positionScreen.y );
  3672. if ( !_clipRect.intersects( _bboxRect ) ) {
  3673. continue;
  3674. }
  3675. renderLine( _v1, _v2, element, material, scene );
  3676. } else if ( element instanceof THREE.RenderableFace3 ) {
  3677. _v1 = element.v1; _v2 = element.v2; _v3 = element.v3;
  3678. _v1.positionScreen.x *= _svgWidthHalf; _v1.positionScreen.y *= - _svgHeightHalf;
  3679. _v2.positionScreen.x *= _svgWidthHalf; _v2.positionScreen.y *= - _svgHeightHalf;
  3680. _v3.positionScreen.x *= _svgWidthHalf; _v3.positionScreen.y *= - _svgHeightHalf;
  3681. _bboxRect.addPoint( _v1.positionScreen.x, _v1.positionScreen.y );
  3682. _bboxRect.addPoint( _v2.positionScreen.x, _v2.positionScreen.y );
  3683. _bboxRect.addPoint( _v3.positionScreen.x, _v3.positionScreen.y );
  3684. if ( !_clipRect.intersects( _bboxRect ) ) {
  3685. continue;
  3686. }
  3687. renderFace3( _v1, _v2, _v3, element, material, scene );
  3688. } else if ( element instanceof THREE.RenderableFace4 ) {
  3689. _v1 = element.v1; _v2 = element.v2; _v3 = element.v3; _v4 = element.v4;
  3690. _v1.positionScreen.x *= _svgWidthHalf; _v1.positionScreen.y *= -_svgHeightHalf;
  3691. _v2.positionScreen.x *= _svgWidthHalf; _v2.positionScreen.y *= -_svgHeightHalf;
  3692. _v3.positionScreen.x *= _svgWidthHalf; _v3.positionScreen.y *= -_svgHeightHalf;
  3693. _v4.positionScreen.x *= _svgWidthHalf; _v4.positionScreen.y *= -_svgHeightHalf;
  3694. _bboxRect.addPoint( _v1.positionScreen.x, _v1.positionScreen.y );
  3695. _bboxRect.addPoint( _v2.positionScreen.x, _v2.positionScreen.y );
  3696. _bboxRect.addPoint( _v3.positionScreen.x, _v3.positionScreen.y );
  3697. _bboxRect.addPoint( _v4.positionScreen.x, _v4.positionScreen.y );
  3698. if ( !_clipRect.intersects( _bboxRect) ) {
  3699. continue;
  3700. }
  3701. renderFace4( _v1, _v2, _v3, _v4, element, material, scene );
  3702. }
  3703. }
  3704. };
  3705. function calculateLights( lights ) {
  3706. var l, ll, light, lightColor;
  3707. _ambientLight.setRGB( 0, 0, 0 );
  3708. _directionalLights.setRGB( 0, 0, 0 );
  3709. _pointLights.setRGB( 0, 0, 0 );
  3710. for ( l = 0, ll = lights.length; l < ll; l++ ) {
  3711. light = lights[ l ];
  3712. lightColor = light.color;
  3713. if ( light instanceof THREE.AmbientLight ) {
  3714. _ambientLight.r += lightColor.r;
  3715. _ambientLight.g += lightColor.g;
  3716. _ambientLight.b += lightColor.b;
  3717. } else if ( light instanceof THREE.DirectionalLight ) {
  3718. _directionalLights.r += lightColor.r;
  3719. _directionalLights.g += lightColor.g;
  3720. _directionalLights.b += lightColor.b;
  3721. } else if ( light instanceof THREE.PointLight ) {
  3722. _pointLights.r += lightColor.r;
  3723. _pointLights.g += lightColor.g;
  3724. _pointLights.b += lightColor.b;
  3725. }
  3726. }
  3727. }
  3728. function calculateLight( lights, position, normal, color ) {
  3729. var l, ll, light, lightColor, lightPosition, amount;
  3730. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  3731. light = lights[ l ];
  3732. lightColor = light.color;
  3733. if ( light instanceof THREE.DirectionalLight ) {
  3734. lightPosition = light.matrixWorld.getPosition();
  3735. amount = normal.dot( lightPosition );
  3736. if ( amount <= 0 ) continue;
  3737. amount *= light.intensity;
  3738. color.r += lightColor.r * amount;
  3739. color.g += lightColor.g * amount;
  3740. color.b += lightColor.b * amount;
  3741. } else if ( light instanceof THREE.PointLight ) {
  3742. lightPosition = light.matrixWorld.getPosition();
  3743. amount = normal.dot( _vector3.sub( lightPosition, position ).normalize() );
  3744. if ( amount <= 0 ) continue;
  3745. amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( lightPosition ) / light.distance, 1 );
  3746. if ( amount == 0 ) continue;
  3747. amount *= light.intensity;
  3748. color.r += lightColor.r * amount;
  3749. color.g += lightColor.g * amount;
  3750. color.b += lightColor.b * amount;
  3751. }
  3752. }
  3753. }
  3754. function renderParticle( v1, element, material, scene ) {
  3755. /*
  3756. _svgNode = getCircleNode( _circleCount++ );
  3757. _svgNode.setAttribute( 'cx', v1.x );
  3758. _svgNode.setAttribute( 'cy', v1.y );
  3759. _svgNode.setAttribute( 'r', element.scale.x * _svgWidthHalf );
  3760. if ( material instanceof THREE.ParticleCircleMaterial ) {
  3761. if ( _enableLighting ) {
  3762. _color.r = _ambientLight.r + _directionalLights.r + _pointLights.r;
  3763. _color.g = _ambientLight.g + _directionalLights.g + _pointLights.g;
  3764. _color.b = _ambientLight.b + _directionalLights.b + _pointLights.b;
  3765. _color.r = material.color.r * _color.r;
  3766. _color.g = material.color.g * _color.g;
  3767. _color.b = material.color.b * _color.b;
  3768. _color.updateStyleString();
  3769. } else {
  3770. _color = material.color;
  3771. }
  3772. _svgNode.setAttribute( 'style', 'fill: ' + _color.__styleString );
  3773. }
  3774. _svg.appendChild( _svgNode );
  3775. */
  3776. }
  3777. function renderLine ( v1, v2, element, material, scene ) {
  3778. _svgNode = getLineNode( _lineCount ++ );
  3779. _svgNode.setAttribute( 'x1', v1.positionScreen.x );
  3780. _svgNode.setAttribute( 'y1', v1.positionScreen.y );
  3781. _svgNode.setAttribute( 'x2', v2.positionScreen.x );
  3782. _svgNode.setAttribute( 'y2', v2.positionScreen.y );
  3783. if ( material instanceof THREE.LineBasicMaterial ) {
  3784. _svgNode.setAttribute( 'style', 'fill: none; stroke: ' + material.color.getContextStyle() + '; stroke-width: ' + material.linewidth + '; stroke-opacity: ' + material.opacity + '; stroke-linecap: ' + material.linecap + '; stroke-linejoin: ' + material.linejoin );
  3785. _svg.appendChild( _svgNode );
  3786. }
  3787. }
  3788. function renderFace3( v1, v2, v3, element, material, scene ) {
  3789. _this.info.render.vertices += 3;
  3790. _this.info.render.faces ++;
  3791. _svgNode = getPathNode( _pathCount ++ );
  3792. _svgNode.setAttribute( 'd', 'M ' + v1.positionScreen.x + ' ' + v1.positionScreen.y + ' L ' + v2.positionScreen.x + ' ' + v2.positionScreen.y + ' L ' + v3.positionScreen.x + ',' + v3.positionScreen.y + 'z' );
  3793. if ( material instanceof THREE.MeshBasicMaterial ) {
  3794. _color.copy( material.color );
  3795. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  3796. if ( _enableLighting ) {
  3797. _color.r = _ambientLight.r;
  3798. _color.g = _ambientLight.g;
  3799. _color.b = _ambientLight.b;
  3800. calculateLight( _lights, element.centroidWorld, element.normalWorld, _color );
  3801. _color.r = Math.max( 0, Math.min( material.color.r * _color.r, 1 ) );
  3802. _color.g = Math.max( 0, Math.min( material.color.g * _color.g, 1 ) );
  3803. _color.b = Math.max( 0, Math.min( material.color.b * _color.b, 1 ) );
  3804. } else {
  3805. _color.copy( material.color );
  3806. }
  3807. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  3808. _w = 1 - ( material.__2near / (material.__farPlusNear - element.z * material.__farMinusNear) );
  3809. _color.setRGB( _w, _w, _w );
  3810. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  3811. _color.setRGB( normalToComponent( element.normalWorld.x ), normalToComponent( element.normalWorld.y ), normalToComponent( element.normalWorld.z ) );
  3812. }
  3813. if ( material.wireframe ) {
  3814. _svgNode.setAttribute( 'style', 'fill: none; stroke: ' + _color.getContextStyle() + '; stroke-width: ' + material.wireframeLinewidth + '; stroke-opacity: ' + material.opacity + '; stroke-linecap: ' + material.wireframeLinecap + '; stroke-linejoin: ' + material.wireframeLinejoin );
  3815. } else {
  3816. _svgNode.setAttribute( 'style', 'fill: ' + _color.getContextStyle() + '; fill-opacity: ' + material.opacity );
  3817. }
  3818. _svg.appendChild( _svgNode );
  3819. }
  3820. function renderFace4( v1, v2, v3, v4, element, material, scene ) {
  3821. _this.info.render.vertices += 4;
  3822. _this.info.render.faces ++;
  3823. _svgNode = getPathNode( _pathCount ++ );
  3824. _svgNode.setAttribute( 'd', 'M ' + v1.positionScreen.x + ' ' + v1.positionScreen.y + ' L ' + v2.positionScreen.x + ' ' + v2.positionScreen.y + ' L ' + v3.positionScreen.x + ',' + v3.positionScreen.y + ' L ' + v4.positionScreen.x + ',' + v4.positionScreen.y + 'z' );
  3825. if ( material instanceof THREE.MeshBasicMaterial ) {
  3826. _color.copy( material.color );
  3827. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  3828. if ( _enableLighting ) {
  3829. _color.r = _ambientLight.r;
  3830. _color.g = _ambientLight.g;
  3831. _color.b = _ambientLight.b;
  3832. calculateLight( _lights, element.centroidWorld, element.normalWorld, _color );
  3833. _color.r = Math.max( 0, Math.min( material.color.r * _color.r, 1 ) );
  3834. _color.g = Math.max( 0, Math.min( material.color.g * _color.g, 1 ) );
  3835. _color.b = Math.max( 0, Math.min( material.color.b * _color.b, 1 ) );
  3836. } else {
  3837. _color.copy( material.color );
  3838. }
  3839. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  3840. _w = 1 - ( material.__2near / (material.__farPlusNear - element.z * material.__farMinusNear) );
  3841. _color.setRGB( _w, _w, _w );
  3842. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  3843. _color.setRGB( normalToComponent( element.normalWorld.x ), normalToComponent( element.normalWorld.y ), normalToComponent( element.normalWorld.z ) );
  3844. }
  3845. if ( material.wireframe ) {
  3846. _svgNode.setAttribute( 'style', 'fill: none; stroke: ' + _color.getContextStyle() + '; stroke-width: ' + material.wireframeLinewidth + '; stroke-opacity: ' + material.opacity + '; stroke-linecap: ' + material.wireframeLinecap + '; stroke-linejoin: ' + material.wireframeLinejoin );
  3847. } else {
  3848. _svgNode.setAttribute( 'style', 'fill: ' + _color.getContextStyle() + '; fill-opacity: ' + material.opacity );
  3849. }
  3850. _svg.appendChild( _svgNode );
  3851. }
  3852. function getLineNode( id ) {
  3853. if ( _svgLinePool[ id ] == null ) {
  3854. _svgLinePool[ id ] = document.createElementNS( 'http://www.w3.org/2000/svg', 'line' );
  3855. if ( _quality == 0 ) {
  3856. _svgLinePool[ id ].setAttribute( 'shape-rendering', 'crispEdges' ); //optimizeSpeed
  3857. }
  3858. return _svgLinePool[ id ];
  3859. }
  3860. return _svgLinePool[ id ];
  3861. }
  3862. function getPathNode( id ) {
  3863. if ( _svgPathPool[ id ] == null ) {
  3864. _svgPathPool[ id ] = document.createElementNS( 'http://www.w3.org/2000/svg', 'path' );
  3865. if ( _quality == 0 ) {
  3866. _svgPathPool[ id ].setAttribute( 'shape-rendering', 'crispEdges' ); //optimizeSpeed
  3867. }
  3868. return _svgPathPool[ id ];
  3869. }
  3870. return _svgPathPool[ id ];
  3871. }
  3872. function getCircleNode( id ) {
  3873. if ( _svgCirclePool[id] == null ) {
  3874. _svgCirclePool[ id ] = document.createElementNS( 'http://www.w3.org/2000/svg', 'circle' );
  3875. if ( _quality == 0 ) {
  3876. _svgCirclePool[id].setAttribute( 'shape-rendering', 'crispEdges' ); //optimizeSpeed
  3877. }
  3878. return _svgCirclePool[ id ];
  3879. }
  3880. return _svgCirclePool[ id ];
  3881. }
  3882. function normalToComponent( normal ) {
  3883. var component = ( normal + 1 ) * 0.5;
  3884. return component < 0 ? 0 : ( component > 1 ? 1 : component );
  3885. }
  3886. function pad( str ) {
  3887. while ( str.length < 6 ) str = '0' + str;
  3888. return str;
  3889. }
  3890. };
  3891. /**
  3892. * @author mr.doob / http://mrdoob.com/
  3893. */
  3894. THREE.RenderableVertex = function () {
  3895. this.positionWorld = new THREE.Vector3();
  3896. this.positionScreen = new THREE.Vector4();
  3897. this.visible = true;
  3898. };
  3899. THREE.RenderableVertex.prototype.copy = function ( vertex ) {
  3900. this.positionWorld.copy( vertex.positionWorld );
  3901. this.positionScreen.copy( vertex.positionScreen );
  3902. }
  3903. /**
  3904. * @author mr.doob / http://mrdoob.com/
  3905. */
  3906. THREE.RenderableFace3 = function () {
  3907. this.v1 = new THREE.RenderableVertex();
  3908. this.v2 = new THREE.RenderableVertex();
  3909. this.v3 = new THREE.RenderableVertex();
  3910. this.centroidWorld = new THREE.Vector3();
  3911. this.centroidScreen = new THREE.Vector3();
  3912. this.normalWorld = new THREE.Vector3();
  3913. this.vertexNormalsWorld = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  3914. this.material = null;
  3915. this.faceMaterial = null;
  3916. this.uvs = [[]];
  3917. this.z = null;
  3918. };
  3919. /**
  3920. * @author mr.doob / http://mrdoob.com/
  3921. */
  3922. THREE.RenderableFace4 = function () {
  3923. this.v1 = new THREE.RenderableVertex();
  3924. this.v2 = new THREE.RenderableVertex();
  3925. this.v3 = new THREE.RenderableVertex();
  3926. this.v4 = new THREE.RenderableVertex();
  3927. this.centroidWorld = new THREE.Vector3();
  3928. this.centroidScreen = new THREE.Vector3();
  3929. this.normalWorld = new THREE.Vector3();
  3930. this.vertexNormalsWorld = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  3931. this.material = null;
  3932. this.faceMaterial = null;
  3933. this.uvs = [[]];
  3934. this.z = null;
  3935. };
  3936. /**
  3937. * @author mr.doob / http://mrdoob.com/
  3938. */
  3939. THREE.RenderableObject = function () {
  3940. this.object = null;
  3941. this.z = null;
  3942. };
  3943. /**
  3944. * @author mr.doob / http://mrdoob.com/
  3945. */
  3946. THREE.RenderableParticle = function () {
  3947. this.x = null;
  3948. this.y = null;
  3949. this.z = null;
  3950. this.rotation = null;
  3951. this.scale = new THREE.Vector2();
  3952. this.material = null;
  3953. };
  3954. /**
  3955. * @author mr.doob / http://mrdoob.com/
  3956. */
  3957. THREE.RenderableLine = function () {
  3958. this.z = null;
  3959. this.v1 = new THREE.RenderableVertex();
  3960. this.v2 = new THREE.RenderableVertex();
  3961. this.material = null;
  3962. };
  3963. =======
  3964. // ThreeSVG.js - http://github.com/mrdoob/three.js
  3965. 'use strict';var THREE=THREE||{REVISION:"49dev"};self.Int32Array||(self.Int32Array=Array,self.Float32Array=Array);
  3966. (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=
  3967. function(a){clearTimeout(a)}})();THREE.Color=function(a){a!==void 0&&this.setHex(a);return this};
  3968. 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);
  3969. 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=
  3970. 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)}};
  3971. THREE.Vector2=function(a,b){this.x=a||0;this.y=b||0};
  3972. 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=
  3973. 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)},
  3974. 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};
  3975. 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+
  3976. 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=
  3977. 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())},
  3978. 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,
  3979. 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,j=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(-j/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=
  3980. 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};
  3981. 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=
  3982. 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())},
  3983. 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]};
  3984. 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],j=d[5],k=d[6],i=d[7],h=d[8],n=d[9],m=d[10],o=d[11],q=d[12],l=d[13],s=d[14],d=d[15];c[0].set(f-a,i-g,o-h,d-q);c[1].set(f+a,i+g,o+h,d+q);c[2].set(f+b,i+j,o+n,d+l);c[3].set(f-b,i-j,o-n,d-l);c[4].set(f-e,i-k,o-m,d-s);c[5].set(f+e,i+k,o+m,d+s);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))}};
  3985. 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;
  3986. THREE.Ray=function(a,b){function c(a,b,c){q.sub(c,a);w=q.dot(b);r=l.add(a,s.copy(b).multiplyScalar(w));return A=c.distanceTo(r)}function d(a,b,c,d){q.sub(d,b);l.sub(c,b);s.sub(a,b);u=q.dot(q);t=q.dot(l);B=q.dot(s);x=l.dot(l);D=l.dot(s);z=1/(u*x-t*t);C=(x*B-t*D)*z;F=(u*D-t*B)*z;return C>=0&&F>=0&&C+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,j=new THREE.Vector3,k=new THREE.Vector3,
  3987. i=new THREE.Vector3,h=new THREE.Vector3,n=new THREE.Vector3,m=new THREE.Vector3,o=new THREE.Vector3;this.intersectObject=function(a){var b,l=[];if(a instanceof THREE.Particle){var q=c(this.origin,this.direction,a.matrixWorld.getPosition());if(q>a.scale.x)return[];b={distance:q,point:a.position,face:null,object:a};l.push(b)}else if(a instanceof THREE.Mesh){var q=c(this.origin,this.direction,a.matrixWorld.getPosition()),s=THREE.Frustum.__v1.set(a.matrixWorld.getColumnX().length(),a.matrixWorld.getColumnY().length(),
  3988. a.matrixWorld.getColumnZ().length());if(q>a.geometry.boundingSphere.radius*Math.max(s.x,Math.max(s.y,s.z)))return l;var r,t,u=a.geometry,y=u.vertices,p;a.matrixRotationWorld.extractRotation(a.matrixWorld);q=0;for(s=u.faces.length;q<s;q++){b=u.faces[q];i.copy(this.origin);h.copy(this.direction);p=a.matrixWorld;n=p.multiplyVector3(n.copy(b.centroid)).subSelf(i);m=a.matrixRotationWorld.multiplyVector3(m.copy(b.normal));r=h.dot(m);if(!(Math.abs(r)<e)){t=m.dot(n)/r;if(!(t<0)&&(a.doubleSided||(a.flipSided?
  3989. r>0:r<0))){o.add(i,h.multiplyScalar(t));if(b instanceof THREE.Face3){f=p.multiplyVector3(f.copy(y[b.a]));g=p.multiplyVector3(g.copy(y[b.b]));j=p.multiplyVector3(j.copy(y[b.c]));if(d(o,f,g,j)){b={distance:i.distanceTo(o),point:o.clone(),face:b,object:a};l.push(b)}}else if(b instanceof THREE.Face4){f=p.multiplyVector3(f.copy(y[b.a]));g=p.multiplyVector3(g.copy(y[b.b]));j=p.multiplyVector3(j.copy(y[b.c]));k=p.multiplyVector3(k.copy(y[b.d]));if(d(o,f,g,k)||d(o,g,j,k)){b={distance:i.distanceTo(o),point:o.clone(),
  3990. face:b,object:a};l.push(b)}}}}}}return l};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 q=new THREE.Vector3,l=new THREE.Vector3,s=new THREE.Vector3,w,r,A,u,t,B,x,D,z,C,F};
  3991. THREE.Rectangle=function(){function a(){f=d-b;g=e-c}var b,c,d,e,f,g,j=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,n){j=false;b=f;c=g;d=h;e=n;a()};this.addPoint=function(f,g){if(j){j=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?
  3992. e:g}a()};this.add3Points=function(f,g,h,n,m,o){if(j){j=false;b=f<h?f<m?f:m:h<m?h:m;c=g<n?g<o?g:o:n<o?n:o;d=f>h?f>m?f:m:h>m?h:m;e=g>n?g>o?g:o:n>o?n:o}else{b=f<h?f<m?f<b?f:b:m<b?m:b:h<m?h<b?h:b:m<b?m:b;c=g<n?g<o?g<c?g:c:o<c?o:c:n<o?n<c?n:c:o<c?o:c;d=f>h?f>m?f>d?f:d:m>d?m:d:h>m?h>d?h:d:m>d?m:d;e=g>n?g>o?g>e?g:e:o>e?o:e:n>o?n>e?n:e:o>e?o:e}a()};this.addRectangle=function(f){if(j){j=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();
  3993. 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(){j=true;e=d=c=b=0;a()};this.isEmpty=function(){return j}};
  3994. 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)};
  3995. 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],j=b[9]*b[4]-b[5]*b[8],k=-b[9]*b[0]+b[1]*b[8],i=b[5]*b[0]-b[1]*b[4],b=b[0]*a+b[1]*e+b[2]*j;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*j;h[7]=b*k;h[8]=b*i;return this},
  3996. 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,j,k,i,h,n,m,o,q,l){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,j||0,k||0,i||0,h!==void 0?h:1,n||0,m||0,o||0,q||0,l!==void 0?l:1)};
  3997. THREE.Matrix4.prototype={constructor:THREE.Matrix4,set:function(a,b,c,d,e,f,g,j,k,i,h,n,m,o,q,l){var s=this.elements;s[0]=a;s[4]=b;s[8]=c;s[12]=d;s[1]=e;s[5]=f;s[9]=g;s[13]=j;s[2]=k;s[6]=i;s[10]=h;s[14]=n;s[3]=m;s[7]=o;s[11]=q;s[15]=l;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,
  3998. 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],j=c[8],k=c[12],i=c[1],h=c[5],n=c[9],m=c[13],o=c[2],q=c[6],l=c[10],s=c[14],w=c[3],r=c[7],A=c[11],c=c[15],u=d[0],t=d[4],
  3999. B=d[8],x=d[12],D=d[1],z=d[5],C=d[9],F=d[13],E=d[2],L=d[6],H=d[10],v=d[14],I=d[3],J=d[7],K=d[11],d=d[15];e[0]=f*u+g*D+j*E+k*I;e[4]=f*t+g*z+j*L+k*J;e[8]=f*B+g*C+j*H+k*K;e[12]=f*x+g*F+j*v+k*d;e[1]=i*u+h*D+n*E+m*I;e[5]=i*t+h*z+n*L+m*J;e[9]=i*B+h*C+n*H+m*K;e[13]=i*x+h*F+n*v+m*d;e[2]=o*u+q*D+l*E+s*I;e[6]=o*t+q*z+l*L+s*J;e[10]=o*B+q*C+l*H+s*K;e[14]=o*x+q*F+l*v+s*d;e[3]=w*u+r*D+A*E+c*I;e[7]=w*t+r*z+A*L+c*J;e[11]=w*B+r*C+A*H+c*K;e[15]=w*x+r*F+A*v+c*d;return this},multiplySelf:function(a){return this.multiply(this,
  4000. 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]=
  4001. 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,
  4002. 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],j=a[9],k=a[13],i=a[2],h=a[6],n=a[10],m=a[14],o=a[3],q=a[7],
  4003. l=a[11],a=a[15];return e*j*h*o-d*k*h*o-e*g*n*o+c*k*n*o+d*g*m*o-c*j*m*o-e*j*i*q+d*k*i*q+e*f*n*q-b*k*n*q-d*f*m*q+b*j*m*q+e*g*i*l-c*k*i*l-e*f*h*l+b*k*h*l+c*f*m*l-b*g*m*l-d*g*i*a+c*j*i*a+d*f*h*a-b*j*h*a-c*f*n*a+b*g*n*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];
  4004. 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],
  4005. 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],j=c[1],k=c[5],i=c[9],h=c[13],n=c[2],m=c[6],o=c[10],q=
  4006. c[14],l=c[3],s=c[7],w=c[11],c=c[15];b[0]=i*q*s-h*o*s+h*m*w-k*q*w-i*m*c+k*o*c;b[4]=g*o*s-f*q*s-g*m*w+e*q*w+f*m*c-e*o*c;b[8]=f*h*s-g*i*s+g*k*w-e*h*w-f*k*c+e*i*c;b[12]=g*i*m-f*h*m-g*k*o+e*h*o+f*k*q-e*i*q;b[1]=h*o*l-i*q*l-h*n*w+j*q*w+i*n*c-j*o*c;b[5]=f*q*l-g*o*l+g*n*w-d*q*w-f*n*c+d*o*c;b[9]=g*i*l-f*h*l-g*j*w+d*h*w+f*j*c-d*i*c;b[13]=f*h*n-g*i*n+g*j*o-d*h*o-f*j*q+d*i*q;b[2]=k*q*l-h*m*l+h*n*s-j*q*s-k*n*c+j*m*c;b[6]=g*m*l-e*q*l-g*n*s+d*q*s+e*n*c-d*m*c;b[10]=e*h*l-g*k*l+g*j*s-d*h*s-e*j*c+d*k*c;b[14]=g*k*n-
  4007. e*h*n-g*j*m+d*h*m+e*j*q-d*k*q;b[3]=i*m*l-k*o*l-i*n*s+j*o*s+k*n*w-j*m*w;b[7]=e*o*l-f*m*l+f*n*s-d*o*s-e*n*w+d*m*w;b[11]=f*k*l-e*i*l-f*j*s+d*i*s+e*j*w-d*k*w;b[15]=e*i*n-f*k*n+f*j*m-d*i*m-e*j*o+d*k*o;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),j=Math.cos(e),e=Math.sin(e),k=Math.cos(f),f=Math.sin(f);switch(b){case "YXZ":var i=j*k,h=j*f,n=e*k,m=e*f;c[0]=i+m*d;c[4]=n*d-h;c[8]=g*e;c[1]=g*f;c[5]=g*
  4008. k;c[9]=-d;c[2]=h*d-n;c[6]=m+i*d;c[10]=g*j;break;case "ZXY":i=j*k;h=j*f;n=e*k;m=e*f;c[0]=i-m*d;c[4]=-g*f;c[8]=n+h*d;c[1]=h+n*d;c[5]=g*k;c[9]=m-i*d;c[2]=-g*e;c[6]=d;c[10]=g*j;break;case "ZYX":i=g*k;h=g*f;n=d*k;m=d*f;c[0]=j*k;c[4]=n*e-h;c[8]=i*e+m;c[1]=j*f;c[5]=m*e+i;c[9]=h*e-n;c[2]=-e;c[6]=d*j;c[10]=g*j;break;case "YZX":i=g*j;h=g*e;n=d*j;m=d*e;c[0]=j*k;c[4]=m-i*f;c[8]=n*f+h;c[1]=f;c[5]=g*k;c[9]=-d*k;c[2]=-e*k;c[6]=h*f+n;c[10]=i-m*f;break;case "XZY":i=g*j;h=g*e;n=d*j;m=d*e;c[0]=j*k;c[4]=-f;c[8]=e*k;
  4009. c[1]=i*f+m;c[5]=g*k;c[9]=h*f-n;c[2]=n*f-h;c[6]=d*k;c[10]=m*f+i;break;default:i=g*k;h=g*f;n=d*k;m=d*f;c[0]=j*k;c[4]=-j*f;c[8]=e;c[1]=h+n*e;c[5]=i-m*e;c[9]=-d*j;c[2]=m-i*e;c[6]=n+h*e;c[10]=g*j}return this},setRotationFromQuaternion:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,f=a.w,g=c+c,j=d+d,k=e+e,a=c*g,i=c*j,c=c*k,h=d*j,d=d*k,e=e*k,g=f*g,j=f*j,f=f*k;b[0]=1-(h+e);b[4]=i-f;b[8]=c+j;b[1]=i+f;b[5]=1-(a+e);b[9]=d-g;b[2]=c-j;b[6]=d+g;b[10]=1-(a+h);return this},compose:function(a,b,c){var d=this.elements,
  4010. 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;
  4011. 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;
  4012. 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]*
  4013. 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],j=b[9],k=b[10],i=b[11],h=Math.cos(a),a=Math.sin(a);b[4]=h*c+a*g;b[5]=h*d+a*j;b[6]=h*e+a*k;b[7]=h*f+a*i;b[8]=h*g-a*c;b[9]=h*j-a*d;b[10]=h*k-a*e;b[11]=h*i-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],j=b[9],k=b[10],i=b[11],h=Math.cos(a),a=Math.sin(a);b[0]=h*c-a*g;b[1]=h*d-a*j;b[2]=h*e-a*k;b[3]=h*f-a*i;b[8]=h*g+a*c;b[9]=
  4014. h*j+a*d;b[10]=h*k+a*e;b[11]=h*i+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],j=b[5],k=b[6],i=b[7],h=Math.cos(a),a=Math.sin(a);b[0]=h*c+a*g;b[1]=h*d+a*j;b[2]=h*e+a*k;b[3]=h*f+a*i;b[4]=h*g-a*c;b[5]=h*j-a*d;b[6]=h*k-a*e;b[7]=h*i-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,
  4015. 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,j=e*e,k=f*f,i=Math.cos(b),h=Math.sin(b),n=1-i,m=d*e*n,o=d*f*n,n=e*f*n,d=d*h,q=e*h,h=f*h,f=g+(1-g)*i,g=m+h,e=o-q,m=m-h,j=j+(1-j)*i,h=n+d,o=o+q,n=n-d,k=k+(1-k)*i,i=c[0],d=c[1],q=c[2],l=c[3],s=c[4],w=c[5],r=c[6],A=c[7],u=c[8],t=c[9],B=c[10],x=c[11];c[0]=f*i+g*s+e*u;c[1]=f*d+g*w+e*t;c[2]=f*q+g*r+e*B;c[3]=f*l+g*A+e*x;c[4]=m*i+j*s+h*u;c[5]=m*d+j*w+h*t;c[6]=m*q+j*r+h*B;c[7]=m*l+j*A+h*x;c[8]=o*i+n*s+k*u;c[9]=o*d+n*w+k*t;c[10]=o*q+n*r+k*B;c[11]=
  4016. o*l+n*A+k*x;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},
  4017. 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,j=a.z,k=e*f,i=e*g;this.set(k*f+c,k*g-d*j,k*j+d*g,0,k*g+d*j,i*g+c,i*j-d*f,0,k*j-
  4018. d*g,i*j+d*f,e*j*j+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,
  4019. b,c,d,e,f){var g=this.elements,j=b-a,k=c-d,i=f-e;g[0]=2/j;g[4]=0;g[8]=0;g[12]=-((b+a)/j);g[1]=0;g[5]=2/k;g[9]=0;g[13]=-((c+d)/k);g[2]=0;g[6]=0;g[10]=-2/i;g[14]=-((f+e)/i);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;
  4020. THREE.Matrix4.__m2=new THREE.Matrix4;
  4021. 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=
  4022. 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};
  4023. 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,
  4024. 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=
  4025. 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,
  4026. 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<
  4027. c;b++)this.children[b].updateMatrixWorld(a)}};THREE.Object3DCount=0;
  4028. THREE.Projector=function(){function a(){var a=g[f]=g[f]||new THREE.RenderableObject;f++;return a}function b(){var a=i[k]=i[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,f=a.z+a.w,e=b.z+b.w,g=-a.z+a.w,h=-b.z+b.w;if(f>=0&&e>=0&&g>=0&&h>=0)return true;if(f<0&&e<0||g<0&&h<0)return false;f<0?c=Math.max(c,f/(f-e)):e<0&&(d=Math.min(d,f/(f-e)));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-
  4029. d);return true}var e,f,g=[],j,k,i=[],h,n,m=[],o,q=[],l,s,w=[],r,A,u=[],t={objects:[],sprites:[],lights:[],elements:[]},B=new THREE.Vector3,x=new THREE.Vector4,D=new THREE.Matrix4,z=new THREE.Matrix4,C=new THREE.Frustum,F=new THREE.Vector4,E=new THREE.Vector4;this.projectVector=function(a,b){b.matrixWorldInverse.getInverse(b.matrixWorld);D.multiply(b.projectionMatrix,b.matrixWorldInverse);D.multiplyVector3(a);return a};this.unprojectVector=function(a,b){b.projectionMatrixInverse.getInverse(b.projectionMatrix);
  4030. D.multiply(b.matrixWorld,b.projectionMatrixInverse);D.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;t.objects.length=0;t.sprites.length=0;t.lights.length=0;var g=function(b){if(b.visible!==false){if((b instanceof THREE.Mesh||b instanceof THREE.Line)&&(b.frustumCulled===false||C.contains(b))){B.copy(b.matrixWorld.getPosition());
  4031. D.multiplyVector3(B);e=a();e.object=b;e.z=B.z;t.objects.push(e)}else if(b instanceof THREE.Sprite||b instanceof THREE.Particle){B.copy(b.matrixWorld.getPosition());D.multiplyVector3(B);e=a();e.object=b;e.z=B.z;t.sprites.push(e)}else b instanceof THREE.Light&&t.lights.push(b);for(var c=0,d=b.children.length;c<d;c++)g(b.children[c])}};g(b);d&&t.objects.sort(c);return t};this.projectScene=function(a,f,e){var g=f.near,B=f.far,K=false,R,y,p,P,G,N,O,Q,M,S,T,V,W,X,U;A=s=o=n=0;t.elements.length=0;if(f.parent===
  4032. void 0){console.warn("DEPRECATED: Camera hasn't been added to a Scene. Adding it...");a.add(f)}a.updateMatrixWorld();f.matrixWorldInverse.getInverse(f.matrixWorld);D.multiply(f.projectionMatrix,f.matrixWorldInverse);C.setFromMatrix(D);t=this.projectGraph(a,false);a=0;for(R=t.objects.length;a<R;a++){M=t.objects[a].object;S=M.matrixWorld;k=0;if(M instanceof THREE.Mesh){T=M.geometry;V=M.geometry.materials;P=T.vertices;W=T.faces;X=T.faceVertexUvs;T=M.matrixRotationWorld.extractRotation(S);y=0;for(p=P.length;y<
  4033. p;y++){j=b();j.positionWorld.copy(P[y]);S.multiplyVector3(j.positionWorld);j.positionScreen.copy(j.positionWorld);D.multiplyVector4(j.positionScreen);j.positionScreen.x=j.positionScreen.x/j.positionScreen.w;j.positionScreen.y=j.positionScreen.y/j.positionScreen.w;j.visible=j.positionScreen.z>g&&j.positionScreen.z<B}P=0;for(y=W.length;P<y;P++){p=W[P];if(p instanceof THREE.Face3){G=i[p.a];N=i[p.b];O=i[p.c];if(G.visible&&N.visible&&O.visible){K=(O.positionScreen.x-G.positionScreen.x)*(N.positionScreen.y-
  4034. G.positionScreen.y)-(O.positionScreen.y-G.positionScreen.y)*(N.positionScreen.x-G.positionScreen.x)<0;if(M.doubleSided||K!=M.flipSided){Q=m[n]=m[n]||new THREE.RenderableFace3;n++;h=Q;h.v1.copy(G);h.v2.copy(N);h.v3.copy(O)}else continue}else continue}else if(p instanceof THREE.Face4){G=i[p.a];N=i[p.b];O=i[p.c];Q=i[p.d];if(G.visible&&N.visible&&O.visible&&Q.visible){K=(Q.positionScreen.x-G.positionScreen.x)*(N.positionScreen.y-G.positionScreen.y)-(Q.positionScreen.y-G.positionScreen.y)*(N.positionScreen.x-
  4035. G.positionScreen.x)<0||(N.positionScreen.x-O.positionScreen.x)*(Q.positionScreen.y-O.positionScreen.y)-(N.positionScreen.y-O.positionScreen.y)*(Q.positionScreen.x-O.positionScreen.x)<0;if(M.doubleSided||K!=M.flipSided){U=q[o]=q[o]||new THREE.RenderableFace4;o++;h=U;h.v1.copy(G);h.v2.copy(N);h.v3.copy(O);h.v4.copy(Q)}else continue}else continue}h.normalWorld.copy(p.normal);!K&&(M.flipSided||M.doubleSided)&&h.normalWorld.negate();T.multiplyVector3(h.normalWorld);h.centroidWorld.copy(p.centroid);S.multiplyVector3(h.centroidWorld);
  4036. h.centroidScreen.copy(h.centroidWorld);D.multiplyVector3(h.centroidScreen);O=p.vertexNormals;G=0;for(N=O.length;G<N;G++){Q=h.vertexNormalsWorld[G];Q.copy(O[G]);!K&&(M.flipSided||M.doubleSided)&&Q.negate();T.multiplyVector3(Q)}G=0;for(N=X.length;G<N;G++)if(U=X[G][P]){O=0;for(Q=U.length;O<Q;O++)h.uvs[G][O]=U[O]}h.material=M.material;h.faceMaterial=p.materialIndex!==null?V[p.materialIndex]:null;h.z=h.centroidScreen.z;t.elements.push(h)}}else if(M instanceof THREE.Line){z.multiply(D,S);P=M.geometry.vertices;
  4037. G=b();G.positionScreen.copy(P[0]);z.multiplyVector4(G.positionScreen);S=M.type===THREE.LinePieces?2:1;y=1;for(p=P.length;y<p;y++){G=b();G.positionScreen.copy(P[y]);z.multiplyVector4(G.positionScreen);if(!((y+1)%S>0)){N=i[k-2];F.copy(G.positionScreen);E.copy(N.positionScreen);if(d(F,E)){F.multiplyScalar(1/F.w);E.multiplyScalar(1/E.w);V=w[s]=w[s]||new THREE.RenderableLine;s++;l=V;l.v1.positionScreen.copy(F);l.v2.positionScreen.copy(E);l.z=Math.max(F.z,E.z);l.material=M.material;t.elements.push(l)}}}}}a=
  4038. 0;for(R=t.sprites.length;a<R;a++){M=t.sprites[a].object;S=M.matrixWorld;if(M instanceof THREE.Particle){x.set(S.elements[12],S.elements[13],S.elements[14],1);D.multiplyVector4(x);x.z=x.z/x.w;if(x.z>0&&x.z<1){g=u[A]=u[A]||new THREE.RenderableParticle;A++;r=g;r.x=x.x/x.w;r.y=x.y/x.w;r.z=x.z;r.rotation=M.rotation.z;r.scale.x=M.scale.x*Math.abs(r.x-(x.x+f.projectionMatrix.elements[0])/(x.w+f.projectionMatrix.elements[12]));r.scale.y=M.scale.y*Math.abs(r.y-(x.y+f.projectionMatrix.elements[5])/(x.w+f.projectionMatrix.elements[13]));
  4039. r.material=M.material;t.elements.push(r)}}}e&&t.elements.sort(c);return t}};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};
  4040. 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,j=d*e;this.w=g*f-j*c;this.x=g*c+j*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);
  4041. 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):
  4042. 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=
  4043. 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,j=a.z,a=a.w;this.x=b*a+e*f+c*j-d*g;this.y=
  4044. c*a+e*g+d*f-b*j;this.z=d*a+e*j+b*g-c*f;this.w=e*a-b*f-c*g-d*j;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,j=this.z,k=this.w,i=k*c+g*e-j*d,h=k*d+j*c-f*e,n=k*e+f*d-g*c,c=-f*c-g*d-j*e;b.x=i*k+c*-f+h*-j-n*-g;b.y=h*k+c*-g+n*-f-i*-j;b.z=n*k+c*-j+i*-g-h*-f;return b},clone:function(){return new THREE.Quaternion(this.x,this.y,this.z,this.w)}};
  4045. 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.001){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.")};
  4046. 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};
  4047. 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();
  4048. 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};
  4049. 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();
  4050. 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)}};
  4051. THREE.Geometry=function(){this.id=THREE.GeometryCount++;this.vertices=[];this.colors=[];this.materials=[];this.faces=[];this.faceUvs=[[]];this.faceVertexUvs=[[]];this.morphTargets=[];this.morphColors=[];this.morphNormals=[];this.skinWeights=[];this.skinIndices=[];this.boundingSphere=this.boundingBox=null;this.dynamic=this.hasTangents=false};
  4052. THREE.Geometry.prototype={constructor:THREE.Geometry,applyMatrix:function(a){var b=new THREE.Matrix4;b.extractRotation(a);for(var c=0,d=this.vertices.length;c<d;c++)a.multiplyVector3(this.vertices[c]);c=0;for(d=this.faces.length;c<d;c++){var e=this.faces[c];b.multiplyVector3(e.normal);for(var f=0,g=e.vertexNormals.length;f<g;f++)b.multiplyVector3(e.vertexNormals[f]);a.multiplyVector3(e.centroid)}},computeCentroids:function(){var a,b,c;a=0;for(b=this.faces.length;a<b;a++){c=this.faces[a];c.centroid.set(0,
  4053. 0,0);if(c instanceof THREE.Face3){c.centroid.addSelf(this.vertices[c.a]);c.centroid.addSelf(this.vertices[c.b]);c.centroid.addSelf(this.vertices[c.c]);c.centroid.divideScalar(3)}else if(c instanceof THREE.Face4){c.centroid.addSelf(this.vertices[c.a]);c.centroid.addSelf(this.vertices[c.b]);c.centroid.addSelf(this.vertices[c.c]);c.centroid.addSelf(this.vertices[c.d]);c.centroid.divideScalar(4)}}},computeFaceNormals:function(){var a,b,c,d,e,f,g=new THREE.Vector3,j=new THREE.Vector3;a=0;for(b=this.faces.length;a<
  4054. b;a++){c=this.faces[a];d=this.vertices[c.a];e=this.vertices[c.b];f=this.vertices[c.c];g.sub(f,e);j.sub(d,e);g.crossSelf(j);g.isZero()||g.normalize();c.normal.copy(g)}},computeVertexNormals:function(){var a,b,c,d;if(this.__tmpVertices===void 0){d=this.__tmpVertices=Array(this.vertices.length);a=0;for(b=this.vertices.length;a<b;a++)d[a]=new THREE.Vector3;a=0;for(b=this.faces.length;a<b;a++){c=this.faces[a];if(c instanceof THREE.Face3)c.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];
  4055. else if(c instanceof THREE.Face4)c.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3]}}else{d=this.__tmpVertices;a=0;for(b=this.vertices.length;a<b;a++)d[a].set(0,0,0)}a=0;for(b=this.faces.length;a<b;a++){c=this.faces[a];if(c instanceof THREE.Face3){d[c.a].addSelf(c.normal);d[c.b].addSelf(c.normal);d[c.c].addSelf(c.normal)}else if(c instanceof THREE.Face4){d[c.a].addSelf(c.normal);d[c.b].addSelf(c.normal);d[c.c].addSelf(c.normal);d[c.d].addSelf(c.normal)}}a=0;
  4056. for(b=this.vertices.length;a<b;a++)d[a].normalize();a=0;for(b=this.faces.length;a<b;a++){c=this.faces[a];if(c instanceof THREE.Face3){c.vertexNormals[0].copy(d[c.a]);c.vertexNormals[1].copy(d[c.b]);c.vertexNormals[2].copy(d[c.c])}else if(c instanceof THREE.Face4){c.vertexNormals[0].copy(d[c.a]);c.vertexNormals[1].copy(d[c.b]);c.vertexNormals[2].copy(d[c.c]);c.vertexNormals[3].copy(d[c.d])}}},computeMorphNormals:function(){var a,b,c,d,e;c=0;for(d=this.faces.length;c<d;c++){e=this.faces[c];e.__originalFaceNormal?
  4057. e.__originalFaceNormal.copy(e.normal):e.__originalFaceNormal=e.normal.clone();if(!e.__originalVertexNormals)e.__originalVertexNormals=[];a=0;for(b=e.vertexNormals.length;a<b;a++)e.__originalVertexNormals[a]?e.__originalVertexNormals[a].copy(e.vertexNormals[a]):e.__originalVertexNormals[a]=e.vertexNormals[a].clone()}var f=new THREE.Geometry;f.faces=this.faces;a=0;for(b=this.morphTargets.length;a<b;a++){if(!this.morphNormals[a]){this.morphNormals[a]={};this.morphNormals[a].faceNormals=[];this.morphNormals[a].vertexNormals=
  4058. [];var g=this.morphNormals[a].faceNormals,j=this.morphNormals[a].vertexNormals,k,i;c=0;for(d=this.faces.length;c<d;c++){e=this.faces[c];k=new THREE.Vector3;i=e instanceof THREE.Face3?{a:new THREE.Vector3,b:new THREE.Vector3,c:new THREE.Vector3}:{a:new THREE.Vector3,b:new THREE.Vector3,c:new THREE.Vector3,d:new THREE.Vector3};g.push(k);j.push(i)}}g=this.morphNormals[a];f.vertices=this.morphTargets[a].vertices;f.computeFaceNormals();f.computeVertexNormals();c=0;for(d=this.faces.length;c<d;c++){e=this.faces[c];
  4059. k=g.faceNormals[c];i=g.vertexNormals[c];k.copy(e.normal);if(e instanceof THREE.Face3){i.a.copy(e.vertexNormals[0]);i.b.copy(e.vertexNormals[1]);i.c.copy(e.vertexNormals[2])}else{i.a.copy(e.vertexNormals[0]);i.b.copy(e.vertexNormals[1]);i.c.copy(e.vertexNormals[2]);i.d.copy(e.vertexNormals[3])}}}c=0;for(d=this.faces.length;c<d;c++){e=this.faces[c];e.normal=e.__originalFaceNormal;e.vertexNormals=e.__originalVertexNormals}},computeTangents:function(){function a(a,b,c,d,f,e,G){j=a.vertices[b];k=a.vertices[c];
  4060. i=a.vertices[d];h=g[f];n=g[e];m=g[G];o=k.x-j.x;q=i.x-j.x;l=k.y-j.y;s=i.y-j.y;w=k.z-j.z;r=i.z-j.z;A=n.u-h.u;u=m.u-h.u;t=n.v-h.v;B=m.v-h.v;x=1/(A*B-u*t);F.set((B*o-t*q)*x,(B*l-t*s)*x,(B*w-t*r)*x);E.set((A*q-u*o)*x,(A*s-u*l)*x,(A*r-u*w)*x);z[b].addSelf(F);z[c].addSelf(F);z[d].addSelf(F);C[b].addSelf(E);C[c].addSelf(E);C[d].addSelf(E)}var b,c,d,e,f,g,j,k,i,h,n,m,o,q,l,s,w,r,A,u,t,B,x,D,z=[],C=[],F=new THREE.Vector3,E=new THREE.Vector3,L=new THREE.Vector3,H=new THREE.Vector3,v=new THREE.Vector3;b=0;for(c=
  4061. this.vertices.length;b<c;b++){z[b]=new THREE.Vector3;C[b]=new THREE.Vector3}b=0;for(c=this.faces.length;b<c;b++){f=this.faces[b];g=this.faceVertexUvs[0][b];if(f instanceof THREE.Face3)a(this,f.a,f.b,f.c,0,1,2);else if(f instanceof THREE.Face4){a(this,f.a,f.b,f.d,0,1,3);a(this,f.b,f.c,f.d,1,2,3)}}var I=["a","b","c","d"];b=0;for(c=this.faces.length;b<c;b++){f=this.faces[b];for(d=0;d<f.vertexNormals.length;d++){v.copy(f.vertexNormals[d]);e=f[I[d]];D=z[e];L.copy(D);L.subSelf(v.multiplyScalar(v.dot(D))).normalize();
  4062. H.cross(f.vertexNormals[d],D);e=H.dot(C[e]);e=e<0?-1:1;f.vertexTangents[d]=new THREE.Vector4(L.x,L.y,L.z,e)}}this.hasTangents=true},computeBoundingBox:function(){if(!this.boundingBox)this.boundingBox={min:new THREE.Vector3,max:new THREE.Vector3};if(this.vertices.length>0){var a;a=this.vertices[0];this.boundingBox.min.copy(a);this.boundingBox.max.copy(a);for(var b=this.boundingBox.min,c=this.boundingBox.max,d=1,e=this.vertices.length;d<e;d++){a=this.vertices[d];if(a.x<b.x)b.x=a.x;else if(a.x>c.x)c.x=
  4063. a.x;if(a.y<b.y)b.y=a.y;else if(a.y>c.y)c.y=a.y;if(a.z<b.z)b.z=a.z;else if(a.z>c.z)c.z=a.z}}else{this.boundingBox.min.set(0,0,0);this.boundingBox.max.set(0,0,0)}},computeBoundingSphere:function(){if(!this.boundingSphere)this.boundingSphere={radius:0};for(var a,b=0,c=0,d=this.vertices.length;c<d;c++){a=this.vertices[c].length();a>b&&(b=a)}this.boundingSphere.radius=b},mergeVertices:function(){var a={},b=[],c=[],d,e=Math.pow(10,4),f,g,j;f=0;for(g=this.vertices.length;f<g;f++){d=this.vertices[f];d=[Math.round(d.x*
  4064. e),Math.round(d.y*e),Math.round(d.z*e)].join("_");if(a[d]===void 0){a[d]=f;b.push(this.vertices[f]);c[f]=b.length-1}else c[f]=c[a[d]]}f=0;for(g=this.faces.length;f<g;f++){e=this.faces[f];if(e instanceof THREE.Face3){e.a=c[e.a];e.b=c[e.b];e.c=c[e.c]}else if(e instanceof THREE.Face4){e.a=c[e.a];e.b=c[e.b];e.c=c[e.c];e.d=c[e.d];d=[e.a,e.b,e.c,e.d];for(a=3;a>0;a--)if(d.indexOf(e["abcd"[a]])!=a){d.splice(a,1);this.faces[f]=new THREE.Face3(d[0],d[1],d[2]);e=0;for(d=this.faceVertexUvs.length;e<d;e++)(j=
  4065. this.faceVertexUvs[e][f])&&j.splice(a,1);break}}}c=this.vertices.length-b.length;this.vertices=b;return c}};THREE.GeometryCount=0;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;
  4066. THREE.Camera.prototype.lookAt=function(a){this.matrix.lookAt(this.position,a,this.up);this.rotationAutoUpdate&&this.rotation.getRotationFromMatrix(this.matrix)};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;
  4067. THREE.OrthographicCamera.prototype.updateProjectionMatrix=function(){this.projectionMatrix.makeOrthographic(this.left,this.right,this.top,this.bottom,this.near,this.far)};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;
  4068. THREE.PerspectiveCamera.prototype.setLens=function(a,b){this.fov=2*Math.atan((b!==void 0?b:24)/(a*2))*(180/Math.PI);this.updateProjectionMatrix()};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()};
  4069. 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)};
  4070. 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.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;
  4071. THREE.DirectionalLight=function(a,b,c){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.target=new THREE.Object3D;this.intensity=b!==void 0?b:1;this.distance=c!==void 0?c:0;this.onlyShadow=this.castShadow=false;this.shadowCameraNear=50;this.shadowCameraFar=5E3;this.shadowCameraLeft=-500;this.shadowCameraTop=this.shadowCameraRight=500;this.shadowCameraBottom=-500;this.shadowCameraVisible=false;this.shadowBias=0;this.shadowDarkness=0.5;this.shadowMapHeight=this.shadowMapWidth=512;
  4072. this.shadowCascade=false;this.shadowCascadeOffset=new THREE.Vector3(0,0,-1E3);this.shadowCascadeCount=2;this.shadowCascadeBias=[0,0,0];this.shadowCascadeWidth=[512,512,512];this.shadowCascadeHeight=[512,512,512];this.shadowCascadeNearZ=[-1,0.99,0.998];this.shadowCascadeFarZ=[0.99,0.998,1];this.shadowCascadeArray=[];this.shadowMatrix=this.shadowCamera=this.shadowMapSize=this.shadowMap=null};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;
  4073. THREE.PointLight=function(a,b,c){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,0,0);this.intensity=b!==void 0?b:1;this.distance=c!==void 0?c:0};THREE.PointLight.prototype=new THREE.Light;THREE.PointLight.prototype.constructor=THREE.PointLight;THREE.Loader=function(a){this.statusDomElement=(this.showStatus=a)?THREE.Loader.prototype.addStatusElement():null;this.onLoadStart=function(){};this.onLoadProgress=function(){};this.onLoadComplete=function(){}};
  4074. 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/
  4075. 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=
  4076. 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 f=new Image;f.onload=function(){if(!c(this.width)||!c(this.height)){var b=d(this.width),f=d(this.height);a.image.width=b;a.image.height=f;a.image.getContext("2d").drawImage(this,0,0,b,f)}else a.image=this;a.needsUpdate=true};f.crossOrigin=j.crossOrigin;f.src=b}function f(a,c,d,f,g,h){var j=document.createElement("canvas");a[c]=new THREE.Texture(j);a[c].sourceFile=
  4077. 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 j=this,k="MeshLambertMaterial",i={color:15658734,opacity:1,map:null,lightMap:null,normalMap:null,wireframe:a.wireframe};
  4078. 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)i.blending=THREE[a.blending];if(a.transparent!==void 0||a.opacity<1)i.transparent=a.transparent;if(a.depthTest!==void 0)i.depthTest=a.depthTest;if(a.depthWrite!==void 0)i.depthWrite=a.depthWrite;if(a.vertexColors!==void 0)if(a.vertexColors=="face")i.vertexColors=THREE.FaceColors;else if(a.vertexColors)i.vertexColors=THREE.VertexColors;
  4079. if(a.colorDiffuse)i.color=g(a.colorDiffuse);else if(a.DbgColor)i.color=a.DbgColor;if(a.colorSpecular)i.specular=g(a.colorSpecular);if(a.colorAmbient)i.ambient=g(a.colorAmbient);if(a.transparency)i.opacity=a.transparency;if(a.specularCoef)i.shininess=a.specularCoef;a.mapDiffuse&&b&&f(i,"map",a.mapDiffuse,a.mapDiffuseRepeat,a.mapDiffuseOffset,a.mapDiffuseWrap);a.mapLight&&b&&f(i,"lightMap",a.mapLight,a.mapLightRepeat,a.mapLightOffset,a.mapLightWrap);a.mapNormal&&b&&f(i,"normalMap",a.mapNormal,a.mapNormalRepeat,
  4080. a.mapNormalOffset,a.mapNormalWrap);a.mapSpecular&&b&&f(i,"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=i.normalMap;if(a.mapNormalFactor)h.uNormalScale.value=a.mapNormalFactor;if(i.map){h.tDiffuse.texture=i.map;h.enableDiffuse.value=true}if(i.specularMap){h.tSpecular.texture=i.specularMap;h.enableSpecular.value=true}if(i.lightMap){h.tAO.texture=i.lightMap;
  4081. h.enableAO.value=true}h.uDiffuseColor.value.setHex(i.color);h.uSpecularColor.value.setHex(i.specular);h.uAmbientColor.value.setHex(i.ambient);h.uShininess.value=i.shininess;if(i.opacity!==void 0)h.uOpacity.value=i.opacity;i=new THREE.ShaderMaterial({fragmentShader:k.fragmentShader,vertexShader:k.vertexShader,uniforms:h,lights:true,fog:true})}else i=new THREE[k](i);if(a.DbgName!==void 0)i.name=a.DbgName;return i}};THREE.BinaryLoader=function(a){THREE.Loader.call(this,a)};
  4082. THREE.BinaryLoader.prototype=new THREE.Loader;THREE.BinaryLoader.prototype.constructor=THREE.BinaryLoader;THREE.BinaryLoader.prototype.load=function(a,b,c,d){var c=c?c:this.extractUrlBase(a),d=d?d:this.extractUrlBase(a),e=this.showProgress?THREE.Loader.prototype.updateProgress:null;this.onLoadStart();this.loadAjaxJSON(this,a,b,c,d,e)};
  4083. THREE.BinaryLoader.prototype.loadAjaxJSON=function(a,b,c,d,e,f){var g=new XMLHttpRequest;g.onreadystatechange=function(){if(g.readyState==4)if(g.status==200||g.status==0){var j=JSON.parse(g.responseText);a.loadAjaxBuffers(j,c,e,d,f)}else console.error("THREE.BinaryLoader: Couldn't load ["+b+"] ["+g.status+"]")};g.open("GET",b,true);g.overrideMimeType&&g.overrideMimeType("text/plain; charset=x-user-defined");g.setRequestHeader("Content-Type","text/plain");g.send(null)};
  4084. THREE.BinaryLoader.prototype.loadAjaxBuffers=function(a,b,c,d,e){var f=new XMLHttpRequest,g=c+"/"+a.buffers,j=0;f.onreadystatechange=function(){if(f.readyState==4)f.status==200||f.status==0?THREE.BinaryLoader.prototype.createBinModel(f.response,b,d,a.materials):console.error("THREE.BinaryLoader: Couldn't load ["+g+"] ["+f.status+"]");else if(f.readyState==3){if(e){j==0&&(j=f.getResponseHeader("Content-Length"));e({total:j,loaded:f.responseText.length})}}else f.readyState==2&&(j=f.getResponseHeader("Content-Length"))};
  4085. f.open("GET",g,true);f.responseType="arraybuffer";f.send(null)};
  4086. THREE.BinaryLoader.prototype.createBinModel=function(a,b,c,d){var e=function(b){var c,e,k,i,h,n,m,o,q,l,s,w,r,A,u;function t(a){return a%4?4-a%4:0}function B(a,b){return(new Uint8Array(a,b,1))[0]}function x(a,b){return(new Uint32Array(a,b,1))[0]}function D(b,c){var d,f,e,g,h,j,i,k,l=new Uint32Array(a,c,3*b);for(d=0;d<b;d++){f=l[d*3];e=l[d*3+1];g=l[d*3+2];h=J[f*2];f=J[f*2+1];j=J[e*2];i=J[e*2+1];e=J[g*2];k=J[g*2+1];g=H.faceVertexUvs[0];var m=[];m.push(new THREE.UV(h,f));m.push(new THREE.UV(j,i));m.push(new THREE.UV(e,
  4087. k));g.push(m)}}function z(b,c){var d,f,e,g,h,j,i,k,l,m,n=new Uint32Array(a,c,4*b);for(d=0;d<b;d++){f=n[d*4];e=n[d*4+1];g=n[d*4+2];h=n[d*4+3];j=J[f*2];f=J[f*2+1];i=J[e*2];l=J[e*2+1];k=J[g*2];m=J[g*2+1];g=J[h*2];e=J[h*2+1];h=H.faceVertexUvs[0];var o=[];o.push(new THREE.UV(j,f));o.push(new THREE.UV(i,l));o.push(new THREE.UV(k,m));o.push(new THREE.UV(g,e));h.push(o)}}function C(b,c,d){for(var f,e,g,h,c=new Uint32Array(a,c,3*b),j=new Uint16Array(a,d,b),d=0;d<b;d++){f=c[d*3];e=c[d*3+1];g=c[d*3+2];h=j[d];
  4088. H.faces.push(new THREE.Face3(f,e,g,null,null,h))}}function F(b,c,d){for(var f,e,g,h,j,c=new Uint32Array(a,c,4*b),i=new Uint16Array(a,d,b),d=0;d<b;d++){f=c[d*4];e=c[d*4+1];g=c[d*4+2];h=c[d*4+3];j=i[d];H.faces.push(new THREE.Face4(f,e,g,h,null,null,j))}}function E(b,c,d,f){for(var e,g,h,j,i,k,l,c=new Uint32Array(a,c,3*b),d=new Uint32Array(a,d,3*b),m=new Uint16Array(a,f,b),f=0;f<b;f++){e=c[f*3];g=c[f*3+1];h=c[f*3+2];i=d[f*3];k=d[f*3+1];l=d[f*3+2];j=m[f];var n=I[k*3],o=I[k*3+1];k=I[k*3+2];var q=I[l*3],
  4089. r=I[l*3+1];l=I[l*3+2];H.faces.push(new THREE.Face3(e,g,h,[new THREE.Vector3(I[i*3],I[i*3+1],I[i*3+2]),new THREE.Vector3(n,o,k),new THREE.Vector3(q,r,l)],null,j))}}function L(b,c,d,f){for(var e,g,h,j,i,k,l,m,n,c=new Uint32Array(a,c,4*b),d=new Uint32Array(a,d,4*b),o=new Uint16Array(a,f,b),f=0;f<b;f++){e=c[f*4];g=c[f*4+1];h=c[f*4+2];j=c[f*4+3];k=d[f*4];l=d[f*4+1];m=d[f*4+2];n=d[f*4+3];i=o[f];var q=I[l*3],r=I[l*3+1];l=I[l*3+2];var s=I[m*3],t=I[m*3+1];m=I[m*3+2];var u=I[n*3],v=I[n*3+1];n=I[n*3+2];H.faces.push(new THREE.Face4(e,
  4090. g,h,j,[new THREE.Vector3(I[k*3],I[k*3+1],I[k*3+2]),new THREE.Vector3(q,r,l),new THREE.Vector3(s,t,m),new THREE.Vector3(u,v,n)],null,i))}}var H=this,v=0,I=[],J=[],K,R,y;THREE.Geometry.call(this);THREE.Loader.prototype.initMaterials(H,d,b);(function(a,b,c){for(var a=new Uint8Array(a,b,c),d="",f=0;f<c;f++)d=d+String.fromCharCode(a[b+f]);return d})(a,v,12);c=B(a,v+12);B(a,v+13);B(a,v+14);B(a,v+15);e=B(a,v+16);k=B(a,v+17);i=B(a,v+18);h=B(a,v+19);n=x(a,v+20);m=x(a,v+20+4);o=x(a,v+20+8);b=x(a,v+20+12);q=
  4091. x(a,v+20+16);l=x(a,v+20+20);s=x(a,v+20+24);w=x(a,v+20+28);r=x(a,v+20+32);A=x(a,v+20+36);u=x(a,v+20+40);v=v+c;c=e*3+h;y=e*4+h;K=b*c;R=q*(c+k*3);e=l*(c+i*3);h=s*(c+k*3+i*3);c=w*y;k=r*(y+k*4);i=A*(y+i*4);v=v+function(b){var b=new Float32Array(a,b,n*3),c,d,f,e;for(c=0;c<n;c++){d=b[c*3];f=b[c*3+1];e=b[c*3+2];H.vertices.push(new THREE.Vector3(d,f,e))}return n*3*Float32Array.BYTES_PER_ELEMENT}(v);v=v+function(b){if(m){var b=new Int8Array(a,b,m*3),c,d,f,e;for(c=0;c<m;c++){d=b[c*3];f=b[c*3+1];e=b[c*3+2];I.push(d/
  4092. 127,f/127,e/127)}}return m*3*Int8Array.BYTES_PER_ELEMENT}(v);v=v+t(m*3);v=v+function(b){if(o){var b=new Float32Array(a,b,o*2),c,d,f;for(c=0;c<o;c++){d=b[c*2];f=b[c*2+1];J.push(d,f)}}return o*2*Float32Array.BYTES_PER_ELEMENT}(v);K=v+K+t(b*2);R=K+R+t(q*2);e=R+e+t(l*2);h=e+h+t(s*2);c=h+c+t(w*2);k=c+k+t(r*2);i=k+i+t(A*2);(function(a){if(l){var b=a+l*Uint32Array.BYTES_PER_ELEMENT*3;C(l,a,b+l*Uint32Array.BYTES_PER_ELEMENT*3);D(l,b)}})(R);(function(a){if(s){var b=a+s*Uint32Array.BYTES_PER_ELEMENT*3,c=b+
  4093. s*Uint32Array.BYTES_PER_ELEMENT*3;E(s,a,b,c+s*Uint32Array.BYTES_PER_ELEMENT*3);D(s,c)}})(e);(function(a){if(A){var b=a+A*Uint32Array.BYTES_PER_ELEMENT*4;F(A,a,b+A*Uint32Array.BYTES_PER_ELEMENT*4);z(A,b)}})(k);(function(a){if(u){var b=a+u*Uint32Array.BYTES_PER_ELEMENT*4,c=b+u*Uint32Array.BYTES_PER_ELEMENT*4;L(u,a,b,c+u*Uint32Array.BYTES_PER_ELEMENT*4);z(u,c)}})(i);b&&C(b,v,v+b*Uint32Array.BYTES_PER_ELEMENT*3);(function(a){if(q){var b=a+q*Uint32Array.BYTES_PER_ELEMENT*3;E(q,a,b,b+q*Uint32Array.BYTES_PER_ELEMENT*
  4094. 3)}})(K);w&&F(w,h,h+w*Uint32Array.BYTES_PER_ELEMENT*4);(function(a){if(r){var b=a+r*Uint32Array.BYTES_PER_ELEMENT*4;L(r,a,b,b+r*Uint32Array.BYTES_PER_ELEMENT*4)}})(c);this.computeCentroids();this.computeFaceNormals();THREE.Loader.prototype.hasNormals(this)&&this.computeTangents()};e.prototype=new THREE.Geometry;e.prototype.constructor=e;b(new e(c))};THREE.JSONLoader=function(a){THREE.Loader.call(this,a)};THREE.JSONLoader.prototype=new THREE.Loader;THREE.JSONLoader.prototype.constructor=THREE.JSONLoader;
  4095. THREE.JSONLoader.prototype.load=function(a,b,c){c=c?c:this.extractUrlBase(a);this.onLoadStart();this.loadAjaxJSON(this,a,b,c)};
  4096. THREE.JSONLoader.prototype.loadAjaxJSON=function(a,b,c,d,e){var f=new XMLHttpRequest,g=0;f.onreadystatechange=function(){if(f.readyState===f.DONE)if(f.status===200||f.status===0){if(f.responseText){var j=JSON.parse(f.responseText);a.createModel(j,c,d)}else console.warn("THREE.JSONLoader: ["+b+"] seems to be unreachable or file there is empty");a.onLoadComplete()}else console.error("THREE.JSONLoader: Couldn't load ["+b+"] ["+f.status+"]");else if(f.readyState===f.LOADING){if(e){g===0&&(g=f.getResponseHeader("Content-Length"));
  4097. e({total:g,loaded:f.responseText.length})}}else f.readyState===f.HEADERS_RECEIVED&&(g=f.getResponseHeader("Content-Length"))};f.open("GET",b,true);f.overrideMimeType&&f.overrideMimeType("text/plain; charset=x-user-defined");f.setRequestHeader("Content-Type","text/plain");f.send(null)};
  4098. THREE.JSONLoader.prototype.createModel=function(a,b,c){var d=new THREE.Geometry,e=a.scale!==void 0?1/a.scale:1;this.initMaterials(d,a.materials,c);(function(b){var c,e,k,i,h,n,m,o,q,l,s,w,r,A,u=a.faces;n=a.vertices;var t=a.normals,B=a.colors,x=0;for(c=0;c<a.uvs.length;c++)a.uvs[c].length&&x++;for(c=0;c<x;c++){d.faceUvs[c]=[];d.faceVertexUvs[c]=[]}i=0;for(h=n.length;i<h;){m=new THREE.Vector3;m.x=n[i++]*b;m.y=n[i++]*b;m.z=n[i++]*b;d.vertices.push(m)}i=0;for(h=u.length;i<h;){b=u[i++];n=b&1;k=b&2;c=b&
  4099. 4;e=b&8;o=b&16;m=b&32;l=b&64;b=b&128;if(n){s=new THREE.Face4;s.a=u[i++];s.b=u[i++];s.c=u[i++];s.d=u[i++];n=4}else{s=new THREE.Face3;s.a=u[i++];s.b=u[i++];s.c=u[i++];n=3}if(k){k=u[i++];s.materialIndex=k}k=d.faces.length;if(c)for(c=0;c<x;c++){w=a.uvs[c];q=u[i++];A=w[q*2];q=w[q*2+1];d.faceUvs[c][k]=new THREE.UV(A,q)}if(e)for(c=0;c<x;c++){w=a.uvs[c];r=[];for(e=0;e<n;e++){q=u[i++];A=w[q*2];q=w[q*2+1];r[e]=new THREE.UV(A,q)}d.faceVertexUvs[c][k]=r}if(o){o=u[i++]*3;e=new THREE.Vector3;e.x=t[o++];e.y=t[o++];
  4100. e.z=t[o];s.normal=e}if(m)for(c=0;c<n;c++){o=u[i++]*3;e=new THREE.Vector3;e.x=t[o++];e.y=t[o++];e.z=t[o];s.vertexNormals.push(e)}if(l){m=u[i++];m=new THREE.Color(B[m]);s.color=m}if(b)for(c=0;c<n;c++){m=u[i++];m=new THREE.Color(B[m]);s.vertexColors.push(m)}d.faces.push(s)}})(e);(function(){var b,c,e,k;if(a.skinWeights){b=0;for(c=a.skinWeights.length;b<c;b=b+2){e=a.skinWeights[b];k=a.skinWeights[b+1];d.skinWeights.push(new THREE.Vector4(e,k,0,0))}}if(a.skinIndices){b=0;for(c=a.skinIndices.length;b<c;b=
  4101. b+2){e=a.skinIndices[b];k=a.skinIndices[b+1];d.skinIndices.push(new THREE.Vector4(e,k,0,0))}}d.bones=a.bones;d.animation=a.animation})();(function(b){if(a.morphTargets!==void 0){var c,e,k,i,h,n;c=0;for(e=a.morphTargets.length;c<e;c++){d.morphTargets[c]={};d.morphTargets[c].name=a.morphTargets[c].name;d.morphTargets[c].vertices=[];h=d.morphTargets[c].vertices;n=a.morphTargets[c].vertices;k=0;for(i=n.length;k<i;k=k+3){var m=new THREE.Vector3;m.x=n[k]*b;m.y=n[k+1]*b;m.z=n[k+2]*b;h.push(m)}}}if(a.morphColors!==
  4102. void 0){c=0;for(e=a.morphColors.length;c<e;c++){d.morphColors[c]={};d.morphColors[c].name=a.morphColors[c].name;d.morphColors[c].colors=[];i=d.morphColors[c].colors;h=a.morphColors[c].colors;b=0;for(k=h.length;b<k;b=b+3){n=new THREE.Color(16755200);n.setRGB(h[b],h[b+1],h[b+2]);i.push(n)}}}})(e);d.computeCentroids();d.computeFaceNormals();this.hasNormals(d)&&d.computeTangents();b(d)};
  4103. THREE.SceneLoader=function(){this.onLoadStart=function(){};this.onLoadProgress=function(){};this.onLoadComplete=function(){};this.callbackSync=function(){};this.callbackProgress=function(){}};THREE.SceneLoader.prototype.constructor=THREE.SceneLoader;
  4104. THREE.SceneLoader.prototype.load=function(a,b){var c=this,d=new XMLHttpRequest;d.onreadystatechange=function(){if(d.readyState==4)if(d.status==200||d.status==0){var e=JSON.parse(d.responseText);c.createScene(e,b,a)}else console.error("THREE.SceneLoader: Couldn't load ["+a+"] ["+d.status+"]")};d.open("GET",a,true);d.overrideMimeType&&d.overrideMimeType("text/plain; charset=x-user-defined");d.setRequestHeader("Content-Type","text/plain");d.send(null)};
  4105. THREE.SceneLoader.prototype.createScene=function(a,b,c){function d(a,b){return b=="relativeToHTML"?a:i+"/"+a}function e(){var a;for(m in v.objects)if(!p.objects[m]){w=v.objects[m];if(w.geometry!==void 0){if(F=p.geometries[w.geometry]){a=false;E=p.materials[w.materials[0]];(a=E instanceof THREE.ShaderMaterial)&&F.computeTangents();t=w.position;B=w.rotation;x=w.quaternion;D=w.scale;r=w.matrix;x=0;w.materials.length==0&&(E=new THREE.MeshFaceMaterial);w.materials.length>1&&(E=new THREE.MeshFaceMaterial);
  4106. a=new THREE.Mesh(F,E);a.name=m;if(r){a.matrixAutoUpdate=false;a.matrix.set(r[0],r[1],r[2],r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11],r[12],r[13],r[14],r[15])}else{a.position.set(t[0],t[1],t[2]);if(x){a.quaternion.set(x[0],x[1],x[2],x[3]);a.useQuaternion=true}else a.rotation.set(B[0],B[1],B[2]);a.scale.set(D[0],D[1],D[2])}a.visible=w.visible;a.doubleSided=w.doubleSided;a.castShadow=w.castShadow;a.receiveShadow=w.receiveShadow;p.scene.add(a);p.objects[m]=a}}else{t=w.position;B=w.rotation;x=w.quaternion;
  4107. D=w.scale;x=0;a=new THREE.Object3D;a.name=m;a.position.set(t[0],t[1],t[2]);if(x){a.quaternion.set(x[0],x[1],x[2],x[3]);a.useQuaternion=true}else a.rotation.set(B[0],B[1],B[2]);a.scale.set(D[0],D[1],D[2]);a.visible=w.visible!==void 0?w.visible:false;p.scene.add(a);p.objects[m]=a;p.empties[m]=a}}}function f(a){return function(b){p.geometries[a]=b;e();J=J-1;k.onLoadComplete();j()}}function g(a){return function(b){p.geometries[a]=b}}function j(){k.callbackProgress({totalModels:R,totalTextures:y,loadedModels:R-
  4108. J,loadedTextures:y-K},p);k.onLoadProgress();J==0&&K==0&&b(p)}var k=this,i=THREE.Loader.prototype.extractUrlBase(c),h,n,m,o,q,l,s,w,r,A,u,t,B,x,D,z,C,F,E,L,H,v,I,J,K,R,y,p;v=a;c=new THREE.BinaryLoader;I=new THREE.JSONLoader;K=J=0;p={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{},empties:{}};if(v.transform){a=v.transform.position;A=v.transform.rotation;z=v.transform.scale;a&&p.scene.position.set(a[0],a[1],a[2]);A&&p.scene.rotation.set(A[0],A[1],
  4109. A[2]);z&&p.scene.scale.set(z[0],z[1],z[2]);if(a||A||z){p.scene.updateMatrix();p.scene.updateMatrixWorld()}}a=function(){K=K-1;j();k.onLoadComplete()};for(q in v.cameras){z=v.cameras[q];z.type=="perspective"?L=new THREE.PerspectiveCamera(z.fov,z.aspect,z.near,z.far):z.type=="ortho"&&(L=new THREE.OrthographicCamera(z.left,z.right,z.top,z.bottom,z.near,z.far));t=z.position;A=z.target;z=z.up;L.position.set(t[0],t[1],t[2]);L.target=new THREE.Vector3(A[0],A[1],A[2]);z&&L.up.set(z[0],z[1],z[2]);p.cameras[q]=
  4110. L}for(o in v.lights){A=v.lights[o];q=A.color!==void 0?A.color:16777215;L=A.intensity!==void 0?A.intensity:1;if(A.type=="directional"){t=A.direction;u=new THREE.DirectionalLight(q,L);u.position.set(t[0],t[1],t[2]);u.position.normalize()}else if(A.type=="point"){t=A.position;u=A.distance;u=new THREE.PointLight(q,L,u);u.position.set(t[0],t[1],t[2])}else A.type=="ambient"&&(u=new THREE.AmbientLight(q));p.scene.add(u);p.lights[o]=u}for(l in v.fogs){o=v.fogs[l];o.type=="linear"?H=new THREE.Fog(0,o.near,
  4111. o.far):o.type=="exp2"&&(H=new THREE.FogExp2(0,o.density));z=o.color;H.color.setRGB(z[0],z[1],z[2]);p.fogs[l]=H}if(p.cameras&&v.defaults.camera)p.currentCamera=p.cameras[v.defaults.camera];if(p.fogs&&v.defaults.fog)p.scene.fog=p.fogs[v.defaults.fog];z=v.defaults.bgcolor;p.bgColor=new THREE.Color;p.bgColor.setRGB(z[0],z[1],z[2]);p.bgColorAlpha=v.defaults.bgalpha;for(h in v.geometries){l=v.geometries[h];if(l.type=="bin_mesh"||l.type=="ascii_mesh"){J=J+1;k.onLoadStart()}}R=J;for(h in v.geometries){l=
  4112. v.geometries[h];if(l.type=="cube"){F=new THREE.CubeGeometry(l.width,l.height,l.depth,l.segmentsWidth,l.segmentsHeight,l.segmentsDepth,null,l.flipped,l.sides);p.geometries[h]=F}else if(l.type=="plane"){F=new THREE.PlaneGeometry(l.width,l.height,l.segmentsWidth,l.segmentsHeight);p.geometries[h]=F}else if(l.type=="sphere"){F=new THREE.SphereGeometry(l.radius,l.segmentsWidth,l.segmentsHeight);p.geometries[h]=F}else if(l.type=="cylinder"){F=new THREE.CylinderGeometry(l.topRad,l.botRad,l.height,l.radSegs,
  4113. l.heightSegs);p.geometries[h]=F}else if(l.type=="torus"){F=new THREE.TorusGeometry(l.radius,l.tube,l.segmentsR,l.segmentsT);p.geometries[h]=F}else if(l.type=="icosahedron"){F=new THREE.IcosahedronGeometry(l.radius,l.subdivisions);p.geometries[h]=F}else if(l.type=="bin_mesh")c.load(d(l.url,v.urlBaseType),f(h));else if(l.type=="ascii_mesh")I.load(d(l.url,v.urlBaseType),f(h));else if(l.type=="embedded_mesh"){l=v.embeds[l.id];l.metadata=v.metadata;l&&I.createModel(l,g(h),"")}}for(s in v.textures){h=v.textures[s];
  4114. if(h.url instanceof Array){K=K+h.url.length;for(l=0;l<h.url.length;l++)k.onLoadStart()}else{K=K+1;k.onLoadStart()}}y=K;for(s in v.textures){h=v.textures[s];if(h.mapping!=void 0&&THREE[h.mapping]!=void 0)h.mapping=new THREE[h.mapping];if(h.url instanceof Array){l=[];for(H=0;H<h.url.length;H++)l[H]=d(h.url[H],v.urlBaseType);l=THREE.ImageUtils.loadTextureCube(l,h.mapping,a)}else{l=THREE.ImageUtils.loadTexture(d(h.url,v.urlBaseType),h.mapping,a);if(THREE[h.minFilter]!=void 0)l.minFilter=THREE[h.minFilter];
  4115. if(THREE[h.magFilter]!=void 0)l.magFilter=THREE[h.magFilter];if(h.repeat){l.repeat.set(h.repeat[0],h.repeat[1]);if(h.repeat[0]!=1)l.wrapS=THREE.RepeatWrapping;if(h.repeat[1]!=1)l.wrapT=THREE.RepeatWrapping}h.offset&&l.offset.set(h.offset[0],h.offset[1]);if(h.wrap){H={repeat:THREE.RepeatWrapping,mirror:THREE.MirroredRepeatWrapping};if(H[h.wrap[0]]!==void 0)l.wrapS=H[h.wrap[0]];if(H[h.wrap[1]]!==void 0)l.wrapT=H[h.wrap[1]]}}p.textures[s]=l}for(n in v.materials){r=v.materials[n];for(C in r.parameters)if(C==
  4116. "envMap"||C=="map"||C=="lightMap")r.parameters[C]=p.textures[r.parameters[C]];else if(C=="shading")r.parameters[C]=r.parameters[C]=="flat"?THREE.FlatShading:THREE.SmoothShading;else if(C=="blending")r.parameters[C]=THREE[r.parameters[C]]?THREE[r.parameters[C]]:THREE.NormalBlending;else if(C=="combine")r.parameters[C]=r.parameters[C]=="MixOperation"?THREE.MixOperation:THREE.MultiplyOperation;else if(C=="vertexColors")if(r.parameters[C]=="face")r.parameters[C]=THREE.FaceColors;else if(r.parameters[C])r.parameters[C]=
  4117. THREE.VertexColors;if(r.parameters.opacity!==void 0&&r.parameters.opacity<1)r.parameters.transparent=true;if(r.parameters.normalMap){s=THREE.ShaderUtils.lib.normal;a=THREE.UniformsUtils.clone(s.uniforms);h=r.parameters.color;l=r.parameters.specular;H=r.parameters.ambient;c=r.parameters.shininess;a.tNormal.texture=p.textures[r.parameters.normalMap];if(r.parameters.normalMapFactor)a.uNormalScale.value=r.parameters.normalMapFactor;if(r.parameters.map){a.tDiffuse.texture=r.parameters.map;a.enableDiffuse.value=
  4118. true}if(r.parameters.lightMap){a.tAO.texture=r.parameters.lightMap;a.enableAO.value=true}if(r.parameters.specularMap){a.tSpecular.texture=p.textures[r.parameters.specularMap];a.enableSpecular.value=true}a.uDiffuseColor.value.setHex(h);a.uSpecularColor.value.setHex(l);a.uAmbientColor.value.setHex(H);a.uShininess.value=c;if(r.parameters.opacity)a.uOpacity.value=r.parameters.opacity;E=new THREE.ShaderMaterial({fragmentShader:s.fragmentShader,vertexShader:s.vertexShader,uniforms:a,lights:true,fog:true})}else E=
  4119. new THREE[r.type](r.parameters);p.materials[n]=E}e();k.callbackSync(p);j()};
  4120. 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?
  4121. 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;
  4122. 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;
  4123. THREE.DstAlphaFactor=206;THREE.OneMinusDstAlphaFactor=207;THREE.DstColorFactor=208;THREE.OneMinusDstColorFactor=209;THREE.SrcAlphaSaturateFactor=210;
  4124. 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;
  4125. 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:
  4126. 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!==
  4127. void 0?a.morphTargets:false};THREE.MeshBasicMaterial.prototype=new THREE.Material;THREE.MeshBasicMaterial.prototype.constructor=THREE.MeshBasicMaterial;
  4128. THREE.MeshLambertMaterial=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.ambient=a.ambient!==void 0?new THREE.Color(a.ambient):new THREE.Color(16777215);this.emissive=a.emissive!==void 0?new THREE.Color(a.emissive):new THREE.Color(0);this.wrapAround=a.wrapAround!==void 0?a.wrapAround:false;this.wrapRGB=new THREE.Vector3(1,1,1);this.map=a.map!==void 0?a.map:null;this.lightMap=a.lightMap!==void 0?a.lightMap:null;this.envMap=
  4129. 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: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?
  4130. 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!==void 0?a.morphTargets:false;this.morphNormals=a.morphNormals!==void 0?a.morphNormals:false};THREE.MeshLambertMaterial.prototype=new THREE.Material;THREE.MeshLambertMaterial.prototype.constructor=THREE.MeshLambertMaterial;
  4131. THREE.MeshPhongMaterial=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.ambient=a.ambient!==void 0?new THREE.Color(a.ambient):new THREE.Color(16777215);this.emissive=a.emissive!==void 0?new THREE.Color(a.emissive):new THREE.Color(0);this.specular=a.specular!==void 0?new THREE.Color(a.specular):new THREE.Color(1118481);this.shininess=a.shininess!==void 0?a.shininess:30;this.metal=a.metal!==void 0?a.metal:false;this.perPixel=
  4132. a.perPixel!==void 0?a.perPixel:false;this.wrapAround=a.wrapAround!==void 0?a.wrapAround:false;this.wrapRGB=new THREE.Vector3(1,1,1);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:true;this.shading=
  4133. 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!==void 0?
  4134. a.morphTargets:false;this.morphNormals=a.morphNormals!==void 0?a.morphNormals:false};THREE.MeshPhongMaterial.prototype=new THREE.Material;THREE.MeshPhongMaterial.prototype.constructor=THREE.MeshPhongMaterial;THREE.MeshDepthMaterial=function(a){THREE.Material.call(this,a);a=a||{};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};
  4135. THREE.MeshDepthMaterial.prototype=new THREE.Material;THREE.MeshDepthMaterial.prototype.constructor=THREE.MeshDepthMaterial;THREE.MeshNormalMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.shading=a.shading?a.shading:THREE.FlatShading;this.wireframe=a.wireframe?a.wireframe:false;this.wireframeLinewidth=a.wireframeLinewidth?a.wireframeLinewidth:1};THREE.MeshNormalMaterial.prototype=new THREE.Material;THREE.MeshNormalMaterial.prototype.constructor=THREE.MeshNormalMaterial;
  4136. THREE.MeshFaceMaterial=function(){};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;
  4137. THREE.ParticleBasicMaterial.prototype.constructor=THREE.ParticleBasicMaterial;
  4138. THREE.Texture=function(a,b,c,d,e,f,g,j){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=j!==void 0?j:THREE.UnsignedByteType;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.generateMipmaps=
  4139. 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(){};
  4140. 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;
  4141. 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,j,k,i){THREE.Texture.call(this,null,f,g,j,k,i,d,e);this.image={data:a,width:b,height:c}};THREE.DataTexture.prototype=new THREE.Texture;THREE.DataTexture.prototype.constructor=THREE.DataTexture;
  4142. 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;
  4143. 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;
  4144. 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);
  4145. 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};
  4146. THREE.Bone=function(a){THREE.Object3D.call(this);this.skin=a;this.skinMatrix=new THREE.Matrix4};THREE.Bone.prototype=new THREE.Object3D;THREE.Bone.prototype.constructor=THREE.Bone;THREE.Bone.prototype.supr=THREE.Object3D.prototype;
  4147. 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)};
  4148. 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!==
  4149. 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=
  4150. 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={};
  4151. 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);
  4152. 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;
  4153. 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])};
  4154. 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])};
  4155. THREE.SVGRenderer=function(){function a(a,b,c,d){var e,f,g,h,i,j;e=0;for(f=a.length;e<f;e++){g=a[e];h=g.color;if(g instanceof THREE.DirectionalLight){i=g.matrixWorld.getPosition();j=c.dot(i);if(!(j<=0)){j=j*g.intensity;d.r=d.r+h.r*j;d.g=d.g+h.g*j;d.b=d.b+h.b*j}}else if(g instanceof THREE.PointLight){i=g.matrixWorld.getPosition();j=c.dot(z.sub(i,b).normalize());if(!(j<=0)){j=j*(g.distance==0?1:1-Math.min(b.distanceTo(i)/g.distance,1));if(j!=0){j=j*g.intensity;d.r=d.r+h.r*j;d.g=d.g+h.g*j;d.b=d.b+h.b*
  4156. j}}}}}function b(a){if(C[a]==null){C[a]=document.createElementNS("http://www.w3.org/2000/svg","path");v==0&&C[a].setAttribute("shape-rendering","crispEdges")}return C[a]}function c(a){a=(a+1)*0.5;return a<0?0:a>1?1:a}console.log("THREE.SVGRenderer",THREE.REVISION);var d=this,e,f,g,j=new THREE.Projector,k=document.createElementNS("http://www.w3.org/2000/svg","svg"),i,h,n,m,o,q,l,s,w=new THREE.Rectangle,r=new THREE.Rectangle,A=false,u=new THREE.Color,t=new THREE.Color,B=new THREE.Color,x=new THREE.Color,
  4157. D,z=new THREE.Vector3,C=[],F=[],E,L,H,v=1;this.domElement=k;this.sortElements=this.sortObjects=this.autoClear=true;this.info={render:{vertices:0,faces:0}};this.setQuality=function(a){switch(a){case "high":v=1;break;case "low":v=0}};this.setSize=function(a,b){i=a;h=b;n=i/2;m=h/2;k.setAttribute("viewBox",-n+" "+-m+" "+i+" "+h);k.setAttribute("width",i);k.setAttribute("height",h);w.set(-n,-m,n,m)};this.clear=function(){for(;k.childNodes.length>0;)k.removeChild(k.childNodes[0])};this.render=function(h,
  4158. i){var z,C,y,p;this.autoClear&&this.clear();d.info.render.vertices=0;d.info.render.faces=0;e=j.projectScene(h,i,this.sortElements);f=e.elements;g=e.lights;H=L=0;if(A=g.length>0){t.setRGB(0,0,0);B.setRGB(0,0,0);x.setRGB(0,0,0);z=0;for(C=g.length;z<C;z++){p=g[z];y=p.color;if(p instanceof THREE.AmbientLight){t.r=t.r+y.r;t.g=t.g+y.g;t.b=t.b+y.b}else if(p instanceof THREE.DirectionalLight){B.r=B.r+y.r;B.g=B.g+y.g;B.b=B.b+y.b}else if(p instanceof THREE.PointLight){x.r=x.r+y.r;x.g=x.g+y.g;x.b=x.b+y.b}}}z=
  4159. 0;for(C=f.length;z<C;z++){y=f[z];p=y.material;p=p instanceof THREE.MeshFaceMaterial?y.faceMaterial:p;if(!(p===void 0||p.visible===false)){r.empty();if(y instanceof THREE.RenderableParticle){o=y;o.x=o.x*n;o.y=o.y*-m}else if(y instanceof THREE.RenderableLine){o=y.v1;q=y.v2;o.positionScreen.x=o.positionScreen.x*n;o.positionScreen.y=o.positionScreen.y*-m;q.positionScreen.x=q.positionScreen.x*n;q.positionScreen.y=q.positionScreen.y*-m;r.addPoint(o.positionScreen.x,o.positionScreen.y);r.addPoint(q.positionScreen.x,
  4160. q.positionScreen.y);if(w.intersects(r)){y=o;var P=q,G=H++;if(F[G]==null){F[G]=document.createElementNS("http://www.w3.org/2000/svg","line");v==0&&F[G].setAttribute("shape-rendering","crispEdges")}E=F[G];E.setAttribute("x1",y.positionScreen.x);E.setAttribute("y1",y.positionScreen.y);E.setAttribute("x2",P.positionScreen.x);E.setAttribute("y2",P.positionScreen.y);if(p instanceof THREE.LineBasicMaterial){E.setAttribute("style","fill: none; stroke: "+p.color.getContextStyle()+"; stroke-width: "+p.linewidth+
  4161. "; stroke-opacity: "+p.opacity+"; stroke-linecap: "+p.linecap+"; stroke-linejoin: "+p.linejoin);k.appendChild(E)}}}else if(y instanceof THREE.RenderableFace3){o=y.v1;q=y.v2;l=y.v3;o.positionScreen.x=o.positionScreen.x*n;o.positionScreen.y=o.positionScreen.y*-m;q.positionScreen.x=q.positionScreen.x*n;q.positionScreen.y=q.positionScreen.y*-m;l.positionScreen.x=l.positionScreen.x*n;l.positionScreen.y=l.positionScreen.y*-m;r.addPoint(o.positionScreen.x,o.positionScreen.y);r.addPoint(q.positionScreen.x,
  4162. q.positionScreen.y);r.addPoint(l.positionScreen.x,l.positionScreen.y);if(w.intersects(r)){var P=o,G=q,N=l;d.info.render.vertices=d.info.render.vertices+3;d.info.render.faces++;E=b(L++);E.setAttribute("d","M "+P.positionScreen.x+" "+P.positionScreen.y+" L "+G.positionScreen.x+" "+G.positionScreen.y+" L "+N.positionScreen.x+","+N.positionScreen.y+"z");if(p instanceof THREE.MeshBasicMaterial)u.copy(p.color);else if(p instanceof THREE.MeshLambertMaterial)if(A){u.r=t.r;u.g=t.g;u.b=t.b;a(g,y.centroidWorld,
  4163. y.normalWorld,u);u.r=Math.max(0,Math.min(p.color.r*u.r,1));u.g=Math.max(0,Math.min(p.color.g*u.g,1));u.b=Math.max(0,Math.min(p.color.b*u.b,1))}else u.copy(p.color);else if(p instanceof THREE.MeshDepthMaterial){D=1-p.__2near/(p.__farPlusNear-y.z*p.__farMinusNear);u.setRGB(D,D,D)}else p instanceof THREE.MeshNormalMaterial&&u.setRGB(c(y.normalWorld.x),c(y.normalWorld.y),c(y.normalWorld.z));p.wireframe?E.setAttribute("style","fill: none; stroke: "+u.getContextStyle()+"; stroke-width: "+p.wireframeLinewidth+
  4164. "; stroke-opacity: "+p.opacity+"; stroke-linecap: "+p.wireframeLinecap+"; stroke-linejoin: "+p.wireframeLinejoin):E.setAttribute("style","fill: "+u.getContextStyle()+"; fill-opacity: "+p.opacity);k.appendChild(E)}}else if(y instanceof THREE.RenderableFace4){o=y.v1;q=y.v2;l=y.v3;s=y.v4;o.positionScreen.x=o.positionScreen.x*n;o.positionScreen.y=o.positionScreen.y*-m;q.positionScreen.x=q.positionScreen.x*n;q.positionScreen.y=q.positionScreen.y*-m;l.positionScreen.x=l.positionScreen.x*n;l.positionScreen.y=
  4165. l.positionScreen.y*-m;s.positionScreen.x=s.positionScreen.x*n;s.positionScreen.y=s.positionScreen.y*-m;r.addPoint(o.positionScreen.x,o.positionScreen.y);r.addPoint(q.positionScreen.x,q.positionScreen.y);r.addPoint(l.positionScreen.x,l.positionScreen.y);r.addPoint(s.positionScreen.x,s.positionScreen.y);if(w.intersects(r)){var P=o,G=q,N=l,O=s;d.info.render.vertices=d.info.render.vertices+4;d.info.render.faces++;E=b(L++);E.setAttribute("d","M "+P.positionScreen.x+" "+P.positionScreen.y+" L "+G.positionScreen.x+
  4166. " "+G.positionScreen.y+" L "+N.positionScreen.x+","+N.positionScreen.y+" L "+O.positionScreen.x+","+O.positionScreen.y+"z");if(p instanceof THREE.MeshBasicMaterial)u.copy(p.color);else if(p instanceof THREE.MeshLambertMaterial)if(A){u.r=t.r;u.g=t.g;u.b=t.b;a(g,y.centroidWorld,y.normalWorld,u);u.r=Math.max(0,Math.min(p.color.r*u.r,1));u.g=Math.max(0,Math.min(p.color.g*u.g,1));u.b=Math.max(0,Math.min(p.color.b*u.b,1))}else u.copy(p.color);else if(p instanceof THREE.MeshDepthMaterial){D=1-p.__2near/
  4167. (p.__farPlusNear-y.z*p.__farMinusNear);u.setRGB(D,D,D)}else p instanceof THREE.MeshNormalMaterial&&u.setRGB(c(y.normalWorld.x),c(y.normalWorld.y),c(y.normalWorld.z));p.wireframe?E.setAttribute("style","fill: none; stroke: "+u.getContextStyle()+"; stroke-width: "+p.wireframeLinewidth+"; stroke-opacity: "+p.opacity+"; stroke-linecap: "+p.wireframeLinecap+"; stroke-linejoin: "+p.wireframeLinejoin):E.setAttribute("style","fill: "+u.getContextStyle()+"; fill-opacity: "+p.opacity);k.appendChild(E)}}}}}};
  4168. 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)};
  4169. 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};
  4170. 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};
  4171. 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};
  4172. >>>>>>> dev