ThreeWebGL.js 588 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810
  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. * Spline from Tween.js, slightly optimized (and trashed)
  2745. * http://sole.github.com/tween.js/examples/05_spline.html
  2746. *
  2747. * @author mrdoob / http://mrdoob.com/
  2748. * @author alteredq / http://alteredqualia.com/
  2749. */
  2750. THREE.Spline = function ( points ) {
  2751. this.points = points;
  2752. var c = [], v3 = { x: 0, y: 0, z: 0 },
  2753. point, intPoint, weight, w2, w3,
  2754. pa, pb, pc, pd;
  2755. this.initFromArray = function( a ) {
  2756. this.points = [];
  2757. for ( var i = 0; i < a.length; i++ ) {
  2758. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  2759. }
  2760. };
  2761. this.getPoint = function ( k ) {
  2762. point = ( this.points.length - 1 ) * k;
  2763. intPoint = Math.floor( point );
  2764. weight = point - intPoint;
  2765. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  2766. c[ 1 ] = intPoint;
  2767. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  2768. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  2769. pa = this.points[ c[ 0 ] ];
  2770. pb = this.points[ c[ 1 ] ];
  2771. pc = this.points[ c[ 2 ] ];
  2772. pd = this.points[ c[ 3 ] ];
  2773. w2 = weight * weight;
  2774. w3 = weight * w2;
  2775. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  2776. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  2777. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  2778. return v3;
  2779. };
  2780. this.getControlPointsArray = function () {
  2781. var i, p, l = this.points.length,
  2782. coords = [];
  2783. for ( i = 0; i < l; i ++ ) {
  2784. p = this.points[ i ];
  2785. coords[ i ] = [ p.x, p.y, p.z ];
  2786. }
  2787. return coords;
  2788. };
  2789. // approximate length by summing linear segments
  2790. this.getLength = function ( nSubDivisions ) {
  2791. var i, index, nSamples, position,
  2792. point = 0, intPoint = 0, oldIntPoint = 0,
  2793. oldPosition = new THREE.Vector3(),
  2794. tmpVec = new THREE.Vector3(),
  2795. chunkLengths = [],
  2796. totalLength = 0;
  2797. // first point has 0 length
  2798. chunkLengths[ 0 ] = 0;
  2799. if ( !nSubDivisions ) nSubDivisions = 100;
  2800. nSamples = this.points.length * nSubDivisions;
  2801. oldPosition.copy( this.points[ 0 ] );
  2802. for ( i = 1; i < nSamples; i ++ ) {
  2803. index = i / nSamples;
  2804. position = this.getPoint( index );
  2805. tmpVec.copy( position );
  2806. totalLength += tmpVec.distanceTo( oldPosition );
  2807. oldPosition.copy( position );
  2808. point = ( this.points.length - 1 ) * index;
  2809. intPoint = Math.floor( point );
  2810. if ( intPoint != oldIntPoint ) {
  2811. chunkLengths[ intPoint ] = totalLength;
  2812. oldIntPoint = intPoint;
  2813. }
  2814. }
  2815. // last point ends with total length
  2816. chunkLengths[ chunkLengths.length ] = totalLength;
  2817. return { chunks: chunkLengths, total: totalLength };
  2818. };
  2819. this.reparametrizeByArcLength = function ( samplingCoef ) {
  2820. var i, j,
  2821. index, indexCurrent, indexNext,
  2822. linearDistance, realDistance,
  2823. sampling, position,
  2824. newpoints = [],
  2825. tmpVec = new THREE.Vector3(),
  2826. sl = this.getLength();
  2827. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  2828. for ( i = 1; i < this.points.length; i++ ) {
  2829. //tmpVec.copy( this.points[ i - 1 ] );
  2830. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  2831. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  2832. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  2833. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  2834. indexNext = i / ( this.points.length - 1 );
  2835. for ( j = 1; j < sampling - 1; j++ ) {
  2836. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  2837. position = this.getPoint( index );
  2838. newpoints.push( tmpVec.copy( position ).clone() );
  2839. }
  2840. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  2841. }
  2842. this.points = newpoints;
  2843. };
  2844. // Catmull-Rom
  2845. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  2846. var v0 = ( p2 - p0 ) * 0.5,
  2847. v1 = ( p3 - p1 ) * 0.5;
  2848. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  2849. };
  2850. };
  2851. /**
  2852. * @author mr.doob / http://mrdoob.com/
  2853. * @author mikael emtinger / http://gomo.se/
  2854. */
  2855. THREE.Camera = function () {
  2856. THREE.Object3D.call( this );
  2857. this.matrixWorldInverse = new THREE.Matrix4();
  2858. this.projectionMatrix = new THREE.Matrix4();
  2859. this.projectionMatrixInverse = new THREE.Matrix4();
  2860. };
  2861. THREE.Camera.prototype = new THREE.Object3D();
  2862. THREE.Camera.prototype.constructor = THREE.Camera;
  2863. THREE.Camera.prototype.lookAt = function ( vector ) {
  2864. // TODO: Add hierarchy support.
  2865. this.matrix.lookAt( this.position, vector, this.up );
  2866. if ( this.rotationAutoUpdate ) {
  2867. this.rotation.getRotationFromMatrix( this.matrix );
  2868. }
  2869. };
  2870. /**
  2871. * @author alteredq / http://alteredqualia.com/
  2872. */
  2873. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  2874. THREE.Camera.call( this );
  2875. this.left = left;
  2876. this.right = right;
  2877. this.top = top;
  2878. this.bottom = bottom;
  2879. this.near = ( near !== undefined ) ? near : 0.1;
  2880. this.far = ( far !== undefined ) ? far : 2000;
  2881. this.updateProjectionMatrix();
  2882. };
  2883. THREE.OrthographicCamera.prototype = new THREE.Camera();
  2884. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  2885. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  2886. this.projectionMatrix.makeOrthographic( this.left, this.right, this.top, this.bottom, this.near, this.far );
  2887. };
  2888. /**
  2889. * @author mr.doob / http://mrdoob.com/
  2890. * @author greggman / http://games.greggman.com/
  2891. * @author zz85 / http://www.lab4games.net/zz85/blog
  2892. */
  2893. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  2894. THREE.Camera.call( this );
  2895. this.fov = fov !== undefined ? fov : 50;
  2896. this.aspect = aspect !== undefined ? aspect : 1;
  2897. this.near = near !== undefined ? near : 0.1;
  2898. this.far = far !== undefined ? far : 2000;
  2899. this.updateProjectionMatrix();
  2900. };
  2901. THREE.PerspectiveCamera.prototype = new THREE.Camera();
  2902. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  2903. /**
  2904. * Uses Focal Length (in mm) to estimate and set FOV
  2905. * 35mm (fullframe) camera is used if frame size is not specified;
  2906. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  2907. */
  2908. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  2909. frameHeight = frameHeight !== undefined ? frameHeight : 24;
  2910. this.fov = 2 * Math.atan( frameHeight / ( focalLength * 2 ) ) * ( 180 / Math.PI );
  2911. this.updateProjectionMatrix();
  2912. }
  2913. /**
  2914. * Sets an offset in a larger frustum. This is useful for multi-window or
  2915. * multi-monitor/multi-machine setups.
  2916. *
  2917. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  2918. * the monitors are in grid like this
  2919. *
  2920. * +---+---+---+
  2921. * | A | B | C |
  2922. * +---+---+---+
  2923. * | D | E | F |
  2924. * +---+---+---+
  2925. *
  2926. * then for each monitor you would call it like this
  2927. *
  2928. * var w = 1920;
  2929. * var h = 1080;
  2930. * var fullWidth = w * 3;
  2931. * var fullHeight = h * 2;
  2932. *
  2933. * --A--
  2934. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  2935. * --B--
  2936. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  2937. * --C--
  2938. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  2939. * --D--
  2940. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  2941. * --E--
  2942. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  2943. * --F--
  2944. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  2945. *
  2946. * Note there is no reason monitors have to be the same size or in a grid.
  2947. */
  2948. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  2949. this.fullWidth = fullWidth;
  2950. this.fullHeight = fullHeight;
  2951. this.x = x;
  2952. this.y = y;
  2953. this.width = width;
  2954. this.height = height;
  2955. this.updateProjectionMatrix();
  2956. };
  2957. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  2958. if ( this.fullWidth ) {
  2959. var aspect = this.fullWidth / this.fullHeight;
  2960. var top = Math.tan( this.fov * Math.PI / 360 ) * this.near;
  2961. var bottom = -top;
  2962. var left = aspect * bottom;
  2963. var right = aspect * top;
  2964. var width = Math.abs( right - left );
  2965. var height = Math.abs( top - bottom );
  2966. this.projectionMatrix.makeFrustum(
  2967. left + this.x * width / this.fullWidth,
  2968. left + ( this.x + this.width ) * width / this.fullWidth,
  2969. top - ( this.y + this.height ) * height / this.fullHeight,
  2970. top - this.y * height / this.fullHeight,
  2971. this.near,
  2972. this.far
  2973. );
  2974. } else {
  2975. this.projectionMatrix.makePerspective( this.fov, this.aspect, this.near, this.far );
  2976. }
  2977. };
  2978. /**
  2979. * @author mr.doob / http://mrdoob.com/
  2980. * @author alteredq / http://alteredqualia.com/
  2981. */
  2982. THREE.Light = function ( hex ) {
  2983. THREE.Object3D.call( this );
  2984. this.color = new THREE.Color( hex );
  2985. };
  2986. THREE.Light.prototype = new THREE.Object3D();
  2987. THREE.Light.prototype.constructor = THREE.Light;
  2988. THREE.Light.prototype.supr = THREE.Object3D.prototype;
  2989. /**
  2990. * @author mr.doob / http://mrdoob.com/
  2991. */
  2992. THREE.AmbientLight = function ( hex ) {
  2993. THREE.Light.call( this, hex );
  2994. };
  2995. THREE.AmbientLight.prototype = new THREE.Light();
  2996. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  2997. /**
  2998. * @author mr.doob / http://mrdoob.com/
  2999. * @author alteredq / http://alteredqualia.com/
  3000. */
  3001. THREE.DirectionalLight = function ( hex, intensity, distance ) {
  3002. THREE.Light.call( this, hex );
  3003. this.position = new THREE.Vector3( 0, 1, 0 );
  3004. this.target = new THREE.Object3D();
  3005. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  3006. this.distance = ( distance !== undefined ) ? distance : 0;
  3007. this.castShadow = false;
  3008. this.onlyShadow = false;
  3009. //
  3010. this.shadowCameraNear = 50;
  3011. this.shadowCameraFar = 5000;
  3012. this.shadowCameraLeft = -500;
  3013. this.shadowCameraRight = 500;
  3014. this.shadowCameraTop = 500;
  3015. this.shadowCameraBottom = -500;
  3016. this.shadowCameraVisible = false;
  3017. this.shadowBias = 0;
  3018. this.shadowDarkness = 0.5;
  3019. this.shadowMapWidth = 512;
  3020. this.shadowMapHeight = 512;
  3021. //
  3022. this.shadowCascade = false;
  3023. this.shadowCascadeOffset = new THREE.Vector3( 0, 0, -1000 );
  3024. this.shadowCascadeCount = 2;
  3025. this.shadowCascadeBias = [ 0, 0, 0 ];
  3026. this.shadowCascadeWidth = [ 512, 512, 512 ];
  3027. this.shadowCascadeHeight = [ 512, 512, 512 ];
  3028. this.shadowCascadeNearZ = [ -1.000, 0.990, 0.998 ];
  3029. this.shadowCascadeFarZ = [ 0.990, 0.998, 1.000 ];
  3030. this.shadowCascadeArray = [];
  3031. //
  3032. this.shadowMap = null;
  3033. this.shadowMapSize = null;
  3034. this.shadowCamera = null;
  3035. this.shadowMatrix = null;
  3036. };
  3037. THREE.DirectionalLight.prototype = new THREE.Light();
  3038. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  3039. /**
  3040. * @author mr.doob / http://mrdoob.com/
  3041. */
  3042. THREE.PointLight = function ( hex, intensity, distance ) {
  3043. THREE.Light.call( this, hex );
  3044. this.position = new THREE.Vector3( 0, 0, 0 );
  3045. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  3046. this.distance = ( distance !== undefined ) ? distance : 0;
  3047. };
  3048. THREE.PointLight.prototype = new THREE.Light();
  3049. THREE.PointLight.prototype.constructor = THREE.PointLight;
  3050. /**
  3051. * @author alteredq / http://alteredqualia.com/
  3052. */
  3053. THREE.SpotLight = function ( hex, intensity, distance, angle, exponent ) {
  3054. THREE.Light.call( this, hex );
  3055. this.position = new THREE.Vector3( 0, 1, 0 );
  3056. this.target = new THREE.Object3D();
  3057. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  3058. this.distance = ( distance !== undefined ) ? distance : 0;
  3059. this.angle = ( angle !== undefined ) ? angle : Math.PI / 2;
  3060. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  3061. this.castShadow = false;
  3062. this.onlyShadow = false;
  3063. //
  3064. this.shadowCameraNear = 50;
  3065. this.shadowCameraFar = 5000;
  3066. this.shadowCameraFov = 50;
  3067. this.shadowCameraVisible = false;
  3068. this.shadowBias = 0;
  3069. this.shadowDarkness = 0.5;
  3070. this.shadowMapWidth = 512;
  3071. this.shadowMapHeight = 512;
  3072. //
  3073. this.shadowMap = null;
  3074. this.shadowMapSize = null;
  3075. this.shadowCamera = null;
  3076. this.shadowMatrix = null;
  3077. };
  3078. THREE.SpotLight.prototype = new THREE.Light();
  3079. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  3080. /**
  3081. * @author mr.doob / http://mrdoob.com/
  3082. * @author alteredq / http://alteredqualia.com/
  3083. */
  3084. THREE.Material = function ( parameters ) {
  3085. parameters = parameters || {};
  3086. this.id = THREE.MaterialCount ++;
  3087. this.name = '';
  3088. this.opacity = parameters.opacity !== undefined ? parameters.opacity : 1;
  3089. this.transparent = parameters.transparent !== undefined ? parameters.transparent : false;
  3090. this.blending = parameters.blending !== undefined ? parameters.blending : THREE.NormalBlending;
  3091. this.blendSrc = parameters.blendSrc !== undefined ? parameters.blendSrc : THREE.SrcAlphaFactor;
  3092. this.blendDst = parameters.blendDst !== undefined ? parameters.blendDst : THREE.OneMinusSrcAlphaFactor;
  3093. this.blendEquation = parameters.blendEquation !== undefined ? parameters.blendEquation : THREE.AddEquation;
  3094. this.depthTest = parameters.depthTest !== undefined ? parameters.depthTest : true;
  3095. this.depthWrite = parameters.depthWrite !== undefined ? parameters.depthWrite : true;
  3096. this.polygonOffset = parameters.polygonOffset !== undefined ? parameters.polygonOffset : false;
  3097. this.polygonOffsetFactor = parameters.polygonOffsetFactor !== undefined ? parameters.polygonOffsetFactor : 0;
  3098. this.polygonOffsetUnits = parameters.polygonOffsetUnits !== undefined ? parameters.polygonOffsetUnits : 0;
  3099. this.alphaTest = parameters.alphaTest !== undefined ? parameters.alphaTest : 0;
  3100. this.overdraw = parameters.overdraw !== undefined ? parameters.overdraw : false; // Boolean for fixing antialiasing gaps in CanvasRenderer
  3101. this.needsUpdate = true;
  3102. }
  3103. THREE.MaterialCount = 0;
  3104. // shading
  3105. THREE.NoShading = 0;
  3106. THREE.FlatShading = 1;
  3107. THREE.SmoothShading = 2;
  3108. // colors
  3109. THREE.NoColors = 0;
  3110. THREE.FaceColors = 1;
  3111. THREE.VertexColors = 2;
  3112. // blending modes
  3113. THREE.NoBlending = 0;
  3114. THREE.NormalBlending = 1;
  3115. THREE.AdditiveBlending = 2;
  3116. THREE.SubtractiveBlending = 3;
  3117. THREE.MultiplyBlending = 4;
  3118. THREE.AdditiveAlphaBlending = 5;
  3119. THREE.CustomBlending = 6;
  3120. // custom blending equations
  3121. // (numbers start from 100 not to clash with other
  3122. // mappings to OpenGL constants defined in Texture.js)
  3123. THREE.AddEquation = 100;
  3124. THREE.SubtractEquation = 101;
  3125. THREE.ReverseSubtractEquation = 102;
  3126. // custom blending destination factors
  3127. THREE.ZeroFactor = 200;
  3128. THREE.OneFactor = 201;
  3129. THREE.SrcColorFactor = 202;
  3130. THREE.OneMinusSrcColorFactor = 203;
  3131. THREE.SrcAlphaFactor = 204;
  3132. THREE.OneMinusSrcAlphaFactor = 205;
  3133. THREE.DstAlphaFactor = 206;
  3134. THREE.OneMinusDstAlphaFactor = 207;
  3135. // custom blending source factors
  3136. //THREE.ZeroFactor = 200;
  3137. //THREE.OneFactor = 201;
  3138. //THREE.SrcAlphaFactor = 204;
  3139. //THREE.OneMinusSrcAlphaFactor = 205;
  3140. //THREE.DstAlphaFactor = 206;
  3141. //THREE.OneMinusDstAlphaFactor = 207;
  3142. THREE.DstColorFactor = 208;
  3143. THREE.OneMinusDstColorFactor = 209;
  3144. THREE.SrcAlphaSaturateFactor = 210;
  3145. /**
  3146. * @author mr.doob / http://mrdoob.com/
  3147. * @author alteredq / http://alteredqualia.com/
  3148. *
  3149. * parameters = {
  3150. * color: <hex>,
  3151. * opacity: <float>,
  3152. *
  3153. * blending: THREE.NormalBlending,
  3154. * depthTest: <bool>,
  3155. *
  3156. * linewidth: <float>,
  3157. * linecap: "round",
  3158. * linejoin: "round",
  3159. *
  3160. * vertexColors: <bool>
  3161. *
  3162. * fog: <bool>
  3163. * }
  3164. */
  3165. THREE.LineBasicMaterial = function ( parameters ) {
  3166. THREE.Material.call( this, parameters );
  3167. parameters = parameters || {};
  3168. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3169. this.linewidth = parameters.linewidth !== undefined ? parameters.linewidth : 1;
  3170. this.linecap = parameters.linecap !== undefined ? parameters.linecap : 'round';
  3171. this.linejoin = parameters.linejoin !== undefined ? parameters.linejoin : 'round';
  3172. this.vertexColors = parameters.vertexColors ? parameters.vertexColors : false;
  3173. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3174. };
  3175. THREE.LineBasicMaterial.prototype = new THREE.Material();
  3176. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  3177. /**
  3178. * @author mr.doob / http://mrdoob.com/
  3179. * @author alteredq / http://alteredqualia.com/
  3180. *
  3181. * parameters = {
  3182. * color: <hex>,
  3183. * opacity: <float>,
  3184. * map: new THREE.Texture( <Image> ),
  3185. *
  3186. * lightMap: new THREE.Texture( <Image> ),
  3187. *
  3188. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  3189. * combine: THREE.Multiply,
  3190. * reflectivity: <float>,
  3191. * refractionRatio: <float>,
  3192. *
  3193. * shading: THREE.SmoothShading,
  3194. * blending: THREE.NormalBlending,
  3195. * depthTest: <bool>,
  3196. *
  3197. * wireframe: <boolean>,
  3198. * wireframeLinewidth: <float>,
  3199. *
  3200. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  3201. *
  3202. * skinning: <bool>,
  3203. * morphTargets: <bool>,
  3204. *
  3205. * fog: <bool>
  3206. * }
  3207. */
  3208. THREE.MeshBasicMaterial = function ( parameters ) {
  3209. THREE.Material.call( this, parameters );
  3210. parameters = parameters || {};
  3211. // color property represents emissive for MeshBasicMaterial
  3212. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3213. this.map = parameters.map !== undefined ? parameters.map : null;
  3214. this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null;
  3215. this.envMap = parameters.envMap !== undefined ? parameters.envMap : null;
  3216. this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation;
  3217. this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1;
  3218. this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98;
  3219. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3220. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
  3221. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3222. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3223. this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round';
  3224. this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round';
  3225. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors;
  3226. this.skinning = parameters.skinning !== undefined ? parameters.skinning : false;
  3227. this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false;
  3228. };
  3229. THREE.MeshBasicMaterial.prototype = new THREE.Material();
  3230. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  3231. /**
  3232. * @author mr.doob / http://mrdoob.com/
  3233. * @author alteredq / http://alteredqualia.com/
  3234. *
  3235. * parameters = {
  3236. * color: <hex>,
  3237. * ambient: <hex>,
  3238. * emissive: <hex>,
  3239. * opacity: <float>,
  3240. *
  3241. * map: new THREE.Texture( <Image> ),
  3242. *
  3243. * lightMap: new THREE.Texture( <Image> ),
  3244. *
  3245. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  3246. * combine: THREE.Multiply,
  3247. * reflectivity: <float>,
  3248. * refractionRatio: <float>,
  3249. *
  3250. * shading: THREE.SmoothShading,
  3251. * blending: THREE.NormalBlending,
  3252. * depthTest: <bool>,
  3253. *
  3254. * wireframe: <boolean>,
  3255. * wireframeLinewidth: <float>,
  3256. *
  3257. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  3258. *
  3259. * skinning: <bool>,
  3260. * morphTargets: <bool>,
  3261. * morphNormals: <bool>,
  3262. *
  3263. * fog: <bool>
  3264. * }
  3265. */
  3266. THREE.MeshLambertMaterial = function ( parameters ) {
  3267. THREE.Material.call( this, parameters );
  3268. parameters = parameters || {};
  3269. // color property represents diffuse for MeshLambertMaterial
  3270. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3271. this.ambient = parameters.ambient !== undefined ? new THREE.Color( parameters.ambient ) : new THREE.Color( 0xffffff );
  3272. this.emissive = parameters.emissive !== undefined ? new THREE.Color( parameters.emissive ) : new THREE.Color( 0x000000 );
  3273. this.wrapAround = parameters.wrapAround !== undefined ? parameters.wrapAround: false;
  3274. this.wrapRGB = new THREE.Vector3( 1, 1, 1 );
  3275. this.map = parameters.map !== undefined ? parameters.map : null;
  3276. this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null;
  3277. this.envMap = parameters.envMap !== undefined ? parameters.envMap : null;
  3278. this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation;
  3279. this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1;
  3280. this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98;
  3281. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3282. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
  3283. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3284. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3285. this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round';
  3286. this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round';
  3287. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors;
  3288. this.skinning = parameters.skinning !== undefined ? parameters.skinning : false;
  3289. this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false;
  3290. this.morphNormals = parameters.morphNormals !== undefined ? parameters.morphNormals : false;
  3291. };
  3292. THREE.MeshLambertMaterial.prototype = new THREE.Material();
  3293. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  3294. /**
  3295. * @author mr.doob / http://mrdoob.com/
  3296. * @author alteredq / http://alteredqualia.com/
  3297. *
  3298. * parameters = {
  3299. * color: <hex>,
  3300. * ambient: <hex>,
  3301. * emissive: <hex>,
  3302. * specular: <hex>,
  3303. * shininess: <float>,
  3304. * opacity: <float>,
  3305. *
  3306. * map: new THREE.Texture( <Image> ),
  3307. *
  3308. * lightMap: new THREE.Texture( <Image> ),
  3309. *
  3310. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  3311. * combine: THREE.Multiply,
  3312. * reflectivity: <float>,
  3313. * refractionRatio: <float>,
  3314. *
  3315. * shading: THREE.SmoothShading,
  3316. * blending: THREE.NormalBlending,
  3317. * depthTest: <bool>,
  3318. *
  3319. * wireframe: <boolean>,
  3320. * wireframeLinewidth: <float>,
  3321. *
  3322. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  3323. *
  3324. * skinning: <bool>,
  3325. * morphTargets: <bool>,
  3326. * morphNormals: <bool>,
  3327. *
  3328. * fog: <bool>
  3329. * }
  3330. */
  3331. THREE.MeshPhongMaterial = function ( parameters ) {
  3332. THREE.Material.call( this, parameters );
  3333. parameters = parameters || {};
  3334. // color property represents diffuse for MeshPhongMaterial
  3335. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3336. this.ambient = parameters.ambient !== undefined ? new THREE.Color( parameters.ambient ) : new THREE.Color( 0xffffff );
  3337. this.emissive = parameters.emissive !== undefined ? new THREE.Color( parameters.emissive ) : new THREE.Color( 0x000000 );
  3338. this.specular = parameters.specular !== undefined ? new THREE.Color( parameters.specular ) : new THREE.Color( 0x111111 );
  3339. this.shininess = parameters.shininess !== undefined ? parameters.shininess : 30;
  3340. this.metal = parameters.metal !== undefined ? parameters.metal : false;
  3341. this.perPixel = parameters.perPixel !== undefined ? parameters.perPixel : false;
  3342. this.wrapAround = parameters.wrapAround !== undefined ? parameters.wrapAround: false;
  3343. this.wrapRGB = new THREE.Vector3( 1, 1, 1 );
  3344. this.map = parameters.map !== undefined ? parameters.map : null;
  3345. this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null;
  3346. this.envMap = parameters.envMap !== undefined ? parameters.envMap : null;
  3347. this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation;
  3348. this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1;
  3349. this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98;
  3350. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3351. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
  3352. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3353. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3354. this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round';
  3355. this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round';
  3356. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors;
  3357. this.skinning = parameters.skinning !== undefined ? parameters.skinning : false;
  3358. this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false;
  3359. this.morphNormals = parameters.morphNormals !== undefined ? parameters.morphNormals : false;
  3360. };
  3361. THREE.MeshPhongMaterial.prototype = new THREE.Material();
  3362. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  3363. /**
  3364. * @author mr.doob / http://mrdoob.com/
  3365. * @author alteredq / http://alteredqualia.com/
  3366. *
  3367. * parameters = {
  3368. * opacity: <float>,
  3369. * blending: THREE.NormalBlending,
  3370. * depthTest: <bool>,
  3371. * wireframe: <boolean>,
  3372. * wireframeLinewidth: <float>
  3373. * }
  3374. */
  3375. THREE.MeshDepthMaterial = function ( parameters ) {
  3376. THREE.Material.call( this, parameters );
  3377. parameters = parameters || {};
  3378. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading; // doesn't really apply here, normals are not used
  3379. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3380. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3381. };
  3382. THREE.MeshDepthMaterial.prototype = new THREE.Material();
  3383. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  3384. /**
  3385. * @author mr.doob / http://mrdoob.com/
  3386. *
  3387. * parameters = {
  3388. * opacity: <float>,
  3389. * shading: THREE.FlatShading,
  3390. * blending: THREE.NormalBlending,
  3391. * depthTest: <bool>,
  3392. * wireframe: <boolean>,
  3393. * wireframeLinewidth: <float>
  3394. * }
  3395. */
  3396. THREE.MeshNormalMaterial = function ( parameters ) {
  3397. THREE.Material.call( this, parameters );
  3398. parameters = parameters || {};
  3399. this.shading = parameters.shading ? parameters.shading : THREE.FlatShading;
  3400. this.wireframe = parameters.wireframe ? parameters.wireframe : false;
  3401. this.wireframeLinewidth = parameters.wireframeLinewidth ? parameters.wireframeLinewidth : 1;
  3402. };
  3403. THREE.MeshNormalMaterial.prototype = new THREE.Material();
  3404. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  3405. /**
  3406. * @author mr.doob / http://mrdoob.com/
  3407. */
  3408. THREE.MeshFaceMaterial = function () {
  3409. };
  3410. /**
  3411. * @author mr.doob / http://mrdoob.com/
  3412. * @author alteredq / http://alteredqualia.com/
  3413. *
  3414. * parameters = {
  3415. * color: <hex>,
  3416. * opacity: <float>,
  3417. * map: new THREE.Texture( <Image> ),
  3418. *
  3419. * size: <float>,
  3420. *
  3421. * blending: THREE.NormalBlending,
  3422. * depthTest: <bool>,
  3423. *
  3424. * vertexColors: <bool>,
  3425. *
  3426. * fog: <bool>
  3427. * }
  3428. */
  3429. THREE.ParticleBasicMaterial = function ( parameters ) {
  3430. THREE.Material.call( this, parameters );
  3431. parameters = parameters || {};
  3432. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3433. this.map = parameters.map !== undefined ? parameters.map : null;
  3434. this.size = parameters.size !== undefined ? parameters.size : 1;
  3435. this.sizeAttenuation = parameters.sizeAttenuation !== undefined ? parameters.sizeAttenuation : true;
  3436. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : false;
  3437. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3438. };
  3439. THREE.ParticleBasicMaterial.prototype = new THREE.Material();
  3440. THREE.ParticleBasicMaterial.prototype.constructor = THREE.ParticleBasicMaterial;
  3441. /**
  3442. * @author alteredq / http://alteredqualia.com/
  3443. *
  3444. * parameters = {
  3445. * fragmentShader: <string>,
  3446. * vertexShader: <string>,
  3447. *
  3448. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  3449. *
  3450. * shading: THREE.SmoothShading,
  3451. * blending: THREE.NormalBlending,
  3452. * depthTest: <bool>,
  3453. *
  3454. * wireframe: <boolean>,
  3455. * wireframeLinewidth: <float>,
  3456. *
  3457. * lights: <bool>,
  3458. *
  3459. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  3460. *
  3461. * skinning: <bool>,
  3462. * morphTargets: <bool>,
  3463. * morphNormals: <bool>,
  3464. *
  3465. * fog: <bool>
  3466. * }
  3467. */
  3468. THREE.ShaderMaterial = function ( parameters ) {
  3469. THREE.Material.call( this, parameters );
  3470. parameters = parameters || {};
  3471. this.fragmentShader = parameters.fragmentShader !== undefined ? parameters.fragmentShader : "void main() {}";
  3472. this.vertexShader = parameters.vertexShader !== undefined ? parameters.vertexShader : "void main() {}";
  3473. this.uniforms = parameters.uniforms !== undefined ? parameters.uniforms : {};
  3474. this.attributes = parameters.attributes;
  3475. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
  3476. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3477. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3478. this.fog = parameters.fog !== undefined ? parameters.fog : false; // set to use scene fog
  3479. this.lights = parameters.lights !== undefined ? parameters.lights : false; // set to use scene lights
  3480. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors; // set to use "color" attribute stream
  3481. this.skinning = parameters.skinning !== undefined ? parameters.skinning : false; // set to use skinning attribute streams
  3482. this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false; // set to use morph targets
  3483. this.morphNormals = parameters.morphNormals !== undefined ? parameters.morphNormals : false; // set to use morph normals
  3484. };
  3485. THREE.ShaderMaterial.prototype = new THREE.Material();
  3486. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  3487. /**
  3488. * @author mr.doob / http://mrdoob.com/
  3489. * @author alteredq / http://alteredqualia.com/
  3490. * @author szimek / https://github.com/szimek/
  3491. */
  3492. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type ) {
  3493. this.id = THREE.TextureCount ++;
  3494. this.image = image;
  3495. this.mapping = mapping !== undefined ? mapping : new THREE.UVMapping();
  3496. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  3497. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  3498. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  3499. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  3500. this.format = format !== undefined ? format : THREE.RGBAFormat;
  3501. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  3502. this.offset = new THREE.Vector2( 0, 0 );
  3503. this.repeat = new THREE.Vector2( 1, 1 );
  3504. this.generateMipmaps = true;
  3505. this.premultiplyAlpha = false;
  3506. this.needsUpdate = false;
  3507. this.onUpdate = null;
  3508. };
  3509. THREE.Texture.prototype = {
  3510. constructor: THREE.Texture,
  3511. clone: function () {
  3512. var clonedTexture = new THREE.Texture( this.image, this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter, this.format, this.type );
  3513. clonedTexture.offset.copy( this.offset );
  3514. clonedTexture.repeat.copy( this.repeat );
  3515. return clonedTexture;
  3516. }
  3517. };
  3518. THREE.TextureCount = 0;
  3519. THREE.MultiplyOperation = 0;
  3520. THREE.MixOperation = 1;
  3521. // Mapping modes
  3522. THREE.UVMapping = function () {};
  3523. THREE.CubeReflectionMapping = function () {};
  3524. THREE.CubeRefractionMapping = function () {};
  3525. THREE.SphericalReflectionMapping = function () {};
  3526. THREE.SphericalRefractionMapping = function () {};
  3527. // Wrapping modes
  3528. THREE.RepeatWrapping = 0;
  3529. THREE.ClampToEdgeWrapping = 1;
  3530. THREE.MirroredRepeatWrapping = 2;
  3531. // Filters
  3532. THREE.NearestFilter = 3;
  3533. THREE.NearestMipMapNearestFilter = 4;
  3534. THREE.NearestMipMapLinearFilter = 5;
  3535. THREE.LinearFilter = 6;
  3536. THREE.LinearMipMapNearestFilter = 7;
  3537. THREE.LinearMipMapLinearFilter = 8;
  3538. // Types
  3539. THREE.ByteType = 9;
  3540. THREE.UnsignedByteType = 10;
  3541. THREE.ShortType = 11;
  3542. THREE.UnsignedShortType = 12;
  3543. THREE.IntType = 13;
  3544. THREE.UnsignedIntType = 14;
  3545. THREE.FloatType = 15;
  3546. // Formats
  3547. THREE.AlphaFormat = 16;
  3548. THREE.RGBFormat = 17;
  3549. THREE.RGBAFormat = 18;
  3550. THREE.LuminanceFormat = 19;
  3551. THREE.LuminanceAlphaFormat = 20;
  3552. /**
  3553. * @author alteredq / http://alteredqualia.com/
  3554. */
  3555. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter ) {
  3556. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type );
  3557. this.image = { data: data, width: width, height: height };
  3558. };
  3559. THREE.DataTexture.prototype = new THREE.Texture();
  3560. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  3561. THREE.DataTexture.prototype.clone = function () {
  3562. 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 );
  3563. clonedTexture.offset.copy( this.offset );
  3564. clonedTexture.repeat.copy( this.repeat );
  3565. return clonedTexture;
  3566. };
  3567. /**
  3568. * @author mr.doob / http://mrdoob.com/
  3569. */
  3570. THREE.Particle = function ( material ) {
  3571. THREE.Object3D.call( this );
  3572. this.material = material;
  3573. };
  3574. THREE.Particle.prototype = new THREE.Object3D();
  3575. THREE.Particle.prototype.constructor = THREE.Particle;
  3576. /**
  3577. * @author alteredq / http://alteredqualia.com/
  3578. */
  3579. THREE.ParticleSystem = function ( geometry, material ) {
  3580. THREE.Object3D.call( this );
  3581. this.geometry = geometry;
  3582. this.material = ( material !== undefined ) ? material : new THREE.ParticleBasicMaterial( { color: Math.random() * 0xffffff } );
  3583. this.sortParticles = false;
  3584. if ( this.geometry ) {
  3585. // calc bound radius
  3586. if( !this.geometry.boundingSphere ) {
  3587. this.geometry.computeBoundingSphere();
  3588. }
  3589. this.boundRadius = geometry.boundingSphere.radius;
  3590. }
  3591. this.frustumCulled = false;
  3592. };
  3593. THREE.ParticleSystem.prototype = new THREE.Object3D();
  3594. THREE.ParticleSystem.prototype.constructor = THREE.ParticleSystem;
  3595. /**
  3596. * @author mr.doob / http://mrdoob.com/
  3597. */
  3598. THREE.Line = function ( geometry, material, type ) {
  3599. THREE.Object3D.call( this );
  3600. this.geometry = geometry;
  3601. this.material = ( material !== undefined ) ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  3602. this.type = ( type !== undefined ) ? type : THREE.LineStrip;
  3603. if ( this.geometry ) {
  3604. if ( ! this.geometry.boundingSphere ) {
  3605. this.geometry.computeBoundingSphere();
  3606. }
  3607. }
  3608. };
  3609. THREE.LineStrip = 0;
  3610. THREE.LinePieces = 1;
  3611. THREE.Line.prototype = new THREE.Object3D();
  3612. THREE.Line.prototype.constructor = THREE.Line;
  3613. /**
  3614. * @author mr.doob / http://mrdoob.com/
  3615. * @author alteredq / http://alteredqualia.com/
  3616. * @author mikael emtinger / http://gomo.se/
  3617. */
  3618. THREE.Mesh = function ( geometry, material ) {
  3619. THREE.Object3D.call( this );
  3620. this.geometry = geometry;
  3621. this.material = ( material !== undefined ) ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, wireframe: true } );
  3622. if ( this.geometry ) {
  3623. // calc bound radius
  3624. if( ! this.geometry.boundingSphere ) {
  3625. this.geometry.computeBoundingSphere();
  3626. }
  3627. this.boundRadius = geometry.boundingSphere.radius;
  3628. // setup morph targets
  3629. if( this.geometry.morphTargets.length ) {
  3630. this.morphTargetBase = -1;
  3631. this.morphTargetForcedOrder = [];
  3632. this.morphTargetInfluences = [];
  3633. this.morphTargetDictionary = {};
  3634. for( var m = 0; m < this.geometry.morphTargets.length; m ++ ) {
  3635. this.morphTargetInfluences.push( 0 );
  3636. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  3637. }
  3638. }
  3639. }
  3640. }
  3641. THREE.Mesh.prototype = new THREE.Object3D();
  3642. THREE.Mesh.prototype.constructor = THREE.Mesh;
  3643. THREE.Mesh.prototype.supr = THREE.Object3D.prototype;
  3644. /*
  3645. * Get Morph Target Index by Name
  3646. */
  3647. THREE.Mesh.prototype.getMorphTargetIndexByName = function( name ) {
  3648. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  3649. return this.morphTargetDictionary[ name ];
  3650. }
  3651. console.log( "THREE.Mesh.getMorphTargetIndexByName: morph target " + name + " does not exist. Returning 0." );
  3652. return 0;
  3653. }
  3654. /**
  3655. * @author mikael emtinger / http://gomo.se/
  3656. * @author alteredq / http://alteredqualia.com/
  3657. */
  3658. THREE.Bone = function( belongsToSkin ) {
  3659. THREE.Object3D.call( this );
  3660. this.skin = belongsToSkin;
  3661. this.skinMatrix = new THREE.Matrix4();
  3662. };
  3663. THREE.Bone.prototype = new THREE.Object3D();
  3664. THREE.Bone.prototype.constructor = THREE.Bone;
  3665. THREE.Bone.prototype.supr = THREE.Object3D.prototype;
  3666. THREE.Bone.prototype.update = function( parentSkinMatrix, forceUpdate ) {
  3667. // update local
  3668. if ( this.matrixAutoUpdate ) {
  3669. forceUpdate |= this.updateMatrix();
  3670. }
  3671. // update skin matrix
  3672. if ( forceUpdate || this.matrixWorldNeedsUpdate ) {
  3673. if( parentSkinMatrix ) {
  3674. this.skinMatrix.multiply( parentSkinMatrix, this.matrix );
  3675. } else {
  3676. this.skinMatrix.copy( this.matrix );
  3677. }
  3678. this.matrixWorldNeedsUpdate = false;
  3679. forceUpdate = true;
  3680. }
  3681. // update children
  3682. var child, i, l = this.children.length;
  3683. for ( i = 0; i < l; i ++ ) {
  3684. this.children[ i ].update( this.skinMatrix, forceUpdate );
  3685. }
  3686. };
  3687. /**
  3688. * @author mikael emtinger / http://gomo.se/
  3689. * @author alteredq / http://alteredqualia.com/
  3690. */
  3691. THREE.SkinnedMesh = function ( geometry, material ) {
  3692. THREE.Mesh.call( this, geometry, material );
  3693. // init bones
  3694. this.identityMatrix = new THREE.Matrix4();
  3695. this.bones = [];
  3696. this.boneMatrices = [];
  3697. var b, bone, gbone, p, q, s;
  3698. if ( this.geometry.bones !== undefined ) {
  3699. for ( b = 0; b < this.geometry.bones.length; b ++ ) {
  3700. gbone = this.geometry.bones[ b ];
  3701. p = gbone.pos;
  3702. q = gbone.rotq;
  3703. s = gbone.scl;
  3704. bone = this.addBone();
  3705. bone.name = gbone.name;
  3706. bone.position.set( p[0], p[1], p[2] );
  3707. bone.quaternion.set( q[0], q[1], q[2], q[3] );
  3708. bone.useQuaternion = true;
  3709. if ( s !== undefined ) {
  3710. bone.scale.set( s[0], s[1], s[2] );
  3711. } else {
  3712. bone.scale.set( 1, 1, 1 );
  3713. }
  3714. }
  3715. for ( b = 0; b < this.bones.length; b ++ ) {
  3716. gbone = this.geometry.bones[ b ];
  3717. bone = this.bones[ b ];
  3718. if ( gbone.parent === -1 ) {
  3719. this.add( bone );
  3720. } else {
  3721. this.bones[ gbone.parent ].add( bone );
  3722. }
  3723. }
  3724. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  3725. this.pose();
  3726. }
  3727. };
  3728. THREE.SkinnedMesh.prototype = new THREE.Mesh();
  3729. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  3730. THREE.SkinnedMesh.prototype.addBone = function( bone ) {
  3731. if ( bone === undefined ) {
  3732. bone = new THREE.Bone( this );
  3733. }
  3734. this.bones.push( bone );
  3735. return bone;
  3736. };
  3737. THREE.SkinnedMesh.prototype.updateMatrixWorld = function ( force ) {
  3738. this.matrixAutoUpdate && this.updateMatrix();
  3739. // update matrixWorld
  3740. if ( this.matrixWorldNeedsUpdate || force ) {
  3741. if ( this.parent ) {
  3742. this.matrixWorld.multiply( this.parent.matrixWorld, this.matrix );
  3743. } else {
  3744. this.matrixWorld.copy( this.matrix );
  3745. }
  3746. this.matrixWorldNeedsUpdate = false;
  3747. force = true;
  3748. }
  3749. // update children
  3750. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  3751. var child = this.children[ i ];
  3752. if ( child instanceof THREE.Bone ) {
  3753. child.update( this.identityMatrix, false );
  3754. } else {
  3755. child.updateMatrixWorld( true );
  3756. }
  3757. }
  3758. // flatten bone matrices to array
  3759. var b, bl = this.bones.length,
  3760. ba = this.bones,
  3761. bm = this.boneMatrices;
  3762. for ( b = 0; b < bl; b ++ ) {
  3763. ba[ b ].skinMatrix.flattenToArrayOffset( bm, b * 16 );
  3764. }
  3765. };
  3766. /*
  3767. * Pose
  3768. */
  3769. THREE.SkinnedMesh.prototype.pose = function() {
  3770. this.updateMatrixWorld( true );
  3771. var bim, bone, boneInverses = [];
  3772. for ( var b = 0; b < this.bones.length; b ++ ) {
  3773. bone = this.bones[ b ];
  3774. var inverseMatrix = new THREE.Matrix4();
  3775. inverseMatrix.getInverse( bone.skinMatrix );
  3776. boneInverses.push( inverseMatrix );
  3777. bone.skinMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  3778. }
  3779. // project vertices to local
  3780. if ( this.geometry.skinVerticesA === undefined ) {
  3781. this.geometry.skinVerticesA = [];
  3782. this.geometry.skinVerticesB = [];
  3783. var orgVertex, vertex;
  3784. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  3785. orgVertex = this.geometry.vertices[ i ];
  3786. var indexA = this.geometry.skinIndices[ i ].x;
  3787. var indexB = this.geometry.skinIndices[ i ].y;
  3788. vertex = new THREE.Vector3( orgVertex.x, orgVertex.y, orgVertex.z );
  3789. this.geometry.skinVerticesA.push( boneInverses[ indexA ].multiplyVector3( vertex ) );
  3790. vertex = new THREE.Vector3( orgVertex.x, orgVertex.y, orgVertex.z );
  3791. this.geometry.skinVerticesB.push( boneInverses[ indexB ].multiplyVector3( vertex ) );
  3792. // todo: add more influences
  3793. // normalize weights
  3794. if ( this.geometry.skinWeights[ i ].x + this.geometry.skinWeights[ i ].y !== 1 ) {
  3795. var len = ( 1.0 - ( this.geometry.skinWeights[ i ].x + this.geometry.skinWeights[ i ].y ) ) * 0.5;
  3796. this.geometry.skinWeights[ i ].x += len;
  3797. this.geometry.skinWeights[ i ].y += len;
  3798. }
  3799. }
  3800. }
  3801. };
  3802. /**
  3803. * @author alteredq / http://alteredqualia.com/
  3804. */
  3805. THREE.Ribbon = function ( geometry, material ) {
  3806. THREE.Object3D.call( this );
  3807. this.geometry = geometry;
  3808. this.material = material;
  3809. };
  3810. THREE.Ribbon.prototype = new THREE.Object3D();
  3811. THREE.Ribbon.prototype.constructor = THREE.Ribbon;
  3812. /**
  3813. * @author mikael emtinger / http://gomo.se/
  3814. * @author alteredq / http://alteredqualia.com/
  3815. * @author mr.doob / http://mrdoob.com/
  3816. */
  3817. THREE.LOD = function () {
  3818. THREE.Object3D.call( this );
  3819. this.LODs = [];
  3820. };
  3821. THREE.LOD.prototype = new THREE.Object3D();
  3822. THREE.LOD.prototype.constructor = THREE.LOD;
  3823. THREE.LOD.prototype.supr = THREE.Object3D.prototype;
  3824. THREE.LOD.prototype.addLevel = function ( object3D, visibleAtDistance ) {
  3825. if ( visibleAtDistance === undefined ) {
  3826. visibleAtDistance = 0;
  3827. }
  3828. visibleAtDistance = Math.abs( visibleAtDistance );
  3829. for ( var l = 0; l < this.LODs.length; l ++ ) {
  3830. if ( visibleAtDistance < this.LODs[ l ].visibleAtDistance ) {
  3831. break;
  3832. }
  3833. }
  3834. this.LODs.splice( l, 0, { visibleAtDistance: visibleAtDistance, object3D: object3D } );
  3835. this.add( object3D );
  3836. };
  3837. THREE.LOD.prototype.update = function ( camera ) {
  3838. if ( this.LODs.length > 1 ) {
  3839. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  3840. var inverse = camera.matrixWorldInverse;
  3841. var distance = -( inverse.elements[2] * this.matrixWorld.elements[12] + inverse.elements[6] * this.matrixWorld.elements[13] + inverse.elements[10] * this.matrixWorld.elements[14] + inverse.elements[14] );
  3842. this.LODs[ 0 ].object3D.visible = true;
  3843. for ( var l = 1; l < this.LODs.length; l ++ ) {
  3844. if( distance >= this.LODs[ l ].visibleAtDistance ) {
  3845. this.LODs[ l - 1 ].object3D.visible = false;
  3846. this.LODs[ l ].object3D.visible = true;
  3847. } else {
  3848. break;
  3849. }
  3850. }
  3851. for( ; l < this.LODs.length; l ++ ) {
  3852. this.LODs[ l ].object3D.visible = false;
  3853. }
  3854. }
  3855. };
  3856. /**
  3857. * @author mikael emtinger / http://gomo.se/
  3858. */
  3859. THREE.Sprite = function ( parameters ) {
  3860. THREE.Object3D.call( this );
  3861. this.color = ( parameters.color !== undefined ) ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3862. this.map = ( parameters.map !== undefined ) ? parameters.map : new THREE.Texture();
  3863. this.blending = ( parameters.blending !== undefined ) ? parameters.blending : THREE.NormalBlending;
  3864. this.blendSrc = parameters.blendSrc !== undefined ? parameters.blendSrc : THREE.SrcAlphaFactor;
  3865. this.blendDst = parameters.blendDst !== undefined ? parameters.blendDst : THREE.OneMinusSrcAlphaFactor;
  3866. this.blendEquation = parameters.blendEquation !== undefined ? parameters.blendEquation : THREE.AddEquation;
  3867. this.useScreenCoordinates = ( parameters.useScreenCoordinates !== undefined ) ? parameters.useScreenCoordinates : true;
  3868. this.mergeWith3D = ( parameters.mergeWith3D !== undefined ) ? parameters.mergeWith3D : !this.useScreenCoordinates;
  3869. this.affectedByDistance = ( parameters.affectedByDistance !== undefined ) ? parameters.affectedByDistance : !this.useScreenCoordinates;
  3870. this.scaleByViewport = ( parameters.scaleByViewport !== undefined ) ? parameters.scaleByViewport : !this.affectedByDistance;
  3871. this.alignment = ( parameters.alignment instanceof THREE.Vector2 ) ? parameters.alignment : THREE.SpriteAlignment.center;
  3872. this.rotation3d = this.rotation;
  3873. this.rotation = 0;
  3874. this.opacity = 1;
  3875. this.uvOffset = new THREE.Vector2( 0, 0 );
  3876. this.uvScale = new THREE.Vector2( 1, 1 );
  3877. };
  3878. THREE.Sprite.prototype = new THREE.Object3D();
  3879. THREE.Sprite.prototype.constructor = THREE.Sprite;
  3880. /*
  3881. * Custom update matrix
  3882. */
  3883. THREE.Sprite.prototype.updateMatrix = function () {
  3884. this.matrix.setPosition( this.position );
  3885. this.rotation3d.set( 0, 0, this.rotation );
  3886. this.matrix.setRotationFromEuler( this.rotation3d );
  3887. if ( this.scale.x !== 1 || this.scale.y !== 1 ) {
  3888. this.matrix.scale( this.scale );
  3889. this.boundRadiusScale = Math.max( this.scale.x, this.scale.y );
  3890. }
  3891. this.matrixWorldNeedsUpdate = true;
  3892. };
  3893. /*
  3894. * Alignment
  3895. */
  3896. THREE.SpriteAlignment = {};
  3897. THREE.SpriteAlignment.topLeft = new THREE.Vector2( 1, -1 );
  3898. THREE.SpriteAlignment.topCenter = new THREE.Vector2( 0, -1 );
  3899. THREE.SpriteAlignment.topRight = new THREE.Vector2( -1, -1 );
  3900. THREE.SpriteAlignment.centerLeft = new THREE.Vector2( 1, 0 );
  3901. THREE.SpriteAlignment.center = new THREE.Vector2( 0, 0 );
  3902. THREE.SpriteAlignment.centerRight = new THREE.Vector2( -1, 0 );
  3903. THREE.SpriteAlignment.bottomLeft = new THREE.Vector2( 1, 1 );
  3904. THREE.SpriteAlignment.bottomCenter = new THREE.Vector2( 0, 1 );
  3905. THREE.SpriteAlignment.bottomRight = new THREE.Vector2( -1, 1 );
  3906. /**
  3907. * @author mr.doob / http://mrdoob.com/
  3908. */
  3909. THREE.Scene = function () {
  3910. THREE.Object3D.call( this );
  3911. this.fog = null;
  3912. this.overrideMaterial = null;
  3913. this.matrixAutoUpdate = false;
  3914. this.__objects = [];
  3915. this.__lights = [];
  3916. this.__objectsAdded = [];
  3917. this.__objectsRemoved = [];
  3918. };
  3919. THREE.Scene.prototype = new THREE.Object3D();
  3920. THREE.Scene.prototype.constructor = THREE.Scene;
  3921. THREE.Scene.prototype.__addObject = function ( object ) {
  3922. if ( object instanceof THREE.Light ) {
  3923. if ( this.__lights.indexOf( object ) === - 1 ) {
  3924. this.__lights.push( object );
  3925. }
  3926. } else if ( !( object instanceof THREE.Camera || object instanceof THREE.Bone ) ) {
  3927. if ( this.__objects.indexOf( object ) === - 1 ) {
  3928. this.__objects.push( object );
  3929. this.__objectsAdded.push( object );
  3930. // check if previously removed
  3931. var i = this.__objectsRemoved.indexOf( object );
  3932. if ( i !== -1 ) {
  3933. this.__objectsRemoved.splice( i, 1 );
  3934. }
  3935. }
  3936. }
  3937. for ( var c = 0; c < object.children.length; c ++ ) {
  3938. this.__addObject( object.children[ c ] );
  3939. }
  3940. };
  3941. THREE.Scene.prototype.__removeObject = function ( object ) {
  3942. if ( object instanceof THREE.Light ) {
  3943. var i = this.__lights.indexOf( object );
  3944. if ( i !== -1 ) {
  3945. this.__lights.splice( i, 1 );
  3946. }
  3947. } else if ( !( object instanceof THREE.Camera ) ) {
  3948. var i = this.__objects.indexOf( object );
  3949. if( i !== -1 ) {
  3950. this.__objects.splice( i, 1 );
  3951. this.__objectsRemoved.push( object );
  3952. // check if previously added
  3953. var ai = this.__objectsAdded.indexOf( object );
  3954. if ( ai !== -1 ) {
  3955. this.__objectsAdded.splice( ai, 1 );
  3956. }
  3957. }
  3958. }
  3959. for ( var c = 0; c < object.children.length; c ++ ) {
  3960. this.__removeObject( object.children[ c ] );
  3961. }
  3962. };
  3963. /**
  3964. * @author mr.doob / http://mrdoob.com/
  3965. * @author alteredq / http://alteredqualia.com/
  3966. */
  3967. THREE.Fog = function ( hex, near, far ) {
  3968. this.color = new THREE.Color( hex );
  3969. this.near = ( near !== undefined ) ? near : 1;
  3970. this.far = ( far !== undefined ) ? far : 1000;
  3971. };
  3972. /**
  3973. * @author mr.doob / http://mrdoob.com/
  3974. * @author alteredq / http://alteredqualia.com/
  3975. */
  3976. THREE.FogExp2 = function ( hex, density ) {
  3977. this.color = new THREE.Color( hex );
  3978. this.density = ( density !== undefined ) ? density : 0.00025;
  3979. };
  3980. /**
  3981. * @author alteredq / http://alteredqualia.com/
  3982. * @author mrdoob / http://mrdoob.com/
  3983. * @author mikael emtinger / http://gomo.se/
  3984. */
  3985. THREE.ShaderChunk = {
  3986. // FOG
  3987. fog_pars_fragment: [
  3988. "#ifdef USE_FOG",
  3989. "uniform vec3 fogColor;",
  3990. "#ifdef FOG_EXP2",
  3991. "uniform float fogDensity;",
  3992. "#else",
  3993. "uniform float fogNear;",
  3994. "uniform float fogFar;",
  3995. "#endif",
  3996. "#endif"
  3997. ].join("\n"),
  3998. fog_fragment: [
  3999. "#ifdef USE_FOG",
  4000. "float depth = gl_FragCoord.z / gl_FragCoord.w;",
  4001. "#ifdef FOG_EXP2",
  4002. "const float LOG2 = 1.442695;",
  4003. "float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );",
  4004. "fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );",
  4005. "#else",
  4006. "float fogFactor = smoothstep( fogNear, fogFar, depth );",
  4007. "#endif",
  4008. "gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );",
  4009. "#endif"
  4010. ].join("\n"),
  4011. // ENVIRONMENT MAP
  4012. envmap_pars_fragment: [
  4013. "#ifdef USE_ENVMAP",
  4014. "varying vec3 vReflect;",
  4015. "uniform float reflectivity;",
  4016. "uniform samplerCube envMap;",
  4017. "uniform float flipEnvMap;",
  4018. "uniform int combine;",
  4019. "#endif"
  4020. ].join("\n"),
  4021. envmap_fragment: [
  4022. "#ifdef USE_ENVMAP",
  4023. "#ifdef DOUBLE_SIDED",
  4024. "float flipNormal = ( -1.0 + 2.0 * float( gl_FrontFacing ) );",
  4025. "vec4 cubeColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * vReflect.x, vReflect.yz ) );",
  4026. "#else",
  4027. "vec4 cubeColor = textureCube( envMap, vec3( flipEnvMap * vReflect.x, vReflect.yz ) );",
  4028. "#endif",
  4029. "#ifdef GAMMA_INPUT",
  4030. "cubeColor.xyz *= cubeColor.xyz;",
  4031. "#endif",
  4032. "if ( combine == 1 ) {",
  4033. "gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity );",
  4034. "} else {",
  4035. "gl_FragColor.xyz = gl_FragColor.xyz * cubeColor.xyz;",
  4036. "}",
  4037. "#endif"
  4038. ].join("\n"),
  4039. envmap_pars_vertex: [
  4040. "#ifdef USE_ENVMAP",
  4041. "varying vec3 vReflect;",
  4042. "uniform float refractionRatio;",
  4043. "uniform bool useRefract;",
  4044. "#endif"
  4045. ].join("\n"),
  4046. envmap_vertex : [
  4047. "#ifdef USE_ENVMAP",
  4048. "vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
  4049. "vec3 nWorld = mat3( objectMatrix[ 0 ].xyz, objectMatrix[ 1 ].xyz, objectMatrix[ 2 ].xyz ) * normal;",
  4050. "if ( useRefract ) {",
  4051. "vReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refractionRatio );",
  4052. "} else {",
  4053. "vReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );",
  4054. "}",
  4055. "#endif"
  4056. ].join("\n"),
  4057. // COLOR MAP (particles)
  4058. map_particle_pars_fragment: [
  4059. "#ifdef USE_MAP",
  4060. "uniform sampler2D map;",
  4061. "#endif"
  4062. ].join("\n"),
  4063. map_particle_fragment: [
  4064. "#ifdef USE_MAP",
  4065. "gl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );",
  4066. "#endif"
  4067. ].join("\n"),
  4068. // COLOR MAP (triangles)
  4069. map_pars_vertex: [
  4070. "#ifdef USE_MAP",
  4071. "varying vec2 vUv;",
  4072. "uniform vec4 offsetRepeat;",
  4073. "#endif"
  4074. ].join("\n"),
  4075. map_pars_fragment: [
  4076. "#ifdef USE_MAP",
  4077. "varying vec2 vUv;",
  4078. "uniform sampler2D map;",
  4079. "#endif"
  4080. ].join("\n"),
  4081. map_vertex: [
  4082. "#ifdef USE_MAP",
  4083. "vUv = uv * offsetRepeat.zw + offsetRepeat.xy;",
  4084. "#endif"
  4085. ].join("\n"),
  4086. map_fragment: [
  4087. "#ifdef USE_MAP",
  4088. "#ifdef GAMMA_INPUT",
  4089. "vec4 texelColor = texture2D( map, vUv );",
  4090. "texelColor.xyz *= texelColor.xyz;",
  4091. "gl_FragColor = gl_FragColor * texelColor;",
  4092. "#else",
  4093. "gl_FragColor = gl_FragColor * texture2D( map, vUv );",
  4094. "#endif",
  4095. "#endif"
  4096. ].join("\n"),
  4097. // LIGHT MAP
  4098. lightmap_pars_fragment: [
  4099. "#ifdef USE_LIGHTMAP",
  4100. "varying vec2 vUv2;",
  4101. "uniform sampler2D lightMap;",
  4102. "#endif"
  4103. ].join("\n"),
  4104. lightmap_pars_vertex: [
  4105. "#ifdef USE_LIGHTMAP",
  4106. "varying vec2 vUv2;",
  4107. "#endif"
  4108. ].join("\n"),
  4109. lightmap_fragment: [
  4110. "#ifdef USE_LIGHTMAP",
  4111. "gl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );",
  4112. "#endif"
  4113. ].join("\n"),
  4114. lightmap_vertex: [
  4115. "#ifdef USE_LIGHTMAP",
  4116. "vUv2 = uv2;",
  4117. "#endif"
  4118. ].join("\n"),
  4119. // LIGHTS LAMBERT
  4120. lights_lambert_pars_vertex: [
  4121. "uniform vec3 ambient;",
  4122. "uniform vec3 diffuse;",
  4123. "uniform vec3 emissive;",
  4124. "uniform vec3 ambientLightColor;",
  4125. "#if MAX_DIR_LIGHTS > 0",
  4126. "uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];",
  4127. "uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",
  4128. "#endif",
  4129. "#if MAX_POINT_LIGHTS > 0",
  4130. "uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
  4131. "uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
  4132. "uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
  4133. "#endif",
  4134. "#if MAX_SPOT_LIGHTS > 0",
  4135. "uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];",
  4136. "uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];",
  4137. "uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];",
  4138. "uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];",
  4139. "uniform float spotLightAngle[ MAX_SPOT_LIGHTS ];",
  4140. "uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];",
  4141. "#endif",
  4142. "#ifdef WRAP_AROUND",
  4143. "uniform vec3 wrapRGB;",
  4144. "#endif"
  4145. ].join("\n"),
  4146. lights_lambert_vertex: [
  4147. "vLightFront = vec3( 0.0 );",
  4148. "#ifdef DOUBLE_SIDED",
  4149. "vLightBack = vec3( 0.0 );",
  4150. "#endif",
  4151. "transformedNormal = normalize( transformedNormal );",
  4152. "#if MAX_DIR_LIGHTS > 0",
  4153. "for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {",
  4154. "vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
  4155. "vec3 dirVector = normalize( lDirection.xyz );",
  4156. "float dotProduct = dot( transformedNormal, dirVector );",
  4157. "vec3 directionalLightWeighting = vec3( max( dotProduct, 0.0 ) );",
  4158. "#ifdef DOUBLE_SIDED",
  4159. "vec3 directionalLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );",
  4160. "#ifdef WRAP_AROUND",
  4161. "vec3 directionalLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );",
  4162. "#endif",
  4163. "#endif",
  4164. "#ifdef WRAP_AROUND",
  4165. "vec3 directionalLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );",
  4166. "directionalLightWeighting = mix( directionalLightWeighting, directionalLightWeightingHalf, wrapRGB );",
  4167. "#ifdef DOUBLE_SIDED",
  4168. "directionalLightWeightingBack = mix( directionalLightWeightingBack, directionalLightWeightingHalfBack, wrapRGB );",
  4169. "#endif",
  4170. "#endif",
  4171. "vLightFront += directionalLightColor[ i ] * directionalLightWeighting;",
  4172. "#ifdef DOUBLE_SIDED",
  4173. "vLightBack += directionalLightColor[ i ] * directionalLightWeightingBack;",
  4174. "#endif",
  4175. "}",
  4176. "#endif",
  4177. "#if MAX_POINT_LIGHTS > 0",
  4178. "for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
  4179. "vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
  4180. "vec3 lVector = lPosition.xyz - mvPosition.xyz;",
  4181. "float lDistance = 1.0;",
  4182. "if ( pointLightDistance[ i ] > 0.0 )",
  4183. "lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
  4184. "lVector = normalize( lVector );",
  4185. "float dotProduct = dot( transformedNormal, lVector );",
  4186. "vec3 pointLightWeighting = vec3( max( dotProduct, 0.0 ) );",
  4187. "#ifdef DOUBLE_SIDED",
  4188. "vec3 pointLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );",
  4189. "#ifdef WRAP_AROUND",
  4190. "vec3 pointLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );",
  4191. "#endif",
  4192. "#endif",
  4193. "#ifdef WRAP_AROUND",
  4194. "vec3 pointLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );",
  4195. "pointLightWeighting = mix( pointLightWeighting, pointLightWeightingHalf, wrapRGB );",
  4196. "#ifdef DOUBLE_SIDED",
  4197. "pointLightWeightingBack = mix( pointLightWeightingBack, pointLightWeightingHalfBack, wrapRGB );",
  4198. "#endif",
  4199. "#endif",
  4200. "vLightFront += pointLightColor[ i ] * pointLightWeighting * lDistance;",
  4201. "#ifdef DOUBLE_SIDED",
  4202. "vLightBack += pointLightColor[ i ] * pointLightWeightingBack * lDistance;",
  4203. "#endif",
  4204. "}",
  4205. "#endif",
  4206. "#if MAX_SPOT_LIGHTS > 0",
  4207. "for( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {",
  4208. "vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );",
  4209. "vec3 lVector = lPosition.xyz - mvPosition.xyz;",
  4210. "lVector = normalize( lVector );",
  4211. "float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - mPosition.xyz ) );",
  4212. "if ( spotEffect > spotLightAngle[ i ] ) {",
  4213. "spotEffect = pow( spotEffect, spotLightExponent[ i ] );",
  4214. "float lDistance = 1.0;",
  4215. "if ( spotLightDistance[ i ] > 0.0 )",
  4216. "lDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );",
  4217. "float dotProduct = dot( transformedNormal, lVector );",
  4218. "vec3 spotLightWeighting = vec3( max( dotProduct, 0.0 ) );",
  4219. "#ifdef DOUBLE_SIDED",
  4220. "vec3 spotLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );",
  4221. "#ifdef WRAP_AROUND",
  4222. "vec3 spotLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );",
  4223. "#endif",
  4224. "#endif",
  4225. "#ifdef WRAP_AROUND",
  4226. "vec3 spotLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );",
  4227. "spotLightWeighting = mix( spotLightWeighting, spotLightWeightingHalf, wrapRGB );",
  4228. "#ifdef DOUBLE_SIDED",
  4229. "spotLightWeightingBack = mix( spotLightWeightingBack, spotLightWeightingHalfBack, wrapRGB );",
  4230. "#endif",
  4231. "#endif",
  4232. "vLightFront += spotLightColor[ i ] * spotLightWeighting * lDistance * spotEffect;",
  4233. "#ifdef DOUBLE_SIDED",
  4234. "vLightBack += spotLightColor[ i ] * spotLightWeightingBack * lDistance * spotEffect;",
  4235. "#endif",
  4236. "}",
  4237. "}",
  4238. "#endif",
  4239. "vLightFront = vLightFront * diffuse + ambient * ambientLightColor + emissive;",
  4240. "#ifdef DOUBLE_SIDED",
  4241. "vLightBack = vLightBack * diffuse + ambient * ambientLightColor + emissive;",
  4242. "#endif"
  4243. ].join("\n"),
  4244. // LIGHTS PHONG
  4245. lights_phong_pars_vertex: [
  4246. "#ifndef PHONG_PER_PIXEL",
  4247. "#if MAX_POINT_LIGHTS > 0",
  4248. "uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
  4249. "uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
  4250. "varying vec4 vPointLight[ MAX_POINT_LIGHTS ];",
  4251. "#endif",
  4252. "#if MAX_SPOT_LIGHTS > 0",
  4253. "uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];",
  4254. "uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];",
  4255. "varying vec4 vSpotLight[ MAX_SPOT_LIGHTS ];",
  4256. "#endif",
  4257. "#endif",
  4258. "#if MAX_SPOT_LIGHTS > 0",
  4259. "varying vec3 vWorldPosition;",
  4260. "#endif"
  4261. ].join("\n"),
  4262. lights_phong_vertex: [
  4263. "#ifndef PHONG_PER_PIXEL",
  4264. "#if MAX_POINT_LIGHTS > 0",
  4265. "for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
  4266. "vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
  4267. "vec3 lVector = lPosition.xyz - mvPosition.xyz;",
  4268. "float lDistance = 1.0;",
  4269. "if ( pointLightDistance[ i ] > 0.0 )",
  4270. "lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
  4271. "vPointLight[ i ] = vec4( lVector, lDistance );",
  4272. "}",
  4273. "#endif",
  4274. "#if MAX_SPOT_LIGHTS > 0",
  4275. "for( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {",
  4276. "vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );",
  4277. "vec3 lVector = lPosition.xyz - mvPosition.xyz;",
  4278. "float lDistance = 1.0;",
  4279. "if ( spotLightDistance[ i ] > 0.0 )",
  4280. "lDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );",
  4281. "vSpotLight[ i ] = vec4( lVector, lDistance );",
  4282. "}",
  4283. "#endif",
  4284. "#endif",
  4285. "#if MAX_SPOT_LIGHTS > 0",
  4286. "vWorldPosition = mPosition.xyz;",
  4287. "#endif"
  4288. ].join("\n"),
  4289. lights_phong_pars_fragment: [
  4290. "uniform vec3 ambientLightColor;",
  4291. "#if MAX_DIR_LIGHTS > 0",
  4292. "uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];",
  4293. "uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",
  4294. "#endif",
  4295. "#if MAX_POINT_LIGHTS > 0",
  4296. "uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
  4297. "#ifdef PHONG_PER_PIXEL",
  4298. "uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
  4299. "uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
  4300. "#else",
  4301. "varying vec4 vPointLight[ MAX_POINT_LIGHTS ];",
  4302. "#endif",
  4303. "#endif",
  4304. "#if MAX_SPOT_LIGHTS > 0",
  4305. "uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];",
  4306. "uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];",
  4307. "uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];",
  4308. "uniform float spotLightAngle[ MAX_SPOT_LIGHTS ];",
  4309. "uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];",
  4310. "#ifdef PHONG_PER_PIXEL",
  4311. "uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];",
  4312. "#else",
  4313. "varying vec4 vSpotLight[ MAX_SPOT_LIGHTS ];",
  4314. "#endif",
  4315. "varying vec3 vWorldPosition;",
  4316. "#endif",
  4317. "#ifdef WRAP_AROUND",
  4318. "uniform vec3 wrapRGB;",
  4319. "#endif",
  4320. "varying vec3 vViewPosition;",
  4321. "varying vec3 vNormal;"
  4322. ].join("\n"),
  4323. lights_phong_fragment: [
  4324. "vec3 normal = normalize( vNormal );",
  4325. "vec3 viewPosition = normalize( vViewPosition );",
  4326. "#ifdef DOUBLE_SIDED",
  4327. "normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );",
  4328. "#endif",
  4329. "#if MAX_POINT_LIGHTS > 0",
  4330. "vec3 pointDiffuse = vec3( 0.0 );",
  4331. "vec3 pointSpecular = vec3( 0.0 );",
  4332. "for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
  4333. "#ifdef PHONG_PER_PIXEL",
  4334. "vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
  4335. "vec3 lVector = lPosition.xyz + vViewPosition.xyz;",
  4336. "float lDistance = 1.0;",
  4337. "if ( pointLightDistance[ i ] > 0.0 )",
  4338. "lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
  4339. "lVector = normalize( lVector );",
  4340. "#else",
  4341. "vec3 lVector = normalize( vPointLight[ i ].xyz );",
  4342. "float lDistance = vPointLight[ i ].w;",
  4343. "#endif",
  4344. // diffuse
  4345. "float dotProduct = dot( normal, lVector );",
  4346. "#ifdef WRAP_AROUND",
  4347. "float pointDiffuseWeightFull = max( dotProduct, 0.0 );",
  4348. "float pointDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );",
  4349. "vec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );",
  4350. "#else",
  4351. "float pointDiffuseWeight = max( dotProduct, 0.0 );",
  4352. "#endif",
  4353. "pointDiffuse += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;",
  4354. // specular
  4355. "vec3 pointHalfVector = normalize( lVector + viewPosition );",
  4356. "float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
  4357. "float pointSpecularWeight = max( pow( pointDotNormalHalf, shininess ), 0.0 );",
  4358. "#ifdef PHYSICALLY_BASED_SHADING",
  4359. // 2.0 => 2.0001 is hack to work around ANGLE bug
  4360. "float specularNormalization = ( shininess + 2.0001 ) / 8.0;",
  4361. "vec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVector, pointHalfVector ), 5.0 );",
  4362. "pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance * specularNormalization;",
  4363. "#else",
  4364. "pointSpecular += specular * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance;",
  4365. "#endif",
  4366. "}",
  4367. "#endif",
  4368. "#if MAX_SPOT_LIGHTS > 0",
  4369. "vec3 spotDiffuse = vec3( 0.0 );",
  4370. "vec3 spotSpecular = vec3( 0.0 );",
  4371. "for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {",
  4372. "#ifdef PHONG_PER_PIXEL",
  4373. "vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );",
  4374. "vec3 lVector = lPosition.xyz + vViewPosition.xyz;",
  4375. "float lDistance = 1.0;",
  4376. "if ( spotLightDistance[ i ] > 0.0 )",
  4377. "lDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );",
  4378. "lVector = normalize( lVector );",
  4379. "#else",
  4380. "vec3 lVector = normalize( vSpotLight[ i ].xyz );",
  4381. "float lDistance = vSpotLight[ i ].w;",
  4382. "#endif",
  4383. "float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );",
  4384. "if ( spotEffect > spotLightAngle[ i ] ) {",
  4385. "spotEffect = pow( spotEffect, spotLightExponent[ i ] );",
  4386. // diffuse
  4387. "float dotProduct = dot( normal, lVector );",
  4388. "#ifdef WRAP_AROUND",
  4389. "float spotDiffuseWeightFull = max( dotProduct, 0.0 );",
  4390. "float spotDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );",
  4391. "vec3 spotDiffuseWeight = mix( vec3 ( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );",
  4392. "#else",
  4393. "float spotDiffuseWeight = max( dotProduct, 0.0 );",
  4394. "#endif",
  4395. "spotDiffuse += diffuse * spotLightColor[ i ] * spotDiffuseWeight * lDistance * spotEffect;",
  4396. // specular
  4397. "vec3 spotHalfVector = normalize( lVector + viewPosition );",
  4398. "float spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );",
  4399. "float spotSpecularWeight = max( pow( spotDotNormalHalf, shininess ), 0.0 );",
  4400. "#ifdef PHYSICALLY_BASED_SHADING",
  4401. // 2.0 => 2.0001 is hack to work around ANGLE bug
  4402. "float specularNormalization = ( shininess + 2.0001 ) / 8.0;",
  4403. "vec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVector, spotHalfVector ), 5.0 );",
  4404. "spotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * lDistance * specularNormalization * spotEffect;",
  4405. "#else",
  4406. "spotSpecular += specular * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * lDistance * spotEffect;",
  4407. "#endif",
  4408. "}",
  4409. "}",
  4410. "#endif",
  4411. "#if MAX_DIR_LIGHTS > 0",
  4412. "vec3 dirDiffuse = vec3( 0.0 );",
  4413. "vec3 dirSpecular = vec3( 0.0 );" ,
  4414. "for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {",
  4415. "vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
  4416. "vec3 dirVector = normalize( lDirection.xyz );",
  4417. // diffuse
  4418. "float dotProduct = dot( normal, dirVector );",
  4419. "#ifdef WRAP_AROUND",
  4420. "float dirDiffuseWeightFull = max( dotProduct, 0.0 );",
  4421. "float dirDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );",
  4422. "vec3 dirDiffuseWeight = mix( vec3( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), wrapRGB );",
  4423. "#else",
  4424. "float dirDiffuseWeight = max( dotProduct, 0.0 );",
  4425. "#endif",
  4426. "dirDiffuse += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;",
  4427. // specular
  4428. "vec3 dirHalfVector = normalize( dirVector + viewPosition );",
  4429. "float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
  4430. "float dirSpecularWeight = max( pow( dirDotNormalHalf, shininess ), 0.0 );",
  4431. "#ifdef PHYSICALLY_BASED_SHADING",
  4432. /*
  4433. // fresnel term from skin shader
  4434. "const float F0 = 0.128;",
  4435. "float base = 1.0 - dot( viewPosition, dirHalfVector );",
  4436. "float exponential = pow( base, 5.0 );",
  4437. "float fresnel = exponential + F0 * ( 1.0 - exponential );",
  4438. */
  4439. /*
  4440. // fresnel term from fresnel shader
  4441. "const float mFresnelBias = 0.08;",
  4442. "const float mFresnelScale = 0.3;",
  4443. "const float mFresnelPower = 5.0;",
  4444. "float fresnel = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( -viewPosition ), normal ), mFresnelPower );",
  4445. */
  4446. // 2.0 => 2.0001 is hack to work around ANGLE bug
  4447. "float specularNormalization = ( shininess + 2.0001 ) / 8.0;",
  4448. //"dirSpecular += specular * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization * fresnel;",
  4449. "vec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( dirVector, dirHalfVector ), 5.0 );",
  4450. "dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;",
  4451. "#else",
  4452. "dirSpecular += specular * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight;",
  4453. "#endif",
  4454. "}",
  4455. "#endif",
  4456. "vec3 totalDiffuse = vec3( 0.0 );",
  4457. "vec3 totalSpecular = vec3( 0.0 );",
  4458. "#if MAX_DIR_LIGHTS > 0",
  4459. "totalDiffuse += dirDiffuse;",
  4460. "totalSpecular += dirSpecular;",
  4461. "#endif",
  4462. "#if MAX_POINT_LIGHTS > 0",
  4463. "totalDiffuse += pointDiffuse;",
  4464. "totalSpecular += pointSpecular;",
  4465. "#endif",
  4466. "#if MAX_SPOT_LIGHTS > 0",
  4467. "totalDiffuse += spotDiffuse;",
  4468. "totalSpecular += spotSpecular;",
  4469. "#endif",
  4470. "#ifdef METAL",
  4471. "gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient + totalSpecular );",
  4472. "#else",
  4473. "gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient ) + totalSpecular;",
  4474. "#endif"
  4475. ].join("\n"),
  4476. // VERTEX COLORS
  4477. color_pars_fragment: [
  4478. "#ifdef USE_COLOR",
  4479. "varying vec3 vColor;",
  4480. "#endif"
  4481. ].join("\n"),
  4482. color_fragment: [
  4483. "#ifdef USE_COLOR",
  4484. "gl_FragColor = gl_FragColor * vec4( vColor, opacity );",
  4485. "#endif"
  4486. ].join("\n"),
  4487. color_pars_vertex: [
  4488. "#ifdef USE_COLOR",
  4489. "varying vec3 vColor;",
  4490. "#endif"
  4491. ].join("\n"),
  4492. color_vertex: [
  4493. "#ifdef USE_COLOR",
  4494. "#ifdef GAMMA_INPUT",
  4495. "vColor = color * color;",
  4496. "#else",
  4497. "vColor = color;",
  4498. "#endif",
  4499. "#endif"
  4500. ].join("\n"),
  4501. // SKINNING
  4502. skinning_pars_vertex: [
  4503. "#ifdef USE_SKINNING",
  4504. "uniform mat4 boneGlobalMatrices[ MAX_BONES ];",
  4505. "#endif"
  4506. ].join("\n"),
  4507. skinning_vertex: [
  4508. "#ifdef USE_SKINNING",
  4509. "gl_Position = ( boneGlobalMatrices[ int( skinIndex.x ) ] * skinVertexA ) * skinWeight.x;",
  4510. "gl_Position += ( boneGlobalMatrices[ int( skinIndex.y ) ] * skinVertexB ) * skinWeight.y;",
  4511. "gl_Position = projectionMatrix * modelViewMatrix * gl_Position;",
  4512. "#endif"
  4513. ].join("\n"),
  4514. // MORPHING
  4515. morphtarget_pars_vertex: [
  4516. "#ifdef USE_MORPHTARGETS",
  4517. "#ifndef USE_MORPHNORMALS",
  4518. "uniform float morphTargetInfluences[ 8 ];",
  4519. "#else",
  4520. "uniform float morphTargetInfluences[ 4 ];",
  4521. "#endif",
  4522. "#endif"
  4523. ].join("\n"),
  4524. morphtarget_vertex: [
  4525. "#ifdef USE_MORPHTARGETS",
  4526. "vec3 morphed = vec3( 0.0 );",
  4527. "morphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];",
  4528. "morphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];",
  4529. "morphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];",
  4530. "morphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];",
  4531. "#ifndef USE_MORPHNORMALS",
  4532. "morphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];",
  4533. "morphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];",
  4534. "morphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];",
  4535. "morphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];",
  4536. "#endif",
  4537. "morphed += position;",
  4538. "gl_Position = projectionMatrix * modelViewMatrix * vec4( morphed, 1.0 );",
  4539. "#endif"
  4540. ].join("\n"),
  4541. default_vertex : [
  4542. "#ifndef USE_MORPHTARGETS",
  4543. "#ifndef USE_SKINNING",
  4544. "gl_Position = projectionMatrix * mvPosition;",
  4545. "#endif",
  4546. "#endif"
  4547. ].join("\n"),
  4548. morphnormal_vertex: [
  4549. "#ifdef USE_MORPHNORMALS",
  4550. "vec3 morphedNormal = vec3( 0.0 );",
  4551. "morphedNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];",
  4552. "morphedNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];",
  4553. "morphedNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];",
  4554. "morphedNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];",
  4555. "morphedNormal += normal;",
  4556. "vec3 transformedNormal = normalMatrix * morphedNormal;",
  4557. "#else",
  4558. "vec3 transformedNormal = normalMatrix * normal;",
  4559. "#endif"
  4560. ].join("\n"),
  4561. // SHADOW MAP
  4562. // based on SpiderGL shadow map and Fabien Sanglard's GLSL shadow mapping examples
  4563. // http://spidergl.org/example.php?id=6
  4564. // http://fabiensanglard.net/shadowmapping
  4565. shadowmap_pars_fragment: [
  4566. "#ifdef USE_SHADOWMAP",
  4567. "uniform sampler2D shadowMap[ MAX_SHADOWS ];",
  4568. "uniform vec2 shadowMapSize[ MAX_SHADOWS ];",
  4569. "uniform float shadowDarkness[ MAX_SHADOWS ];",
  4570. "uniform float shadowBias[ MAX_SHADOWS ];",
  4571. "varying vec4 vShadowCoord[ MAX_SHADOWS ];",
  4572. "float unpackDepth( const in vec4 rgba_depth ) {",
  4573. "const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
  4574. "float depth = dot( rgba_depth, bit_shift );",
  4575. "return depth;",
  4576. "}",
  4577. "#endif"
  4578. ].join("\n"),
  4579. shadowmap_fragment: [
  4580. "#ifdef USE_SHADOWMAP",
  4581. "#ifdef SHADOWMAP_DEBUG",
  4582. "vec3 frustumColors[3];",
  4583. "frustumColors[0] = vec3( 1.0, 0.5, 0.0 );",
  4584. "frustumColors[1] = vec3( 0.0, 1.0, 0.8 );",
  4585. "frustumColors[2] = vec3( 0.0, 0.5, 1.0 );",
  4586. "#endif",
  4587. "#ifdef SHADOWMAP_CASCADE",
  4588. "int inFrustumCount = 0;",
  4589. "#endif",
  4590. "float fDepth;",
  4591. "vec3 shadowColor = vec3( 1.0 );",
  4592. "for( int i = 0; i < MAX_SHADOWS; i ++ ) {",
  4593. "vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;",
  4594. // "if ( something && something )" breaks ATI OpenGL shader compiler
  4595. // "if ( all( something, something ) )" using this instead
  4596. "bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );",
  4597. "bool inFrustum = all( inFrustumVec );",
  4598. // don't shadow pixels outside of light frustum
  4599. // use just first frustum (for cascades)
  4600. // don't shadow pixels behind far plane of light frustum
  4601. "#ifdef SHADOWMAP_CASCADE",
  4602. "inFrustumCount += int( inFrustum );",
  4603. "bvec3 frustumTestVec = bvec3( inFrustum, inFrustumCount == 1, shadowCoord.z <= 1.0 );",
  4604. "#else",
  4605. "bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );",
  4606. "#endif",
  4607. "bool frustumTest = all( frustumTestVec );",
  4608. "if ( frustumTest ) {",
  4609. "shadowCoord.z += shadowBias[ i ];",
  4610. "#ifdef SHADOWMAP_SOFT",
  4611. // Percentage-close filtering
  4612. // (9 pixel kernel)
  4613. // http://fabiensanglard.net/shadowmappingPCF/
  4614. "float shadow = 0.0;",
  4615. /*
  4616. // nested loops breaks shader compiler / validator on some ATI cards when using OpenGL
  4617. // must enroll loop manually
  4618. "for ( float y = -1.25; y <= 1.25; y += 1.25 )",
  4619. "for ( float x = -1.25; x <= 1.25; x += 1.25 ) {",
  4620. "vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );",
  4621. // doesn't seem to produce any noticeable visual difference compared to simple "texture2D" lookup
  4622. //"vec4 rgbaDepth = texture2DProj( shadowMap[ i ], vec4( vShadowCoord[ i ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ i ].w ) );",
  4623. "float fDepth = unpackDepth( rgbaDepth );",
  4624. "if ( fDepth < shadowCoord.z )",
  4625. "shadow += 1.0;",
  4626. "}",
  4627. "shadow /= 9.0;",
  4628. */
  4629. "const float shadowDelta = 1.0 / 9.0;",
  4630. "float xPixelOffset = 1.0 / shadowMapSize[ i ].x;",
  4631. "float yPixelOffset = 1.0 / shadowMapSize[ i ].y;",
  4632. "float dx0 = -1.25 * xPixelOffset;",
  4633. "float dy0 = -1.25 * yPixelOffset;",
  4634. "float dx1 = 1.25 * xPixelOffset;",
  4635. "float dy1 = 1.25 * yPixelOffset;",
  4636. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );",
  4637. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  4638. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );",
  4639. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  4640. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );",
  4641. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  4642. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );",
  4643. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  4644. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );",
  4645. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  4646. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );",
  4647. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  4648. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );",
  4649. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  4650. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );",
  4651. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  4652. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );",
  4653. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  4654. "shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );",
  4655. "#else",
  4656. "vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );",
  4657. "float fDepth = unpackDepth( rgbaDepth );",
  4658. "if ( fDepth < shadowCoord.z )",
  4659. // spot with multiple shadows is darker
  4660. "shadowColor = shadowColor * vec3( 1.0 - shadowDarkness[ i ] );",
  4661. // spot with multiple shadows has the same color as single shadow spot
  4662. //"shadowColor = min( shadowColor, vec3( shadowDarkness[ i ] ) );",
  4663. "#endif",
  4664. "}",
  4665. "#ifdef SHADOWMAP_DEBUG",
  4666. "#ifdef SHADOWMAP_CASCADE",
  4667. "if ( inFrustum && inFrustumCount == 1 ) gl_FragColor.xyz *= frustumColors[ i ];",
  4668. "#else",
  4669. "if ( inFrustum ) gl_FragColor.xyz *= frustumColors[ i ];",
  4670. "#endif",
  4671. "#endif",
  4672. "}",
  4673. "#ifdef GAMMA_OUTPUT",
  4674. "shadowColor *= shadowColor;",
  4675. "#endif",
  4676. "gl_FragColor.xyz = gl_FragColor.xyz * shadowColor;",
  4677. "#endif"
  4678. ].join("\n"),
  4679. shadowmap_pars_vertex: [
  4680. "#ifdef USE_SHADOWMAP",
  4681. "varying vec4 vShadowCoord[ MAX_SHADOWS ];",
  4682. "uniform mat4 shadowMatrix[ MAX_SHADOWS ];",
  4683. "#endif"
  4684. ].join("\n"),
  4685. shadowmap_vertex: [
  4686. "#ifdef USE_SHADOWMAP",
  4687. "for( int i = 0; i < MAX_SHADOWS; i ++ ) {",
  4688. "#ifdef USE_MORPHTARGETS",
  4689. "vShadowCoord[ i ] = shadowMatrix[ i ] * objectMatrix * vec4( morphed, 1.0 );",
  4690. "#else",
  4691. "vShadowCoord[ i ] = shadowMatrix[ i ] * objectMatrix * vec4( position, 1.0 );",
  4692. "#endif",
  4693. "}",
  4694. "#endif"
  4695. ].join("\n"),
  4696. // ALPHATEST
  4697. alphatest_fragment: [
  4698. "#ifdef ALPHATEST",
  4699. "if ( gl_FragColor.a < ALPHATEST ) discard;",
  4700. "#endif"
  4701. ].join("\n"),
  4702. // LINEAR SPACE
  4703. linear_to_gamma_fragment: [
  4704. "#ifdef GAMMA_OUTPUT",
  4705. "gl_FragColor.xyz = sqrt( gl_FragColor.xyz );",
  4706. "#endif"
  4707. ].join("\n"),
  4708. };
  4709. THREE.UniformsUtils = {
  4710. merge: function ( uniforms ) {
  4711. var u, p, tmp, merged = {};
  4712. for ( u = 0; u < uniforms.length; u++ ) {
  4713. tmp = this.clone( uniforms[ u ] );
  4714. for ( p in tmp ) {
  4715. merged[ p ] = tmp[ p ];
  4716. }
  4717. }
  4718. return merged;
  4719. },
  4720. clone: function ( uniforms_src ) {
  4721. var u, p, parameter, parameter_src, uniforms_dst = {};
  4722. for ( u in uniforms_src ) {
  4723. uniforms_dst[ u ] = {};
  4724. for ( p in uniforms_src[ u ] ) {
  4725. parameter_src = uniforms_src[ u ][ p ];
  4726. if ( parameter_src instanceof THREE.Color ||
  4727. parameter_src instanceof THREE.Vector2 ||
  4728. parameter_src instanceof THREE.Vector3 ||
  4729. parameter_src instanceof THREE.Vector4 ||
  4730. parameter_src instanceof THREE.Matrix4 ||
  4731. parameter_src instanceof THREE.Texture ) {
  4732. uniforms_dst[ u ][ p ] = parameter_src.clone();
  4733. } else if ( parameter_src instanceof Array ) {
  4734. uniforms_dst[ u ][ p ] = parameter_src.slice();
  4735. } else {
  4736. uniforms_dst[ u ][ p ] = parameter_src;
  4737. }
  4738. }
  4739. }
  4740. return uniforms_dst;
  4741. }
  4742. };
  4743. THREE.UniformsLib = {
  4744. common: {
  4745. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  4746. "opacity" : { type: "f", value: 1.0 },
  4747. "map" : { type: "t", value: 0, texture: null },
  4748. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  4749. "lightMap" : { type: "t", value: 2, texture: null },
  4750. "envMap" : { type: "t", value: 1, texture: null },
  4751. "flipEnvMap" : { type: "f", value: -1 },
  4752. "useRefract" : { type: "i", value: 0 },
  4753. "reflectivity" : { type: "f", value: 1.0 },
  4754. "refractionRatio" : { type: "f", value: 0.98 },
  4755. "combine" : { type: "i", value: 0 },
  4756. "morphTargetInfluences" : { type: "f", value: 0 }
  4757. },
  4758. fog : {
  4759. "fogDensity" : { type: "f", value: 0.00025 },
  4760. "fogNear" : { type: "f", value: 1 },
  4761. "fogFar" : { type: "f", value: 2000 },
  4762. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  4763. },
  4764. lights: {
  4765. "ambientLightColor" : { type: "fv", value: [] },
  4766. "directionalLightDirection" : { type: "fv", value: [] },
  4767. "directionalLightColor" : { type: "fv", value: [] },
  4768. "pointLightColor" : { type: "fv", value: [] },
  4769. "pointLightPosition" : { type: "fv", value: [] },
  4770. "pointLightDistance" : { type: "fv1", value: [] },
  4771. "spotLightColor" : { type: "fv", value: [] },
  4772. "spotLightPosition" : { type: "fv", value: [] },
  4773. "spotLightDirection" : { type: "fv", value: [] },
  4774. "spotLightDistance" : { type: "fv1", value: [] },
  4775. "spotLightAngle" : { type: "fv1", value: [] },
  4776. "spotLightExponent" : { type: "fv1", value: [] }
  4777. },
  4778. particle: {
  4779. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  4780. "opacity" : { type: "f", value: 1.0 },
  4781. "size" : { type: "f", value: 1.0 },
  4782. "scale" : { type: "f", value: 1.0 },
  4783. "map" : { type: "t", value: 0, texture: null },
  4784. "fogDensity" : { type: "f", value: 0.00025 },
  4785. "fogNear" : { type: "f", value: 1 },
  4786. "fogFar" : { type: "f", value: 2000 },
  4787. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  4788. },
  4789. shadowmap: {
  4790. "shadowMap": { type: "tv", value: 6, texture: [] },
  4791. "shadowMapSize": { type: "v2v", value: [] },
  4792. "shadowBias" : { type: "fv1", value: [] },
  4793. "shadowDarkness": { type: "fv1", value: [] },
  4794. "shadowMatrix" : { type: "m4v", value: [] },
  4795. }
  4796. };
  4797. THREE.ShaderLib = {
  4798. 'depth': {
  4799. uniforms: {
  4800. "mNear": { type: "f", value: 1.0 },
  4801. "mFar" : { type: "f", value: 2000.0 },
  4802. "opacity" : { type: "f", value: 1.0 }
  4803. },
  4804. vertexShader: [
  4805. "void main() {",
  4806. "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  4807. "}"
  4808. ].join("\n"),
  4809. fragmentShader: [
  4810. "uniform float mNear;",
  4811. "uniform float mFar;",
  4812. "uniform float opacity;",
  4813. "void main() {",
  4814. "float depth = gl_FragCoord.z / gl_FragCoord.w;",
  4815. "float color = 1.0 - smoothstep( mNear, mFar, depth );",
  4816. "gl_FragColor = vec4( vec3( color ), opacity );",
  4817. "}"
  4818. ].join("\n")
  4819. },
  4820. 'normal': {
  4821. uniforms: {
  4822. "opacity" : { type: "f", value: 1.0 }
  4823. },
  4824. vertexShader: [
  4825. "varying vec3 vNormal;",
  4826. "void main() {",
  4827. "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  4828. "vNormal = normalMatrix * normal;",
  4829. "gl_Position = projectionMatrix * mvPosition;",
  4830. "}"
  4831. ].join("\n"),
  4832. fragmentShader: [
  4833. "uniform float opacity;",
  4834. "varying vec3 vNormal;",
  4835. "void main() {",
  4836. "gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  4837. "}"
  4838. ].join("\n")
  4839. },
  4840. 'basic': {
  4841. uniforms: THREE.UniformsUtils.merge( [
  4842. THREE.UniformsLib[ "common" ],
  4843. THREE.UniformsLib[ "fog" ],
  4844. THREE.UniformsLib[ "shadowmap" ]
  4845. ] ),
  4846. vertexShader: [
  4847. THREE.ShaderChunk[ "map_pars_vertex" ],
  4848. THREE.ShaderChunk[ "lightmap_pars_vertex" ],
  4849. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  4850. THREE.ShaderChunk[ "color_pars_vertex" ],
  4851. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  4852. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  4853. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  4854. "void main() {",
  4855. "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  4856. THREE.ShaderChunk[ "map_vertex" ],
  4857. THREE.ShaderChunk[ "lightmap_vertex" ],
  4858. THREE.ShaderChunk[ "envmap_vertex" ],
  4859. THREE.ShaderChunk[ "color_vertex" ],
  4860. THREE.ShaderChunk[ "skinning_vertex" ],
  4861. THREE.ShaderChunk[ "morphtarget_vertex" ],
  4862. THREE.ShaderChunk[ "default_vertex" ],
  4863. THREE.ShaderChunk[ "shadowmap_vertex" ],
  4864. "}"
  4865. ].join("\n"),
  4866. fragmentShader: [
  4867. "uniform vec3 diffuse;",
  4868. "uniform float opacity;",
  4869. THREE.ShaderChunk[ "color_pars_fragment" ],
  4870. THREE.ShaderChunk[ "map_pars_fragment" ],
  4871. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  4872. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  4873. THREE.ShaderChunk[ "fog_pars_fragment" ],
  4874. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  4875. "void main() {",
  4876. "gl_FragColor = vec4( diffuse, opacity );",
  4877. THREE.ShaderChunk[ "map_fragment" ],
  4878. THREE.ShaderChunk[ "alphatest_fragment" ],
  4879. THREE.ShaderChunk[ "lightmap_fragment" ],
  4880. THREE.ShaderChunk[ "color_fragment" ],
  4881. THREE.ShaderChunk[ "envmap_fragment" ],
  4882. THREE.ShaderChunk[ "shadowmap_fragment" ],
  4883. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  4884. THREE.ShaderChunk[ "fog_fragment" ],
  4885. "}"
  4886. ].join("\n")
  4887. },
  4888. 'lambert': {
  4889. uniforms: THREE.UniformsUtils.merge( [
  4890. THREE.UniformsLib[ "common" ],
  4891. THREE.UniformsLib[ "fog" ],
  4892. THREE.UniformsLib[ "lights" ],
  4893. THREE.UniformsLib[ "shadowmap" ],
  4894. {
  4895. "ambient" : { type: "c", value: new THREE.Color( 0xffffff ) },
  4896. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  4897. "wrapRGB" : { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
  4898. }
  4899. ] ),
  4900. vertexShader: [
  4901. "varying vec3 vLightFront;",
  4902. "#ifdef DOUBLE_SIDED",
  4903. "varying vec3 vLightBack;",
  4904. "#endif",
  4905. THREE.ShaderChunk[ "map_pars_vertex" ],
  4906. THREE.ShaderChunk[ "lightmap_pars_vertex" ],
  4907. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  4908. THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
  4909. THREE.ShaderChunk[ "color_pars_vertex" ],
  4910. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  4911. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  4912. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  4913. "void main() {",
  4914. "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  4915. THREE.ShaderChunk[ "map_vertex" ],
  4916. THREE.ShaderChunk[ "lightmap_vertex" ],
  4917. THREE.ShaderChunk[ "envmap_vertex" ],
  4918. THREE.ShaderChunk[ "color_vertex" ],
  4919. THREE.ShaderChunk[ "morphnormal_vertex" ],
  4920. "#ifndef USE_ENVMAP",
  4921. "vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
  4922. "#endif",
  4923. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  4924. THREE.ShaderChunk[ "skinning_vertex" ],
  4925. THREE.ShaderChunk[ "morphtarget_vertex" ],
  4926. THREE.ShaderChunk[ "default_vertex" ],
  4927. THREE.ShaderChunk[ "shadowmap_vertex" ],
  4928. "}"
  4929. ].join("\n"),
  4930. fragmentShader: [
  4931. "uniform float opacity;",
  4932. "varying vec3 vLightFront;",
  4933. "#ifdef DOUBLE_SIDED",
  4934. "varying vec3 vLightBack;",
  4935. "#endif",
  4936. THREE.ShaderChunk[ "color_pars_fragment" ],
  4937. THREE.ShaderChunk[ "map_pars_fragment" ],
  4938. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  4939. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  4940. THREE.ShaderChunk[ "fog_pars_fragment" ],
  4941. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  4942. "void main() {",
  4943. "gl_FragColor = vec4( vec3 ( 1.0 ), opacity );",
  4944. THREE.ShaderChunk[ "map_fragment" ],
  4945. THREE.ShaderChunk[ "alphatest_fragment" ],
  4946. "#ifdef DOUBLE_SIDED",
  4947. //"float isFront = float( gl_FrontFacing );",
  4948. //"gl_FragColor.xyz *= isFront * vLightFront + ( 1.0 - isFront ) * vLightBack;",
  4949. "if ( gl_FrontFacing )",
  4950. "gl_FragColor.xyz *= vLightFront;",
  4951. "else",
  4952. "gl_FragColor.xyz *= vLightBack;",
  4953. "#else",
  4954. "gl_FragColor.xyz *= vLightFront;",
  4955. "#endif",
  4956. THREE.ShaderChunk[ "lightmap_fragment" ],
  4957. THREE.ShaderChunk[ "color_fragment" ],
  4958. THREE.ShaderChunk[ "envmap_fragment" ],
  4959. THREE.ShaderChunk[ "shadowmap_fragment" ],
  4960. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  4961. THREE.ShaderChunk[ "fog_fragment" ],
  4962. "}"
  4963. ].join("\n")
  4964. },
  4965. 'phong': {
  4966. uniforms: THREE.UniformsUtils.merge( [
  4967. THREE.UniformsLib[ "common" ],
  4968. THREE.UniformsLib[ "fog" ],
  4969. THREE.UniformsLib[ "lights" ],
  4970. THREE.UniformsLib[ "shadowmap" ],
  4971. {
  4972. "ambient" : { type: "c", value: new THREE.Color( 0xffffff ) },
  4973. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  4974. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  4975. "shininess": { type: "f", value: 30 },
  4976. "wrapRGB" : { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
  4977. }
  4978. ] ),
  4979. vertexShader: [
  4980. "varying vec3 vViewPosition;",
  4981. "varying vec3 vNormal;",
  4982. THREE.ShaderChunk[ "map_pars_vertex" ],
  4983. THREE.ShaderChunk[ "lightmap_pars_vertex" ],
  4984. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  4985. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  4986. THREE.ShaderChunk[ "color_pars_vertex" ],
  4987. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  4988. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  4989. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  4990. "void main() {",
  4991. "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  4992. THREE.ShaderChunk[ "map_vertex" ],
  4993. THREE.ShaderChunk[ "lightmap_vertex" ],
  4994. THREE.ShaderChunk[ "envmap_vertex" ],
  4995. THREE.ShaderChunk[ "color_vertex" ],
  4996. "#ifndef USE_ENVMAP",
  4997. "vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
  4998. "#endif",
  4999. "vViewPosition = -mvPosition.xyz;",
  5000. THREE.ShaderChunk[ "morphnormal_vertex" ],
  5001. "vNormal = transformedNormal;",
  5002. THREE.ShaderChunk[ "lights_phong_vertex" ],
  5003. THREE.ShaderChunk[ "skinning_vertex" ],
  5004. THREE.ShaderChunk[ "morphtarget_vertex" ],
  5005. THREE.ShaderChunk[ "default_vertex" ],
  5006. THREE.ShaderChunk[ "shadowmap_vertex" ],
  5007. "}"
  5008. ].join("\n"),
  5009. fragmentShader: [
  5010. "uniform vec3 diffuse;",
  5011. "uniform float opacity;",
  5012. "uniform vec3 ambient;",
  5013. "uniform vec3 emissive;",
  5014. "uniform vec3 specular;",
  5015. "uniform float shininess;",
  5016. THREE.ShaderChunk[ "color_pars_fragment" ],
  5017. THREE.ShaderChunk[ "map_pars_fragment" ],
  5018. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  5019. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  5020. THREE.ShaderChunk[ "fog_pars_fragment" ],
  5021. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  5022. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  5023. "void main() {",
  5024. "gl_FragColor = vec4( vec3 ( 1.0 ), opacity );",
  5025. THREE.ShaderChunk[ "map_fragment" ],
  5026. THREE.ShaderChunk[ "alphatest_fragment" ],
  5027. THREE.ShaderChunk[ "lights_phong_fragment" ],
  5028. THREE.ShaderChunk[ "lightmap_fragment" ],
  5029. THREE.ShaderChunk[ "color_fragment" ],
  5030. THREE.ShaderChunk[ "envmap_fragment" ],
  5031. THREE.ShaderChunk[ "shadowmap_fragment" ],
  5032. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  5033. THREE.ShaderChunk[ "fog_fragment" ],
  5034. "}"
  5035. ].join("\n")
  5036. },
  5037. 'particle_basic': {
  5038. uniforms: THREE.UniformsUtils.merge( [
  5039. THREE.UniformsLib[ "particle" ],
  5040. THREE.UniformsLib[ "shadowmap" ]
  5041. ] ),
  5042. vertexShader: [
  5043. "uniform float size;",
  5044. "uniform float scale;",
  5045. THREE.ShaderChunk[ "color_pars_vertex" ],
  5046. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  5047. "void main() {",
  5048. THREE.ShaderChunk[ "color_vertex" ],
  5049. "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  5050. "#ifdef USE_SIZEATTENUATION",
  5051. "gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
  5052. "#else",
  5053. "gl_PointSize = size;",
  5054. "#endif",
  5055. "gl_Position = projectionMatrix * mvPosition;",
  5056. THREE.ShaderChunk[ "shadowmap_vertex" ],
  5057. "}"
  5058. ].join("\n"),
  5059. fragmentShader: [
  5060. "uniform vec3 psColor;",
  5061. "uniform float opacity;",
  5062. THREE.ShaderChunk[ "color_pars_fragment" ],
  5063. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  5064. THREE.ShaderChunk[ "fog_pars_fragment" ],
  5065. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  5066. "void main() {",
  5067. "gl_FragColor = vec4( psColor, opacity );",
  5068. THREE.ShaderChunk[ "map_particle_fragment" ],
  5069. THREE.ShaderChunk[ "alphatest_fragment" ],
  5070. THREE.ShaderChunk[ "color_fragment" ],
  5071. THREE.ShaderChunk[ "shadowmap_fragment" ],
  5072. THREE.ShaderChunk[ "fog_fragment" ],
  5073. "}"
  5074. ].join("\n")
  5075. },
  5076. // Depth encoding into RGBA texture
  5077. // based on SpiderGL shadow map example
  5078. // http://spidergl.org/example.php?id=6
  5079. // originally from
  5080. // http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  5081. // see also here:
  5082. // http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  5083. 'depthRGBA': {
  5084. uniforms: {},
  5085. vertexShader: [
  5086. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  5087. "void main() {",
  5088. "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  5089. THREE.ShaderChunk[ "morphtarget_vertex" ],
  5090. THREE.ShaderChunk[ "default_vertex" ],
  5091. "}"
  5092. ].join("\n"),
  5093. fragmentShader: [
  5094. "vec4 pack_depth( const in float depth ) {",
  5095. "const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  5096. "const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  5097. "vec4 res = fract( depth * bit_shift );",
  5098. "res -= res.xxyz * bit_mask;",
  5099. "return res;",
  5100. "}",
  5101. "void main() {",
  5102. "gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  5103. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  5104. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  5105. //"gl_FragData[ 0 ] = pack_depth( z );",
  5106. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  5107. "}"
  5108. ].join("\n")
  5109. }
  5110. };/**
  5111. * @author supereggbert / http://www.paulbrunt.co.uk/
  5112. * @author mrdoob / http://mrdoob.com/
  5113. * @author alteredq / http://alteredqualia.com/
  5114. * @author szimek / https://github.com/szimek/
  5115. */
  5116. THREE.WebGLRenderer = function ( parameters ) {
  5117. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  5118. parameters = parameters || {};
  5119. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  5120. _precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  5121. _alpha = parameters.alpha !== undefined ? parameters.alpha : true,
  5122. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  5123. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  5124. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  5125. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  5126. _clearColor = parameters.clearColor !== undefined ? new THREE.Color( parameters.clearColor ) : new THREE.Color( 0x000000 ),
  5127. _clearAlpha = parameters.clearAlpha !== undefined ? parameters.clearAlpha : 0,
  5128. _maxLights = parameters.maxLights !== undefined ? parameters.maxLights : 4;
  5129. // public properties
  5130. this.domElement = _canvas;
  5131. this.context = null;
  5132. // clearing
  5133. this.autoClear = true;
  5134. this.autoClearColor = true;
  5135. this.autoClearDepth = true;
  5136. this.autoClearStencil = true;
  5137. // scene graph
  5138. this.sortObjects = true;
  5139. this.autoUpdateObjects = true;
  5140. this.autoUpdateScene = true;
  5141. // physically based shading
  5142. this.gammaInput = false;
  5143. this.gammaOutput = false;
  5144. this.physicallyBasedShading = false;
  5145. // shadow map
  5146. this.shadowMapEnabled = false;
  5147. this.shadowMapAutoUpdate = true;
  5148. this.shadowMapSoft = true;
  5149. this.shadowMapCullFrontFaces = true;
  5150. this.shadowMapDebug = false;
  5151. this.shadowMapCascade = false;
  5152. // morphs
  5153. this.maxMorphTargets = 8;
  5154. this.maxMorphNormals = 4;
  5155. // flags
  5156. this.autoScaleCubemaps = true;
  5157. // custom render plugins
  5158. this.renderPluginsPre = [];
  5159. this.renderPluginsPost = [];
  5160. // info
  5161. this.info = {
  5162. memory: {
  5163. programs: 0,
  5164. geometries: 0,
  5165. textures: 0
  5166. },
  5167. render: {
  5168. calls: 0,
  5169. vertices: 0,
  5170. faces: 0,
  5171. points: 0
  5172. }
  5173. };
  5174. // internal properties
  5175. var _this = this,
  5176. _gl,
  5177. _programs = [],
  5178. // internal state cache
  5179. _currentProgram = null,
  5180. _currentFramebuffer = null,
  5181. _currentMaterialId = -1,
  5182. _currentGeometryGroupHash = null,
  5183. _currentCamera = null,
  5184. _geometryGroupCounter = 0,
  5185. // GL state cache
  5186. _oldDoubleSided = null,
  5187. _oldFlipSided = null,
  5188. _oldBlending = null,
  5189. _oldBlendEquation = null,
  5190. _oldBlendSrc = null,
  5191. _oldBlendDst = null,
  5192. _oldDepthTest = null,
  5193. _oldDepthWrite = null,
  5194. _oldPolygonOffset = null,
  5195. _oldPolygonOffsetFactor = null,
  5196. _oldPolygonOffsetUnits = null,
  5197. _oldLineWidth = null,
  5198. _viewportX = 0,
  5199. _viewportY = 0,
  5200. _viewportWidth = 0,
  5201. _viewportHeight = 0,
  5202. _currentWidth = 0,
  5203. _currentHeight = 0,
  5204. // frustum
  5205. _frustum = new THREE.Frustum(),
  5206. // camera matrices cache
  5207. _projScreenMatrix = new THREE.Matrix4(),
  5208. _projScreenMatrixPS = new THREE.Matrix4(),
  5209. _vector3 = new THREE.Vector4(),
  5210. // light arrays cache
  5211. _direction = new THREE.Vector3(),
  5212. _lights = {
  5213. ambient: [ 0, 0, 0 ],
  5214. directional: { length: 0, colors: new Array(), positions: new Array() },
  5215. point: { length: 0, colors: new Array(), positions: new Array(), distances: new Array() },
  5216. spot: { length: 0, colors: new Array(), positions: new Array(), distances: new Array(), directions: new Array(), angles: new Array(), exponents: new Array() }
  5217. };
  5218. // initialize
  5219. _gl = initGL();
  5220. setDefaultGLState();
  5221. this.context = _gl;
  5222. // GPU capabilities
  5223. var _maxVertexTextures = _gl.getParameter( _gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ),
  5224. _maxTextureSize = _gl.getParameter( _gl.MAX_TEXTURE_SIZE ),
  5225. _maxCubemapSize = _gl.getParameter( _gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  5226. // API
  5227. this.getContext = function () {
  5228. return _gl;
  5229. };
  5230. this.supportsVertexTextures = function () {
  5231. return _maxVertexTextures > 0;
  5232. };
  5233. this.setSize = function ( width, height ) {
  5234. _canvas.width = width;
  5235. _canvas.height = height;
  5236. this.setViewport( 0, 0, _canvas.width, _canvas.height );
  5237. };
  5238. this.setViewport = function ( x, y, width, height ) {
  5239. _viewportX = x;
  5240. _viewportY = y;
  5241. _viewportWidth = width;
  5242. _viewportHeight = height;
  5243. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  5244. };
  5245. this.setScissor = function ( x, y, width, height ) {
  5246. _gl.scissor( x, y, width, height );
  5247. };
  5248. this.enableScissorTest = function ( enable ) {
  5249. enable ? _gl.enable( _gl.SCISSOR_TEST ) : _gl.disable( _gl.SCISSOR_TEST );
  5250. };
  5251. // Clearing
  5252. this.setClearColorHex = function ( hex, alpha ) {
  5253. _clearColor.setHex( hex );
  5254. _clearAlpha = alpha;
  5255. _gl.clearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  5256. };
  5257. this.setClearColor = function ( color, alpha ) {
  5258. _clearColor.copy( color );
  5259. _clearAlpha = alpha;
  5260. _gl.clearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  5261. };
  5262. this.getClearColor = function () {
  5263. return _clearColor;
  5264. };
  5265. this.getClearAlpha = function () {
  5266. return _clearAlpha;
  5267. };
  5268. this.clear = function ( color, depth, stencil ) {
  5269. var bits = 0;
  5270. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  5271. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  5272. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  5273. _gl.clear( bits );
  5274. };
  5275. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  5276. this.setRenderTarget( renderTarget );
  5277. this.clear( color, depth, stencil );
  5278. };
  5279. // Plugins
  5280. this.addPostPlugin = function ( plugin ) {
  5281. plugin.init( this );
  5282. this.renderPluginsPost.push( plugin );
  5283. };
  5284. this.addPrePlugin = function ( plugin ) {
  5285. plugin.init( this );
  5286. this.renderPluginsPre.push( plugin );
  5287. };
  5288. // Deallocation
  5289. this.deallocateObject = function ( object ) {
  5290. if ( ! object.__webglInit ) return;
  5291. object.__webglInit = false;
  5292. delete object._modelViewMatrix;
  5293. delete object._normalMatrix;
  5294. delete object._normalMatrixArray;
  5295. delete object._modelViewMatrixArray;
  5296. delete object._objectMatrixArray;
  5297. if ( object instanceof THREE.Mesh ) {
  5298. for ( var g in object.geometry.geometryGroups ) {
  5299. deleteMeshBuffers( object.geometry.geometryGroups[ g ] );
  5300. }
  5301. } else if ( object instanceof THREE.Ribbon ) {
  5302. deleteRibbonBuffers( object.geometry );
  5303. } else if ( object instanceof THREE.Line ) {
  5304. deleteLineBuffers( object.geometry );
  5305. } else if ( object instanceof THREE.ParticleSystem ) {
  5306. deleteParticleBuffers( object.geometry );
  5307. }
  5308. };
  5309. this.deallocateTexture = function ( texture ) {
  5310. if ( ! texture.__webglInit ) return;
  5311. texture.__webglInit = false;
  5312. _gl.deleteTexture( texture.__webglTexture );
  5313. _this.info.memory.textures --;
  5314. };
  5315. this.deallocateRenderTarget = function ( renderTarget ) {
  5316. if ( !renderTarget || ! renderTarget.__webglTexture ) return;
  5317. _gl.deleteTexture( renderTarget.__webglTexture );
  5318. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  5319. for ( var i = 0; i < 6; i ++ ) {
  5320. _gl.deleteFramebuffer( renderTarget.__webglFramebuffer[ i ] );
  5321. _gl.deleteRenderbuffer( renderTarget.__webglRenderbuffer[ i ] );
  5322. }
  5323. } else {
  5324. _gl.deleteFramebuffer( renderTarget.__webglFramebuffer );
  5325. _gl.deleteRenderbuffer( renderTarget.__webglRenderbuffer );
  5326. }
  5327. };
  5328. // Rendering
  5329. this.updateShadowMap = function ( scene, camera ) {
  5330. _currentProgram = null;
  5331. _oldBlending = -1;
  5332. _oldDepthTest = -1;
  5333. _oldDepthWrite = -1;
  5334. _currentGeometryGroupHash = -1;
  5335. _currentMaterialId = -1;
  5336. this.shadowMapPlugin.update( scene, camera );
  5337. };
  5338. // Internal functions
  5339. // Buffer allocation
  5340. function createParticleBuffers ( geometry ) {
  5341. geometry.__webglVertexBuffer = _gl.createBuffer();
  5342. geometry.__webglColorBuffer = _gl.createBuffer();
  5343. _this.info.geometries ++;
  5344. };
  5345. function createLineBuffers ( geometry ) {
  5346. geometry.__webglVertexBuffer = _gl.createBuffer();
  5347. geometry.__webglColorBuffer = _gl.createBuffer();
  5348. _this.info.memory.geometries ++;
  5349. };
  5350. function createRibbonBuffers ( geometry ) {
  5351. geometry.__webglVertexBuffer = _gl.createBuffer();
  5352. geometry.__webglColorBuffer = _gl.createBuffer();
  5353. _this.info.memory.geometries ++;
  5354. };
  5355. function createMeshBuffers ( geometryGroup ) {
  5356. geometryGroup.__webglVertexBuffer = _gl.createBuffer();
  5357. geometryGroup.__webglNormalBuffer = _gl.createBuffer();
  5358. geometryGroup.__webglTangentBuffer = _gl.createBuffer();
  5359. geometryGroup.__webglColorBuffer = _gl.createBuffer();
  5360. geometryGroup.__webglUVBuffer = _gl.createBuffer();
  5361. geometryGroup.__webglUV2Buffer = _gl.createBuffer();
  5362. geometryGroup.__webglSkinVertexABuffer = _gl.createBuffer();
  5363. geometryGroup.__webglSkinVertexBBuffer = _gl.createBuffer();
  5364. geometryGroup.__webglSkinIndicesBuffer = _gl.createBuffer();
  5365. geometryGroup.__webglSkinWeightsBuffer = _gl.createBuffer();
  5366. geometryGroup.__webglFaceBuffer = _gl.createBuffer();
  5367. geometryGroup.__webglLineBuffer = _gl.createBuffer();
  5368. var m, ml;
  5369. if ( geometryGroup.numMorphTargets ) {
  5370. geometryGroup.__webglMorphTargetsBuffers = [];
  5371. for ( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m ++ ) {
  5372. geometryGroup.__webglMorphTargetsBuffers.push( _gl.createBuffer() );
  5373. }
  5374. }
  5375. if ( geometryGroup.numMorphNormals ) {
  5376. geometryGroup.__webglMorphNormalsBuffers = [];
  5377. for ( m = 0, ml = geometryGroup.numMorphNormals; m < ml; m ++ ) {
  5378. geometryGroup.__webglMorphNormalsBuffers.push( _gl.createBuffer() );
  5379. }
  5380. }
  5381. _this.info.memory.geometries ++;
  5382. };
  5383. // Buffer deallocation
  5384. function deleteParticleBuffers ( geometry ) {
  5385. _gl.deleteBuffer( geometry.__webglVertexBuffer );
  5386. _gl.deleteBuffer( geometry.__webglColorBuffer );
  5387. _this.info.memory.geometries --;
  5388. };
  5389. function deleteLineBuffers ( geometry ) {
  5390. _gl.deleteBuffer( geometry.__webglVertexBuffer );
  5391. _gl.deleteBuffer( geometry.__webglColorBuffer );
  5392. _this.info.memory.geometries --;
  5393. };
  5394. function deleteRibbonBuffers ( geometry ) {
  5395. _gl.deleteBuffer( geometry.__webglVertexBuffer );
  5396. _gl.deleteBuffer( geometry.__webglColorBuffer );
  5397. _this.info.memory.geometries --;
  5398. };
  5399. function deleteMeshBuffers ( geometryGroup ) {
  5400. _gl.deleteBuffer( geometryGroup.__webglVertexBuffer );
  5401. _gl.deleteBuffer( geometryGroup.__webglNormalBuffer );
  5402. _gl.deleteBuffer( geometryGroup.__webglTangentBuffer );
  5403. _gl.deleteBuffer( geometryGroup.__webglColorBuffer );
  5404. _gl.deleteBuffer( geometryGroup.__webglUVBuffer );
  5405. _gl.deleteBuffer( geometryGroup.__webglUV2Buffer );
  5406. _gl.deleteBuffer( geometryGroup.__webglSkinVertexABuffer );
  5407. _gl.deleteBuffer( geometryGroup.__webglSkinVertexBBuffer );
  5408. _gl.deleteBuffer( geometryGroup.__webglSkinIndicesBuffer );
  5409. _gl.deleteBuffer( geometryGroup.__webglSkinWeightsBuffer );
  5410. _gl.deleteBuffer( geometryGroup.__webglFaceBuffer );
  5411. _gl.deleteBuffer( geometryGroup.__webglLineBuffer );
  5412. var m, ml;
  5413. if ( geometryGroup.numMorphTargets ) {
  5414. for ( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m ++ ) {
  5415. _gl.deleteBuffer( geometryGroup.__webglMorphTargetsBuffers[ m ] );
  5416. }
  5417. }
  5418. if ( geometryGroup.numMorphNormals ) {
  5419. for ( m = 0, ml = geometryGroup.numMorphNormals; m < ml; m ++ ) {
  5420. _gl.deleteBuffer( geometryGroup.__webglMorphNormalsBuffers[ m ] );
  5421. }
  5422. }
  5423. if ( geometryGroup.__webglCustomAttributesList ) {
  5424. for ( var id in geometryGroup.__webglCustomAttributesList ) {
  5425. _gl.deleteBuffer( geometryGroup.__webglCustomAttributesList[ id ].buffer );
  5426. }
  5427. }
  5428. _this.info.memory.geometries --;
  5429. };
  5430. // Buffer initialization
  5431. function initCustomAttributes ( geometry, object ) {
  5432. var nvertices = geometry.vertices.length;
  5433. var material = object.material;
  5434. if ( material.attributes ) {
  5435. if ( geometry.__webglCustomAttributesList === undefined ) {
  5436. geometry.__webglCustomAttributesList = [];
  5437. }
  5438. for ( var a in material.attributes ) {
  5439. var attribute = material.attributes[ a ];
  5440. if( !attribute.__webglInitialized || attribute.createUniqueBuffers ) {
  5441. attribute.__webglInitialized = true;
  5442. var size = 1; // "f" and "i"
  5443. if ( attribute.type === "v2" ) size = 2;
  5444. else if ( attribute.type === "v3" ) size = 3;
  5445. else if ( attribute.type === "v4" ) size = 4;
  5446. else if ( attribute.type === "c" ) size = 3;
  5447. attribute.size = size;
  5448. attribute.array = new Float32Array( nvertices * size );
  5449. attribute.buffer = _gl.createBuffer();
  5450. attribute.buffer.belongsToAttribute = a;
  5451. attribute.needsUpdate = true;
  5452. }
  5453. geometry.__webglCustomAttributesList.push( attribute );
  5454. }
  5455. }
  5456. };
  5457. function initParticleBuffers ( geometry, object ) {
  5458. var nvertices = geometry.vertices.length;
  5459. geometry.__vertexArray = new Float32Array( nvertices * 3 );
  5460. geometry.__colorArray = new Float32Array( nvertices * 3 );
  5461. geometry.__sortArray = [];
  5462. geometry.__webglParticleCount = nvertices;
  5463. initCustomAttributes ( geometry, object );
  5464. };
  5465. function initLineBuffers ( geometry, object ) {
  5466. var nvertices = geometry.vertices.length;
  5467. geometry.__vertexArray = new Float32Array( nvertices * 3 );
  5468. geometry.__colorArray = new Float32Array( nvertices * 3 );
  5469. geometry.__webglLineCount = nvertices;
  5470. initCustomAttributes ( geometry, object );
  5471. };
  5472. function initRibbonBuffers ( geometry ) {
  5473. var nvertices = geometry.vertices.length;
  5474. geometry.__vertexArray = new Float32Array( nvertices * 3 );
  5475. geometry.__colorArray = new Float32Array( nvertices * 3 );
  5476. geometry.__webglVertexCount = nvertices;
  5477. };
  5478. function initMeshBuffers ( geometryGroup, object ) {
  5479. var geometry = object.geometry,
  5480. faces3 = geometryGroup.faces3,
  5481. faces4 = geometryGroup.faces4,
  5482. nvertices = faces3.length * 3 + faces4.length * 4,
  5483. ntris = faces3.length * 1 + faces4.length * 2,
  5484. nlines = faces3.length * 3 + faces4.length * 4,
  5485. material = getBufferMaterial( object, geometryGroup ),
  5486. uvType = bufferGuessUVType( material ),
  5487. normalType = bufferGuessNormalType( material ),
  5488. vertexColorType = bufferGuessVertexColorType( material );
  5489. //console.log( "uvType", uvType, "normalType", normalType, "vertexColorType", vertexColorType, object, geometryGroup, material );
  5490. geometryGroup.__vertexArray = new Float32Array( nvertices * 3 );
  5491. if ( normalType ) {
  5492. geometryGroup.__normalArray = new Float32Array( nvertices * 3 );
  5493. }
  5494. if ( geometry.hasTangents ) {
  5495. geometryGroup.__tangentArray = new Float32Array( nvertices * 4 );
  5496. }
  5497. if ( vertexColorType ) {
  5498. geometryGroup.__colorArray = new Float32Array( nvertices * 3 );
  5499. }
  5500. if ( uvType ) {
  5501. if ( geometry.faceUvs.length > 0 || geometry.faceVertexUvs.length > 0 ) {
  5502. geometryGroup.__uvArray = new Float32Array( nvertices * 2 );
  5503. }
  5504. if ( geometry.faceUvs.length > 1 || geometry.faceVertexUvs.length > 1 ) {
  5505. geometryGroup.__uv2Array = new Float32Array( nvertices * 2 );
  5506. }
  5507. }
  5508. if ( object.geometry.skinWeights.length && object.geometry.skinIndices.length ) {
  5509. geometryGroup.__skinVertexAArray = new Float32Array( nvertices * 4 );
  5510. geometryGroup.__skinVertexBArray = new Float32Array( nvertices * 4 );
  5511. geometryGroup.__skinIndexArray = new Float32Array( nvertices * 4 );
  5512. geometryGroup.__skinWeightArray = new Float32Array( nvertices * 4 );
  5513. }
  5514. geometryGroup.__faceArray = new Uint16Array( ntris * 3 );
  5515. geometryGroup.__lineArray = new Uint16Array( nlines * 2 );
  5516. var m, ml;
  5517. if ( geometryGroup.numMorphTargets ) {
  5518. geometryGroup.__morphTargetsArrays = [];
  5519. for ( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m ++ ) {
  5520. geometryGroup.__morphTargetsArrays.push( new Float32Array( nvertices * 3 ) );
  5521. }
  5522. }
  5523. if ( geometryGroup.numMorphNormals ) {
  5524. geometryGroup.__morphNormalsArrays = [];
  5525. for ( m = 0, ml = geometryGroup.numMorphNormals; m < ml; m ++ ) {
  5526. geometryGroup.__morphNormalsArrays.push( new Float32Array( nvertices * 3 ) );
  5527. }
  5528. }
  5529. geometryGroup.__webglFaceCount = ntris * 3;
  5530. geometryGroup.__webglLineCount = nlines * 2;
  5531. // custom attributes
  5532. if ( material.attributes ) {
  5533. if ( geometryGroup.__webglCustomAttributesList === undefined ) {
  5534. geometryGroup.__webglCustomAttributesList = [];
  5535. }
  5536. for ( var a in material.attributes ) {
  5537. // Do a shallow copy of the attribute object so different geometryGroup chunks use different
  5538. // attribute buffers which are correctly indexed in the setMeshBuffers function
  5539. var originalAttribute = material.attributes[ a ];
  5540. var attribute = {};
  5541. for ( var property in originalAttribute ) {
  5542. attribute[ property ] = originalAttribute[ property ];
  5543. }
  5544. if( !attribute.__webglInitialized || attribute.createUniqueBuffers ) {
  5545. attribute.__webglInitialized = true;
  5546. var size = 1; // "f" and "i"
  5547. if( attribute.type === "v2" ) size = 2;
  5548. else if( attribute.type === "v3" ) size = 3;
  5549. else if( attribute.type === "v4" ) size = 4;
  5550. else if( attribute.type === "c" ) size = 3;
  5551. attribute.size = size;
  5552. attribute.array = new Float32Array( nvertices * size );
  5553. attribute.buffer = _gl.createBuffer();
  5554. attribute.buffer.belongsToAttribute = a;
  5555. originalAttribute.needsUpdate = true;
  5556. attribute.__original = originalAttribute;
  5557. }
  5558. geometryGroup.__webglCustomAttributesList.push( attribute );
  5559. }
  5560. }
  5561. geometryGroup.__inittedArrays = true;
  5562. };
  5563. function getBufferMaterial( object, geometryGroup ) {
  5564. if ( object.material && ! ( object.material instanceof THREE.MeshFaceMaterial ) ) {
  5565. return object.material;
  5566. } else if ( geometryGroup.materialIndex >= 0 ) {
  5567. return object.geometry.materials[ geometryGroup.materialIndex ];
  5568. }
  5569. };
  5570. function materialNeedsSmoothNormals ( material ) {
  5571. return material && material.shading !== undefined && material.shading === THREE.SmoothShading;
  5572. };
  5573. function bufferGuessNormalType ( material ) {
  5574. // only MeshBasicMaterial and MeshDepthMaterial don't need normals
  5575. if ( ( material instanceof THREE.MeshBasicMaterial && !material.envMap ) || material instanceof THREE.MeshDepthMaterial ) {
  5576. return false;
  5577. }
  5578. if ( materialNeedsSmoothNormals( material ) ) {
  5579. return THREE.SmoothShading;
  5580. } else {
  5581. return THREE.FlatShading;
  5582. }
  5583. };
  5584. function bufferGuessVertexColorType ( material ) {
  5585. if ( material.vertexColors ) {
  5586. return material.vertexColors;
  5587. }
  5588. return false;
  5589. };
  5590. function bufferGuessUVType ( material ) {
  5591. // material must use some texture to require uvs
  5592. if ( material.map || material.lightMap || material instanceof THREE.ShaderMaterial ) {
  5593. return true;
  5594. }
  5595. return false;
  5596. };
  5597. // Buffer setting
  5598. function setParticleBuffers ( geometry, hint, object ) {
  5599. var v, c, vertex, offset, index, color,
  5600. vertices = geometry.vertices,
  5601. vl = vertices.length,
  5602. colors = geometry.colors,
  5603. cl = colors.length,
  5604. vertexArray = geometry.__vertexArray,
  5605. colorArray = geometry.__colorArray,
  5606. sortArray = geometry.__sortArray,
  5607. dirtyVertices = geometry.__dirtyVertices,
  5608. dirtyElements = geometry.__dirtyElements,
  5609. dirtyColors = geometry.__dirtyColors,
  5610. customAttributes = geometry.__webglCustomAttributesList,
  5611. i, il,
  5612. a, ca, cal, value,
  5613. customAttribute;
  5614. if ( object.sortParticles ) {
  5615. _projScreenMatrixPS.copy( _projScreenMatrix );
  5616. _projScreenMatrixPS.multiplySelf( object.matrixWorld );
  5617. for ( v = 0; v < vl; v ++ ) {
  5618. vertex = vertices[ v ];
  5619. _vector3.copy( vertex );
  5620. _projScreenMatrixPS.multiplyVector3( _vector3 );
  5621. sortArray[ v ] = [ _vector3.z, v ];
  5622. }
  5623. sortArray.sort( function( a, b ) { return b[ 0 ] - a[ 0 ]; } );
  5624. for ( v = 0; v < vl; v ++ ) {
  5625. vertex = vertices[ sortArray[v][1] ];
  5626. offset = v * 3;
  5627. vertexArray[ offset ] = vertex.x;
  5628. vertexArray[ offset + 1 ] = vertex.y;
  5629. vertexArray[ offset + 2 ] = vertex.z;
  5630. }
  5631. for ( c = 0; c < cl; c ++ ) {
  5632. offset = c * 3;
  5633. color = colors[ sortArray[c][1] ];
  5634. colorArray[ offset ] = color.r;
  5635. colorArray[ offset + 1 ] = color.g;
  5636. colorArray[ offset + 2 ] = color.b;
  5637. }
  5638. if ( customAttributes ) {
  5639. for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
  5640. customAttribute = customAttributes[ i ];
  5641. if ( ! ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) ) continue;
  5642. offset = 0;
  5643. cal = customAttribute.value.length;
  5644. if ( customAttribute.size === 1 ) {
  5645. for ( ca = 0; ca < cal; ca ++ ) {
  5646. index = sortArray[ ca ][ 1 ];
  5647. customAttribute.array[ ca ] = customAttribute.value[ index ];
  5648. }
  5649. } else if ( customAttribute.size === 2 ) {
  5650. for ( ca = 0; ca < cal; ca ++ ) {
  5651. index = sortArray[ ca ][ 1 ];
  5652. value = customAttribute.value[ index ];
  5653. customAttribute.array[ offset ] = value.x;
  5654. customAttribute.array[ offset + 1 ] = value.y;
  5655. offset += 2;
  5656. }
  5657. } else if ( customAttribute.size === 3 ) {
  5658. if ( customAttribute.type === "c" ) {
  5659. for ( ca = 0; ca < cal; ca ++ ) {
  5660. index = sortArray[ ca ][ 1 ];
  5661. value = customAttribute.value[ index ];
  5662. customAttribute.array[ offset ] = value.r;
  5663. customAttribute.array[ offset + 1 ] = value.g;
  5664. customAttribute.array[ offset + 2 ] = value.b;
  5665. offset += 3;
  5666. }
  5667. } else {
  5668. for ( ca = 0; ca < cal; ca ++ ) {
  5669. index = sortArray[ ca ][ 1 ];
  5670. value = customAttribute.value[ index ];
  5671. customAttribute.array[ offset ] = value.x;
  5672. customAttribute.array[ offset + 1 ] = value.y;
  5673. customAttribute.array[ offset + 2 ] = value.z;
  5674. offset += 3;
  5675. }
  5676. }
  5677. } else if ( customAttribute.size === 4 ) {
  5678. for ( ca = 0; ca < cal; ca ++ ) {
  5679. index = sortArray[ ca ][ 1 ];
  5680. value = customAttribute.value[ index ];
  5681. customAttribute.array[ offset ] = value.x;
  5682. customAttribute.array[ offset + 1 ] = value.y;
  5683. customAttribute.array[ offset + 2 ] = value.z;
  5684. customAttribute.array[ offset + 3 ] = value.w;
  5685. offset += 4;
  5686. }
  5687. }
  5688. }
  5689. }
  5690. } else {
  5691. if ( dirtyVertices ) {
  5692. for ( v = 0; v < vl; v ++ ) {
  5693. vertex = vertices[ v ];
  5694. offset = v * 3;
  5695. vertexArray[ offset ] = vertex.x;
  5696. vertexArray[ offset + 1 ] = vertex.y;
  5697. vertexArray[ offset + 2 ] = vertex.z;
  5698. }
  5699. }
  5700. if ( dirtyColors ) {
  5701. for ( c = 0; c < cl; c ++ ) {
  5702. color = colors[ c ];
  5703. offset = c * 3;
  5704. colorArray[ offset ] = color.r;
  5705. colorArray[ offset + 1 ] = color.g;
  5706. colorArray[ offset + 2 ] = color.b;
  5707. }
  5708. }
  5709. if ( customAttributes ) {
  5710. for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
  5711. customAttribute = customAttributes[ i ];
  5712. if ( customAttribute.needsUpdate &&
  5713. ( customAttribute.boundTo === undefined ||
  5714. customAttribute.boundTo === "vertices") ) {
  5715. cal = customAttribute.value.length;
  5716. offset = 0;
  5717. if ( customAttribute.size === 1 ) {
  5718. for ( ca = 0; ca < cal; ca ++ ) {
  5719. customAttribute.array[ ca ] = customAttribute.value[ ca ];
  5720. }
  5721. } else if ( customAttribute.size === 2 ) {
  5722. for ( ca = 0; ca < cal; ca ++ ) {
  5723. value = customAttribute.value[ ca ];
  5724. customAttribute.array[ offset ] = value.x;
  5725. customAttribute.array[ offset + 1 ] = value.y;
  5726. offset += 2;
  5727. }
  5728. } else if ( customAttribute.size === 3 ) {
  5729. if ( customAttribute.type === "c" ) {
  5730. for ( ca = 0; ca < cal; ca ++ ) {
  5731. value = customAttribute.value[ ca ];
  5732. customAttribute.array[ offset ] = value.r;
  5733. customAttribute.array[ offset + 1 ] = value.g;
  5734. customAttribute.array[ offset + 2 ] = value.b;
  5735. offset += 3;
  5736. }
  5737. } else {
  5738. for ( ca = 0; ca < cal; ca ++ ) {
  5739. value = customAttribute.value[ ca ];
  5740. customAttribute.array[ offset ] = value.x;
  5741. customAttribute.array[ offset + 1 ] = value.y;
  5742. customAttribute.array[ offset + 2 ] = value.z;
  5743. offset += 3;
  5744. }
  5745. }
  5746. } else if ( customAttribute.size === 4 ) {
  5747. for ( ca = 0; ca < cal; ca ++ ) {
  5748. value = customAttribute.value[ ca ];
  5749. customAttribute.array[ offset ] = value.x;
  5750. customAttribute.array[ offset + 1 ] = value.y;
  5751. customAttribute.array[ offset + 2 ] = value.z;
  5752. customAttribute.array[ offset + 3 ] = value.w;
  5753. offset += 4;
  5754. }
  5755. }
  5756. }
  5757. }
  5758. }
  5759. }
  5760. if ( dirtyVertices || object.sortParticles ) {
  5761. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglVertexBuffer );
  5762. _gl.bufferData( _gl.ARRAY_BUFFER, vertexArray, hint );
  5763. }
  5764. if ( dirtyColors || object.sortParticles ) {
  5765. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglColorBuffer );
  5766. _gl.bufferData( _gl.ARRAY_BUFFER, colorArray, hint );
  5767. }
  5768. if ( customAttributes ) {
  5769. for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
  5770. customAttribute = customAttributes[ i ];
  5771. if ( customAttribute.needsUpdate || object.sortParticles ) {
  5772. _gl.bindBuffer( _gl.ARRAY_BUFFER, customAttribute.buffer );
  5773. _gl.bufferData( _gl.ARRAY_BUFFER, customAttribute.array, hint );
  5774. }
  5775. }
  5776. }
  5777. };
  5778. function setLineBuffers ( geometry, hint ) {
  5779. var v, c, vertex, offset, color,
  5780. vertices = geometry.vertices,
  5781. colors = geometry.colors,
  5782. vl = vertices.length,
  5783. cl = colors.length,
  5784. vertexArray = geometry.__vertexArray,
  5785. colorArray = geometry.__colorArray,
  5786. dirtyVertices = geometry.__dirtyVertices,
  5787. dirtyColors = geometry.__dirtyColors,
  5788. customAttributes = geometry.__webglCustomAttributesList,
  5789. i, il,
  5790. a, ca, cal, value,
  5791. customAttribute;
  5792. if ( dirtyVertices ) {
  5793. for ( v = 0; v < vl; v ++ ) {
  5794. vertex = vertices[ v ];
  5795. offset = v * 3;
  5796. vertexArray[ offset ] = vertex.x;
  5797. vertexArray[ offset + 1 ] = vertex.y;
  5798. vertexArray[ offset + 2 ] = vertex.z;
  5799. }
  5800. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglVertexBuffer );
  5801. _gl.bufferData( _gl.ARRAY_BUFFER, vertexArray, hint );
  5802. }
  5803. if ( dirtyColors ) {
  5804. for ( c = 0; c < cl; c ++ ) {
  5805. color = colors[ c ];
  5806. offset = c * 3;
  5807. colorArray[ offset ] = color.r;
  5808. colorArray[ offset + 1 ] = color.g;
  5809. colorArray[ offset + 2 ] = color.b;
  5810. }
  5811. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglColorBuffer );
  5812. _gl.bufferData( _gl.ARRAY_BUFFER, colorArray, hint );
  5813. }
  5814. if ( customAttributes ) {
  5815. for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
  5816. customAttribute = customAttributes[ i ];
  5817. if ( customAttribute.needsUpdate &&
  5818. ( customAttribute.boundTo === undefined ||
  5819. customAttribute.boundTo === "vertices" ) ) {
  5820. offset = 0;
  5821. cal = customAttribute.value.length;
  5822. if ( customAttribute.size === 1 ) {
  5823. for ( ca = 0; ca < cal; ca ++ ) {
  5824. customAttribute.array[ ca ] = customAttribute.value[ ca ];
  5825. }
  5826. } else if ( customAttribute.size === 2 ) {
  5827. for ( ca = 0; ca < cal; ca ++ ) {
  5828. value = customAttribute.value[ ca ];
  5829. customAttribute.array[ offset ] = value.x;
  5830. customAttribute.array[ offset + 1 ] = value.y;
  5831. offset += 2;
  5832. }
  5833. } else if ( customAttribute.size === 3 ) {
  5834. if ( customAttribute.type === "c" ) {
  5835. for ( ca = 0; ca < cal; ca ++ ) {
  5836. value = customAttribute.value[ ca ];
  5837. customAttribute.array[ offset ] = value.r;
  5838. customAttribute.array[ offset + 1 ] = value.g;
  5839. customAttribute.array[ offset + 2 ] = value.b;
  5840. offset += 3;
  5841. }
  5842. } else {
  5843. for ( ca = 0; ca < cal; ca ++ ) {
  5844. value = customAttribute.value[ ca ];
  5845. customAttribute.array[ offset ] = value.x;
  5846. customAttribute.array[ offset + 1 ] = value.y;
  5847. customAttribute.array[ offset + 2 ] = value.z;
  5848. offset += 3;
  5849. }
  5850. }
  5851. } else if ( customAttribute.size === 4 ) {
  5852. for ( ca = 0; ca < cal; ca ++ ) {
  5853. value = customAttribute.value[ ca ];
  5854. customAttribute.array[ offset ] = value.x;
  5855. customAttribute.array[ offset + 1 ] = value.y;
  5856. customAttribute.array[ offset + 2 ] = value.z;
  5857. customAttribute.array[ offset + 3 ] = value.w;
  5858. offset += 4;
  5859. }
  5860. }
  5861. _gl.bindBuffer( _gl.ARRAY_BUFFER, customAttribute.buffer );
  5862. _gl.bufferData( _gl.ARRAY_BUFFER, customAttribute.array, hint );
  5863. }
  5864. }
  5865. }
  5866. };
  5867. function setRibbonBuffers ( geometry, hint ) {
  5868. var v, c, vertex, offset, color,
  5869. vertices = geometry.vertices,
  5870. colors = geometry.colors,
  5871. vl = vertices.length,
  5872. cl = colors.length,
  5873. vertexArray = geometry.__vertexArray,
  5874. colorArray = geometry.__colorArray,
  5875. dirtyVertices = geometry.__dirtyVertices,
  5876. dirtyColors = geometry.__dirtyColors;
  5877. if ( dirtyVertices ) {
  5878. for ( v = 0; v < vl; v ++ ) {
  5879. vertex = vertices[ v ];
  5880. offset = v * 3;
  5881. vertexArray[ offset ] = vertex.x;
  5882. vertexArray[ offset + 1 ] = vertex.y;
  5883. vertexArray[ offset + 2 ] = vertex.z;
  5884. }
  5885. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglVertexBuffer );
  5886. _gl.bufferData( _gl.ARRAY_BUFFER, vertexArray, hint );
  5887. }
  5888. if ( dirtyColors ) {
  5889. for ( c = 0; c < cl; c ++ ) {
  5890. color = colors[ c ];
  5891. offset = c * 3;
  5892. colorArray[ offset ] = color.r;
  5893. colorArray[ offset + 1 ] = color.g;
  5894. colorArray[ offset + 2 ] = color.b;
  5895. }
  5896. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglColorBuffer );
  5897. _gl.bufferData( _gl.ARRAY_BUFFER, colorArray, hint );
  5898. }
  5899. };
  5900. function setMeshBuffers( geometryGroup, object, hint, dispose, material ) {
  5901. if ( ! geometryGroup.__inittedArrays ) {
  5902. // console.log( object );
  5903. return;
  5904. }
  5905. var normalType = bufferGuessNormalType( material ),
  5906. vertexColorType = bufferGuessVertexColorType( material ),
  5907. uvType = bufferGuessUVType( material ),
  5908. needsSmoothNormals = ( normalType === THREE.SmoothShading );
  5909. var f, fl, fi, face,
  5910. vertexNormals, faceNormal, normal,
  5911. vertexColors, faceColor,
  5912. vertexTangents,
  5913. uv, uv2, v1, v2, v3, v4, t1, t2, t3, t4, n1, n2, n3, n4,
  5914. c1, c2, c3, c4,
  5915. sw1, sw2, sw3, sw4,
  5916. si1, si2, si3, si4,
  5917. sa1, sa2, sa3, sa4,
  5918. sb1, sb2, sb3, sb4,
  5919. m, ml, i, il,
  5920. vn, uvi, uv2i,
  5921. vk, vkl, vka,
  5922. nka, chf, faceVertexNormals,
  5923. a,
  5924. vertexIndex = 0,
  5925. offset = 0,
  5926. offset_uv = 0,
  5927. offset_uv2 = 0,
  5928. offset_face = 0,
  5929. offset_normal = 0,
  5930. offset_tangent = 0,
  5931. offset_line = 0,
  5932. offset_color = 0,
  5933. offset_skin = 0,
  5934. offset_morphTarget = 0,
  5935. offset_custom = 0,
  5936. offset_customSrc = 0,
  5937. value,
  5938. vertexArray = geometryGroup.__vertexArray,
  5939. uvArray = geometryGroup.__uvArray,
  5940. uv2Array = geometryGroup.__uv2Array,
  5941. normalArray = geometryGroup.__normalArray,
  5942. tangentArray = geometryGroup.__tangentArray,
  5943. colorArray = geometryGroup.__colorArray,
  5944. skinVertexAArray = geometryGroup.__skinVertexAArray,
  5945. skinVertexBArray = geometryGroup.__skinVertexBArray,
  5946. skinIndexArray = geometryGroup.__skinIndexArray,
  5947. skinWeightArray = geometryGroup.__skinWeightArray,
  5948. morphTargetsArrays = geometryGroup.__morphTargetsArrays,
  5949. morphNormalsArrays = geometryGroup.__morphNormalsArrays,
  5950. customAttributes = geometryGroup.__webglCustomAttributesList,
  5951. customAttribute,
  5952. faceArray = geometryGroup.__faceArray,
  5953. lineArray = geometryGroup.__lineArray,
  5954. geometry = object.geometry, // this is shared for all chunks
  5955. dirtyVertices = geometry.__dirtyVertices,
  5956. dirtyElements = geometry.__dirtyElements,
  5957. dirtyUvs = geometry.__dirtyUvs,
  5958. dirtyNormals = geometry.__dirtyNormals,
  5959. dirtyTangents = geometry.__dirtyTangents,
  5960. dirtyColors = geometry.__dirtyColors,
  5961. dirtyMorphTargets = geometry.__dirtyMorphTargets,
  5962. vertices = geometry.vertices,
  5963. chunk_faces3 = geometryGroup.faces3,
  5964. chunk_faces4 = geometryGroup.faces4,
  5965. obj_faces = geometry.faces,
  5966. obj_uvs = geometry.faceVertexUvs[ 0 ],
  5967. obj_uvs2 = geometry.faceVertexUvs[ 1 ],
  5968. obj_colors = geometry.colors,
  5969. obj_skinVerticesA = geometry.skinVerticesA,
  5970. obj_skinVerticesB = geometry.skinVerticesB,
  5971. obj_skinIndices = geometry.skinIndices,
  5972. obj_skinWeights = geometry.skinWeights,
  5973. morphTargets = geometry.morphTargets,
  5974. morphNormals = geometry.morphNormals;
  5975. if ( dirtyVertices ) {
  5976. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  5977. face = obj_faces[ chunk_faces3[ f ] ];
  5978. v1 = vertices[ face.a ];
  5979. v2 = vertices[ face.b ];
  5980. v3 = vertices[ face.c ];
  5981. vertexArray[ offset ] = v1.x;
  5982. vertexArray[ offset + 1 ] = v1.y;
  5983. vertexArray[ offset + 2 ] = v1.z;
  5984. vertexArray[ offset + 3 ] = v2.x;
  5985. vertexArray[ offset + 4 ] = v2.y;
  5986. vertexArray[ offset + 5 ] = v2.z;
  5987. vertexArray[ offset + 6 ] = v3.x;
  5988. vertexArray[ offset + 7 ] = v3.y;
  5989. vertexArray[ offset + 8 ] = v3.z;
  5990. offset += 9;
  5991. }
  5992. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  5993. face = obj_faces[ chunk_faces4[ f ] ];
  5994. v1 = vertices[ face.a ];
  5995. v2 = vertices[ face.b ];
  5996. v3 = vertices[ face.c ];
  5997. v4 = vertices[ face.d ];
  5998. vertexArray[ offset ] = v1.x;
  5999. vertexArray[ offset + 1 ] = v1.y;
  6000. vertexArray[ offset + 2 ] = v1.z;
  6001. vertexArray[ offset + 3 ] = v2.x;
  6002. vertexArray[ offset + 4 ] = v2.y;
  6003. vertexArray[ offset + 5 ] = v2.z;
  6004. vertexArray[ offset + 6 ] = v3.x;
  6005. vertexArray[ offset + 7 ] = v3.y;
  6006. vertexArray[ offset + 8 ] = v3.z;
  6007. vertexArray[ offset + 9 ] = v4.x;
  6008. vertexArray[ offset + 10 ] = v4.y;
  6009. vertexArray[ offset + 11 ] = v4.z;
  6010. offset += 12;
  6011. }
  6012. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglVertexBuffer );
  6013. _gl.bufferData( _gl.ARRAY_BUFFER, vertexArray, hint );
  6014. }
  6015. if ( dirtyMorphTargets ) {
  6016. for ( vk = 0, vkl = morphTargets.length; vk < vkl; vk ++ ) {
  6017. offset_morphTarget = 0;
  6018. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6019. chf = chunk_faces3[ f ];
  6020. face = obj_faces[ chf ];
  6021. // morph positions
  6022. v1 = morphTargets[ vk ].vertices[ face.a ];
  6023. v2 = morphTargets[ vk ].vertices[ face.b ];
  6024. v3 = morphTargets[ vk ].vertices[ face.c ];
  6025. vka = morphTargetsArrays[ vk ];
  6026. vka[ offset_morphTarget ] = v1.x;
  6027. vka[ offset_morphTarget + 1 ] = v1.y;
  6028. vka[ offset_morphTarget + 2 ] = v1.z;
  6029. vka[ offset_morphTarget + 3 ] = v2.x;
  6030. vka[ offset_morphTarget + 4 ] = v2.y;
  6031. vka[ offset_morphTarget + 5 ] = v2.z;
  6032. vka[ offset_morphTarget + 6 ] = v3.x;
  6033. vka[ offset_morphTarget + 7 ] = v3.y;
  6034. vka[ offset_morphTarget + 8 ] = v3.z;
  6035. // morph normals
  6036. if ( material.morphNormals ) {
  6037. if ( needsSmoothNormals ) {
  6038. faceVertexNormals = morphNormals[ vk ].vertexNormals[ chf ];
  6039. n1 = faceVertexNormals.a;
  6040. n2 = faceVertexNormals.b;
  6041. n3 = faceVertexNormals.c;
  6042. } else {
  6043. n1 = morphNormals[ vk ].faceNormals[ chf ];
  6044. n2 = n1;
  6045. n3 = n1;
  6046. }
  6047. nka = morphNormalsArrays[ vk ];
  6048. nka[ offset_morphTarget ] = n1.x;
  6049. nka[ offset_morphTarget + 1 ] = n1.y;
  6050. nka[ offset_morphTarget + 2 ] = n1.z;
  6051. nka[ offset_morphTarget + 3 ] = n2.x;
  6052. nka[ offset_morphTarget + 4 ] = n2.y;
  6053. nka[ offset_morphTarget + 5 ] = n2.z;
  6054. nka[ offset_morphTarget + 6 ] = n3.x;
  6055. nka[ offset_morphTarget + 7 ] = n3.y;
  6056. nka[ offset_morphTarget + 8 ] = n3.z;
  6057. }
  6058. //
  6059. offset_morphTarget += 9;
  6060. }
  6061. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6062. chf = chunk_faces4[ f ];
  6063. face = obj_faces[ chf ];
  6064. // morph positions
  6065. v1 = morphTargets[ vk ].vertices[ face.a ];
  6066. v2 = morphTargets[ vk ].vertices[ face.b ];
  6067. v3 = morphTargets[ vk ].vertices[ face.c ];
  6068. v4 = morphTargets[ vk ].vertices[ face.d ];
  6069. vka = morphTargetsArrays[ vk ];
  6070. vka[ offset_morphTarget ] = v1.x;
  6071. vka[ offset_morphTarget + 1 ] = v1.y;
  6072. vka[ offset_morphTarget + 2 ] = v1.z;
  6073. vka[ offset_morphTarget + 3 ] = v2.x;
  6074. vka[ offset_morphTarget + 4 ] = v2.y;
  6075. vka[ offset_morphTarget + 5 ] = v2.z;
  6076. vka[ offset_morphTarget + 6 ] = v3.x;
  6077. vka[ offset_morphTarget + 7 ] = v3.y;
  6078. vka[ offset_morphTarget + 8 ] = v3.z;
  6079. vka[ offset_morphTarget + 9 ] = v4.x;
  6080. vka[ offset_morphTarget + 10 ] = v4.y;
  6081. vka[ offset_morphTarget + 11 ] = v4.z;
  6082. // morph normals
  6083. if ( material.morphNormals ) {
  6084. if ( needsSmoothNormals ) {
  6085. faceVertexNormals = morphNormals[ vk ].vertexNormals[ chf ];
  6086. n1 = faceVertexNormals.a;
  6087. n2 = faceVertexNormals.b;
  6088. n3 = faceVertexNormals.c;
  6089. n4 = faceVertexNormals.d;
  6090. } else {
  6091. n1 = morphNormals[ vk ].faceNormals[ chf ];
  6092. n2 = n1;
  6093. n3 = n1;
  6094. n4 = n1;
  6095. }
  6096. nka = morphNormalsArrays[ vk ];
  6097. nka[ offset_morphTarget ] = n1.x;
  6098. nka[ offset_morphTarget + 1 ] = n1.y;
  6099. nka[ offset_morphTarget + 2 ] = n1.z;
  6100. nka[ offset_morphTarget + 3 ] = n2.x;
  6101. nka[ offset_morphTarget + 4 ] = n2.y;
  6102. nka[ offset_morphTarget + 5 ] = n2.z;
  6103. nka[ offset_morphTarget + 6 ] = n3.x;
  6104. nka[ offset_morphTarget + 7 ] = n3.y;
  6105. nka[ offset_morphTarget + 8 ] = n3.z;
  6106. nka[ offset_morphTarget + 9 ] = n4.x;
  6107. nka[ offset_morphTarget + 10 ] = n4.y;
  6108. nka[ offset_morphTarget + 11 ] = n4.z;
  6109. }
  6110. //
  6111. offset_morphTarget += 12;
  6112. }
  6113. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ vk ] );
  6114. _gl.bufferData( _gl.ARRAY_BUFFER, morphTargetsArrays[ vk ], hint );
  6115. if ( material.morphNormals ) {
  6116. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphNormalsBuffers[ vk ] );
  6117. _gl.bufferData( _gl.ARRAY_BUFFER, morphNormalsArrays[ vk ], hint );
  6118. }
  6119. }
  6120. }
  6121. if ( obj_skinWeights.length ) {
  6122. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6123. face = obj_faces[ chunk_faces3[ f ] ];
  6124. // weights
  6125. sw1 = obj_skinWeights[ face.a ];
  6126. sw2 = obj_skinWeights[ face.b ];
  6127. sw3 = obj_skinWeights[ face.c ];
  6128. skinWeightArray[ offset_skin ] = sw1.x;
  6129. skinWeightArray[ offset_skin + 1 ] = sw1.y;
  6130. skinWeightArray[ offset_skin + 2 ] = sw1.z;
  6131. skinWeightArray[ offset_skin + 3 ] = sw1.w;
  6132. skinWeightArray[ offset_skin + 4 ] = sw2.x;
  6133. skinWeightArray[ offset_skin + 5 ] = sw2.y;
  6134. skinWeightArray[ offset_skin + 6 ] = sw2.z;
  6135. skinWeightArray[ offset_skin + 7 ] = sw2.w;
  6136. skinWeightArray[ offset_skin + 8 ] = sw3.x;
  6137. skinWeightArray[ offset_skin + 9 ] = sw3.y;
  6138. skinWeightArray[ offset_skin + 10 ] = sw3.z;
  6139. skinWeightArray[ offset_skin + 11 ] = sw3.w;
  6140. // indices
  6141. si1 = obj_skinIndices[ face.a ];
  6142. si2 = obj_skinIndices[ face.b ];
  6143. si3 = obj_skinIndices[ face.c ];
  6144. skinIndexArray[ offset_skin ] = si1.x;
  6145. skinIndexArray[ offset_skin + 1 ] = si1.y;
  6146. skinIndexArray[ offset_skin + 2 ] = si1.z;
  6147. skinIndexArray[ offset_skin + 3 ] = si1.w;
  6148. skinIndexArray[ offset_skin + 4 ] = si2.x;
  6149. skinIndexArray[ offset_skin + 5 ] = si2.y;
  6150. skinIndexArray[ offset_skin + 6 ] = si2.z;
  6151. skinIndexArray[ offset_skin + 7 ] = si2.w;
  6152. skinIndexArray[ offset_skin + 8 ] = si3.x;
  6153. skinIndexArray[ offset_skin + 9 ] = si3.y;
  6154. skinIndexArray[ offset_skin + 10 ] = si3.z;
  6155. skinIndexArray[ offset_skin + 11 ] = si3.w;
  6156. // vertices A
  6157. sa1 = obj_skinVerticesA[ face.a ];
  6158. sa2 = obj_skinVerticesA[ face.b ];
  6159. sa3 = obj_skinVerticesA[ face.c ];
  6160. skinVertexAArray[ offset_skin ] = sa1.x;
  6161. skinVertexAArray[ offset_skin + 1 ] = sa1.y;
  6162. skinVertexAArray[ offset_skin + 2 ] = sa1.z;
  6163. skinVertexAArray[ offset_skin + 3 ] = 1; // pad for faster vertex shader
  6164. skinVertexAArray[ offset_skin + 4 ] = sa2.x;
  6165. skinVertexAArray[ offset_skin + 5 ] = sa2.y;
  6166. skinVertexAArray[ offset_skin + 6 ] = sa2.z;
  6167. skinVertexAArray[ offset_skin + 7 ] = 1;
  6168. skinVertexAArray[ offset_skin + 8 ] = sa3.x;
  6169. skinVertexAArray[ offset_skin + 9 ] = sa3.y;
  6170. skinVertexAArray[ offset_skin + 10 ] = sa3.z;
  6171. skinVertexAArray[ offset_skin + 11 ] = 1;
  6172. // vertices B
  6173. sb1 = obj_skinVerticesB[ face.a ];
  6174. sb2 = obj_skinVerticesB[ face.b ];
  6175. sb3 = obj_skinVerticesB[ face.c ];
  6176. skinVertexBArray[ offset_skin ] = sb1.x;
  6177. skinVertexBArray[ offset_skin + 1 ] = sb1.y;
  6178. skinVertexBArray[ offset_skin + 2 ] = sb1.z;
  6179. skinVertexBArray[ offset_skin + 3 ] = 1; // pad for faster vertex shader
  6180. skinVertexBArray[ offset_skin + 4 ] = sb2.x;
  6181. skinVertexBArray[ offset_skin + 5 ] = sb2.y;
  6182. skinVertexBArray[ offset_skin + 6 ] = sb2.z;
  6183. skinVertexBArray[ offset_skin + 7 ] = 1;
  6184. skinVertexBArray[ offset_skin + 8 ] = sb3.x;
  6185. skinVertexBArray[ offset_skin + 9 ] = sb3.y;
  6186. skinVertexBArray[ offset_skin + 10 ] = sb3.z;
  6187. skinVertexBArray[ offset_skin + 11 ] = 1;
  6188. offset_skin += 12;
  6189. }
  6190. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6191. face = obj_faces[ chunk_faces4[ f ] ];
  6192. // weights
  6193. sw1 = obj_skinWeights[ face.a ];
  6194. sw2 = obj_skinWeights[ face.b ];
  6195. sw3 = obj_skinWeights[ face.c ];
  6196. sw4 = obj_skinWeights[ face.d ];
  6197. skinWeightArray[ offset_skin ] = sw1.x;
  6198. skinWeightArray[ offset_skin + 1 ] = sw1.y;
  6199. skinWeightArray[ offset_skin + 2 ] = sw1.z;
  6200. skinWeightArray[ offset_skin + 3 ] = sw1.w;
  6201. skinWeightArray[ offset_skin + 4 ] = sw2.x;
  6202. skinWeightArray[ offset_skin + 5 ] = sw2.y;
  6203. skinWeightArray[ offset_skin + 6 ] = sw2.z;
  6204. skinWeightArray[ offset_skin + 7 ] = sw2.w;
  6205. skinWeightArray[ offset_skin + 8 ] = sw3.x;
  6206. skinWeightArray[ offset_skin + 9 ] = sw3.y;
  6207. skinWeightArray[ offset_skin + 10 ] = sw3.z;
  6208. skinWeightArray[ offset_skin + 11 ] = sw3.w;
  6209. skinWeightArray[ offset_skin + 12 ] = sw4.x;
  6210. skinWeightArray[ offset_skin + 13 ] = sw4.y;
  6211. skinWeightArray[ offset_skin + 14 ] = sw4.z;
  6212. skinWeightArray[ offset_skin + 15 ] = sw4.w;
  6213. // indices
  6214. si1 = obj_skinIndices[ face.a ];
  6215. si2 = obj_skinIndices[ face.b ];
  6216. si3 = obj_skinIndices[ face.c ];
  6217. si4 = obj_skinIndices[ face.d ];
  6218. skinIndexArray[ offset_skin ] = si1.x;
  6219. skinIndexArray[ offset_skin + 1 ] = si1.y;
  6220. skinIndexArray[ offset_skin + 2 ] = si1.z;
  6221. skinIndexArray[ offset_skin + 3 ] = si1.w;
  6222. skinIndexArray[ offset_skin + 4 ] = si2.x;
  6223. skinIndexArray[ offset_skin + 5 ] = si2.y;
  6224. skinIndexArray[ offset_skin + 6 ] = si2.z;
  6225. skinIndexArray[ offset_skin + 7 ] = si2.w;
  6226. skinIndexArray[ offset_skin + 8 ] = si3.x;
  6227. skinIndexArray[ offset_skin + 9 ] = si3.y;
  6228. skinIndexArray[ offset_skin + 10 ] = si3.z;
  6229. skinIndexArray[ offset_skin + 11 ] = si3.w;
  6230. skinIndexArray[ offset_skin + 12 ] = si4.x;
  6231. skinIndexArray[ offset_skin + 13 ] = si4.y;
  6232. skinIndexArray[ offset_skin + 14 ] = si4.z;
  6233. skinIndexArray[ offset_skin + 15 ] = si4.w;
  6234. // vertices A
  6235. sa1 = obj_skinVerticesA[ face.a ];
  6236. sa2 = obj_skinVerticesA[ face.b ];
  6237. sa3 = obj_skinVerticesA[ face.c ];
  6238. sa4 = obj_skinVerticesA[ face.d ];
  6239. skinVertexAArray[ offset_skin ] = sa1.x;
  6240. skinVertexAArray[ offset_skin + 1 ] = sa1.y;
  6241. skinVertexAArray[ offset_skin + 2 ] = sa1.z;
  6242. skinVertexAArray[ offset_skin + 3 ] = 1; // pad for faster vertex shader
  6243. skinVertexAArray[ offset_skin + 4 ] = sa2.x;
  6244. skinVertexAArray[ offset_skin + 5 ] = sa2.y;
  6245. skinVertexAArray[ offset_skin + 6 ] = sa2.z;
  6246. skinVertexAArray[ offset_skin + 7 ] = 1;
  6247. skinVertexAArray[ offset_skin + 8 ] = sa3.x;
  6248. skinVertexAArray[ offset_skin + 9 ] = sa3.y;
  6249. skinVertexAArray[ offset_skin + 10 ] = sa3.z;
  6250. skinVertexAArray[ offset_skin + 11 ] = 1;
  6251. skinVertexAArray[ offset_skin + 12 ] = sa4.x;
  6252. skinVertexAArray[ offset_skin + 13 ] = sa4.y;
  6253. skinVertexAArray[ offset_skin + 14 ] = sa4.z;
  6254. skinVertexAArray[ offset_skin + 15 ] = 1;
  6255. // vertices B
  6256. sb1 = obj_skinVerticesB[ face.a ];
  6257. sb2 = obj_skinVerticesB[ face.b ];
  6258. sb3 = obj_skinVerticesB[ face.c ];
  6259. sb4 = obj_skinVerticesB[ face.d ];
  6260. skinVertexBArray[ offset_skin ] = sb1.x;
  6261. skinVertexBArray[ offset_skin + 1 ] = sb1.y;
  6262. skinVertexBArray[ offset_skin + 2 ] = sb1.z;
  6263. skinVertexBArray[ offset_skin + 3 ] = 1; // pad for faster vertex shader
  6264. skinVertexBArray[ offset_skin + 4 ] = sb2.x;
  6265. skinVertexBArray[ offset_skin + 5 ] = sb2.y;
  6266. skinVertexBArray[ offset_skin + 6 ] = sb2.z;
  6267. skinVertexBArray[ offset_skin + 7 ] = 1;
  6268. skinVertexBArray[ offset_skin + 8 ] = sb3.x;
  6269. skinVertexBArray[ offset_skin + 9 ] = sb3.y;
  6270. skinVertexBArray[ offset_skin + 10 ] = sb3.z;
  6271. skinVertexBArray[ offset_skin + 11 ] = 1;
  6272. skinVertexBArray[ offset_skin + 12 ] = sb4.x;
  6273. skinVertexBArray[ offset_skin + 13 ] = sb4.y;
  6274. skinVertexBArray[ offset_skin + 14 ] = sb4.z;
  6275. skinVertexBArray[ offset_skin + 15 ] = 1;
  6276. offset_skin += 16;
  6277. }
  6278. if ( offset_skin > 0 ) {
  6279. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinVertexABuffer );
  6280. _gl.bufferData( _gl.ARRAY_BUFFER, skinVertexAArray, hint );
  6281. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinVertexBBuffer );
  6282. _gl.bufferData( _gl.ARRAY_BUFFER, skinVertexBArray, hint );
  6283. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinIndicesBuffer );
  6284. _gl.bufferData( _gl.ARRAY_BUFFER, skinIndexArray, hint );
  6285. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinWeightsBuffer );
  6286. _gl.bufferData( _gl.ARRAY_BUFFER, skinWeightArray, hint );
  6287. }
  6288. }
  6289. if ( dirtyColors && vertexColorType ) {
  6290. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6291. face = obj_faces[ chunk_faces3[ f ] ];
  6292. vertexColors = face.vertexColors;
  6293. faceColor = face.color;
  6294. if ( vertexColors.length === 3 && vertexColorType === THREE.VertexColors ) {
  6295. c1 = vertexColors[ 0 ];
  6296. c2 = vertexColors[ 1 ];
  6297. c3 = vertexColors[ 2 ];
  6298. } else {
  6299. c1 = faceColor;
  6300. c2 = faceColor;
  6301. c3 = faceColor;
  6302. }
  6303. colorArray[ offset_color ] = c1.r;
  6304. colorArray[ offset_color + 1 ] = c1.g;
  6305. colorArray[ offset_color + 2 ] = c1.b;
  6306. colorArray[ offset_color + 3 ] = c2.r;
  6307. colorArray[ offset_color + 4 ] = c2.g;
  6308. colorArray[ offset_color + 5 ] = c2.b;
  6309. colorArray[ offset_color + 6 ] = c3.r;
  6310. colorArray[ offset_color + 7 ] = c3.g;
  6311. colorArray[ offset_color + 8 ] = c3.b;
  6312. offset_color += 9;
  6313. }
  6314. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6315. face = obj_faces[ chunk_faces4[ f ] ];
  6316. vertexColors = face.vertexColors;
  6317. faceColor = face.color;
  6318. if ( vertexColors.length === 4 && vertexColorType === THREE.VertexColors ) {
  6319. c1 = vertexColors[ 0 ];
  6320. c2 = vertexColors[ 1 ];
  6321. c3 = vertexColors[ 2 ];
  6322. c4 = vertexColors[ 3 ];
  6323. } else {
  6324. c1 = faceColor;
  6325. c2 = faceColor;
  6326. c3 = faceColor;
  6327. c4 = faceColor;
  6328. }
  6329. colorArray[ offset_color ] = c1.r;
  6330. colorArray[ offset_color + 1 ] = c1.g;
  6331. colorArray[ offset_color + 2 ] = c1.b;
  6332. colorArray[ offset_color + 3 ] = c2.r;
  6333. colorArray[ offset_color + 4 ] = c2.g;
  6334. colorArray[ offset_color + 5 ] = c2.b;
  6335. colorArray[ offset_color + 6 ] = c3.r;
  6336. colorArray[ offset_color + 7 ] = c3.g;
  6337. colorArray[ offset_color + 8 ] = c3.b;
  6338. colorArray[ offset_color + 9 ] = c4.r;
  6339. colorArray[ offset_color + 10 ] = c4.g;
  6340. colorArray[ offset_color + 11 ] = c4.b;
  6341. offset_color += 12;
  6342. }
  6343. if ( offset_color > 0 ) {
  6344. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglColorBuffer );
  6345. _gl.bufferData( _gl.ARRAY_BUFFER, colorArray, hint );
  6346. }
  6347. }
  6348. if ( dirtyTangents && geometry.hasTangents ) {
  6349. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6350. face = obj_faces[ chunk_faces3[ f ] ];
  6351. vertexTangents = face.vertexTangents;
  6352. t1 = vertexTangents[ 0 ];
  6353. t2 = vertexTangents[ 1 ];
  6354. t3 = vertexTangents[ 2 ];
  6355. tangentArray[ offset_tangent ] = t1.x;
  6356. tangentArray[ offset_tangent + 1 ] = t1.y;
  6357. tangentArray[ offset_tangent + 2 ] = t1.z;
  6358. tangentArray[ offset_tangent + 3 ] = t1.w;
  6359. tangentArray[ offset_tangent + 4 ] = t2.x;
  6360. tangentArray[ offset_tangent + 5 ] = t2.y;
  6361. tangentArray[ offset_tangent + 6 ] = t2.z;
  6362. tangentArray[ offset_tangent + 7 ] = t2.w;
  6363. tangentArray[ offset_tangent + 8 ] = t3.x;
  6364. tangentArray[ offset_tangent + 9 ] = t3.y;
  6365. tangentArray[ offset_tangent + 10 ] = t3.z;
  6366. tangentArray[ offset_tangent + 11 ] = t3.w;
  6367. offset_tangent += 12;
  6368. }
  6369. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6370. face = obj_faces[ chunk_faces4[ f ] ];
  6371. vertexTangents = face.vertexTangents;
  6372. t1 = vertexTangents[ 0 ];
  6373. t2 = vertexTangents[ 1 ];
  6374. t3 = vertexTangents[ 2 ];
  6375. t4 = vertexTangents[ 3 ];
  6376. tangentArray[ offset_tangent ] = t1.x;
  6377. tangentArray[ offset_tangent + 1 ] = t1.y;
  6378. tangentArray[ offset_tangent + 2 ] = t1.z;
  6379. tangentArray[ offset_tangent + 3 ] = t1.w;
  6380. tangentArray[ offset_tangent + 4 ] = t2.x;
  6381. tangentArray[ offset_tangent + 5 ] = t2.y;
  6382. tangentArray[ offset_tangent + 6 ] = t2.z;
  6383. tangentArray[ offset_tangent + 7 ] = t2.w;
  6384. tangentArray[ offset_tangent + 8 ] = t3.x;
  6385. tangentArray[ offset_tangent + 9 ] = t3.y;
  6386. tangentArray[ offset_tangent + 10 ] = t3.z;
  6387. tangentArray[ offset_tangent + 11 ] = t3.w;
  6388. tangentArray[ offset_tangent + 12 ] = t4.x;
  6389. tangentArray[ offset_tangent + 13 ] = t4.y;
  6390. tangentArray[ offset_tangent + 14 ] = t4.z;
  6391. tangentArray[ offset_tangent + 15 ] = t4.w;
  6392. offset_tangent += 16;
  6393. }
  6394. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglTangentBuffer );
  6395. _gl.bufferData( _gl.ARRAY_BUFFER, tangentArray, hint );
  6396. }
  6397. if ( dirtyNormals && normalType ) {
  6398. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6399. face = obj_faces[ chunk_faces3[ f ] ];
  6400. vertexNormals = face.vertexNormals;
  6401. faceNormal = face.normal;
  6402. if ( vertexNormals.length === 3 && needsSmoothNormals ) {
  6403. for ( i = 0; i < 3; i ++ ) {
  6404. vn = vertexNormals[ i ];
  6405. normalArray[ offset_normal ] = vn.x;
  6406. normalArray[ offset_normal + 1 ] = vn.y;
  6407. normalArray[ offset_normal + 2 ] = vn.z;
  6408. offset_normal += 3;
  6409. }
  6410. } else {
  6411. for ( i = 0; i < 3; i ++ ) {
  6412. normalArray[ offset_normal ] = faceNormal.x;
  6413. normalArray[ offset_normal + 1 ] = faceNormal.y;
  6414. normalArray[ offset_normal + 2 ] = faceNormal.z;
  6415. offset_normal += 3;
  6416. }
  6417. }
  6418. }
  6419. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6420. face = obj_faces[ chunk_faces4[ f ] ];
  6421. vertexNormals = face.vertexNormals;
  6422. faceNormal = face.normal;
  6423. if ( vertexNormals.length === 4 && needsSmoothNormals ) {
  6424. for ( i = 0; i < 4; i ++ ) {
  6425. vn = vertexNormals[ i ];
  6426. normalArray[ offset_normal ] = vn.x;
  6427. normalArray[ offset_normal + 1 ] = vn.y;
  6428. normalArray[ offset_normal + 2 ] = vn.z;
  6429. offset_normal += 3;
  6430. }
  6431. } else {
  6432. for ( i = 0; i < 4; i ++ ) {
  6433. normalArray[ offset_normal ] = faceNormal.x;
  6434. normalArray[ offset_normal + 1 ] = faceNormal.y;
  6435. normalArray[ offset_normal + 2 ] = faceNormal.z;
  6436. offset_normal += 3;
  6437. }
  6438. }
  6439. }
  6440. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglNormalBuffer );
  6441. _gl.bufferData( _gl.ARRAY_BUFFER, normalArray, hint );
  6442. }
  6443. if ( dirtyUvs && obj_uvs && uvType ) {
  6444. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6445. fi = chunk_faces3[ f ];
  6446. face = obj_faces[ fi ];
  6447. uv = obj_uvs[ fi ];
  6448. if ( uv === undefined ) continue;
  6449. for ( i = 0; i < 3; i ++ ) {
  6450. uvi = uv[ i ];
  6451. uvArray[ offset_uv ] = uvi.u;
  6452. uvArray[ offset_uv + 1 ] = uvi.v;
  6453. offset_uv += 2;
  6454. }
  6455. }
  6456. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6457. fi = chunk_faces4[ f ];
  6458. face = obj_faces[ fi ];
  6459. uv = obj_uvs[ fi ];
  6460. if ( uv === undefined ) continue;
  6461. for ( i = 0; i < 4; i ++ ) {
  6462. uvi = uv[ i ];
  6463. uvArray[ offset_uv ] = uvi.u;
  6464. uvArray[ offset_uv + 1 ] = uvi.v;
  6465. offset_uv += 2;
  6466. }
  6467. }
  6468. if ( offset_uv > 0 ) {
  6469. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglUVBuffer );
  6470. _gl.bufferData( _gl.ARRAY_BUFFER, uvArray, hint );
  6471. }
  6472. }
  6473. if ( dirtyUvs && obj_uvs2 && uvType ) {
  6474. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6475. fi = chunk_faces3[ f ];
  6476. face = obj_faces[ fi ];
  6477. uv2 = obj_uvs2[ fi ];
  6478. if ( uv2 === undefined ) continue;
  6479. for ( i = 0; i < 3; i ++ ) {
  6480. uv2i = uv2[ i ];
  6481. uv2Array[ offset_uv2 ] = uv2i.u;
  6482. uv2Array[ offset_uv2 + 1 ] = uv2i.v;
  6483. offset_uv2 += 2;
  6484. }
  6485. }
  6486. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6487. fi = chunk_faces4[ f ];
  6488. face = obj_faces[ fi ];
  6489. uv2 = obj_uvs2[ fi ];
  6490. if ( uv2 === undefined ) continue;
  6491. for ( i = 0; i < 4; i ++ ) {
  6492. uv2i = uv2[ i ];
  6493. uv2Array[ offset_uv2 ] = uv2i.u;
  6494. uv2Array[ offset_uv2 + 1 ] = uv2i.v;
  6495. offset_uv2 += 2;
  6496. }
  6497. }
  6498. if ( offset_uv2 > 0 ) {
  6499. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglUV2Buffer );
  6500. _gl.bufferData( _gl.ARRAY_BUFFER, uv2Array, hint );
  6501. }
  6502. }
  6503. if ( dirtyElements ) {
  6504. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6505. face = obj_faces[ chunk_faces3[ f ] ];
  6506. faceArray[ offset_face ] = vertexIndex;
  6507. faceArray[ offset_face + 1 ] = vertexIndex + 1;
  6508. faceArray[ offset_face + 2 ] = vertexIndex + 2;
  6509. offset_face += 3;
  6510. lineArray[ offset_line ] = vertexIndex;
  6511. lineArray[ offset_line + 1 ] = vertexIndex + 1;
  6512. lineArray[ offset_line + 2 ] = vertexIndex;
  6513. lineArray[ offset_line + 3 ] = vertexIndex + 2;
  6514. lineArray[ offset_line + 4 ] = vertexIndex + 1;
  6515. lineArray[ offset_line + 5 ] = vertexIndex + 2;
  6516. offset_line += 6;
  6517. vertexIndex += 3;
  6518. }
  6519. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6520. face = obj_faces[ chunk_faces4[ f ] ];
  6521. faceArray[ offset_face ] = vertexIndex;
  6522. faceArray[ offset_face + 1 ] = vertexIndex + 1;
  6523. faceArray[ offset_face + 2 ] = vertexIndex + 3;
  6524. faceArray[ offset_face + 3 ] = vertexIndex + 1;
  6525. faceArray[ offset_face + 4 ] = vertexIndex + 2;
  6526. faceArray[ offset_face + 5 ] = vertexIndex + 3;
  6527. offset_face += 6;
  6528. lineArray[ offset_line ] = vertexIndex;
  6529. lineArray[ offset_line + 1 ] = vertexIndex + 1;
  6530. lineArray[ offset_line + 2 ] = vertexIndex;
  6531. lineArray[ offset_line + 3 ] = vertexIndex + 3;
  6532. lineArray[ offset_line + 4 ] = vertexIndex + 1;
  6533. lineArray[ offset_line + 5 ] = vertexIndex + 2;
  6534. lineArray[ offset_line + 6 ] = vertexIndex + 2;
  6535. lineArray[ offset_line + 7 ] = vertexIndex + 3;
  6536. offset_line += 8;
  6537. vertexIndex += 4;
  6538. }
  6539. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryGroup.__webglFaceBuffer );
  6540. _gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, faceArray, hint );
  6541. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryGroup.__webglLineBuffer );
  6542. _gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, lineArray, hint );
  6543. }
  6544. if ( customAttributes ) {
  6545. for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
  6546. customAttribute = customAttributes[ i ];
  6547. if ( ! customAttribute.__original.needsUpdate ) continue;
  6548. offset_custom = 0;
  6549. offset_customSrc = 0;
  6550. if ( customAttribute.size === 1 ) {
  6551. if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
  6552. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6553. face = obj_faces[ chunk_faces3[ f ] ];
  6554. customAttribute.array[ offset_custom ] = customAttribute.value[ face.a ];
  6555. customAttribute.array[ offset_custom + 1 ] = customAttribute.value[ face.b ];
  6556. customAttribute.array[ offset_custom + 2 ] = customAttribute.value[ face.c ];
  6557. offset_custom += 3;
  6558. }
  6559. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6560. face = obj_faces[ chunk_faces4[ f ] ];
  6561. customAttribute.array[ offset_custom ] = customAttribute.value[ face.a ];
  6562. customAttribute.array[ offset_custom + 1 ] = customAttribute.value[ face.b ];
  6563. customAttribute.array[ offset_custom + 2 ] = customAttribute.value[ face.c ];
  6564. customAttribute.array[ offset_custom + 3 ] = customAttribute.value[ face.d ];
  6565. offset_custom += 4;
  6566. }
  6567. } else if ( customAttribute.boundTo === "faces" ) {
  6568. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6569. value = customAttribute.value[ chunk_faces3[ f ] ];
  6570. customAttribute.array[ offset_custom ] = value;
  6571. customAttribute.array[ offset_custom + 1 ] = value;
  6572. customAttribute.array[ offset_custom + 2 ] = value;
  6573. offset_custom += 3;
  6574. }
  6575. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6576. value = customAttribute.value[ chunk_faces4[ f ] ];
  6577. customAttribute.array[ offset_custom ] = value;
  6578. customAttribute.array[ offset_custom + 1 ] = value;
  6579. customAttribute.array[ offset_custom + 2 ] = value;
  6580. customAttribute.array[ offset_custom + 3 ] = value;
  6581. offset_custom += 4;
  6582. }
  6583. }
  6584. } else if ( customAttribute.size === 2 ) {
  6585. if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
  6586. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6587. face = obj_faces[ chunk_faces3[ f ] ];
  6588. v1 = customAttribute.value[ face.a ];
  6589. v2 = customAttribute.value[ face.b ];
  6590. v3 = customAttribute.value[ face.c ];
  6591. customAttribute.array[ offset_custom ] = v1.x;
  6592. customAttribute.array[ offset_custom + 1 ] = v1.y;
  6593. customAttribute.array[ offset_custom + 2 ] = v2.x;
  6594. customAttribute.array[ offset_custom + 3 ] = v2.y;
  6595. customAttribute.array[ offset_custom + 4 ] = v3.x;
  6596. customAttribute.array[ offset_custom + 5 ] = v3.y;
  6597. offset_custom += 6;
  6598. }
  6599. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6600. face = obj_faces[ chunk_faces4[ f ] ];
  6601. v1 = customAttribute.value[ face.a ];
  6602. v2 = customAttribute.value[ face.b ];
  6603. v3 = customAttribute.value[ face.c ];
  6604. v4 = customAttribute.value[ face.d ];
  6605. customAttribute.array[ offset_custom ] = v1.x;
  6606. customAttribute.array[ offset_custom + 1 ] = v1.y;
  6607. customAttribute.array[ offset_custom + 2 ] = v2.x;
  6608. customAttribute.array[ offset_custom + 3 ] = v2.y;
  6609. customAttribute.array[ offset_custom + 4 ] = v3.x;
  6610. customAttribute.array[ offset_custom + 5 ] = v3.y;
  6611. customAttribute.array[ offset_custom + 6 ] = v4.x;
  6612. customAttribute.array[ offset_custom + 7 ] = v4.y;
  6613. offset_custom += 8;
  6614. }
  6615. } else if ( customAttribute.boundTo === "faces" ) {
  6616. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6617. value = customAttribute.value[ chunk_faces3[ f ] ];
  6618. v1 = value;
  6619. v2 = value;
  6620. v3 = value;
  6621. customAttribute.array[ offset_custom ] = v1.x;
  6622. customAttribute.array[ offset_custom + 1 ] = v1.y;
  6623. customAttribute.array[ offset_custom + 2 ] = v2.x;
  6624. customAttribute.array[ offset_custom + 3 ] = v2.y;
  6625. customAttribute.array[ offset_custom + 4 ] = v3.x;
  6626. customAttribute.array[ offset_custom + 5 ] = v3.y;
  6627. offset_custom += 6;
  6628. }
  6629. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6630. value = customAttribute.value[ chunk_faces4[ f ] ];
  6631. v1 = value;
  6632. v2 = value;
  6633. v3 = value;
  6634. v4 = value;
  6635. customAttribute.array[ offset_custom ] = v1.x;
  6636. customAttribute.array[ offset_custom + 1 ] = v1.y;
  6637. customAttribute.array[ offset_custom + 2 ] = v2.x;
  6638. customAttribute.array[ offset_custom + 3 ] = v2.y;
  6639. customAttribute.array[ offset_custom + 4 ] = v3.x;
  6640. customAttribute.array[ offset_custom + 5 ] = v3.y;
  6641. customAttribute.array[ offset_custom + 6 ] = v4.x;
  6642. customAttribute.array[ offset_custom + 7 ] = v4.y;
  6643. offset_custom += 8;
  6644. }
  6645. }
  6646. } else if ( customAttribute.size === 3 ) {
  6647. var pp;
  6648. if ( customAttribute.type === "c" ) {
  6649. pp = [ "r", "g", "b" ];
  6650. } else {
  6651. pp = [ "x", "y", "z" ];
  6652. }
  6653. if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
  6654. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6655. face = obj_faces[ chunk_faces3[ f ] ];
  6656. v1 = customAttribute.value[ face.a ];
  6657. v2 = customAttribute.value[ face.b ];
  6658. v3 = customAttribute.value[ face.c ];
  6659. customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
  6660. customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
  6661. customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
  6662. customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
  6663. customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
  6664. customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
  6665. customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
  6666. customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
  6667. customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
  6668. offset_custom += 9;
  6669. }
  6670. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6671. face = obj_faces[ chunk_faces4[ f ] ];
  6672. v1 = customAttribute.value[ face.a ];
  6673. v2 = customAttribute.value[ face.b ];
  6674. v3 = customAttribute.value[ face.c ];
  6675. v4 = customAttribute.value[ face.d ];
  6676. customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
  6677. customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
  6678. customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
  6679. customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
  6680. customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
  6681. customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
  6682. customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
  6683. customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
  6684. customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
  6685. customAttribute.array[ offset_custom + 9 ] = v4[ pp[ 0 ] ];
  6686. customAttribute.array[ offset_custom + 10 ] = v4[ pp[ 1 ] ];
  6687. customAttribute.array[ offset_custom + 11 ] = v4[ pp[ 2 ] ];
  6688. offset_custom += 12;
  6689. }
  6690. } else if ( customAttribute.boundTo === "faces" ) {
  6691. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6692. value = customAttribute.value[ chunk_faces3[ f ] ];
  6693. v1 = value;
  6694. v2 = value;
  6695. v3 = value;
  6696. customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
  6697. customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
  6698. customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
  6699. customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
  6700. customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
  6701. customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
  6702. customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
  6703. customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
  6704. customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
  6705. offset_custom += 9;
  6706. }
  6707. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6708. value = customAttribute.value[ chunk_faces4[ f ] ];
  6709. v1 = value;
  6710. v2 = value;
  6711. v3 = value;
  6712. v4 = value;
  6713. customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
  6714. customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
  6715. customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
  6716. customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
  6717. customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
  6718. customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
  6719. customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
  6720. customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
  6721. customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
  6722. customAttribute.array[ offset_custom + 9 ] = v4[ pp[ 0 ] ];
  6723. customAttribute.array[ offset_custom + 10 ] = v4[ pp[ 1 ] ];
  6724. customAttribute.array[ offset_custom + 11 ] = v4[ pp[ 2 ] ];
  6725. offset_custom += 12;
  6726. }
  6727. }
  6728. } else if ( customAttribute.size === 4 ) {
  6729. if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
  6730. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6731. face = obj_faces[ chunk_faces3[ f ] ];
  6732. v1 = customAttribute.value[ face.a ];
  6733. v2 = customAttribute.value[ face.b ];
  6734. v3 = customAttribute.value[ face.c ];
  6735. customAttribute.array[ offset_custom ] = v1.x;
  6736. customAttribute.array[ offset_custom + 1 ] = v1.y;
  6737. customAttribute.array[ offset_custom + 2 ] = v1.z;
  6738. customAttribute.array[ offset_custom + 3 ] = v1.w;
  6739. customAttribute.array[ offset_custom + 4 ] = v2.x;
  6740. customAttribute.array[ offset_custom + 5 ] = v2.y;
  6741. customAttribute.array[ offset_custom + 6 ] = v2.z;
  6742. customAttribute.array[ offset_custom + 7 ] = v2.w;
  6743. customAttribute.array[ offset_custom + 8 ] = v3.x;
  6744. customAttribute.array[ offset_custom + 9 ] = v3.y;
  6745. customAttribute.array[ offset_custom + 10 ] = v3.z;
  6746. customAttribute.array[ offset_custom + 11 ] = v3.w;
  6747. offset_custom += 12;
  6748. }
  6749. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6750. face = obj_faces[ chunk_faces4[ f ] ];
  6751. v1 = customAttribute.value[ face.a ];
  6752. v2 = customAttribute.value[ face.b ];
  6753. v3 = customAttribute.value[ face.c ];
  6754. v4 = customAttribute.value[ face.d ];
  6755. customAttribute.array[ offset_custom ] = v1.x;
  6756. customAttribute.array[ offset_custom + 1 ] = v1.y;
  6757. customAttribute.array[ offset_custom + 2 ] = v1.z;
  6758. customAttribute.array[ offset_custom + 3 ] = v1.w;
  6759. customAttribute.array[ offset_custom + 4 ] = v2.x;
  6760. customAttribute.array[ offset_custom + 5 ] = v2.y;
  6761. customAttribute.array[ offset_custom + 6 ] = v2.z;
  6762. customAttribute.array[ offset_custom + 7 ] = v2.w;
  6763. customAttribute.array[ offset_custom + 8 ] = v3.x;
  6764. customAttribute.array[ offset_custom + 9 ] = v3.y;
  6765. customAttribute.array[ offset_custom + 10 ] = v3.z;
  6766. customAttribute.array[ offset_custom + 11 ] = v3.w;
  6767. customAttribute.array[ offset_custom + 12 ] = v4.x;
  6768. customAttribute.array[ offset_custom + 13 ] = v4.y;
  6769. customAttribute.array[ offset_custom + 14 ] = v4.z;
  6770. customAttribute.array[ offset_custom + 15 ] = v4.w;
  6771. offset_custom += 16;
  6772. }
  6773. } else if ( customAttribute.boundTo === "faces" ) {
  6774. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  6775. value = customAttribute.value[ chunk_faces3[ f ] ];
  6776. v1 = value;
  6777. v2 = value;
  6778. v3 = value;
  6779. customAttribute.array[ offset_custom ] = v1.x;
  6780. customAttribute.array[ offset_custom + 1 ] = v1.y;
  6781. customAttribute.array[ offset_custom + 2 ] = v1.z;
  6782. customAttribute.array[ offset_custom + 3 ] = v1.w;
  6783. customAttribute.array[ offset_custom + 4 ] = v2.x;
  6784. customAttribute.array[ offset_custom + 5 ] = v2.y;
  6785. customAttribute.array[ offset_custom + 6 ] = v2.z;
  6786. customAttribute.array[ offset_custom + 7 ] = v2.w;
  6787. customAttribute.array[ offset_custom + 8 ] = v3.x;
  6788. customAttribute.array[ offset_custom + 9 ] = v3.y;
  6789. customAttribute.array[ offset_custom + 10 ] = v3.z;
  6790. customAttribute.array[ offset_custom + 11 ] = v3.w;
  6791. offset_custom += 12;
  6792. }
  6793. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  6794. value = customAttribute.value[ chunk_faces4[ f ] ];
  6795. v1 = value;
  6796. v2 = value;
  6797. v3 = value;
  6798. v4 = value;
  6799. customAttribute.array[ offset_custom ] = v1.x;
  6800. customAttribute.array[ offset_custom + 1 ] = v1.y;
  6801. customAttribute.array[ offset_custom + 2 ] = v1.z;
  6802. customAttribute.array[ offset_custom + 3 ] = v1.w;
  6803. customAttribute.array[ offset_custom + 4 ] = v2.x;
  6804. customAttribute.array[ offset_custom + 5 ] = v2.y;
  6805. customAttribute.array[ offset_custom + 6 ] = v2.z;
  6806. customAttribute.array[ offset_custom + 7 ] = v2.w;
  6807. customAttribute.array[ offset_custom + 8 ] = v3.x;
  6808. customAttribute.array[ offset_custom + 9 ] = v3.y;
  6809. customAttribute.array[ offset_custom + 10 ] = v3.z;
  6810. customAttribute.array[ offset_custom + 11 ] = v3.w;
  6811. customAttribute.array[ offset_custom + 12 ] = v4.x;
  6812. customAttribute.array[ offset_custom + 13 ] = v4.y;
  6813. customAttribute.array[ offset_custom + 14 ] = v4.z;
  6814. customAttribute.array[ offset_custom + 15 ] = v4.w;
  6815. offset_custom += 16;
  6816. }
  6817. }
  6818. }
  6819. _gl.bindBuffer( _gl.ARRAY_BUFFER, customAttribute.buffer );
  6820. _gl.bufferData( _gl.ARRAY_BUFFER, customAttribute.array, hint );
  6821. }
  6822. }
  6823. if ( dispose ) {
  6824. delete geometryGroup.__inittedArrays;
  6825. delete geometryGroup.__colorArray;
  6826. delete geometryGroup.__normalArray;
  6827. delete geometryGroup.__tangentArray;
  6828. delete geometryGroup.__uvArray;
  6829. delete geometryGroup.__uv2Array;
  6830. delete geometryGroup.__faceArray;
  6831. delete geometryGroup.__vertexArray;
  6832. delete geometryGroup.__lineArray;
  6833. delete geometryGroup.__skinVertexAArray;
  6834. delete geometryGroup.__skinVertexBArray;
  6835. delete geometryGroup.__skinIndexArray;
  6836. delete geometryGroup.__skinWeightArray;
  6837. }
  6838. };
  6839. // Buffer rendering
  6840. this.renderBufferImmediate = function ( object, program, shading ) {
  6841. if ( ! object.__webglVertexBuffer ) object.__webglVertexBuffer = _gl.createBuffer();
  6842. if ( ! object.__webglNormalBuffer ) object.__webglNormalBuffer = _gl.createBuffer();
  6843. if ( object.hasPos ) {
  6844. _gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglVertexBuffer );
  6845. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  6846. _gl.enableVertexAttribArray( program.attributes.position );
  6847. _gl.vertexAttribPointer( program.attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  6848. }
  6849. if ( object.hasNormal ) {
  6850. _gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglNormalBuffer );
  6851. if ( shading === THREE.FlatShading ) {
  6852. var nx, ny, nz,
  6853. nax, nbx, ncx, nay, nby, ncy, naz, nbz, ncz,
  6854. normalArray,
  6855. i, il = object.count * 3;
  6856. for( i = 0; i < il; i += 9 ) {
  6857. normalArray = object.normalArray;
  6858. nax = normalArray[ i ];
  6859. nay = normalArray[ i + 1 ];
  6860. naz = normalArray[ i + 2 ];
  6861. nbx = normalArray[ i + 3 ];
  6862. nby = normalArray[ i + 4 ];
  6863. nbz = normalArray[ i + 5 ];
  6864. ncx = normalArray[ i + 6 ];
  6865. ncy = normalArray[ i + 7 ];
  6866. ncz = normalArray[ i + 8 ];
  6867. nx = ( nax + nbx + ncx ) / 3;
  6868. ny = ( nay + nby + ncy ) / 3;
  6869. nz = ( naz + nbz + ncz ) / 3;
  6870. normalArray[ i ] = nx;
  6871. normalArray[ i + 1 ] = ny;
  6872. normalArray[ i + 2 ] = nz;
  6873. normalArray[ i + 3 ] = nx;
  6874. normalArray[ i + 4 ] = ny;
  6875. normalArray[ i + 5 ] = nz;
  6876. normalArray[ i + 6 ] = nx;
  6877. normalArray[ i + 7 ] = ny;
  6878. normalArray[ i + 8 ] = nz;
  6879. }
  6880. }
  6881. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  6882. _gl.enableVertexAttribArray( program.attributes.normal );
  6883. _gl.vertexAttribPointer( program.attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  6884. }
  6885. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  6886. object.count = 0;
  6887. };
  6888. this.renderBufferDirect = function ( camera, lights, fog, material, geometryGroup, object ) {
  6889. if ( material.opacity === 0 ) return;
  6890. var program, attributes, linewidth, primitives, a, attribute;
  6891. program = setProgram( camera, lights, fog, material, object );
  6892. attributes = program.attributes;
  6893. var updateBuffers = false,
  6894. wireframeBit = material.wireframe ? 1 : 0,
  6895. geometryGroupHash = ( geometryGroup.id * 0xffffff ) + ( program.id * 2 ) + wireframeBit;
  6896. if ( geometryGroupHash !== _currentGeometryGroupHash ) {
  6897. _currentGeometryGroupHash = geometryGroupHash;
  6898. updateBuffers = true;
  6899. }
  6900. // render mesh
  6901. if ( object instanceof THREE.Mesh ) {
  6902. var offsets = geometryGroup.offsets;
  6903. for ( var i = 0, il = offsets.length; i < il; ++ i ) {
  6904. if ( updateBuffers ) {
  6905. // vertices
  6906. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.vertexPositionBuffer );
  6907. _gl.vertexAttribPointer( attributes.position, geometryGroup.vertexPositionBuffer.itemSize, _gl.FLOAT, false, 0, offsets[ i ].index * 4 * 3 );
  6908. // normals
  6909. if ( attributes.normal >= 0 && geometryGroup.vertexNormalBuffer ) {
  6910. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.vertexNormalBuffer );
  6911. _gl.vertexAttribPointer( attributes.normal, geometryGroup.vertexNormalBuffer.itemSize, _gl.FLOAT, false, 0, offsets[ i ].index * 4 * 3 );
  6912. }
  6913. // uvs
  6914. if ( attributes.uv >= 0 && geometryGroup.vertexUvBuffer ) {
  6915. if ( geometryGroup.vertexUvBuffer ) {
  6916. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.vertexUvBuffer );
  6917. _gl.vertexAttribPointer( attributes.uv, geometryGroup.vertexUvBuffer.itemSize, _gl.FLOAT, false, 0, offsets[ i ].index * 4 * 2 );
  6918. _gl.enableVertexAttribArray( attributes.uv );
  6919. } else {
  6920. _gl.disableVertexAttribArray( attributes.uv );
  6921. }
  6922. }
  6923. // colors
  6924. if ( attributes.color >= 0 && geometryGroup.vertexColorBuffer ) {
  6925. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.vertexColorBuffer );
  6926. _gl.vertexAttribPointer( attributes.color, geometryGroup.vertexColorBuffer.itemSize, _gl.FLOAT, false, 0, offsets[ i ].index * 4 * 4 );
  6927. }
  6928. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryGroup.vertexIndexBuffer );
  6929. }
  6930. // render indexed triangles
  6931. _gl.drawElements( _gl.TRIANGLES, offsets[ i ].count, _gl.UNSIGNED_SHORT, offsets[ i ].start * 2 ); // 2 = Uint16
  6932. _this.info.render.calls ++;
  6933. _this.info.render.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  6934. _this.info.render.faces += offsets[ i ].count / 3;
  6935. }
  6936. }
  6937. };
  6938. this.renderBuffer = function ( camera, lights, fog, material, geometryGroup, object ) {
  6939. if ( material.opacity === 0 ) return;
  6940. var program, attributes, linewidth, primitives, a, attribute, i, il;
  6941. program = setProgram( camera, lights, fog, material, object );
  6942. attributes = program.attributes;
  6943. var updateBuffers = false,
  6944. wireframeBit = material.wireframe ? 1 : 0,
  6945. geometryGroupHash = ( geometryGroup.id * 0xffffff ) + ( program.id * 2 ) + wireframeBit;
  6946. if ( geometryGroupHash !== _currentGeometryGroupHash ) {
  6947. _currentGeometryGroupHash = geometryGroupHash;
  6948. updateBuffers = true;
  6949. }
  6950. // vertices
  6951. if ( !material.morphTargets && attributes.position >= 0 ) {
  6952. if ( updateBuffers ) {
  6953. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglVertexBuffer );
  6954. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  6955. }
  6956. } else {
  6957. if ( object.morphTargetBase ) {
  6958. setupMorphTargets( material, geometryGroup, object );
  6959. }
  6960. }
  6961. if ( updateBuffers ) {
  6962. // custom attributes
  6963. // Use the per-geometryGroup custom attribute arrays which are setup in initMeshBuffers
  6964. if ( geometryGroup.__webglCustomAttributesList ) {
  6965. for ( i = 0, il = geometryGroup.__webglCustomAttributesList.length; i < il; i ++ ) {
  6966. attribute = geometryGroup.__webglCustomAttributesList[ i ];
  6967. if( attributes[ attribute.buffer.belongsToAttribute ] >= 0 ) {
  6968. _gl.bindBuffer( _gl.ARRAY_BUFFER, attribute.buffer );
  6969. _gl.vertexAttribPointer( attributes[ attribute.buffer.belongsToAttribute ], attribute.size, _gl.FLOAT, false, 0, 0 );
  6970. }
  6971. }
  6972. }
  6973. // colors
  6974. if ( attributes.color >= 0 ) {
  6975. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglColorBuffer );
  6976. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  6977. }
  6978. // normals
  6979. if ( attributes.normal >= 0 ) {
  6980. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglNormalBuffer );
  6981. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  6982. }
  6983. // tangents
  6984. if ( attributes.tangent >= 0 ) {
  6985. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglTangentBuffer );
  6986. _gl.vertexAttribPointer( attributes.tangent, 4, _gl.FLOAT, false, 0, 0 );
  6987. }
  6988. // uvs
  6989. if ( attributes.uv >= 0 ) {
  6990. if ( geometryGroup.__webglUVBuffer ) {
  6991. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglUVBuffer );
  6992. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  6993. _gl.enableVertexAttribArray( attributes.uv );
  6994. } else {
  6995. _gl.disableVertexAttribArray( attributes.uv );
  6996. }
  6997. }
  6998. if ( attributes.uv2 >= 0 ) {
  6999. if ( geometryGroup.__webglUV2Buffer ) {
  7000. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglUV2Buffer );
  7001. _gl.vertexAttribPointer( attributes.uv2, 2, _gl.FLOAT, false, 0, 0 );
  7002. _gl.enableVertexAttribArray( attributes.uv2 );
  7003. } else {
  7004. _gl.disableVertexAttribArray( attributes.uv2 );
  7005. }
  7006. }
  7007. if ( material.skinning &&
  7008. attributes.skinVertexA >= 0 && attributes.skinVertexB >= 0 &&
  7009. attributes.skinIndex >= 0 && attributes.skinWeight >= 0 ) {
  7010. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinVertexABuffer );
  7011. _gl.vertexAttribPointer( attributes.skinVertexA, 4, _gl.FLOAT, false, 0, 0 );
  7012. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinVertexBBuffer );
  7013. _gl.vertexAttribPointer( attributes.skinVertexB, 4, _gl.FLOAT, false, 0, 0 );
  7014. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinIndicesBuffer );
  7015. _gl.vertexAttribPointer( attributes.skinIndex, 4, _gl.FLOAT, false, 0, 0 );
  7016. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinWeightsBuffer );
  7017. _gl.vertexAttribPointer( attributes.skinWeight, 4, _gl.FLOAT, false, 0, 0 );
  7018. }
  7019. }
  7020. // render mesh
  7021. if ( object instanceof THREE.Mesh ) {
  7022. // wireframe
  7023. if ( material.wireframe ) {
  7024. setLineWidth( material.wireframeLinewidth );
  7025. if ( updateBuffers ) _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryGroup.__webglLineBuffer );
  7026. _gl.drawElements( _gl.LINES, geometryGroup.__webglLineCount, _gl.UNSIGNED_SHORT, 0 );
  7027. // triangles
  7028. } else {
  7029. if ( updateBuffers ) _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryGroup.__webglFaceBuffer );
  7030. _gl.drawElements( _gl.TRIANGLES, geometryGroup.__webglFaceCount, _gl.UNSIGNED_SHORT, 0 );
  7031. }
  7032. _this.info.render.calls ++;
  7033. _this.info.render.vertices += geometryGroup.__webglFaceCount;
  7034. _this.info.render.faces += geometryGroup.__webglFaceCount / 3;
  7035. // render lines
  7036. } else if ( object instanceof THREE.Line ) {
  7037. primitives = ( object.type === THREE.LineStrip ) ? _gl.LINE_STRIP : _gl.LINES;
  7038. setLineWidth( material.linewidth );
  7039. _gl.drawArrays( primitives, 0, geometryGroup.__webglLineCount );
  7040. _this.info.render.calls ++;
  7041. // render particles
  7042. } else if ( object instanceof THREE.ParticleSystem ) {
  7043. _gl.drawArrays( _gl.POINTS, 0, geometryGroup.__webglParticleCount );
  7044. _this.info.render.calls ++;
  7045. _this.info.render.points += geometryGroup.__webglParticleCount;
  7046. // render ribbon
  7047. } else if ( object instanceof THREE.Ribbon ) {
  7048. _gl.drawArrays( _gl.TRIANGLE_STRIP, 0, geometryGroup.__webglVertexCount );
  7049. _this.info.render.calls ++;
  7050. }
  7051. };
  7052. function setupMorphTargets ( material, geometryGroup, object ) {
  7053. // set base
  7054. var attributes = material.program.attributes;
  7055. if ( object.morphTargetBase !== - 1 ) {
  7056. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ object.morphTargetBase ] );
  7057. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  7058. } else if ( attributes.position >= 0 ) {
  7059. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglVertexBuffer );
  7060. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  7061. }
  7062. if ( object.morphTargetForcedOrder.length ) {
  7063. // set forced order
  7064. var m = 0;
  7065. var order = object.morphTargetForcedOrder;
  7066. var influences = object.morphTargetInfluences;
  7067. while ( m < material.numSupportedMorphTargets && m < order.length ) {
  7068. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ order[ m ] ] );
  7069. _gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
  7070. if ( material.morphNormals ) {
  7071. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphNormalsBuffers[ order[ m ] ] );
  7072. _gl.vertexAttribPointer( attributes[ "morphNormal" + m ], 3, _gl.FLOAT, false, 0, 0 );
  7073. }
  7074. object.__webglMorphTargetInfluences[ m ] = influences[ order[ m ] ];
  7075. m ++;
  7076. }
  7077. } else {
  7078. // find most influencing
  7079. var used = [];
  7080. var candidateInfluence = - 1;
  7081. var candidate = 0;
  7082. var influences = object.morphTargetInfluences;
  7083. var i, il = influences.length;
  7084. var m = 0;
  7085. if ( object.morphTargetBase !== - 1 ) {
  7086. used[ object.morphTargetBase ] = true;
  7087. }
  7088. while ( m < material.numSupportedMorphTargets ) {
  7089. for ( i = 0; i < il; i ++ ) {
  7090. if ( !used[ i ] && influences[ i ] > candidateInfluence ) {
  7091. candidate = i;
  7092. candidateInfluence = influences[ candidate ];
  7093. }
  7094. }
  7095. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ candidate ] );
  7096. _gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
  7097. if ( material.morphNormals ) {
  7098. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphNormalsBuffers[ candidate ] );
  7099. _gl.vertexAttribPointer( attributes[ "morphNormal" + m ], 3, _gl.FLOAT, false, 0, 0 );
  7100. }
  7101. object.__webglMorphTargetInfluences[ m ] = candidateInfluence;
  7102. used[ candidate ] = 1;
  7103. candidateInfluence = -1;
  7104. m ++;
  7105. }
  7106. }
  7107. // load updated influences uniform
  7108. if( material.program.uniforms.morphTargetInfluences !== null ) {
  7109. _gl.uniform1fv( material.program.uniforms.morphTargetInfluences, object.__webglMorphTargetInfluences );
  7110. }
  7111. };
  7112. function painterSort ( a, b ) {
  7113. return b.z - a.z;
  7114. };
  7115. // Rendering
  7116. this.render = function ( scene, camera, renderTarget, forceClear ) {
  7117. var i, il,
  7118. webglObject, object,
  7119. renderList,
  7120. lights = scene.__lights,
  7121. fog = scene.fog;
  7122. _currentMaterialId = -1;
  7123. // update scene graph
  7124. if ( camera.parent === undefined ) {
  7125. console.warn( 'DEPRECATED: Camera hasn\'t been added to a Scene. Adding it...' );
  7126. scene.add( camera );
  7127. }
  7128. if ( this.autoUpdateScene ) scene.updateMatrixWorld();
  7129. // update camera matrices and frustum
  7130. if ( ! camera._viewMatrixArray ) camera._viewMatrixArray = new Float32Array( 16 );
  7131. if ( ! camera._projectionMatrixArray ) camera._projectionMatrixArray = new Float32Array( 16 );
  7132. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  7133. camera.matrixWorldInverse.flattenToArray( camera._viewMatrixArray );
  7134. camera.projectionMatrix.flattenToArray( camera._projectionMatrixArray );
  7135. _projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );
  7136. _frustum.setFromMatrix( _projScreenMatrix );
  7137. // update WebGL objects
  7138. if ( this.autoUpdateObjects ) this.initWebGLObjects( scene );
  7139. // custom render plugins (pre pass)
  7140. renderPlugins( this.renderPluginsPre, scene, camera );
  7141. //
  7142. _this.info.render.calls = 0;
  7143. _this.info.render.vertices = 0;
  7144. _this.info.render.faces = 0;
  7145. _this.info.render.points = 0;
  7146. this.setRenderTarget( renderTarget );
  7147. if ( this.autoClear || forceClear ) {
  7148. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  7149. }
  7150. // set matrices for regular objects (frustum culled)
  7151. renderList = scene.__webglObjects;
  7152. for ( i = 0, il = renderList.length; i < il; i ++ ) {
  7153. webglObject = renderList[ i ];
  7154. object = webglObject.object;
  7155. webglObject.render = false;
  7156. if ( object.visible ) {
  7157. if ( ! ( object instanceof THREE.Mesh || object instanceof THREE.ParticleSystem ) || ! ( object.frustumCulled ) || _frustum.contains( object ) ) {
  7158. //object.matrixWorld.flattenToArray( object._objectMatrixArray );
  7159. setupMatrices( object, camera );
  7160. unrollBufferMaterial( webglObject );
  7161. webglObject.render = true;
  7162. if ( this.sortObjects ) {
  7163. if ( object.renderDepth ) {
  7164. webglObject.z = object.renderDepth;
  7165. } else {
  7166. _vector3.copy( object.matrixWorld.getPosition() );
  7167. _projScreenMatrix.multiplyVector3( _vector3 );
  7168. webglObject.z = _vector3.z;
  7169. }
  7170. }
  7171. }
  7172. }
  7173. }
  7174. if ( this.sortObjects ) {
  7175. renderList.sort( painterSort );
  7176. }
  7177. // set matrices for immediate objects
  7178. renderList = scene.__webglObjectsImmediate;
  7179. for ( i = 0, il = renderList.length; i < il; i ++ ) {
  7180. webglObject = renderList[ i ];
  7181. object = webglObject.object;
  7182. if ( object.visible ) {
  7183. /*
  7184. if ( object.matrixAutoUpdate ) {
  7185. object.matrixWorld.flattenToArray( object._objectMatrixArray );
  7186. }
  7187. */
  7188. setupMatrices( object, camera );
  7189. unrollImmediateBufferMaterial( webglObject );
  7190. }
  7191. }
  7192. if ( scene.overrideMaterial ) {
  7193. var material = scene.overrideMaterial;
  7194. this.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  7195. this.setDepthTest( material.depthTest );
  7196. this.setDepthWrite( material.depthWrite );
  7197. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  7198. renderObjects( scene.__webglObjects, false, "", camera, lights, fog, true, material );
  7199. renderObjectsImmediate( scene.__webglObjectsImmediate, "", camera, lights, fog, false, material );
  7200. } else {
  7201. // opaque pass (front-to-back order)
  7202. this.setBlending( THREE.NormalBlending );
  7203. renderObjects( scene.__webglObjects, true, "opaque", camera, lights, fog, false );
  7204. renderObjectsImmediate( scene.__webglObjectsImmediate, "opaque", camera, lights, fog, false );
  7205. // transparent pass (back-to-front order)
  7206. renderObjects( scene.__webglObjects, false, "transparent", camera, lights, fog, true );
  7207. renderObjectsImmediate( scene.__webglObjectsImmediate, "transparent", camera, lights, fog, true );
  7208. }
  7209. // custom render plugins (post pass)
  7210. renderPlugins( this.renderPluginsPost, scene, camera );
  7211. // Generate mipmap if we're using any kind of mipmap filtering
  7212. if ( renderTarget && renderTarget.generateMipmaps && renderTarget.minFilter !== THREE.NearestFilter && renderTarget.minFilter !== THREE.LinearFilter ) {
  7213. updateRenderTargetMipmap( renderTarget );
  7214. }
  7215. // Ensure depth buffer writing is enabled so it can be cleared on next render
  7216. this.setDepthTest( true );
  7217. this.setDepthWrite( true );
  7218. // _gl.finish();
  7219. };
  7220. function renderPlugins( plugins, scene, camera ) {
  7221. if ( ! plugins.length ) return;
  7222. for ( var i = 0, il = plugins.length; i < il; i ++ ) {
  7223. _currentProgram = null;
  7224. _currentCamera = null;
  7225. _oldBlending = -1;
  7226. _oldDepthTest = -1;
  7227. _oldDepthWrite = -1;
  7228. _currentGeometryGroupHash = -1;
  7229. _currentMaterialId = -1;
  7230. plugins[ i ].render( scene, camera, _currentWidth, _currentHeight );
  7231. _currentProgram = null;
  7232. _currentCamera = null;
  7233. _oldBlending = -1;
  7234. _oldDepthTest = -1;
  7235. _oldDepthWrite = -1;
  7236. _currentGeometryGroupHash = -1;
  7237. _currentMaterialId = -1;
  7238. }
  7239. };
  7240. function renderObjects ( renderList, reverse, materialType, camera, lights, fog, useBlending, overrideMaterial ) {
  7241. var webglObject, object, buffer, material, start, end, delta;
  7242. if ( reverse ) {
  7243. start = renderList.length - 1;
  7244. end = -1;
  7245. delta = -1;
  7246. } else {
  7247. start = 0;
  7248. end = renderList.length;
  7249. delta = 1;
  7250. }
  7251. for ( var i = start; i !== end; i += delta ) {
  7252. webglObject = renderList[ i ];
  7253. if ( webglObject.render ) {
  7254. object = webglObject.object;
  7255. buffer = webglObject.buffer;
  7256. if ( overrideMaterial ) {
  7257. material = overrideMaterial;
  7258. } else {
  7259. material = webglObject[ materialType ];
  7260. if ( ! material ) continue;
  7261. if ( useBlending ) _this.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  7262. _this.setDepthTest( material.depthTest );
  7263. _this.setDepthWrite( material.depthWrite );
  7264. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  7265. }
  7266. _this.setObjectFaces( object );
  7267. if ( buffer instanceof THREE.BufferGeometry ) {
  7268. _this.renderBufferDirect( camera, lights, fog, material, buffer, object );
  7269. } else {
  7270. _this.renderBuffer( camera, lights, fog, material, buffer, object );
  7271. }
  7272. }
  7273. }
  7274. };
  7275. function renderObjectsImmediate ( renderList, materialType, camera, lights, fog, useBlending, overrideMaterial ) {
  7276. var webglObject, object, material, program;
  7277. for ( var i = 0, il = renderList.length; i < il; i ++ ) {
  7278. webglObject = renderList[ i ];
  7279. object = webglObject.object;
  7280. if ( object.visible ) {
  7281. if ( overrideMaterial ) {
  7282. material = overrideMaterial;
  7283. } else {
  7284. material = webglObject[ materialType ];
  7285. if ( ! material ) continue;
  7286. if ( useBlending ) _this.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  7287. _this.setDepthTest( material.depthTest );
  7288. _this.setDepthWrite( material.depthWrite );
  7289. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  7290. }
  7291. _this.renderImmediateObject( camera, lights, fog, material, object );
  7292. }
  7293. }
  7294. };
  7295. this.renderImmediateObject = function ( camera, lights, fog, material, object ) {
  7296. var program = setProgram( camera, lights, fog, material, object );
  7297. _currentGeometryGroupHash = -1;
  7298. _this.setObjectFaces( object );
  7299. if ( object.immediateRenderCallback ) {
  7300. object.immediateRenderCallback( program, _gl, _frustum );
  7301. } else {
  7302. object.render( function( object ) { _this.renderBufferImmediate( object, program, material.shading ); } );
  7303. }
  7304. };
  7305. function unrollImmediateBufferMaterial ( globject ) {
  7306. var object = globject.object,
  7307. material = object.material;
  7308. if ( material.transparent ) {
  7309. globject.transparent = material;
  7310. globject.opaque = null;
  7311. } else {
  7312. globject.opaque = material;
  7313. globject.transparent = null;
  7314. }
  7315. };
  7316. function unrollBufferMaterial ( globject ) {
  7317. var object = globject.object,
  7318. buffer = globject.buffer,
  7319. material, materialIndex, meshMaterial;
  7320. meshMaterial = object.material;
  7321. if ( meshMaterial instanceof THREE.MeshFaceMaterial ) {
  7322. materialIndex = buffer.materialIndex;
  7323. if ( materialIndex >= 0 ) {
  7324. material = object.geometry.materials[ materialIndex ];
  7325. if ( material.transparent ) {
  7326. globject.transparent = material;
  7327. globject.opaque = null;
  7328. } else {
  7329. globject.opaque = material;
  7330. globject.transparent = null;
  7331. }
  7332. }
  7333. } else {
  7334. material = meshMaterial;
  7335. if ( material ) {
  7336. if ( material.transparent ) {
  7337. globject.transparent = material;
  7338. globject.opaque = null;
  7339. } else {
  7340. globject.opaque = material;
  7341. globject.transparent = null;
  7342. }
  7343. }
  7344. }
  7345. };
  7346. // Geometry splitting
  7347. function sortFacesByMaterial ( geometry ) {
  7348. var f, fl, face, materialIndex, vertices,
  7349. materialHash, groupHash,
  7350. hash_map = {};
  7351. var numMorphTargets = geometry.morphTargets.length;
  7352. var numMorphNormals = geometry.morphNormals.length;
  7353. geometry.geometryGroups = {};
  7354. for ( f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
  7355. face = geometry.faces[ f ];
  7356. materialIndex = face.materialIndex;
  7357. materialHash = ( materialIndex !== undefined ) ? materialIndex : -1;
  7358. if ( hash_map[ materialHash ] === undefined ) {
  7359. hash_map[ materialHash ] = { 'hash': materialHash, 'counter': 0 };
  7360. }
  7361. groupHash = hash_map[ materialHash ].hash + '_' + hash_map[ materialHash ].counter;
  7362. if ( geometry.geometryGroups[ groupHash ] === undefined ) {
  7363. geometry.geometryGroups[ groupHash ] = { 'faces3': [], 'faces4': [], 'materialIndex': materialIndex, 'vertices': 0, 'numMorphTargets': numMorphTargets, 'numMorphNormals': numMorphNormals };
  7364. }
  7365. vertices = face instanceof THREE.Face3 ? 3 : 4;
  7366. if ( geometry.geometryGroups[ groupHash ].vertices + vertices > 65535 ) {
  7367. hash_map[ materialHash ].counter += 1;
  7368. groupHash = hash_map[ materialHash ].hash + '_' + hash_map[ materialHash ].counter;
  7369. if ( geometry.geometryGroups[ groupHash ] === undefined ) {
  7370. geometry.geometryGroups[ groupHash ] = { 'faces3': [], 'faces4': [], 'materialIndex': materialIndex, 'vertices': 0, 'numMorphTargets': numMorphTargets, 'numMorphNormals': numMorphNormals };
  7371. }
  7372. }
  7373. if ( face instanceof THREE.Face3 ) {
  7374. geometry.geometryGroups[ groupHash ].faces3.push( f );
  7375. } else {
  7376. geometry.geometryGroups[ groupHash ].faces4.push( f );
  7377. }
  7378. geometry.geometryGroups[ groupHash ].vertices += vertices;
  7379. }
  7380. geometry.geometryGroupsList = [];
  7381. for ( var g in geometry.geometryGroups ) {
  7382. geometry.geometryGroups[ g ].id = _geometryGroupCounter ++;
  7383. geometry.geometryGroupsList.push( geometry.geometryGroups[ g ] );
  7384. }
  7385. };
  7386. // Objects refresh
  7387. this.initWebGLObjects = function ( scene ) {
  7388. if ( !scene.__webglObjects ) {
  7389. scene.__webglObjects = [];
  7390. scene.__webglObjectsImmediate = [];
  7391. scene.__webglSprites = [];
  7392. scene.__webglFlares = [];
  7393. }
  7394. while ( scene.__objectsAdded.length ) {
  7395. addObject( scene.__objectsAdded[ 0 ], scene );
  7396. scene.__objectsAdded.splice( 0, 1 );
  7397. }
  7398. while ( scene.__objectsRemoved.length ) {
  7399. removeObject( scene.__objectsRemoved[ 0 ], scene );
  7400. scene.__objectsRemoved.splice( 0, 1 );
  7401. }
  7402. // update must be called after objects adding / removal
  7403. for ( var o = 0, ol = scene.__webglObjects.length; o < ol; o ++ ) {
  7404. updateObject( scene.__webglObjects[ o ].object );
  7405. }
  7406. };
  7407. // Objects adding
  7408. function addObject ( object, scene ) {
  7409. var g, geometry, geometryGroup;
  7410. if ( ! object.__webglInit ) {
  7411. object.__webglInit = true;
  7412. object._modelViewMatrix = new THREE.Matrix4();
  7413. object._normalMatrix = new THREE.Matrix3();
  7414. //object._normalMatrixArray = new Float32Array( 9 );
  7415. //object._modelViewMatrixArray = new Float32Array( 16 );
  7416. //object._objectMatrixArray = new Float32Array( 16 );
  7417. //object.matrixWorld.flattenToArray( object._objectMatrixArray );
  7418. if ( object instanceof THREE.Mesh ) {
  7419. geometry = object.geometry;
  7420. if ( geometry instanceof THREE.Geometry ) {
  7421. if ( geometry.geometryGroups === undefined ) {
  7422. sortFacesByMaterial( geometry );
  7423. }
  7424. // create separate VBOs per geometry chunk
  7425. for ( g in geometry.geometryGroups ) {
  7426. geometryGroup = geometry.geometryGroups[ g ];
  7427. // initialise VBO on the first access
  7428. if ( ! geometryGroup.__webglVertexBuffer ) {
  7429. createMeshBuffers( geometryGroup );
  7430. initMeshBuffers( geometryGroup, object );
  7431. geometry.__dirtyVertices = true;
  7432. geometry.__dirtyMorphTargets = true;
  7433. geometry.__dirtyElements = true;
  7434. geometry.__dirtyUvs = true;
  7435. geometry.__dirtyNormals = true;
  7436. geometry.__dirtyTangents = true;
  7437. geometry.__dirtyColors = true;
  7438. }
  7439. }
  7440. }
  7441. } else if ( object instanceof THREE.Ribbon ) {
  7442. geometry = object.geometry;
  7443. if( ! geometry.__webglVertexBuffer ) {
  7444. createRibbonBuffers( geometry );
  7445. initRibbonBuffers( geometry );
  7446. geometry.__dirtyVertices = true;
  7447. geometry.__dirtyColors = true;
  7448. }
  7449. } else if ( object instanceof THREE.Line ) {
  7450. geometry = object.geometry;
  7451. if( ! geometry.__webglVertexBuffer ) {
  7452. createLineBuffers( geometry );
  7453. initLineBuffers( geometry, object );
  7454. geometry.__dirtyVertices = true;
  7455. geometry.__dirtyColors = true;
  7456. }
  7457. } else if ( object instanceof THREE.ParticleSystem ) {
  7458. geometry = object.geometry;
  7459. if ( ! geometry.__webglVertexBuffer ) {
  7460. createParticleBuffers( geometry );
  7461. initParticleBuffers( geometry, object );
  7462. geometry.__dirtyVertices = true;
  7463. geometry.__dirtyColors = true;
  7464. }
  7465. }
  7466. }
  7467. if ( ! object.__webglActive ) {
  7468. if ( object instanceof THREE.Mesh ) {
  7469. geometry = object.geometry;
  7470. if ( geometry instanceof THREE.BufferGeometry ) {
  7471. addBuffer( scene.__webglObjects, geometry, object );
  7472. } else {
  7473. for ( g in geometry.geometryGroups ) {
  7474. geometryGroup = geometry.geometryGroups[ g ];
  7475. addBuffer( scene.__webglObjects, geometryGroup, object );
  7476. }
  7477. }
  7478. } else if ( object instanceof THREE.Ribbon ||
  7479. object instanceof THREE.Line ||
  7480. object instanceof THREE.ParticleSystem ) {
  7481. geometry = object.geometry;
  7482. addBuffer( scene.__webglObjects, geometry, object );
  7483. } else if ( object instanceof THREE.ImmediateRenderObject || object.immediateRenderCallback ) {
  7484. addBufferImmediate( scene.__webglObjectsImmediate, object );
  7485. } else if ( object instanceof THREE.Sprite ) {
  7486. scene.__webglSprites.push( object );
  7487. } else if ( object instanceof THREE.LensFlare ) {
  7488. scene.__webglFlares.push( object );
  7489. }
  7490. object.__webglActive = true;
  7491. }
  7492. };
  7493. function addBuffer ( objlist, buffer, object ) {
  7494. objlist.push(
  7495. {
  7496. buffer: buffer,
  7497. object: object,
  7498. opaque: null,
  7499. transparent: null
  7500. }
  7501. );
  7502. };
  7503. function addBufferImmediate ( objlist, object ) {
  7504. objlist.push(
  7505. {
  7506. object: object,
  7507. opaque: null,
  7508. transparent: null
  7509. }
  7510. );
  7511. };
  7512. // Objects updates
  7513. function updateObject ( object ) {
  7514. var geometry = object.geometry,
  7515. geometryGroup, customAttributesDirty, material;
  7516. if ( object instanceof THREE.Mesh ) {
  7517. if ( geometry instanceof THREE.BufferGeometry ) {
  7518. /*
  7519. if ( geometry.__dirtyVertices || geometry.__dirtyElements ||
  7520. geometry.__dirtyUvs || geometry.__dirtyNormals ||
  7521. geometry.__dirtyColors ) {
  7522. // TODO
  7523. // set buffers from typed arrays
  7524. }
  7525. */
  7526. geometry.__dirtyVertices = false;
  7527. geometry.__dirtyElements = false;
  7528. geometry.__dirtyUvs = false;
  7529. geometry.__dirtyNormals = false;
  7530. geometry.__dirtyColors = false;
  7531. } else {
  7532. // check all geometry groups
  7533. for( var i = 0, il = geometry.geometryGroupsList.length; i < il; i ++ ) {
  7534. geometryGroup = geometry.geometryGroupsList[ i ];
  7535. material = getBufferMaterial( object, geometryGroup );
  7536. customAttributesDirty = material.attributes && areCustomAttributesDirty( material );
  7537. if ( geometry.__dirtyVertices || geometry.__dirtyMorphTargets || geometry.__dirtyElements ||
  7538. geometry.__dirtyUvs || geometry.__dirtyNormals ||
  7539. geometry.__dirtyColors || geometry.__dirtyTangents || customAttributesDirty ) {
  7540. setMeshBuffers( geometryGroup, object, _gl.DYNAMIC_DRAW, !geometry.dynamic, material );
  7541. }
  7542. }
  7543. geometry.__dirtyVertices = false;
  7544. geometry.__dirtyMorphTargets = false;
  7545. geometry.__dirtyElements = false;
  7546. geometry.__dirtyUvs = false;
  7547. geometry.__dirtyNormals = false;
  7548. geometry.__dirtyColors = false;
  7549. geometry.__dirtyTangents = false;
  7550. material.attributes && clearCustomAttributes( material );
  7551. }
  7552. } else if ( object instanceof THREE.Ribbon ) {
  7553. if ( geometry.__dirtyVertices || geometry.__dirtyColors ) {
  7554. setRibbonBuffers( geometry, _gl.DYNAMIC_DRAW );
  7555. }
  7556. geometry.__dirtyVertices = false;
  7557. geometry.__dirtyColors = false;
  7558. } else if ( object instanceof THREE.Line ) {
  7559. material = getBufferMaterial( object, geometryGroup );
  7560. customAttributesDirty = material.attributes && areCustomAttributesDirty( material );
  7561. if ( geometry.__dirtyVertices || geometry.__dirtyColors || customAttributesDirty ) {
  7562. setLineBuffers( geometry, _gl.DYNAMIC_DRAW );
  7563. }
  7564. geometry.__dirtyVertices = false;
  7565. geometry.__dirtyColors = false;
  7566. material.attributes && clearCustomAttributes( material );
  7567. } else if ( object instanceof THREE.ParticleSystem ) {
  7568. material = getBufferMaterial( object, geometryGroup );
  7569. customAttributesDirty = material.attributes && areCustomAttributesDirty( material );
  7570. if ( geometry.__dirtyVertices || geometry.__dirtyColors || object.sortParticles || customAttributesDirty ) {
  7571. setParticleBuffers( geometry, _gl.DYNAMIC_DRAW, object );
  7572. }
  7573. geometry.__dirtyVertices = false;
  7574. geometry.__dirtyColors = false;
  7575. material.attributes && clearCustomAttributes( material );
  7576. }
  7577. };
  7578. // Objects updates - custom attributes check
  7579. function areCustomAttributesDirty ( material ) {
  7580. for ( var a in material.attributes ) {
  7581. if ( material.attributes[ a ].needsUpdate ) return true;
  7582. }
  7583. return false;
  7584. };
  7585. function clearCustomAttributes ( material ) {
  7586. for ( var a in material.attributes ) {
  7587. material.attributes[ a ].needsUpdate = false;
  7588. }
  7589. };
  7590. // Objects removal
  7591. function removeObject ( object, scene ) {
  7592. if ( object instanceof THREE.Mesh ||
  7593. object instanceof THREE.ParticleSystem ||
  7594. object instanceof THREE.Ribbon ||
  7595. object instanceof THREE.Line ) {
  7596. removeInstances( scene.__webglObjects, object );
  7597. } else if ( object instanceof THREE.Sprite ) {
  7598. removeInstancesDirect( scene.__webglSprites, object );
  7599. } else if ( object instanceof THREE.LensFlare ) {
  7600. removeInstancesDirect( scene.__webglFlares, object );
  7601. } else if ( object instanceof THREE.ImmediateRenderObject || object.immediateRenderCallback ) {
  7602. removeInstances( scene.__webglObjectsImmediate, object );
  7603. }
  7604. object.__webglActive = false;
  7605. };
  7606. function removeInstances ( objlist, object ) {
  7607. for ( var o = objlist.length - 1; o >= 0; o -- ) {
  7608. if ( objlist[ o ].object === object ) {
  7609. objlist.splice( o, 1 );
  7610. }
  7611. }
  7612. };
  7613. function removeInstancesDirect ( objlist, object ) {
  7614. for ( var o = objlist.length - 1; o >= 0; o -- ) {
  7615. if ( objlist[ o ] === object ) {
  7616. objlist.splice( o, 1 );
  7617. }
  7618. }
  7619. };
  7620. // Materials
  7621. this.initMaterial = function ( material, lights, fog, object ) {
  7622. var u, a, identifiers, i, parameters, maxLightCount, maxBones, maxShadows, shaderID;
  7623. if ( material instanceof THREE.MeshDepthMaterial ) {
  7624. shaderID = 'depth';
  7625. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  7626. shaderID = 'normal';
  7627. } else if ( material instanceof THREE.MeshBasicMaterial ) {
  7628. shaderID = 'basic';
  7629. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  7630. shaderID = 'lambert';
  7631. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  7632. shaderID = 'phong';
  7633. } else if ( material instanceof THREE.LineBasicMaterial ) {
  7634. shaderID = 'basic';
  7635. } else if ( material instanceof THREE.ParticleBasicMaterial ) {
  7636. shaderID = 'particle_basic';
  7637. }
  7638. if ( shaderID ) {
  7639. setMaterialShaders( material, THREE.ShaderLib[ shaderID ] );
  7640. }
  7641. // heuristics to create shader parameters according to lights in the scene
  7642. // (not to blow over maxLights budget)
  7643. maxLightCount = allocateLights( lights );
  7644. maxShadows = allocateShadows( lights );
  7645. maxBones = allocateBones( object );
  7646. parameters = {
  7647. map: !!material.map,
  7648. envMap: !!material.envMap,
  7649. lightMap: !!material.lightMap,
  7650. vertexColors: material.vertexColors,
  7651. fog: fog,
  7652. useFog: material.fog,
  7653. sizeAttenuation: material.sizeAttenuation,
  7654. skinning: material.skinning,
  7655. maxBones: maxBones,
  7656. morphTargets: material.morphTargets,
  7657. morphNormals: material.morphNormals,
  7658. maxMorphTargets: this.maxMorphTargets,
  7659. maxMorphNormals: this.maxMorphNormals,
  7660. maxDirLights: maxLightCount.directional,
  7661. maxPointLights: maxLightCount.point,
  7662. maxSpotLights: maxLightCount.spot,
  7663. maxShadows: maxShadows,
  7664. shadowMapEnabled: this.shadowMapEnabled && object.receiveShadow,
  7665. shadowMapSoft: this.shadowMapSoft,
  7666. shadowMapDebug: this.shadowMapDebug,
  7667. shadowMapCascade: this.shadowMapCascade,
  7668. alphaTest: material.alphaTest,
  7669. metal: material.metal,
  7670. perPixel: material.perPixel,
  7671. wrapAround: material.wrapAround,
  7672. doubleSided: object && object.doubleSided
  7673. };
  7674. material.program = buildProgram( shaderID, material.fragmentShader, material.vertexShader, material.uniforms, material.attributes, parameters );
  7675. var attributes = material.program.attributes;
  7676. if ( attributes.position >= 0 ) _gl.enableVertexAttribArray( attributes.position );
  7677. if ( attributes.color >= 0 ) _gl.enableVertexAttribArray( attributes.color );
  7678. if ( attributes.normal >= 0 ) _gl.enableVertexAttribArray( attributes.normal );
  7679. if ( attributes.tangent >= 0 ) _gl.enableVertexAttribArray( attributes.tangent );
  7680. if ( material.skinning &&
  7681. attributes.skinVertexA >=0 && attributes.skinVertexB >= 0 &&
  7682. attributes.skinIndex >= 0 && attributes.skinWeight >= 0 ) {
  7683. _gl.enableVertexAttribArray( attributes.skinVertexA );
  7684. _gl.enableVertexAttribArray( attributes.skinVertexB );
  7685. _gl.enableVertexAttribArray( attributes.skinIndex );
  7686. _gl.enableVertexAttribArray( attributes.skinWeight );
  7687. }
  7688. if ( material.attributes ) {
  7689. for ( a in material.attributes ) {
  7690. if( attributes[ a ] !== undefined && attributes[ a ] >= 0 ) _gl.enableVertexAttribArray( attributes[ a ] );
  7691. }
  7692. }
  7693. if ( material.morphTargets ) {
  7694. material.numSupportedMorphTargets = 0;
  7695. var id, base = "morphTarget";
  7696. for ( i = 0; i < this.maxMorphTargets; i ++ ) {
  7697. id = base + i;
  7698. if ( attributes[ id ] >= 0 ) {
  7699. _gl.enableVertexAttribArray( attributes[ id ] );
  7700. material.numSupportedMorphTargets ++;
  7701. }
  7702. }
  7703. }
  7704. if ( material.morphNormals ) {
  7705. material.numSupportedMorphNormals = 0;
  7706. var id, base = "morphNormal";
  7707. for ( i = 0; i < this.maxMorphNormals; i ++ ) {
  7708. id = base + i;
  7709. if ( attributes[ id ] >= 0 ) {
  7710. _gl.enableVertexAttribArray( attributes[ id ] );
  7711. material.numSupportedMorphNormals ++;
  7712. }
  7713. }
  7714. }
  7715. material.uniformsList = [];
  7716. for ( u in material.uniforms ) {
  7717. material.uniformsList.push( [ material.uniforms[ u ], u ] );
  7718. }
  7719. };
  7720. function setMaterialShaders( material, shaders ) {
  7721. material.uniforms = THREE.UniformsUtils.clone( shaders.uniforms );
  7722. material.vertexShader = shaders.vertexShader;
  7723. material.fragmentShader = shaders.fragmentShader;
  7724. };
  7725. function setProgram( camera, lights, fog, material, object ) {
  7726. if ( ! material.program || material.needsUpdate ) {
  7727. _this.initMaterial( material, lights, fog, object );
  7728. material.needsUpdate = false;
  7729. }
  7730. if ( material.morphTargets ) {
  7731. if ( ! object.__webglMorphTargetInfluences ) {
  7732. object.__webglMorphTargetInfluences = new Float32Array( _this.maxMorphTargets );
  7733. for ( var i = 0, il = _this.maxMorphTargets; i < il; i ++ ) {
  7734. object.__webglMorphTargetInfluences[ i ] = 0;
  7735. }
  7736. }
  7737. }
  7738. var refreshMaterial = false;
  7739. var program = material.program,
  7740. p_uniforms = program.uniforms,
  7741. m_uniforms = material.uniforms;
  7742. if ( program !== _currentProgram ) {
  7743. _gl.useProgram( program );
  7744. _currentProgram = program;
  7745. refreshMaterial = true;
  7746. }
  7747. if ( material.id !== _currentMaterialId ) {
  7748. _currentMaterialId = material.id;
  7749. refreshMaterial = true;
  7750. }
  7751. if ( refreshMaterial || camera !== _currentCamera ) {
  7752. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera._projectionMatrixArray );
  7753. if ( camera !== _currentCamera ) _currentCamera = camera;
  7754. }
  7755. if ( refreshMaterial ) {
  7756. // refresh uniforms common to several materials
  7757. if ( fog && material.fog ) {
  7758. refreshUniformsFog( m_uniforms, fog );
  7759. }
  7760. if ( material instanceof THREE.MeshPhongMaterial ||
  7761. material instanceof THREE.MeshLambertMaterial ||
  7762. material.lights ) {
  7763. setupLights( program, lights );
  7764. refreshUniformsLights( m_uniforms, _lights );
  7765. }
  7766. if ( material instanceof THREE.MeshBasicMaterial ||
  7767. material instanceof THREE.MeshLambertMaterial ||
  7768. material instanceof THREE.MeshPhongMaterial ) {
  7769. refreshUniformsCommon( m_uniforms, material );
  7770. }
  7771. // refresh single material specific uniforms
  7772. if ( material instanceof THREE.LineBasicMaterial ) {
  7773. refreshUniformsLine( m_uniforms, material );
  7774. } else if ( material instanceof THREE.ParticleBasicMaterial ) {
  7775. refreshUniformsParticle( m_uniforms, material );
  7776. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  7777. refreshUniformsPhong( m_uniforms, material );
  7778. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  7779. refreshUniformsLambert( m_uniforms, material );
  7780. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  7781. m_uniforms.mNear.value = camera.near;
  7782. m_uniforms.mFar.value = camera.far;
  7783. m_uniforms.opacity.value = material.opacity;
  7784. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  7785. m_uniforms.opacity.value = material.opacity;
  7786. }
  7787. if ( object.receiveShadow && ! material._shadowPass ) {
  7788. refreshUniformsShadow( m_uniforms, lights );
  7789. }
  7790. // load common uniforms
  7791. loadUniformsGeneric( program, material.uniformsList );
  7792. // load material specific uniforms
  7793. // (shader material also gets them for the sake of genericity)
  7794. if ( material instanceof THREE.ShaderMaterial ||
  7795. material instanceof THREE.MeshPhongMaterial ||
  7796. material.envMap ) {
  7797. if ( p_uniforms.cameraPosition !== null ) {
  7798. var position = camera.matrixWorld.getPosition();
  7799. _gl.uniform3f( p_uniforms.cameraPosition, position.x, position.y, position.z );
  7800. }
  7801. }
  7802. if ( material instanceof THREE.MeshPhongMaterial ||
  7803. material instanceof THREE.MeshLambertMaterial ||
  7804. material instanceof THREE.ShaderMaterial ||
  7805. material.skinning ) {
  7806. if ( p_uniforms.viewMatrix !== null ) {
  7807. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera._viewMatrixArray );
  7808. }
  7809. }
  7810. if ( material.skinning ) {
  7811. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.boneMatrices );
  7812. }
  7813. }
  7814. loadUniformsMatrices( p_uniforms, object );
  7815. if ( material instanceof THREE.ShaderMaterial ||
  7816. material.envMap ||
  7817. material.skinning ||
  7818. object.receiveShadow ) {
  7819. if ( p_uniforms.objectMatrix !== null ) {
  7820. _gl.uniformMatrix4fv( p_uniforms.objectMatrix, false, object.matrixWorld.elements );
  7821. }
  7822. }
  7823. return program;
  7824. };
  7825. // Uniforms (refresh uniforms objects)
  7826. function refreshUniformsCommon ( uniforms, material ) {
  7827. uniforms.opacity.value = material.opacity;
  7828. if ( _this.gammaInput ) {
  7829. uniforms.diffuse.value.copyGammaToLinear( material.color );
  7830. } else {
  7831. uniforms.diffuse.value = material.color;
  7832. }
  7833. uniforms.map.texture = material.map;
  7834. if ( material.map ) {
  7835. uniforms.offsetRepeat.value.set( material.map.offset.x, material.map.offset.y, material.map.repeat.x, material.map.repeat.y );
  7836. }
  7837. uniforms.lightMap.texture = material.lightMap;
  7838. uniforms.envMap.texture = material.envMap;
  7839. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : -1;
  7840. if ( _this.gammaInput ) {
  7841. //uniforms.reflectivity.value = material.reflectivity * material.reflectivity;
  7842. uniforms.reflectivity.value = material.reflectivity;
  7843. } else {
  7844. uniforms.reflectivity.value = material.reflectivity;
  7845. }
  7846. uniforms.refractionRatio.value = material.refractionRatio;
  7847. uniforms.combine.value = material.combine;
  7848. uniforms.useRefract.value = material.envMap && material.envMap.mapping instanceof THREE.CubeRefractionMapping;
  7849. };
  7850. function refreshUniformsLine ( uniforms, material ) {
  7851. uniforms.diffuse.value = material.color;
  7852. uniforms.opacity.value = material.opacity;
  7853. };
  7854. function refreshUniformsParticle ( uniforms, material ) {
  7855. uniforms.psColor.value = material.color;
  7856. uniforms.opacity.value = material.opacity;
  7857. uniforms.size.value = material.size;
  7858. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  7859. uniforms.map.texture = material.map;
  7860. };
  7861. function refreshUniformsFog ( uniforms, fog ) {
  7862. uniforms.fogColor.value = fog.color;
  7863. if ( fog instanceof THREE.Fog ) {
  7864. uniforms.fogNear.value = fog.near;
  7865. uniforms.fogFar.value = fog.far;
  7866. } else if ( fog instanceof THREE.FogExp2 ) {
  7867. uniforms.fogDensity.value = fog.density;
  7868. }
  7869. };
  7870. function refreshUniformsPhong ( uniforms, material ) {
  7871. uniforms.shininess.value = material.shininess;
  7872. if ( _this.gammaInput ) {
  7873. uniforms.ambient.value.copyGammaToLinear( material.ambient );
  7874. uniforms.emissive.value.copyGammaToLinear( material.emissive );
  7875. uniforms.specular.value.copyGammaToLinear( material.specular );
  7876. } else {
  7877. uniforms.ambient.value = material.ambient;
  7878. uniforms.emissive.value = material.emissive;
  7879. uniforms.specular.value = material.specular;
  7880. }
  7881. if ( material.wrapAround ) {
  7882. uniforms.wrapRGB.value.copy( material.wrapRGB );
  7883. }
  7884. };
  7885. function refreshUniformsLambert ( uniforms, material ) {
  7886. if ( _this.gammaInput ) {
  7887. uniforms.ambient.value.copyGammaToLinear( material.ambient );
  7888. uniforms.emissive.value.copyGammaToLinear( material.emissive );
  7889. } else {
  7890. uniforms.ambient.value = material.ambient;
  7891. uniforms.emissive.value = material.emissive;
  7892. }
  7893. if ( material.wrapAround ) {
  7894. uniforms.wrapRGB.value.copy( material.wrapRGB );
  7895. }
  7896. };
  7897. function refreshUniformsLights ( uniforms, lights ) {
  7898. uniforms.ambientLightColor.value = lights.ambient;
  7899. uniforms.directionalLightColor.value = lights.directional.colors;
  7900. uniforms.directionalLightDirection.value = lights.directional.positions;
  7901. uniforms.pointLightColor.value = lights.point.colors;
  7902. uniforms.pointLightPosition.value = lights.point.positions;
  7903. uniforms.pointLightDistance.value = lights.point.distances;
  7904. uniforms.spotLightColor.value = lights.spot.colors;
  7905. uniforms.spotLightPosition.value = lights.spot.positions;
  7906. uniforms.spotLightDistance.value = lights.spot.distances;
  7907. uniforms.spotLightDirection.value = lights.spot.directions;
  7908. uniforms.spotLightAngle.value = lights.spot.angles;
  7909. uniforms.spotLightExponent.value = lights.spot.exponents;
  7910. };
  7911. function refreshUniformsShadow ( uniforms, lights ) {
  7912. if ( uniforms.shadowMatrix ) {
  7913. var j = 0;
  7914. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  7915. var light = lights[ i ];
  7916. if ( ! light.castShadow ) continue;
  7917. if ( light instanceof THREE.SpotLight || ( light instanceof THREE.DirectionalLight && ! light.shadowCascade ) ) {
  7918. uniforms.shadowMap.texture[ j ] = light.shadowMap;
  7919. uniforms.shadowMapSize.value[ j ] = light.shadowMapSize;
  7920. uniforms.shadowMatrix.value[ j ] = light.shadowMatrix;
  7921. uniforms.shadowDarkness.value[ j ] = light.shadowDarkness;
  7922. uniforms.shadowBias.value[ j ] = light.shadowBias;
  7923. j ++;
  7924. }
  7925. }
  7926. }
  7927. };
  7928. // Uniforms (load to GPU)
  7929. function loadUniformsMatrices ( uniforms, object ) {
  7930. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object._modelViewMatrix.elements );
  7931. if ( uniforms.normalMatrix ) {
  7932. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object._normalMatrix.elements );
  7933. }
  7934. };
  7935. function loadUniformsGeneric ( program, uniforms ) {
  7936. var uniform, value, type, location, texture, i, il, j, jl, offset;
  7937. for( j = 0, jl = uniforms.length; j < jl; j ++ ) {
  7938. location = program.uniforms[ uniforms[ j ][ 1 ] ];
  7939. if ( !location ) continue;
  7940. uniform = uniforms[ j ][ 0 ];
  7941. type = uniform.type;
  7942. value = uniform.value;
  7943. // single integer
  7944. if( type === "i" ) {
  7945. _gl.uniform1i( location, value );
  7946. // single float
  7947. } else if( type === "f" ) {
  7948. _gl.uniform1f( location, value );
  7949. // single THREE.Vector2
  7950. } else if( type === "v2" ) {
  7951. _gl.uniform2f( location, value.x, value.y );
  7952. // single THREE.Vector3
  7953. } else if( type === "v3" ) {
  7954. _gl.uniform3f( location, value.x, value.y, value.z );
  7955. // single THREE.Vector4
  7956. } else if( type === "v4" ) {
  7957. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  7958. // single THREE.Color
  7959. } else if( type === "c" ) {
  7960. _gl.uniform3f( location, value.r, value.g, value.b );
  7961. // flat array of floats (JS or typed array)
  7962. } else if( type === "fv1" ) {
  7963. _gl.uniform1fv( location, value );
  7964. // flat array of floats with 3 x N size (JS or typed array)
  7965. } else if( type === "fv" ) {
  7966. _gl.uniform3fv( location, value );
  7967. // array of THREE.Vector2
  7968. } else if( type === "v2v" ) {
  7969. if ( ! uniform._array ) {
  7970. uniform._array = new Float32Array( 2 * value.length );
  7971. }
  7972. for ( i = 0, il = value.length; i < il; i ++ ) {
  7973. offset = i * 2;
  7974. uniform._array[ offset ] = value[ i ].x;
  7975. uniform._array[ offset + 1 ] = value[ i ].y;
  7976. }
  7977. _gl.uniform2fv( location, uniform._array );
  7978. // array of THREE.Vector3
  7979. } else if( type === "v3v" ) {
  7980. if ( ! uniform._array ) {
  7981. uniform._array = new Float32Array( 3 * value.length );
  7982. }
  7983. for ( i = 0, il = value.length; i < il; i ++ ) {
  7984. offset = i * 3;
  7985. uniform._array[ offset ] = value[ i ].x;
  7986. uniform._array[ offset + 1 ] = value[ i ].y;
  7987. uniform._array[ offset + 2 ] = value[ i ].z;
  7988. }
  7989. _gl.uniform3fv( location, uniform._array );
  7990. // array of THREE.Vector4
  7991. } else if( type == "v4v" ) {
  7992. if ( ! uniform._array ) {
  7993. uniform._array = new Float32Array( 4 * value.length );
  7994. }
  7995. for ( i = 0, il = value.length; i < il; i ++ ) {
  7996. offset = i * 4;
  7997. uniform._array[ offset ] = value[ i ].x;
  7998. uniform._array[ offset + 1 ] = value[ i ].y;
  7999. uniform._array[ offset + 2 ] = value[ i ].z;
  8000. uniform._array[ offset + 3 ] = value[ i ].w;
  8001. }
  8002. _gl.uniform4fv( location, uniform._array );
  8003. // single THREE.Matrix4
  8004. } else if( type === "m4" ) {
  8005. if ( ! uniform._array ) {
  8006. uniform._array = new Float32Array( 16 );
  8007. }
  8008. value.flattenToArray( uniform._array );
  8009. _gl.uniformMatrix4fv( location, false, uniform._array );
  8010. // array of THREE.Matrix4
  8011. } else if( type === "m4v" ) {
  8012. if ( ! uniform._array ) {
  8013. uniform._array = new Float32Array( 16 * value.length );
  8014. }
  8015. for ( i = 0, il = value.length; i < il; i ++ ) {
  8016. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  8017. }
  8018. _gl.uniformMatrix4fv( location, false, uniform._array );
  8019. // single THREE.Texture (2d or cube)
  8020. } else if( type === "t" ) {
  8021. _gl.uniform1i( location, value );
  8022. texture = uniform.texture;
  8023. if ( !texture ) continue;
  8024. if ( texture.image instanceof Array && texture.image.length === 6 ) {
  8025. setCubeTexture( texture, value );
  8026. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  8027. setCubeTextureDynamic( texture, value );
  8028. } else {
  8029. _this.setTexture( texture, value );
  8030. }
  8031. // array of THREE.Texture (2d)
  8032. } else if( type === "tv" ) {
  8033. if ( ! uniform._array ) {
  8034. uniform._array = [];
  8035. for( i = 0, il = uniform.texture.length; i < il; i ++ ) {
  8036. uniform._array[ i ] = value + i;
  8037. }
  8038. }
  8039. _gl.uniform1iv( location, uniform._array );
  8040. for( i = 0, il = uniform.texture.length; i < il; i ++ ) {
  8041. texture = uniform.texture[ i ];
  8042. if ( !texture ) continue;
  8043. _this.setTexture( texture, uniform._array[ i ] );
  8044. }
  8045. }
  8046. }
  8047. };
  8048. function setupMatrices ( object, camera ) {
  8049. object._modelViewMatrix.multiply( camera.matrixWorldInverse, object.matrixWorld);
  8050. object._normalMatrix.getInverse( object._modelViewMatrix );
  8051. object._normalMatrix.transpose();
  8052. };
  8053. function setupLights ( program, lights ) {
  8054. var l, ll, light, n,
  8055. r = 0, g = 0, b = 0,
  8056. color, position, intensity, distance,
  8057. zlights = _lights,
  8058. dcolors = zlights.directional.colors,
  8059. dpositions = zlights.directional.positions,
  8060. pcolors = zlights.point.colors,
  8061. ppositions = zlights.point.positions,
  8062. pdistances = zlights.point.distances,
  8063. scolors = zlights.spot.colors,
  8064. spositions = zlights.spot.positions,
  8065. sdistances = zlights.spot.distances,
  8066. sdirections = zlights.spot.directions,
  8067. sangles = zlights.spot.angles,
  8068. sexponents = zlights.spot.exponents,
  8069. dlength = 0,
  8070. plength = 0,
  8071. slength = 0,
  8072. doffset = 0,
  8073. poffset = 0,
  8074. soffset = 0;
  8075. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  8076. light = lights[ l ];
  8077. if ( light.onlyShadow ) continue;
  8078. color = light.color;
  8079. intensity = light.intensity;
  8080. distance = light.distance;
  8081. if ( light instanceof THREE.AmbientLight ) {
  8082. if ( _this.gammaInput ) {
  8083. r += color.r * color.r;
  8084. g += color.g * color.g;
  8085. b += color.b * color.b;
  8086. } else {
  8087. r += color.r;
  8088. g += color.g;
  8089. b += color.b;
  8090. }
  8091. } else if ( light instanceof THREE.DirectionalLight ) {
  8092. doffset = dlength * 3;
  8093. if ( _this.gammaInput ) {
  8094. dcolors[ doffset ] = color.r * color.r * intensity * intensity;
  8095. dcolors[ doffset + 1 ] = color.g * color.g * intensity * intensity;
  8096. dcolors[ doffset + 2 ] = color.b * color.b * intensity * intensity;
  8097. } else {
  8098. dcolors[ doffset ] = color.r * intensity;
  8099. dcolors[ doffset + 1 ] = color.g * intensity;
  8100. dcolors[ doffset + 2 ] = color.b * intensity;
  8101. }
  8102. _direction.copy( light.matrixWorld.getPosition() );
  8103. _direction.subSelf( light.target.matrixWorld.getPosition() );
  8104. _direction.normalize();
  8105. dpositions[ doffset ] = _direction.x;
  8106. dpositions[ doffset + 1 ] = _direction.y;
  8107. dpositions[ doffset + 2 ] = _direction.z;
  8108. dlength += 1;
  8109. } else if( light instanceof THREE.PointLight ) {
  8110. poffset = plength * 3;
  8111. if ( _this.gammaInput ) {
  8112. pcolors[ poffset ] = color.r * color.r * intensity * intensity;
  8113. pcolors[ poffset + 1 ] = color.g * color.g * intensity * intensity;
  8114. pcolors[ poffset + 2 ] = color.b * color.b * intensity * intensity;
  8115. } else {
  8116. pcolors[ poffset ] = color.r * intensity;
  8117. pcolors[ poffset + 1 ] = color.g * intensity;
  8118. pcolors[ poffset + 2 ] = color.b * intensity;
  8119. }
  8120. position = light.matrixWorld.getPosition();
  8121. ppositions[ poffset ] = position.x;
  8122. ppositions[ poffset + 1 ] = position.y;
  8123. ppositions[ poffset + 2 ] = position.z;
  8124. pdistances[ plength ] = distance;
  8125. plength += 1;
  8126. } else if( light instanceof THREE.SpotLight ) {
  8127. soffset = slength * 3;
  8128. if ( _this.gammaInput ) {
  8129. scolors[ soffset ] = color.r * color.r * intensity * intensity;
  8130. scolors[ soffset + 1 ] = color.g * color.g * intensity * intensity;
  8131. scolors[ soffset + 2 ] = color.b * color.b * intensity * intensity;
  8132. } else {
  8133. scolors[ soffset ] = color.r * intensity;
  8134. scolors[ soffset + 1 ] = color.g * intensity;
  8135. scolors[ soffset + 2 ] = color.b * intensity;
  8136. }
  8137. position = light.matrixWorld.getPosition();
  8138. spositions[ soffset ] = position.x;
  8139. spositions[ soffset + 1 ] = position.y;
  8140. spositions[ soffset + 2 ] = position.z;
  8141. sdistances[ slength ] = distance;
  8142. _direction.copy( position );
  8143. _direction.subSelf( light.target.matrixWorld.getPosition() );
  8144. _direction.normalize();
  8145. sdirections[ soffset ] = _direction.x;
  8146. sdirections[ soffset + 1 ] = _direction.y;
  8147. sdirections[ soffset + 2 ] = _direction.z;
  8148. sangles[ slength ] = Math.cos( light.angle );
  8149. sexponents[ slength ] = light.exponent;
  8150. slength += 1;
  8151. }
  8152. }
  8153. // null eventual remains from removed lights
  8154. // (this is to avoid if in shader)
  8155. for ( l = dlength * 3, ll = dcolors.length; l < ll; l ++ ) dcolors[ l ] = 0.0;
  8156. for ( l = plength * 3, ll = pcolors.length; l < ll; l ++ ) pcolors[ l ] = 0.0;
  8157. for ( l = slength * 3, ll = scolors.length; l < ll; l ++ ) scolors[ l ] = 0.0;
  8158. zlights.directional.length = dlength;
  8159. zlights.point.length = plength;
  8160. zlights.spot.length = slength;
  8161. zlights.ambient[ 0 ] = r;
  8162. zlights.ambient[ 1 ] = g;
  8163. zlights.ambient[ 2 ] = b;
  8164. };
  8165. // GL state setting
  8166. this.setFaceCulling = function ( cullFace, frontFace ) {
  8167. if ( cullFace ) {
  8168. if ( !frontFace || frontFace === "ccw" ) {
  8169. _gl.frontFace( _gl.CCW );
  8170. } else {
  8171. _gl.frontFace( _gl.CW );
  8172. }
  8173. if( cullFace === "back" ) {
  8174. _gl.cullFace( _gl.BACK );
  8175. } else if( cullFace === "front" ) {
  8176. _gl.cullFace( _gl.FRONT );
  8177. } else {
  8178. _gl.cullFace( _gl.FRONT_AND_BACK );
  8179. }
  8180. _gl.enable( _gl.CULL_FACE );
  8181. } else {
  8182. _gl.disable( _gl.CULL_FACE );
  8183. }
  8184. };
  8185. this.setObjectFaces = function ( object ) {
  8186. if ( _oldDoubleSided !== object.doubleSided ) {
  8187. if( object.doubleSided ) {
  8188. _gl.disable( _gl.CULL_FACE );
  8189. } else {
  8190. _gl.enable( _gl.CULL_FACE );
  8191. }
  8192. _oldDoubleSided = object.doubleSided;
  8193. }
  8194. if ( _oldFlipSided !== object.flipSided ) {
  8195. if( object.flipSided ) {
  8196. _gl.frontFace( _gl.CW );
  8197. } else {
  8198. _gl.frontFace( _gl.CCW );
  8199. }
  8200. _oldFlipSided = object.flipSided;
  8201. }
  8202. };
  8203. this.setDepthTest = function ( depthTest ) {
  8204. if ( _oldDepthTest !== depthTest ) {
  8205. if ( depthTest ) {
  8206. _gl.enable( _gl.DEPTH_TEST );
  8207. } else {
  8208. _gl.disable( _gl.DEPTH_TEST );
  8209. }
  8210. _oldDepthTest = depthTest;
  8211. }
  8212. };
  8213. this.setDepthWrite = function ( depthWrite ) {
  8214. if ( _oldDepthWrite !== depthWrite ) {
  8215. _gl.depthMask( depthWrite );
  8216. _oldDepthWrite = depthWrite;
  8217. }
  8218. };
  8219. function setLineWidth ( width ) {
  8220. if ( width !== _oldLineWidth ) {
  8221. _gl.lineWidth( width );
  8222. _oldLineWidth = width;
  8223. }
  8224. };
  8225. function setPolygonOffset ( polygonoffset, factor, units ) {
  8226. if ( _oldPolygonOffset !== polygonoffset ) {
  8227. if ( polygonoffset ) {
  8228. _gl.enable( _gl.POLYGON_OFFSET_FILL );
  8229. } else {
  8230. _gl.disable( _gl.POLYGON_OFFSET_FILL );
  8231. }
  8232. _oldPolygonOffset = polygonoffset;
  8233. }
  8234. if ( polygonoffset && ( _oldPolygonOffsetFactor !== factor || _oldPolygonOffsetUnits !== units ) ) {
  8235. _gl.polygonOffset( factor, units );
  8236. _oldPolygonOffsetFactor = factor;
  8237. _oldPolygonOffsetUnits = units;
  8238. }
  8239. };
  8240. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst ) {
  8241. if ( blending !== _oldBlending ) {
  8242. switch ( blending ) {
  8243. case THREE.NoBlending:
  8244. _gl.disable( _gl.BLEND );
  8245. break;
  8246. case THREE.AdditiveBlending:
  8247. _gl.enable( _gl.BLEND );
  8248. _gl.blendEquation( _gl.FUNC_ADD );
  8249. _gl.blendFunc( _gl.SRC_ALPHA, _gl.ONE );
  8250. break;
  8251. case THREE.SubtractiveBlending:
  8252. // TODO: Find blendFuncSeparate() combination
  8253. _gl.enable( _gl.BLEND );
  8254. _gl.blendEquation( _gl.FUNC_ADD );
  8255. _gl.blendFunc( _gl.ZERO, _gl.ONE_MINUS_SRC_COLOR );
  8256. break;
  8257. case THREE.MultiplyBlending:
  8258. // TODO: Find blendFuncSeparate() combination
  8259. _gl.enable( _gl.BLEND );
  8260. _gl.blendEquation( _gl.FUNC_ADD );
  8261. _gl.blendFunc( _gl.ZERO, _gl.SRC_COLOR );
  8262. break;
  8263. case THREE.CustomBlending:
  8264. _gl.enable( _gl.BLEND );
  8265. break;
  8266. default:
  8267. _gl.enable( _gl.BLEND );
  8268. _gl.blendEquationSeparate( _gl.FUNC_ADD, _gl.FUNC_ADD );
  8269. _gl.blendFuncSeparate( _gl.SRC_ALPHA, _gl.ONE_MINUS_SRC_ALPHA, _gl.ONE, _gl.ONE_MINUS_SRC_ALPHA );
  8270. break;
  8271. }
  8272. _oldBlending = blending;
  8273. }
  8274. if ( blending === THREE.CustomBlending ) {
  8275. if ( blendEquation !== _oldBlendEquation ) {
  8276. _gl.blendEquation( paramThreeToGL( blendEquation ) );
  8277. _oldBlendEquation = blendEquation;
  8278. }
  8279. if ( blendSrc !== _oldBlendSrc || blendDst !== _oldBlendDst ) {
  8280. _gl.blendFunc( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ) );
  8281. _oldBlendSrc = blendSrc;
  8282. _oldBlendDst = blendDst;
  8283. }
  8284. } else {
  8285. _oldBlendEquation = null;
  8286. _oldBlendSrc = null;
  8287. _oldBlendDst = null;
  8288. }
  8289. };
  8290. // Shaders
  8291. function buildProgram ( shaderID, fragmentShader, vertexShader, uniforms, attributes, parameters ) {
  8292. var p, pl, program, code;
  8293. var chunks = [];
  8294. // Generate code
  8295. if ( shaderID ) {
  8296. chunks.push( shaderID );
  8297. } else {
  8298. chunks.push( fragmentShader );
  8299. chunks.push( vertexShader );
  8300. }
  8301. for ( p in parameters ) {
  8302. chunks.push( p );
  8303. chunks.push( parameters[ p ] );
  8304. }
  8305. code = chunks.join();
  8306. // Check if code has been already compiled
  8307. for ( p = 0, pl = _programs.length; p < pl; p ++ ) {
  8308. if ( _programs[ p ].code === code ) {
  8309. // console.log( "Code already compiled." /*: \n\n" + code*/ );
  8310. return _programs[ p ].program;
  8311. }
  8312. }
  8313. //console.log( "building new program " );
  8314. //
  8315. program = _gl.createProgram();
  8316. var prefix_vertex = [
  8317. "precision " + _precision + " float;",
  8318. ( _maxVertexTextures > 0 ) ? "#define VERTEX_TEXTURES" : "",
  8319. _this.gammaInput ? "#define GAMMA_INPUT" : "",
  8320. _this.gammaOutput ? "#define GAMMA_OUTPUT" : "",
  8321. _this.physicallyBasedShading ? "#define PHYSICALLY_BASED_SHADING" : "",
  8322. "#define MAX_DIR_LIGHTS " + parameters.maxDirLights,
  8323. "#define MAX_POINT_LIGHTS " + parameters.maxPointLights,
  8324. "#define MAX_SPOT_LIGHTS " + parameters.maxSpotLights,
  8325. "#define MAX_SHADOWS " + parameters.maxShadows,
  8326. "#define MAX_BONES " + parameters.maxBones,
  8327. parameters.map ? "#define USE_MAP" : "",
  8328. parameters.envMap ? "#define USE_ENVMAP" : "",
  8329. parameters.lightMap ? "#define USE_LIGHTMAP" : "",
  8330. parameters.vertexColors ? "#define USE_COLOR" : "",
  8331. parameters.skinning ? "#define USE_SKINNING" : "",
  8332. parameters.morphTargets ? "#define USE_MORPHTARGETS" : "",
  8333. parameters.morphNormals ? "#define USE_MORPHNORMALS" : "",
  8334. parameters.perPixel ? "#define PHONG_PER_PIXEL" : "",
  8335. parameters.wrapAround ? "#define WRAP_AROUND" : "",
  8336. parameters.doubleSided ? "#define DOUBLE_SIDED" : "",
  8337. parameters.shadowMapEnabled ? "#define USE_SHADOWMAP" : "",
  8338. parameters.shadowMapSoft ? "#define SHADOWMAP_SOFT" : "",
  8339. parameters.shadowMapDebug ? "#define SHADOWMAP_DEBUG" : "",
  8340. parameters.shadowMapCascade ? "#define SHADOWMAP_CASCADE" : "",
  8341. parameters.sizeAttenuation ? "#define USE_SIZEATTENUATION" : "",
  8342. "uniform mat4 objectMatrix;",
  8343. "uniform mat4 modelViewMatrix;",
  8344. "uniform mat4 projectionMatrix;",
  8345. "uniform mat4 viewMatrix;",
  8346. "uniform mat3 normalMatrix;",
  8347. "uniform vec3 cameraPosition;",
  8348. "attribute vec3 position;",
  8349. "attribute vec3 normal;",
  8350. "attribute vec2 uv;",
  8351. "attribute vec2 uv2;",
  8352. "#ifdef USE_COLOR",
  8353. "attribute vec3 color;",
  8354. "#endif",
  8355. "#ifdef USE_MORPHTARGETS",
  8356. "attribute vec3 morphTarget0;",
  8357. "attribute vec3 morphTarget1;",
  8358. "attribute vec3 morphTarget2;",
  8359. "attribute vec3 morphTarget3;",
  8360. "#ifdef USE_MORPHNORMALS",
  8361. "attribute vec3 morphNormal0;",
  8362. "attribute vec3 morphNormal1;",
  8363. "attribute vec3 morphNormal2;",
  8364. "attribute vec3 morphNormal3;",
  8365. "#else",
  8366. "attribute vec3 morphTarget4;",
  8367. "attribute vec3 morphTarget5;",
  8368. "attribute vec3 morphTarget6;",
  8369. "attribute vec3 morphTarget7;",
  8370. "#endif",
  8371. "#endif",
  8372. "#ifdef USE_SKINNING",
  8373. "attribute vec4 skinVertexA;",
  8374. "attribute vec4 skinVertexB;",
  8375. "attribute vec4 skinIndex;",
  8376. "attribute vec4 skinWeight;",
  8377. "#endif",
  8378. ""
  8379. ].join("\n");
  8380. var prefix_fragment = [
  8381. "precision " + _precision + " float;",
  8382. "#define MAX_DIR_LIGHTS " + parameters.maxDirLights,
  8383. "#define MAX_POINT_LIGHTS " + parameters.maxPointLights,
  8384. "#define MAX_SPOT_LIGHTS " + parameters.maxSpotLights,
  8385. "#define MAX_SHADOWS " + parameters.maxShadows,
  8386. parameters.alphaTest ? "#define ALPHATEST " + parameters.alphaTest: "",
  8387. _this.gammaInput ? "#define GAMMA_INPUT" : "",
  8388. _this.gammaOutput ? "#define GAMMA_OUTPUT" : "",
  8389. _this.physicallyBasedShading ? "#define PHYSICALLY_BASED_SHADING" : "",
  8390. ( parameters.useFog && parameters.fog ) ? "#define USE_FOG" : "",
  8391. ( parameters.useFog && parameters.fog instanceof THREE.FogExp2 ) ? "#define FOG_EXP2" : "",
  8392. parameters.map ? "#define USE_MAP" : "",
  8393. parameters.envMap ? "#define USE_ENVMAP" : "",
  8394. parameters.lightMap ? "#define USE_LIGHTMAP" : "",
  8395. parameters.vertexColors ? "#define USE_COLOR" : "",
  8396. parameters.metal ? "#define METAL" : "",
  8397. parameters.perPixel ? "#define PHONG_PER_PIXEL" : "",
  8398. parameters.wrapAround ? "#define WRAP_AROUND" : "",
  8399. parameters.doubleSided ? "#define DOUBLE_SIDED" : "",
  8400. parameters.shadowMapEnabled ? "#define USE_SHADOWMAP" : "",
  8401. parameters.shadowMapSoft ? "#define SHADOWMAP_SOFT" : "",
  8402. parameters.shadowMapDebug ? "#define SHADOWMAP_DEBUG" : "",
  8403. parameters.shadowMapCascade ? "#define SHADOWMAP_CASCADE" : "",
  8404. "uniform mat4 viewMatrix;",
  8405. "uniform vec3 cameraPosition;",
  8406. ""
  8407. ].join("\n");
  8408. _gl.attachShader( program, getShader( "fragment", prefix_fragment + fragmentShader ) );
  8409. _gl.attachShader( program, getShader( "vertex", prefix_vertex + vertexShader ) );
  8410. _gl.linkProgram( program );
  8411. if ( !_gl.getProgramParameter( program, _gl.LINK_STATUS ) ) {
  8412. console.error( "Could not initialise shader\n" + "VALIDATE_STATUS: " + _gl.getProgramParameter( program, _gl.VALIDATE_STATUS ) + ", gl error [" + _gl.getError() + "]" );
  8413. }
  8414. //console.log( prefix_fragment + fragmentShader );
  8415. //console.log( prefix_vertex + vertexShader );
  8416. program.uniforms = {};
  8417. program.attributes = {};
  8418. var identifiers, u, a, i;
  8419. // cache uniform locations
  8420. identifiers = [
  8421. 'viewMatrix', 'modelViewMatrix', 'projectionMatrix', 'normalMatrix', 'objectMatrix', 'cameraPosition',
  8422. 'boneGlobalMatrices', 'morphTargetInfluences'
  8423. ];
  8424. for ( u in uniforms ) {
  8425. identifiers.push( u );
  8426. }
  8427. cacheUniformLocations( program, identifiers );
  8428. // cache attributes locations
  8429. identifiers = [
  8430. "position", "normal", "uv", "uv2", "tangent", "color",
  8431. "skinVertexA", "skinVertexB", "skinIndex", "skinWeight"
  8432. ];
  8433. for ( i = 0; i < parameters.maxMorphTargets; i ++ ) {
  8434. identifiers.push( "morphTarget" + i );
  8435. }
  8436. for ( i = 0; i < parameters.maxMorphNormals; i ++ ) {
  8437. identifiers.push( "morphNormal" + i );
  8438. }
  8439. for ( a in attributes ) {
  8440. identifiers.push( a );
  8441. }
  8442. cacheAttributeLocations( program, identifiers );
  8443. program.id = _programs.length;
  8444. _programs.push( { program: program, code: code } );
  8445. _this.info.memory.programs = _programs.length;
  8446. return program;
  8447. };
  8448. // Shader parameters cache
  8449. function cacheUniformLocations ( program, identifiers ) {
  8450. var i, l, id;
  8451. for( i = 0, l = identifiers.length; i < l; i ++ ) {
  8452. id = identifiers[ i ];
  8453. program.uniforms[ id ] = _gl.getUniformLocation( program, id );
  8454. }
  8455. };
  8456. function cacheAttributeLocations ( program, identifiers ) {
  8457. var i, l, id;
  8458. for( i = 0, l = identifiers.length; i < l; i ++ ) {
  8459. id = identifiers[ i ];
  8460. program.attributes[ id ] = _gl.getAttribLocation( program, id );
  8461. }
  8462. };
  8463. function getShader ( type, string ) {
  8464. var shader;
  8465. if ( type === "fragment" ) {
  8466. shader = _gl.createShader( _gl.FRAGMENT_SHADER );
  8467. } else if ( type === "vertex" ) {
  8468. shader = _gl.createShader( _gl.VERTEX_SHADER );
  8469. }
  8470. _gl.shaderSource( shader, string );
  8471. _gl.compileShader( shader );
  8472. if ( !_gl.getShaderParameter( shader, _gl.COMPILE_STATUS ) ) {
  8473. console.error( _gl.getShaderInfoLog( shader ) );
  8474. console.error( string );
  8475. return null;
  8476. }
  8477. return shader;
  8478. };
  8479. // Textures
  8480. function isPowerOfTwo ( value ) {
  8481. return ( value & ( value - 1 ) ) === 0;
  8482. };
  8483. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  8484. if ( isImagePowerOfTwo ) {
  8485. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  8486. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  8487. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  8488. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  8489. } else {
  8490. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  8491. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  8492. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  8493. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  8494. }
  8495. };
  8496. this.setTexture = function ( texture, slot ) {
  8497. if ( texture.needsUpdate ) {
  8498. if ( ! texture.__webglInit ) {
  8499. texture.__webglInit = true;
  8500. texture.__webglTexture = _gl.createTexture();
  8501. _this.info.memory.textures ++;
  8502. }
  8503. _gl.activeTexture( _gl.TEXTURE0 + slot );
  8504. _gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
  8505. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  8506. var image = texture.image,
  8507. isImagePowerOfTwo = isPowerOfTwo( image.width ) && isPowerOfTwo( image.height ),
  8508. glFormat = paramThreeToGL( texture.format ),
  8509. glType = paramThreeToGL( texture.type );
  8510. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  8511. if ( texture instanceof THREE.DataTexture ) {
  8512. _gl.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  8513. } else {
  8514. _gl.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  8515. }
  8516. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  8517. texture.needsUpdate = false;
  8518. if ( texture.onUpdate ) texture.onUpdate();
  8519. } else {
  8520. _gl.activeTexture( _gl.TEXTURE0 + slot );
  8521. _gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
  8522. }
  8523. };
  8524. function clampToMaxSize ( image, maxSize ) {
  8525. if ( image.width <= maxSize && image.height <= maxSize ) {
  8526. return image;
  8527. }
  8528. // Warning: Scaling through the canvas will only work with images that use
  8529. // premultiplied alpha.
  8530. var maxDimension = Math.max( image.width, image.height );
  8531. var newWidth = Math.floor( image.width * maxSize / maxDimension );
  8532. var newHeight = Math.floor( image.height * maxSize / maxDimension );
  8533. var canvas = document.createElement( 'canvas' );
  8534. canvas.width = newWidth;
  8535. canvas.height = newHeight;
  8536. var ctx = canvas.getContext( "2d" );
  8537. ctx.drawImage( image, 0, 0, image.width, image.height, 0, 0, newWidth, newHeight );
  8538. return canvas;
  8539. }
  8540. function setCubeTexture ( texture, slot ) {
  8541. if ( texture.image.length === 6 ) {
  8542. if ( texture.needsUpdate ) {
  8543. if ( ! texture.image.__webglTextureCube ) {
  8544. texture.image.__webglTextureCube = _gl.createTexture();
  8545. }
  8546. _gl.activeTexture( _gl.TEXTURE0 + slot );
  8547. _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, texture.image.__webglTextureCube );
  8548. var cubeImage = [];
  8549. for ( var i = 0; i < 6; i ++ ) {
  8550. if ( _this.autoScaleCubemaps ) {
  8551. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], _maxCubemapSize );
  8552. } else {
  8553. cubeImage[ i ] = texture.image[ i ];
  8554. }
  8555. }
  8556. var image = cubeImage[ 0 ],
  8557. isImagePowerOfTwo = isPowerOfTwo( image.width ) && isPowerOfTwo( image.height ),
  8558. glFormat = paramThreeToGL( texture.format ),
  8559. glType = paramThreeToGL( texture.type );
  8560. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  8561. for ( var i = 0; i < 6; i ++ ) {
  8562. _gl.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  8563. }
  8564. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  8565. texture.needsUpdate = false;
  8566. if ( texture.onUpdate ) texture.onUpdate();
  8567. } else {
  8568. _gl.activeTexture( _gl.TEXTURE0 + slot );
  8569. _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, texture.image.__webglTextureCube );
  8570. }
  8571. }
  8572. };
  8573. function setCubeTextureDynamic ( texture, slot ) {
  8574. _gl.activeTexture( _gl.TEXTURE0 + slot );
  8575. _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, texture.__webglTexture );
  8576. };
  8577. // Render targets
  8578. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  8579. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  8580. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, renderTarget.__webglTexture, 0 );
  8581. };
  8582. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  8583. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  8584. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  8585. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  8586. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  8587. /* For some reason this is not working. Defaulting to RGBA4.
  8588. } else if( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  8589. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  8590. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  8591. */
  8592. } else if( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  8593. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  8594. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  8595. } else {
  8596. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  8597. }
  8598. };
  8599. this.setRenderTarget = function ( renderTarget ) {
  8600. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  8601. if ( renderTarget && ! renderTarget.__webglFramebuffer ) {
  8602. if( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  8603. if( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  8604. renderTarget.__webglTexture = _gl.createTexture();
  8605. // Setup texture, create render and frame buffers
  8606. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget.width ) && isPowerOfTwo( renderTarget.height ),
  8607. glFormat = paramThreeToGL( renderTarget.format ),
  8608. glType = paramThreeToGL( renderTarget.type );
  8609. if ( isCube ) {
  8610. renderTarget.__webglFramebuffer = [];
  8611. renderTarget.__webglRenderbuffer = [];
  8612. _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTarget.__webglTexture );
  8613. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget, isTargetPowerOfTwo );
  8614. for ( var i = 0; i < 6; i ++ ) {
  8615. renderTarget.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  8616. renderTarget.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  8617. _gl.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  8618. setupFrameBuffer( renderTarget.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  8619. setupRenderBuffer( renderTarget.__webglRenderbuffer[ i ], renderTarget );
  8620. }
  8621. if ( isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  8622. } else {
  8623. renderTarget.__webglFramebuffer = _gl.createFramebuffer();
  8624. renderTarget.__webglRenderbuffer = _gl.createRenderbuffer();
  8625. _gl.bindTexture( _gl.TEXTURE_2D, renderTarget.__webglTexture );
  8626. setTextureParameters( _gl.TEXTURE_2D, renderTarget, isTargetPowerOfTwo );
  8627. _gl.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  8628. setupFrameBuffer( renderTarget.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  8629. setupRenderBuffer( renderTarget.__webglRenderbuffer, renderTarget );
  8630. if ( isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  8631. }
  8632. // Release everything
  8633. if ( isCube ) {
  8634. _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  8635. } else {
  8636. _gl.bindTexture( _gl.TEXTURE_2D, null );
  8637. }
  8638. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  8639. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null);
  8640. }
  8641. var framebuffer, width, height, vx, vy;
  8642. if ( renderTarget ) {
  8643. if ( isCube ) {
  8644. framebuffer = renderTarget.__webglFramebuffer[ renderTarget.activeCubeFace ];
  8645. } else {
  8646. framebuffer = renderTarget.__webglFramebuffer;
  8647. }
  8648. width = renderTarget.width;
  8649. height = renderTarget.height;
  8650. vx = 0;
  8651. vy = 0;
  8652. } else {
  8653. framebuffer = null;
  8654. width = _viewportWidth;
  8655. height = _viewportHeight;
  8656. vx = _viewportX;
  8657. vy = _viewportY;
  8658. }
  8659. if ( framebuffer !== _currentFramebuffer ) {
  8660. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  8661. _gl.viewport( vx, vy, width, height );
  8662. _currentFramebuffer = framebuffer;
  8663. }
  8664. _currentWidth = width;
  8665. _currentHeight = height;
  8666. };
  8667. function updateRenderTargetMipmap ( renderTarget ) {
  8668. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  8669. _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTarget.__webglTexture );
  8670. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  8671. _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  8672. } else {
  8673. _gl.bindTexture( _gl.TEXTURE_2D, renderTarget.__webglTexture );
  8674. _gl.generateMipmap( _gl.TEXTURE_2D );
  8675. _gl.bindTexture( _gl.TEXTURE_2D, null );
  8676. }
  8677. };
  8678. // Fallback filters for non-power-of-2 textures
  8679. function filterFallback ( f ) {
  8680. switch ( f ) {
  8681. case THREE.NearestFilter:
  8682. case THREE.NearestMipMapNearestFilter:
  8683. case THREE.NearestMipMapLinearFilter: return _gl.NEAREST; break;
  8684. case THREE.LinearFilter:
  8685. case THREE.LinearMipMapNearestFilter:
  8686. case THREE.LinearMipMapLinearFilter:
  8687. default:
  8688. return _gl.LINEAR; break;
  8689. }
  8690. };
  8691. // Map three.js constants to WebGL constants
  8692. function paramThreeToGL ( p ) {
  8693. switch ( p ) {
  8694. case THREE.RepeatWrapping: return _gl.REPEAT; break;
  8695. case THREE.ClampToEdgeWrapping: return _gl.CLAMP_TO_EDGE; break;
  8696. case THREE.MirroredRepeatWrapping: return _gl.MIRRORED_REPEAT; break;
  8697. case THREE.NearestFilter: return _gl.NEAREST; break;
  8698. case THREE.NearestMipMapNearestFilter: return _gl.NEAREST_MIPMAP_NEAREST; break;
  8699. case THREE.NearestMipMapLinearFilter: return _gl.NEAREST_MIPMAP_LINEAR; break;
  8700. case THREE.LinearFilter: return _gl.LINEAR; break;
  8701. case THREE.LinearMipMapNearestFilter: return _gl.LINEAR_MIPMAP_NEAREST; break;
  8702. case THREE.LinearMipMapLinearFilter: return _gl.LINEAR_MIPMAP_LINEAR; break;
  8703. case THREE.ByteType: return _gl.BYTE; break;
  8704. case THREE.UnsignedByteType: return _gl.UNSIGNED_BYTE; break;
  8705. case THREE.ShortType: return _gl.SHORT; break;
  8706. case THREE.UnsignedShortType: return _gl.UNSIGNED_SHORT; break;
  8707. case THREE.IntType: return _gl.INT; break;
  8708. case THREE.UnsignedIntType: return _gl.UNSIGNED_INT; break;
  8709. case THREE.FloatType: return _gl.FLOAT; break;
  8710. case THREE.AlphaFormat: return _gl.ALPHA; break;
  8711. case THREE.RGBFormat: return _gl.RGB; break;
  8712. case THREE.RGBAFormat: return _gl.RGBA; break;
  8713. case THREE.LuminanceFormat: return _gl.LUMINANCE; break;
  8714. case THREE.LuminanceAlphaFormat: return _gl.LUMINANCE_ALPHA; break;
  8715. case THREE.AddEquation: return _gl.FUNC_ADD; break;
  8716. case THREE.SubtractEquation: return _gl.FUNC_SUBTRACT; break;
  8717. case THREE.ReverseSubtractEquation: return _gl.FUNC_REVERSE_SUBTRACT; break;
  8718. case THREE.ZeroFactor: return _gl.ZERO; break;
  8719. case THREE.OneFactor: return _gl.ONE; break;
  8720. case THREE.SrcColorFactor: return _gl.SRC_COLOR; break;
  8721. case THREE.OneMinusSrcColorFactor: return _gl.ONE_MINUS_SRC_COLOR; break;
  8722. case THREE.SrcAlphaFactor: return _gl.SRC_ALPHA; break;
  8723. case THREE.OneMinusSrcAlphaFactor: return _gl.ONE_MINUS_SRC_ALPHA; break;
  8724. case THREE.DstAlphaFactor: return _gl.DST_ALPHA; break;
  8725. case THREE.OneMinusDstAlphaFactor: return _gl.ONE_MINUS_DST_ALPHA; break;
  8726. case THREE.DstColorFactor: return _gl.DST_COLOR; break;
  8727. case THREE.OneMinusDstColorFactor: return _gl.ONE_MINUS_DST_COLOR; break;
  8728. case THREE.SrcAlphaSaturateFactor: return _gl.SRC_ALPHA_SATURATE; break;
  8729. }
  8730. return 0;
  8731. };
  8732. // Allocations
  8733. function allocateBones ( object ) {
  8734. // default for when object is not specified
  8735. // ( for example when prebuilding shader
  8736. // to be used with multiple objects )
  8737. //
  8738. // - leave some extra space for other uniforms
  8739. // - limit here is ANGLE's 254 max uniform vectors
  8740. // (up to 54 should be safe)
  8741. var maxBones = 50;
  8742. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  8743. maxBones = object.bones.length;
  8744. }
  8745. return maxBones;
  8746. };
  8747. function allocateLights ( lights ) {
  8748. var l, ll, light, dirLights, pointLights, spotLights, maxDirLights, maxPointLights, maxSpotLights;
  8749. dirLights = pointLights = spotLights = maxDirLights = maxPointLights = maxSpotLights = 0;
  8750. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  8751. light = lights[ l ];
  8752. if ( light.onlyShadow ) continue;
  8753. if ( light instanceof THREE.DirectionalLight ) dirLights ++;
  8754. if ( light instanceof THREE.PointLight ) pointLights ++;
  8755. if ( light instanceof THREE.SpotLight ) spotLights ++;
  8756. }
  8757. if ( ( pointLights + spotLights + dirLights ) <= _maxLights ) {
  8758. maxDirLights = dirLights;
  8759. maxPointLights = pointLights;
  8760. maxSpotLights = spotLights;
  8761. } else {
  8762. maxDirLights = Math.ceil( _maxLights * dirLights / ( pointLights + dirLights ) );
  8763. maxPointLights = _maxLights - maxDirLights;
  8764. maxSpotLights = maxPointLights; // this is not really correct
  8765. }
  8766. return { 'directional' : maxDirLights, 'point' : maxPointLights, 'spot': maxSpotLights };
  8767. };
  8768. function allocateShadows ( lights ) {
  8769. var l, ll, light, maxShadows = 0;
  8770. for ( l = 0, ll = lights.length; l < ll; l++ ) {
  8771. light = lights[ l ];
  8772. if ( ! light.castShadow ) continue;
  8773. if ( light instanceof THREE.SpotLight ) maxShadows ++;
  8774. if ( light instanceof THREE.DirectionalLight && ! light.shadowCascade ) maxShadows ++;
  8775. }
  8776. return maxShadows;
  8777. };
  8778. // Initialization
  8779. function initGL () {
  8780. var gl;
  8781. try {
  8782. if ( ! ( gl = _canvas.getContext( 'experimental-webgl', { alpha: _alpha, premultipliedAlpha: _premultipliedAlpha, antialias: _antialias, stencil: _stencil, preserveDrawingBuffer: _preserveDrawingBuffer } ) ) ) {
  8783. throw 'Error creating WebGL context.';
  8784. }
  8785. } catch ( error ) {
  8786. console.error( error );
  8787. }
  8788. return gl;
  8789. };
  8790. function setDefaultGLState () {
  8791. _gl.clearColor( 0, 0, 0, 1 );
  8792. _gl.clearDepth( 1 );
  8793. _gl.clearStencil( 0 );
  8794. _gl.enable( _gl.DEPTH_TEST );
  8795. _gl.depthFunc( _gl.LEQUAL );
  8796. _gl.frontFace( _gl.CCW );
  8797. _gl.cullFace( _gl.BACK );
  8798. _gl.enable( _gl.CULL_FACE );
  8799. _gl.enable( _gl.BLEND );
  8800. _gl.blendEquation( _gl.FUNC_ADD );
  8801. _gl.blendFunc( _gl.SRC_ALPHA, _gl.ONE_MINUS_SRC_ALPHA );
  8802. _gl.clearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  8803. };
  8804. // default plugins (order is important)
  8805. this.shadowMapPlugin = new THREE.ShadowMapPlugin();
  8806. this.addPrePlugin( this.shadowMapPlugin );
  8807. this.addPostPlugin( new THREE.SpritePlugin() );
  8808. this.addPostPlugin( new THREE.LensFlarePlugin() );
  8809. };
  8810. /**
  8811. * @author szimek / https://github.com/szimek/
  8812. */
  8813. THREE.WebGLRenderTarget = function ( width, height, options ) {
  8814. this.width = width;
  8815. this.height = height;
  8816. options = options || {};
  8817. this.wrapS = options.wrapS !== undefined ? options.wrapS : THREE.ClampToEdgeWrapping;
  8818. this.wrapT = options.wrapT !== undefined ? options.wrapT : THREE.ClampToEdgeWrapping;
  8819. this.magFilter = options.magFilter !== undefined ? options.magFilter : THREE.LinearFilter;
  8820. this.minFilter = options.minFilter !== undefined ? options.minFilter : THREE.LinearMipMapLinearFilter;
  8821. this.offset = new THREE.Vector2( 0, 0 );
  8822. this.repeat = new THREE.Vector2( 1, 1 );
  8823. this.format = options.format !== undefined ? options.format : THREE.RGBAFormat;
  8824. this.type = options.type !== undefined ? options.type : THREE.UnsignedByteType;
  8825. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  8826. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  8827. this.generateMipmaps = true;
  8828. };
  8829. THREE.WebGLRenderTarget.prototype.clone = function() {
  8830. var tmp = new THREE.WebGLRenderTarget( this.width, this.height );
  8831. tmp.wrapS = this.wrapS;
  8832. tmp.wrapT = this.wrapT;
  8833. tmp.magFilter = this.magFilter;
  8834. tmp.minFilter = this.minFilter;
  8835. tmp.offset.copy( this.offset );
  8836. tmp.repeat.copy( this.repeat );
  8837. tmp.format = this.format;
  8838. tmp.type = this.type;
  8839. tmp.depthBuffer = this.depthBuffer;
  8840. tmp.stencilBuffer = this.stencilBuffer;
  8841. return tmp;
  8842. };
  8843. /**
  8844. * @author alteredq / http://alteredqualia.com
  8845. */
  8846. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  8847. THREE.WebGLRenderTarget.call( this, width, height, options );
  8848. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  8849. };
  8850. THREE.WebGLRenderTargetCube.prototype = new THREE.WebGLRenderTarget();
  8851. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  8852. /**
  8853. * @author mr.doob / http://mrdoob.com/
  8854. */
  8855. THREE.RenderableVertex = function () {
  8856. this.positionWorld = new THREE.Vector3();
  8857. this.positionScreen = new THREE.Vector4();
  8858. this.visible = true;
  8859. };
  8860. THREE.RenderableVertex.prototype.copy = function ( vertex ) {
  8861. this.positionWorld.copy( vertex.positionWorld );
  8862. this.positionScreen.copy( vertex.positionScreen );
  8863. }
  8864. /**
  8865. * @author mr.doob / http://mrdoob.com/
  8866. */
  8867. THREE.RenderableFace3 = function () {
  8868. this.v1 = new THREE.RenderableVertex();
  8869. this.v2 = new THREE.RenderableVertex();
  8870. this.v3 = new THREE.RenderableVertex();
  8871. this.centroidWorld = new THREE.Vector3();
  8872. this.centroidScreen = new THREE.Vector3();
  8873. this.normalWorld = new THREE.Vector3();
  8874. this.vertexNormalsWorld = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  8875. this.material = null;
  8876. this.faceMaterial = null;
  8877. this.uvs = [[]];
  8878. this.z = null;
  8879. };
  8880. /**
  8881. * @author mr.doob / http://mrdoob.com/
  8882. */
  8883. THREE.RenderableFace4 = function () {
  8884. this.v1 = new THREE.RenderableVertex();
  8885. this.v2 = new THREE.RenderableVertex();
  8886. this.v3 = new THREE.RenderableVertex();
  8887. this.v4 = new THREE.RenderableVertex();
  8888. this.centroidWorld = new THREE.Vector3();
  8889. this.centroidScreen = new THREE.Vector3();
  8890. this.normalWorld = new THREE.Vector3();
  8891. this.vertexNormalsWorld = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  8892. this.material = null;
  8893. this.faceMaterial = null;
  8894. this.uvs = [[]];
  8895. this.z = null;
  8896. };
  8897. /**
  8898. * @author mr.doob / http://mrdoob.com/
  8899. */
  8900. THREE.RenderableObject = function () {
  8901. this.object = null;
  8902. this.z = null;
  8903. };
  8904. /**
  8905. * @author mr.doob / http://mrdoob.com/
  8906. */
  8907. THREE.RenderableParticle = function () {
  8908. this.x = null;
  8909. this.y = null;
  8910. this.z = null;
  8911. this.rotation = null;
  8912. this.scale = new THREE.Vector2();
  8913. this.material = null;
  8914. };
  8915. /**
  8916. * @author mr.doob / http://mrdoob.com/
  8917. */
  8918. THREE.RenderableLine = function () {
  8919. this.z = null;
  8920. this.v1 = new THREE.RenderableVertex();
  8921. this.v2 = new THREE.RenderableVertex();
  8922. this.material = null;
  8923. };
  8924. /**
  8925. * @author alteredq / http://alteredqualia.com/
  8926. */
  8927. THREE.BufferGeometry = function () {
  8928. this.id = THREE.GeometryCount ++;
  8929. // GL buffers
  8930. this.vertexIndexBuffer = null;
  8931. this.vertexPositionBuffer = null;
  8932. this.vertexNormalBuffer = null;
  8933. this.vertexUvBuffer = null;
  8934. this.vertexColorBuffer = null;
  8935. // typed arrays (kept only if dynamic flag is set)
  8936. this.vertexIndexArray = null;
  8937. this.vertexPositionArray = null;
  8938. this.vertexNormalArray = null;
  8939. this.vertexUvArray = null;
  8940. this.vertexColorArray = null;
  8941. this.dynamic = false;
  8942. // boundings
  8943. this.boundingBox = null;
  8944. this.boundingSphere = null;
  8945. // for compatibility
  8946. this.morphTargets = [];
  8947. };
  8948. THREE.BufferGeometry.prototype = {
  8949. constructor : THREE.BufferGeometry,
  8950. // for compatibility
  8951. computeBoundingBox: function () {
  8952. },
  8953. // for compatibility
  8954. computeBoundingSphere: function () {
  8955. }
  8956. };
  8957. /**
  8958. * @author alteredq / http://alteredqualia.com/
  8959. */
  8960. THREE.Gyroscope = function () {
  8961. THREE.Object3D.call( this );
  8962. };
  8963. THREE.Gyroscope.prototype = new THREE.Object3D();
  8964. THREE.Gyroscope.prototype.constructor = THREE.Gyroscope;
  8965. THREE.Gyroscope.prototype.updateMatrixWorld = function ( force ) {
  8966. this.matrixAutoUpdate && this.updateMatrix();
  8967. // update matrixWorld
  8968. if ( this.matrixWorldNeedsUpdate || force ) {
  8969. if ( this.parent ) {
  8970. this.matrixWorld.multiply( this.parent.matrixWorld, this.matrix );
  8971. this.matrixWorld.decompose( this.translationWorld, this.rotationWorld, this.scaleWorld );
  8972. this.matrix.decompose( this.translationObject, this.rotationObject, this.scaleObject );
  8973. this.matrixWorld.compose( this.translationWorld, this.rotationObject, this.scaleWorld );
  8974. } else {
  8975. this.matrixWorld.copy( this.matrix );
  8976. }
  8977. this.matrixWorldNeedsUpdate = false;
  8978. force = true;
  8979. }
  8980. // update children
  8981. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  8982. this.children[ i ].updateMatrixWorld( force );
  8983. }
  8984. };
  8985. THREE.Gyroscope.prototype.translationWorld = new THREE.Vector3();
  8986. THREE.Gyroscope.prototype.translationObject = new THREE.Vector3();
  8987. THREE.Gyroscope.prototype.rotationWorld = new THREE.Quaternion();
  8988. THREE.Gyroscope.prototype.rotationObject = new THREE.Quaternion();
  8989. THREE.Gyroscope.prototype.scaleWorld = new THREE.Vector3();
  8990. THREE.Gyroscope.prototype.scaleObject = new THREE.Vector3();
  8991. /**
  8992. * @author alteredq / http://alteredqualia.com/
  8993. *
  8994. * - shows frustum, line of sight and up of the camera
  8995. * - suitable for fast updates
  8996. * - based on frustum visualization in lightgl.js shadowmap example
  8997. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  8998. */
  8999. THREE.CameraHelper = function ( camera ) {
  9000. THREE.Object3D.call( this );
  9001. var _this = this;
  9002. this.lineGeometry = new THREE.Geometry();
  9003. this.lineMaterial = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  9004. this.pointMap = {};
  9005. // colors
  9006. var hexFrustum = 0xffaa00,
  9007. hexCone = 0xff0000,
  9008. hexUp = 0x00aaff,
  9009. hexTarget = 0xffffff,
  9010. hexCross = 0x333333;
  9011. // near
  9012. addLine( "n1", "n2", hexFrustum );
  9013. addLine( "n2", "n4", hexFrustum );
  9014. addLine( "n4", "n3", hexFrustum );
  9015. addLine( "n3", "n1", hexFrustum );
  9016. // far
  9017. addLine( "f1", "f2", hexFrustum );
  9018. addLine( "f2", "f4", hexFrustum );
  9019. addLine( "f4", "f3", hexFrustum );
  9020. addLine( "f3", "f1", hexFrustum );
  9021. // sides
  9022. addLine( "n1", "f1", hexFrustum );
  9023. addLine( "n2", "f2", hexFrustum );
  9024. addLine( "n3", "f3", hexFrustum );
  9025. addLine( "n4", "f4", hexFrustum );
  9026. // cone
  9027. addLine( "p", "n1", hexCone );
  9028. addLine( "p", "n2", hexCone );
  9029. addLine( "p", "n3", hexCone );
  9030. addLine( "p", "n4", hexCone );
  9031. // up
  9032. addLine( "u1", "u2", hexUp );
  9033. addLine( "u2", "u3", hexUp );
  9034. addLine( "u3", "u1", hexUp );
  9035. // target
  9036. addLine( "c", "t", hexTarget );
  9037. addLine( "p", "c", hexCross );
  9038. // cross
  9039. addLine( "cn1", "cn2", hexCross );
  9040. addLine( "cn3", "cn4", hexCross );
  9041. addLine( "cf1", "cf2", hexCross );
  9042. addLine( "cf3", "cf4", hexCross );
  9043. this.camera = camera;
  9044. function addLine( a, b, hex ) {
  9045. addPoint( a, hex );
  9046. addPoint( b, hex );
  9047. }
  9048. function addPoint( id, hex ) {
  9049. _this.lineGeometry.vertices.push( new THREE.Vector3() );
  9050. _this.lineGeometry.colors.push( new THREE.Color( hex ) );
  9051. if ( _this.pointMap[ id ] === undefined ) _this.pointMap[ id ] = [];
  9052. _this.pointMap[ id ].push( _this.lineGeometry.vertices.length - 1 );
  9053. }
  9054. this.update( camera );
  9055. this.lines = new THREE.Line( this.lineGeometry, this.lineMaterial, THREE.LinePieces );
  9056. this.add( this.lines );
  9057. };
  9058. THREE.CameraHelper.prototype = new THREE.Object3D();
  9059. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  9060. THREE.CameraHelper.prototype.update = function () {
  9061. var camera = this.camera;
  9062. var w = 1;
  9063. var h = 1;
  9064. var _this = this;
  9065. // we need just camera projection matrix
  9066. // world matrix must be identity
  9067. THREE.CameraHelper.__c.projectionMatrix.copy( camera.projectionMatrix );
  9068. // center / target
  9069. setPoint( "c", 0, 0, -1 );
  9070. setPoint( "t", 0, 0, 1 );
  9071. // near
  9072. setPoint( "n1", -w, -h, -1 );
  9073. setPoint( "n2", w, -h, -1 );
  9074. setPoint( "n3", -w, h, -1 );
  9075. setPoint( "n4", w, h, -1 );
  9076. // far
  9077. setPoint( "f1", -w, -h, 1 );
  9078. setPoint( "f2", w, -h, 1 );
  9079. setPoint( "f3", -w, h, 1 );
  9080. setPoint( "f4", w, h, 1 );
  9081. // up
  9082. setPoint( "u1", w * 0.7, h * 1.1, -1 );
  9083. setPoint( "u2", -w * 0.7, h * 1.1, -1 );
  9084. setPoint( "u3", 0, h * 2, -1 );
  9085. // cross
  9086. setPoint( "cf1", -w, 0, 1 );
  9087. setPoint( "cf2", w, 0, 1 );
  9088. setPoint( "cf3", 0, -h, 1 );
  9089. setPoint( "cf4", 0, h, 1 );
  9090. setPoint( "cn1", -w, 0, -1 );
  9091. setPoint( "cn2", w, 0, -1 );
  9092. setPoint( "cn3", 0, -h, -1 );
  9093. setPoint( "cn4", 0, h, -1 );
  9094. function setPoint( point, x, y, z ) {
  9095. THREE.CameraHelper.__v.set( x, y, z );
  9096. THREE.CameraHelper.__projector.unprojectVector( THREE.CameraHelper.__v, THREE.CameraHelper.__c );
  9097. var points = _this.pointMap[ point ];
  9098. if ( points !== undefined ) {
  9099. for ( var i = 0, il = points.length; i < il; i ++ ) {
  9100. var j = points[ i ];
  9101. _this.lineGeometry.vertices[ j ].copy( THREE.CameraHelper.__v );
  9102. }
  9103. }
  9104. }
  9105. this.lineGeometry.__dirtyVertices = true;
  9106. };
  9107. THREE.CameraHelper.__projector = new THREE.Projector();
  9108. THREE.CameraHelper.__v = new THREE.Vector3();
  9109. THREE.CameraHelper.__c = new THREE.Camera();
  9110. /**
  9111. * @author mikael emtinger / http://gomo.se/
  9112. * @author alteredq / http://alteredqualia.com/
  9113. */
  9114. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  9115. THREE.Object3D.call( this );
  9116. this.lensFlares = [];
  9117. this.positionScreen = new THREE.Vector3();
  9118. this.customUpdateCallback = undefined;
  9119. if( texture !== undefined ) {
  9120. this.add( texture, size, distance, blending, color );
  9121. }
  9122. };
  9123. THREE.LensFlare.prototype = new THREE.Object3D();
  9124. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  9125. THREE.LensFlare.prototype.supr = THREE.Object3D.prototype;
  9126. /*
  9127. * Add: adds another flare
  9128. */
  9129. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  9130. if( size === undefined ) size = -1;
  9131. if( distance === undefined ) distance = 0;
  9132. if( opacity === undefined ) opacity = 1;
  9133. if( color === undefined ) color = new THREE.Color( 0xffffff );
  9134. if( blending === undefined ) blending = THREE.NormalBlending;
  9135. distance = Math.min( distance, Math.max( 0, distance ) );
  9136. this.lensFlares.push( { texture: texture, // THREE.Texture
  9137. size: size, // size in pixels (-1 = use texture.width)
  9138. distance: distance, // distance (0-1) from light source (0=at light source)
  9139. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is ontop z = 1 is back
  9140. scale: 1, // scale
  9141. rotation: 1, // rotation
  9142. opacity: opacity, // opacity
  9143. color: color, // color
  9144. blending: blending } ); // blending
  9145. };
  9146. /*
  9147. * Update lens flares update positions on all flares based on the screen position
  9148. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  9149. */
  9150. THREE.LensFlare.prototype.updateLensFlares = function () {
  9151. var f, fl = this.lensFlares.length;
  9152. var flare;
  9153. var vecX = -this.positionScreen.x * 2;
  9154. var vecY = -this.positionScreen.y * 2;
  9155. for( f = 0; f < fl; f ++ ) {
  9156. flare = this.lensFlares[ f ];
  9157. flare.x = this.positionScreen.x + vecX * flare.distance;
  9158. flare.y = this.positionScreen.y + vecY * flare.distance;
  9159. flare.wantedRotation = flare.x * Math.PI * 0.25;
  9160. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  9161. }
  9162. };
  9163. /**
  9164. * @author alteredq / http://alteredqualia.com/
  9165. */
  9166. THREE.ImmediateRenderObject = function ( ) {
  9167. THREE.Object3D.call( this );
  9168. this.render = function( renderCallback ) {
  9169. };
  9170. };
  9171. THREE.ImmediateRenderObject.prototype = new THREE.Object3D();
  9172. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  9173. /**
  9174. * @author mikael emtinger / http://gomo.se/
  9175. * @author alteredq / http://alteredqualia.com/
  9176. */
  9177. THREE.LensFlarePlugin = function ( ) {
  9178. var _gl, _renderer, _lensFlare = {};
  9179. this.init = function ( renderer ) {
  9180. _gl = renderer.context;
  9181. _renderer = renderer;
  9182. _lensFlare.vertices = new Float32Array( 8 + 8 );
  9183. _lensFlare.faces = new Uint16Array( 6 );
  9184. var i = 0;
  9185. _lensFlare.vertices[ i++ ] = -1; _lensFlare.vertices[ i++ ] = -1; // vertex
  9186. _lensFlare.vertices[ i++ ] = 0; _lensFlare.vertices[ i++ ] = 0; // uv... etc.
  9187. _lensFlare.vertices[ i++ ] = 1; _lensFlare.vertices[ i++ ] = -1;
  9188. _lensFlare.vertices[ i++ ] = 1; _lensFlare.vertices[ i++ ] = 0;
  9189. _lensFlare.vertices[ i++ ] = 1; _lensFlare.vertices[ i++ ] = 1;
  9190. _lensFlare.vertices[ i++ ] = 1; _lensFlare.vertices[ i++ ] = 1;
  9191. _lensFlare.vertices[ i++ ] = -1; _lensFlare.vertices[ i++ ] = 1;
  9192. _lensFlare.vertices[ i++ ] = 0; _lensFlare.vertices[ i++ ] = 1;
  9193. i = 0;
  9194. _lensFlare.faces[ i++ ] = 0; _lensFlare.faces[ i++ ] = 1; _lensFlare.faces[ i++ ] = 2;
  9195. _lensFlare.faces[ i++ ] = 0; _lensFlare.faces[ i++ ] = 2; _lensFlare.faces[ i++ ] = 3;
  9196. // buffers
  9197. _lensFlare.vertexBuffer = _gl.createBuffer();
  9198. _lensFlare.elementBuffer = _gl.createBuffer();
  9199. _gl.bindBuffer( _gl.ARRAY_BUFFER, _lensFlare.vertexBuffer );
  9200. _gl.bufferData( _gl.ARRAY_BUFFER, _lensFlare.vertices, _gl.STATIC_DRAW );
  9201. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, _lensFlare.elementBuffer );
  9202. _gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, _lensFlare.faces, _gl.STATIC_DRAW );
  9203. // textures
  9204. _lensFlare.tempTexture = _gl.createTexture();
  9205. _lensFlare.occlusionTexture = _gl.createTexture();
  9206. _gl.bindTexture( _gl.TEXTURE_2D, _lensFlare.tempTexture );
  9207. _gl.texImage2D( _gl.TEXTURE_2D, 0, _gl.RGB, 16, 16, 0, _gl.RGB, _gl.UNSIGNED_BYTE, null );
  9208. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  9209. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  9210. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_MAG_FILTER, _gl.NEAREST );
  9211. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_MIN_FILTER, _gl.NEAREST );
  9212. _gl.bindTexture( _gl.TEXTURE_2D, _lensFlare.occlusionTexture );
  9213. _gl.texImage2D( _gl.TEXTURE_2D, 0, _gl.RGBA, 16, 16, 0, _gl.RGBA, _gl.UNSIGNED_BYTE, null );
  9214. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  9215. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  9216. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_MAG_FILTER, _gl.NEAREST );
  9217. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_MIN_FILTER, _gl.NEAREST );
  9218. if ( _gl.getParameter( _gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) <= 0 ) {
  9219. _lensFlare.hasVertexTexture = false;
  9220. _lensFlare.program = createProgram( THREE.ShaderFlares[ "lensFlare" ] );
  9221. } else {
  9222. _lensFlare.hasVertexTexture = true;
  9223. _lensFlare.program = createProgram( THREE.ShaderFlares[ "lensFlareVertexTexture" ] );
  9224. }
  9225. _lensFlare.attributes = {};
  9226. _lensFlare.uniforms = {};
  9227. _lensFlare.attributes.vertex = _gl.getAttribLocation ( _lensFlare.program, "position" );
  9228. _lensFlare.attributes.uv = _gl.getAttribLocation ( _lensFlare.program, "uv" );
  9229. _lensFlare.uniforms.renderType = _gl.getUniformLocation( _lensFlare.program, "renderType" );
  9230. _lensFlare.uniforms.map = _gl.getUniformLocation( _lensFlare.program, "map" );
  9231. _lensFlare.uniforms.occlusionMap = _gl.getUniformLocation( _lensFlare.program, "occlusionMap" );
  9232. _lensFlare.uniforms.opacity = _gl.getUniformLocation( _lensFlare.program, "opacity" );
  9233. _lensFlare.uniforms.color = _gl.getUniformLocation( _lensFlare.program, "color" );
  9234. _lensFlare.uniforms.scale = _gl.getUniformLocation( _lensFlare.program, "scale" );
  9235. _lensFlare.uniforms.rotation = _gl.getUniformLocation( _lensFlare.program, "rotation" );
  9236. _lensFlare.uniforms.screenPosition = _gl.getUniformLocation( _lensFlare.program, "screenPosition" );
  9237. _lensFlare.attributesEnabled = false;
  9238. };
  9239. /*
  9240. * Render lens flares
  9241. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  9242. * reads these back and calculates occlusion.
  9243. * Then _lensFlare.update_lensFlares() is called to re-position and
  9244. * update transparency of flares. Then they are rendered.
  9245. *
  9246. */
  9247. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  9248. var flares = scene.__webglFlares,
  9249. nFlares = flares.length;
  9250. if ( ! nFlares ) return;
  9251. var tempPosition = new THREE.Vector3();
  9252. var invAspect = viewportHeight / viewportWidth,
  9253. halfViewportWidth = viewportWidth * 0.5,
  9254. halfViewportHeight = viewportHeight * 0.5;
  9255. var size = 16 / viewportHeight,
  9256. scale = new THREE.Vector2( size * invAspect, size );
  9257. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  9258. screenPositionPixels = new THREE.Vector2( 1, 1 );
  9259. var uniforms = _lensFlare.uniforms,
  9260. attributes = _lensFlare.attributes;
  9261. // set _lensFlare program and reset blending
  9262. _gl.useProgram( _lensFlare.program );
  9263. if ( ! _lensFlare.attributesEnabled ) {
  9264. _gl.enableVertexAttribArray( _lensFlare.attributes.vertex );
  9265. _gl.enableVertexAttribArray( _lensFlare.attributes.uv );
  9266. _lensFlare.attributesEnabled = true;
  9267. }
  9268. // loop through all lens flares to update their occlusion and positions
  9269. // setup gl and common used attribs/unforms
  9270. _gl.uniform1i( uniforms.occlusionMap, 0 );
  9271. _gl.uniform1i( uniforms.map, 1 );
  9272. _gl.bindBuffer( _gl.ARRAY_BUFFER, _lensFlare.vertexBuffer );
  9273. _gl.vertexAttribPointer( attributes.vertex, 2, _gl.FLOAT, false, 2 * 8, 0 );
  9274. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 2 * 8, 8 );
  9275. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, _lensFlare.elementBuffer );
  9276. _gl.disable( _gl.CULL_FACE );
  9277. _gl.depthMask( false );
  9278. var i, j, jl, flare, sprite;
  9279. for ( i = 0; i < nFlares; i ++ ) {
  9280. size = 16 / viewportHeight;
  9281. scale.set( size * invAspect, size );
  9282. // calc object screen position
  9283. flare = flares[ i ];
  9284. tempPosition.set( flare.matrixWorld.elements[12], flare.matrixWorld.elements[13], flare.matrixWorld.elements[14] );
  9285. camera.matrixWorldInverse.multiplyVector3( tempPosition );
  9286. camera.projectionMatrix.multiplyVector3( tempPosition );
  9287. // setup arrays for gl programs
  9288. screenPosition.copy( tempPosition )
  9289. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  9290. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  9291. // screen cull
  9292. if ( _lensFlare.hasVertexTexture || (
  9293. screenPositionPixels.x > 0 &&
  9294. screenPositionPixels.x < viewportWidth &&
  9295. screenPositionPixels.y > 0 &&
  9296. screenPositionPixels.y < viewportHeight ) ) {
  9297. // save current RGB to temp texture
  9298. _gl.activeTexture( _gl.TEXTURE1 );
  9299. _gl.bindTexture( _gl.TEXTURE_2D, _lensFlare.tempTexture );
  9300. _gl.copyTexImage2D( _gl.TEXTURE_2D, 0, _gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  9301. // render pink quad
  9302. _gl.uniform1i( uniforms.renderType, 0 );
  9303. _gl.uniform2f( uniforms.scale, scale.x, scale.y );
  9304. _gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  9305. _gl.disable( _gl.BLEND );
  9306. _gl.enable( _gl.DEPTH_TEST );
  9307. _gl.drawElements( _gl.TRIANGLES, 6, _gl.UNSIGNED_SHORT, 0 );
  9308. // copy result to occlusionMap
  9309. _gl.activeTexture( _gl.TEXTURE0 );
  9310. _gl.bindTexture( _gl.TEXTURE_2D, _lensFlare.occlusionTexture );
  9311. _gl.copyTexImage2D( _gl.TEXTURE_2D, 0, _gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  9312. // restore graphics
  9313. _gl.uniform1i( uniforms.renderType, 1 );
  9314. _gl.disable( _gl.DEPTH_TEST );
  9315. _gl.activeTexture( _gl.TEXTURE1 );
  9316. _gl.bindTexture( _gl.TEXTURE_2D, _lensFlare.tempTexture );
  9317. _gl.drawElements( _gl.TRIANGLES, 6, _gl.UNSIGNED_SHORT, 0 );
  9318. // update object positions
  9319. flare.positionScreen.copy( screenPosition )
  9320. if ( flare.customUpdateCallback ) {
  9321. flare.customUpdateCallback( flare );
  9322. } else {
  9323. flare.updateLensFlares();
  9324. }
  9325. // render flares
  9326. _gl.uniform1i( uniforms.renderType, 2 );
  9327. _gl.enable( _gl.BLEND );
  9328. for ( j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  9329. sprite = flare.lensFlares[ j ];
  9330. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  9331. screenPosition.x = sprite.x;
  9332. screenPosition.y = sprite.y;
  9333. screenPosition.z = sprite.z;
  9334. size = sprite.size * sprite.scale / viewportHeight;
  9335. scale.x = size * invAspect;
  9336. scale.y = size;
  9337. _gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  9338. _gl.uniform2f( uniforms.scale, scale.x, scale.y );
  9339. _gl.uniform1f( uniforms.rotation, sprite.rotation );
  9340. _gl.uniform1f( uniforms.opacity, sprite.opacity );
  9341. _gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  9342. _renderer.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  9343. _renderer.setTexture( sprite.texture, 1 );
  9344. _gl.drawElements( _gl.TRIANGLES, 6, _gl.UNSIGNED_SHORT, 0 );
  9345. }
  9346. }
  9347. }
  9348. }
  9349. // restore gl
  9350. _gl.enable( _gl.CULL_FACE );
  9351. _gl.enable( _gl.DEPTH_TEST );
  9352. _gl.depthMask( true );
  9353. };
  9354. function createProgram ( shader ) {
  9355. var program = _gl.createProgram();
  9356. var fragmentShader = _gl.createShader( _gl.FRAGMENT_SHADER );
  9357. var vertexShader = _gl.createShader( _gl.VERTEX_SHADER );
  9358. _gl.shaderSource( fragmentShader, shader.fragmentShader );
  9359. _gl.shaderSource( vertexShader, shader.vertexShader );
  9360. _gl.compileShader( fragmentShader );
  9361. _gl.compileShader( vertexShader );
  9362. _gl.attachShader( program, fragmentShader );
  9363. _gl.attachShader( program, vertexShader );
  9364. _gl.linkProgram( program );
  9365. return program;
  9366. };
  9367. };/**
  9368. * @author alteredq / http://alteredqualia.com/
  9369. */
  9370. THREE.ShadowMapPlugin = function ( ) {
  9371. var _gl,
  9372. _renderer,
  9373. _depthMaterial, _depthMaterialMorph,
  9374. _frustum = new THREE.Frustum(),
  9375. _projScreenMatrix = new THREE.Matrix4(),
  9376. _min = new THREE.Vector3(),
  9377. _max = new THREE.Vector3();
  9378. this.init = function ( renderer ) {
  9379. _gl = renderer.context;
  9380. _renderer = renderer;
  9381. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  9382. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  9383. _depthMaterial = new THREE.ShaderMaterial( { fragmentShader: depthShader.fragmentShader, vertexShader: depthShader.vertexShader, uniforms: depthUniforms } );
  9384. _depthMaterialMorph = new THREE.ShaderMaterial( { fragmentShader: depthShader.fragmentShader, vertexShader: depthShader.vertexShader, uniforms: depthUniforms, morphTargets: true } );
  9385. _depthMaterial._shadowPass = true;
  9386. _depthMaterialMorph._shadowPass = true;
  9387. };
  9388. this.render = function ( scene, camera ) {
  9389. if ( ! ( _renderer.shadowMapEnabled && _renderer.shadowMapAutoUpdate ) ) return;
  9390. this.update( scene, camera );
  9391. };
  9392. this.update = function ( scene, camera ) {
  9393. var i, il, j, jl, n,
  9394. shadowMap, shadowMatrix, shadowCamera,
  9395. program, buffer, material,
  9396. webglObject, object, light,
  9397. renderList,
  9398. lights = [],
  9399. k = 0,
  9400. fog = null;
  9401. // set GL state for depth map
  9402. _gl.clearColor( 1, 1, 1, 1 );
  9403. _gl.disable( _gl.BLEND );
  9404. if ( _renderer.shadowMapCullFrontFaces ) _gl.cullFace( _gl.FRONT );
  9405. _renderer.setDepthTest( true );
  9406. // preprocess lights
  9407. // - skip lights that are not casting shadows
  9408. // - create virtual lights for cascaded shadow maps
  9409. for ( i = 0, il = scene.__lights.length; i < il; i ++ ) {
  9410. light = scene.__lights[ i ];
  9411. if ( ! light.castShadow ) continue;
  9412. if ( ( light instanceof THREE.DirectionalLight ) && light.shadowCascade ) {
  9413. for ( n = 0; n < light.shadowCascadeCount; n ++ ) {
  9414. var virtualLight;
  9415. if ( ! light.shadowCascadeArray[ n ] ) {
  9416. virtualLight = createVirtualLight( light, n );
  9417. virtualLight.originalCamera = camera;
  9418. var gyro = new THREE.Gyroscope();
  9419. gyro.position = light.shadowCascadeOffset;
  9420. gyro.add( virtualLight );
  9421. gyro.add( virtualLight.target );
  9422. camera.add( gyro );
  9423. light.shadowCascadeArray[ n ] = virtualLight;
  9424. console.log( "Created virtualLight", virtualLight );
  9425. } else {
  9426. virtualLight = light.shadowCascadeArray[ n ];
  9427. }
  9428. updateVirtualLight( light, n );
  9429. lights[ k ] = virtualLight;
  9430. k ++;
  9431. }
  9432. } else {
  9433. lights[ k ] = light;
  9434. k ++;
  9435. }
  9436. }
  9437. // render depth map
  9438. for ( i = 0, il = lights.length; i < il; i ++ ) {
  9439. light = lights[ i ];
  9440. if ( ! light.shadowMap ) {
  9441. var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat };
  9442. light.shadowMap = new THREE.WebGLRenderTarget( light.shadowMapWidth, light.shadowMapHeight, pars );
  9443. light.shadowMapSize = new THREE.Vector2( light.shadowMapWidth, light.shadowMapHeight );
  9444. light.shadowMatrix = new THREE.Matrix4();
  9445. }
  9446. if ( ! light.shadowCamera ) {
  9447. if ( light instanceof THREE.SpotLight ) {
  9448. light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, light.shadowMapWidth / light.shadowMapHeight, light.shadowCameraNear, light.shadowCameraFar );
  9449. } else if ( light instanceof THREE.DirectionalLight ) {
  9450. light.shadowCamera = new THREE.OrthographicCamera( light.shadowCameraLeft, light.shadowCameraRight, light.shadowCameraTop, light.shadowCameraBottom, light.shadowCameraNear, light.shadowCameraFar );
  9451. } else {
  9452. console.error( "Unsupported light type for shadow" );
  9453. continue;
  9454. }
  9455. scene.add( light.shadowCamera );
  9456. if ( _renderer.autoUpdateScene ) scene.updateMatrixWorld();
  9457. }
  9458. if ( light.shadowCameraVisible && ! light.cameraHelper ) {
  9459. light.cameraHelper = new THREE.CameraHelper( light.shadowCamera );
  9460. light.shadowCamera.add( light.cameraHelper );
  9461. }
  9462. if ( light.isVirtual && virtualLight.originalCamera == camera ) {
  9463. updateShadowCamera( camera, light );
  9464. }
  9465. shadowMap = light.shadowMap;
  9466. shadowMatrix = light.shadowMatrix;
  9467. shadowCamera = light.shadowCamera;
  9468. shadowCamera.position.copy( light.matrixWorld.getPosition() );
  9469. shadowCamera.lookAt( light.target.matrixWorld.getPosition() );
  9470. shadowCamera.updateMatrixWorld();
  9471. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  9472. if ( light.cameraHelper ) light.cameraHelper.lines.visible = light.shadowCameraVisible;
  9473. if ( light.shadowCameraVisible ) light.cameraHelper.update();
  9474. // compute shadow matrix
  9475. shadowMatrix.set( 0.5, 0.0, 0.0, 0.5,
  9476. 0.0, 0.5, 0.0, 0.5,
  9477. 0.0, 0.0, 0.5, 0.5,
  9478. 0.0, 0.0, 0.0, 1.0 );
  9479. shadowMatrix.multiplySelf( shadowCamera.projectionMatrix );
  9480. shadowMatrix.multiplySelf( shadowCamera.matrixWorldInverse );
  9481. // update camera matrices and frustum
  9482. if ( ! shadowCamera._viewMatrixArray ) shadowCamera._viewMatrixArray = new Float32Array( 16 );
  9483. if ( ! shadowCamera._projectionMatrixArray ) shadowCamera._projectionMatrixArray = new Float32Array( 16 );
  9484. shadowCamera.matrixWorldInverse.flattenToArray( shadowCamera._viewMatrixArray );
  9485. shadowCamera.projectionMatrix.flattenToArray( shadowCamera._projectionMatrixArray );
  9486. _projScreenMatrix.multiply( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  9487. _frustum.setFromMatrix( _projScreenMatrix );
  9488. // render shadow map
  9489. _renderer.setRenderTarget( shadowMap );
  9490. _renderer.clear();
  9491. // set object matrices & frustum culling
  9492. renderList = scene.__webglObjects;
  9493. for ( j = 0, jl = renderList.length; j < jl; j ++ ) {
  9494. webglObject = renderList[ j ];
  9495. object = webglObject.object;
  9496. webglObject.render = false;
  9497. if ( object.visible && object.castShadow ) {
  9498. if ( ! ( object instanceof THREE.Mesh ) || ! ( object.frustumCulled ) || _frustum.contains( object ) ) {
  9499. //object.matrixWorld.flattenToArray( object._objectMatrixArray );
  9500. object._modelViewMatrix.multiply( shadowCamera.matrixWorldInverse, object.matrixWorld);
  9501. webglObject.render = true;
  9502. }
  9503. }
  9504. }
  9505. // render regular objects
  9506. for ( j = 0, jl = renderList.length; j < jl; j ++ ) {
  9507. webglObject = renderList[ j ];
  9508. if ( webglObject.render ) {
  9509. object = webglObject.object;
  9510. buffer = webglObject.buffer;
  9511. _renderer.setObjectFaces( object );
  9512. if ( object.customDepthMaterial ) {
  9513. material = object.customDepthMaterial;
  9514. } else if ( object.geometry.morphTargets.length ) {
  9515. material = _depthMaterialMorph;
  9516. } else {
  9517. material = _depthMaterial;
  9518. }
  9519. if ( buffer instanceof THREE.BufferGeometry ) {
  9520. _renderer.renderBufferDirect( shadowCamera, scene.__lights, fog, material, buffer, object );
  9521. } else {
  9522. _renderer.renderBuffer( shadowCamera, scene.__lights, fog, material, buffer, object );
  9523. }
  9524. }
  9525. }
  9526. // set matrices and render immediate objects
  9527. renderList = scene.__webglObjectsImmediate;
  9528. for ( j = 0, jl = renderList.length; j < jl; j ++ ) {
  9529. webglObject = renderList[ j ];
  9530. object = webglObject.object;
  9531. if ( object.visible && object.castShadow ) {
  9532. /*
  9533. if ( object.matrixAutoUpdate ) {
  9534. object.matrixWorld.flattenToArray( object._objectMatrixArray );
  9535. }
  9536. */
  9537. object._modelViewMatrix.multiply( shadowCamera.matrixWorldInverse, object.matrixWorld);
  9538. _renderer.renderImmediateObject( shadowCamera, scene.__lights, fog, _depthMaterial, object );
  9539. }
  9540. }
  9541. }
  9542. // restore GL state
  9543. var clearColor = _renderer.getClearColor(),
  9544. clearAlpha = _renderer.getClearAlpha();
  9545. _gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearAlpha );
  9546. _gl.enable( _gl.BLEND );
  9547. if ( _renderer.shadowMapCullFrontFaces ) _gl.cullFace( _gl.BACK );
  9548. };
  9549. function createVirtualLight( light, cascade ) {
  9550. var virtualLight = new THREE.DirectionalLight();
  9551. virtualLight.isVirtual = true;
  9552. virtualLight.onlyShadow = true;
  9553. virtualLight.castShadow = true;
  9554. virtualLight.shadowCameraNear = light.shadowCameraNear;
  9555. virtualLight.shadowCameraFar = light.shadowCameraFar;
  9556. virtualLight.shadowCameraLeft = light.shadowCameraLeft;
  9557. virtualLight.shadowCameraRight = light.shadowCameraRight;
  9558. virtualLight.shadowCameraBottom = light.shadowCameraBottom;
  9559. virtualLight.shadowCameraTop = light.shadowCameraTop;
  9560. virtualLight.shadowCameraVisible = light.shadowCameraVisible;
  9561. virtualLight.shadowDarkness = light.shadowDarkness;
  9562. virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
  9563. virtualLight.shadowMapWidth = light.shadowCascadeWidth[ cascade ];
  9564. virtualLight.shadowMapHeight = light.shadowCascadeHeight[ cascade ];
  9565. virtualLight.pointsWorld = [];
  9566. virtualLight.pointsFrustum = [];
  9567. var pointsWorld = virtualLight.pointsWorld,
  9568. pointsFrustum = virtualLight.pointsFrustum;
  9569. for ( var i = 0; i < 8; i ++ ) {
  9570. pointsWorld[ i ] = new THREE.Vector3();
  9571. pointsFrustum[ i ] = new THREE.Vector3();
  9572. }
  9573. var nearZ = light.shadowCascadeNearZ[ cascade ];
  9574. var farZ = light.shadowCascadeFarZ[ cascade ];
  9575. pointsFrustum[ 0 ].set( -1, -1, nearZ );
  9576. pointsFrustum[ 1 ].set( 1, -1, nearZ );
  9577. pointsFrustum[ 2 ].set( -1, 1, nearZ );
  9578. pointsFrustum[ 3 ].set( 1, 1, nearZ );
  9579. pointsFrustum[ 4 ].set( -1, -1, farZ );
  9580. pointsFrustum[ 5 ].set( 1, -1, farZ );
  9581. pointsFrustum[ 6 ].set( -1, 1, farZ );
  9582. pointsFrustum[ 7 ].set( 1, 1, farZ );
  9583. return virtualLight;
  9584. }
  9585. // Synchronize virtual light with the original light
  9586. function updateVirtualLight( light, cascade ) {
  9587. var virtualLight = light.shadowCascadeArray[ cascade ];
  9588. virtualLight.position.copy( light.position );
  9589. virtualLight.target.position.copy( light.target.position );
  9590. virtualLight.lookAt( virtualLight.target );
  9591. virtualLight.shadowCameraVisible = light.shadowCameraVisible;
  9592. virtualLight.shadowDarkness = light.shadowDarkness;
  9593. virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
  9594. var nearZ = light.shadowCascadeNearZ[ cascade ];
  9595. var farZ = light.shadowCascadeFarZ[ cascade ];
  9596. var pointsFrustum = virtualLight.pointsFrustum;
  9597. pointsFrustum[ 0 ].z = nearZ;
  9598. pointsFrustum[ 1 ].z = nearZ;
  9599. pointsFrustum[ 2 ].z = nearZ;
  9600. pointsFrustum[ 3 ].z = nearZ;
  9601. pointsFrustum[ 4 ].z = farZ;
  9602. pointsFrustum[ 5 ].z = farZ;
  9603. pointsFrustum[ 6 ].z = farZ;
  9604. pointsFrustum[ 7 ].z = farZ;
  9605. }
  9606. // Fit shadow camera's ortho frustum to camera frustum
  9607. function updateShadowCamera( camera, light ) {
  9608. var shadowCamera = light.shadowCamera,
  9609. pointsFrustum = light.pointsFrustum,
  9610. pointsWorld = light.pointsWorld;
  9611. _min.set( Infinity, Infinity, Infinity );
  9612. _max.set( -Infinity, -Infinity, -Infinity );
  9613. for ( var i = 0; i < 8; i ++ ) {
  9614. var p = pointsWorld[ i ];
  9615. p.copy( pointsFrustum[ i ] );
  9616. THREE.ShadowMapPlugin.__projector.unprojectVector( p, camera );
  9617. shadowCamera.matrixWorldInverse.multiplyVector3( p );
  9618. if ( p.x < _min.x ) _min.x = p.x;
  9619. if ( p.x > _max.x ) _max.x = p.x;
  9620. if ( p.y < _min.y ) _min.y = p.y;
  9621. if ( p.y > _max.y ) _max.y = p.y;
  9622. if ( p.z < _min.z ) _min.z = p.z;
  9623. if ( p.z > _max.z ) _max.z = p.z;
  9624. }
  9625. shadowCamera.left = _min.x;
  9626. shadowCamera.right = _max.x;
  9627. shadowCamera.top = _max.y;
  9628. shadowCamera.bottom = _min.y;
  9629. // can't really fit near/far
  9630. //shadowCamera.near = _min.z;
  9631. //shadowCamera.far = _max.z;
  9632. shadowCamera.updateProjectionMatrix();
  9633. }
  9634. };
  9635. THREE.ShadowMapPlugin.__projector = new THREE.Projector();
  9636. /**
  9637. * @author mikael emtinger / http://gomo.se/
  9638. * @author alteredq / http://alteredqualia.com/
  9639. */
  9640. THREE.SpritePlugin = function ( ) {
  9641. var _gl, _renderer, _sprite = {};
  9642. this.init = function ( renderer ) {
  9643. _gl = renderer.context;
  9644. _renderer = renderer;
  9645. _sprite.vertices = new Float32Array( 8 + 8 );
  9646. _sprite.faces = new Uint16Array( 6 );
  9647. var i = 0;
  9648. _sprite.vertices[ i++ ] = -1; _sprite.vertices[ i++ ] = -1; // vertex 0
  9649. _sprite.vertices[ i++ ] = 0; _sprite.vertices[ i++ ] = 1; // uv 0
  9650. _sprite.vertices[ i++ ] = 1; _sprite.vertices[ i++ ] = -1; // vertex 1
  9651. _sprite.vertices[ i++ ] = 1; _sprite.vertices[ i++ ] = 1; // uv 1
  9652. _sprite.vertices[ i++ ] = 1; _sprite.vertices[ i++ ] = 1; // vertex 2
  9653. _sprite.vertices[ i++ ] = 1; _sprite.vertices[ i++ ] = 0; // uv 2
  9654. _sprite.vertices[ i++ ] = -1; _sprite.vertices[ i++ ] = 1; // vertex 3
  9655. _sprite.vertices[ i++ ] = 0; _sprite.vertices[ i++ ] = 0; // uv 3
  9656. i = 0;
  9657. _sprite.faces[ i++ ] = 0; _sprite.faces[ i++ ] = 1; _sprite.faces[ i++ ] = 2;
  9658. _sprite.faces[ i++ ] = 0; _sprite.faces[ i++ ] = 2; _sprite.faces[ i++ ] = 3;
  9659. _sprite.vertexBuffer = _gl.createBuffer();
  9660. _sprite.elementBuffer = _gl.createBuffer();
  9661. _gl.bindBuffer( _gl.ARRAY_BUFFER, _sprite.vertexBuffer );
  9662. _gl.bufferData( _gl.ARRAY_BUFFER, _sprite.vertices, _gl.STATIC_DRAW );
  9663. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, _sprite.elementBuffer );
  9664. _gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, _sprite.faces, _gl.STATIC_DRAW );
  9665. _sprite.program = createProgram( THREE.ShaderSprite[ "sprite" ] );
  9666. _sprite.attributes = {};
  9667. _sprite.uniforms = {};
  9668. _sprite.attributes.position = _gl.getAttribLocation ( _sprite.program, "position" );
  9669. _sprite.attributes.uv = _gl.getAttribLocation ( _sprite.program, "uv" );
  9670. _sprite.uniforms.uvOffset = _gl.getUniformLocation( _sprite.program, "uvOffset" );
  9671. _sprite.uniforms.uvScale = _gl.getUniformLocation( _sprite.program, "uvScale" );
  9672. _sprite.uniforms.rotation = _gl.getUniformLocation( _sprite.program, "rotation" );
  9673. _sprite.uniforms.scale = _gl.getUniformLocation( _sprite.program, "scale" );
  9674. _sprite.uniforms.alignment = _gl.getUniformLocation( _sprite.program, "alignment" );
  9675. _sprite.uniforms.color = _gl.getUniformLocation( _sprite.program, "color" );
  9676. _sprite.uniforms.map = _gl.getUniformLocation( _sprite.program, "map" );
  9677. _sprite.uniforms.opacity = _gl.getUniformLocation( _sprite.program, "opacity" );
  9678. _sprite.uniforms.useScreenCoordinates = _gl.getUniformLocation( _sprite.program, "useScreenCoordinates" );
  9679. _sprite.uniforms.affectedByDistance = _gl.getUniformLocation( _sprite.program, "affectedByDistance" );
  9680. _sprite.uniforms.screenPosition = _gl.getUniformLocation( _sprite.program, "screenPosition" );
  9681. _sprite.uniforms.modelViewMatrix = _gl.getUniformLocation( _sprite.program, "modelViewMatrix" );
  9682. _sprite.uniforms.projectionMatrix = _gl.getUniformLocation( _sprite.program, "projectionMatrix" );
  9683. _sprite.attributesEnabled = false;
  9684. };
  9685. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  9686. var sprites = scene.__webglSprites,
  9687. nSprites = sprites.length;
  9688. if ( ! nSprites ) return;
  9689. var attributes = _sprite.attributes,
  9690. uniforms = _sprite.uniforms;
  9691. var invAspect = viewportHeight / viewportWidth;
  9692. var halfViewportWidth = viewportWidth * 0.5,
  9693. halfViewportHeight = viewportHeight * 0.5;
  9694. var mergeWith3D = true;
  9695. // setup gl
  9696. _gl.useProgram( _sprite.program );
  9697. if ( ! _sprite.attributesEnabled ) {
  9698. _gl.enableVertexAttribArray( attributes.position );
  9699. _gl.enableVertexAttribArray( attributes.uv );
  9700. _sprite.attributesEnabled = true;
  9701. }
  9702. _gl.disable( _gl.CULL_FACE );
  9703. _gl.enable( _gl.BLEND );
  9704. _gl.depthMask( true );
  9705. _gl.bindBuffer( _gl.ARRAY_BUFFER, _sprite.vertexBuffer );
  9706. _gl.vertexAttribPointer( attributes.position, 2, _gl.FLOAT, false, 2 * 8, 0 );
  9707. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 2 * 8, 8 );
  9708. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, _sprite.elementBuffer );
  9709. _gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera._projectionMatrixArray );
  9710. _gl.activeTexture( _gl.TEXTURE0 );
  9711. _gl.uniform1i( uniforms.map, 0 );
  9712. // update positions and sort
  9713. var i, sprite, screenPosition, size, scale = [];
  9714. for( i = 0; i < nSprites; i ++ ) {
  9715. sprite = sprites[ i ];
  9716. if ( ! sprite.visible || sprite.opacity === 0 ) continue;
  9717. if( ! sprite.useScreenCoordinates ) {
  9718. sprite._modelViewMatrix.multiply( camera.matrixWorldInverse, sprite.matrixWorld);
  9719. sprite.z = - sprite._modelViewMatrix.elements[14];
  9720. } else {
  9721. sprite.z = - sprite.position.z;
  9722. }
  9723. }
  9724. sprites.sort( painterSort );
  9725. // render all sprites
  9726. for( i = 0; i < nSprites; i ++ ) {
  9727. sprite = sprites[ i ];
  9728. if ( ! sprite.visible || sprite.opacity === 0 ) continue;
  9729. if ( sprite.map && sprite.map.image && sprite.map.image.width ) {
  9730. if ( sprite.useScreenCoordinates ) {
  9731. _gl.uniform1i( uniforms.useScreenCoordinates, 1 );
  9732. _gl.uniform3f( uniforms.screenPosition, ( sprite.position.x - halfViewportWidth ) / halfViewportWidth,
  9733. ( halfViewportHeight - sprite.position.y ) / halfViewportHeight,
  9734. Math.max( 0, Math.min( 1, sprite.position.z ) ) );
  9735. } else {
  9736. _gl.uniform1i( uniforms.useScreenCoordinates, 0 );
  9737. _gl.uniform1i( uniforms.affectedByDistance, sprite.affectedByDistance ? 1 : 0 );
  9738. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite._modelViewMatrix.elements);
  9739. }
  9740. size = sprite.map.image.width / ( sprite.scaleByViewport ? viewportHeight : 1 );
  9741. scale[ 0 ] = size * invAspect * sprite.scale.x;
  9742. scale[ 1 ] = size * sprite.scale.y;
  9743. _gl.uniform2f( uniforms.uvScale, sprite.uvScale.x, sprite.uvScale.y );
  9744. _gl.uniform2f( uniforms.uvOffset, sprite.uvOffset.x, sprite.uvOffset.y );
  9745. _gl.uniform2f( uniforms.alignment, sprite.alignment.x, sprite.alignment.y );
  9746. _gl.uniform1f( uniforms.opacity, sprite.opacity );
  9747. _gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  9748. _gl.uniform1f( uniforms.rotation, sprite.rotation );
  9749. _gl.uniform2fv( uniforms.scale, scale );
  9750. if ( sprite.mergeWith3D && !mergeWith3D ) {
  9751. _gl.enable( _gl.DEPTH_TEST );
  9752. mergeWith3D = true;
  9753. } else if ( ! sprite.mergeWith3D && mergeWith3D ) {
  9754. _gl.disable( _gl.DEPTH_TEST );
  9755. mergeWith3D = false;
  9756. }
  9757. _renderer.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  9758. _renderer.setTexture( sprite.map, 0 );
  9759. _gl.drawElements( _gl.TRIANGLES, 6, _gl.UNSIGNED_SHORT, 0 );
  9760. }
  9761. }
  9762. // restore gl
  9763. _gl.enable( _gl.CULL_FACE );
  9764. _gl.enable( _gl.DEPTH_TEST );
  9765. _gl.depthMask( true );
  9766. };
  9767. function createProgram ( shader ) {
  9768. var program = _gl.createProgram();
  9769. var fragmentShader = _gl.createShader( _gl.FRAGMENT_SHADER );
  9770. var vertexShader = _gl.createShader( _gl.VERTEX_SHADER );
  9771. _gl.shaderSource( fragmentShader, shader.fragmentShader );
  9772. _gl.shaderSource( vertexShader, shader.vertexShader );
  9773. _gl.compileShader( fragmentShader );
  9774. _gl.compileShader( vertexShader );
  9775. _gl.attachShader( program, fragmentShader );
  9776. _gl.attachShader( program, vertexShader );
  9777. _gl.linkProgram( program );
  9778. return program;
  9779. };
  9780. function painterSort ( a, b ) {
  9781. return b.z - a.z;
  9782. };
  9783. };/**
  9784. * @author mikael emtinger / http://gomo.se/
  9785. *
  9786. */
  9787. THREE.ShaderFlares = {
  9788. 'lensFlareVertexTexture': {
  9789. vertexShader: [
  9790. "uniform vec3 screenPosition;",
  9791. "uniform vec2 scale;",
  9792. "uniform float rotation;",
  9793. "uniform int renderType;",
  9794. "uniform sampler2D occlusionMap;",
  9795. "attribute vec2 position;",
  9796. "attribute vec2 uv;",
  9797. "varying vec2 vUV;",
  9798. "varying float vVisibility;",
  9799. "void main() {",
  9800. "vUV = uv;",
  9801. "vec2 pos = position;",
  9802. "if( renderType == 2 ) {",
  9803. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) ) +",
  9804. "texture2D( occlusionMap, vec2( 0.5, 0.1 ) ) +",
  9805. "texture2D( occlusionMap, vec2( 0.9, 0.1 ) ) +",
  9806. "texture2D( occlusionMap, vec2( 0.9, 0.5 ) ) +",
  9807. "texture2D( occlusionMap, vec2( 0.9, 0.9 ) ) +",
  9808. "texture2D( occlusionMap, vec2( 0.5, 0.9 ) ) +",
  9809. "texture2D( occlusionMap, vec2( 0.1, 0.9 ) ) +",
  9810. "texture2D( occlusionMap, vec2( 0.1, 0.5 ) ) +",
  9811. "texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  9812. "vVisibility = ( visibility.r / 9.0 ) *",
  9813. "( 1.0 - visibility.g / 9.0 ) *",
  9814. "( visibility.b / 9.0 ) *",
  9815. "( 1.0 - visibility.a / 9.0 );",
  9816. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  9817. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  9818. "}",
  9819. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  9820. "}"
  9821. ].join( "\n" ),
  9822. fragmentShader: [
  9823. "precision mediump float;",
  9824. "uniform sampler2D map;",
  9825. "uniform float opacity;",
  9826. "uniform int renderType;",
  9827. "uniform vec3 color;",
  9828. "varying vec2 vUV;",
  9829. "varying float vVisibility;",
  9830. "void main() {",
  9831. // pink square
  9832. "if( renderType == 0 ) {",
  9833. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  9834. // restore
  9835. "} else if( renderType == 1 ) {",
  9836. "gl_FragColor = texture2D( map, vUV );",
  9837. // flare
  9838. "} else {",
  9839. "vec4 texture = texture2D( map, vUV );",
  9840. "texture.a *= opacity * vVisibility;",
  9841. "gl_FragColor = texture;",
  9842. "gl_FragColor.rgb *= color;",
  9843. "}",
  9844. "}"
  9845. ].join( "\n" )
  9846. },
  9847. 'lensFlare': {
  9848. vertexShader: [
  9849. "uniform vec3 screenPosition;",
  9850. "uniform vec2 scale;",
  9851. "uniform float rotation;",
  9852. "uniform int renderType;",
  9853. "attribute vec2 position;",
  9854. "attribute vec2 uv;",
  9855. "varying vec2 vUV;",
  9856. "void main() {",
  9857. "vUV = uv;",
  9858. "vec2 pos = position;",
  9859. "if( renderType == 2 ) {",
  9860. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  9861. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  9862. "}",
  9863. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  9864. "}"
  9865. ].join( "\n" ),
  9866. fragmentShader: [
  9867. "precision mediump float;",
  9868. "uniform sampler2D map;",
  9869. "uniform sampler2D occlusionMap;",
  9870. "uniform float opacity;",
  9871. "uniform int renderType;",
  9872. "uniform vec3 color;",
  9873. "varying vec2 vUV;",
  9874. "void main() {",
  9875. // pink square
  9876. "if( renderType == 0 ) {",
  9877. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  9878. // restore
  9879. "} else if( renderType == 1 ) {",
  9880. "gl_FragColor = texture2D( map, vUV );",
  9881. // flare
  9882. "} else {",
  9883. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a +",
  9884. "texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a +",
  9885. "texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a +",
  9886. "texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  9887. "visibility = ( 1.0 - visibility / 4.0 );",
  9888. "vec4 texture = texture2D( map, vUV );",
  9889. "texture.a *= opacity * visibility;",
  9890. "gl_FragColor = texture;",
  9891. "gl_FragColor.rgb *= color;",
  9892. "}",
  9893. "}"
  9894. ].join( "\n" )
  9895. }
  9896. };
  9897. /**
  9898. * @author mikael emtinger / http://gomo.se/
  9899. *
  9900. */
  9901. THREE.ShaderSprite = {
  9902. 'sprite': {
  9903. vertexShader: [
  9904. "uniform int useScreenCoordinates;",
  9905. "uniform int affectedByDistance;",
  9906. "uniform vec3 screenPosition;",
  9907. "uniform mat4 modelViewMatrix;",
  9908. "uniform mat4 projectionMatrix;",
  9909. "uniform float rotation;",
  9910. "uniform vec2 scale;",
  9911. "uniform vec2 alignment;",
  9912. "uniform vec2 uvOffset;",
  9913. "uniform vec2 uvScale;",
  9914. "attribute vec2 position;",
  9915. "attribute vec2 uv;",
  9916. "varying vec2 vUV;",
  9917. "void main() {",
  9918. "vUV = uvOffset + uv * uvScale;",
  9919. "vec2 alignedPosition = position + alignment;",
  9920. "vec2 rotatedPosition;",
  9921. "rotatedPosition.x = ( cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y ) * scale.x;",
  9922. "rotatedPosition.y = ( sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y ) * scale.y;",
  9923. "vec4 finalPosition;",
  9924. "if( useScreenCoordinates != 0 ) {",
  9925. "finalPosition = vec4( screenPosition.xy + rotatedPosition, screenPosition.z, 1.0 );",
  9926. "} else {",
  9927. "finalPosition = projectionMatrix * modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );",
  9928. "finalPosition.xy += rotatedPosition * ( affectedByDistance == 1 ? 1.0 : finalPosition.z );",
  9929. "}",
  9930. "gl_Position = finalPosition;",
  9931. "}"
  9932. ].join( "\n" ),
  9933. fragmentShader: [
  9934. "precision mediump float;",
  9935. "uniform vec3 color;",
  9936. "uniform sampler2D map;",
  9937. "uniform float opacity;",
  9938. "varying vec2 vUV;",
  9939. "void main() {",
  9940. "vec4 texture = texture2D( map, vUV );",
  9941. "gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );",
  9942. "}"
  9943. ].join( "\n" )
  9944. }
  9945. };
  9946. =======
  9947. // ThreeWebGL.js - http://github.com/mrdoob/three.js
  9948. 'use strict';var THREE=THREE||{REVISION:"49dev"};self.Int32Array||(self.Int32Array=Array,self.Float32Array=Array);
  9949. (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(),g=Math.max(0,16-(c-a)),h=window.setTimeout(function(){b(c+g)},g);a=c+g;return h};if(!window.cancelAnimationFrame)window.cancelAnimationFrame=
  9950. function(a){clearTimeout(a)}})();THREE.Color=function(a){a!==void 0&&this.setHex(a);return this};
  9951. 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);
  9952. 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,f,g;if(c===0)this.r=this.g=this.b=0;else{d=Math.floor(a*6);f=a*6-d;a=c*(1-b);g=c*(1-b*f);b=c*(1-b*(1-f));switch(d){case 1:this.r=g;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=g;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=g;break;case 6:case 0:this.r=c;this.g=b;this.b=a}}return this},setHex:function(a){a=
  9953. 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)}};
  9954. THREE.Vector2=function(a,b){this.x=a||0;this.y=b||0};
  9955. 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=
  9956. 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)},
  9957. 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};
  9958. 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+
  9959. 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=
  9960. 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())},
  9961. 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,
  9962. 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,f=b?b.z:1,g=a.elements[0]/c,h=a.elements[4]/d,c=a.elements[1]/c,d=a.elements[5]/d,l=a.elements[9]/f,m=a.elements[10]/f;this.y=Math.asin(a.elements[8]/f);f=Math.cos(this.y);if(Math.abs(f)>1.0E-5){this.x=Math.atan2(-l/f,m/f);this.z=Math.atan2(-h/f,g/f)}else{this.x=0;this.z=Math.atan2(c,d)}return this},getScaleFromMatrix:function(a){var b=
  9963. 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};
  9964. 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=
  9965. 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())},
  9966. 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]};
  9967. THREE.Frustum.prototype.setFromMatrix=function(a){var b,c=this.planes,d=a.elements,a=d[0];b=d[1];var f=d[2],g=d[3],h=d[4],l=d[5],m=d[6],j=d[7],i=d[8],o=d[9],k=d[10],u=d[11],r=d[12],n=d[13],p=d[14],d=d[15];c[0].set(g-a,j-h,u-i,d-r);c[1].set(g+a,j+h,u+i,d+r);c[2].set(g+b,j+l,u+o,d+n);c[3].set(g-b,j-l,u-o,d-n);c[4].set(g-f,j-m,u-k,d-p);c[5].set(g+f,j+m,u+k,d+p);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))}};
  9968. THREE.Frustum.prototype.contains=function(a){for(var b=this.planes,c=a.matrixWorld,d=c.elements,c=-a.geometry.boundingSphere.radius*c.getMaxScaleOnAxis(),f=0;f<6;f++){a=b[f].x*d[12]+b[f].y*d[13]+b[f].z*d[14]+b[f].w;if(a<=c)return false}return true};THREE.Frustum.__v1=new THREE.Vector3;
  9969. THREE.Ray=function(a,b){function c(a,b,c){r.sub(c,a);w=r.dot(b);q=n.add(a,p.copy(b).multiplyScalar(w));return I=c.distanceTo(q)}function d(a,b,c,d){r.sub(d,b);n.sub(c,b);p.sub(a,b);B=r.dot(r);s=r.dot(n);J=r.dot(p);C=n.dot(n);G=n.dot(p);F=1/(B*C-s*s);P=(C*J-s*G)*F;Q=(B*G-s*J)*F;return P>=0&&Q>=0&&P+Q<1}this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3;var f=1.0E-4;this.setPrecision=function(a){f=a};var g=new THREE.Vector3,h=new THREE.Vector3,l=new THREE.Vector3,m=new THREE.Vector3,
  9970. j=new THREE.Vector3,i=new THREE.Vector3,o=new THREE.Vector3,k=new THREE.Vector3,u=new THREE.Vector3;this.intersectObject=function(a){var b,n=[];if(a instanceof THREE.Particle){var r=c(this.origin,this.direction,a.matrixWorld.getPosition());if(r>a.scale.x)return[];b={distance:r,point:a.position,face:null,object:a};n.push(b)}else if(a instanceof THREE.Mesh){var r=c(this.origin,this.direction,a.matrixWorld.getPosition()),p=THREE.Frustum.__v1.set(a.matrixWorld.getColumnX().length(),a.matrixWorld.getColumnY().length(),
  9971. a.matrixWorld.getColumnZ().length());if(r>a.geometry.boundingSphere.radius*Math.max(p.x,Math.max(p.y,p.z)))return n;var q,e,w=a.geometry,s=w.vertices,D;a.matrixRotationWorld.extractRotation(a.matrixWorld);r=0;for(p=w.faces.length;r<p;r++){b=w.faces[r];j.copy(this.origin);i.copy(this.direction);D=a.matrixWorld;o=D.multiplyVector3(o.copy(b.centroid)).subSelf(j);k=a.matrixRotationWorld.multiplyVector3(k.copy(b.normal));q=i.dot(k);if(!(Math.abs(q)<f)){e=k.dot(o)/q;if(!(e<0)&&(a.doubleSided||(a.flipSided?
  9972. q>0:q<0))){u.add(j,i.multiplyScalar(e));if(b instanceof THREE.Face3){g=D.multiplyVector3(g.copy(s[b.a]));h=D.multiplyVector3(h.copy(s[b.b]));l=D.multiplyVector3(l.copy(s[b.c]));if(d(u,g,h,l)){b={distance:j.distanceTo(u),point:u.clone(),face:b,object:a};n.push(b)}}else if(b instanceof THREE.Face4){g=D.multiplyVector3(g.copy(s[b.a]));h=D.multiplyVector3(h.copy(s[b.b]));l=D.multiplyVector3(l.copy(s[b.c]));m=D.multiplyVector3(m.copy(s[b.d]));if(d(u,g,h,m)||d(u,h,l,m)){b={distance:j.distanceTo(u),point:u.clone(),
  9973. face:b,object:a};n.push(b)}}}}}}return n};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 r=new THREE.Vector3,n=new THREE.Vector3,p=new THREE.Vector3,w,q,I,B,s,J,C,G,F,P,Q};
  9974. THREE.Rectangle=function(){function a(){g=d-b;h=f-c}var b,c,d,f,g,h,l=true;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return g};this.getHeight=function(){return h};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return f};this.set=function(g,h,i,o){l=false;b=g;c=h;d=i;f=o;a()};this.addPoint=function(g,h){if(l){l=false;b=g;c=h;d=g;f=h}else{b=b<g?b:g;c=c<h?c:h;d=d>g?d:g;f=f>h?
  9975. f:h}a()};this.add3Points=function(g,h,i,o,k,u){if(l){l=false;b=g<i?g<k?g:k:i<k?i:k;c=h<o?h<u?h:u:o<u?o:u;d=g>i?g>k?g:k:i>k?i:k;f=h>o?h>u?h:u:o>u?o:u}else{b=g<i?g<k?g<b?g:b:k<b?k:b:i<k?i<b?i:b:k<b?k:b;c=h<o?h<u?h<c?h:c:u<c?u:c:o<u?o<c?o:c:u<c?u:c;d=g>i?g>k?g>d?g:d:k>d?k:d:i>k?i>d?i:d:k>d?k:d;f=h>o?h>u?h>f?h:f:u>f?u:f:o>u?o>f?o:f:u>f?u:f}a()};this.addRectangle=function(g){if(l){l=false;b=g.getLeft();c=g.getTop();d=g.getRight();f=g.getBottom()}else{b=b<g.getLeft()?b:g.getLeft();c=c<g.getTop()?c:g.getTop();
  9976. d=d>g.getRight()?d:g.getRight();f=f>g.getBottom()?f:g.getBottom()}a()};this.inflate=function(g){b=b-g;c=c-g;d=d+g;f=f+g;a()};this.minSelf=function(g){b=b>g.getLeft()?b:g.getLeft();c=c>g.getTop()?c:g.getTop();d=d<g.getRight()?d:g.getRight();f=f<g.getBottom()?f:g.getBottom();a()};this.intersects=function(a){return d<a.getLeft()||b>a.getRight()||f<a.getTop()||c>a.getBottom()?false:true};this.empty=function(){l=true;f=d=c=b=0;a()};this.isEmpty=function(){return l}};
  9977. 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,f){return d+(a-b)*(f-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)};
  9978. 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],f=-b[10]*b[4]+b[6]*b[8],g=b[10]*b[0]-b[2]*b[8],h=-b[6]*b[0]+b[2]*b[4],l=b[9]*b[4]-b[5]*b[8],m=-b[9]*b[0]+b[1]*b[8],j=b[5]*b[0]-b[1]*b[4],b=b[0]*a+b[1]*f+b[2]*l;b===0&&console.warn("Matrix3.getInverse(): determinant == 0");var b=1/b,i=this.elements;i[0]=b*a;i[1]=b*c;i[2]=b*d;i[3]=b*f;i[4]=b*g;i[5]=b*h;i[6]=b*l;i[7]=b*m;i[8]=b*j;return this},
  9979. 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,f,g,h,l,m,j,i,o,k,u,r,n){this.elements=new Float32Array(16);this.set(a!==void 0?a:1,b||0,c||0,d||0,f||0,g!==void 0?g:1,h||0,l||0,m||0,j||0,i!==void 0?i:1,o||0,k||0,u||0,r||0,n!==void 0?n:1)};
  9980. THREE.Matrix4.prototype={constructor:THREE.Matrix4,set:function(a,b,c,d,f,g,h,l,m,j,i,o,k,u,r,n){var p=this.elements;p[0]=a;p[4]=b;p[8]=c;p[12]=d;p[1]=f;p[5]=g;p[9]=h;p[13]=l;p[2]=m;p[6]=j;p[10]=i;p[14]=o;p[3]=k;p[7]=u;p[11]=r;p[15]=n;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,
  9981. f=THREE.Matrix4.__v1,g=THREE.Matrix4.__v2,h=THREE.Matrix4.__v3;h.sub(a,b).normalize();if(h.length()===0)h.z=1;f.cross(c,h).normalize();if(f.length()===0){h.x=h.x+1.0E-4;f.cross(c,h).normalize()}g.cross(h,f);d[0]=f.x;d[4]=g.x;d[8]=h.x;d[1]=f.y;d[5]=g.y;d[9]=h.y;d[2]=f.z;d[6]=g.z;d[10]=h.z;return this},multiply:function(a,b){var c=a.elements,d=b.elements,f=this.elements,g=c[0],h=c[4],l=c[8],m=c[12],j=c[1],i=c[5],o=c[9],k=c[13],u=c[2],r=c[6],n=c[10],p=c[14],w=c[3],q=c[7],I=c[11],c=c[15],B=d[0],s=d[4],
  9982. J=d[8],C=d[12],G=d[1],F=d[5],P=d[9],Q=d[13],T=d[2],Z=d[6],R=d[10],z=d[14],H=d[3],E=d[7],e=d[11],d=d[15];f[0]=g*B+h*G+l*T+m*H;f[4]=g*s+h*F+l*Z+m*E;f[8]=g*J+h*P+l*R+m*e;f[12]=g*C+h*Q+l*z+m*d;f[1]=j*B+i*G+o*T+k*H;f[5]=j*s+i*F+o*Z+k*E;f[9]=j*J+i*P+o*R+k*e;f[13]=j*C+i*Q+o*z+k*d;f[2]=u*B+r*G+n*T+p*H;f[6]=u*s+r*F+n*Z+p*E;f[10]=u*J+r*P+n*R+p*e;f[14]=u*C+r*Q+n*z+p*d;f[3]=w*B+q*G+I*T+c*H;f[7]=w*s+q*F+I*Z+c*E;f[11]=w*J+q*P+I*R+c*e;f[15]=w*C+q*Q+I*z+c*d;return this},multiplySelf:function(a){return this.multiply(this,
  9983. 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]=
  9984. b[15]*a;return this},multiplyVector3:function(a){var b=this.elements,c=a.x,d=a.y,f=a.z,g=1/(b[3]*c+b[7]*d+b[11]*f+b[15]);a.x=(b[0]*c+b[4]*d+b[8]*f+b[12])*g;a.y=(b[1]*c+b[5]*d+b[9]*f+b[13])*g;a.z=(b[2]*c+b[6]*d+b[10]*f+b[14])*g;return a},multiplyVector4:function(a){var b=this.elements,c=a.x,d=a.y,f=a.z,g=a.w;a.x=b[0]*c+b[4]*d+b[8]*f+b[12]*g;a.y=b[1]*c+b[5]*d+b[9]*f+b[13]*g;a.z=b[2]*c+b[6]*d+b[10]*f+b[14]*g;a.w=b[3]*c+b[7]*d+b[11]*f+b[15]*g;return a},rotateAxis:function(a){var b=this.elements,c=a.x,
  9985. d=a.y,f=a.z;a.x=c*b[0]+d*b[4]+f*b[8];a.y=c*b[1]+d*b[5]+f*b[9];a.z=c*b[2]+d*b[6]+f*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],f=a[12],g=a[1],h=a[5],l=a[9],m=a[13],j=a[2],i=a[6],o=a[10],k=a[14],u=a[3],r=a[7],
  9986. n=a[11],a=a[15];return f*l*i*u-d*m*i*u-f*h*o*u+c*m*o*u+d*h*k*u-c*l*k*u-f*l*j*r+d*m*j*r+f*g*o*r-b*m*o*r-d*g*k*r+b*l*k*r+f*h*j*n-c*m*j*n-f*g*i*n+b*m*i*n+c*g*k*n-b*h*k*n-d*h*j*a+c*l*j*a+d*g*i*a-b*l*i*a-c*g*o*a+b*h*o*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];
  9987. 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],
  9988. 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],f=c[4],g=c[8],h=c[12],l=c[1],m=c[5],j=c[9],i=c[13],o=c[2],k=c[6],u=c[10],r=
  9989. c[14],n=c[3],p=c[7],w=c[11],c=c[15];b[0]=j*r*p-i*u*p+i*k*w-m*r*w-j*k*c+m*u*c;b[4]=h*u*p-g*r*p-h*k*w+f*r*w+g*k*c-f*u*c;b[8]=g*i*p-h*j*p+h*m*w-f*i*w-g*m*c+f*j*c;b[12]=h*j*k-g*i*k-h*m*u+f*i*u+g*m*r-f*j*r;b[1]=i*u*n-j*r*n-i*o*w+l*r*w+j*o*c-l*u*c;b[5]=g*r*n-h*u*n+h*o*w-d*r*w-g*o*c+d*u*c;b[9]=h*j*n-g*i*n-h*l*w+d*i*w+g*l*c-d*j*c;b[13]=g*i*o-h*j*o+h*l*u-d*i*u-g*l*r+d*j*r;b[2]=m*r*n-i*k*n+i*o*p-l*r*p-m*o*c+l*k*c;b[6]=h*k*n-f*r*n-h*o*p+d*r*p+f*o*c-d*k*c;b[10]=f*i*n-h*m*n+h*l*p-d*i*p-f*l*c+d*m*c;b[14]=h*m*o-
  9990. f*i*o-h*l*k+d*i*k+f*l*r-d*m*r;b[3]=j*k*n-m*u*n-j*o*p+l*u*p+m*o*w-l*k*w;b[7]=f*u*n-g*k*n+g*o*p-d*u*p-f*o*w+d*k*w;b[11]=g*m*n-f*j*n-g*l*p+d*j*p+f*l*w-d*m*w;b[15]=f*j*o-g*m*o+g*l*k-d*j*k-f*l*u+d*m*u;this.multiplyScalar(1/a.determinant());return this},setRotationFromEuler:function(a,b){var c=this.elements,d=a.x,f=a.y,g=a.z,h=Math.cos(d),d=Math.sin(d),l=Math.cos(f),f=Math.sin(f),m=Math.cos(g),g=Math.sin(g);switch(b){case "YXZ":var j=l*m,i=l*g,o=f*m,k=f*g;c[0]=j+k*d;c[4]=o*d-i;c[8]=h*f;c[1]=h*g;c[5]=h*
  9991. m;c[9]=-d;c[2]=i*d-o;c[6]=k+j*d;c[10]=h*l;break;case "ZXY":j=l*m;i=l*g;o=f*m;k=f*g;c[0]=j-k*d;c[4]=-h*g;c[8]=o+i*d;c[1]=i+o*d;c[5]=h*m;c[9]=k-j*d;c[2]=-h*f;c[6]=d;c[10]=h*l;break;case "ZYX":j=h*m;i=h*g;o=d*m;k=d*g;c[0]=l*m;c[4]=o*f-i;c[8]=j*f+k;c[1]=l*g;c[5]=k*f+j;c[9]=i*f-o;c[2]=-f;c[6]=d*l;c[10]=h*l;break;case "YZX":j=h*l;i=h*f;o=d*l;k=d*f;c[0]=l*m;c[4]=k-j*g;c[8]=o*g+i;c[1]=g;c[5]=h*m;c[9]=-d*m;c[2]=-f*m;c[6]=i*g+o;c[10]=j-k*g;break;case "XZY":j=h*l;i=h*f;o=d*l;k=d*f;c[0]=l*m;c[4]=-g;c[8]=f*m;
  9992. c[1]=j*g+k;c[5]=h*m;c[9]=i*g-o;c[2]=o*g-i;c[6]=d*m;c[10]=k*g+j;break;default:j=h*m;i=h*g;o=d*m;k=d*g;c[0]=l*m;c[4]=-l*g;c[8]=f;c[1]=i+o*f;c[5]=j-k*f;c[9]=-d*l;c[2]=k-j*f;c[6]=o+i*f;c[10]=h*l}return this},setRotationFromQuaternion:function(a){var b=this.elements,c=a.x,d=a.y,f=a.z,g=a.w,h=c+c,l=d+d,m=f+f,a=c*h,j=c*l,c=c*m,i=d*l,d=d*m,f=f*m,h=g*h,l=g*l,g=g*m;b[0]=1-(i+f);b[4]=j-g;b[8]=c+l;b[1]=j+g;b[5]=1-(a+f);b[9]=d-h;b[2]=c-l;b[6]=d+h;b[10]=1-(a+i);return this},compose:function(a,b,c){var d=this.elements,
  9993. f=THREE.Matrix4.__m1,g=THREE.Matrix4.__m2;f.identity();f.setRotationFromQuaternion(b);g.makeScale(c.x,c.y,c.z);this.multiply(f,g);d[12]=a.x;d[13]=a.y;d[14]=a.z;return this},decompose:function(a,b,c){var d=this.elements,f=THREE.Matrix4.__v1,g=THREE.Matrix4.__v2,h=THREE.Matrix4.__v3;f.set(d[0],d[1],d[2]);g.set(d[4],d[5],d[6]);h.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;
  9994. c.x=f.length();c.y=g.length();c.z=h.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;
  9995. 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(),f=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]*f;b[5]=a[5]*f;b[6]=a[6]*f;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]*
  9996. 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],f=b[6],g=b[7],h=b[8],l=b[9],m=b[10],j=b[11],i=Math.cos(a),a=Math.sin(a);b[4]=i*c+a*h;b[5]=i*d+a*l;b[6]=i*f+a*m;b[7]=i*g+a*j;b[8]=i*h-a*c;b[9]=i*l-a*d;b[10]=i*m-a*f;b[11]=i*j-a*g;return this},rotateY:function(a){var b=this.elements,c=b[0],d=b[1],f=b[2],g=b[3],h=b[8],l=b[9],m=b[10],j=b[11],i=Math.cos(a),a=Math.sin(a);b[0]=i*c-a*h;b[1]=i*d-a*l;b[2]=i*f-a*m;b[3]=i*g-a*j;b[8]=i*h+a*c;b[9]=
  9997. i*l+a*d;b[10]=i*m+a*f;b[11]=i*j+a*g;return this},rotateZ:function(a){var b=this.elements,c=b[0],d=b[1],f=b[2],g=b[3],h=b[4],l=b[5],m=b[6],j=b[7],i=Math.cos(a),a=Math.sin(a);b[0]=i*c+a*h;b[1]=i*d+a*l;b[2]=i*f+a*m;b[3]=i*g+a*j;b[4]=i*h-a*c;b[5]=i*l-a*d;b[6]=i*m-a*f;b[7]=i*j-a*g;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,
  9998. f=a.y,g=a.z,h=Math.sqrt(d*d+f*f+g*g),d=d/h,f=f/h,g=g/h,h=d*d,l=f*f,m=g*g,j=Math.cos(b),i=Math.sin(b),o=1-j,k=d*f*o,u=d*g*o,o=f*g*o,d=d*i,r=f*i,i=g*i,g=h+(1-h)*j,h=k+i,f=u-r,k=k-i,l=l+(1-l)*j,i=o+d,u=u+r,o=o-d,m=m+(1-m)*j,j=c[0],d=c[1],r=c[2],n=c[3],p=c[4],w=c[5],q=c[6],I=c[7],B=c[8],s=c[9],J=c[10],C=c[11];c[0]=g*j+h*p+f*B;c[1]=g*d+h*w+f*s;c[2]=g*r+h*q+f*J;c[3]=g*n+h*I+f*C;c[4]=k*j+l*p+i*B;c[5]=k*d+l*w+i*s;c[6]=k*r+l*q+i*J;c[7]=k*n+l*I+i*C;c[8]=u*j+o*p+m*B;c[9]=u*d+o*w+m*s;c[10]=u*r+o*q+m*J;c[11]=
  9999. u*n+o*I+m*C;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},
  10000. 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),f=1-c,g=a.x,h=a.y,l=a.z,m=f*g,j=f*h;this.set(m*g+c,m*h-d*l,m*l+d*h,0,m*h+d*l,j*h+c,j*l-d*g,0,m*l-
  10001. d*h,j*l+d*g,f*l*l+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,f,g){var h=this.elements;h[0]=2*f/(b-a);h[4]=0;h[8]=(b+a)/(b-a);h[12]=0;h[1]=0;h[5]=2*f/(d-c);h[9]=(d+c)/(d-c);h[13]=0;h[2]=0;h[6]=0;h[10]=-(g+f)/(g-f);h[14]=-2*g*f/(g-f);h[3]=0;h[7]=0;h[11]=-1;h[15]=0;return this},makePerspective:function(a,b,c,d){var a=c*Math.tan(a*Math.PI/360),f=-a;return this.makeFrustum(f*b,a*b,f,a,c,d)},makeOrthographic:function(a,
  10002. b,c,d,f,g){var h=this.elements,l=b-a,m=c-d,j=g-f;h[0]=2/l;h[4]=0;h[8]=0;h[12]=-((b+a)/l);h[1]=0;h[5]=2/m;h[9]=0;h[13]=-((c+d)/m);h[2]=0;h[6]=0;h[10]=-2/j;h[14]=-((g+f)/j);h[3]=0;h[7]=0;h[11]=0;h[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;
  10003. THREE.Matrix4.__m2=new THREE.Matrix4;
  10004. 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=
  10005. 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};
  10006. 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,
  10007. 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=
  10008. 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,f;c=0;for(d=this.children.length;c<d;c++){f=this.children[c];if(f.name===a)return f;if(b){f=f.getChildByName(a,b);if(f!==void 0)return f}}},updateMatrix:function(){this.matrix.setPosition(this.position);this.useQuaternion?this.matrix.setRotationFromQuaternion(this.quaternion):this.matrix.setRotationFromEuler(this.rotation,
  10009. 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<
  10010. c;b++)this.children[b].updateMatrixWorld(a)}};THREE.Object3DCount=0;
  10011. THREE.Projector=function(){function a(){var a=h[g]=h[g]||new THREE.RenderableObject;g++;return a}function b(){var a=j[m]=j[m]||new THREE.RenderableVertex;m++;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-
  10012. d);return true}var f,g,h=[],l,m,j=[],i,o,k=[],u,r=[],n,p,w=[],q,I,B=[],s={objects:[],sprites:[],lights:[],elements:[]},J=new THREE.Vector3,C=new THREE.Vector4,G=new THREE.Matrix4,F=new THREE.Matrix4,P=new THREE.Frustum,Q=new THREE.Vector4,T=new THREE.Vector4;this.projectVector=function(a,b){b.matrixWorldInverse.getInverse(b.matrixWorld);G.multiply(b.projectionMatrix,b.matrixWorldInverse);G.multiplyVector3(a);return a};this.unprojectVector=function(a,b){b.projectionMatrixInverse.getInverse(b.projectionMatrix);
  10013. G.multiply(b.matrixWorld,b.projectionMatrixInverse);G.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){g=0;s.objects.length=0;s.sprites.length=0;s.lights.length=0;var h=function(b){if(b.visible!==false){if((b instanceof THREE.Mesh||b instanceof THREE.Line)&&(b.frustumCulled===false||P.contains(b))){J.copy(b.matrixWorld.getPosition());
  10014. G.multiplyVector3(J);f=a();f.object=b;f.z=J.z;s.objects.push(f)}else if(b instanceof THREE.Sprite||b instanceof THREE.Particle){J.copy(b.matrixWorld.getPosition());G.multiplyVector3(J);f=a();f.object=b;f.z=J.z;s.sprites.push(f)}else b instanceof THREE.Light&&s.lights.push(b);for(var c=0,e=b.children.length;c<e;c++)h(b.children[c])}};h(b);d&&s.objects.sort(c);return s};this.projectScene=function(a,f,g){var h=f.near,E=f.far,e=false,J,X,D,la,S,ma,ua,ra,L,Aa,Ca,Na,Ua,Oa,Fa;I=p=u=o=0;s.elements.length=
  10015. 0;if(f.parent===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);G.multiply(f.projectionMatrix,f.matrixWorldInverse);P.setFromMatrix(G);s=this.projectGraph(a,false);a=0;for(J=s.objects.length;a<J;a++){L=s.objects[a].object;Aa=L.matrixWorld;m=0;if(L instanceof THREE.Mesh){Ca=L.geometry;Na=L.geometry.materials;la=Ca.vertices;Ua=Ca.faces;Oa=Ca.faceVertexUvs;Ca=L.matrixRotationWorld.extractRotation(Aa);
  10016. X=0;for(D=la.length;X<D;X++){l=b();l.positionWorld.copy(la[X]);Aa.multiplyVector3(l.positionWorld);l.positionScreen.copy(l.positionWorld);G.multiplyVector4(l.positionScreen);l.positionScreen.x=l.positionScreen.x/l.positionScreen.w;l.positionScreen.y=l.positionScreen.y/l.positionScreen.w;l.visible=l.positionScreen.z>h&&l.positionScreen.z<E}la=0;for(X=Ua.length;la<X;la++){D=Ua[la];if(D instanceof THREE.Face3){S=j[D.a];ma=j[D.b];ua=j[D.c];if(S.visible&&ma.visible&&ua.visible){e=(ua.positionScreen.x-
  10017. S.positionScreen.x)*(ma.positionScreen.y-S.positionScreen.y)-(ua.positionScreen.y-S.positionScreen.y)*(ma.positionScreen.x-S.positionScreen.x)<0;if(L.doubleSided||e!=L.flipSided){ra=k[o]=k[o]||new THREE.RenderableFace3;o++;i=ra;i.v1.copy(S);i.v2.copy(ma);i.v3.copy(ua)}else continue}else continue}else if(D instanceof THREE.Face4){S=j[D.a];ma=j[D.b];ua=j[D.c];ra=j[D.d];if(S.visible&&ma.visible&&ua.visible&&ra.visible){e=(ra.positionScreen.x-S.positionScreen.x)*(ma.positionScreen.y-S.positionScreen.y)-
  10018. (ra.positionScreen.y-S.positionScreen.y)*(ma.positionScreen.x-S.positionScreen.x)<0||(ma.positionScreen.x-ua.positionScreen.x)*(ra.positionScreen.y-ua.positionScreen.y)-(ma.positionScreen.y-ua.positionScreen.y)*(ra.positionScreen.x-ua.positionScreen.x)<0;if(L.doubleSided||e!=L.flipSided){Fa=r[u]=r[u]||new THREE.RenderableFace4;u++;i=Fa;i.v1.copy(S);i.v2.copy(ma);i.v3.copy(ua);i.v4.copy(ra)}else continue}else continue}i.normalWorld.copy(D.normal);!e&&(L.flipSided||L.doubleSided)&&i.normalWorld.negate();
  10019. Ca.multiplyVector3(i.normalWorld);i.centroidWorld.copy(D.centroid);Aa.multiplyVector3(i.centroidWorld);i.centroidScreen.copy(i.centroidWorld);G.multiplyVector3(i.centroidScreen);ua=D.vertexNormals;S=0;for(ma=ua.length;S<ma;S++){ra=i.vertexNormalsWorld[S];ra.copy(ua[S]);!e&&(L.flipSided||L.doubleSided)&&ra.negate();Ca.multiplyVector3(ra)}S=0;for(ma=Oa.length;S<ma;S++)if(Fa=Oa[S][la]){ua=0;for(ra=Fa.length;ua<ra;ua++)i.uvs[S][ua]=Fa[ua]}i.material=L.material;i.faceMaterial=D.materialIndex!==null?Na[D.materialIndex]:
  10020. null;i.z=i.centroidScreen.z;s.elements.push(i)}}else if(L instanceof THREE.Line){F.multiply(G,Aa);la=L.geometry.vertices;S=b();S.positionScreen.copy(la[0]);F.multiplyVector4(S.positionScreen);Aa=L.type===THREE.LinePieces?2:1;X=1;for(D=la.length;X<D;X++){S=b();S.positionScreen.copy(la[X]);F.multiplyVector4(S.positionScreen);if(!((X+1)%Aa>0)){ma=j[m-2];Q.copy(S.positionScreen);T.copy(ma.positionScreen);if(d(Q,T)){Q.multiplyScalar(1/Q.w);T.multiplyScalar(1/T.w);Na=w[p]=w[p]||new THREE.RenderableLine;
  10021. p++;n=Na;n.v1.positionScreen.copy(Q);n.v2.positionScreen.copy(T);n.z=Math.max(Q.z,T.z);n.material=L.material;s.elements.push(n)}}}}}a=0;for(J=s.sprites.length;a<J;a++){L=s.sprites[a].object;Aa=L.matrixWorld;if(L instanceof THREE.Particle){C.set(Aa.elements[12],Aa.elements[13],Aa.elements[14],1);G.multiplyVector4(C);C.z=C.z/C.w;if(C.z>0&&C.z<1){h=B[I]=B[I]||new THREE.RenderableParticle;I++;q=h;q.x=C.x/C.w;q.y=C.y/C.w;q.z=C.z;q.rotation=L.rotation.z;q.scale.x=L.scale.x*Math.abs(q.x-(C.x+f.projectionMatrix.elements[0])/
  10022. (C.w+f.projectionMatrix.elements[12]));q.scale.y=L.scale.y*Math.abs(q.y-(C.y+f.projectionMatrix.elements[5])/(C.w+f.projectionMatrix.elements[13]));q.material=L.material;s.elements.push(q)}}}g&&s.elements.sort(c);return s}};THREE.Quaternion=function(a,b,c,d){this.x=a||0;this.y=b||0;this.z=c||0;this.w=d!==void 0?d:1};
  10023. 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,f=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-f),f=Math.sin(-f),g=Math.cos(c),c=Math.sin(c),h=a*b,l=d*f;this.w=h*g-l*c;this.x=h*c+l*g;this.y=d*b*g+a*f*c;this.z=a*f*g-d*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c);
  10024. 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):
  10025. 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=
  10026. 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,f=this.w,g=a.x,h=a.y,l=a.z,a=a.w;this.x=b*a+f*g+c*l-d*h;this.y=
  10027. c*a+f*h+d*g-b*l;this.z=d*a+f*l+b*h-c*g;this.w=f*a-b*g-c*h-d*l;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,f=a.z,g=this.x,h=this.y,l=this.z,m=this.w,j=m*c+h*f-l*d,i=m*d+l*c-g*f,o=m*f+g*d-h*c,c=-g*c-h*d-l*f;b.x=j*m+c*-g+i*-l-o*-h;b.y=i*m+c*-h+o*-g-j*-l;b.z=o*m+c*-l+j*-h-i*-g;return b},clone:function(){return new THREE.Quaternion(this.x,this.y,this.z,this.w)}};
  10028. THREE.Quaternion.slerp=function(a,b,c,d){var f=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;if(f<0){c.w=-b.w;c.x=-b.x;c.y=-b.y;c.z=-b.z;f=-f}else c.copy(b);if(Math.abs(f)>=1){c.w=a.w;c.x=a.x;c.y=a.y;c.z=a.z;return c}var g=Math.acos(f),f=Math.sqrt(1-f*f);if(Math.abs(f)<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)*g)/f;d=Math.sin(d*g)/f;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.")};
  10029. THREE.Face3=function(a,b,c,d,f,g){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=f instanceof THREE.Color?f:new THREE.Color;this.vertexColors=f instanceof Array?f:[];this.vertexTangents=[];this.materialIndex=g;this.centroid=new THREE.Vector3};
  10030. 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();
  10031. return a}};THREE.Face4=function(a,b,c,d,f,g,h){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.color=g instanceof THREE.Color?g:new THREE.Color;this.vertexColors=g instanceof Array?g:[];this.vertexTangents=[];this.materialIndex=h;this.centroid=new THREE.Vector3};
  10032. 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();
  10033. 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)}};
  10034. 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};
  10035. 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 f=this.faces[c];b.multiplyVector3(f.normal);for(var g=0,h=f.vertexNormals.length;g<h;g++)b.multiplyVector3(f.vertexNormals[g]);a.multiplyVector3(f.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,
  10036. 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,f,g,h=new THREE.Vector3,l=new THREE.Vector3;a=0;for(b=this.faces.length;a<
  10037. b;a++){c=this.faces[a];d=this.vertices[c.a];f=this.vertices[c.b];g=this.vertices[c.c];h.sub(g,f);l.sub(d,f);h.crossSelf(l);h.isZero()||h.normalize();c.normal.copy(h)}},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];
  10038. 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;
  10039. 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,f;c=0;for(d=this.faces.length;c<d;c++){f=this.faces[c];f.__originalFaceNormal?
  10040. f.__originalFaceNormal.copy(f.normal):f.__originalFaceNormal=f.normal.clone();if(!f.__originalVertexNormals)f.__originalVertexNormals=[];a=0;for(b=f.vertexNormals.length;a<b;a++)f.__originalVertexNormals[a]?f.__originalVertexNormals[a].copy(f.vertexNormals[a]):f.__originalVertexNormals[a]=f.vertexNormals[a].clone()}var g=new THREE.Geometry;g.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=
  10041. [];var h=this.morphNormals[a].faceNormals,l=this.morphNormals[a].vertexNormals,m,j;c=0;for(d=this.faces.length;c<d;c++){f=this.faces[c];m=new THREE.Vector3;j=f 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};h.push(m);l.push(j)}}h=this.morphNormals[a];g.vertices=this.morphTargets[a].vertices;g.computeFaceNormals();g.computeVertexNormals();c=0;for(d=this.faces.length;c<d;c++){f=this.faces[c];
  10042. m=h.faceNormals[c];j=h.vertexNormals[c];m.copy(f.normal);if(f instanceof THREE.Face3){j.a.copy(f.vertexNormals[0]);j.b.copy(f.vertexNormals[1]);j.c.copy(f.vertexNormals[2])}else{j.a.copy(f.vertexNormals[0]);j.b.copy(f.vertexNormals[1]);j.c.copy(f.vertexNormals[2]);j.d.copy(f.vertexNormals[3])}}}c=0;for(d=this.faces.length;c<d;c++){f=this.faces[c];f.normal=f.__originalFaceNormal;f.vertexNormals=f.__originalVertexNormals}},computeTangents:function(){function a(a,b,c,d,f,g,S){l=a.vertices[b];m=a.vertices[c];
  10043. j=a.vertices[d];i=h[f];o=h[g];k=h[S];u=m.x-l.x;r=j.x-l.x;n=m.y-l.y;p=j.y-l.y;w=m.z-l.z;q=j.z-l.z;I=o.u-i.u;B=k.u-i.u;s=o.v-i.v;J=k.v-i.v;C=1/(I*J-B*s);Q.set((J*u-s*r)*C,(J*n-s*p)*C,(J*w-s*q)*C);T.set((I*r-B*u)*C,(I*p-B*n)*C,(I*q-B*w)*C);F[b].addSelf(Q);F[c].addSelf(Q);F[d].addSelf(Q);P[b].addSelf(T);P[c].addSelf(T);P[d].addSelf(T)}var b,c,d,f,g,h,l,m,j,i,o,k,u,r,n,p,w,q,I,B,s,J,C,G,F=[],P=[],Q=new THREE.Vector3,T=new THREE.Vector3,Z=new THREE.Vector3,R=new THREE.Vector3,z=new THREE.Vector3;b=0;for(c=
  10044. this.vertices.length;b<c;b++){F[b]=new THREE.Vector3;P[b]=new THREE.Vector3}b=0;for(c=this.faces.length;b<c;b++){g=this.faces[b];h=this.faceVertexUvs[0][b];if(g instanceof THREE.Face3)a(this,g.a,g.b,g.c,0,1,2);else if(g instanceof THREE.Face4){a(this,g.a,g.b,g.d,0,1,3);a(this,g.b,g.c,g.d,1,2,3)}}var H=["a","b","c","d"];b=0;for(c=this.faces.length;b<c;b++){g=this.faces[b];for(d=0;d<g.vertexNormals.length;d++){z.copy(g.vertexNormals[d]);f=g[H[d]];G=F[f];Z.copy(G);Z.subSelf(z.multiplyScalar(z.dot(G))).normalize();
  10045. R.cross(g.vertexNormals[d],G);f=R.dot(P[f]);f=f<0?-1:1;g.vertexTangents[d]=new THREE.Vector4(Z.x,Z.y,Z.z,f)}}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,f=this.vertices.length;d<f;d++){a=this.vertices[d];if(a.x<b.x)b.x=a.x;else if(a.x>c.x)c.x=
  10046. 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,f=Math.pow(10,4),g,h,l;g=0;for(h=this.vertices.length;g<h;g++){d=this.vertices[g];d=[Math.round(d.x*
  10047. f),Math.round(d.y*f),Math.round(d.z*f)].join("_");if(a[d]===void 0){a[d]=g;b.push(this.vertices[g]);c[g]=b.length-1}else c[g]=c[a[d]]}g=0;for(h=this.faces.length;g<h;g++){f=this.faces[g];if(f instanceof THREE.Face3){f.a=c[f.a];f.b=c[f.b];f.c=c[f.c]}else if(f instanceof THREE.Face4){f.a=c[f.a];f.b=c[f.b];f.c=c[f.c];f.d=c[f.d];d=[f.a,f.b,f.c,f.d];for(a=3;a>0;a--)if(d.indexOf(f["abcd"[a]])!=a){d.splice(a,1);this.faces[g]=new THREE.Face3(d[0],d[1],d[2]);f=0;for(d=this.faceVertexUvs.length;f<d;f++)(l=
  10048. this.faceVertexUvs[f][g])&&l.splice(a,1);break}}}c=this.vertices.length-b.length;this.vertices=b;return c}};THREE.GeometryCount=0;
  10049. THREE.Spline=function(a){function b(a,b,c,d,f,g,h){a=(c-a)*0.5;d=(d-b)*0.5;return(2*(b-c)+a+d)*h+(-3*(b-c)-2*a-d)*g+a*f+b}this.points=a;var c=[],d={x:0,y:0,z:0},f,g,h,l,m,j,i,o,k;this.initFromArray=function(a){this.points=[];for(var b=0;b<a.length;b++)this.points[b]={x:a[b][0],y:a[b][1],z:a[b][2]}};this.getPoint=function(a){f=(this.points.length-1)*a;g=Math.floor(f);h=f-g;c[0]=g===0?g:g-1;c[1]=g;c[2]=g>this.points.length-2?this.points.length-1:g+1;c[3]=g>this.points.length-3?this.points.length-1:
  10050. g+2;j=this.points[c[0]];i=this.points[c[1]];o=this.points[c[2]];k=this.points[c[3]];l=h*h;m=h*l;d.x=b(j.x,i.x,o.x,k.x,h,l,m);d.y=b(j.y,i.y,o.y,k.y,h,l,m);d.z=b(j.z,i.z,o.z,k.z,h,l,m);return d};this.getControlPointsArray=function(){var a,b,c=this.points.length,d=[];for(a=0;a<c;a++){b=this.points[a];d[a]=[b.x,b.y,b.z]}return d};this.getLength=function(a){var b,c,d,f=b=b=0,g=new THREE.Vector3,h=new THREE.Vector3,i=[],l=0;i[0]=0;a||(a=100);c=this.points.length*a;g.copy(this.points[0]);for(a=1;a<c;a++){b=
  10051. a/c;d=this.getPoint(b);h.copy(d);l=l+h.distanceTo(g);g.copy(d);b=(this.points.length-1)*b;b=Math.floor(b);if(b!=f){i[b]=l;f=b}}i[i.length]=l;return{chunks:i,total:l}};this.reparametrizeByArcLength=function(a){var b,c,d,f,g,h,i=[],l=new THREE.Vector3,k=this.getLength();i.push(l.copy(this.points[0]).clone());for(b=1;b<this.points.length;b++){c=k.chunks[b]-k.chunks[b-1];h=Math.ceil(a*c/k.total);f=(b-1)/(this.points.length-1);g=b/(this.points.length-1);for(c=1;c<h-1;c++){d=f+c*(1/h)*(g-f);d=this.getPoint(d);
  10052. i.push(l.copy(d).clone())}i.push(l.copy(this.points[b]).clone())}this.points=i}};THREE.Camera=function(){THREE.Object3D.call(this);this.matrixWorldInverse=new THREE.Matrix4;this.projectionMatrix=new THREE.Matrix4;this.projectionMatrixInverse=new THREE.Matrix4};THREE.Camera.prototype=new THREE.Object3D;THREE.Camera.prototype.constructor=THREE.Camera;THREE.Camera.prototype.lookAt=function(a){this.matrix.lookAt(this.position,a,this.up);this.rotationAutoUpdate&&this.rotation.getRotationFromMatrix(this.matrix)};
  10053. THREE.OrthographicCamera=function(a,b,c,d,f,g){THREE.Camera.call(this);this.left=a;this.right=b;this.top=c;this.bottom=d;this.near=f!==void 0?f:0.1;this.far=g!==void 0?g:2E3;this.updateProjectionMatrix()};THREE.OrthographicCamera.prototype=new THREE.Camera;THREE.OrthographicCamera.prototype.constructor=THREE.OrthographicCamera;THREE.OrthographicCamera.prototype.updateProjectionMatrix=function(){this.projectionMatrix.makeOrthographic(this.left,this.right,this.top,this.bottom,this.near,this.far)};
  10054. THREE.PerspectiveCamera=function(a,b,c,d){THREE.Camera.call(this);this.fov=a!==void 0?a:50;this.aspect=b!==void 0?b:1;this.near=c!==void 0?c:0.1;this.far=d!==void 0?d:2E3;this.updateProjectionMatrix()};THREE.PerspectiveCamera.prototype=new THREE.Camera;THREE.PerspectiveCamera.prototype.constructor=THREE.PerspectiveCamera;THREE.PerspectiveCamera.prototype.setLens=function(a,b){this.fov=2*Math.atan((b!==void 0?b:24)/(a*2))*(180/Math.PI);this.updateProjectionMatrix()};
  10055. THREE.PerspectiveCamera.prototype.setViewOffset=function(a,b,c,d,f,g){this.fullWidth=a;this.fullHeight=b;this.x=c;this.y=d;this.width=f;this.height=g;this.updateProjectionMatrix()};
  10056. 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)};
  10057. 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;
  10058. 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;
  10059. 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;
  10060. 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;
  10061. THREE.SpotLight=function(a,b,c,d,f){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.angle=d!==void 0?d:Math.PI/2;this.exponent=f!==void 0?f:10;this.onlyShadow=this.castShadow=false;this.shadowCameraNear=50;this.shadowCameraFar=5E3;this.shadowCameraFov=50;this.shadowCameraVisible=false;this.shadowBias=0;this.shadowDarkness=0.5;this.shadowMapHeight=this.shadowMapWidth=512;this.shadowMatrix=
  10062. this.shadowCamera=this.shadowMapSize=this.shadowMap=null};THREE.SpotLight.prototype=new THREE.Light;THREE.SpotLight.prototype.constructor=THREE.SpotLight;THREE.Loader=function(a){this.statusDomElement=(this.showStatus=a)?THREE.Loader.prototype.addStatusElement():null;this.onLoadStart=function(){};this.onLoadProgress=function(){};this.onLoadComplete=function(){}};
  10063. 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/
  10064. 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=
  10065. 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 f(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=l.crossOrigin;f.src=b}function g(a,c,d,g,h,i){var l=document.createElement("canvas");a[c]=new THREE.Texture(l);a[c].sourceFile=
  10066. d;if(g){a[c].repeat.set(g[0],g[1]);if(g[0]!=1)a[c].wrapS=THREE.RepeatWrapping;if(g[1]!=1)a[c].wrapT=THREE.RepeatWrapping}h&&a[c].offset.set(h[0],h[1]);if(i){g={repeat:THREE.RepeatWrapping,mirror:THREE.MirroredRepeatWrapping};if(g[i[0]]!==void 0)a[c].wrapS=g[i[0]];if(g[i[1]]!==void 0)a[c].wrapT=g[i[1]]}f(a[c],b+"/"+d)}function h(a){return(a[0]*255<<16)+(a[1]*255<<8)+a[2]*255}var l=this,m="MeshLambertMaterial",j={color:15658734,opacity:1,map:null,lightMap:null,normalMap:null,wireframe:a.wireframe};
  10067. if(a.shading){var i=a.shading.toLowerCase();i==="phong"?m="MeshPhongMaterial":i==="basic"&&(m="MeshBasicMaterial")}if(a.blending!==void 0&&THREE[a.blending]!==void 0)j.blending=THREE[a.blending];if(a.transparent!==void 0||a.opacity<1)j.transparent=a.transparent;if(a.depthTest!==void 0)j.depthTest=a.depthTest;if(a.depthWrite!==void 0)j.depthWrite=a.depthWrite;if(a.vertexColors!==void 0)if(a.vertexColors=="face")j.vertexColors=THREE.FaceColors;else if(a.vertexColors)j.vertexColors=THREE.VertexColors;
  10068. if(a.colorDiffuse)j.color=h(a.colorDiffuse);else if(a.DbgColor)j.color=a.DbgColor;if(a.colorSpecular)j.specular=h(a.colorSpecular);if(a.colorAmbient)j.ambient=h(a.colorAmbient);if(a.transparency)j.opacity=a.transparency;if(a.specularCoef)j.shininess=a.specularCoef;a.mapDiffuse&&b&&g(j,"map",a.mapDiffuse,a.mapDiffuseRepeat,a.mapDiffuseOffset,a.mapDiffuseWrap);a.mapLight&&b&&g(j,"lightMap",a.mapLight,a.mapLightRepeat,a.mapLightOffset,a.mapLightWrap);a.mapNormal&&b&&g(j,"normalMap",a.mapNormal,a.mapNormalRepeat,
  10069. a.mapNormalOffset,a.mapNormalWrap);a.mapSpecular&&b&&g(j,"specularMap",a.mapSpecular,a.mapSpecularRepeat,a.mapSpecularOffset,a.mapSpecularWrap);if(a.mapNormal){m=THREE.ShaderUtils.lib.normal;i=THREE.UniformsUtils.clone(m.uniforms);i.tNormal.texture=j.normalMap;if(a.mapNormalFactor)i.uNormalScale.value=a.mapNormalFactor;if(j.map){i.tDiffuse.texture=j.map;i.enableDiffuse.value=true}if(j.specularMap){i.tSpecular.texture=j.specularMap;i.enableSpecular.value=true}if(j.lightMap){i.tAO.texture=j.lightMap;
  10070. i.enableAO.value=true}i.uDiffuseColor.value.setHex(j.color);i.uSpecularColor.value.setHex(j.specular);i.uAmbientColor.value.setHex(j.ambient);i.uShininess.value=j.shininess;if(j.opacity!==void 0)i.uOpacity.value=j.opacity;j=new THREE.ShaderMaterial({fragmentShader:m.fragmentShader,vertexShader:m.vertexShader,uniforms:i,lights:true,fog:true})}else j=new THREE[m](j);if(a.DbgName!==void 0)j.name=a.DbgName;return j}};THREE.BinaryLoader=function(a){THREE.Loader.call(this,a)};
  10071. 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),f=this.showProgress?THREE.Loader.prototype.updateProgress:null;this.onLoadStart();this.loadAjaxJSON(this,a,b,c,d,f)};
  10072. THREE.BinaryLoader.prototype.loadAjaxJSON=function(a,b,c,d,f,g){var h=new XMLHttpRequest;h.onreadystatechange=function(){if(h.readyState==4)if(h.status==200||h.status==0){var l=JSON.parse(h.responseText);a.loadAjaxBuffers(l,c,f,d,g)}else console.error("THREE.BinaryLoader: Couldn't load ["+b+"] ["+h.status+"]")};h.open("GET",b,true);h.overrideMimeType&&h.overrideMimeType("text/plain; charset=x-user-defined");h.setRequestHeader("Content-Type","text/plain");h.send(null)};
  10073. THREE.BinaryLoader.prototype.loadAjaxBuffers=function(a,b,c,d,f){var g=new XMLHttpRequest,h=c+"/"+a.buffers,l=0;g.onreadystatechange=function(){if(g.readyState==4)g.status==200||g.status==0?THREE.BinaryLoader.prototype.createBinModel(g.response,b,d,a.materials):console.error("THREE.BinaryLoader: Couldn't load ["+h+"] ["+g.status+"]");else if(g.readyState==3){if(f){l==0&&(l=g.getResponseHeader("Content-Length"));f({total:l,loaded:g.responseText.length})}}else g.readyState==2&&(l=g.getResponseHeader("Content-Length"))};
  10074. g.open("GET",h,true);g.responseType="arraybuffer";g.send(null)};
  10075. THREE.BinaryLoader.prototype.createBinModel=function(a,b,c,d){var f=function(b){var c,f,m,j,i,o,k,u,r,n,p,w,q,I,B;function s(a){return a%4?4-a%4:0}function J(a,b){return(new Uint8Array(a,b,1))[0]}function C(a,b){return(new Uint32Array(a,b,1))[0]}function G(b,c){var e,d,f,g,h,i,l,j,k=new Uint32Array(a,c,3*b);for(e=0;e<b;e++){d=k[e*3];f=k[e*3+1];g=k[e*3+2];h=E[d*2];d=E[d*2+1];i=E[f*2];l=E[f*2+1];f=E[g*2];j=E[g*2+1];g=R.faceVertexUvs[0];var m=[];m.push(new THREE.UV(h,d));m.push(new THREE.UV(i,l));m.push(new THREE.UV(f,
  10076. j));g.push(m)}}function F(b,c){var e,d,f,g,h,i,l,k,j,m,n=new Uint32Array(a,c,4*b);for(e=0;e<b;e++){d=n[e*4];f=n[e*4+1];g=n[e*4+2];h=n[e*4+3];i=E[d*2];d=E[d*2+1];l=E[f*2];j=E[f*2+1];k=E[g*2];m=E[g*2+1];g=E[h*2];f=E[h*2+1];h=R.faceVertexUvs[0];var o=[];o.push(new THREE.UV(i,d));o.push(new THREE.UV(l,j));o.push(new THREE.UV(k,m));o.push(new THREE.UV(g,f));h.push(o)}}function P(b,c,e){for(var d,f,g,h,c=new Uint32Array(a,c,3*b),i=new Uint16Array(a,e,b),e=0;e<b;e++){d=c[e*3];f=c[e*3+1];g=c[e*3+2];h=i[e];
  10077. R.faces.push(new THREE.Face3(d,f,g,null,null,h))}}function Q(b,c,e){for(var d,f,g,h,i,c=new Uint32Array(a,c,4*b),l=new Uint16Array(a,e,b),e=0;e<b;e++){d=c[e*4];f=c[e*4+1];g=c[e*4+2];h=c[e*4+3];i=l[e];R.faces.push(new THREE.Face4(d,f,g,h,null,null,i))}}function T(b,c,e,d){for(var f,g,h,i,l,k,j,c=new Uint32Array(a,c,3*b),e=new Uint32Array(a,e,3*b),m=new Uint16Array(a,d,b),d=0;d<b;d++){f=c[d*3];g=c[d*3+1];h=c[d*3+2];l=e[d*3];k=e[d*3+1];j=e[d*3+2];i=m[d];var n=H[k*3],o=H[k*3+1];k=H[k*3+2];var r=H[j*3],
  10078. p=H[j*3+1];j=H[j*3+2];R.faces.push(new THREE.Face3(f,g,h,[new THREE.Vector3(H[l*3],H[l*3+1],H[l*3+2]),new THREE.Vector3(n,o,k),new THREE.Vector3(r,p,j)],null,i))}}function Z(b,c,e,d){for(var f,g,h,i,l,k,j,m,n,c=new Uint32Array(a,c,4*b),e=new Uint32Array(a,e,4*b),o=new Uint16Array(a,d,b),d=0;d<b;d++){f=c[d*4];g=c[d*4+1];h=c[d*4+2];i=c[d*4+3];k=e[d*4];j=e[d*4+1];m=e[d*4+2];n=e[d*4+3];l=o[d];var r=H[j*3],p=H[j*3+1];j=H[j*3+2];var q=H[m*3],u=H[m*3+1];m=H[m*3+2];var s=H[n*3],w=H[n*3+1];n=H[n*3+2];R.faces.push(new THREE.Face4(f,
  10079. g,h,i,[new THREE.Vector3(H[k*3],H[k*3+1],H[k*3+2]),new THREE.Vector3(r,p,j),new THREE.Vector3(q,u,m),new THREE.Vector3(s,w,n)],null,l))}}var R=this,z=0,H=[],E=[],e,Ba,X;THREE.Geometry.call(this);THREE.Loader.prototype.initMaterials(R,d,b);(function(a,b,c){for(var a=new Uint8Array(a,b,c),e="",d=0;d<c;d++)e=e+String.fromCharCode(a[b+d]);return e})(a,z,12);c=J(a,z+12);J(a,z+13);J(a,z+14);J(a,z+15);f=J(a,z+16);m=J(a,z+17);j=J(a,z+18);i=J(a,z+19);o=C(a,z+20);k=C(a,z+20+4);u=C(a,z+20+8);b=C(a,z+20+12);
  10080. r=C(a,z+20+16);n=C(a,z+20+20);p=C(a,z+20+24);w=C(a,z+20+28);q=C(a,z+20+32);I=C(a,z+20+36);B=C(a,z+20+40);z=z+c;c=f*3+i;X=f*4+i;e=b*c;Ba=r*(c+m*3);f=n*(c+j*3);i=p*(c+m*3+j*3);c=w*X;m=q*(X+m*4);j=I*(X+j*4);z=z+function(b){var b=new Float32Array(a,b,o*3),c,e,d,f;for(c=0;c<o;c++){e=b[c*3];d=b[c*3+1];f=b[c*3+2];R.vertices.push(new THREE.Vector3(e,d,f))}return o*3*Float32Array.BYTES_PER_ELEMENT}(z);z=z+function(b){if(k){var b=new Int8Array(a,b,k*3),c,e,d,f;for(c=0;c<k;c++){e=b[c*3];d=b[c*3+1];f=b[c*3+2];
  10081. H.push(e/127,d/127,f/127)}}return k*3*Int8Array.BYTES_PER_ELEMENT}(z);z=z+s(k*3);z=z+function(b){if(u){var b=new Float32Array(a,b,u*2),c,e,d;for(c=0;c<u;c++){e=b[c*2];d=b[c*2+1];E.push(e,d)}}return u*2*Float32Array.BYTES_PER_ELEMENT}(z);e=z+e+s(b*2);Ba=e+Ba+s(r*2);f=Ba+f+s(n*2);i=f+i+s(p*2);c=i+c+s(w*2);m=c+m+s(q*2);j=m+j+s(I*2);(function(a){if(n){var b=a+n*Uint32Array.BYTES_PER_ELEMENT*3;P(n,a,b+n*Uint32Array.BYTES_PER_ELEMENT*3);G(n,b)}})(Ba);(function(a){if(p){var b=a+p*Uint32Array.BYTES_PER_ELEMENT*
  10082. 3,c=b+p*Uint32Array.BYTES_PER_ELEMENT*3;T(p,a,b,c+p*Uint32Array.BYTES_PER_ELEMENT*3);G(p,c)}})(f);(function(a){if(I){var b=a+I*Uint32Array.BYTES_PER_ELEMENT*4;Q(I,a,b+I*Uint32Array.BYTES_PER_ELEMENT*4);F(I,b)}})(m);(function(a){if(B){var b=a+B*Uint32Array.BYTES_PER_ELEMENT*4,c=b+B*Uint32Array.BYTES_PER_ELEMENT*4;Z(B,a,b,c+B*Uint32Array.BYTES_PER_ELEMENT*4);F(B,c)}})(j);b&&P(b,z,z+b*Uint32Array.BYTES_PER_ELEMENT*3);(function(a){if(r){var b=a+r*Uint32Array.BYTES_PER_ELEMENT*3;T(r,a,b,b+r*Uint32Array.BYTES_PER_ELEMENT*
  10083. 3)}})(e);w&&Q(w,i,i+w*Uint32Array.BYTES_PER_ELEMENT*4);(function(a){if(q){var b=a+q*Uint32Array.BYTES_PER_ELEMENT*4;Z(q,a,b,b+q*Uint32Array.BYTES_PER_ELEMENT*4)}})(c);this.computeCentroids();this.computeFaceNormals();THREE.Loader.prototype.hasNormals(this)&&this.computeTangents()};f.prototype=new THREE.Geometry;f.prototype.constructor=f;b(new f(c))};THREE.JSONLoader=function(a){THREE.Loader.call(this,a)};THREE.JSONLoader.prototype=new THREE.Loader;THREE.JSONLoader.prototype.constructor=THREE.JSONLoader;
  10084. THREE.JSONLoader.prototype.load=function(a,b,c){c=c?c:this.extractUrlBase(a);this.onLoadStart();this.loadAjaxJSON(this,a,b,c)};
  10085. THREE.JSONLoader.prototype.loadAjaxJSON=function(a,b,c,d,f){var g=new XMLHttpRequest,h=0;g.onreadystatechange=function(){if(g.readyState===g.DONE)if(g.status===200||g.status===0){if(g.responseText){var l=JSON.parse(g.responseText);a.createModel(l,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+"] ["+g.status+"]");else if(g.readyState===g.LOADING){if(f){h===0&&(h=g.getResponseHeader("Content-Length"));
  10086. f({total:h,loaded:g.responseText.length})}}else g.readyState===g.HEADERS_RECEIVED&&(h=g.getResponseHeader("Content-Length"))};g.open("GET",b,true);g.overrideMimeType&&g.overrideMimeType("text/plain; charset=x-user-defined");g.setRequestHeader("Content-Type","text/plain");g.send(null)};
  10087. THREE.JSONLoader.prototype.createModel=function(a,b,c){var d=new THREE.Geometry,f=a.scale!==void 0?1/a.scale:1;this.initMaterials(d,a.materials,c);(function(b){var c,f,m,j,i,o,k,u,r,n,p,w,q,I,B=a.faces;o=a.vertices;var s=a.normals,J=a.colors,C=0;for(c=0;c<a.uvs.length;c++)a.uvs[c].length&&C++;for(c=0;c<C;c++){d.faceUvs[c]=[];d.faceVertexUvs[c]=[]}j=0;for(i=o.length;j<i;){k=new THREE.Vector3;k.x=o[j++]*b;k.y=o[j++]*b;k.z=o[j++]*b;d.vertices.push(k)}j=0;for(i=B.length;j<i;){b=B[j++];o=b&1;m=b&2;c=b&
  10088. 4;f=b&8;u=b&16;k=b&32;n=b&64;b=b&128;if(o){p=new THREE.Face4;p.a=B[j++];p.b=B[j++];p.c=B[j++];p.d=B[j++];o=4}else{p=new THREE.Face3;p.a=B[j++];p.b=B[j++];p.c=B[j++];o=3}if(m){m=B[j++];p.materialIndex=m}m=d.faces.length;if(c)for(c=0;c<C;c++){w=a.uvs[c];r=B[j++];I=w[r*2];r=w[r*2+1];d.faceUvs[c][m]=new THREE.UV(I,r)}if(f)for(c=0;c<C;c++){w=a.uvs[c];q=[];for(f=0;f<o;f++){r=B[j++];I=w[r*2];r=w[r*2+1];q[f]=new THREE.UV(I,r)}d.faceVertexUvs[c][m]=q}if(u){u=B[j++]*3;f=new THREE.Vector3;f.x=s[u++];f.y=s[u++];
  10089. f.z=s[u];p.normal=f}if(k)for(c=0;c<o;c++){u=B[j++]*3;f=new THREE.Vector3;f.x=s[u++];f.y=s[u++];f.z=s[u];p.vertexNormals.push(f)}if(n){k=B[j++];k=new THREE.Color(J[k]);p.color=k}if(b)for(c=0;c<o;c++){k=B[j++];k=new THREE.Color(J[k]);p.vertexColors.push(k)}d.faces.push(p)}})(f);(function(){var b,c,f,m;if(a.skinWeights){b=0;for(c=a.skinWeights.length;b<c;b=b+2){f=a.skinWeights[b];m=a.skinWeights[b+1];d.skinWeights.push(new THREE.Vector4(f,m,0,0))}}if(a.skinIndices){b=0;for(c=a.skinIndices.length;b<c;b=
  10090. b+2){f=a.skinIndices[b];m=a.skinIndices[b+1];d.skinIndices.push(new THREE.Vector4(f,m,0,0))}}d.bones=a.bones;d.animation=a.animation})();(function(b){if(a.morphTargets!==void 0){var c,f,m,j,i,o;c=0;for(f=a.morphTargets.length;c<f;c++){d.morphTargets[c]={};d.morphTargets[c].name=a.morphTargets[c].name;d.morphTargets[c].vertices=[];i=d.morphTargets[c].vertices;o=a.morphTargets[c].vertices;m=0;for(j=o.length;m<j;m=m+3){var k=new THREE.Vector3;k.x=o[m]*b;k.y=o[m+1]*b;k.z=o[m+2]*b;i.push(k)}}}if(a.morphColors!==
  10091. void 0){c=0;for(f=a.morphColors.length;c<f;c++){d.morphColors[c]={};d.morphColors[c].name=a.morphColors[c].name;d.morphColors[c].colors=[];j=d.morphColors[c].colors;i=a.morphColors[c].colors;b=0;for(m=i.length;b<m;b=b+3){o=new THREE.Color(16755200);o.setRGB(i[b],i[b+1],i[b+2]);j.push(o)}}}})(f);d.computeCentroids();d.computeFaceNormals();this.hasNormals(d)&&d.computeTangents();b(d)};
  10092. THREE.SceneLoader=function(){this.onLoadStart=function(){};this.onLoadProgress=function(){};this.onLoadComplete=function(){};this.callbackSync=function(){};this.callbackProgress=function(){}};THREE.SceneLoader.prototype.constructor=THREE.SceneLoader;
  10093. 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 f=JSON.parse(d.responseText);c.createScene(f,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)};
  10094. THREE.SceneLoader.prototype.createScene=function(a,b,c){function d(a,b){return b=="relativeToHTML"?a:j+"/"+a}function f(){var a;for(k in z.objects)if(!D.objects[k]){w=z.objects[k];if(w.geometry!==void 0){if(Q=D.geometries[w.geometry]){a=false;T=D.materials[w.materials[0]];(a=T instanceof THREE.ShaderMaterial)&&Q.computeTangents();s=w.position;J=w.rotation;C=w.quaternion;G=w.scale;q=w.matrix;C=0;w.materials.length==0&&(T=new THREE.MeshFaceMaterial);w.materials.length>1&&(T=new THREE.MeshFaceMaterial);
  10095. a=new THREE.Mesh(Q,T);a.name=k;if(q){a.matrixAutoUpdate=false;a.matrix.set(q[0],q[1],q[2],q[3],q[4],q[5],q[6],q[7],q[8],q[9],q[10],q[11],q[12],q[13],q[14],q[15])}else{a.position.set(s[0],s[1],s[2]);if(C){a.quaternion.set(C[0],C[1],C[2],C[3]);a.useQuaternion=true}else a.rotation.set(J[0],J[1],J[2]);a.scale.set(G[0],G[1],G[2])}a.visible=w.visible;a.doubleSided=w.doubleSided;a.castShadow=w.castShadow;a.receiveShadow=w.receiveShadow;D.scene.add(a);D.objects[k]=a}}else{s=w.position;J=w.rotation;C=w.quaternion;
  10096. G=w.scale;C=0;a=new THREE.Object3D;a.name=k;a.position.set(s[0],s[1],s[2]);if(C){a.quaternion.set(C[0],C[1],C[2],C[3]);a.useQuaternion=true}else a.rotation.set(J[0],J[1],J[2]);a.scale.set(G[0],G[1],G[2]);a.visible=w.visible!==void 0?w.visible:false;D.scene.add(a);D.objects[k]=a;D.empties[k]=a}}}function g(a){return function(b){D.geometries[a]=b;f();E=E-1;m.onLoadComplete();l()}}function h(a){return function(b){D.geometries[a]=b}}function l(){m.callbackProgress({totalModels:Ba,totalTextures:X,loadedModels:Ba-
  10097. E,loadedTextures:X-e},D);m.onLoadProgress();E==0&&e==0&&b(D)}var m=this,j=THREE.Loader.prototype.extractUrlBase(c),i,o,k,u,r,n,p,w,q,I,B,s,J,C,G,F,P,Q,T,Z,R,z,H,E,e,Ba,X,D;z=a;c=new THREE.BinaryLoader;H=new THREE.JSONLoader;e=E=0;D={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{},empties:{}};if(z.transform){a=z.transform.position;I=z.transform.rotation;F=z.transform.scale;a&&D.scene.position.set(a[0],a[1],a[2]);I&&D.scene.rotation.set(I[0],I[1],
  10098. I[2]);F&&D.scene.scale.set(F[0],F[1],F[2]);if(a||I||F){D.scene.updateMatrix();D.scene.updateMatrixWorld()}}a=function(){e=e-1;l();m.onLoadComplete()};for(r in z.cameras){F=z.cameras[r];F.type=="perspective"?Z=new THREE.PerspectiveCamera(F.fov,F.aspect,F.near,F.far):F.type=="ortho"&&(Z=new THREE.OrthographicCamera(F.left,F.right,F.top,F.bottom,F.near,F.far));s=F.position;I=F.target;F=F.up;Z.position.set(s[0],s[1],s[2]);Z.target=new THREE.Vector3(I[0],I[1],I[2]);F&&Z.up.set(F[0],F[1],F[2]);D.cameras[r]=
  10099. Z}for(u in z.lights){I=z.lights[u];r=I.color!==void 0?I.color:16777215;Z=I.intensity!==void 0?I.intensity:1;if(I.type=="directional"){s=I.direction;B=new THREE.DirectionalLight(r,Z);B.position.set(s[0],s[1],s[2]);B.position.normalize()}else if(I.type=="point"){s=I.position;B=I.distance;B=new THREE.PointLight(r,Z,B);B.position.set(s[0],s[1],s[2])}else I.type=="ambient"&&(B=new THREE.AmbientLight(r));D.scene.add(B);D.lights[u]=B}for(n in z.fogs){u=z.fogs[n];u.type=="linear"?R=new THREE.Fog(0,u.near,
  10100. u.far):u.type=="exp2"&&(R=new THREE.FogExp2(0,u.density));F=u.color;R.color.setRGB(F[0],F[1],F[2]);D.fogs[n]=R}if(D.cameras&&z.defaults.camera)D.currentCamera=D.cameras[z.defaults.camera];if(D.fogs&&z.defaults.fog)D.scene.fog=D.fogs[z.defaults.fog];F=z.defaults.bgcolor;D.bgColor=new THREE.Color;D.bgColor.setRGB(F[0],F[1],F[2]);D.bgColorAlpha=z.defaults.bgalpha;for(i in z.geometries){n=z.geometries[i];if(n.type=="bin_mesh"||n.type=="ascii_mesh"){E=E+1;m.onLoadStart()}}Ba=E;for(i in z.geometries){n=
  10101. z.geometries[i];if(n.type=="cube"){Q=new THREE.CubeGeometry(n.width,n.height,n.depth,n.segmentsWidth,n.segmentsHeight,n.segmentsDepth,null,n.flipped,n.sides);D.geometries[i]=Q}else if(n.type=="plane"){Q=new THREE.PlaneGeometry(n.width,n.height,n.segmentsWidth,n.segmentsHeight);D.geometries[i]=Q}else if(n.type=="sphere"){Q=new THREE.SphereGeometry(n.radius,n.segmentsWidth,n.segmentsHeight);D.geometries[i]=Q}else if(n.type=="cylinder"){Q=new THREE.CylinderGeometry(n.topRad,n.botRad,n.height,n.radSegs,
  10102. n.heightSegs);D.geometries[i]=Q}else if(n.type=="torus"){Q=new THREE.TorusGeometry(n.radius,n.tube,n.segmentsR,n.segmentsT);D.geometries[i]=Q}else if(n.type=="icosahedron"){Q=new THREE.IcosahedronGeometry(n.radius,n.subdivisions);D.geometries[i]=Q}else if(n.type=="bin_mesh")c.load(d(n.url,z.urlBaseType),g(i));else if(n.type=="ascii_mesh")H.load(d(n.url,z.urlBaseType),g(i));else if(n.type=="embedded_mesh"){n=z.embeds[n.id];n.metadata=z.metadata;n&&H.createModel(n,h(i),"")}}for(p in z.textures){i=z.textures[p];
  10103. if(i.url instanceof Array){e=e+i.url.length;for(n=0;n<i.url.length;n++)m.onLoadStart()}else{e=e+1;m.onLoadStart()}}X=e;for(p in z.textures){i=z.textures[p];if(i.mapping!=void 0&&THREE[i.mapping]!=void 0)i.mapping=new THREE[i.mapping];if(i.url instanceof Array){n=[];for(R=0;R<i.url.length;R++)n[R]=d(i.url[R],z.urlBaseType);n=THREE.ImageUtils.loadTextureCube(n,i.mapping,a)}else{n=THREE.ImageUtils.loadTexture(d(i.url,z.urlBaseType),i.mapping,a);if(THREE[i.minFilter]!=void 0)n.minFilter=THREE[i.minFilter];
  10104. if(THREE[i.magFilter]!=void 0)n.magFilter=THREE[i.magFilter];if(i.repeat){n.repeat.set(i.repeat[0],i.repeat[1]);if(i.repeat[0]!=1)n.wrapS=THREE.RepeatWrapping;if(i.repeat[1]!=1)n.wrapT=THREE.RepeatWrapping}i.offset&&n.offset.set(i.offset[0],i.offset[1]);if(i.wrap){R={repeat:THREE.RepeatWrapping,mirror:THREE.MirroredRepeatWrapping};if(R[i.wrap[0]]!==void 0)n.wrapS=R[i.wrap[0]];if(R[i.wrap[1]]!==void 0)n.wrapT=R[i.wrap[1]]}}D.textures[p]=n}for(o in z.materials){q=z.materials[o];for(P in q.parameters)if(P==
  10105. "envMap"||P=="map"||P=="lightMap")q.parameters[P]=D.textures[q.parameters[P]];else if(P=="shading")q.parameters[P]=q.parameters[P]=="flat"?THREE.FlatShading:THREE.SmoothShading;else if(P=="blending")q.parameters[P]=THREE[q.parameters[P]]?THREE[q.parameters[P]]:THREE.NormalBlending;else if(P=="combine")q.parameters[P]=q.parameters[P]=="MixOperation"?THREE.MixOperation:THREE.MultiplyOperation;else if(P=="vertexColors")if(q.parameters[P]=="face")q.parameters[P]=THREE.FaceColors;else if(q.parameters[P])q.parameters[P]=
  10106. THREE.VertexColors;if(q.parameters.opacity!==void 0&&q.parameters.opacity<1)q.parameters.transparent=true;if(q.parameters.normalMap){p=THREE.ShaderUtils.lib.normal;a=THREE.UniformsUtils.clone(p.uniforms);i=q.parameters.color;n=q.parameters.specular;R=q.parameters.ambient;c=q.parameters.shininess;a.tNormal.texture=D.textures[q.parameters.normalMap];if(q.parameters.normalMapFactor)a.uNormalScale.value=q.parameters.normalMapFactor;if(q.parameters.map){a.tDiffuse.texture=q.parameters.map;a.enableDiffuse.value=
  10107. true}if(q.parameters.lightMap){a.tAO.texture=q.parameters.lightMap;a.enableAO.value=true}if(q.parameters.specularMap){a.tSpecular.texture=D.textures[q.parameters.specularMap];a.enableSpecular.value=true}a.uDiffuseColor.value.setHex(i);a.uSpecularColor.value.setHex(n);a.uAmbientColor.value.setHex(R);a.uShininess.value=c;if(q.parameters.opacity)a.uOpacity.value=q.parameters.opacity;T=new THREE.ShaderMaterial({fragmentShader:p.fragmentShader,vertexShader:p.vertexShader,uniforms:a,lights:true,fog:true})}else T=
  10108. new THREE[q.type](q.parameters);D.materials[o]=T}f();m.callbackSync(D);l()};
  10109. 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?
  10110. 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;
  10111. 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;
  10112. THREE.DstAlphaFactor=206;THREE.OneMinusDstAlphaFactor=207;THREE.DstColorFactor=208;THREE.OneMinusDstColorFactor=209;THREE.SrcAlphaSaturateFactor=210;
  10113. 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;
  10114. 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:
  10115. 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!==
  10116. void 0?a.morphTargets:false};THREE.MeshBasicMaterial.prototype=new THREE.Material;THREE.MeshBasicMaterial.prototype.constructor=THREE.MeshBasicMaterial;
  10117. 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=
  10118. 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?
  10119. 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;
  10120. 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=
  10121. 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=
  10122. 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?
  10123. 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};
  10124. 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;
  10125. 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;
  10126. THREE.ParticleBasicMaterial.prototype.constructor=THREE.ParticleBasicMaterial;
  10127. THREE.ShaderMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.fragmentShader=a.fragmentShader!==void 0?a.fragmentShader:"void main() {}";this.vertexShader=a.vertexShader!==void 0?a.vertexShader:"void main() {}";this.uniforms=a.uniforms!==void 0?a.uniforms:{};this.attributes=a.attributes;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.fog=
  10128. a.fog!==void 0?a.fog:false;this.lights=a.lights!==void 0?a.lights:false;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.ShaderMaterial.prototype=new THREE.Material;THREE.ShaderMaterial.prototype.constructor=THREE.ShaderMaterial;
  10129. THREE.Texture=function(a,b,c,d,f,g,h,l){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=f!==void 0?f:THREE.LinearFilter;this.minFilter=g!==void 0?g:THREE.LinearMipMapLinearFilter;this.format=h!==void 0?h:THREE.RGBAFormat;this.type=l!==void 0?l:THREE.UnsignedByteType;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.generateMipmaps=
  10130. 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(){};
  10131. 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;
  10132. THREE.AlphaFormat=16;THREE.RGBFormat=17;THREE.RGBAFormat=18;THREE.LuminanceFormat=19;THREE.LuminanceAlphaFormat=20;THREE.DataTexture=function(a,b,c,d,f,g,h,l,m,j){THREE.Texture.call(this,null,g,h,l,m,j,d,f);this.image={data:a,width:b,height:c}};THREE.DataTexture.prototype=new THREE.Texture;THREE.DataTexture.prototype.constructor=THREE.DataTexture;
  10133. 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;
  10134. THREE.ParticleSystem=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.material=b!==void 0?b:new THREE.ParticleBasicMaterial({color:Math.random()*16777215});this.sortParticles=false;if(this.geometry){this.geometry.boundingSphere||this.geometry.computeBoundingSphere();this.boundRadius=a.boundingSphere.radius}this.frustumCulled=false};THREE.ParticleSystem.prototype=new THREE.Object3D;THREE.ParticleSystem.prototype.constructor=THREE.ParticleSystem;
  10135. 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;
  10136. 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);
  10137. 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};
  10138. 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;
  10139. 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)};
  10140. THREE.SkinnedMesh=function(a,b){THREE.Mesh.call(this,a,b);this.identityMatrix=new THREE.Matrix4;this.bones=[];this.boneMatrices=[];var c,d,f,g,h,l;if(this.geometry.bones!==void 0){for(c=0;c<this.geometry.bones.length;c++){f=this.geometry.bones[c];g=f.pos;h=f.rotq;l=f.scl;d=this.addBone();d.name=f.name;d.position.set(g[0],g[1],g[2]);d.quaternion.set(h[0],h[1],h[2],h[3]);d.useQuaternion=true;l!==void 0?d.scale.set(l[0],l[1],l[2]):d.scale.set(1,1,1)}for(c=0;c<this.bones.length;c++){f=this.geometry.bones[c];
  10141. d=this.bones[c];f.parent===-1?this.add(d):this.bones[f.parent].add(d)}this.boneMatrices=new Float32Array(16*this.bones.length);this.pose()}};THREE.SkinnedMesh.prototype=new THREE.Mesh;THREE.SkinnedMesh.prototype.constructor=THREE.SkinnedMesh;THREE.SkinnedMesh.prototype.addBone=function(a){a===void 0&&(a=new THREE.Bone(this));this.bones.push(a);return a};
  10142. THREE.SkinnedMesh.prototype.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}for(var a=0,b=this.children.length;a<b;a++){var c=this.children[a];c instanceof THREE.Bone?c.update(this.identityMatrix,false):c.updateMatrixWorld(true)}for(var b=this.bones.length,c=this.bones,d=this.boneMatrices,a=0;a<b;a++)c[a].skinMatrix.flattenToArrayOffset(d,
  10143. a*16)};
  10144. THREE.SkinnedMesh.prototype.pose=function(){this.updateMatrixWorld(true);for(var a,b=[],c=0;c<this.bones.length;c++){a=this.bones[c];var d=new THREE.Matrix4;d.getInverse(a.skinMatrix);b.push(d);a.skinMatrix.flattenToArrayOffset(this.boneMatrices,c*16)}if(this.geometry.skinVerticesA===void 0){this.geometry.skinVerticesA=[];this.geometry.skinVerticesB=[];for(a=0;a<this.geometry.skinIndices.length;a++){var c=this.geometry.vertices[a],f=this.geometry.skinIndices[a].x,g=this.geometry.skinIndices[a].y,d=
  10145. new THREE.Vector3(c.x,c.y,c.z);this.geometry.skinVerticesA.push(b[f].multiplyVector3(d));d=new THREE.Vector3(c.x,c.y,c.z);this.geometry.skinVerticesB.push(b[g].multiplyVector3(d));if(this.geometry.skinWeights[a].x+this.geometry.skinWeights[a].y!==1){c=(1-(this.geometry.skinWeights[a].x+this.geometry.skinWeights[a].y))*0.5;this.geometry.skinWeights[a].x=this.geometry.skinWeights[a].x+c;this.geometry.skinWeights[a].y=this.geometry.skinWeights[a].y+c}}}};
  10146. THREE.Ribbon=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.material=b};THREE.Ribbon.prototype=new THREE.Object3D;THREE.Ribbon.prototype.constructor=THREE.Ribbon;THREE.LOD=function(){THREE.Object3D.call(this);this.LODs=[]};THREE.LOD.prototype=new THREE.Object3D;THREE.LOD.prototype.constructor=THREE.LOD;THREE.LOD.prototype.supr=THREE.Object3D.prototype;
  10147. THREE.LOD.prototype.addLevel=function(a,b){b===void 0&&(b=0);for(var b=Math.abs(b),c=0;c<this.LODs.length;c++)if(b<this.LODs[c].visibleAtDistance)break;this.LODs.splice(c,0,{visibleAtDistance:b,object3D:a});this.add(a)};
  10148. THREE.LOD.prototype.update=function(a){if(this.LODs.length>1){a.matrixWorldInverse.getInverse(a.matrixWorld);a=a.matrixWorldInverse;a=-(a.elements[2]*this.matrixWorld.elements[12]+a.elements[6]*this.matrixWorld.elements[13]+a.elements[10]*this.matrixWorld.elements[14]+a.elements[14]);this.LODs[0].object3D.visible=true;for(var b=1;b<this.LODs.length;b++)if(a>=this.LODs[b].visibleAtDistance){this.LODs[b-1].object3D.visible=false;this.LODs[b].object3D.visible=true}else break;for(;b<this.LODs.length;b++)this.LODs[b].object3D.visible=
  10149. false}};
  10150. 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!==void 0?
  10151. 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=
  10152. 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={};
  10153. 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);
  10154. 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;
  10155. 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])};
  10156. 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])};
  10157. THREE.Fog=function(a,b,c){this.color=new THREE.Color(a);this.near=b!==void 0?b:1;this.far=c!==void 0?c:1E3};THREE.FogExp2=function(a,b){this.color=new THREE.Color(a);this.density=b!==void 0?b:2.5E-4};
  10158. THREE.ShaderChunk={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube envMap;\nuniform float flipEnvMap;\nuniform int combine;\n#endif",
  10159. envmap_fragment:"#ifdef USE_ENVMAP\n#ifdef DOUBLE_SIDED\nfloat flipNormal = ( -1.0 + 2.0 * float( gl_FrontFacing ) );\nvec4 cubeColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * vReflect.x, vReflect.yz ) );\n#else\nvec4 cubeColor = textureCube( envMap, vec3( flipEnvMap * vReflect.x, vReflect.yz ) );\n#endif\n#ifdef GAMMA_INPUT\ncubeColor.xyz *= cubeColor.xyz;\n#endif\nif ( combine == 1 ) {\ngl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity );\n} else {\ngl_FragColor.xyz = gl_FragColor.xyz * cubeColor.xyz;\n}\n#endif",
  10160. envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refractionRatio;\nuniform bool useRefract;\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[ 0 ].xyz, objectMatrix[ 1 ].xyz, objectMatrix[ 2 ].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refractionRatio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",
  10161. map_particle_pars_fragment:"#ifdef USE_MAP\nuniform sampler2D map;\n#endif",map_particle_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform vec4 offsetRepeat;\n#endif",map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n#endif",map_fragment:"#ifdef USE_MAP\n#ifdef GAMMA_INPUT\nvec4 texelColor = texture2D( map, vUv );\ntexelColor.xyz *= texelColor.xyz;\ngl_FragColor = gl_FragColor * texelColor;\n#else\ngl_FragColor = gl_FragColor * texture2D( map, vUv );\n#endif\n#endif",
  10162. lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\nuniform sampler2D lightMap;\n#endif",lightmap_pars_vertex:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\n#endif",lightmap_fragment:"#ifdef USE_LIGHTMAP\ngl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );\n#endif",lightmap_vertex:"#ifdef USE_LIGHTMAP\nvUv2 = uv2;\n#endif",lights_lambert_pars_vertex:"uniform vec3 ambient;\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n#endif\n#if MAX_SPOT_LIGHTS > 0\nuniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\nuniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\nuniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\nuniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\nuniform float spotLightAngle[ MAX_SPOT_LIGHTS ];\nuniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n#endif\n#ifdef WRAP_AROUND\nuniform vec3 wrapRGB;\n#endif",
  10163. lights_lambert_vertex:"vLightFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\nvLightBack = vec3( 0.0 );\n#endif\ntransformedNormal = normalize( transformedNormal );\n#if MAX_DIR_LIGHTS > 0\nfor( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nfloat dotProduct = dot( transformedNormal, dirVector );\nvec3 directionalLightWeighting = vec3( max( dotProduct, 0.0 ) );\n#ifdef DOUBLE_SIDED\nvec3 directionalLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );\n#ifdef WRAP_AROUND\nvec3 directionalLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );\n#endif\n#endif\n#ifdef WRAP_AROUND\nvec3 directionalLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );\ndirectionalLightWeighting = mix( directionalLightWeighting, directionalLightWeightingHalf, wrapRGB );\n#ifdef DOUBLE_SIDED\ndirectionalLightWeightingBack = mix( directionalLightWeightingBack, directionalLightWeightingHalfBack, wrapRGB );\n#endif\n#endif\nvLightFront += directionalLightColor[ i ] * directionalLightWeighting;\n#ifdef DOUBLE_SIDED\nvLightBack += directionalLightColor[ i ] * directionalLightWeightingBack;\n#endif\n}\n#endif\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\nfloat dotProduct = dot( transformedNormal, lVector );\nvec3 pointLightWeighting = vec3( max( dotProduct, 0.0 ) );\n#ifdef DOUBLE_SIDED\nvec3 pointLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );\n#ifdef WRAP_AROUND\nvec3 pointLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );\n#endif\n#endif\n#ifdef WRAP_AROUND\nvec3 pointLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );\npointLightWeighting = mix( pointLightWeighting, pointLightWeightingHalf, wrapRGB );\n#ifdef DOUBLE_SIDED\npointLightWeightingBack = mix( pointLightWeightingBack, pointLightWeightingHalfBack, wrapRGB );\n#endif\n#endif\nvLightFront += pointLightColor[ i ] * pointLightWeighting * lDistance;\n#ifdef DOUBLE_SIDED\nvLightBack += pointLightColor[ i ] * pointLightWeightingBack * lDistance;\n#endif\n}\n#endif\n#if MAX_SPOT_LIGHTS > 0\nfor( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\nvec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nlVector = normalize( lVector );\nfloat spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - mPosition.xyz ) );\nif ( spotEffect > spotLightAngle[ i ] ) {\nspotEffect = pow( spotEffect, spotLightExponent[ i ] );\nfloat lDistance = 1.0;\nif ( spotLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );\nfloat dotProduct = dot( transformedNormal, lVector );\nvec3 spotLightWeighting = vec3( max( dotProduct, 0.0 ) );\n#ifdef DOUBLE_SIDED\nvec3 spotLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );\n#ifdef WRAP_AROUND\nvec3 spotLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );\n#endif\n#endif\n#ifdef WRAP_AROUND\nvec3 spotLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );\nspotLightWeighting = mix( spotLightWeighting, spotLightWeightingHalf, wrapRGB );\n#ifdef DOUBLE_SIDED\nspotLightWeightingBack = mix( spotLightWeightingBack, spotLightWeightingHalfBack, wrapRGB );\n#endif\n#endif\nvLightFront += spotLightColor[ i ] * spotLightWeighting * lDistance * spotEffect;\n#ifdef DOUBLE_SIDED\nvLightBack += spotLightColor[ i ] * spotLightWeightingBack * lDistance * spotEffect;\n#endif\n}\n}\n#endif\nvLightFront = vLightFront * diffuse + ambient * ambientLightColor + emissive;\n#ifdef DOUBLE_SIDED\nvLightBack = vLightBack * diffuse + ambient * ambientLightColor + emissive;\n#endif",
  10164. lights_phong_pars_vertex:"#ifndef PHONG_PER_PIXEL\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\n#if MAX_SPOT_LIGHTS > 0\nuniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\nuniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\nvarying vec4 vSpotLight[ MAX_SPOT_LIGHTS ];\n#endif\n#endif\n#if MAX_SPOT_LIGHTS > 0\nvarying vec3 vWorldPosition;\n#endif",lights_phong_vertex:"#ifndef PHONG_PER_PIXEL\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nvPointLight[ i ] = vec4( lVector, lDistance );\n}\n#endif\n#if MAX_SPOT_LIGHTS > 0\nfor( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\nvec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( spotLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );\nvSpotLight[ i ] = vec4( lVector, lDistance );\n}\n#endif\n#endif\n#if MAX_SPOT_LIGHTS > 0\nvWorldPosition = mPosition.xyz;\n#endif",
  10165. lights_phong_pars_fragment:"uniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n#ifdef PHONG_PER_PIXEL\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n#else\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\n#endif\n#if MAX_SPOT_LIGHTS > 0\nuniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\nuniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\nuniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\nuniform float spotLightAngle[ MAX_SPOT_LIGHTS ];\nuniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n#ifdef PHONG_PER_PIXEL\nuniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n#else\nvarying vec4 vSpotLight[ MAX_SPOT_LIGHTS ];\n#endif\nvarying vec3 vWorldPosition;\n#endif\n#ifdef WRAP_AROUND\nuniform vec3 wrapRGB;\n#endif\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",
  10166. lights_phong_fragment:"vec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );\n#ifdef DOUBLE_SIDED\nnormal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n#endif\n#if MAX_POINT_LIGHTS > 0\nvec3 pointDiffuse = vec3( 0.0 );\nvec3 pointSpecular = vec3( 0.0 );\nfor ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n#ifdef PHONG_PER_PIXEL\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz + vViewPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\n#else\nvec3 lVector = normalize( vPointLight[ i ].xyz );\nfloat lDistance = vPointLight[ i ].w;\n#endif\nfloat dotProduct = dot( normal, lVector );\n#ifdef WRAP_AROUND\nfloat pointDiffuseWeightFull = max( dotProduct, 0.0 );\nfloat pointDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );\nvec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );\n#else\nfloat pointDiffuseWeight = max( dotProduct, 0.0 );\n#endif\npointDiffuse += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;\nvec3 pointHalfVector = normalize( lVector + viewPosition );\nfloat pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );\nfloat pointSpecularWeight = max( pow( pointDotNormalHalf, shininess ), 0.0 );\n#ifdef PHYSICALLY_BASED_SHADING\nfloat specularNormalization = ( shininess + 2.0001 ) / 8.0;\nvec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVector, pointHalfVector ), 5.0 );\npointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance * specularNormalization;\n#else\npointSpecular += specular * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance;\n#endif\n}\n#endif\n#if MAX_SPOT_LIGHTS > 0\nvec3 spotDiffuse = vec3( 0.0 );\nvec3 spotSpecular = vec3( 0.0 );\nfor ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n#ifdef PHONG_PER_PIXEL\nvec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz + vViewPosition.xyz;\nfloat lDistance = 1.0;\nif ( spotLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\n#else\nvec3 lVector = normalize( vSpotLight[ i ].xyz );\nfloat lDistance = vSpotLight[ i ].w;\n#endif\nfloat spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );\nif ( spotEffect > spotLightAngle[ i ] ) {\nspotEffect = pow( spotEffect, spotLightExponent[ i ] );\nfloat dotProduct = dot( normal, lVector );\n#ifdef WRAP_AROUND\nfloat spotDiffuseWeightFull = max( dotProduct, 0.0 );\nfloat spotDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );\nvec3 spotDiffuseWeight = mix( vec3 ( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );\n#else\nfloat spotDiffuseWeight = max( dotProduct, 0.0 );\n#endif\nspotDiffuse += diffuse * spotLightColor[ i ] * spotDiffuseWeight * lDistance * spotEffect;\nvec3 spotHalfVector = normalize( lVector + viewPosition );\nfloat spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );\nfloat spotSpecularWeight = max( pow( spotDotNormalHalf, shininess ), 0.0 );\n#ifdef PHYSICALLY_BASED_SHADING\nfloat specularNormalization = ( shininess + 2.0001 ) / 8.0;\nvec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVector, spotHalfVector ), 5.0 );\nspotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * lDistance * specularNormalization * spotEffect;\n#else\nspotSpecular += specular * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * lDistance * spotEffect;\n#endif\n}\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec3 dirDiffuse = vec3( 0.0 );\nvec3 dirSpecular = vec3( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nfloat dotProduct = dot( normal, dirVector );\n#ifdef WRAP_AROUND\nfloat dirDiffuseWeightFull = max( dotProduct, 0.0 );\nfloat dirDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );\nvec3 dirDiffuseWeight = mix( vec3( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), wrapRGB );\n#else\nfloat dirDiffuseWeight = max( dotProduct, 0.0 );\n#endif\ndirDiffuse += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;\nvec3 dirHalfVector = normalize( dirVector + viewPosition );\nfloat dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );\nfloat dirSpecularWeight = max( pow( dirDotNormalHalf, shininess ), 0.0 );\n#ifdef PHYSICALLY_BASED_SHADING\nfloat specularNormalization = ( shininess + 2.0001 ) / 8.0;\nvec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( dirVector, dirHalfVector ), 5.0 );\ndirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;\n#else\ndirSpecular += specular * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight;\n#endif\n}\n#endif\nvec3 totalDiffuse = vec3( 0.0 );\nvec3 totalSpecular = vec3( 0.0 );\n#if MAX_DIR_LIGHTS > 0\ntotalDiffuse += dirDiffuse;\ntotalSpecular += dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalDiffuse += pointDiffuse;\ntotalSpecular += pointSpecular;\n#endif\n#if MAX_SPOT_LIGHTS > 0\ntotalDiffuse += spotDiffuse;\ntotalSpecular += spotSpecular;\n#endif\n#ifdef METAL\ngl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient + totalSpecular );\n#else\ngl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient ) + totalSpecular;\n#endif",
  10167. color_pars_fragment:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_fragment:"#ifdef USE_COLOR\ngl_FragColor = gl_FragColor * vec4( vColor, opacity );\n#endif",color_pars_vertex:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_vertex:"#ifdef USE_COLOR\n#ifdef GAMMA_INPUT\nvColor = color * color;\n#else\nvColor = color;\n#endif\n#endif",skinning_pars_vertex:"#ifdef USE_SKINNING\nuniform mat4 boneGlobalMatrices[ MAX_BONES ];\n#endif",skinning_vertex:"#ifdef USE_SKINNING\ngl_Position = ( boneGlobalMatrices[ int( skinIndex.x ) ] * skinVertexA ) * skinWeight.x;\ngl_Position += ( boneGlobalMatrices[ int( skinIndex.y ) ] * skinVertexB ) * skinWeight.y;\ngl_Position = projectionMatrix * modelViewMatrix * gl_Position;\n#endif",
  10168. morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\n#ifndef USE_MORPHNORMALS\nuniform float morphTargetInfluences[ 8 ];\n#else\nuniform float morphTargetInfluences[ 4 ];\n#endif\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\nvec3 morphed = vec3( 0.0 );\nmorphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\nmorphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\nmorphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\nmorphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n#ifndef USE_MORPHNORMALS\nmorphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\nmorphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\nmorphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\nmorphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n#endif\nmorphed += position;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( morphed, 1.0 );\n#endif",
  10169. default_vertex:"#ifndef USE_MORPHTARGETS\n#ifndef USE_SKINNING\ngl_Position = projectionMatrix * mvPosition;\n#endif\n#endif",morphnormal_vertex:"#ifdef USE_MORPHNORMALS\nvec3 morphedNormal = vec3( 0.0 );\nmorphedNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\nmorphedNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\nmorphedNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\nmorphedNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\nmorphedNormal += normal;\nvec3 transformedNormal = normalMatrix * morphedNormal;\n#else\nvec3 transformedNormal = normalMatrix * normal;\n#endif",
  10170. shadowmap_pars_fragment:"#ifdef USE_SHADOWMAP\nuniform sampler2D shadowMap[ MAX_SHADOWS ];\nuniform vec2 shadowMapSize[ MAX_SHADOWS ];\nuniform float shadowDarkness[ MAX_SHADOWS ];\nuniform float shadowBias[ MAX_SHADOWS ];\nvarying vec4 vShadowCoord[ MAX_SHADOWS ];\nfloat unpackDepth( const in vec4 rgba_depth ) {\nconst vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\nfloat depth = dot( rgba_depth, bit_shift );\nreturn depth;\n}\n#endif",shadowmap_fragment:"#ifdef USE_SHADOWMAP\n#ifdef SHADOWMAP_DEBUG\nvec3 frustumColors[3];\nfrustumColors[0] = vec3( 1.0, 0.5, 0.0 );\nfrustumColors[1] = vec3( 0.0, 1.0, 0.8 );\nfrustumColors[2] = vec3( 0.0, 0.5, 1.0 );\n#endif\n#ifdef SHADOWMAP_CASCADE\nint inFrustumCount = 0;\n#endif\nfloat fDepth;\nvec3 shadowColor = vec3( 1.0 );\nfor( int i = 0; i < MAX_SHADOWS; i ++ ) {\nvec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\nbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\nbool inFrustum = all( inFrustumVec );\n#ifdef SHADOWMAP_CASCADE\ninFrustumCount += int( inFrustum );\nbvec3 frustumTestVec = bvec3( inFrustum, inFrustumCount == 1, shadowCoord.z <= 1.0 );\n#else\nbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n#endif\nbool frustumTest = all( frustumTestVec );\nif ( frustumTest ) {\nshadowCoord.z += shadowBias[ i ];\n#ifdef SHADOWMAP_SOFT\nfloat shadow = 0.0;\nconst float shadowDelta = 1.0 / 9.0;\nfloat xPixelOffset = 1.0 / shadowMapSize[ i ].x;\nfloat yPixelOffset = 1.0 / shadowMapSize[ i ].y;\nfloat dx0 = -1.25 * xPixelOffset;\nfloat dy0 = -1.25 * yPixelOffset;\nfloat dx1 = 1.25 * xPixelOffset;\nfloat dy1 = 1.25 * yPixelOffset;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nshadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );\n#else\nvec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\nfloat fDepth = unpackDepth( rgbaDepth );\nif ( fDepth < shadowCoord.z )\nshadowColor = shadowColor * vec3( 1.0 - shadowDarkness[ i ] );\n#endif\n}\n#ifdef SHADOWMAP_DEBUG\n#ifdef SHADOWMAP_CASCADE\nif ( inFrustum && inFrustumCount == 1 ) gl_FragColor.xyz *= frustumColors[ i ];\n#else\nif ( inFrustum ) gl_FragColor.xyz *= frustumColors[ i ];\n#endif\n#endif\n}\n#ifdef GAMMA_OUTPUT\nshadowColor *= shadowColor;\n#endif\ngl_FragColor.xyz = gl_FragColor.xyz * shadowColor;\n#endif",
  10171. shadowmap_pars_vertex:"#ifdef USE_SHADOWMAP\nvarying vec4 vShadowCoord[ MAX_SHADOWS ];\nuniform mat4 shadowMatrix[ MAX_SHADOWS ];\n#endif",shadowmap_vertex:"#ifdef USE_SHADOWMAP\nfor( int i = 0; i < MAX_SHADOWS; i ++ ) {\n#ifdef USE_MORPHTARGETS\nvShadowCoord[ i ] = shadowMatrix[ i ] * objectMatrix * vec4( morphed, 1.0 );\n#else\nvShadowCoord[ i ] = shadowMatrix[ i ] * objectMatrix * vec4( position, 1.0 );\n#endif\n}\n#endif",alphatest_fragment:"#ifdef ALPHATEST\nif ( gl_FragColor.a < ALPHATEST ) discard;\n#endif",
  10172. linear_to_gamma_fragment:"#ifdef GAMMA_OUTPUT\ngl_FragColor.xyz = sqrt( gl_FragColor.xyz );\n#endif"};
  10173. THREE.UniformsUtils={merge:function(a){var b,c,d,f={};for(b=0;b<a.length;b++){d=this.clone(a[b]);for(c in d)f[c]=d[c]}return f},clone:function(a){var b,c,d,f={};for(b in a){f[b]={};for(c in a[b]){d=a[b][c];f[b][c]=d instanceof THREE.Color||d instanceof THREE.Vector2||d instanceof THREE.Vector3||d instanceof THREE.Vector4||d instanceof THREE.Matrix4||d instanceof THREE.Texture?d.clone():d instanceof Array?d.slice():d}}return f}};
  10174. THREE.UniformsLib={common:{diffuse:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},map:{type:"t",value:0,texture:null},offsetRepeat:{type:"v4",value:new THREE.Vector4(0,0,1,1)},lightMap:{type:"t",value:2,texture:null},envMap:{type:"t",value:1,texture:null},flipEnvMap:{type:"f",value:-1},useRefract:{type:"i",value:0},reflectivity:{type:"f",value:1},refractionRatio:{type:"f",value:0.98},combine:{type:"i",value:0},morphTargetInfluences:{type:"f",value:0}},fog:{fogDensity:{type:"f",
  10175. value:2.5E-4},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",value:new THREE.Color(16777215)}},lights:{ambientLightColor:{type:"fv",value:[]},directionalLightDirection:{type:"fv",value:[]},directionalLightColor:{type:"fv",value:[]},pointLightColor:{type:"fv",value:[]},pointLightPosition:{type:"fv",value:[]},pointLightDistance:{type:"fv1",value:[]},spotLightColor:{type:"fv",value:[]},spotLightPosition:{type:"fv",value:[]},spotLightDirection:{type:"fv",value:[]},spotLightDistance:{type:"fv1",
  10176. value:[]},spotLightAngle:{type:"fv1",value:[]},spotLightExponent:{type:"fv1",value:[]}},particle:{psColor:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},size:{type:"f",value:1},scale:{type:"f",value:1},map:{type:"t",value:0,texture:null},fogDensity:{type:"f",value:2.5E-4},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",value:new THREE.Color(16777215)}},shadowmap:{shadowMap:{type:"tv",value:6,texture:[]},shadowMapSize:{type:"v2v",value:[]},shadowBias:{type:"fv1",
  10177. value:[]},shadowDarkness:{type:"fv1",value:[]},shadowMatrix:{type:"m4v",value:[]}}};
  10178. THREE.ShaderLib={depth:{uniforms:{mNear:{type:"f",value:1},mFar:{type:"f",value:2E3},opacity:{type:"f",value:1}},vertexShader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"uniform float mNear;\nuniform float mFar;\nuniform float opacity;\nvoid main() {\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\nfloat color = 1.0 - smoothstep( mNear, mFar, depth );\ngl_FragColor = vec4( vec3( color ), opacity );\n}"},normal:{uniforms:{opacity:{type:"f",
  10179. value:1}},vertexShader:"varying vec3 vNormal;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalMatrix * normal;\ngl_Position = projectionMatrix * mvPosition;\n}",fragmentShader:"uniform float opacity;\nvarying vec3 vNormal;\nvoid main() {\ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );\n}"},basic:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.common,THREE.UniformsLib.fog,THREE.UniformsLib.shadowmap]),vertexShader:[THREE.ShaderChunk.map_pars_vertex,
  10180. THREE.ShaderChunk.lightmap_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.ShaderChunk.map_vertex,THREE.ShaderChunk.lightmap_vertex,THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.color_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.morphtarget_vertex,
  10181. THREE.ShaderChunk.default_vertex,THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),fragmentShader:["uniform vec3 diffuse;\nuniform float opacity;",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,"void main() {\ngl_FragColor = vec4( diffuse, opacity );",THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphatest_fragment,
  10182. THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},lambert:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.common,THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{ambient:{type:"c",value:new THREE.Color(16777215)},emissive:{type:"c",value:new THREE.Color(0)},wrapRGB:{type:"v3",value:new THREE.Vector3(1,
  10183. 1,1)}}]),vertexShader:["varying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\nvarying vec3 vLightBack;\n#endif",THREE.ShaderChunk.map_pars_vertex,THREE.ShaderChunk.lightmap_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.lights_lambert_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.ShaderChunk.map_vertex,
  10184. THREE.ShaderChunk.lightmap_vertex,THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.color_vertex,THREE.ShaderChunk.morphnormal_vertex,"#ifndef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\n#endif",THREE.ShaderChunk.lights_lambert_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.default_vertex,THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),fragmentShader:["uniform float opacity;\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\nvarying vec3 vLightBack;\n#endif",
  10185. THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,"void main() {\ngl_FragColor = vec4( vec3 ( 1.0 ), opacity );",THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphatest_fragment,"#ifdef DOUBLE_SIDED\nif ( gl_FrontFacing )\ngl_FragColor.xyz *= vLightFront;\nelse\ngl_FragColor.xyz *= vLightBack;\n#else\ngl_FragColor.xyz *= vLightFront;\n#endif",
  10186. THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},phong:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.common,THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{ambient:{type:"c",value:new THREE.Color(16777215)},emissive:{type:"c",value:new THREE.Color(0)},specular:{type:"c",value:new THREE.Color(1118481)},
  10187. shininess:{type:"f",value:30},wrapRGB:{type:"v3",value:new THREE.Vector3(1,1,1)}}]),vertexShader:["varying vec3 vViewPosition;\nvarying vec3 vNormal;",THREE.ShaderChunk.map_pars_vertex,THREE.ShaderChunk.lightmap_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.lights_phong_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  10188. THREE.ShaderChunk.map_vertex,THREE.ShaderChunk.lightmap_vertex,THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.color_vertex,"#ifndef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\n#endif\nvViewPosition = -mvPosition.xyz;",THREE.ShaderChunk.morphnormal_vertex,"vNormal = transformedNormal;",THREE.ShaderChunk.lights_phong_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.default_vertex,THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),
  10189. fragmentShader:["uniform vec3 diffuse;\nuniform float opacity;\nuniform vec3 ambient;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.lights_phong_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,"void main() {\ngl_FragColor = vec4( vec3 ( 1.0 ), opacity );",
  10190. THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphatest_fragment,THREE.ShaderChunk.lights_phong_fragment,THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},particle_basic:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.particle,THREE.UniformsLib.shadowmap]),vertexShader:["uniform float size;\nuniform float scale;",
  10191. THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {",THREE.ShaderChunk.color_vertex,"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n#ifdef USE_SIZEATTENUATION\ngl_PointSize = size * ( scale / length( mvPosition.xyz ) );\n#else\ngl_PointSize = size;\n#endif\ngl_Position = projectionMatrix * mvPosition;",THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),fragmentShader:["uniform vec3 psColor;\nuniform float opacity;",THREE.ShaderChunk.color_pars_fragment,
  10192. THREE.ShaderChunk.map_particle_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,"void main() {\ngl_FragColor = vec4( psColor, opacity );",THREE.ShaderChunk.map_particle_fragment,THREE.ShaderChunk.alphatest_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},depthRGBA:{uniforms:{},vertexShader:[THREE.ShaderChunk.morphtarget_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  10193. THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.default_vertex,"}"].join("\n"),fragmentShader:"vec4 pack_depth( const in float depth ) {\nconst vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );\nconst vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );\nvec4 res = fract( depth * bit_shift );\nres -= res.xxyz * bit_mask;\nreturn res;\n}\nvoid main() {\ngl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );\n}"}};
  10194. THREE.WebGLRenderer=function(a){function b(a,b){var c=a.vertices.length,d=b.material;if(d.attributes){if(a.__webglCustomAttributesList===void 0)a.__webglCustomAttributesList=[];for(var f in d.attributes){var g=d.attributes[f];if(!g.__webglInitialized||g.createUniqueBuffers){g.__webglInitialized=true;var h=1;g.type==="v2"?h=2:g.type==="v3"?h=3:g.type==="v4"?h=4:g.type==="c"&&(h=3);g.size=h;g.array=new Float32Array(c*h);g.buffer=e.createBuffer();g.buffer.belongsToAttribute=f;g.needsUpdate=true}a.__webglCustomAttributesList.push(g)}}}
  10195. function c(a,b){if(a.material&&!(a.material instanceof THREE.MeshFaceMaterial))return a.material;if(b.materialIndex>=0)return a.geometry.materials[b.materialIndex]}function d(a){return a instanceof THREE.MeshBasicMaterial&&!a.envMap||a instanceof THREE.MeshDepthMaterial?false:a&&a.shading!==void 0&&a.shading===THREE.SmoothShading?THREE.SmoothShading:THREE.FlatShading}function f(a){return a.map||a.lightMap||a instanceof THREE.ShaderMaterial?true:false}function g(a,b,c){var d,f,g,h,i=a.vertices;h=i.length;
  10196. var j=a.colors,k=j.length,l=a.__vertexArray,m=a.__colorArray,n=a.__sortArray,o=a.verticesNeedUpdate,r=a.colorsNeedUpdate,p=a.__webglCustomAttributesList;if(c.sortParticles){Pb.copy(tb);Pb.multiplySelf(c.matrixWorld);for(d=0;d<h;d++){f=i[d];Pa.copy(f);Pb.multiplyVector3(Pa);n[d]=[Pa.z,d]}n.sort(function(a,b){return b[0]-a[0]});for(d=0;d<h;d++){f=i[n[d][1]];g=d*3;l[g]=f.x;l[g+1]=f.y;l[g+2]=f.z}for(d=0;d<k;d++){g=d*3;f=j[n[d][1]];m[g]=f.r;m[g+1]=f.g;m[g+2]=f.b}if(p){j=0;for(k=p.length;j<k;j++){i=p[j];
  10197. if(i.boundTo===void 0||i.boundTo==="vertices"){g=0;f=i.value.length;if(i.size===1)for(d=0;d<f;d++){h=n[d][1];i.array[d]=i.value[h]}else if(i.size===2)for(d=0;d<f;d++){h=n[d][1];h=i.value[h];i.array[g]=h.x;i.array[g+1]=h.y;g=g+2}else if(i.size===3)if(i.type==="c")for(d=0;d<f;d++){h=n[d][1];h=i.value[h];i.array[g]=h.r;i.array[g+1]=h.g;i.array[g+2]=h.b;g=g+3}else for(d=0;d<f;d++){h=n[d][1];h=i.value[h];i.array[g]=h.x;i.array[g+1]=h.y;i.array[g+2]=h.z;g=g+3}else if(i.size===4)for(d=0;d<f;d++){h=n[d][1];
  10198. h=i.value[h];i.array[g]=h.x;i.array[g+1]=h.y;i.array[g+2]=h.z;i.array[g+3]=h.w;g=g+4}}}}}else{if(o)for(d=0;d<h;d++){f=i[d];g=d*3;l[g]=f.x;l[g+1]=f.y;l[g+2]=f.z}if(r)for(d=0;d<k;d++){f=j[d];g=d*3;m[g]=f.r;m[g+1]=f.g;m[g+2]=f.b}if(p){j=0;for(k=p.length;j<k;j++){i=p[j];if(i.needsUpdate&&(i.boundTo===void 0||i.boundTo==="vertices")){f=i.value.length;g=0;if(i.size===1)for(d=0;d<f;d++)i.array[d]=i.value[d];else if(i.size===2)for(d=0;d<f;d++){h=i.value[d];i.array[g]=h.x;i.array[g+1]=h.y;g=g+2}else if(i.size===
  10199. 3)if(i.type==="c")for(d=0;d<f;d++){h=i.value[d];i.array[g]=h.r;i.array[g+1]=h.g;i.array[g+2]=h.b;g=g+3}else for(d=0;d<f;d++){h=i.value[d];i.array[g]=h.x;i.array[g+1]=h.y;i.array[g+2]=h.z;g=g+3}else if(i.size===4)for(d=0;d<f;d++){h=i.value[d];i.array[g]=h.x;i.array[g+1]=h.y;i.array[g+2]=h.z;i.array[g+3]=h.w;g=g+4}}}}}if(o||c.sortParticles){e.bindBuffer(e.ARRAY_BUFFER,a.__webglVertexBuffer);e.bufferData(e.ARRAY_BUFFER,l,b)}if(r||c.sortParticles){e.bindBuffer(e.ARRAY_BUFFER,a.__webglColorBuffer);e.bufferData(e.ARRAY_BUFFER,
  10200. m,b)}if(p){j=0;for(k=p.length;j<k;j++){i=p[j];if(i.needsUpdate||c.sortParticles){e.bindBuffer(e.ARRAY_BUFFER,i.buffer);e.bufferData(e.ARRAY_BUFFER,i.array,b)}}}}function h(a,b){return b.z-a.z}function l(a,b,c){if(a.length)for(var d=0,e=a.length;d<e;d++){ma=X=null;la=S=L=ra=Fa=Oa=Aa=-1;nb=true;a[d].render(b,c,sc,Zb);ma=X=null;la=S=L=ra=Fa=Oa=Aa=-1;nb=true}}function m(a,b,c,d,e,f,g,h){var i,j,k,l;if(b){j=a.length-1;l=b=-1}else{j=0;b=a.length;l=1}for(var m=j;m!==b;m=m+l){i=a[m];if(i.render){j=i.object;
  10201. k=i.buffer;if(h)i=h;else{i=i[c];if(!i)continue;g&&E.setBlending(i.blending,i.blendEquation,i.blendSrc,i.blendDst);E.setDepthTest(i.depthTest);E.setDepthWrite(i.depthWrite);w(i.polygonOffset,i.polygonOffsetFactor,i.polygonOffsetUnits)}E.setObjectFaces(j);k instanceof THREE.BufferGeometry?E.renderBufferDirect(d,e,f,i,k,j):E.renderBuffer(d,e,f,i,k,j)}}}function j(a,b,c,d,e,f,g){for(var i,h,j=0,k=a.length;j<k;j++){i=a[j];h=i.object;if(h.visible){if(g)i=g;else{i=i[b];if(!i)continue;f&&E.setBlending(i.blending,
  10202. i.blendEquation,i.blendSrc,i.blendDst);E.setDepthTest(i.depthTest);E.setDepthWrite(i.depthWrite);w(i.polygonOffset,i.polygonOffsetFactor,i.polygonOffsetUnits)}E.renderImmediateObject(c,d,e,i,h)}}}function i(a,b,c){a.push({buffer:b,object:c,opaque:null,transparent:null})}function o(a){for(var b in a.attributes)if(a.attributes[b].needsUpdate)return true;return false}function k(a){for(var b in a.attributes)a.attributes[b].needsUpdate=false}function u(a,b){for(var c=a.length-1;c>=0;c--)a[c].object===
  10203. b&&a.splice(c,1)}function r(a,b){for(var c=a.length-1;c>=0;c--)a[c]===b&&a.splice(c,1)}function n(a,b,c,d,f){if(!d.program||d.needsUpdate){E.initMaterial(d,b,c,f);d.needsUpdate=false}if(d.morphTargets&&!f.__webglMorphTargetInfluences){f.__webglMorphTargetInfluences=new Float32Array(E.maxMorphTargets);for(var g=0,i=E.maxMorphTargets;g<i;g++)f.__webglMorphTargetInfluences[g]=0}var h=false,g=d.program,i=g.uniforms,j=d.uniforms;if(g!==X){e.useProgram(g);X=g;h=true}if(d.id!==la){la=d.id;h=true}if(h||a!==
  10204. ma){e.uniformMatrix4fv(i.projectionMatrix,false,a._projectionMatrixArray);a!==ma&&(ma=a)}if(h){if(c&&d.fog){j.fogColor.value=c.color;if(c instanceof THREE.Fog){j.fogNear.value=c.near;j.fogFar.value=c.far}else if(c instanceof THREE.FogExp2)j.fogDensity.value=c.density}if(d instanceof THREE.MeshPhongMaterial||d instanceof THREE.MeshLambertMaterial||d.lights){if(nb){for(var k,l=0,m=0,n=0,o,r,p,q=$b,u=q.directional.colors,s=q.directional.positions,w=q.point.colors,z=q.point.positions,B=q.point.distances,
  10205. D=q.spot.colors,F=q.spot.positions,H=q.spot.distances,P=q.spot.directions,Q=q.spot.angles,R=q.spot.exponents,G=0,S=0,T=0,L=p=0,c=L=0,h=b.length;c<h;c++){k=b[c];if(!k.onlyShadow){o=k.color;r=k.intensity;p=k.distance;if(k instanceof THREE.AmbientLight)if(E.gammaInput){l=l+o.r*o.r;m=m+o.g*o.g;n=n+o.b*o.b}else{l=l+o.r;m=m+o.g;n=n+o.b}else if(k instanceof THREE.DirectionalLight){p=G*3;if(E.gammaInput){u[p]=o.r*o.r*r*r;u[p+1]=o.g*o.g*r*r;u[p+2]=o.b*o.b*r*r}else{u[p]=o.r*r;u[p+1]=o.g*r;u[p+2]=o.b*r}La.copy(k.matrixWorld.getPosition());
  10206. La.subSelf(k.target.matrixWorld.getPosition());La.normalize();s[p]=La.x;s[p+1]=La.y;s[p+2]=La.z;G=G+1}else if(k instanceof THREE.PointLight){L=S*3;if(E.gammaInput){w[L]=o.r*o.r*r*r;w[L+1]=o.g*o.g*r*r;w[L+2]=o.b*o.b*r*r}else{w[L]=o.r*r;w[L+1]=o.g*r;w[L+2]=o.b*r}o=k.matrixWorld.getPosition();z[L]=o.x;z[L+1]=o.y;z[L+2]=o.z;B[S]=p;S=S+1}else if(k instanceof THREE.SpotLight){L=T*3;if(E.gammaInput){D[L]=o.r*o.r*r*r;D[L+1]=o.g*o.g*r*r;D[L+2]=o.b*o.b*r*r}else{D[L]=o.r*r;D[L+1]=o.g*r;D[L+2]=o.b*r}o=k.matrixWorld.getPosition();
  10207. F[L]=o.x;F[L+1]=o.y;F[L+2]=o.z;H[T]=p;La.copy(o);La.subSelf(k.target.matrixWorld.getPosition());La.normalize();P[L]=La.x;P[L+1]=La.y;P[L+2]=La.z;Q[T]=Math.cos(k.angle);R[T]=k.exponent;T=T+1}}}c=G*3;for(h=u.length;c<h;c++)u[c]=0;c=S*3;for(h=w.length;c<h;c++)w[c]=0;c=T*3;for(h=D.length;c<h;c++)D[c]=0;q.directional.length=G;q.point.length=S;q.spot.length=T;q.ambient[0]=l;q.ambient[1]=m;q.ambient[2]=n;nb=false}c=$b;j.ambientLightColor.value=c.ambient;j.directionalLightColor.value=c.directional.colors;
  10208. j.directionalLightDirection.value=c.directional.positions;j.pointLightColor.value=c.point.colors;j.pointLightPosition.value=c.point.positions;j.pointLightDistance.value=c.point.distances;j.spotLightColor.value=c.spot.colors;j.spotLightPosition.value=c.spot.positions;j.spotLightDistance.value=c.spot.distances;j.spotLightDirection.value=c.spot.directions;j.spotLightAngle.value=c.spot.angles;j.spotLightExponent.value=c.spot.exponents}if(d instanceof THREE.MeshBasicMaterial||d instanceof THREE.MeshLambertMaterial||
  10209. d instanceof THREE.MeshPhongMaterial){j.opacity.value=d.opacity;E.gammaInput?j.diffuse.value.copyGammaToLinear(d.color):j.diffuse.value=d.color;(j.map.texture=d.map)&&j.offsetRepeat.value.set(d.map.offset.x,d.map.offset.y,d.map.repeat.x,d.map.repeat.y);j.lightMap.texture=d.lightMap;j.envMap.texture=d.envMap;j.flipEnvMap.value=d.envMap instanceof THREE.WebGLRenderTargetCube?1:-1;j.reflectivity.value=d.reflectivity;j.refractionRatio.value=d.refractionRatio;j.combine.value=d.combine;j.useRefract.value=
  10210. d.envMap&&d.envMap.mapping instanceof THREE.CubeRefractionMapping}if(d instanceof THREE.LineBasicMaterial){j.diffuse.value=d.color;j.opacity.value=d.opacity}else if(d instanceof THREE.ParticleBasicMaterial){j.psColor.value=d.color;j.opacity.value=d.opacity;j.size.value=d.size;j.scale.value=C.height/2;j.map.texture=d.map}else if(d instanceof THREE.MeshPhongMaterial){j.shininess.value=d.shininess;if(E.gammaInput){j.ambient.value.copyGammaToLinear(d.ambient);j.emissive.value.copyGammaToLinear(d.emissive);
  10211. j.specular.value.copyGammaToLinear(d.specular)}else{j.ambient.value=d.ambient;j.emissive.value=d.emissive;j.specular.value=d.specular}d.wrapAround&&j.wrapRGB.value.copy(d.wrapRGB)}else if(d instanceof THREE.MeshLambertMaterial){if(E.gammaInput){j.ambient.value.copyGammaToLinear(d.ambient);j.emissive.value.copyGammaToLinear(d.emissive)}else{j.ambient.value=d.ambient;j.emissive.value=d.emissive}d.wrapAround&&j.wrapRGB.value.copy(d.wrapRGB)}else if(d instanceof THREE.MeshDepthMaterial){j.mNear.value=
  10212. a.near;j.mFar.value=a.far;j.opacity.value=d.opacity}else if(d instanceof THREE.MeshNormalMaterial)j.opacity.value=d.opacity;if(f.receiveShadow&&!d._shadowPass&&j.shadowMatrix){h=c=0;for(k=b.length;h<k;h++){l=b[h];if(l.castShadow&&(l instanceof THREE.SpotLight||l instanceof THREE.DirectionalLight&&!l.shadowCascade)){j.shadowMap.texture[c]=l.shadowMap;j.shadowMapSize.value[c]=l.shadowMapSize;j.shadowMatrix.value[c]=l.shadowMatrix;j.shadowDarkness.value[c]=l.shadowDarkness;j.shadowBias.value[c]=l.shadowBias;
  10213. c++}}}b=d.uniformsList;j=0;for(c=b.length;j<c;j++)if(l=g.uniforms[b[j][1]]){h=b[j][0];m=h.type;k=h.value;switch(m){case "i":e.uniform1i(l,k);break;case "f":e.uniform1f(l,k);break;case "v2":e.uniform2f(l,k.x,k.y);break;case "v3":e.uniform3f(l,k.x,k.y,k.z);break;case "v4":e.uniform4f(l,k.x,k.y,k.z,k.w);break;case "c":e.uniform3f(l,k.r,k.g,k.b);break;case "fv1":e.uniform1fv(l,k);break;case "fv":e.uniform3fv(l,k);break;case "v2v":if(!h._array)h._array=new Float32Array(2*k.length);m=0;for(n=k.length;m<
  10214. n;m++){q=m*2;h._array[q]=k[m].x;h._array[q+1]=k[m].y}e.uniform2fv(l,h._array);break;case "v3v":if(!h._array)h._array=new Float32Array(3*k.length);m=0;for(n=k.length;m<n;m++){q=m*3;h._array[q]=k[m].x;h._array[q+1]=k[m].y;h._array[q+2]=k[m].z}e.uniform3fv(l,h._array);break;case "v4v":if(!h._array)h._array=new Float32Array(4*k.length);m=0;for(n=k.length;m<n;m++){q=m*4;h._array[q]=k[m].x;h._array[q+1]=k[m].y;h._array[q+2]=k[m].z;h._array[q+3]=k[m].w}e.uniform4fv(l,h._array);break;case "m4":if(!h._array)h._array=
  10215. new Float32Array(16);k.flattenToArray(h._array);e.uniformMatrix4fv(l,false,h._array);break;case "m4v":if(!h._array)h._array=new Float32Array(16*k.length);m=0;for(n=k.length;m<n;m++)k[m].flattenToArrayOffset(h._array,m*16);e.uniformMatrix4fv(l,false,h._array);break;case "t":e.uniform1i(l,k);l=h.texture;if(!l)continue;if(l.image instanceof Array&&l.image.length===6){h=l;if(h.image.length===6)if(h.needsUpdate){if(!h.image.__webglTextureCube)h.image.__webglTextureCube=e.createTexture();e.activeTexture(e.TEXTURE0+
  10216. k);e.bindTexture(e.TEXTURE_CUBE_MAP,h.image.__webglTextureCube);k=[];for(l=0;l<6;l++){m=k;n=l;if(E.autoScaleCubemaps){q=h.image[l];s=Ic;if(!(q.width<=s&&q.height<=s)){w=Math.max(q.width,q.height);u=Math.floor(q.width*s/w);s=Math.floor(q.height*s/w);w=document.createElement("canvas");w.width=u;w.height=s;w.getContext("2d").drawImage(q,0,0,q.width,q.height,0,0,u,s);q=w}}else q=h.image[l];m[n]=q}l=k[0];m=(l.width&l.width-1)===0&&(l.height&l.height-1)===0;n=J(h.format);q=J(h.type);I(e.TEXTURE_CUBE_MAP,
  10217. h,m);for(l=0;l<6;l++)e.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+l,0,n,n,q,k[l]);h.generateMipmaps&&m&&e.generateMipmap(e.TEXTURE_CUBE_MAP);h.needsUpdate=false;if(h.onUpdate)h.onUpdate()}else{e.activeTexture(e.TEXTURE0+k);e.bindTexture(e.TEXTURE_CUBE_MAP,h.image.__webglTextureCube)}}else if(l instanceof THREE.WebGLRenderTargetCube){h=l;e.activeTexture(e.TEXTURE0+k);e.bindTexture(e.TEXTURE_CUBE_MAP,h.__webglTexture)}else E.setTexture(l,k);break;case "tv":if(!h._array){h._array=[];m=0;for(n=h.texture.length;m<
  10218. n;m++)h._array[m]=k+m}e.uniform1iv(l,h._array);m=0;for(n=h.texture.length;m<n;m++)(l=h.texture[m])&&E.setTexture(l,h._array[m])}}if((d instanceof THREE.ShaderMaterial||d instanceof THREE.MeshPhongMaterial||d.envMap)&&i.cameraPosition!==null){b=a.matrixWorld.getPosition();e.uniform3f(i.cameraPosition,b.x,b.y,b.z)}(d instanceof THREE.MeshPhongMaterial||d instanceof THREE.MeshLambertMaterial||d instanceof THREE.ShaderMaterial||d.skinning)&&i.viewMatrix!==null&&e.uniformMatrix4fv(i.viewMatrix,false,a._viewMatrixArray);
  10219. d.skinning&&e.uniformMatrix4fv(i.boneGlobalMatrices,false,f.boneMatrices)}e.uniformMatrix4fv(i.modelViewMatrix,false,f._modelViewMatrix.elements);i.normalMatrix&&e.uniformMatrix3fv(i.normalMatrix,false,f._normalMatrix.elements);i.objectMatrix!==null&&e.uniformMatrix4fv(i.objectMatrix,false,f.matrixWorld.elements);return g}function p(a,b){a._modelViewMatrix.multiply(b.matrixWorldInverse,a.matrixWorld);a._normalMatrix.getInverse(a._modelViewMatrix);a._normalMatrix.transpose()}function w(a,b,c){if(pc!==
  10220. a){a?e.enable(e.POLYGON_OFFSET_FILL):e.disable(e.POLYGON_OFFSET_FILL);pc=a}if(a&&(qc!==b||rc!==c)){e.polygonOffset(b,c);qc=b;rc=c}}function q(a,b){var c;a==="fragment"?c=e.createShader(e.FRAGMENT_SHADER):a==="vertex"&&(c=e.createShader(e.VERTEX_SHADER));e.shaderSource(c,b);e.compileShader(c);if(!e.getShaderParameter(c,e.COMPILE_STATUS)){console.error(e.getShaderInfoLog(c));console.error(b);return null}return c}function I(a,b,c){if(c){e.texParameteri(a,e.TEXTURE_WRAP_S,J(b.wrapS));e.texParameteri(a,
  10221. e.TEXTURE_WRAP_T,J(b.wrapT));e.texParameteri(a,e.TEXTURE_MAG_FILTER,J(b.magFilter));e.texParameteri(a,e.TEXTURE_MIN_FILTER,J(b.minFilter))}else{e.texParameteri(a,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE);e.texParameteri(a,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);e.texParameteri(a,e.TEXTURE_MAG_FILTER,s(b.magFilter));e.texParameteri(a,e.TEXTURE_MIN_FILTER,s(b.minFilter))}}function B(a,b){e.bindRenderbuffer(e.RENDERBUFFER,a);if(b.depthBuffer&&!b.stencilBuffer){e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_COMPONENT16,
  10222. b.width,b.height);e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,a)}else if(b.depthBuffer&&b.stencilBuffer){e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_STENCIL,b.width,b.height);e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.RENDERBUFFER,a)}else e.renderbufferStorage(e.RENDERBUFFER,e.RGBA4,b.width,b.height)}function s(a){switch(a){case THREE.NearestFilter:case THREE.NearestMipMapNearestFilter:case THREE.NearestMipMapLinearFilter:return e.NEAREST;default:return e.LINEAR}}
  10223. function J(a){switch(a){case THREE.RepeatWrapping:return e.REPEAT;case THREE.ClampToEdgeWrapping:return e.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return e.MIRRORED_REPEAT;case THREE.NearestFilter:return e.NEAREST;case THREE.NearestMipMapNearestFilter:return e.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return e.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return e.LINEAR;case THREE.LinearMipMapNearestFilter:return e.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return e.LINEAR_MIPMAP_LINEAR;
  10224. case THREE.ByteType:return e.BYTE;case THREE.UnsignedByteType:return e.UNSIGNED_BYTE;case THREE.ShortType:return e.SHORT;case THREE.UnsignedShortType:return e.UNSIGNED_SHORT;case THREE.IntType:return e.INT;case THREE.UnsignedIntType:return e.UNSIGNED_INT;case THREE.FloatType:return e.FLOAT;case THREE.AlphaFormat:return e.ALPHA;case THREE.RGBFormat:return e.RGB;case THREE.RGBAFormat:return e.RGBA;case THREE.LuminanceFormat:return e.LUMINANCE;case THREE.LuminanceAlphaFormat:return e.LUMINANCE_ALPHA;
  10225. case THREE.AddEquation:return e.FUNC_ADD;case THREE.SubtractEquation:return e.FUNC_SUBTRACT;case THREE.ReverseSubtractEquation:return e.FUNC_REVERSE_SUBTRACT;case THREE.ZeroFactor:return e.ZERO;case THREE.OneFactor:return e.ONE;case THREE.SrcColorFactor:return e.SRC_COLOR;case THREE.OneMinusSrcColorFactor:return e.ONE_MINUS_SRC_COLOR;case THREE.SrcAlphaFactor:return e.SRC_ALPHA;case THREE.OneMinusSrcAlphaFactor:return e.ONE_MINUS_SRC_ALPHA;case THREE.DstAlphaFactor:return e.DST_ALPHA;case THREE.OneMinusDstAlphaFactor:return e.ONE_MINUS_DST_ALPHA;
  10226. case THREE.DstColorFactor:return e.DST_COLOR;case THREE.OneMinusDstColorFactor:return e.ONE_MINUS_DST_COLOR;case THREE.SrcAlphaSaturateFactor:return e.SRC_ALPHA_SATURATE}return 0}console.log("THREE.WebGLRenderer",THREE.REVISION);var a=a||{},C=a.canvas!==void 0?a.canvas:document.createElement("canvas"),G=a.precision!==void 0?a.precision:"highp",F=a.alpha!==void 0?a.alpha:true,P=a.premultipliedAlpha!==void 0?a.premultipliedAlpha:true,Q=a.antialias!==void 0?a.antialias:false,T=a.stencil!==void 0?a.stencil:
  10227. true,Z=a.preserveDrawingBuffer!==void 0?a.preserveDrawingBuffer:false,R=a.clearColor!==void 0?new THREE.Color(a.clearColor):new THREE.Color(0),z=a.clearAlpha!==void 0?a.clearAlpha:0,H=a.maxLights!==void 0?a.maxLights:4;this.domElement=C;this.context=null;this.autoUpdateScene=this.autoUpdateObjects=this.sortObjects=this.autoClearStencil=this.autoClearDepth=this.autoClearColor=this.autoClear=true;this.shadowMapEnabled=this.physicallyBasedShading=this.gammaOutput=this.gammaInput=false;this.shadowMapCullFrontFaces=
  10228. this.shadowMapSoft=this.shadowMapAutoUpdate=true;this.shadowMapCascade=this.shadowMapDebug=false;this.maxMorphTargets=8;this.maxMorphNormals=4;this.autoScaleCubemaps=true;this.renderPluginsPre=[];this.renderPluginsPost=[];this.info={memory:{programs:0,geometries:0,textures:0},render:{calls:0,vertices:0,faces:0,points:0}};var E=this,e,Ba=[],X=null,D=null,la=-1,S=null,ma=null,ua=0,ra=-1,L=-1,Aa=-1,Ca=-1,Na=-1,Ua=-1,Oa=-1,Fa=-1,pc=null,qc=null,rc=null,mb=null,Ob=0,Yb=0,Hb=0,ac=0,sc=0,Zb=0,Ib=new THREE.Frustum,
  10229. tb=new THREE.Matrix4,Pb=new THREE.Matrix4,Pa=new THREE.Vector4,La=new THREE.Vector3,nb=true,$b={ambient:[0,0,0],directional:{length:0,colors:[],positions:[]},point:{length:0,colors:[],positions:[],distances:[]},spot:{length:0,colors:[],positions:[],distances:[],directions:[],angles:[],exponents:[]}};e=function(){var a;try{if(!(a=C.getContext("experimental-webgl",{alpha:F,premultipliedAlpha:P,antialias:Q,stencil:T,preserveDrawingBuffer:Z})))throw"Error creating WebGL context.";}catch(b){console.error(b)}return a}();
  10230. e.clearColor(0,0,0,1);e.clearDepth(1);e.clearStencil(0);e.enable(e.DEPTH_TEST);e.depthFunc(e.LEQUAL);e.frontFace(e.CCW);e.cullFace(e.BACK);e.enable(e.CULL_FACE);e.enable(e.BLEND);e.blendEquation(e.FUNC_ADD);e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA);e.clearColor(R.r,R.g,R.b,z);this.context=e;var bc=e.getParameter(e.MAX_VERTEX_TEXTURE_IMAGE_UNITS);e.getParameter(e.MAX_TEXTURE_SIZE);var Ic=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE);this.getContext=function(){return e};this.supportsVertexTextures=
  10231. function(){return bc>0};this.setSize=function(a,b){C.width=a;C.height=b;this.setViewport(0,0,C.width,C.height)};this.setViewport=function(a,b,c,d){Ob=a;Yb=b;Hb=c;ac=d;e.viewport(Ob,Yb,Hb,ac)};this.setScissor=function(a,b,c,d){e.scissor(a,b,c,d)};this.enableScissorTest=function(a){a?e.enable(e.SCISSOR_TEST):e.disable(e.SCISSOR_TEST)};this.setClearColorHex=function(a,b){R.setHex(a);z=b;e.clearColor(R.r,R.g,R.b,z)};this.setClearColor=function(a,b){R.copy(a);z=b;e.clearColor(R.r,R.g,R.b,z)};this.getClearColor=
  10232. function(){return R};this.getClearAlpha=function(){return z};this.clear=function(a,b,c){var d=0;if(a===void 0||a)d=d|e.COLOR_BUFFER_BIT;if(b===void 0||b)d=d|e.DEPTH_BUFFER_BIT;if(c===void 0||c)d=d|e.STENCIL_BUFFER_BIT;e.clear(d)};this.clearTarget=function(a,b,c,d){this.setRenderTarget(a);this.clear(b,c,d)};this.addPostPlugin=function(a){a.init(this);this.renderPluginsPost.push(a)};this.addPrePlugin=function(a){a.init(this);this.renderPluginsPre.push(a)};this.deallocateObject=function(a){if(a.__webglInit){a.__webglInit=
  10233. false;delete a._modelViewMatrix;delete a._normalMatrix;delete a._normalMatrixArray;delete a._modelViewMatrixArray;delete a._objectMatrixArray;if(a instanceof THREE.Mesh)for(var b in a.geometry.geometryGroups){var c=a.geometry.geometryGroups[b];e.deleteBuffer(c.__webglVertexBuffer);e.deleteBuffer(c.__webglNormalBuffer);e.deleteBuffer(c.__webglTangentBuffer);e.deleteBuffer(c.__webglColorBuffer);e.deleteBuffer(c.__webglUVBuffer);e.deleteBuffer(c.__webglUV2Buffer);e.deleteBuffer(c.__webglSkinVertexABuffer);
  10234. e.deleteBuffer(c.__webglSkinVertexBBuffer);e.deleteBuffer(c.__webglSkinIndicesBuffer);e.deleteBuffer(c.__webglSkinWeightsBuffer);e.deleteBuffer(c.__webglFaceBuffer);e.deleteBuffer(c.__webglLineBuffer);var d=void 0,f=void 0;if(c.numMorphTargets){d=0;for(f=c.numMorphTargets;d<f;d++)e.deleteBuffer(c.__webglMorphTargetsBuffers[d])}if(c.numMorphNormals){d=0;for(f=c.numMorphNormals;d<f;d++)e.deleteBuffer(c.__webglMorphNormalsBuffers[d])}if(c.__webglCustomAttributesList){d=void 0;for(d in c.__webglCustomAttributesList)e.deleteBuffer(c.__webglCustomAttributesList[d].buffer)}E.info.memory.geometries--}else if(a instanceof
  10235. THREE.Ribbon){a=a.geometry;e.deleteBuffer(a.__webglVertexBuffer);e.deleteBuffer(a.__webglColorBuffer);E.info.memory.geometries--}else if(a instanceof THREE.Line){a=a.geometry;e.deleteBuffer(a.__webglVertexBuffer);e.deleteBuffer(a.__webglColorBuffer);E.info.memory.geometries--}else if(a instanceof THREE.ParticleSystem){a=a.geometry;e.deleteBuffer(a.__webglVertexBuffer);e.deleteBuffer(a.__webglColorBuffer);E.info.memory.geometries--}}};this.deallocateTexture=function(a){if(a.__webglInit){a.__webglInit=
  10236. false;e.deleteTexture(a.__webglTexture);E.info.memory.textures--}};this.deallocateRenderTarget=function(a){if(a&&a.__webglTexture){e.deleteTexture(a.__webglTexture);if(a instanceof THREE.WebGLRenderTargetCube)for(var b=0;b<6;b++){e.deleteFramebuffer(a.__webglFramebuffer[b]);e.deleteRenderbuffer(a.__webglRenderbuffer[b])}else{e.deleteFramebuffer(a.__webglFramebuffer);e.deleteRenderbuffer(a.__webglRenderbuffer)}}};this.updateShadowMap=function(a,b){X=null;la=S=Fa=Oa=Aa=-1;nb=true;L=ra=-1;this.shadowMapPlugin.update(a,
  10237. b)};this.renderBufferImmediate=function(a,b,c){if(!a.__webglVertexBuffer)a.__webglVertexBuffer=e.createBuffer();if(!a.__webglNormalBuffer)a.__webglNormalBuffer=e.createBuffer();if(a.hasPos){e.bindBuffer(e.ARRAY_BUFFER,a.__webglVertexBuffer);e.bufferData(e.ARRAY_BUFFER,a.positionArray,e.DYNAMIC_DRAW);e.enableVertexAttribArray(b.attributes.position);e.vertexAttribPointer(b.attributes.position,3,e.FLOAT,false,0,0)}if(a.hasNormal){e.bindBuffer(e.ARRAY_BUFFER,a.__webglNormalBuffer);if(c===THREE.FlatShading){var d,
  10238. f,g,h,i,j,k,l,m,n,o=a.count*3;for(n=0;n<o;n=n+9){c=a.normalArray;d=c[n];f=c[n+1];g=c[n+2];h=c[n+3];j=c[n+4];l=c[n+5];i=c[n+6];k=c[n+7];m=c[n+8];d=(d+h+i)/3;f=(f+j+k)/3;g=(g+l+m)/3;c[n]=d;c[n+1]=f;c[n+2]=g;c[n+3]=d;c[n+4]=f;c[n+5]=g;c[n+6]=d;c[n+7]=f;c[n+8]=g}}e.bufferData(e.ARRAY_BUFFER,a.normalArray,e.DYNAMIC_DRAW);e.enableVertexAttribArray(b.attributes.normal);e.vertexAttribPointer(b.attributes.normal,3,e.FLOAT,false,0,0)}e.drawArrays(e.TRIANGLES,0,a.count);a.count=0};this.renderBufferDirect=function(a,
  10239. b,c,d,f,g){if(d.visible!==false){c=n(a,b,c,d,g);a=c.attributes;b=false;d=f.id*16777215+c.id*2+(d.wireframe?1:0);if(d!==S){S=d;b=true}if(g instanceof THREE.Mesh){g=f.offsets;d=0;for(c=g.length;d<c;++d){if(b){e.bindBuffer(e.ARRAY_BUFFER,f.vertexPositionBuffer);e.vertexAttribPointer(a.position,f.vertexPositionBuffer.itemSize,e.FLOAT,false,0,g[d].index*12);if(a.normal>=0&&f.vertexNormalBuffer){e.bindBuffer(e.ARRAY_BUFFER,f.vertexNormalBuffer);e.vertexAttribPointer(a.normal,f.vertexNormalBuffer.itemSize,
  10240. e.FLOAT,false,0,g[d].index*12)}if(a.uv>=0&&f.vertexUvBuffer)if(f.vertexUvBuffer){e.bindBuffer(e.ARRAY_BUFFER,f.vertexUvBuffer);e.vertexAttribPointer(a.uv,f.vertexUvBuffer.itemSize,e.FLOAT,false,0,g[d].index*8);e.enableVertexAttribArray(a.uv)}else e.disableVertexAttribArray(a.uv);if(a.color>=0&&f.vertexColorBuffer){e.bindBuffer(e.ARRAY_BUFFER,f.vertexColorBuffer);e.vertexAttribPointer(a.color,f.vertexColorBuffer.itemSize,e.FLOAT,false,0,g[d].index*16)}e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,f.vertexIndexBuffer)}e.drawElements(e.TRIANGLES,
  10241. g[d].count,e.UNSIGNED_SHORT,g[d].start*2);E.info.render.calls++;E.info.render.vertices=E.info.render.vertices+g[d].count;E.info.render.faces=E.info.render.faces+g[d].count/3}}}};this.renderBuffer=function(a,b,c,d,f,g){if(d.visible!==false){var h,i,c=n(a,b,c,d,g),b=c.attributes,a=false,c=f.id*16777215+c.id*2+(d.wireframe?1:0);if(c!==S){S=c;a=true}if(!d.morphTargets&&b.position>=0){if(a){e.bindBuffer(e.ARRAY_BUFFER,f.__webglVertexBuffer);e.vertexAttribPointer(b.position,3,e.FLOAT,false,0,0)}}else if(g.morphTargetBase){c=
  10242. d.program.attributes;if(g.morphTargetBase!==-1){e.bindBuffer(e.ARRAY_BUFFER,f.__webglMorphTargetsBuffers[g.morphTargetBase]);e.vertexAttribPointer(c.position,3,e.FLOAT,false,0,0)}else if(c.position>=0){e.bindBuffer(e.ARRAY_BUFFER,f.__webglVertexBuffer);e.vertexAttribPointer(c.position,3,e.FLOAT,false,0,0)}if(g.morphTargetForcedOrder.length){h=0;var j=g.morphTargetForcedOrder;for(i=g.morphTargetInfluences;h<d.numSupportedMorphTargets&&h<j.length;){e.bindBuffer(e.ARRAY_BUFFER,f.__webglMorphTargetsBuffers[j[h]]);
  10243. e.vertexAttribPointer(c["morphTarget"+h],3,e.FLOAT,false,0,0);if(d.morphNormals){e.bindBuffer(e.ARRAY_BUFFER,f.__webglMorphNormalsBuffers[j[h]]);e.vertexAttribPointer(c["morphNormal"+h],3,e.FLOAT,false,0,0)}g.__webglMorphTargetInfluences[h]=i[j[h]];h++}}else{var j=[],k=-1,l=0;i=g.morphTargetInfluences;var m,o=i.length;h=0;for(g.morphTargetBase!==-1&&(j[g.morphTargetBase]=true);h<d.numSupportedMorphTargets;){for(m=0;m<o;m++)if(!j[m]&&i[m]>k){l=m;k=i[l]}e.bindBuffer(e.ARRAY_BUFFER,f.__webglMorphTargetsBuffers[l]);
  10244. e.vertexAttribPointer(c["morphTarget"+h],3,e.FLOAT,false,0,0);if(d.morphNormals){e.bindBuffer(e.ARRAY_BUFFER,f.__webglMorphNormalsBuffers[l]);e.vertexAttribPointer(c["morphNormal"+h],3,e.FLOAT,false,0,0)}g.__webglMorphTargetInfluences[h]=k;j[l]=1;k=-1;h++}}d.program.uniforms.morphTargetInfluences!==null&&e.uniform1fv(d.program.uniforms.morphTargetInfluences,g.__webglMorphTargetInfluences)}if(a){if(f.__webglCustomAttributesList){h=0;for(i=f.__webglCustomAttributesList.length;h<i;h++){c=f.__webglCustomAttributesList[h];
  10245. if(b[c.buffer.belongsToAttribute]>=0){e.bindBuffer(e.ARRAY_BUFFER,c.buffer);e.vertexAttribPointer(b[c.buffer.belongsToAttribute],c.size,e.FLOAT,false,0,0)}}}if(b.color>=0){e.bindBuffer(e.ARRAY_BUFFER,f.__webglColorBuffer);e.vertexAttribPointer(b.color,3,e.FLOAT,false,0,0)}if(b.normal>=0){e.bindBuffer(e.ARRAY_BUFFER,f.__webglNormalBuffer);e.vertexAttribPointer(b.normal,3,e.FLOAT,false,0,0)}if(b.tangent>=0){e.bindBuffer(e.ARRAY_BUFFER,f.__webglTangentBuffer);e.vertexAttribPointer(b.tangent,4,e.FLOAT,
  10246. false,0,0)}if(b.uv>=0)if(f.__webglUVBuffer){e.bindBuffer(e.ARRAY_BUFFER,f.__webglUVBuffer);e.vertexAttribPointer(b.uv,2,e.FLOAT,false,0,0);e.enableVertexAttribArray(b.uv)}else e.disableVertexAttribArray(b.uv);if(b.uv2>=0)if(f.__webglUV2Buffer){e.bindBuffer(e.ARRAY_BUFFER,f.__webglUV2Buffer);e.vertexAttribPointer(b.uv2,2,e.FLOAT,false,0,0);e.enableVertexAttribArray(b.uv2)}else e.disableVertexAttribArray(b.uv2);if(d.skinning&&b.skinVertexA>=0&&b.skinVertexB>=0&&b.skinIndex>=0&&b.skinWeight>=0){e.bindBuffer(e.ARRAY_BUFFER,
  10247. f.__webglSkinVertexABuffer);e.vertexAttribPointer(b.skinVertexA,4,e.FLOAT,false,0,0);e.bindBuffer(e.ARRAY_BUFFER,f.__webglSkinVertexBBuffer);e.vertexAttribPointer(b.skinVertexB,4,e.FLOAT,false,0,0);e.bindBuffer(e.ARRAY_BUFFER,f.__webglSkinIndicesBuffer);e.vertexAttribPointer(b.skinIndex,4,e.FLOAT,false,0,0);e.bindBuffer(e.ARRAY_BUFFER,f.__webglSkinWeightsBuffer);e.vertexAttribPointer(b.skinWeight,4,e.FLOAT,false,0,0)}}if(g instanceof THREE.Mesh){if(d.wireframe){d=d.wireframeLinewidth;if(d!==mb){e.lineWidth(d);
  10248. mb=d}a&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,f.__webglLineBuffer);e.drawElements(e.LINES,f.__webglLineCount,e.UNSIGNED_SHORT,0)}else{a&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,f.__webglFaceBuffer);e.drawElements(e.TRIANGLES,f.__webglFaceCount,e.UNSIGNED_SHORT,0)}E.info.render.calls++;E.info.render.vertices=E.info.render.vertices+f.__webglFaceCount;E.info.render.faces=E.info.render.faces+f.__webglFaceCount/3}else if(g instanceof THREE.Line){g=g.type===THREE.LineStrip?e.LINE_STRIP:e.LINES;d=d.linewidth;
  10249. if(d!==mb){e.lineWidth(d);mb=d}e.drawArrays(g,0,f.__webglLineCount);E.info.render.calls++}else if(g instanceof THREE.ParticleSystem){e.drawArrays(e.POINTS,0,f.__webglParticleCount);E.info.render.calls++;E.info.render.points=E.info.render.points+f.__webglParticleCount}else if(g instanceof THREE.Ribbon){e.drawArrays(e.TRIANGLE_STRIP,0,f.__webglVertexCount);E.info.render.calls++}}};this.render=function(a,b,c,d){var f,g,i,k,n=a.__lights,o=a.fog;la=-1;nb=true;if(b.parent===void 0){console.warn("DEPRECATED: Camera hasn't been added to a Scene. Adding it...");
  10250. a.add(b)}this.autoUpdateScene&&a.updateMatrixWorld();if(!b._viewMatrixArray)b._viewMatrixArray=new Float32Array(16);if(!b._projectionMatrixArray)b._projectionMatrixArray=new Float32Array(16);b.matrixWorldInverse.getInverse(b.matrixWorld);b.matrixWorldInverse.flattenToArray(b._viewMatrixArray);b.projectionMatrix.flattenToArray(b._projectionMatrixArray);tb.multiply(b.projectionMatrix,b.matrixWorldInverse);Ib.setFromMatrix(tb);this.autoUpdateObjects&&this.initWebGLObjects(a);l(this.renderPluginsPre,
  10251. a,b);E.info.render.calls=0;E.info.render.vertices=0;E.info.render.faces=0;E.info.render.points=0;this.setRenderTarget(c);(this.autoClear||d)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil);k=a.__webglObjects;d=0;for(f=k.length;d<f;d++){g=k[d];i=g.object;g.render=false;if(i.visible&&(!(i instanceof THREE.Mesh||i instanceof THREE.ParticleSystem)||!i.frustumCulled||Ib.contains(i))){p(i,b);var r=g,q=r.object,u=r.buffer,s=void 0,s=s=void 0,s=q.material;if(s instanceof THREE.MeshFaceMaterial){s=
  10252. u.materialIndex;if(s>=0){s=q.geometry.materials[s];if(s.transparent){r.transparent=s;r.opaque=null}else{r.opaque=s;r.transparent=null}}}else if(s)if(s.transparent){r.transparent=s;r.opaque=null}else{r.opaque=s;r.transparent=null}g.render=true;if(this.sortObjects)if(i.renderDepth)g.z=i.renderDepth;else{Pa.copy(i.matrixWorld.getPosition());tb.multiplyVector3(Pa);g.z=Pa.z}}}this.sortObjects&&k.sort(h);k=a.__webglObjectsImmediate;d=0;for(f=k.length;d<f;d++){g=k[d];i=g.object;if(i.visible){p(i,b);i=g.object.material;
  10253. if(i.transparent){g.transparent=i;g.opaque=null}else{g.opaque=i;g.transparent=null}}}if(a.overrideMaterial){d=a.overrideMaterial;this.setBlending(d.blending,d.blendEquation,d.blendSrc,d.blendDst);this.setDepthTest(d.depthTest);this.setDepthWrite(d.depthWrite);w(d.polygonOffset,d.polygonOffsetFactor,d.polygonOffsetUnits);m(a.__webglObjects,false,"",b,n,o,true,d);j(a.__webglObjectsImmediate,"",b,n,o,false,d)}else{this.setBlending(THREE.NormalBlending);m(a.__webglObjects,true,"opaque",b,n,o,false);j(a.__webglObjectsImmediate,
  10254. "opaque",b,n,o,false);m(a.__webglObjects,false,"transparent",b,n,o,true);j(a.__webglObjectsImmediate,"transparent",b,n,o,true)}l(this.renderPluginsPost,a,b);if(c&&c.generateMipmaps&&c.minFilter!==THREE.NearestFilter&&c.minFilter!==THREE.LinearFilter)if(c instanceof THREE.WebGLRenderTargetCube){e.bindTexture(e.TEXTURE_CUBE_MAP,c.__webglTexture);e.generateMipmap(e.TEXTURE_CUBE_MAP);e.bindTexture(e.TEXTURE_CUBE_MAP,null)}else{e.bindTexture(e.TEXTURE_2D,c.__webglTexture);e.generateMipmap(e.TEXTURE_2D);
  10255. e.bindTexture(e.TEXTURE_2D,null)}this.setDepthTest(true);this.setDepthWrite(true)};this.renderImmediateObject=function(a,b,c,d,f){var g=n(a,b,c,d,f);S=-1;E.setObjectFaces(f);f.immediateRenderCallback?f.immediateRenderCallback(g,e,Ib):f.render(function(a){E.renderBufferImmediate(a,g,d.shading)})};this.initWebGLObjects=function(a){if(!a.__webglObjects){a.__webglObjects=[];a.__webglObjectsImmediate=[];a.__webglSprites=[];a.__webglFlares=[]}for(;a.__objectsAdded.length;){var h=a.__objectsAdded[0],j=a,
  10256. l=void 0,m=void 0,n=void 0;if(!h.__webglInit){h.__webglInit=true;h._modelViewMatrix=new THREE.Matrix4;h._normalMatrix=new THREE.Matrix3;if(h instanceof THREE.Mesh){m=h.geometry;if(m instanceof THREE.Geometry){if(m.geometryGroups===void 0){var q=m,p=void 0,s=void 0,w=void 0,z=void 0,B=void 0,C=void 0,D=void 0,F={},I=q.morphTargets.length,J=q.morphNormals.length;q.geometryGroups={};p=0;for(s=q.faces.length;p<s;p++){w=q.faces[p];z=w.materialIndex;C=z!==void 0?z:-1;F[C]===void 0&&(F[C]={hash:C,counter:0});
  10257. D=F[C].hash+"_"+F[C].counter;q.geometryGroups[D]===void 0&&(q.geometryGroups[D]={faces3:[],faces4:[],materialIndex:z,vertices:0,numMorphTargets:I,numMorphNormals:J});B=w instanceof THREE.Face3?3:4;if(q.geometryGroups[D].vertices+B>65535){F[C].counter=F[C].counter+1;D=F[C].hash+"_"+F[C].counter;q.geometryGroups[D]===void 0&&(q.geometryGroups[D]={faces3:[],faces4:[],materialIndex:z,vertices:0,numMorphTargets:I,numMorphNormals:J})}w instanceof THREE.Face3?q.geometryGroups[D].faces3.push(p):q.geometryGroups[D].faces4.push(p);
  10258. q.geometryGroups[D].vertices=q.geometryGroups[D].vertices+B}q.geometryGroupsList=[];var P=void 0;for(P in q.geometryGroups){q.geometryGroups[P].id=ua++;q.geometryGroupsList.push(q.geometryGroups[P])}}for(l in m.geometryGroups){n=m.geometryGroups[l];if(!n.__webglVertexBuffer){var H=n;H.__webglVertexBuffer=e.createBuffer();H.__webglNormalBuffer=e.createBuffer();H.__webglTangentBuffer=e.createBuffer();H.__webglColorBuffer=e.createBuffer();H.__webglUVBuffer=e.createBuffer();H.__webglUV2Buffer=e.createBuffer();
  10259. H.__webglSkinVertexABuffer=e.createBuffer();H.__webglSkinVertexBBuffer=e.createBuffer();H.__webglSkinIndicesBuffer=e.createBuffer();H.__webglSkinWeightsBuffer=e.createBuffer();H.__webglFaceBuffer=e.createBuffer();H.__webglLineBuffer=e.createBuffer();var L=void 0,Q=void 0;if(H.numMorphTargets){H.__webglMorphTargetsBuffers=[];L=0;for(Q=H.numMorphTargets;L<Q;L++)H.__webglMorphTargetsBuffers.push(e.createBuffer())}if(H.numMorphNormals){H.__webglMorphNormalsBuffers=[];L=0;for(Q=H.numMorphNormals;L<Q;L++)H.__webglMorphNormalsBuffers.push(e.createBuffer())}E.info.memory.geometries++;
  10260. var G=n,R=h,S=R.geometry,T=G.faces3,Z=G.faces4,X=T.length*3+Z.length*4,ma=T.length*1+Z.length*2,ra=T.length*3+Z.length*4,la=c(R,G),Aa=f(la),Ba=d(la),La=la.vertexColors?la.vertexColors:false;G.__vertexArray=new Float32Array(X*3);if(Ba)G.__normalArray=new Float32Array(X*3);if(S.hasTangents)G.__tangentArray=new Float32Array(X*4);if(La)G.__colorArray=new Float32Array(X*3);if(Aa){if(S.faceUvs.length>0||S.faceVertexUvs.length>0)G.__uvArray=new Float32Array(X*2);if(S.faceUvs.length>1||S.faceVertexUvs.length>
  10261. 1)G.__uv2Array=new Float32Array(X*2)}if(R.geometry.skinWeights.length&&R.geometry.skinIndices.length){G.__skinVertexAArray=new Float32Array(X*4);G.__skinVertexBArray=new Float32Array(X*4);G.__skinIndexArray=new Float32Array(X*4);G.__skinWeightArray=new Float32Array(X*4)}G.__faceArray=new Uint16Array(ma*3);G.__lineArray=new Uint16Array(ra*2);var Ca=void 0,Fa=void 0;if(G.numMorphTargets){G.__morphTargetsArrays=[];Ca=0;for(Fa=G.numMorphTargets;Ca<Fa;Ca++)G.__morphTargetsArrays.push(new Float32Array(X*
  10262. 3))}if(G.numMorphNormals){G.__morphNormalsArrays=[];Ca=0;for(Fa=G.numMorphNormals;Ca<Fa;Ca++)G.__morphNormalsArrays.push(new Float32Array(X*3))}G.__webglFaceCount=ma*3;G.__webglLineCount=ra*2;if(la.attributes){if(G.__webglCustomAttributesList===void 0)G.__webglCustomAttributesList=[];var Oa=void 0;for(Oa in la.attributes){var Na=la.attributes[Oa],Ma={},Ua;for(Ua in Na)Ma[Ua]=Na[Ua];if(!Ma.__webglInitialized||Ma.createUniqueBuffers){Ma.__webglInitialized=true;var Pa=1;Ma.type==="v2"?Pa=2:Ma.type===
  10263. "v3"?Pa=3:Ma.type==="v4"?Pa=4:Ma.type==="c"&&(Pa=3);Ma.size=Pa;Ma.array=new Float32Array(X*Pa);Ma.buffer=e.createBuffer();Ma.buffer.belongsToAttribute=Oa;Na.needsUpdate=true;Ma.__original=Na}G.__webglCustomAttributesList.push(Ma)}}G.__inittedArrays=true;m.verticesNeedUpdate=true;m.morphTargetsNeedUpdate=true;m.elementsNeedUpdate=true;m.uvsNeedUpdate=true;m.normalsNeedUpdate=true;m.tangetsNeedUpdate=true;m.colorsNeedUpdate=true}}}}else if(h instanceof THREE.Ribbon){m=h.geometry;if(!m.__webglVertexBuffer){var nb=
  10264. m;nb.__webglVertexBuffer=e.createBuffer();nb.__webglColorBuffer=e.createBuffer();E.info.memory.geometries++;var mb=m,tb=mb.vertices.length;mb.__vertexArray=new Float32Array(tb*3);mb.__colorArray=new Float32Array(tb*3);mb.__webglVertexCount=tb;m.verticesNeedUpdate=true;m.colorsNeedUpdate=true}}else if(h instanceof THREE.Line){m=h.geometry;if(!m.__webglVertexBuffer){var Ob=m;Ob.__webglVertexBuffer=e.createBuffer();Ob.__webglColorBuffer=e.createBuffer();E.info.memory.geometries++;var cc=m,Yb=h,Hb=cc.vertices.length;
  10265. cc.__vertexArray=new Float32Array(Hb*3);cc.__colorArray=new Float32Array(Hb*3);cc.__webglLineCount=Hb;b(cc,Yb);m.verticesNeedUpdate=true;m.colorsNeedUpdate=true}}else if(h instanceof THREE.ParticleSystem){m=h.geometry;if(!m.__webglVertexBuffer){var Pb=m;Pb.__webglVertexBuffer=e.createBuffer();Pb.__webglColorBuffer=e.createBuffer();E.info.geometries++;var Qb=m,ac=h,Ib=Qb.vertices.length;Qb.__vertexArray=new Float32Array(Ib*3);Qb.__colorArray=new Float32Array(Ib*3);Qb.__sortArray=[];Qb.__webglParticleCount=
  10266. Ib;b(Qb,ac);m.verticesNeedUpdate=true;m.colorsNeedUpdate=true}}}if(!h.__webglActive){if(h instanceof THREE.Mesh){m=h.geometry;if(m instanceof THREE.BufferGeometry)i(j.__webglObjects,m,h);else for(l in m.geometryGroups){n=m.geometryGroups[l];i(j.__webglObjects,n,h)}}else if(h instanceof THREE.Ribbon||h instanceof THREE.Line||h instanceof THREE.ParticleSystem){m=h.geometry;i(j.__webglObjects,m,h)}else h instanceof THREE.ImmediateRenderObject||h.immediateRenderCallback?j.__webglObjectsImmediate.push({object:h,
  10267. opaque:null,transparent:null}):h instanceof THREE.Sprite?j.__webglSprites.push(h):h instanceof THREE.LensFlare&&j.__webglFlares.push(h);h.__webglActive=true}a.__objectsAdded.splice(0,1)}for(;a.__objectsRemoved.length;){var Qa=a.__objectsRemoved[0],tc=a;Qa instanceof THREE.Mesh||Qa instanceof THREE.ParticleSystem||Qa instanceof THREE.Ribbon||Qa instanceof THREE.Line?u(tc.__webglObjects,Qa):Qa instanceof THREE.Sprite?r(tc.__webglSprites,Qa):Qa instanceof THREE.LensFlare?r(tc.__webglFlares,Qa):(Qa instanceof
  10268. THREE.ImmediateRenderObject||Qa.immediateRenderCallback)&&u(tc.__webglObjectsImmediate,Qa);Qa.__webglActive=false;a.__objectsRemoved.splice(0,1)}for(var Jc=0,pc=a.__webglObjects.length;Jc<pc;Jc++){var Va=a.__webglObjects[Jc].object,Y=Va.geometry,dc=void 0,Rb=void 0,Ga=void 0;if(Va instanceof THREE.Mesh)if(Y instanceof THREE.BufferGeometry){Y.verticesNeedUpdate=false;Y.elementsNeedUpdate=false;Y.uvsNeedUpdate=false;Y.normalsNeedUpdate=false;Y.colorsNeedUpdate=false}else{for(var Kc=0,qc=Y.geometryGroupsList.length;Kc<
  10269. qc;Kc++){dc=Y.geometryGroupsList[Kc];Ga=c(Va,dc);Rb=Ga.attributes&&o(Ga);if(Y.verticesNeedUpdate||Y.morphTargetsNeedUpdate||Y.elementsNeedUpdate||Y.uvsNeedUpdate||Y.normalsNeedUpdate||Y.colorsNeedUpdate||Y.tangetsNeedUpdate||Rb){var V=dc,rc=Va,Ia=e.DYNAMIC_DRAW,sc=!Y.dynamic,Jb=Ga;if(V.__inittedArrays){var Zb=d(Jb),Lc=Jb.vertexColors?Jb.vertexColors:false,$b=f(Jb),uc=Zb===THREE.SmoothShading,x=void 0,K=void 0,Ta=void 0,A=void 0,Sb=void 0,ub=void 0,Wa=void 0,vc=void 0,ob=void 0,Tb=void 0,Ub=void 0,
  10270. M=void 0,N=void 0,O=void 0,ca=void 0,Xa=void 0,Ya=void 0,Za=void 0,ec=void 0,$a=void 0,ab=void 0,bb=void 0,fc=void 0,cb=void 0,db=void 0,eb=void 0,gc=void 0,fb=void 0,gb=void 0,hb=void 0,hc=void 0,ib=void 0,jb=void 0,kb=void 0,ic=void 0,vb=void 0,wb=void 0,xb=void 0,wc=void 0,yb=void 0,zb=void 0,Ab=void 0,xc=void 0,$=void 0,bc=void 0,Bb=void 0,Vb=void 0,Wb=void 0,va=void 0,Tc=void 0,sa=void 0,ta=void 0,Cb=void 0,pb=void 0,na=0,qa=0,qb=0,rb=0,Ra=0,za=0,da=0,Da=0,oa=0,y=0,U=0,v=0,Ja=void 0,wa=V.__vertexArray,
  10271. jc=V.__uvArray,kc=V.__uv2Array,Sa=V.__normalArray,fa=V.__tangentArray,xa=V.__colorArray,ga=V.__skinVertexAArray,ha=V.__skinVertexBArray,ia=V.__skinIndexArray,ja=V.__skinWeightArray,Mc=V.__morphTargetsArrays,Nc=V.__morphNormalsArrays,Oc=V.__webglCustomAttributesList,t=void 0,lb=V.__faceArray,Ka=V.__lineArray,Ea=rc.geometry,Ic=Ea.elementsNeedUpdate,Uc=Ea.uvsNeedUpdate,ad=Ea.normalsNeedUpdate,bd=Ea.tangetsNeedUpdate,cd=Ea.colorsNeedUpdate,dd=Ea.morphTargetsNeedUpdate,Kb=Ea.vertices,aa=V.faces3,ba=V.faces4,
  10272. pa=Ea.faces,Pc=Ea.faceVertexUvs[0],Qc=Ea.faceVertexUvs[1],Lb=Ea.skinVerticesA,Mb=Ea.skinVerticesB,Nb=Ea.skinIndices,Db=Ea.skinWeights,Eb=Ea.morphTargets,yc=Ea.morphNormals;if(Ea.verticesNeedUpdate){x=0;for(K=aa.length;x<K;x++){A=pa[aa[x]];M=Kb[A.a];N=Kb[A.b];O=Kb[A.c];wa[qa]=M.x;wa[qa+1]=M.y;wa[qa+2]=M.z;wa[qa+3]=N.x;wa[qa+4]=N.y;wa[qa+5]=N.z;wa[qa+6]=O.x;wa[qa+7]=O.y;wa[qa+8]=O.z;qa=qa+9}x=0;for(K=ba.length;x<K;x++){A=pa[ba[x]];M=Kb[A.a];N=Kb[A.b];O=Kb[A.c];ca=Kb[A.d];wa[qa]=M.x;wa[qa+1]=M.y;wa[qa+
  10273. 2]=M.z;wa[qa+3]=N.x;wa[qa+4]=N.y;wa[qa+5]=N.z;wa[qa+6]=O.x;wa[qa+7]=O.y;wa[qa+8]=O.z;wa[qa+9]=ca.x;wa[qa+10]=ca.y;wa[qa+11]=ca.z;qa=qa+12}e.bindBuffer(e.ARRAY_BUFFER,V.__webglVertexBuffer);e.bufferData(e.ARRAY_BUFFER,wa,Ia)}if(dd){va=0;for(Tc=Eb.length;va<Tc;va++){x=U=0;for(K=aa.length;x<K;x++){Cb=aa[x];A=pa[Cb];M=Eb[va].vertices[A.a];N=Eb[va].vertices[A.b];O=Eb[va].vertices[A.c];sa=Mc[va];sa[U]=M.x;sa[U+1]=M.y;sa[U+2]=M.z;sa[U+3]=N.x;sa[U+4]=N.y;sa[U+5]=N.z;sa[U+6]=O.x;sa[U+7]=O.y;sa[U+8]=O.z;if(Jb.morphNormals){if(uc){pb=
  10274. yc[va].vertexNormals[Cb];$a=pb.a;ab=pb.b;bb=pb.c}else bb=ab=$a=yc[va].faceNormals[Cb];ta=Nc[va];ta[U]=$a.x;ta[U+1]=$a.y;ta[U+2]=$a.z;ta[U+3]=ab.x;ta[U+4]=ab.y;ta[U+5]=ab.z;ta[U+6]=bb.x;ta[U+7]=bb.y;ta[U+8]=bb.z}U=U+9}x=0;for(K=ba.length;x<K;x++){Cb=ba[x];A=pa[Cb];M=Eb[va].vertices[A.a];N=Eb[va].vertices[A.b];O=Eb[va].vertices[A.c];ca=Eb[va].vertices[A.d];sa=Mc[va];sa[U]=M.x;sa[U+1]=M.y;sa[U+2]=M.z;sa[U+3]=N.x;sa[U+4]=N.y;sa[U+5]=N.z;sa[U+6]=O.x;sa[U+7]=O.y;sa[U+8]=O.z;sa[U+9]=ca.x;sa[U+10]=ca.y;sa[U+
  10275. 11]=ca.z;if(Jb.morphNormals){if(uc){pb=yc[va].vertexNormals[Cb];$a=pb.a;ab=pb.b;bb=pb.c;fc=pb.d}else fc=bb=ab=$a=yc[va].faceNormals[Cb];ta=Nc[va];ta[U]=$a.x;ta[U+1]=$a.y;ta[U+2]=$a.z;ta[U+3]=ab.x;ta[U+4]=ab.y;ta[U+5]=ab.z;ta[U+6]=bb.x;ta[U+7]=bb.y;ta[U+8]=bb.z;ta[U+9]=fc.x;ta[U+10]=fc.y;ta[U+11]=fc.z}U=U+12}e.bindBuffer(e.ARRAY_BUFFER,V.__webglMorphTargetsBuffers[va]);e.bufferData(e.ARRAY_BUFFER,Mc[va],Ia);if(Jb.morphNormals){e.bindBuffer(e.ARRAY_BUFFER,V.__webglMorphNormalsBuffers[va]);e.bufferData(e.ARRAY_BUFFER,
  10276. Nc[va],Ia)}}}if(Db.length){x=0;for(K=aa.length;x<K;x++){A=pa[aa[x]];fb=Db[A.a];gb=Db[A.b];hb=Db[A.c];ja[y]=fb.x;ja[y+1]=fb.y;ja[y+2]=fb.z;ja[y+3]=fb.w;ja[y+4]=gb.x;ja[y+5]=gb.y;ja[y+6]=gb.z;ja[y+7]=gb.w;ja[y+8]=hb.x;ja[y+9]=hb.y;ja[y+10]=hb.z;ja[y+11]=hb.w;ib=Nb[A.a];jb=Nb[A.b];kb=Nb[A.c];ia[y]=ib.x;ia[y+1]=ib.y;ia[y+2]=ib.z;ia[y+3]=ib.w;ia[y+4]=jb.x;ia[y+5]=jb.y;ia[y+6]=jb.z;ia[y+7]=jb.w;ia[y+8]=kb.x;ia[y+9]=kb.y;ia[y+10]=kb.z;ia[y+11]=kb.w;vb=Lb[A.a];wb=Lb[A.b];xb=Lb[A.c];ga[y]=vb.x;ga[y+1]=vb.y;
  10277. ga[y+2]=vb.z;ga[y+3]=1;ga[y+4]=wb.x;ga[y+5]=wb.y;ga[y+6]=wb.z;ga[y+7]=1;ga[y+8]=xb.x;ga[y+9]=xb.y;ga[y+10]=xb.z;ga[y+11]=1;yb=Mb[A.a];zb=Mb[A.b];Ab=Mb[A.c];ha[y]=yb.x;ha[y+1]=yb.y;ha[y+2]=yb.z;ha[y+3]=1;ha[y+4]=zb.x;ha[y+5]=zb.y;ha[y+6]=zb.z;ha[y+7]=1;ha[y+8]=Ab.x;ha[y+9]=Ab.y;ha[y+10]=Ab.z;ha[y+11]=1;y=y+12}x=0;for(K=ba.length;x<K;x++){A=pa[ba[x]];fb=Db[A.a];gb=Db[A.b];hb=Db[A.c];hc=Db[A.d];ja[y]=fb.x;ja[y+1]=fb.y;ja[y+2]=fb.z;ja[y+3]=fb.w;ja[y+4]=gb.x;ja[y+5]=gb.y;ja[y+6]=gb.z;ja[y+7]=gb.w;ja[y+
  10278. 8]=hb.x;ja[y+9]=hb.y;ja[y+10]=hb.z;ja[y+11]=hb.w;ja[y+12]=hc.x;ja[y+13]=hc.y;ja[y+14]=hc.z;ja[y+15]=hc.w;ib=Nb[A.a];jb=Nb[A.b];kb=Nb[A.c];ic=Nb[A.d];ia[y]=ib.x;ia[y+1]=ib.y;ia[y+2]=ib.z;ia[y+3]=ib.w;ia[y+4]=jb.x;ia[y+5]=jb.y;ia[y+6]=jb.z;ia[y+7]=jb.w;ia[y+8]=kb.x;ia[y+9]=kb.y;ia[y+10]=kb.z;ia[y+11]=kb.w;ia[y+12]=ic.x;ia[y+13]=ic.y;ia[y+14]=ic.z;ia[y+15]=ic.w;vb=Lb[A.a];wb=Lb[A.b];xb=Lb[A.c];wc=Lb[A.d];ga[y]=vb.x;ga[y+1]=vb.y;ga[y+2]=vb.z;ga[y+3]=1;ga[y+4]=wb.x;ga[y+5]=wb.y;ga[y+6]=wb.z;ga[y+7]=1;
  10279. ga[y+8]=xb.x;ga[y+9]=xb.y;ga[y+10]=xb.z;ga[y+11]=1;ga[y+12]=wc.x;ga[y+13]=wc.y;ga[y+14]=wc.z;ga[y+15]=1;yb=Mb[A.a];zb=Mb[A.b];Ab=Mb[A.c];xc=Mb[A.d];ha[y]=yb.x;ha[y+1]=yb.y;ha[y+2]=yb.z;ha[y+3]=1;ha[y+4]=zb.x;ha[y+5]=zb.y;ha[y+6]=zb.z;ha[y+7]=1;ha[y+8]=Ab.x;ha[y+9]=Ab.y;ha[y+10]=Ab.z;ha[y+11]=1;ha[y+12]=xc.x;ha[y+13]=xc.y;ha[y+14]=xc.z;ha[y+15]=1;y=y+16}if(y>0){e.bindBuffer(e.ARRAY_BUFFER,V.__webglSkinVertexABuffer);e.bufferData(e.ARRAY_BUFFER,ga,Ia);e.bindBuffer(e.ARRAY_BUFFER,V.__webglSkinVertexBBuffer);
  10280. e.bufferData(e.ARRAY_BUFFER,ha,Ia);e.bindBuffer(e.ARRAY_BUFFER,V.__webglSkinIndicesBuffer);e.bufferData(e.ARRAY_BUFFER,ia,Ia);e.bindBuffer(e.ARRAY_BUFFER,V.__webglSkinWeightsBuffer);e.bufferData(e.ARRAY_BUFFER,ja,Ia)}}if(cd&&Lc){x=0;for(K=aa.length;x<K;x++){A=pa[aa[x]];Wa=A.vertexColors;vc=A.color;if(Wa.length===3&&Lc===THREE.VertexColors){cb=Wa[0];db=Wa[1];eb=Wa[2]}else eb=db=cb=vc;xa[oa]=cb.r;xa[oa+1]=cb.g;xa[oa+2]=cb.b;xa[oa+3]=db.r;xa[oa+4]=db.g;xa[oa+5]=db.b;xa[oa+6]=eb.r;xa[oa+7]=eb.g;xa[oa+
  10281. 8]=eb.b;oa=oa+9}x=0;for(K=ba.length;x<K;x++){A=pa[ba[x]];Wa=A.vertexColors;vc=A.color;if(Wa.length===4&&Lc===THREE.VertexColors){cb=Wa[0];db=Wa[1];eb=Wa[2];gc=Wa[3]}else gc=eb=db=cb=vc;xa[oa]=cb.r;xa[oa+1]=cb.g;xa[oa+2]=cb.b;xa[oa+3]=db.r;xa[oa+4]=db.g;xa[oa+5]=db.b;xa[oa+6]=eb.r;xa[oa+7]=eb.g;xa[oa+8]=eb.b;xa[oa+9]=gc.r;xa[oa+10]=gc.g;xa[oa+11]=gc.b;oa=oa+12}if(oa>0){e.bindBuffer(e.ARRAY_BUFFER,V.__webglColorBuffer);e.bufferData(e.ARRAY_BUFFER,xa,Ia)}}if(bd&&Ea.hasTangents){x=0;for(K=aa.length;x<
  10282. K;x++){A=pa[aa[x]];ob=A.vertexTangents;Xa=ob[0];Ya=ob[1];Za=ob[2];fa[da]=Xa.x;fa[da+1]=Xa.y;fa[da+2]=Xa.z;fa[da+3]=Xa.w;fa[da+4]=Ya.x;fa[da+5]=Ya.y;fa[da+6]=Ya.z;fa[da+7]=Ya.w;fa[da+8]=Za.x;fa[da+9]=Za.y;fa[da+10]=Za.z;fa[da+11]=Za.w;da=da+12}x=0;for(K=ba.length;x<K;x++){A=pa[ba[x]];ob=A.vertexTangents;Xa=ob[0];Ya=ob[1];Za=ob[2];ec=ob[3];fa[da]=Xa.x;fa[da+1]=Xa.y;fa[da+2]=Xa.z;fa[da+3]=Xa.w;fa[da+4]=Ya.x;fa[da+5]=Ya.y;fa[da+6]=Ya.z;fa[da+7]=Ya.w;fa[da+8]=Za.x;fa[da+9]=Za.y;fa[da+10]=Za.z;fa[da+11]=
  10283. Za.w;fa[da+12]=ec.x;fa[da+13]=ec.y;fa[da+14]=ec.z;fa[da+15]=ec.w;da=da+16}e.bindBuffer(e.ARRAY_BUFFER,V.__webglTangentBuffer);e.bufferData(e.ARRAY_BUFFER,fa,Ia)}if(ad&&Zb){x=0;for(K=aa.length;x<K;x++){A=pa[aa[x]];Sb=A.vertexNormals;ub=A.normal;if(Sb.length===3&&uc)for($=0;$<3;$++){Bb=Sb[$];Sa[za]=Bb.x;Sa[za+1]=Bb.y;Sa[za+2]=Bb.z;za=za+3}else for($=0;$<3;$++){Sa[za]=ub.x;Sa[za+1]=ub.y;Sa[za+2]=ub.z;za=za+3}}x=0;for(K=ba.length;x<K;x++){A=pa[ba[x]];Sb=A.vertexNormals;ub=A.normal;if(Sb.length===4&&uc)for($=
  10284. 0;$<4;$++){Bb=Sb[$];Sa[za]=Bb.x;Sa[za+1]=Bb.y;Sa[za+2]=Bb.z;za=za+3}else for($=0;$<4;$++){Sa[za]=ub.x;Sa[za+1]=ub.y;Sa[za+2]=ub.z;za=za+3}}e.bindBuffer(e.ARRAY_BUFFER,V.__webglNormalBuffer);e.bufferData(e.ARRAY_BUFFER,Sa,Ia)}if(Uc&&Pc&&$b){x=0;for(K=aa.length;x<K;x++){Ta=aa[x];A=pa[Ta];Tb=Pc[Ta];if(Tb!==void 0)for($=0;$<3;$++){Vb=Tb[$];jc[qb]=Vb.u;jc[qb+1]=Vb.v;qb=qb+2}}x=0;for(K=ba.length;x<K;x++){Ta=ba[x];A=pa[Ta];Tb=Pc[Ta];if(Tb!==void 0)for($=0;$<4;$++){Vb=Tb[$];jc[qb]=Vb.u;jc[qb+1]=Vb.v;qb=qb+
  10285. 2}}if(qb>0){e.bindBuffer(e.ARRAY_BUFFER,V.__webglUVBuffer);e.bufferData(e.ARRAY_BUFFER,jc,Ia)}}if(Uc&&Qc&&$b){x=0;for(K=aa.length;x<K;x++){Ta=aa[x];A=pa[Ta];Ub=Qc[Ta];if(Ub!==void 0)for($=0;$<3;$++){Wb=Ub[$];kc[rb]=Wb.u;kc[rb+1]=Wb.v;rb=rb+2}}x=0;for(K=ba.length;x<K;x++){Ta=ba[x];A=pa[Ta];Ub=Qc[Ta];if(Ub!==void 0)for($=0;$<4;$++){Wb=Ub[$];kc[rb]=Wb.u;kc[rb+1]=Wb.v;rb=rb+2}}if(rb>0){e.bindBuffer(e.ARRAY_BUFFER,V.__webglUV2Buffer);e.bufferData(e.ARRAY_BUFFER,kc,Ia)}}if(Ic){x=0;for(K=aa.length;x<K;x++){A=
  10286. pa[aa[x]];lb[Ra]=na;lb[Ra+1]=na+1;lb[Ra+2]=na+2;Ra=Ra+3;Ka[Da]=na;Ka[Da+1]=na+1;Ka[Da+2]=na;Ka[Da+3]=na+2;Ka[Da+4]=na+1;Ka[Da+5]=na+2;Da=Da+6;na=na+3}x=0;for(K=ba.length;x<K;x++){A=pa[ba[x]];lb[Ra]=na;lb[Ra+1]=na+1;lb[Ra+2]=na+3;lb[Ra+3]=na+1;lb[Ra+4]=na+2;lb[Ra+5]=na+3;Ra=Ra+6;Ka[Da]=na;Ka[Da+1]=na+1;Ka[Da+2]=na;Ka[Da+3]=na+3;Ka[Da+4]=na+1;Ka[Da+5]=na+2;Ka[Da+6]=na+2;Ka[Da+7]=na+3;Da=Da+8;na=na+4}e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,V.__webglFaceBuffer);e.bufferData(e.ELEMENT_ARRAY_BUFFER,lb,Ia);
  10287. e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,V.__webglLineBuffer);e.bufferData(e.ELEMENT_ARRAY_BUFFER,Ka,Ia)}if(Oc){$=0;for(bc=Oc.length;$<bc;$++){t=Oc[$];if(t.__original.needsUpdate){v=0;if(t.size===1)if(t.boundTo===void 0||t.boundTo==="vertices"){x=0;for(K=aa.length;x<K;x++){A=pa[aa[x]];t.array[v]=t.value[A.a];t.array[v+1]=t.value[A.b];t.array[v+2]=t.value[A.c];v=v+3}x=0;for(K=ba.length;x<K;x++){A=pa[ba[x]];t.array[v]=t.value[A.a];t.array[v+1]=t.value[A.b];t.array[v+2]=t.value[A.c];t.array[v+3]=t.value[A.d];
  10288. v=v+4}}else{if(t.boundTo==="faces"){x=0;for(K=aa.length;x<K;x++){Ja=t.value[aa[x]];t.array[v]=Ja;t.array[v+1]=Ja;t.array[v+2]=Ja;v=v+3}x=0;for(K=ba.length;x<K;x++){Ja=t.value[ba[x]];t.array[v]=Ja;t.array[v+1]=Ja;t.array[v+2]=Ja;t.array[v+3]=Ja;v=v+4}}}else if(t.size===2)if(t.boundTo===void 0||t.boundTo==="vertices"){x=0;for(K=aa.length;x<K;x++){A=pa[aa[x]];M=t.value[A.a];N=t.value[A.b];O=t.value[A.c];t.array[v]=M.x;t.array[v+1]=M.y;t.array[v+2]=N.x;t.array[v+3]=N.y;t.array[v+4]=O.x;t.array[v+5]=O.y;
  10289. v=v+6}x=0;for(K=ba.length;x<K;x++){A=pa[ba[x]];M=t.value[A.a];N=t.value[A.b];O=t.value[A.c];ca=t.value[A.d];t.array[v]=M.x;t.array[v+1]=M.y;t.array[v+2]=N.x;t.array[v+3]=N.y;t.array[v+4]=O.x;t.array[v+5]=O.y;t.array[v+6]=ca.x;t.array[v+7]=ca.y;v=v+8}}else{if(t.boundTo==="faces"){x=0;for(K=aa.length;x<K;x++){O=N=M=Ja=t.value[aa[x]];t.array[v]=M.x;t.array[v+1]=M.y;t.array[v+2]=N.x;t.array[v+3]=N.y;t.array[v+4]=O.x;t.array[v+5]=O.y;v=v+6}x=0;for(K=ba.length;x<K;x++){ca=O=N=M=Ja=t.value[ba[x]];t.array[v]=
  10290. M.x;t.array[v+1]=M.y;t.array[v+2]=N.x;t.array[v+3]=N.y;t.array[v+4]=O.x;t.array[v+5]=O.y;t.array[v+6]=ca.x;t.array[v+7]=ca.y;v=v+8}}}else if(t.size===3){var W;W=t.type==="c"?["r","g","b"]:["x","y","z"];if(t.boundTo===void 0||t.boundTo==="vertices"){x=0;for(K=aa.length;x<K;x++){A=pa[aa[x]];M=t.value[A.a];N=t.value[A.b];O=t.value[A.c];t.array[v]=M[W[0]];t.array[v+1]=M[W[1]];t.array[v+2]=M[W[2]];t.array[v+3]=N[W[0]];t.array[v+4]=N[W[1]];t.array[v+5]=N[W[2]];t.array[v+6]=O[W[0]];t.array[v+7]=O[W[1]];
  10291. t.array[v+8]=O[W[2]];v=v+9}x=0;for(K=ba.length;x<K;x++){A=pa[ba[x]];M=t.value[A.a];N=t.value[A.b];O=t.value[A.c];ca=t.value[A.d];t.array[v]=M[W[0]];t.array[v+1]=M[W[1]];t.array[v+2]=M[W[2]];t.array[v+3]=N[W[0]];t.array[v+4]=N[W[1]];t.array[v+5]=N[W[2]];t.array[v+6]=O[W[0]];t.array[v+7]=O[W[1]];t.array[v+8]=O[W[2]];t.array[v+9]=ca[W[0]];t.array[v+10]=ca[W[1]];t.array[v+11]=ca[W[2]];v=v+12}}else if(t.boundTo==="faces"){x=0;for(K=aa.length;x<K;x++){O=N=M=Ja=t.value[aa[x]];t.array[v]=M[W[0]];t.array[v+
  10292. 1]=M[W[1]];t.array[v+2]=M[W[2]];t.array[v+3]=N[W[0]];t.array[v+4]=N[W[1]];t.array[v+5]=N[W[2]];t.array[v+6]=O[W[0]];t.array[v+7]=O[W[1]];t.array[v+8]=O[W[2]];v=v+9}x=0;for(K=ba.length;x<K;x++){ca=O=N=M=Ja=t.value[ba[x]];t.array[v]=M[W[0]];t.array[v+1]=M[W[1]];t.array[v+2]=M[W[2]];t.array[v+3]=N[W[0]];t.array[v+4]=N[W[1]];t.array[v+5]=N[W[2]];t.array[v+6]=O[W[0]];t.array[v+7]=O[W[1]];t.array[v+8]=O[W[2]];t.array[v+9]=ca[W[0]];t.array[v+10]=ca[W[1]];t.array[v+11]=ca[W[2]];v=v+12}}}else if(t.size===
  10293. 4)if(t.boundTo===void 0||t.boundTo==="vertices"){x=0;for(K=aa.length;x<K;x++){A=pa[aa[x]];M=t.value[A.a];N=t.value[A.b];O=t.value[A.c];t.array[v]=M.x;t.array[v+1]=M.y;t.array[v+2]=M.z;t.array[v+3]=M.w;t.array[v+4]=N.x;t.array[v+5]=N.y;t.array[v+6]=N.z;t.array[v+7]=N.w;t.array[v+8]=O.x;t.array[v+9]=O.y;t.array[v+10]=O.z;t.array[v+11]=O.w;v=v+12}x=0;for(K=ba.length;x<K;x++){A=pa[ba[x]];M=t.value[A.a];N=t.value[A.b];O=t.value[A.c];ca=t.value[A.d];t.array[v]=M.x;t.array[v+1]=M.y;t.array[v+2]=M.z;t.array[v+
  10294. 3]=M.w;t.array[v+4]=N.x;t.array[v+5]=N.y;t.array[v+6]=N.z;t.array[v+7]=N.w;t.array[v+8]=O.x;t.array[v+9]=O.y;t.array[v+10]=O.z;t.array[v+11]=O.w;t.array[v+12]=ca.x;t.array[v+13]=ca.y;t.array[v+14]=ca.z;t.array[v+15]=ca.w;v=v+16}}else if(t.boundTo==="faces"){x=0;for(K=aa.length;x<K;x++){O=N=M=Ja=t.value[aa[x]];t.array[v]=M.x;t.array[v+1]=M.y;t.array[v+2]=M.z;t.array[v+3]=M.w;t.array[v+4]=N.x;t.array[v+5]=N.y;t.array[v+6]=N.z;t.array[v+7]=N.w;t.array[v+8]=O.x;t.array[v+9]=O.y;t.array[v+10]=O.z;t.array[v+
  10295. 11]=O.w;v=v+12}x=0;for(K=ba.length;x<K;x++){ca=O=N=M=Ja=t.value[ba[x]];t.array[v]=M.x;t.array[v+1]=M.y;t.array[v+2]=M.z;t.array[v+3]=M.w;t.array[v+4]=N.x;t.array[v+5]=N.y;t.array[v+6]=N.z;t.array[v+7]=N.w;t.array[v+8]=O.x;t.array[v+9]=O.y;t.array[v+10]=O.z;t.array[v+11]=O.w;t.array[v+12]=ca.x;t.array[v+13]=ca.y;t.array[v+14]=ca.z;t.array[v+15]=ca.w;v=v+16}}e.bindBuffer(e.ARRAY_BUFFER,t.buffer);e.bufferData(e.ARRAY_BUFFER,t.array,Ia)}}}if(sc){delete V.__inittedArrays;delete V.__colorArray;delete V.__normalArray;
  10296. delete V.__tangentArray;delete V.__uvArray;delete V.__uv2Array;delete V.__faceArray;delete V.__vertexArray;delete V.__lineArray;delete V.__skinVertexAArray;delete V.__skinVertexBArray;delete V.__skinIndexArray;delete V.__skinWeightArray}}}}Y.verticesNeedUpdate=false;Y.morphTargetsNeedUpdate=false;Y.elementsNeedUpdate=false;Y.uvsNeedUpdate=false;Y.normalsNeedUpdate=false;Y.colorsNeedUpdate=false;Y.tangetsNeedUpdate=false;Ga.attributes&&k(Ga)}else if(Va instanceof THREE.Ribbon){if(Y.verticesNeedUpdate||
  10297. Y.colorsNeedUpdate){var Fb=Y,Vc=e.DYNAMIC_DRAW,lc=void 0,mc=void 0,zc=void 0,Gb=void 0,Ac=void 0,Wc=Fb.vertices,Xc=Fb.colors,ed=Wc.length,fd=Xc.length,Bc=Fb.__vertexArray,Cc=Fb.__colorArray,gd=Fb.colorsNeedUpdate;if(Fb.verticesNeedUpdate){for(lc=0;lc<ed;lc++){zc=Wc[lc];Gb=lc*3;Bc[Gb]=zc.x;Bc[Gb+1]=zc.y;Bc[Gb+2]=zc.z}e.bindBuffer(e.ARRAY_BUFFER,Fb.__webglVertexBuffer);e.bufferData(e.ARRAY_BUFFER,Bc,Vc)}if(gd){for(mc=0;mc<fd;mc++){Ac=Xc[mc];Gb=mc*3;Cc[Gb]=Ac.r;Cc[Gb+1]=Ac.g;Cc[Gb+2]=Ac.b}e.bindBuffer(e.ARRAY_BUFFER,
  10298. Fb.__webglColorBuffer);e.bufferData(e.ARRAY_BUFFER,Cc,Vc)}}Y.verticesNeedUpdate=false;Y.colorsNeedUpdate=false}else if(Va instanceof THREE.Line){Ga=c(Va,dc);Rb=Ga.attributes&&o(Ga);if(Y.verticesNeedUpdate||Y.colorsNeedUpdate||Rb){var sb=Y,Rc=e.DYNAMIC_DRAW,nc=void 0,oc=void 0,Dc=void 0,ka=void 0,Ec=void 0,Yc=sb.vertices,Zc=sb.colors,hd=Yc.length,id=Zc.length,Fc=sb.__vertexArray,Gc=sb.__colorArray,jd=sb.colorsNeedUpdate,Sc=sb.__webglCustomAttributesList,Hc=void 0,$c=void 0,ya=void 0,Xb=void 0,Ha=void 0,
  10299. ea=void 0;if(sb.verticesNeedUpdate){for(nc=0;nc<hd;nc++){Dc=Yc[nc];ka=nc*3;Fc[ka]=Dc.x;Fc[ka+1]=Dc.y;Fc[ka+2]=Dc.z}e.bindBuffer(e.ARRAY_BUFFER,sb.__webglVertexBuffer);e.bufferData(e.ARRAY_BUFFER,Fc,Rc)}if(jd){for(oc=0;oc<id;oc++){Ec=Zc[oc];ka=oc*3;Gc[ka]=Ec.r;Gc[ka+1]=Ec.g;Gc[ka+2]=Ec.b}e.bindBuffer(e.ARRAY_BUFFER,sb.__webglColorBuffer);e.bufferData(e.ARRAY_BUFFER,Gc,Rc)}if(Sc){Hc=0;for($c=Sc.length;Hc<$c;Hc++){ea=Sc[Hc];if(ea.needsUpdate&&(ea.boundTo===void 0||ea.boundTo==="vertices")){ka=0;Xb=ea.value.length;
  10300. if(ea.size===1)for(ya=0;ya<Xb;ya++)ea.array[ya]=ea.value[ya];else if(ea.size===2)for(ya=0;ya<Xb;ya++){Ha=ea.value[ya];ea.array[ka]=Ha.x;ea.array[ka+1]=Ha.y;ka=ka+2}else if(ea.size===3)if(ea.type==="c")for(ya=0;ya<Xb;ya++){Ha=ea.value[ya];ea.array[ka]=Ha.r;ea.array[ka+1]=Ha.g;ea.array[ka+2]=Ha.b;ka=ka+3}else for(ya=0;ya<Xb;ya++){Ha=ea.value[ya];ea.array[ka]=Ha.x;ea.array[ka+1]=Ha.y;ea.array[ka+2]=Ha.z;ka=ka+3}else if(ea.size===4)for(ya=0;ya<Xb;ya++){Ha=ea.value[ya];ea.array[ka]=Ha.x;ea.array[ka+1]=
  10301. Ha.y;ea.array[ka+2]=Ha.z;ea.array[ka+3]=Ha.w;ka=ka+4}e.bindBuffer(e.ARRAY_BUFFER,ea.buffer);e.bufferData(e.ARRAY_BUFFER,ea.array,Rc)}}}}Y.verticesNeedUpdate=false;Y.colorsNeedUpdate=false;Ga.attributes&&k(Ga)}else if(Va instanceof THREE.ParticleSystem){Ga=c(Va,dc);Rb=Ga.attributes&&o(Ga);(Y.verticesNeedUpdate||Y.colorsNeedUpdate||Va.sortParticles||Rb)&&g(Y,e.DYNAMIC_DRAW,Va);Y.verticesNeedUpdate=false;Y.colorsNeedUpdate=false;Ga.attributes&&k(Ga)}}};this.initMaterial=function(a,b,c,d){var f,g,h;a instanceof
  10302. THREE.MeshDepthMaterial?h="depth":a instanceof THREE.MeshNormalMaterial?h="normal":a instanceof THREE.MeshBasicMaterial?h="basic":a instanceof THREE.MeshLambertMaterial?h="lambert":a instanceof THREE.MeshPhongMaterial?h="phong":a instanceof THREE.LineBasicMaterial?h="basic":a instanceof THREE.ParticleBasicMaterial&&(h="particle_basic");if(h){var i=THREE.ShaderLib[h];a.uniforms=THREE.UniformsUtils.clone(i.uniforms);a.vertexShader=i.vertexShader;a.fragmentShader=i.fragmentShader}var j,k,l,m,n;j=m=n=
  10303. i=0;for(k=b.length;j<k;j++){l=b[j];if(!l.onlyShadow){l instanceof THREE.DirectionalLight&&m++;l instanceof THREE.PointLight&&n++;l instanceof THREE.SpotLight&&i++}}if(n+i+m<=H){k=m;l=n;m=i}else{k=Math.ceil(H*m/(n+m));m=l=H-k}var o=0,i=0;for(n=b.length;i<n;i++){j=b[i];if(j.castShadow){j instanceof THREE.SpotLight&&o++;j instanceof THREE.DirectionalLight&&!j.shadowCascade&&o++}}var r=50;if(d!==void 0&&d instanceof THREE.SkinnedMesh)r=d.bones.length;var p;a:{n=a.fragmentShader;j=a.vertexShader;var i=
  10304. a.uniforms,b=a.attributes,c={map:!!a.map,envMap:!!a.envMap,lightMap:!!a.lightMap,vertexColors:a.vertexColors,fog:c,useFog:a.fog,sizeAttenuation:a.sizeAttenuation,skinning:a.skinning,maxBones:r,morphTargets:a.morphTargets,morphNormals:a.morphNormals,maxMorphTargets:this.maxMorphTargets,maxMorphNormals:this.maxMorphNormals,maxDirLights:k,maxPointLights:l,maxSpotLights:m,maxShadows:o,shadowMapEnabled:this.shadowMapEnabled&&d.receiveShadow,shadowMapSoft:this.shadowMapSoft,shadowMapDebug:this.shadowMapDebug,
  10305. shadowMapCascade:this.shadowMapCascade,alphaTest:a.alphaTest,metal:a.metal,perPixel:a.perPixel,wrapAround:a.wrapAround,doubleSided:d&&d.doubleSided},s,d=[];if(h)d.push(h);else{d.push(n);d.push(j)}for(s in c){d.push(s);d.push(c[s])}h=d.join();s=0;for(d=Ba.length;s<d;s++)if(Ba[s].code===h){p=Ba[s].program;break a}s=e.createProgram();d=["precision "+G+" float;",bc>0?"#define VERTEX_TEXTURES":"",E.gammaInput?"#define GAMMA_INPUT":"",E.gammaOutput?"#define GAMMA_OUTPUT":"",E.physicallyBasedShading?"#define PHYSICALLY_BASED_SHADING":
  10306. "","#define MAX_DIR_LIGHTS "+c.maxDirLights,"#define MAX_POINT_LIGHTS "+c.maxPointLights,"#define MAX_SPOT_LIGHTS "+c.maxSpotLights,"#define MAX_SHADOWS "+c.maxShadows,"#define MAX_BONES "+c.maxBones,c.map?"#define USE_MAP":"",c.envMap?"#define USE_ENVMAP":"",c.lightMap?"#define USE_LIGHTMAP":"",c.vertexColors?"#define USE_COLOR":"",c.skinning?"#define USE_SKINNING":"",c.morphTargets?"#define USE_MORPHTARGETS":"",c.morphNormals?"#define USE_MORPHNORMALS":"",c.perPixel?"#define PHONG_PER_PIXEL":"",
  10307. c.wrapAround?"#define WRAP_AROUND":"",c.doubleSided?"#define DOUBLE_SIDED":"",c.shadowMapEnabled?"#define USE_SHADOWMAP":"",c.shadowMapSoft?"#define SHADOWMAP_SOFT":"",c.shadowMapDebug?"#define SHADOWMAP_DEBUG":"",c.shadowMapCascade?"#define SHADOWMAP_CASCADE":"",c.sizeAttenuation?"#define USE_SIZEATTENUATION":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nattribute vec2 uv2;\n#ifdef USE_COLOR\nattribute vec3 color;\n#endif\n#ifdef USE_MORPHTARGETS\nattribute vec3 morphTarget0;\nattribute vec3 morphTarget1;\nattribute vec3 morphTarget2;\nattribute vec3 morphTarget3;\n#ifdef USE_MORPHNORMALS\nattribute vec3 morphNormal0;\nattribute vec3 morphNormal1;\nattribute vec3 morphNormal2;\nattribute vec3 morphNormal3;\n#else\nattribute vec3 morphTarget4;\nattribute vec3 morphTarget5;\nattribute vec3 morphTarget6;\nattribute vec3 morphTarget7;\n#endif\n#endif\n#ifdef USE_SKINNING\nattribute vec4 skinVertexA;\nattribute vec4 skinVertexB;\nattribute vec4 skinIndex;\nattribute vec4 skinWeight;\n#endif\n"].join("\n");
  10308. k=["precision "+G+" float;","#define MAX_DIR_LIGHTS "+c.maxDirLights,"#define MAX_POINT_LIGHTS "+c.maxPointLights,"#define MAX_SPOT_LIGHTS "+c.maxSpotLights,"#define MAX_SHADOWS "+c.maxShadows,c.alphaTest?"#define ALPHATEST "+c.alphaTest:"",E.gammaInput?"#define GAMMA_INPUT":"",E.gammaOutput?"#define GAMMA_OUTPUT":"",E.physicallyBasedShading?"#define PHYSICALLY_BASED_SHADING":"",c.useFog&&c.fog?"#define USE_FOG":"",c.useFog&&c.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",c.map?"#define USE_MAP":
  10309. "",c.envMap?"#define USE_ENVMAP":"",c.lightMap?"#define USE_LIGHTMAP":"",c.vertexColors?"#define USE_COLOR":"",c.metal?"#define METAL":"",c.perPixel?"#define PHONG_PER_PIXEL":"",c.wrapAround?"#define WRAP_AROUND":"",c.doubleSided?"#define DOUBLE_SIDED":"",c.shadowMapEnabled?"#define USE_SHADOWMAP":"",c.shadowMapSoft?"#define SHADOWMAP_SOFT":"",c.shadowMapDebug?"#define SHADOWMAP_DEBUG":"",c.shadowMapCascade?"#define SHADOWMAP_CASCADE":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");
  10310. e.attachShader(s,q("fragment",k+n));e.attachShader(s,q("vertex",d+j));e.linkProgram(s);e.getProgramParameter(s,e.LINK_STATUS)||console.error("Could not initialise shader\nVALIDATE_STATUS: "+e.getProgramParameter(s,e.VALIDATE_STATUS)+", gl error ["+e.getError()+"]");s.uniforms={};s.attributes={};var u,d=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","boneGlobalMatrices","morphTargetInfluences"];for(u in i)d.push(u);u=d;d=0;for(i=u.length;d<i;d++){n=
  10311. u[d];s.uniforms[n]=e.getUniformLocation(s,n)}d=["position","normal","uv","uv2","tangent","color","skinVertexA","skinVertexB","skinIndex","skinWeight"];for(u=0;u<c.maxMorphTargets;u++)d.push("morphTarget"+u);for(u=0;u<c.maxMorphNormals;u++)d.push("morphNormal"+u);for(p in b)d.push(p);p=d;u=0;for(b=p.length;u<b;u++){c=p[u];s.attributes[c]=e.getAttribLocation(s,c)}s.id=Ba.length;Ba.push({program:s,code:h});E.info.memory.programs=Ba.length;p=s}a.program=p;p=a.program.attributes;p.position>=0&&e.enableVertexAttribArray(p.position);
  10312. p.color>=0&&e.enableVertexAttribArray(p.color);p.normal>=0&&e.enableVertexAttribArray(p.normal);p.tangent>=0&&e.enableVertexAttribArray(p.tangent);if(a.skinning&&p.skinVertexA>=0&&p.skinVertexB>=0&&p.skinIndex>=0&&p.skinWeight>=0){e.enableVertexAttribArray(p.skinVertexA);e.enableVertexAttribArray(p.skinVertexB);e.enableVertexAttribArray(p.skinIndex);e.enableVertexAttribArray(p.skinWeight)}if(a.attributes)for(g in a.attributes)p[g]!==void 0&&p[g]>=0&&e.enableVertexAttribArray(p[g]);if(a.morphTargets){a.numSupportedMorphTargets=
  10313. 0;s="morphTarget";for(g=0;g<this.maxMorphTargets;g++){u=s+g;if(p[u]>=0){e.enableVertexAttribArray(p[u]);a.numSupportedMorphTargets++}}}if(a.morphNormals){a.numSupportedMorphNormals=0;s="morphNormal";for(g=0;g<this.maxMorphNormals;g++){u=s+g;if(p[u]>=0){e.enableVertexAttribArray(p[u]);a.numSupportedMorphNormals++}}}a.uniformsList=[];for(f in a.uniforms)a.uniformsList.push([a.uniforms[f],f])};this.setFaceCulling=function(a,b){if(a){!b||b==="ccw"?e.frontFace(e.CCW):e.frontFace(e.CW);a==="back"?e.cullFace(e.BACK):
  10314. a==="front"?e.cullFace(e.FRONT):e.cullFace(e.FRONT_AND_BACK);e.enable(e.CULL_FACE)}else e.disable(e.CULL_FACE)};this.setObjectFaces=function(a){if(ra!==a.doubleSided){a.doubleSided?e.disable(e.CULL_FACE):e.enable(e.CULL_FACE);ra=a.doubleSided}if(L!==a.flipSided){a.flipSided?e.frontFace(e.CW):e.frontFace(e.CCW);L=a.flipSided}};this.setDepthTest=function(a){if(Oa!==a){a?e.enable(e.DEPTH_TEST):e.disable(e.DEPTH_TEST);Oa=a}};this.setDepthWrite=function(a){if(Fa!==a){e.depthMask(a);Fa=a}};this.setBlending=
  10315. function(a,b,c,d){if(a!==Aa){switch(a){case THREE.NoBlending:e.disable(e.BLEND);break;case THREE.AdditiveBlending:e.enable(e.BLEND);e.blendEquation(e.FUNC_ADD);e.blendFunc(e.SRC_ALPHA,e.ONE);break;case THREE.SubtractiveBlending:e.enable(e.BLEND);e.blendEquation(e.FUNC_ADD);e.blendFunc(e.ZERO,e.ONE_MINUS_SRC_COLOR);break;case THREE.MultiplyBlending:e.enable(e.BLEND);e.blendEquation(e.FUNC_ADD);e.blendFunc(e.ZERO,e.SRC_COLOR);break;case THREE.CustomBlending:e.enable(e.BLEND);break;default:e.enable(e.BLEND);
  10316. e.blendEquationSeparate(e.FUNC_ADD,e.FUNC_ADD);e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)}Aa=a}if(a===THREE.CustomBlending){if(b!==Ca){e.blendEquation(J(b));Ca=b}if(c!==Na||d!==Ua){e.blendFunc(J(c),J(d));Na=c;Ua=d}}else Ua=Na=Ca=null};this.setTexture=function(a,b){if(a.needsUpdate){if(!a.__webglInit){a.__webglInit=true;a.__webglTexture=e.createTexture();E.info.memory.textures++}e.activeTexture(e.TEXTURE0+b);e.bindTexture(e.TEXTURE_2D,a.__webglTexture);e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,
  10317. a.premultiplyAlpha);var c=a.image,d=(c.width&c.width-1)===0&&(c.height&c.height-1)===0,f=J(a.format),g=J(a.type);I(e.TEXTURE_2D,a,d);a instanceof THREE.DataTexture?e.texImage2D(e.TEXTURE_2D,0,f,c.width,c.height,0,f,g,c.data):e.texImage2D(e.TEXTURE_2D,0,f,f,g,a.image);a.generateMipmaps&&d&&e.generateMipmap(e.TEXTURE_2D);a.needsUpdate=false;if(a.onUpdate)a.onUpdate()}else{e.activeTexture(e.TEXTURE0+b);e.bindTexture(e.TEXTURE_2D,a.__webglTexture)}};this.setRenderTarget=function(a){var b=a instanceof
  10318. THREE.WebGLRenderTargetCube;if(a&&!a.__webglFramebuffer){if(a.depthBuffer===void 0)a.depthBuffer=true;if(a.stencilBuffer===void 0)a.stencilBuffer=true;a.__webglTexture=e.createTexture();var c=(a.width&a.width-1)===0&&(a.height&a.height-1)===0,d=J(a.format),f=J(a.type);if(b){a.__webglFramebuffer=[];a.__webglRenderbuffer=[];e.bindTexture(e.TEXTURE_CUBE_MAP,a.__webglTexture);I(e.TEXTURE_CUBE_MAP,a,c);for(var g=0;g<6;g++){a.__webglFramebuffer[g]=e.createFramebuffer();a.__webglRenderbuffer[g]=e.createRenderbuffer();
  10319. e.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+g,0,d,a.width,a.height,0,d,f,null);var h=a,i=e.TEXTURE_CUBE_MAP_POSITIVE_X+g;e.bindFramebuffer(e.FRAMEBUFFER,a.__webglFramebuffer[g]);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,i,h.__webglTexture,0);B(a.__webglRenderbuffer[g],a)}c&&e.generateMipmap(e.TEXTURE_CUBE_MAP)}else{a.__webglFramebuffer=e.createFramebuffer();a.__webglRenderbuffer=e.createRenderbuffer();e.bindTexture(e.TEXTURE_2D,a.__webglTexture);I(e.TEXTURE_2D,a,c);e.texImage2D(e.TEXTURE_2D,
  10320. 0,d,a.width,a.height,0,d,f,null);d=e.TEXTURE_2D;e.bindFramebuffer(e.FRAMEBUFFER,a.__webglFramebuffer);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,d,a.__webglTexture,0);B(a.__webglRenderbuffer,a);c&&e.generateMipmap(e.TEXTURE_2D)}b?e.bindTexture(e.TEXTURE_CUBE_MAP,null):e.bindTexture(e.TEXTURE_2D,null);e.bindRenderbuffer(e.RENDERBUFFER,null);e.bindFramebuffer(e.FRAMEBUFFER,null)}if(a){b=b?a.__webglFramebuffer[a.activeCubeFace]:a.__webglFramebuffer;c=a.width;a=a.height;f=d=0}else{b=null;
  10321. c=Hb;a=ac;d=Ob;f=Yb}if(b!==D){e.bindFramebuffer(e.FRAMEBUFFER,b);e.viewport(d,f,c,a);D=b}sc=c;Zb=a};this.shadowMapPlugin=new THREE.ShadowMapPlugin;this.addPrePlugin(this.shadowMapPlugin);this.addPostPlugin(new THREE.SpritePlugin);this.addPostPlugin(new THREE.LensFlarePlugin)};
  10322. THREE.WebGLRenderTarget=function(a,b,c){this.width=a;this.height=b;c=c||{};this.wrapS=c.wrapS!==void 0?c.wrapS:THREE.ClampToEdgeWrapping;this.wrapT=c.wrapT!==void 0?c.wrapT:THREE.ClampToEdgeWrapping;this.magFilter=c.magFilter!==void 0?c.magFilter:THREE.LinearFilter;this.minFilter=c.minFilter!==void 0?c.minFilter:THREE.LinearMipMapLinearFilter;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.format=c.format!==void 0?c.format:THREE.RGBAFormat;this.type=c.type!==void 0?c.type:
  10323. THREE.UnsignedByteType;this.depthBuffer=c.depthBuffer!==void 0?c.depthBuffer:true;this.stencilBuffer=c.stencilBuffer!==void 0?c.stencilBuffer:true;this.generateMipmaps=true};
  10324. THREE.WebGLRenderTarget.prototype.clone=function(){var a=new THREE.WebGLRenderTarget(this.width,this.height);a.wrapS=this.wrapS;a.wrapT=this.wrapT;a.magFilter=this.magFilter;a.minFilter=this.minFilter;a.offset.copy(this.offset);a.repeat.copy(this.repeat);a.format=this.format;a.type=this.type;a.depthBuffer=this.depthBuffer;a.stencilBuffer=this.stencilBuffer;return a};THREE.WebGLRenderTargetCube=function(a,b,c){THREE.WebGLRenderTarget.call(this,a,b,c);this.activeCubeFace=0};
  10325. THREE.WebGLRenderTargetCube.prototype=new THREE.WebGLRenderTarget;THREE.WebGLRenderTargetCube.prototype.constructor=THREE.WebGLRenderTargetCube;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)};
  10326. 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};
  10327. 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};
  10328. 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};
  10329. THREE.BufferGeometry=function(){this.id=THREE.GeometryCount++;this.vertexColorArray=this.vertexUvArray=this.vertexNormalArray=this.vertexPositionArray=this.vertexIndexArray=this.vertexColorBuffer=this.vertexUvBuffer=this.vertexNormalBuffer=this.vertexPositionBuffer=this.vertexIndexBuffer=null;this.dynamic=false;this.boundingSphere=this.boundingBox=null;this.morphTargets=[]};THREE.BufferGeometry.prototype={constructor:THREE.BufferGeometry,computeBoundingBox:function(){},computeBoundingSphere:function(){}};
  10330. THREE.Gyroscope=function(){THREE.Object3D.call(this)};THREE.Gyroscope.prototype=new THREE.Object3D;THREE.Gyroscope.prototype.constructor=THREE.Gyroscope;
  10331. THREE.Gyroscope.prototype.updateMatrixWorld=function(a){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||a){if(this.parent){this.matrixWorld.multiply(this.parent.matrixWorld,this.matrix);this.matrixWorld.decompose(this.translationWorld,this.rotationWorld,this.scaleWorld);this.matrix.decompose(this.translationObject,this.rotationObject,this.scaleObject);this.matrixWorld.compose(this.translationWorld,this.rotationObject,this.scaleWorld)}else this.matrixWorld.copy(this.matrix);
  10332. this.matrixWorldNeedsUpdate=false;a=true}for(var b=0,c=this.children.length;b<c;b++)this.children[b].updateMatrixWorld(a)};THREE.Gyroscope.prototype.translationWorld=new THREE.Vector3;THREE.Gyroscope.prototype.translationObject=new THREE.Vector3;THREE.Gyroscope.prototype.rotationWorld=new THREE.Quaternion;THREE.Gyroscope.prototype.rotationObject=new THREE.Quaternion;THREE.Gyroscope.prototype.scaleWorld=new THREE.Vector3;THREE.Gyroscope.prototype.scaleObject=new THREE.Vector3;
  10333. THREE.CameraHelper=function(a){function b(a,b,d){c(a,d);c(b,d)}function c(a,b){d.lineGeometry.vertices.push(new THREE.Vector3);d.lineGeometry.colors.push(new THREE.Color(b));d.pointMap[a]===void 0&&(d.pointMap[a]=[]);d.pointMap[a].push(d.lineGeometry.vertices.length-1)}THREE.Object3D.call(this);var d=this;this.lineGeometry=new THREE.Geometry;this.lineMaterial=new THREE.LineBasicMaterial({color:16777215,vertexColors:THREE.FaceColors});this.pointMap={};b("n1","n2",16755200);b("n2","n4",16755200);b("n4",
  10334. "n3",16755200);b("n3","n1",16755200);b("f1","f2",16755200);b("f2","f4",16755200);b("f4","f3",16755200);b("f3","f1",16755200);b("n1","f1",16755200);b("n2","f2",16755200);b("n3","f3",16755200);b("n4","f4",16755200);b("p","n1",16711680);b("p","n2",16711680);b("p","n3",16711680);b("p","n4",16711680);b("u1","u2",43775);b("u2","u3",43775);b("u3","u1",43775);b("c","t",16777215);b("p","c",3355443);b("cn1","cn2",3355443);b("cn3","cn4",3355443);b("cf1","cf2",3355443);b("cf3","cf4",3355443);this.camera=a;this.update(a);
  10335. this.lines=new THREE.Line(this.lineGeometry,this.lineMaterial,THREE.LinePieces);this.add(this.lines)};THREE.CameraHelper.prototype=new THREE.Object3D;THREE.CameraHelper.prototype.constructor=THREE.CameraHelper;
  10336. THREE.CameraHelper.prototype.update=function(){function a(a,d,f,g){THREE.CameraHelper.__v.set(d,f,g);THREE.CameraHelper.__projector.unprojectVector(THREE.CameraHelper.__v,THREE.CameraHelper.__c);a=b.pointMap[a];if(a!==void 0){d=0;for(f=a.length;d<f;d++)b.lineGeometry.vertices[a[d]].copy(THREE.CameraHelper.__v)}}var b=this;THREE.CameraHelper.__c.projectionMatrix.copy(this.camera.projectionMatrix);a("c",0,0,-1);a("t",0,0,1);a("n1",-1,-1,-1);a("n2",1,-1,-1);a("n3",-1,1,-1);a("n4",1,1,-1);a("f1",-1,-1,
  10337. 1);a("f2",1,-1,1);a("f3",-1,1,1);a("f4",1,1,1);a("u1",0.7,1.1,-1);a("u2",-0.7,1.1,-1);a("u3",0,2,-1);a("cf1",-1,0,1);a("cf2",1,0,1);a("cf3",0,-1,1);a("cf4",0,1,1);a("cn1",-1,0,-1);a("cn2",1,0,-1);a("cn3",0,-1,-1);a("cn4",0,1,-1);this.lineGeometry.verticesNeedUpdate=true};THREE.CameraHelper.__projector=new THREE.Projector;THREE.CameraHelper.__v=new THREE.Vector3;THREE.CameraHelper.__c=new THREE.Camera;
  10338. THREE.LensFlare=function(a,b,c,d,f){THREE.Object3D.call(this);this.lensFlares=[];this.positionScreen=new THREE.Vector3;this.customUpdateCallback=void 0;a!==void 0&&this.add(a,b,c,d,f)};THREE.LensFlare.prototype=new THREE.Object3D;THREE.LensFlare.prototype.constructor=THREE.LensFlare;THREE.LensFlare.prototype.supr=THREE.Object3D.prototype;
  10339. THREE.LensFlare.prototype.add=function(a,b,c,d,f,g){b===void 0&&(b=-1);c===void 0&&(c=0);g===void 0&&(g=1);f===void 0&&(f=new THREE.Color(16777215));if(d===void 0)d=THREE.NormalBlending;c=Math.min(c,Math.max(0,c));this.lensFlares.push({texture:a,size:b,distance:c,x:0,y:0,z:0,scale:1,rotation:1,opacity:g,color:f,blending:d})};
  10340. THREE.LensFlare.prototype.updateLensFlares=function(){var a,b=this.lensFlares.length,c,d=-this.positionScreen.x*2,f=-this.positionScreen.y*2;for(a=0;a<b;a++){c=this.lensFlares[a];c.x=this.positionScreen.x+d*c.distance;c.y=this.positionScreen.y+f*c.distance;c.wantedRotation=c.x*Math.PI*0.25;c.rotation=c.rotation+(c.wantedRotation-c.rotation)*0.25}};THREE.ImmediateRenderObject=function(){THREE.Object3D.call(this);this.render=function(){}};THREE.ImmediateRenderObject.prototype=new THREE.Object3D;
  10341. THREE.ImmediateRenderObject.prototype.constructor=THREE.ImmediateRenderObject;
  10342. THREE.LensFlarePlugin=function(){function a(a){var c=b.createProgram(),d=b.createShader(b.FRAGMENT_SHADER),f=b.createShader(b.VERTEX_SHADER);b.shaderSource(d,a.fragmentShader);b.shaderSource(f,a.vertexShader);b.compileShader(d);b.compileShader(f);b.attachShader(c,d);b.attachShader(c,f);b.linkProgram(c);return c}var b,c,d,f,g,h,l,m,j,i,o,k,u;this.init=function(r){b=r.context;c=r;d=new Float32Array(16);f=new Uint16Array(6);r=0;d[r++]=-1;d[r++]=-1;d[r++]=0;d[r++]=0;d[r++]=1;d[r++]=-1;d[r++]=1;d[r++]=
  10343. 0;d[r++]=1;d[r++]=1;d[r++]=1;d[r++]=1;d[r++]=-1;d[r++]=1;d[r++]=0;d[r++]=1;r=0;f[r++]=0;f[r++]=1;f[r++]=2;f[r++]=0;f[r++]=2;f[r++]=3;g=b.createBuffer();h=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,g);b.bufferData(b.ARRAY_BUFFER,d,b.STATIC_DRAW);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,h);b.bufferData(b.ELEMENT_ARRAY_BUFFER,f,b.STATIC_DRAW);l=b.createTexture();m=b.createTexture();b.bindTexture(b.TEXTURE_2D,l);b.texImage2D(b.TEXTURE_2D,0,b.RGB,16,16,0,b.RGB,b.UNSIGNED_BYTE,null);b.texParameteri(b.TEXTURE_2D,
  10344. b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.NEAREST);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.NEAREST);b.bindTexture(b.TEXTURE_2D,m);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,16,16,0,b.RGBA,b.UNSIGNED_BYTE,null);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.NEAREST);
  10345. b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.NEAREST);if(b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)<=0){j=false;i=a(THREE.ShaderFlares.lensFlare)}else{j=true;i=a(THREE.ShaderFlares.lensFlareVertexTexture)}o={};k={};o.vertex=b.getAttribLocation(i,"position");o.uv=b.getAttribLocation(i,"uv");k.renderType=b.getUniformLocation(i,"renderType");k.map=b.getUniformLocation(i,"map");k.occlusionMap=b.getUniformLocation(i,"occlusionMap");k.opacity=b.getUniformLocation(i,"opacity");k.color=b.getUniformLocation(i,
  10346. "color");k.scale=b.getUniformLocation(i,"scale");k.rotation=b.getUniformLocation(i,"rotation");k.screenPosition=b.getUniformLocation(i,"screenPosition");u=false};this.render=function(a,d,f,w){var a=a.__webglFlares,q=a.length;if(q){var I=new THREE.Vector3,B=w/f,s=f*0.5,J=w*0.5,C=16/w,G=new THREE.Vector2(C*B,C),F=new THREE.Vector3(1,1,0),P=new THREE.Vector2(1,1),Q=k,C=o;b.useProgram(i);if(!u){b.enableVertexAttribArray(o.vertex);b.enableVertexAttribArray(o.uv);u=true}b.uniform1i(Q.occlusionMap,0);b.uniform1i(Q.map,
  10347. 1);b.bindBuffer(b.ARRAY_BUFFER,g);b.vertexAttribPointer(C.vertex,2,b.FLOAT,false,16,0);b.vertexAttribPointer(C.uv,2,b.FLOAT,false,16,8);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,h);b.disable(b.CULL_FACE);b.depthMask(false);var T,Z,R,z,H;for(T=0;T<q;T++){C=16/w;G.set(C*B,C);z=a[T];I.set(z.matrixWorld.elements[12],z.matrixWorld.elements[13],z.matrixWorld.elements[14]);d.matrixWorldInverse.multiplyVector3(I);d.projectionMatrix.multiplyVector3(I);F.copy(I);P.x=F.x*s+s;P.y=F.y*J+J;if(j||P.x>0&&P.x<f&&P.y>0&&
  10348. P.y<w){b.activeTexture(b.TEXTURE1);b.bindTexture(b.TEXTURE_2D,l);b.copyTexImage2D(b.TEXTURE_2D,0,b.RGB,P.x-8,P.y-8,16,16,0);b.uniform1i(Q.renderType,0);b.uniform2f(Q.scale,G.x,G.y);b.uniform3f(Q.screenPosition,F.x,F.y,F.z);b.disable(b.BLEND);b.enable(b.DEPTH_TEST);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0);b.activeTexture(b.TEXTURE0);b.bindTexture(b.TEXTURE_2D,m);b.copyTexImage2D(b.TEXTURE_2D,0,b.RGBA,P.x-8,P.y-8,16,16,0);b.uniform1i(Q.renderType,1);b.disable(b.DEPTH_TEST);b.activeTexture(b.TEXTURE1);
  10349. b.bindTexture(b.TEXTURE_2D,l);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0);z.positionScreen.copy(F);z.customUpdateCallback?z.customUpdateCallback(z):z.updateLensFlares();b.uniform1i(Q.renderType,2);b.enable(b.BLEND);Z=0;for(R=z.lensFlares.length;Z<R;Z++){H=z.lensFlares[Z];if(H.opacity>0.001&&H.scale>0.001){F.x=H.x;F.y=H.y;F.z=H.z;C=H.size*H.scale/w;G.x=C*B;G.y=C;b.uniform3f(Q.screenPosition,F.x,F.y,F.z);b.uniform2f(Q.scale,G.x,G.y);b.uniform1f(Q.rotation,H.rotation);b.uniform1f(Q.opacity,H.opacity);
  10350. b.uniform3f(Q.color,H.color.r,H.color.g,H.color.b);c.setBlending(H.blending,H.blendEquation,H.blendSrc,H.blendDst);c.setTexture(H.texture,1);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0)}}}}b.enable(b.CULL_FACE);b.enable(b.DEPTH_TEST);b.depthMask(true)}}};
  10351. THREE.ShadowMapPlugin=function(){var a,b,c,d,f=new THREE.Frustum,g=new THREE.Matrix4,h=new THREE.Vector3,l=new THREE.Vector3;this.init=function(f){a=f.context;b=f;var f=THREE.ShaderLib.depthRGBA,g=THREE.UniformsUtils.clone(f.uniforms);c=new THREE.ShaderMaterial({fragmentShader:f.fragmentShader,vertexShader:f.vertexShader,uniforms:g});d=new THREE.ShaderMaterial({fragmentShader:f.fragmentShader,vertexShader:f.vertexShader,uniforms:g,morphTargets:true});c._shadowPass=true;d._shadowPass=true};this.render=
  10352. function(a,c){b.shadowMapEnabled&&b.shadowMapAutoUpdate&&this.update(a,c)};this.update=function(m,j){var i,o,k,u,r,n,p,w,q,I=[];u=0;a.clearColor(1,1,1,1);a.disable(a.BLEND);a.enable(a.CULL_FACE);b.shadowMapCullFrontFaces?a.cullFace(a.FRONT):a.cullFace(a.BACK);b.setDepthTest(true);i=0;for(o=m.__lights.length;i<o;i++){k=m.__lights[i];if(k.castShadow)if(k instanceof THREE.DirectionalLight&&k.shadowCascade)for(r=0;r<k.shadowCascadeCount;r++){var B;if(k.shadowCascadeArray[r])B=k.shadowCascadeArray[r];
  10353. else{q=k;p=r;B=new THREE.DirectionalLight;B.isVirtual=true;B.onlyShadow=true;B.castShadow=true;B.shadowCameraNear=q.shadowCameraNear;B.shadowCameraFar=q.shadowCameraFar;B.shadowCameraLeft=q.shadowCameraLeft;B.shadowCameraRight=q.shadowCameraRight;B.shadowCameraBottom=q.shadowCameraBottom;B.shadowCameraTop=q.shadowCameraTop;B.shadowCameraVisible=q.shadowCameraVisible;B.shadowDarkness=q.shadowDarkness;B.shadowBias=q.shadowCascadeBias[p];B.shadowMapWidth=q.shadowCascadeWidth[p];B.shadowMapHeight=q.shadowCascadeHeight[p];
  10354. B.pointsWorld=[];B.pointsFrustum=[];w=B.pointsWorld;n=B.pointsFrustum;for(var s=0;s<8;s++){w[s]=new THREE.Vector3;n[s]=new THREE.Vector3}w=q.shadowCascadeNearZ[p];q=q.shadowCascadeFarZ[p];n[0].set(-1,-1,w);n[1].set(1,-1,w);n[2].set(-1,1,w);n[3].set(1,1,w);n[4].set(-1,-1,q);n[5].set(1,-1,q);n[6].set(-1,1,q);n[7].set(1,1,q);B.originalCamera=j;n=new THREE.Gyroscope;n.position=k.shadowCascadeOffset;n.add(B);n.add(B.target);j.add(n);k.shadowCascadeArray[r]=B;console.log("Created virtualLight",B)}p=k;w=
  10355. r;q=p.shadowCascadeArray[w];q.position.copy(p.position);q.target.position.copy(p.target.position);q.lookAt(q.target);q.shadowCameraVisible=p.shadowCameraVisible;q.shadowDarkness=p.shadowDarkness;q.shadowBias=p.shadowCascadeBias[w];n=p.shadowCascadeNearZ[w];p=p.shadowCascadeFarZ[w];q=q.pointsFrustum;q[0].z=n;q[1].z=n;q[2].z=n;q[3].z=n;q[4].z=p;q[5].z=p;q[6].z=p;q[7].z=p;I[u]=B;u++}else{I[u]=k;u++}}i=0;for(o=I.length;i<o;i++){k=I[i];if(!k.shadowMap){k.shadowMap=new THREE.WebGLRenderTarget(k.shadowMapWidth,
  10356. k.shadowMapHeight,{minFilter:THREE.LinearFilter,magFilter:THREE.LinearFilter,format:THREE.RGBAFormat});k.shadowMapSize=new THREE.Vector2(k.shadowMapWidth,k.shadowMapHeight);k.shadowMatrix=new THREE.Matrix4}if(!k.shadowCamera){if(k instanceof THREE.SpotLight)k.shadowCamera=new THREE.PerspectiveCamera(k.shadowCameraFov,k.shadowMapWidth/k.shadowMapHeight,k.shadowCameraNear,k.shadowCameraFar);else if(k instanceof THREE.DirectionalLight)k.shadowCamera=new THREE.OrthographicCamera(k.shadowCameraLeft,k.shadowCameraRight,
  10357. k.shadowCameraTop,k.shadowCameraBottom,k.shadowCameraNear,k.shadowCameraFar);else{console.error("Unsupported light type for shadow");continue}m.add(k.shadowCamera);b.autoUpdateScene&&m.updateMatrixWorld()}if(k.shadowCameraVisible&&!k.cameraHelper){k.cameraHelper=new THREE.CameraHelper(k.shadowCamera);k.shadowCamera.add(k.cameraHelper)}if(k.isVirtual&&B.originalCamera==j){r=j;u=k.shadowCamera;n=k.pointsFrustum;q=k.pointsWorld;h.set(Infinity,Infinity,Infinity);l.set(-Infinity,-Infinity,-Infinity);for(p=
  10358. 0;p<8;p++){w=q[p];w.copy(n[p]);THREE.ShadowMapPlugin.__projector.unprojectVector(w,r);u.matrixWorldInverse.multiplyVector3(w);if(w.x<h.x)h.x=w.x;if(w.x>l.x)l.x=w.x;if(w.y<h.y)h.y=w.y;if(w.y>l.y)l.y=w.y;if(w.z<h.z)h.z=w.z;if(w.z>l.z)l.z=w.z}u.left=h.x;u.right=l.x;u.top=l.y;u.bottom=h.y;u.updateProjectionMatrix()}u=k.shadowMap;n=k.shadowMatrix;r=k.shadowCamera;r.position.copy(k.matrixWorld.getPosition());r.lookAt(k.target.matrixWorld.getPosition());r.updateMatrixWorld();r.matrixWorldInverse.getInverse(r.matrixWorld);
  10359. if(k.cameraHelper)k.cameraHelper.lines.visible=k.shadowCameraVisible;k.shadowCameraVisible&&k.cameraHelper.update();n.set(0.5,0,0,0.5,0,0.5,0,0.5,0,0,0.5,0.5,0,0,0,1);n.multiplySelf(r.projectionMatrix);n.multiplySelf(r.matrixWorldInverse);if(!r._viewMatrixArray)r._viewMatrixArray=new Float32Array(16);if(!r._projectionMatrixArray)r._projectionMatrixArray=new Float32Array(16);r.matrixWorldInverse.flattenToArray(r._viewMatrixArray);r.projectionMatrix.flattenToArray(r._projectionMatrixArray);g.multiply(r.projectionMatrix,
  10360. r.matrixWorldInverse);f.setFromMatrix(g);b.setRenderTarget(u);b.clear();q=m.__webglObjects;k=0;for(u=q.length;k<u;k++){p=q[k];n=p.object;p.render=false;if(n.visible&&n.castShadow&&(!(n instanceof THREE.Mesh)||!n.frustumCulled||f.contains(n))){n._modelViewMatrix.multiply(r.matrixWorldInverse,n.matrixWorld);p.render=true}}k=0;for(u=q.length;k<u;k++){p=q[k];if(p.render){n=p.object;p=p.buffer;w=n.customDepthMaterial?n.customDepthMaterial:n.geometry.morphTargets.length?d:c;p instanceof THREE.BufferGeometry?
  10361. b.renderBufferDirect(r,m.__lights,null,w,p,n):b.renderBuffer(r,m.__lights,null,w,p,n)}}q=m.__webglObjectsImmediate;k=0;for(u=q.length;k<u;k++){p=q[k];n=p.object;if(n.visible&&n.castShadow){n._modelViewMatrix.multiply(r.matrixWorldInverse,n.matrixWorld);b.renderImmediateObject(r,m.__lights,null,c,n)}}}i=b.getClearColor();o=b.getClearAlpha();a.clearColor(i.r,i.g,i.b,o);a.enable(a.BLEND);b.shadowMapCullFrontFaces&&a.cullFace(a.BACK)}};THREE.ShadowMapPlugin.__projector=new THREE.Projector;
  10362. THREE.SpritePlugin=function(){function a(a,b){return b.z-a.z}var b,c,d,f,g,h,l,m,j,i;this.init=function(a){b=a.context;c=a;d=new Float32Array(16);f=new Uint16Array(6);a=0;d[a++]=-1;d[a++]=-1;d[a++]=0;d[a++]=1;d[a++]=1;d[a++]=-1;d[a++]=1;d[a++]=1;d[a++]=1;d[a++]=1;d[a++]=1;d[a++]=0;d[a++]=-1;d[a++]=1;d[a++]=0;a=d[a++]=0;f[a++]=0;f[a++]=1;f[a++]=2;f[a++]=0;f[a++]=2;f[a++]=3;g=b.createBuffer();h=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,g);b.bufferData(b.ARRAY_BUFFER,d,b.STATIC_DRAW);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,
  10363. h);b.bufferData(b.ELEMENT_ARRAY_BUFFER,f,b.STATIC_DRAW);var a=THREE.ShaderSprite.sprite,k=b.createProgram(),u=b.createShader(b.FRAGMENT_SHADER),r=b.createShader(b.VERTEX_SHADER);b.shaderSource(u,a.fragmentShader);b.shaderSource(r,a.vertexShader);b.compileShader(u);b.compileShader(r);b.attachShader(k,u);b.attachShader(k,r);b.linkProgram(k);l=k;m={};j={};m.position=b.getAttribLocation(l,"position");m.uv=b.getAttribLocation(l,"uv");j.uvOffset=b.getUniformLocation(l,"uvOffset");j.uvScale=b.getUniformLocation(l,
  10364. "uvScale");j.rotation=b.getUniformLocation(l,"rotation");j.scale=b.getUniformLocation(l,"scale");j.alignment=b.getUniformLocation(l,"alignment");j.color=b.getUniformLocation(l,"color");j.map=b.getUniformLocation(l,"map");j.opacity=b.getUniformLocation(l,"opacity");j.useScreenCoordinates=b.getUniformLocation(l,"useScreenCoordinates");j.affectedByDistance=b.getUniformLocation(l,"affectedByDistance");j.screenPosition=b.getUniformLocation(l,"screenPosition");j.modelViewMatrix=b.getUniformLocation(l,"modelViewMatrix");
  10365. j.projectionMatrix=b.getUniformLocation(l,"projectionMatrix");i=false};this.render=function(d,f,u,r){var d=d.__webglSprites,n=d.length;if(n){var p=m,w=j,q=r/u,u=u*0.5,I=r*0.5,B=true;b.useProgram(l);if(!i){b.enableVertexAttribArray(p.position);b.enableVertexAttribArray(p.uv);i=true}b.disable(b.CULL_FACE);b.enable(b.BLEND);b.depthMask(true);b.bindBuffer(b.ARRAY_BUFFER,g);b.vertexAttribPointer(p.position,2,b.FLOAT,false,16,0);b.vertexAttribPointer(p.uv,2,b.FLOAT,false,16,8);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,
  10366. h);b.uniformMatrix4fv(w.projectionMatrix,false,f._projectionMatrixArray);b.activeTexture(b.TEXTURE0);b.uniform1i(w.map,0);for(var s,J=[],p=0;p<n;p++){s=d[p];if(s.visible&&s.opacity!==0)if(s.useScreenCoordinates)s.z=-s.position.z;else{s._modelViewMatrix.multiply(f.matrixWorldInverse,s.matrixWorld);s.z=-s._modelViewMatrix.elements[14]}}d.sort(a);for(p=0;p<n;p++){s=d[p];if(s.visible&&s.opacity!==0&&s.map&&s.map.image&&s.map.image.width){if(s.useScreenCoordinates){b.uniform1i(w.useScreenCoordinates,1);
  10367. b.uniform3f(w.screenPosition,(s.position.x-u)/u,(I-s.position.y)/I,Math.max(0,Math.min(1,s.position.z)))}else{b.uniform1i(w.useScreenCoordinates,0);b.uniform1i(w.affectedByDistance,s.affectedByDistance?1:0);b.uniformMatrix4fv(w.modelViewMatrix,false,s._modelViewMatrix.elements)}f=s.map.image.width/(s.scaleByViewport?r:1);J[0]=f*q*s.scale.x;J[1]=f*s.scale.y;b.uniform2f(w.uvScale,s.uvScale.x,s.uvScale.y);b.uniform2f(w.uvOffset,s.uvOffset.x,s.uvOffset.y);b.uniform2f(w.alignment,s.alignment.x,s.alignment.y);
  10368. b.uniform1f(w.opacity,s.opacity);b.uniform3f(w.color,s.color.r,s.color.g,s.color.b);b.uniform1f(w.rotation,s.rotation);b.uniform2fv(w.scale,J);if(s.mergeWith3D&&!B){b.enable(b.DEPTH_TEST);B=true}else if(!s.mergeWith3D&&B){b.disable(b.DEPTH_TEST);B=false}c.setBlending(s.blending,s.blendEquation,s.blendSrc,s.blendDst);c.setTexture(s.map,0);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0)}}b.enable(b.CULL_FACE);b.enable(b.DEPTH_TEST);b.depthMask(true)}}};
  10369. THREE.ShaderFlares={lensFlareVertexTexture:{vertexShader:"uniform vec3 screenPosition;\nuniform vec2 scale;\nuniform float rotation;\nuniform int renderType;\nuniform sampler2D occlusionMap;\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 vUV;\nvarying float vVisibility;\nvoid main() {\nvUV = uv;\nvec2 pos = position;\nif( renderType == 2 ) {\nvec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) ) +\ntexture2D( occlusionMap, vec2( 0.5, 0.1 ) ) +\ntexture2D( occlusionMap, vec2( 0.9, 0.1 ) ) +\ntexture2D( occlusionMap, vec2( 0.9, 0.5 ) ) +\ntexture2D( occlusionMap, vec2( 0.9, 0.9 ) ) +\ntexture2D( occlusionMap, vec2( 0.5, 0.9 ) ) +\ntexture2D( occlusionMap, vec2( 0.1, 0.9 ) ) +\ntexture2D( occlusionMap, vec2( 0.1, 0.5 ) ) +\ntexture2D( occlusionMap, vec2( 0.5, 0.5 ) );\nvVisibility = ( visibility.r / 9.0 ) *\n( 1.0 - visibility.g / 9.0 ) *\n( visibility.b / 9.0 ) *\n( 1.0 - visibility.a / 9.0 );\npos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;\npos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;\n}\ngl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );\n}",fragmentShader:"precision mediump float;\nuniform sampler2D map;\nuniform float opacity;\nuniform int renderType;\nuniform vec3 color;\nvarying vec2 vUV;\nvarying float vVisibility;\nvoid main() {\nif( renderType == 0 ) {\ngl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );\n} else if( renderType == 1 ) {\ngl_FragColor = texture2D( map, vUV );\n} else {\nvec4 texture = texture2D( map, vUV );\ntexture.a *= opacity * vVisibility;\ngl_FragColor = texture;\ngl_FragColor.rgb *= color;\n}\n}"},
  10370. lensFlare:{vertexShader:"uniform vec3 screenPosition;\nuniform vec2 scale;\nuniform float rotation;\nuniform int renderType;\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 vUV;\nvoid main() {\nvUV = uv;\nvec2 pos = position;\nif( renderType == 2 ) {\npos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;\npos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;\n}\ngl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );\n}",fragmentShader:"precision mediump float;\nuniform sampler2D map;\nuniform sampler2D occlusionMap;\nuniform float opacity;\nuniform int renderType;\nuniform vec3 color;\nvarying vec2 vUV;\nvoid main() {\nif( renderType == 0 ) {\ngl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );\n} else if( renderType == 1 ) {\ngl_FragColor = texture2D( map, vUV );\n} else {\nfloat visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a +\ntexture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a +\ntexture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a +\ntexture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;\nvisibility = ( 1.0 - visibility / 4.0 );\nvec4 texture = texture2D( map, vUV );\ntexture.a *= opacity * visibility;\ngl_FragColor = texture;\ngl_FragColor.rgb *= color;\n}\n}"}};
  10371. THREE.ShaderSprite={sprite:{vertexShader:"uniform int useScreenCoordinates;\nuniform int affectedByDistance;\nuniform vec3 screenPosition;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform float rotation;\nuniform vec2 scale;\nuniform vec2 alignment;\nuniform vec2 uvOffset;\nuniform vec2 uvScale;\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 vUV;\nvoid main() {\nvUV = uvOffset + uv * uvScale;\nvec2 alignedPosition = position + alignment;\nvec2 rotatedPosition;\nrotatedPosition.x = ( cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y ) * scale.x;\nrotatedPosition.y = ( sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y ) * scale.y;\nvec4 finalPosition;\nif( useScreenCoordinates != 0 ) {\nfinalPosition = vec4( screenPosition.xy + rotatedPosition, screenPosition.z, 1.0 );\n} else {\nfinalPosition = projectionMatrix * modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\nfinalPosition.xy += rotatedPosition * ( affectedByDistance == 1 ? 1.0 : finalPosition.z );\n}\ngl_Position = finalPosition;\n}",
  10372. fragmentShader:"precision mediump float;\nuniform vec3 color;\nuniform sampler2D map;\nuniform float opacity;\nvarying vec2 vUV;\nvoid main() {\nvec4 texture = texture2D( map, vUV );\ngl_FragColor = vec4( color * texture.xyz, texture.a * opacity );\n}"}};
  10373. >>>>>>> dev
粤ICP备19079148号