three.module.js 1006 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401
  1. // Polyfills
  2. if ( Number.EPSILON === undefined ) {
  3. Number.EPSILON = Math.pow( 2, - 52 );
  4. }
  5. if ( Number.isInteger === undefined ) {
  6. // Missing in IE
  7. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  8. Number.isInteger = function ( value ) {
  9. return typeof value === 'number' && isFinite( value ) && Math.floor( value ) === value;
  10. };
  11. }
  12. //
  13. if ( Math.sign === undefined ) {
  14. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  15. Math.sign = function ( x ) {
  16. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  17. };
  18. }
  19. if ( 'name' in Function.prototype === false ) {
  20. // Missing in IE
  21. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  22. Object.defineProperty( Function.prototype, 'name', {
  23. get: function () {
  24. return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];
  25. }
  26. } );
  27. }
  28. if ( Object.assign === undefined ) {
  29. // Missing in IE
  30. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  31. ( function () {
  32. Object.assign = function ( target ) {
  33. if ( target === undefined || target === null ) {
  34. throw new TypeError( 'Cannot convert undefined or null to object' );
  35. }
  36. var output = Object( target );
  37. for ( var index = 1; index < arguments.length; index ++ ) {
  38. var source = arguments[ index ];
  39. if ( source !== undefined && source !== null ) {
  40. for ( var nextKey in source ) {
  41. if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
  42. output[ nextKey ] = source[ nextKey ];
  43. }
  44. }
  45. }
  46. }
  47. return output;
  48. };
  49. } )();
  50. }
  51. /**
  52. * https://github.com/mrdoob/eventdispatcher.js/
  53. */
  54. function EventDispatcher() {}
  55. Object.assign( EventDispatcher.prototype, {
  56. addEventListener: function ( type, listener ) {
  57. if ( this._listeners === undefined ) this._listeners = {};
  58. var listeners = this._listeners;
  59. if ( listeners[ type ] === undefined ) {
  60. listeners[ type ] = [];
  61. }
  62. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  63. listeners[ type ].push( listener );
  64. }
  65. },
  66. hasEventListener: function ( type, listener ) {
  67. if ( this._listeners === undefined ) return false;
  68. var listeners = this._listeners;
  69. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  70. },
  71. removeEventListener: function ( type, listener ) {
  72. if ( this._listeners === undefined ) return;
  73. var listeners = this._listeners;
  74. var listenerArray = listeners[ type ];
  75. if ( listenerArray !== undefined ) {
  76. var index = listenerArray.indexOf( listener );
  77. if ( index !== - 1 ) {
  78. listenerArray.splice( index, 1 );
  79. }
  80. }
  81. },
  82. dispatchEvent: function ( event ) {
  83. if ( this._listeners === undefined ) return;
  84. var listeners = this._listeners;
  85. var listenerArray = listeners[ event.type ];
  86. if ( listenerArray !== undefined ) {
  87. event.target = this;
  88. var array = listenerArray.slice( 0 );
  89. for ( var i = 0, l = array.length; i < l; i ++ ) {
  90. array[ i ].call( this, event );
  91. }
  92. }
  93. }
  94. } );
  95. var REVISION = '90dev';
  96. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  97. var CullFaceNone = 0;
  98. var CullFaceBack = 1;
  99. var CullFaceFront = 2;
  100. var CullFaceFrontBack = 3;
  101. var FrontFaceDirectionCW = 0;
  102. var FrontFaceDirectionCCW = 1;
  103. var BasicShadowMap = 0;
  104. var PCFShadowMap = 1;
  105. var PCFSoftShadowMap = 2;
  106. var FrontSide = 0;
  107. var BackSide = 1;
  108. var DoubleSide = 2;
  109. var FlatShading = 1;
  110. var SmoothShading = 2;
  111. var NoColors = 0;
  112. var FaceColors = 1;
  113. var VertexColors = 2;
  114. var NoBlending = 0;
  115. var NormalBlending = 1;
  116. var AdditiveBlending = 2;
  117. var SubtractiveBlending = 3;
  118. var MultiplyBlending = 4;
  119. var CustomBlending = 5;
  120. var AddEquation = 100;
  121. var SubtractEquation = 101;
  122. var ReverseSubtractEquation = 102;
  123. var MinEquation = 103;
  124. var MaxEquation = 104;
  125. var ZeroFactor = 200;
  126. var OneFactor = 201;
  127. var SrcColorFactor = 202;
  128. var OneMinusSrcColorFactor = 203;
  129. var SrcAlphaFactor = 204;
  130. var OneMinusSrcAlphaFactor = 205;
  131. var DstAlphaFactor = 206;
  132. var OneMinusDstAlphaFactor = 207;
  133. var DstColorFactor = 208;
  134. var OneMinusDstColorFactor = 209;
  135. var SrcAlphaSaturateFactor = 210;
  136. var NeverDepth = 0;
  137. var AlwaysDepth = 1;
  138. var LessDepth = 2;
  139. var LessEqualDepth = 3;
  140. var EqualDepth = 4;
  141. var GreaterEqualDepth = 5;
  142. var GreaterDepth = 6;
  143. var NotEqualDepth = 7;
  144. var MultiplyOperation = 0;
  145. var MixOperation = 1;
  146. var AddOperation = 2;
  147. var NoToneMapping = 0;
  148. var LinearToneMapping = 1;
  149. var ReinhardToneMapping = 2;
  150. var Uncharted2ToneMapping = 3;
  151. var CineonToneMapping = 4;
  152. var UVMapping = 300;
  153. var CubeReflectionMapping = 301;
  154. var CubeRefractionMapping = 302;
  155. var EquirectangularReflectionMapping = 303;
  156. var EquirectangularRefractionMapping = 304;
  157. var SphericalReflectionMapping = 305;
  158. var CubeUVReflectionMapping = 306;
  159. var CubeUVRefractionMapping = 307;
  160. var RepeatWrapping = 1000;
  161. var ClampToEdgeWrapping = 1001;
  162. var MirroredRepeatWrapping = 1002;
  163. var NearestFilter = 1003;
  164. var NearestMipMapNearestFilter = 1004;
  165. var NearestMipMapLinearFilter = 1005;
  166. var LinearFilter = 1006;
  167. var LinearMipMapNearestFilter = 1007;
  168. var LinearMipMapLinearFilter = 1008;
  169. var UnsignedByteType = 1009;
  170. var ByteType = 1010;
  171. var ShortType = 1011;
  172. var UnsignedShortType = 1012;
  173. var IntType = 1013;
  174. var UnsignedIntType = 1014;
  175. var FloatType = 1015;
  176. var HalfFloatType = 1016;
  177. var UnsignedShort4444Type = 1017;
  178. var UnsignedShort5551Type = 1018;
  179. var UnsignedShort565Type = 1019;
  180. var UnsignedInt248Type = 1020;
  181. var AlphaFormat = 1021;
  182. var RGBFormat = 1022;
  183. var RGBAFormat = 1023;
  184. var LuminanceFormat = 1024;
  185. var LuminanceAlphaFormat = 1025;
  186. var RGBEFormat = RGBAFormat;
  187. var DepthFormat = 1026;
  188. var DepthStencilFormat = 1027;
  189. var RGB_S3TC_DXT1_Format = 33776;
  190. var RGBA_S3TC_DXT1_Format = 33777;
  191. var RGBA_S3TC_DXT3_Format = 33778;
  192. var RGBA_S3TC_DXT5_Format = 33779;
  193. var RGB_PVRTC_4BPPV1_Format = 35840;
  194. var RGB_PVRTC_2BPPV1_Format = 35841;
  195. var RGBA_PVRTC_4BPPV1_Format = 35842;
  196. var RGBA_PVRTC_2BPPV1_Format = 35843;
  197. var RGB_ETC1_Format = 36196;
  198. var RGBA_ASTC_4x4_Format = 37808;
  199. var RGBA_ASTC_5x4_Format = 37809;
  200. var RGBA_ASTC_5x5_Format = 37810;
  201. var RGBA_ASTC_6x5_Format = 37811;
  202. var RGBA_ASTC_6x6_Format = 37812;
  203. var RGBA_ASTC_8x5_Format = 37813;
  204. var RGBA_ASTC_8x6_Format = 37814;
  205. var RGBA_ASTC_8x8_Format = 37815;
  206. var RGBA_ASTC_10x5_Format = 37816;
  207. var RGBA_ASTC_10x6_Format = 37817;
  208. var RGBA_ASTC_10x8_Format = 37818;
  209. var RGBA_ASTC_10x10_Format = 37819;
  210. var RGBA_ASTC_12x10_Format = 37820;
  211. var RGBA_ASTC_12x12_Format = 37821;
  212. var LoopOnce = 2200;
  213. var LoopRepeat = 2201;
  214. var LoopPingPong = 2202;
  215. var InterpolateDiscrete = 2300;
  216. var InterpolateLinear = 2301;
  217. var InterpolateSmooth = 2302;
  218. var ZeroCurvatureEnding = 2400;
  219. var ZeroSlopeEnding = 2401;
  220. var WrapAroundEnding = 2402;
  221. var TrianglesDrawMode = 0;
  222. var TriangleStripDrawMode = 1;
  223. var TriangleFanDrawMode = 2;
  224. var LinearEncoding = 3000;
  225. var sRGBEncoding = 3001;
  226. var GammaEncoding = 3007;
  227. var RGBEEncoding = 3002;
  228. var LogLuvEncoding = 3003;
  229. var RGBM7Encoding = 3004;
  230. var RGBM16Encoding = 3005;
  231. var RGBDEncoding = 3006;
  232. var BasicDepthPacking = 3200;
  233. var RGBADepthPacking = 3201;
  234. /**
  235. * @author alteredq / http://alteredqualia.com/
  236. * @author mrdoob / http://mrdoob.com/
  237. */
  238. var _Math = {
  239. DEG2RAD: Math.PI / 180,
  240. RAD2DEG: 180 / Math.PI,
  241. generateUUID: ( function () {
  242. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  243. var lut = [];
  244. for ( var i = 0; i < 256; i ++ ) {
  245. lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 ).toUpperCase();
  246. }
  247. return function generateUUID() {
  248. var d0 = Math.random() * 0xffffffff | 0;
  249. var d1 = Math.random() * 0xffffffff | 0;
  250. var d2 = Math.random() * 0xffffffff | 0;
  251. var d3 = Math.random() * 0xffffffff | 0;
  252. return lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + '-' +
  253. lut[ d1 & 0xff ] + lut[ d1 >> 8 & 0xff ] + '-' + lut[ d1 >> 16 & 0x0f | 0x40 ] + lut[ d1 >> 24 & 0xff ] + '-' +
  254. lut[ d2 & 0x3f | 0x80 ] + lut[ d2 >> 8 & 0xff ] + '-' + lut[ d2 >> 16 & 0xff ] + lut[ d2 >> 24 & 0xff ] +
  255. lut[ d3 & 0xff ] + lut[ d3 >> 8 & 0xff ] + lut[ d3 >> 16 & 0xff ] + lut[ d3 >> 24 & 0xff ];
  256. };
  257. } )(),
  258. clamp: function ( value, min, max ) {
  259. return Math.max( min, Math.min( max, value ) );
  260. },
  261. // compute euclidian modulo of m % n
  262. // https://en.wikipedia.org/wiki/Modulo_operation
  263. euclideanModulo: function ( n, m ) {
  264. return ( ( n % m ) + m ) % m;
  265. },
  266. // Linear mapping from range <a1, a2> to range <b1, b2>
  267. mapLinear: function ( x, a1, a2, b1, b2 ) {
  268. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  269. },
  270. // https://en.wikipedia.org/wiki/Linear_interpolation
  271. lerp: function ( x, y, t ) {
  272. return ( 1 - t ) * x + t * y;
  273. },
  274. // http://en.wikipedia.org/wiki/Smoothstep
  275. smoothstep: function ( x, min, max ) {
  276. if ( x <= min ) return 0;
  277. if ( x >= max ) return 1;
  278. x = ( x - min ) / ( max - min );
  279. return x * x * ( 3 - 2 * x );
  280. },
  281. smootherstep: function ( x, min, max ) {
  282. if ( x <= min ) return 0;
  283. if ( x >= max ) return 1;
  284. x = ( x - min ) / ( max - min );
  285. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  286. },
  287. // Random integer from <low, high> interval
  288. randInt: function ( low, high ) {
  289. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  290. },
  291. // Random float from <low, high> interval
  292. randFloat: function ( low, high ) {
  293. return low + Math.random() * ( high - low );
  294. },
  295. // Random float from <-range/2, range/2> interval
  296. randFloatSpread: function ( range ) {
  297. return range * ( 0.5 - Math.random() );
  298. },
  299. degToRad: function ( degrees ) {
  300. return degrees * _Math.DEG2RAD;
  301. },
  302. radToDeg: function ( radians ) {
  303. return radians * _Math.RAD2DEG;
  304. },
  305. isPowerOfTwo: function ( value ) {
  306. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  307. },
  308. ceilPowerOfTwo: function ( value ) {
  309. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  310. },
  311. floorPowerOfTwo: function ( value ) {
  312. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  313. }
  314. };
  315. /**
  316. * @author mrdoob / http://mrdoob.com/
  317. * @author philogb / http://blog.thejit.org/
  318. * @author egraether / http://egraether.com/
  319. * @author zz85 / http://www.lab4games.net/zz85/blog
  320. */
  321. function Vector2( x, y ) {
  322. this.x = x || 0;
  323. this.y = y || 0;
  324. }
  325. Object.defineProperties( Vector2.prototype, {
  326. "width": {
  327. get: function () {
  328. return this.x;
  329. },
  330. set: function ( value ) {
  331. this.x = value;
  332. }
  333. },
  334. "height": {
  335. get: function () {
  336. return this.y;
  337. },
  338. set: function ( value ) {
  339. this.y = value;
  340. }
  341. }
  342. } );
  343. Object.assign( Vector2.prototype, {
  344. isVector2: true,
  345. set: function ( x, y ) {
  346. this.x = x;
  347. this.y = y;
  348. return this;
  349. },
  350. setScalar: function ( scalar ) {
  351. this.x = scalar;
  352. this.y = scalar;
  353. return this;
  354. },
  355. setX: function ( x ) {
  356. this.x = x;
  357. return this;
  358. },
  359. setY: function ( y ) {
  360. this.y = y;
  361. return this;
  362. },
  363. setComponent: function ( index, value ) {
  364. switch ( index ) {
  365. case 0: this.x = value; break;
  366. case 1: this.y = value; break;
  367. default: throw new Error( 'index is out of range: ' + index );
  368. }
  369. return this;
  370. },
  371. getComponent: function ( index ) {
  372. switch ( index ) {
  373. case 0: return this.x;
  374. case 1: return this.y;
  375. default: throw new Error( 'index is out of range: ' + index );
  376. }
  377. },
  378. clone: function () {
  379. return new this.constructor( this.x, this.y );
  380. },
  381. copy: function ( v ) {
  382. this.x = v.x;
  383. this.y = v.y;
  384. return this;
  385. },
  386. add: function ( v, w ) {
  387. if ( w !== undefined ) {
  388. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  389. return this.addVectors( v, w );
  390. }
  391. this.x += v.x;
  392. this.y += v.y;
  393. return this;
  394. },
  395. addScalar: function ( s ) {
  396. this.x += s;
  397. this.y += s;
  398. return this;
  399. },
  400. addVectors: function ( a, b ) {
  401. this.x = a.x + b.x;
  402. this.y = a.y + b.y;
  403. return this;
  404. },
  405. addScaledVector: function ( v, s ) {
  406. this.x += v.x * s;
  407. this.y += v.y * s;
  408. return this;
  409. },
  410. sub: function ( v, w ) {
  411. if ( w !== undefined ) {
  412. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  413. return this.subVectors( v, w );
  414. }
  415. this.x -= v.x;
  416. this.y -= v.y;
  417. return this;
  418. },
  419. subScalar: function ( s ) {
  420. this.x -= s;
  421. this.y -= s;
  422. return this;
  423. },
  424. subVectors: function ( a, b ) {
  425. this.x = a.x - b.x;
  426. this.y = a.y - b.y;
  427. return this;
  428. },
  429. multiply: function ( v ) {
  430. this.x *= v.x;
  431. this.y *= v.y;
  432. return this;
  433. },
  434. multiplyScalar: function ( scalar ) {
  435. this.x *= scalar;
  436. this.y *= scalar;
  437. return this;
  438. },
  439. divide: function ( v ) {
  440. this.x /= v.x;
  441. this.y /= v.y;
  442. return this;
  443. },
  444. divideScalar: function ( scalar ) {
  445. return this.multiplyScalar( 1 / scalar );
  446. },
  447. applyMatrix3: function ( m ) {
  448. var x = this.x, y = this.y;
  449. var e = m.elements;
  450. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  451. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  452. return this;
  453. },
  454. min: function ( v ) {
  455. this.x = Math.min( this.x, v.x );
  456. this.y = Math.min( this.y, v.y );
  457. return this;
  458. },
  459. max: function ( v ) {
  460. this.x = Math.max( this.x, v.x );
  461. this.y = Math.max( this.y, v.y );
  462. return this;
  463. },
  464. clamp: function ( min, max ) {
  465. // assumes min < max, componentwise
  466. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  467. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  468. return this;
  469. },
  470. clampScalar: function () {
  471. var min = new Vector2();
  472. var max = new Vector2();
  473. return function clampScalar( minVal, maxVal ) {
  474. min.set( minVal, minVal );
  475. max.set( maxVal, maxVal );
  476. return this.clamp( min, max );
  477. };
  478. }(),
  479. clampLength: function ( min, max ) {
  480. var length = this.length();
  481. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  482. },
  483. floor: function () {
  484. this.x = Math.floor( this.x );
  485. this.y = Math.floor( this.y );
  486. return this;
  487. },
  488. ceil: function () {
  489. this.x = Math.ceil( this.x );
  490. this.y = Math.ceil( this.y );
  491. return this;
  492. },
  493. round: function () {
  494. this.x = Math.round( this.x );
  495. this.y = Math.round( this.y );
  496. return this;
  497. },
  498. roundToZero: function () {
  499. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  500. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  501. return this;
  502. },
  503. negate: function () {
  504. this.x = - this.x;
  505. this.y = - this.y;
  506. return this;
  507. },
  508. dot: function ( v ) {
  509. return this.x * v.x + this.y * v.y;
  510. },
  511. lengthSq: function () {
  512. return this.x * this.x + this.y * this.y;
  513. },
  514. length: function () {
  515. return Math.sqrt( this.x * this.x + this.y * this.y );
  516. },
  517. manhattanLength: function () {
  518. return Math.abs( this.x ) + Math.abs( this.y );
  519. },
  520. normalize: function () {
  521. return this.divideScalar( this.length() || 1 );
  522. },
  523. angle: function () {
  524. // computes the angle in radians with respect to the positive x-axis
  525. var angle = Math.atan2( this.y, this.x );
  526. if ( angle < 0 ) angle += 2 * Math.PI;
  527. return angle;
  528. },
  529. distanceTo: function ( v ) {
  530. return Math.sqrt( this.distanceToSquared( v ) );
  531. },
  532. distanceToSquared: function ( v ) {
  533. var dx = this.x - v.x, dy = this.y - v.y;
  534. return dx * dx + dy * dy;
  535. },
  536. manhattanDistanceTo: function ( v ) {
  537. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  538. },
  539. setLength: function ( length ) {
  540. return this.normalize().multiplyScalar( length );
  541. },
  542. lerp: function ( v, alpha ) {
  543. this.x += ( v.x - this.x ) * alpha;
  544. this.y += ( v.y - this.y ) * alpha;
  545. return this;
  546. },
  547. lerpVectors: function ( v1, v2, alpha ) {
  548. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  549. },
  550. equals: function ( v ) {
  551. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  552. },
  553. fromArray: function ( array, offset ) {
  554. if ( offset === undefined ) offset = 0;
  555. this.x = array[ offset ];
  556. this.y = array[ offset + 1 ];
  557. return this;
  558. },
  559. toArray: function ( array, offset ) {
  560. if ( array === undefined ) array = [];
  561. if ( offset === undefined ) offset = 0;
  562. array[ offset ] = this.x;
  563. array[ offset + 1 ] = this.y;
  564. return array;
  565. },
  566. fromBufferAttribute: function ( attribute, index, offset ) {
  567. if ( offset !== undefined ) {
  568. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  569. }
  570. this.x = attribute.getX( index );
  571. this.y = attribute.getY( index );
  572. return this;
  573. },
  574. rotateAround: function ( center, angle ) {
  575. var c = Math.cos( angle ), s = Math.sin( angle );
  576. var x = this.x - center.x;
  577. var y = this.y - center.y;
  578. this.x = x * c - y * s + center.x;
  579. this.y = x * s + y * c + center.y;
  580. return this;
  581. }
  582. } );
  583. /**
  584. * @author mrdoob / http://mrdoob.com/
  585. * @author supereggbert / http://www.paulbrunt.co.uk/
  586. * @author philogb / http://blog.thejit.org/
  587. * @author jordi_ros / http://plattsoft.com
  588. * @author D1plo1d / http://github.com/D1plo1d
  589. * @author alteredq / http://alteredqualia.com/
  590. * @author mikael emtinger / http://gomo.se/
  591. * @author timknip / http://www.floorplanner.com/
  592. * @author bhouston / http://clara.io
  593. * @author WestLangley / http://github.com/WestLangley
  594. */
  595. function Matrix4() {
  596. this.elements = [
  597. 1, 0, 0, 0,
  598. 0, 1, 0, 0,
  599. 0, 0, 1, 0,
  600. 0, 0, 0, 1
  601. ];
  602. if ( arguments.length > 0 ) {
  603. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  604. }
  605. }
  606. Object.assign( Matrix4.prototype, {
  607. isMatrix4: true,
  608. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  609. var te = this.elements;
  610. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  611. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  612. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  613. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  614. return this;
  615. },
  616. identity: function () {
  617. this.set(
  618. 1, 0, 0, 0,
  619. 0, 1, 0, 0,
  620. 0, 0, 1, 0,
  621. 0, 0, 0, 1
  622. );
  623. return this;
  624. },
  625. clone: function () {
  626. return new Matrix4().fromArray( this.elements );
  627. },
  628. copy: function ( m ) {
  629. var te = this.elements;
  630. var me = m.elements;
  631. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  632. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  633. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  634. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  635. return this;
  636. },
  637. copyPosition: function ( m ) {
  638. var te = this.elements, me = m.elements;
  639. te[ 12 ] = me[ 12 ];
  640. te[ 13 ] = me[ 13 ];
  641. te[ 14 ] = me[ 14 ];
  642. return this;
  643. },
  644. extractBasis: function ( xAxis, yAxis, zAxis ) {
  645. xAxis.setFromMatrixColumn( this, 0 );
  646. yAxis.setFromMatrixColumn( this, 1 );
  647. zAxis.setFromMatrixColumn( this, 2 );
  648. return this;
  649. },
  650. makeBasis: function ( xAxis, yAxis, zAxis ) {
  651. this.set(
  652. xAxis.x, yAxis.x, zAxis.x, 0,
  653. xAxis.y, yAxis.y, zAxis.y, 0,
  654. xAxis.z, yAxis.z, zAxis.z, 0,
  655. 0, 0, 0, 1
  656. );
  657. return this;
  658. },
  659. extractRotation: function () {
  660. var v1 = new Vector3();
  661. return function extractRotation( m ) {
  662. var te = this.elements;
  663. var me = m.elements;
  664. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  665. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  666. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  667. te[ 0 ] = me[ 0 ] * scaleX;
  668. te[ 1 ] = me[ 1 ] * scaleX;
  669. te[ 2 ] = me[ 2 ] * scaleX;
  670. te[ 4 ] = me[ 4 ] * scaleY;
  671. te[ 5 ] = me[ 5 ] * scaleY;
  672. te[ 6 ] = me[ 6 ] * scaleY;
  673. te[ 8 ] = me[ 8 ] * scaleZ;
  674. te[ 9 ] = me[ 9 ] * scaleZ;
  675. te[ 10 ] = me[ 10 ] * scaleZ;
  676. return this;
  677. };
  678. }(),
  679. makeRotationFromEuler: function ( euler ) {
  680. if ( ! ( euler && euler.isEuler ) ) {
  681. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  682. }
  683. var te = this.elements;
  684. var x = euler.x, y = euler.y, z = euler.z;
  685. var a = Math.cos( x ), b = Math.sin( x );
  686. var c = Math.cos( y ), d = Math.sin( y );
  687. var e = Math.cos( z ), f = Math.sin( z );
  688. if ( euler.order === 'XYZ' ) {
  689. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  690. te[ 0 ] = c * e;
  691. te[ 4 ] = - c * f;
  692. te[ 8 ] = d;
  693. te[ 1 ] = af + be * d;
  694. te[ 5 ] = ae - bf * d;
  695. te[ 9 ] = - b * c;
  696. te[ 2 ] = bf - ae * d;
  697. te[ 6 ] = be + af * d;
  698. te[ 10 ] = a * c;
  699. } else if ( euler.order === 'YXZ' ) {
  700. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  701. te[ 0 ] = ce + df * b;
  702. te[ 4 ] = de * b - cf;
  703. te[ 8 ] = a * d;
  704. te[ 1 ] = a * f;
  705. te[ 5 ] = a * e;
  706. te[ 9 ] = - b;
  707. te[ 2 ] = cf * b - de;
  708. te[ 6 ] = df + ce * b;
  709. te[ 10 ] = a * c;
  710. } else if ( euler.order === 'ZXY' ) {
  711. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  712. te[ 0 ] = ce - df * b;
  713. te[ 4 ] = - a * f;
  714. te[ 8 ] = de + cf * b;
  715. te[ 1 ] = cf + de * b;
  716. te[ 5 ] = a * e;
  717. te[ 9 ] = df - ce * b;
  718. te[ 2 ] = - a * d;
  719. te[ 6 ] = b;
  720. te[ 10 ] = a * c;
  721. } else if ( euler.order === 'ZYX' ) {
  722. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  723. te[ 0 ] = c * e;
  724. te[ 4 ] = be * d - af;
  725. te[ 8 ] = ae * d + bf;
  726. te[ 1 ] = c * f;
  727. te[ 5 ] = bf * d + ae;
  728. te[ 9 ] = af * d - be;
  729. te[ 2 ] = - d;
  730. te[ 6 ] = b * c;
  731. te[ 10 ] = a * c;
  732. } else if ( euler.order === 'YZX' ) {
  733. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  734. te[ 0 ] = c * e;
  735. te[ 4 ] = bd - ac * f;
  736. te[ 8 ] = bc * f + ad;
  737. te[ 1 ] = f;
  738. te[ 5 ] = a * e;
  739. te[ 9 ] = - b * e;
  740. te[ 2 ] = - d * e;
  741. te[ 6 ] = ad * f + bc;
  742. te[ 10 ] = ac - bd * f;
  743. } else if ( euler.order === 'XZY' ) {
  744. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  745. te[ 0 ] = c * e;
  746. te[ 4 ] = - f;
  747. te[ 8 ] = d * e;
  748. te[ 1 ] = ac * f + bd;
  749. te[ 5 ] = a * e;
  750. te[ 9 ] = ad * f - bc;
  751. te[ 2 ] = bc * f - ad;
  752. te[ 6 ] = b * e;
  753. te[ 10 ] = bd * f + ac;
  754. }
  755. // last column
  756. te[ 3 ] = 0;
  757. te[ 7 ] = 0;
  758. te[ 11 ] = 0;
  759. // bottom row
  760. te[ 12 ] = 0;
  761. te[ 13 ] = 0;
  762. te[ 14 ] = 0;
  763. te[ 15 ] = 1;
  764. return this;
  765. },
  766. makeRotationFromQuaternion: function ( q ) {
  767. var te = this.elements;
  768. var x = q._x, y = q._y, z = q._z, w = q._w;
  769. var x2 = x + x, y2 = y + y, z2 = z + z;
  770. var xx = x * x2, xy = x * y2, xz = x * z2;
  771. var yy = y * y2, yz = y * z2, zz = z * z2;
  772. var wx = w * x2, wy = w * y2, wz = w * z2;
  773. te[ 0 ] = 1 - ( yy + zz );
  774. te[ 4 ] = xy - wz;
  775. te[ 8 ] = xz + wy;
  776. te[ 1 ] = xy + wz;
  777. te[ 5 ] = 1 - ( xx + zz );
  778. te[ 9 ] = yz - wx;
  779. te[ 2 ] = xz - wy;
  780. te[ 6 ] = yz + wx;
  781. te[ 10 ] = 1 - ( xx + yy );
  782. // last column
  783. te[ 3 ] = 0;
  784. te[ 7 ] = 0;
  785. te[ 11 ] = 0;
  786. // bottom row
  787. te[ 12 ] = 0;
  788. te[ 13 ] = 0;
  789. te[ 14 ] = 0;
  790. te[ 15 ] = 1;
  791. return this;
  792. },
  793. lookAt: function () {
  794. var x = new Vector3();
  795. var y = new Vector3();
  796. var z = new Vector3();
  797. return function lookAt( eye, target, up ) {
  798. var te = this.elements;
  799. z.subVectors( eye, target );
  800. if ( z.lengthSq() === 0 ) {
  801. // eye and target are in the same position
  802. z.z = 1;
  803. }
  804. z.normalize();
  805. x.crossVectors( up, z );
  806. if ( x.lengthSq() === 0 ) {
  807. // up and z are parallel
  808. if ( Math.abs( up.z ) === 1 ) {
  809. z.x += 0.0001;
  810. } else {
  811. z.z += 0.0001;
  812. }
  813. z.normalize();
  814. x.crossVectors( up, z );
  815. }
  816. x.normalize();
  817. y.crossVectors( z, x );
  818. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  819. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  820. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  821. return this;
  822. };
  823. }(),
  824. multiply: function ( m, n ) {
  825. if ( n !== undefined ) {
  826. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  827. return this.multiplyMatrices( m, n );
  828. }
  829. return this.multiplyMatrices( this, m );
  830. },
  831. premultiply: function ( m ) {
  832. return this.multiplyMatrices( m, this );
  833. },
  834. multiplyMatrices: function ( a, b ) {
  835. var ae = a.elements;
  836. var be = b.elements;
  837. var te = this.elements;
  838. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  839. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  840. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  841. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  842. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  843. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  844. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  845. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  846. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  847. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  848. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  849. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  850. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  851. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  852. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  853. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  854. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  855. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  856. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  857. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  858. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  859. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  860. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  861. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  862. return this;
  863. },
  864. multiplyScalar: function ( s ) {
  865. var te = this.elements;
  866. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  867. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  868. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  869. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  870. return this;
  871. },
  872. applyToBufferAttribute: function () {
  873. var v1 = new Vector3();
  874. return function applyToBufferAttribute( attribute ) {
  875. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  876. v1.x = attribute.getX( i );
  877. v1.y = attribute.getY( i );
  878. v1.z = attribute.getZ( i );
  879. v1.applyMatrix4( this );
  880. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  881. }
  882. return attribute;
  883. };
  884. }(),
  885. determinant: function () {
  886. var te = this.elements;
  887. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  888. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  889. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  890. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  891. //TODO: make this more efficient
  892. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  893. return (
  894. n41 * (
  895. + n14 * n23 * n32
  896. - n13 * n24 * n32
  897. - n14 * n22 * n33
  898. + n12 * n24 * n33
  899. + n13 * n22 * n34
  900. - n12 * n23 * n34
  901. ) +
  902. n42 * (
  903. + n11 * n23 * n34
  904. - n11 * n24 * n33
  905. + n14 * n21 * n33
  906. - n13 * n21 * n34
  907. + n13 * n24 * n31
  908. - n14 * n23 * n31
  909. ) +
  910. n43 * (
  911. + n11 * n24 * n32
  912. - n11 * n22 * n34
  913. - n14 * n21 * n32
  914. + n12 * n21 * n34
  915. + n14 * n22 * n31
  916. - n12 * n24 * n31
  917. ) +
  918. n44 * (
  919. - n13 * n22 * n31
  920. - n11 * n23 * n32
  921. + n11 * n22 * n33
  922. + n13 * n21 * n32
  923. - n12 * n21 * n33
  924. + n12 * n23 * n31
  925. )
  926. );
  927. },
  928. transpose: function () {
  929. var te = this.elements;
  930. var tmp;
  931. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  932. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  933. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  934. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  935. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  936. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  937. return this;
  938. },
  939. setPosition: function ( v ) {
  940. var te = this.elements;
  941. te[ 12 ] = v.x;
  942. te[ 13 ] = v.y;
  943. te[ 14 ] = v.z;
  944. return this;
  945. },
  946. getInverse: function ( m, throwOnDegenerate ) {
  947. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  948. var te = this.elements,
  949. me = m.elements,
  950. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  951. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  952. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  953. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  954. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  955. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  956. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  957. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  958. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  959. if ( det === 0 ) {
  960. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  961. if ( throwOnDegenerate === true ) {
  962. throw new Error( msg );
  963. } else {
  964. console.warn( msg );
  965. }
  966. return this.identity();
  967. }
  968. var detInv = 1 / det;
  969. te[ 0 ] = t11 * detInv;
  970. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  971. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  972. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  973. te[ 4 ] = t12 * detInv;
  974. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  975. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  976. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  977. te[ 8 ] = t13 * detInv;
  978. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  979. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  980. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  981. te[ 12 ] = t14 * detInv;
  982. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  983. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  984. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  985. return this;
  986. },
  987. scale: function ( v ) {
  988. var te = this.elements;
  989. var x = v.x, y = v.y, z = v.z;
  990. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  991. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  992. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  993. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  994. return this;
  995. },
  996. getMaxScaleOnAxis: function () {
  997. var te = this.elements;
  998. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  999. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  1000. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  1001. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  1002. },
  1003. makeTranslation: function ( x, y, z ) {
  1004. this.set(
  1005. 1, 0, 0, x,
  1006. 0, 1, 0, y,
  1007. 0, 0, 1, z,
  1008. 0, 0, 0, 1
  1009. );
  1010. return this;
  1011. },
  1012. makeRotationX: function ( theta ) {
  1013. var c = Math.cos( theta ), s = Math.sin( theta );
  1014. this.set(
  1015. 1, 0, 0, 0,
  1016. 0, c, - s, 0,
  1017. 0, s, c, 0,
  1018. 0, 0, 0, 1
  1019. );
  1020. return this;
  1021. },
  1022. makeRotationY: function ( theta ) {
  1023. var c = Math.cos( theta ), s = Math.sin( theta );
  1024. this.set(
  1025. c, 0, s, 0,
  1026. 0, 1, 0, 0,
  1027. - s, 0, c, 0,
  1028. 0, 0, 0, 1
  1029. );
  1030. return this;
  1031. },
  1032. makeRotationZ: function ( theta ) {
  1033. var c = Math.cos( theta ), s = Math.sin( theta );
  1034. this.set(
  1035. c, - s, 0, 0,
  1036. s, c, 0, 0,
  1037. 0, 0, 1, 0,
  1038. 0, 0, 0, 1
  1039. );
  1040. return this;
  1041. },
  1042. makeRotationAxis: function ( axis, angle ) {
  1043. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  1044. var c = Math.cos( angle );
  1045. var s = Math.sin( angle );
  1046. var t = 1 - c;
  1047. var x = axis.x, y = axis.y, z = axis.z;
  1048. var tx = t * x, ty = t * y;
  1049. this.set(
  1050. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  1051. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  1052. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  1053. 0, 0, 0, 1
  1054. );
  1055. return this;
  1056. },
  1057. makeScale: function ( x, y, z ) {
  1058. this.set(
  1059. x, 0, 0, 0,
  1060. 0, y, 0, 0,
  1061. 0, 0, z, 0,
  1062. 0, 0, 0, 1
  1063. );
  1064. return this;
  1065. },
  1066. makeShear: function ( x, y, z ) {
  1067. this.set(
  1068. 1, y, z, 0,
  1069. x, 1, z, 0,
  1070. x, y, 1, 0,
  1071. 0, 0, 0, 1
  1072. );
  1073. return this;
  1074. },
  1075. compose: function ( position, quaternion, scale ) {
  1076. this.makeRotationFromQuaternion( quaternion );
  1077. this.scale( scale );
  1078. this.setPosition( position );
  1079. return this;
  1080. },
  1081. decompose: function () {
  1082. var vector = new Vector3();
  1083. var matrix = new Matrix4();
  1084. return function decompose( position, quaternion, scale ) {
  1085. var te = this.elements;
  1086. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  1087. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  1088. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  1089. // if determine is negative, we need to invert one scale
  1090. var det = this.determinant();
  1091. if ( det < 0 ) sx = - sx;
  1092. position.x = te[ 12 ];
  1093. position.y = te[ 13 ];
  1094. position.z = te[ 14 ];
  1095. // scale the rotation part
  1096. matrix.copy( this );
  1097. var invSX = 1 / sx;
  1098. var invSY = 1 / sy;
  1099. var invSZ = 1 / sz;
  1100. matrix.elements[ 0 ] *= invSX;
  1101. matrix.elements[ 1 ] *= invSX;
  1102. matrix.elements[ 2 ] *= invSX;
  1103. matrix.elements[ 4 ] *= invSY;
  1104. matrix.elements[ 5 ] *= invSY;
  1105. matrix.elements[ 6 ] *= invSY;
  1106. matrix.elements[ 8 ] *= invSZ;
  1107. matrix.elements[ 9 ] *= invSZ;
  1108. matrix.elements[ 10 ] *= invSZ;
  1109. quaternion.setFromRotationMatrix( matrix );
  1110. scale.x = sx;
  1111. scale.y = sy;
  1112. scale.z = sz;
  1113. return this;
  1114. };
  1115. }(),
  1116. makePerspective: function ( left, right, top, bottom, near, far ) {
  1117. if ( far === undefined ) {
  1118. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  1119. }
  1120. var te = this.elements;
  1121. var x = 2 * near / ( right - left );
  1122. var y = 2 * near / ( top - bottom );
  1123. var a = ( right + left ) / ( right - left );
  1124. var b = ( top + bottom ) / ( top - bottom );
  1125. var c = - ( far + near ) / ( far - near );
  1126. var d = - 2 * far * near / ( far - near );
  1127. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  1128. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  1129. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  1130. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  1131. return this;
  1132. },
  1133. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  1134. var te = this.elements;
  1135. var w = 1.0 / ( right - left );
  1136. var h = 1.0 / ( top - bottom );
  1137. var p = 1.0 / ( far - near );
  1138. var x = ( right + left ) * w;
  1139. var y = ( top + bottom ) * h;
  1140. var z = ( far + near ) * p;
  1141. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  1142. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  1143. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  1144. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  1145. return this;
  1146. },
  1147. equals: function ( matrix ) {
  1148. var te = this.elements;
  1149. var me = matrix.elements;
  1150. for ( var i = 0; i < 16; i ++ ) {
  1151. if ( te[ i ] !== me[ i ] ) return false;
  1152. }
  1153. return true;
  1154. },
  1155. fromArray: function ( array, offset ) {
  1156. if ( offset === undefined ) offset = 0;
  1157. for ( var i = 0; i < 16; i ++ ) {
  1158. this.elements[ i ] = array[ i + offset ];
  1159. }
  1160. return this;
  1161. },
  1162. toArray: function ( array, offset ) {
  1163. if ( array === undefined ) array = [];
  1164. if ( offset === undefined ) offset = 0;
  1165. var te = this.elements;
  1166. array[ offset ] = te[ 0 ];
  1167. array[ offset + 1 ] = te[ 1 ];
  1168. array[ offset + 2 ] = te[ 2 ];
  1169. array[ offset + 3 ] = te[ 3 ];
  1170. array[ offset + 4 ] = te[ 4 ];
  1171. array[ offset + 5 ] = te[ 5 ];
  1172. array[ offset + 6 ] = te[ 6 ];
  1173. array[ offset + 7 ] = te[ 7 ];
  1174. array[ offset + 8 ] = te[ 8 ];
  1175. array[ offset + 9 ] = te[ 9 ];
  1176. array[ offset + 10 ] = te[ 10 ];
  1177. array[ offset + 11 ] = te[ 11 ];
  1178. array[ offset + 12 ] = te[ 12 ];
  1179. array[ offset + 13 ] = te[ 13 ];
  1180. array[ offset + 14 ] = te[ 14 ];
  1181. array[ offset + 15 ] = te[ 15 ];
  1182. return array;
  1183. }
  1184. } );
  1185. /**
  1186. * @author mikael emtinger / http://gomo.se/
  1187. * @author alteredq / http://alteredqualia.com/
  1188. * @author WestLangley / http://github.com/WestLangley
  1189. * @author bhouston / http://clara.io
  1190. */
  1191. function Quaternion( x, y, z, w ) {
  1192. this._x = x || 0;
  1193. this._y = y || 0;
  1194. this._z = z || 0;
  1195. this._w = ( w !== undefined ) ? w : 1;
  1196. }
  1197. Object.assign( Quaternion, {
  1198. slerp: function ( qa, qb, qm, t ) {
  1199. return qm.copy( qa ).slerp( qb, t );
  1200. },
  1201. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1202. // fuzz-free, array-based Quaternion SLERP operation
  1203. var x0 = src0[ srcOffset0 + 0 ],
  1204. y0 = src0[ srcOffset0 + 1 ],
  1205. z0 = src0[ srcOffset0 + 2 ],
  1206. w0 = src0[ srcOffset0 + 3 ],
  1207. x1 = src1[ srcOffset1 + 0 ],
  1208. y1 = src1[ srcOffset1 + 1 ],
  1209. z1 = src1[ srcOffset1 + 2 ],
  1210. w1 = src1[ srcOffset1 + 3 ];
  1211. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1212. var s = 1 - t,
  1213. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1214. dir = ( cos >= 0 ? 1 : - 1 ),
  1215. sqrSin = 1 - cos * cos;
  1216. // Skip the Slerp for tiny steps to avoid numeric problems:
  1217. if ( sqrSin > Number.EPSILON ) {
  1218. var sin = Math.sqrt( sqrSin ),
  1219. len = Math.atan2( sin, cos * dir );
  1220. s = Math.sin( s * len ) / sin;
  1221. t = Math.sin( t * len ) / sin;
  1222. }
  1223. var tDir = t * dir;
  1224. x0 = x0 * s + x1 * tDir;
  1225. y0 = y0 * s + y1 * tDir;
  1226. z0 = z0 * s + z1 * tDir;
  1227. w0 = w0 * s + w1 * tDir;
  1228. // Normalize in case we just did a lerp:
  1229. if ( s === 1 - t ) {
  1230. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1231. x0 *= f;
  1232. y0 *= f;
  1233. z0 *= f;
  1234. w0 *= f;
  1235. }
  1236. }
  1237. dst[ dstOffset ] = x0;
  1238. dst[ dstOffset + 1 ] = y0;
  1239. dst[ dstOffset + 2 ] = z0;
  1240. dst[ dstOffset + 3 ] = w0;
  1241. }
  1242. } );
  1243. Object.defineProperties( Quaternion.prototype, {
  1244. x: {
  1245. get: function () {
  1246. return this._x;
  1247. },
  1248. set: function ( value ) {
  1249. this._x = value;
  1250. this.onChangeCallback();
  1251. }
  1252. },
  1253. y: {
  1254. get: function () {
  1255. return this._y;
  1256. },
  1257. set: function ( value ) {
  1258. this._y = value;
  1259. this.onChangeCallback();
  1260. }
  1261. },
  1262. z: {
  1263. get: function () {
  1264. return this._z;
  1265. },
  1266. set: function ( value ) {
  1267. this._z = value;
  1268. this.onChangeCallback();
  1269. }
  1270. },
  1271. w: {
  1272. get: function () {
  1273. return this._w;
  1274. },
  1275. set: function ( value ) {
  1276. this._w = value;
  1277. this.onChangeCallback();
  1278. }
  1279. }
  1280. } );
  1281. Object.assign( Quaternion.prototype, {
  1282. set: function ( x, y, z, w ) {
  1283. this._x = x;
  1284. this._y = y;
  1285. this._z = z;
  1286. this._w = w;
  1287. this.onChangeCallback();
  1288. return this;
  1289. },
  1290. clone: function () {
  1291. return new this.constructor( this._x, this._y, this._z, this._w );
  1292. },
  1293. copy: function ( quaternion ) {
  1294. this._x = quaternion.x;
  1295. this._y = quaternion.y;
  1296. this._z = quaternion.z;
  1297. this._w = quaternion.w;
  1298. this.onChangeCallback();
  1299. return this;
  1300. },
  1301. setFromEuler: function ( euler, update ) {
  1302. if ( ! ( euler && euler.isEuler ) ) {
  1303. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1304. }
  1305. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  1306. // http://www.mathworks.com/matlabcentral/fileexchange/
  1307. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1308. // content/SpinCalc.m
  1309. var cos = Math.cos;
  1310. var sin = Math.sin;
  1311. var c1 = cos( x / 2 );
  1312. var c2 = cos( y / 2 );
  1313. var c3 = cos( z / 2 );
  1314. var s1 = sin( x / 2 );
  1315. var s2 = sin( y / 2 );
  1316. var s3 = sin( z / 2 );
  1317. if ( order === 'XYZ' ) {
  1318. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1319. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1320. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1321. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1322. } else if ( order === 'YXZ' ) {
  1323. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1324. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1325. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1326. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1327. } else if ( order === 'ZXY' ) {
  1328. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1329. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1330. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1331. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1332. } else if ( order === 'ZYX' ) {
  1333. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1334. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1335. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1336. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1337. } else if ( order === 'YZX' ) {
  1338. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1339. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1340. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1341. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1342. } else if ( order === 'XZY' ) {
  1343. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1344. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1345. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1346. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1347. }
  1348. if ( update !== false ) this.onChangeCallback();
  1349. return this;
  1350. },
  1351. setFromAxisAngle: function ( axis, angle ) {
  1352. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1353. // assumes axis is normalized
  1354. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  1355. this._x = axis.x * s;
  1356. this._y = axis.y * s;
  1357. this._z = axis.z * s;
  1358. this._w = Math.cos( halfAngle );
  1359. this.onChangeCallback();
  1360. return this;
  1361. },
  1362. setFromRotationMatrix: function ( m ) {
  1363. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1364. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1365. var te = m.elements,
  1366. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1367. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1368. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1369. trace = m11 + m22 + m33,
  1370. s;
  1371. if ( trace > 0 ) {
  1372. s = 0.5 / Math.sqrt( trace + 1.0 );
  1373. this._w = 0.25 / s;
  1374. this._x = ( m32 - m23 ) * s;
  1375. this._y = ( m13 - m31 ) * s;
  1376. this._z = ( m21 - m12 ) * s;
  1377. } else if ( m11 > m22 && m11 > m33 ) {
  1378. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1379. this._w = ( m32 - m23 ) / s;
  1380. this._x = 0.25 * s;
  1381. this._y = ( m12 + m21 ) / s;
  1382. this._z = ( m13 + m31 ) / s;
  1383. } else if ( m22 > m33 ) {
  1384. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1385. this._w = ( m13 - m31 ) / s;
  1386. this._x = ( m12 + m21 ) / s;
  1387. this._y = 0.25 * s;
  1388. this._z = ( m23 + m32 ) / s;
  1389. } else {
  1390. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1391. this._w = ( m21 - m12 ) / s;
  1392. this._x = ( m13 + m31 ) / s;
  1393. this._y = ( m23 + m32 ) / s;
  1394. this._z = 0.25 * s;
  1395. }
  1396. this.onChangeCallback();
  1397. return this;
  1398. },
  1399. setFromUnitVectors: function () {
  1400. // assumes direction vectors vFrom and vTo are normalized
  1401. var v1 = new Vector3();
  1402. var r;
  1403. var EPS = 0.000001;
  1404. return function setFromUnitVectors( vFrom, vTo ) {
  1405. if ( v1 === undefined ) v1 = new Vector3();
  1406. r = vFrom.dot( vTo ) + 1;
  1407. if ( r < EPS ) {
  1408. r = 0;
  1409. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1410. v1.set( - vFrom.y, vFrom.x, 0 );
  1411. } else {
  1412. v1.set( 0, - vFrom.z, vFrom.y );
  1413. }
  1414. } else {
  1415. v1.crossVectors( vFrom, vTo );
  1416. }
  1417. this._x = v1.x;
  1418. this._y = v1.y;
  1419. this._z = v1.z;
  1420. this._w = r;
  1421. return this.normalize();
  1422. };
  1423. }(),
  1424. inverse: function () {
  1425. // quaternion is assumed to have unit length
  1426. return this.conjugate();
  1427. },
  1428. conjugate: function () {
  1429. this._x *= - 1;
  1430. this._y *= - 1;
  1431. this._z *= - 1;
  1432. this.onChangeCallback();
  1433. return this;
  1434. },
  1435. dot: function ( v ) {
  1436. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1437. },
  1438. lengthSq: function () {
  1439. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1440. },
  1441. length: function () {
  1442. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1443. },
  1444. normalize: function () {
  1445. var l = this.length();
  1446. if ( l === 0 ) {
  1447. this._x = 0;
  1448. this._y = 0;
  1449. this._z = 0;
  1450. this._w = 1;
  1451. } else {
  1452. l = 1 / l;
  1453. this._x = this._x * l;
  1454. this._y = this._y * l;
  1455. this._z = this._z * l;
  1456. this._w = this._w * l;
  1457. }
  1458. this.onChangeCallback();
  1459. return this;
  1460. },
  1461. multiply: function ( q, p ) {
  1462. if ( p !== undefined ) {
  1463. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1464. return this.multiplyQuaternions( q, p );
  1465. }
  1466. return this.multiplyQuaternions( this, q );
  1467. },
  1468. premultiply: function ( q ) {
  1469. return this.multiplyQuaternions( q, this );
  1470. },
  1471. multiplyQuaternions: function ( a, b ) {
  1472. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1473. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1474. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1475. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1476. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1477. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1478. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1479. this.onChangeCallback();
  1480. return this;
  1481. },
  1482. slerp: function ( qb, t ) {
  1483. if ( t === 0 ) return this;
  1484. if ( t === 1 ) return this.copy( qb );
  1485. var x = this._x, y = this._y, z = this._z, w = this._w;
  1486. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1487. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1488. if ( cosHalfTheta < 0 ) {
  1489. this._w = - qb._w;
  1490. this._x = - qb._x;
  1491. this._y = - qb._y;
  1492. this._z = - qb._z;
  1493. cosHalfTheta = - cosHalfTheta;
  1494. } else {
  1495. this.copy( qb );
  1496. }
  1497. if ( cosHalfTheta >= 1.0 ) {
  1498. this._w = w;
  1499. this._x = x;
  1500. this._y = y;
  1501. this._z = z;
  1502. return this;
  1503. }
  1504. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  1505. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  1506. this._w = 0.5 * ( w + this._w );
  1507. this._x = 0.5 * ( x + this._x );
  1508. this._y = 0.5 * ( y + this._y );
  1509. this._z = 0.5 * ( z + this._z );
  1510. return this;
  1511. }
  1512. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1513. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1514. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1515. this._w = ( w * ratioA + this._w * ratioB );
  1516. this._x = ( x * ratioA + this._x * ratioB );
  1517. this._y = ( y * ratioA + this._y * ratioB );
  1518. this._z = ( z * ratioA + this._z * ratioB );
  1519. this.onChangeCallback();
  1520. return this;
  1521. },
  1522. equals: function ( quaternion ) {
  1523. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1524. },
  1525. fromArray: function ( array, offset ) {
  1526. if ( offset === undefined ) offset = 0;
  1527. this._x = array[ offset ];
  1528. this._y = array[ offset + 1 ];
  1529. this._z = array[ offset + 2 ];
  1530. this._w = array[ offset + 3 ];
  1531. this.onChangeCallback();
  1532. return this;
  1533. },
  1534. toArray: function ( array, offset ) {
  1535. if ( array === undefined ) array = [];
  1536. if ( offset === undefined ) offset = 0;
  1537. array[ offset ] = this._x;
  1538. array[ offset + 1 ] = this._y;
  1539. array[ offset + 2 ] = this._z;
  1540. array[ offset + 3 ] = this._w;
  1541. return array;
  1542. },
  1543. onChange: function ( callback ) {
  1544. this.onChangeCallback = callback;
  1545. return this;
  1546. },
  1547. onChangeCallback: function () {}
  1548. } );
  1549. /**
  1550. * @author mrdoob / http://mrdoob.com/
  1551. * @author kile / http://kile.stravaganza.org/
  1552. * @author philogb / http://blog.thejit.org/
  1553. * @author mikael emtinger / http://gomo.se/
  1554. * @author egraether / http://egraether.com/
  1555. * @author WestLangley / http://github.com/WestLangley
  1556. */
  1557. function Vector3( x, y, z ) {
  1558. this.x = x || 0;
  1559. this.y = y || 0;
  1560. this.z = z || 0;
  1561. }
  1562. Object.assign( Vector3.prototype, {
  1563. isVector3: true,
  1564. set: function ( x, y, z ) {
  1565. this.x = x;
  1566. this.y = y;
  1567. this.z = z;
  1568. return this;
  1569. },
  1570. setScalar: function ( scalar ) {
  1571. this.x = scalar;
  1572. this.y = scalar;
  1573. this.z = scalar;
  1574. return this;
  1575. },
  1576. setX: function ( x ) {
  1577. this.x = x;
  1578. return this;
  1579. },
  1580. setY: function ( y ) {
  1581. this.y = y;
  1582. return this;
  1583. },
  1584. setZ: function ( z ) {
  1585. this.z = z;
  1586. return this;
  1587. },
  1588. setComponent: function ( index, value ) {
  1589. switch ( index ) {
  1590. case 0: this.x = value; break;
  1591. case 1: this.y = value; break;
  1592. case 2: this.z = value; break;
  1593. default: throw new Error( 'index is out of range: ' + index );
  1594. }
  1595. return this;
  1596. },
  1597. getComponent: function ( index ) {
  1598. switch ( index ) {
  1599. case 0: return this.x;
  1600. case 1: return this.y;
  1601. case 2: return this.z;
  1602. default: throw new Error( 'index is out of range: ' + index );
  1603. }
  1604. },
  1605. clone: function () {
  1606. return new this.constructor( this.x, this.y, this.z );
  1607. },
  1608. copy: function ( v ) {
  1609. this.x = v.x;
  1610. this.y = v.y;
  1611. this.z = v.z;
  1612. return this;
  1613. },
  1614. add: function ( v, w ) {
  1615. if ( w !== undefined ) {
  1616. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1617. return this.addVectors( v, w );
  1618. }
  1619. this.x += v.x;
  1620. this.y += v.y;
  1621. this.z += v.z;
  1622. return this;
  1623. },
  1624. addScalar: function ( s ) {
  1625. this.x += s;
  1626. this.y += s;
  1627. this.z += s;
  1628. return this;
  1629. },
  1630. addVectors: function ( a, b ) {
  1631. this.x = a.x + b.x;
  1632. this.y = a.y + b.y;
  1633. this.z = a.z + b.z;
  1634. return this;
  1635. },
  1636. addScaledVector: function ( v, s ) {
  1637. this.x += v.x * s;
  1638. this.y += v.y * s;
  1639. this.z += v.z * s;
  1640. return this;
  1641. },
  1642. sub: function ( v, w ) {
  1643. if ( w !== undefined ) {
  1644. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1645. return this.subVectors( v, w );
  1646. }
  1647. this.x -= v.x;
  1648. this.y -= v.y;
  1649. this.z -= v.z;
  1650. return this;
  1651. },
  1652. subScalar: function ( s ) {
  1653. this.x -= s;
  1654. this.y -= s;
  1655. this.z -= s;
  1656. return this;
  1657. },
  1658. subVectors: function ( a, b ) {
  1659. this.x = a.x - b.x;
  1660. this.y = a.y - b.y;
  1661. this.z = a.z - b.z;
  1662. return this;
  1663. },
  1664. multiply: function ( v, w ) {
  1665. if ( w !== undefined ) {
  1666. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1667. return this.multiplyVectors( v, w );
  1668. }
  1669. this.x *= v.x;
  1670. this.y *= v.y;
  1671. this.z *= v.z;
  1672. return this;
  1673. },
  1674. multiplyScalar: function ( scalar ) {
  1675. this.x *= scalar;
  1676. this.y *= scalar;
  1677. this.z *= scalar;
  1678. return this;
  1679. },
  1680. multiplyVectors: function ( a, b ) {
  1681. this.x = a.x * b.x;
  1682. this.y = a.y * b.y;
  1683. this.z = a.z * b.z;
  1684. return this;
  1685. },
  1686. applyEuler: function () {
  1687. var quaternion = new Quaternion();
  1688. return function applyEuler( euler ) {
  1689. if ( ! ( euler && euler.isEuler ) ) {
  1690. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1691. }
  1692. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1693. };
  1694. }(),
  1695. applyAxisAngle: function () {
  1696. var quaternion = new Quaternion();
  1697. return function applyAxisAngle( axis, angle ) {
  1698. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1699. };
  1700. }(),
  1701. applyMatrix3: function ( m ) {
  1702. var x = this.x, y = this.y, z = this.z;
  1703. var e = m.elements;
  1704. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1705. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1706. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1707. return this;
  1708. },
  1709. applyMatrix4: function ( m ) {
  1710. var x = this.x, y = this.y, z = this.z;
  1711. var e = m.elements;
  1712. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1713. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1714. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1715. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1716. return this;
  1717. },
  1718. applyQuaternion: function ( q ) {
  1719. var x = this.x, y = this.y, z = this.z;
  1720. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1721. // calculate quat * vector
  1722. var ix = qw * x + qy * z - qz * y;
  1723. var iy = qw * y + qz * x - qx * z;
  1724. var iz = qw * z + qx * y - qy * x;
  1725. var iw = - qx * x - qy * y - qz * z;
  1726. // calculate result * inverse quat
  1727. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1728. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1729. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1730. return this;
  1731. },
  1732. project: function () {
  1733. var matrix = new Matrix4();
  1734. return function project( camera ) {
  1735. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1736. return this.applyMatrix4( matrix );
  1737. };
  1738. }(),
  1739. unproject: function () {
  1740. var matrix = new Matrix4();
  1741. return function unproject( camera ) {
  1742. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1743. return this.applyMatrix4( matrix );
  1744. };
  1745. }(),
  1746. transformDirection: function ( m ) {
  1747. // input: THREE.Matrix4 affine matrix
  1748. // vector interpreted as a direction
  1749. var x = this.x, y = this.y, z = this.z;
  1750. var e = m.elements;
  1751. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1752. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1753. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1754. return this.normalize();
  1755. },
  1756. divide: function ( v ) {
  1757. this.x /= v.x;
  1758. this.y /= v.y;
  1759. this.z /= v.z;
  1760. return this;
  1761. },
  1762. divideScalar: function ( scalar ) {
  1763. return this.multiplyScalar( 1 / scalar );
  1764. },
  1765. min: function ( v ) {
  1766. this.x = Math.min( this.x, v.x );
  1767. this.y = Math.min( this.y, v.y );
  1768. this.z = Math.min( this.z, v.z );
  1769. return this;
  1770. },
  1771. max: function ( v ) {
  1772. this.x = Math.max( this.x, v.x );
  1773. this.y = Math.max( this.y, v.y );
  1774. this.z = Math.max( this.z, v.z );
  1775. return this;
  1776. },
  1777. clamp: function ( min, max ) {
  1778. // assumes min < max, componentwise
  1779. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1780. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1781. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1782. return this;
  1783. },
  1784. clampScalar: function () {
  1785. var min = new Vector3();
  1786. var max = new Vector3();
  1787. return function clampScalar( minVal, maxVal ) {
  1788. min.set( minVal, minVal, minVal );
  1789. max.set( maxVal, maxVal, maxVal );
  1790. return this.clamp( min, max );
  1791. };
  1792. }(),
  1793. clampLength: function ( min, max ) {
  1794. var length = this.length();
  1795. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1796. },
  1797. floor: function () {
  1798. this.x = Math.floor( this.x );
  1799. this.y = Math.floor( this.y );
  1800. this.z = Math.floor( this.z );
  1801. return this;
  1802. },
  1803. ceil: function () {
  1804. this.x = Math.ceil( this.x );
  1805. this.y = Math.ceil( this.y );
  1806. this.z = Math.ceil( this.z );
  1807. return this;
  1808. },
  1809. round: function () {
  1810. this.x = Math.round( this.x );
  1811. this.y = Math.round( this.y );
  1812. this.z = Math.round( this.z );
  1813. return this;
  1814. },
  1815. roundToZero: function () {
  1816. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1817. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1818. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1819. return this;
  1820. },
  1821. negate: function () {
  1822. this.x = - this.x;
  1823. this.y = - this.y;
  1824. this.z = - this.z;
  1825. return this;
  1826. },
  1827. dot: function ( v ) {
  1828. return this.x * v.x + this.y * v.y + this.z * v.z;
  1829. },
  1830. // TODO lengthSquared?
  1831. lengthSq: function () {
  1832. return this.x * this.x + this.y * this.y + this.z * this.z;
  1833. },
  1834. length: function () {
  1835. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1836. },
  1837. manhattanLength: function () {
  1838. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1839. },
  1840. normalize: function () {
  1841. return this.divideScalar( this.length() || 1 );
  1842. },
  1843. setLength: function ( length ) {
  1844. return this.normalize().multiplyScalar( length );
  1845. },
  1846. lerp: function ( v, alpha ) {
  1847. this.x += ( v.x - this.x ) * alpha;
  1848. this.y += ( v.y - this.y ) * alpha;
  1849. this.z += ( v.z - this.z ) * alpha;
  1850. return this;
  1851. },
  1852. lerpVectors: function ( v1, v2, alpha ) {
  1853. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1854. },
  1855. cross: function ( v, w ) {
  1856. if ( w !== undefined ) {
  1857. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1858. return this.crossVectors( v, w );
  1859. }
  1860. return this.crossVectors( this, v );
  1861. },
  1862. crossVectors: function ( a, b ) {
  1863. var ax = a.x, ay = a.y, az = a.z;
  1864. var bx = b.x, by = b.y, bz = b.z;
  1865. this.x = ay * bz - az * by;
  1866. this.y = az * bx - ax * bz;
  1867. this.z = ax * by - ay * bx;
  1868. return this;
  1869. },
  1870. projectOnVector: function ( vector ) {
  1871. var scalar = vector.dot( this ) / vector.lengthSq();
  1872. return this.copy( vector ).multiplyScalar( scalar );
  1873. },
  1874. projectOnPlane: function () {
  1875. var v1 = new Vector3();
  1876. return function projectOnPlane( planeNormal ) {
  1877. v1.copy( this ).projectOnVector( planeNormal );
  1878. return this.sub( v1 );
  1879. };
  1880. }(),
  1881. reflect: function () {
  1882. // reflect incident vector off plane orthogonal to normal
  1883. // normal is assumed to have unit length
  1884. var v1 = new Vector3();
  1885. return function reflect( normal ) {
  1886. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1887. };
  1888. }(),
  1889. angleTo: function ( v ) {
  1890. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1891. // clamp, to handle numerical problems
  1892. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1893. },
  1894. distanceTo: function ( v ) {
  1895. return Math.sqrt( this.distanceToSquared( v ) );
  1896. },
  1897. distanceToSquared: function ( v ) {
  1898. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1899. return dx * dx + dy * dy + dz * dz;
  1900. },
  1901. manhattanDistanceTo: function ( v ) {
  1902. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1903. },
  1904. setFromSpherical: function ( s ) {
  1905. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1906. this.x = sinPhiRadius * Math.sin( s.theta );
  1907. this.y = Math.cos( s.phi ) * s.radius;
  1908. this.z = sinPhiRadius * Math.cos( s.theta );
  1909. return this;
  1910. },
  1911. setFromCylindrical: function ( c ) {
  1912. this.x = c.radius * Math.sin( c.theta );
  1913. this.y = c.y;
  1914. this.z = c.radius * Math.cos( c.theta );
  1915. return this;
  1916. },
  1917. setFromMatrixPosition: function ( m ) {
  1918. var e = m.elements;
  1919. this.x = e[ 12 ];
  1920. this.y = e[ 13 ];
  1921. this.z = e[ 14 ];
  1922. return this;
  1923. },
  1924. setFromMatrixScale: function ( m ) {
  1925. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1926. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1927. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1928. this.x = sx;
  1929. this.y = sy;
  1930. this.z = sz;
  1931. return this;
  1932. },
  1933. setFromMatrixColumn: function ( m, index ) {
  1934. return this.fromArray( m.elements, index * 4 );
  1935. },
  1936. equals: function ( v ) {
  1937. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1938. },
  1939. fromArray: function ( array, offset ) {
  1940. if ( offset === undefined ) offset = 0;
  1941. this.x = array[ offset ];
  1942. this.y = array[ offset + 1 ];
  1943. this.z = array[ offset + 2 ];
  1944. return this;
  1945. },
  1946. toArray: function ( array, offset ) {
  1947. if ( array === undefined ) array = [];
  1948. if ( offset === undefined ) offset = 0;
  1949. array[ offset ] = this.x;
  1950. array[ offset + 1 ] = this.y;
  1951. array[ offset + 2 ] = this.z;
  1952. return array;
  1953. },
  1954. fromBufferAttribute: function ( attribute, index, offset ) {
  1955. if ( offset !== undefined ) {
  1956. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1957. }
  1958. this.x = attribute.getX( index );
  1959. this.y = attribute.getY( index );
  1960. this.z = attribute.getZ( index );
  1961. return this;
  1962. }
  1963. } );
  1964. /**
  1965. * @author alteredq / http://alteredqualia.com/
  1966. * @author WestLangley / http://github.com/WestLangley
  1967. * @author bhouston / http://clara.io
  1968. * @author tschw
  1969. */
  1970. function Matrix3() {
  1971. this.elements = [
  1972. 1, 0, 0,
  1973. 0, 1, 0,
  1974. 0, 0, 1
  1975. ];
  1976. if ( arguments.length > 0 ) {
  1977. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  1978. }
  1979. }
  1980. Object.assign( Matrix3.prototype, {
  1981. isMatrix3: true,
  1982. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  1983. var te = this.elements;
  1984. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  1985. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  1986. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  1987. return this;
  1988. },
  1989. identity: function () {
  1990. this.set(
  1991. 1, 0, 0,
  1992. 0, 1, 0,
  1993. 0, 0, 1
  1994. );
  1995. return this;
  1996. },
  1997. clone: function () {
  1998. return new this.constructor().fromArray( this.elements );
  1999. },
  2000. copy: function ( m ) {
  2001. var te = this.elements;
  2002. var me = m.elements;
  2003. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  2004. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  2005. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  2006. return this;
  2007. },
  2008. setFromMatrix4: function ( m ) {
  2009. var me = m.elements;
  2010. this.set(
  2011. me[ 0 ], me[ 4 ], me[ 8 ],
  2012. me[ 1 ], me[ 5 ], me[ 9 ],
  2013. me[ 2 ], me[ 6 ], me[ 10 ]
  2014. );
  2015. return this;
  2016. },
  2017. applyToBufferAttribute: function () {
  2018. var v1 = new Vector3();
  2019. return function applyToBufferAttribute( attribute ) {
  2020. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2021. v1.x = attribute.getX( i );
  2022. v1.y = attribute.getY( i );
  2023. v1.z = attribute.getZ( i );
  2024. v1.applyMatrix3( this );
  2025. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  2026. }
  2027. return attribute;
  2028. };
  2029. }(),
  2030. multiply: function ( m ) {
  2031. return this.multiplyMatrices( this, m );
  2032. },
  2033. premultiply: function ( m ) {
  2034. return this.multiplyMatrices( m, this );
  2035. },
  2036. multiplyMatrices: function ( a, b ) {
  2037. var ae = a.elements;
  2038. var be = b.elements;
  2039. var te = this.elements;
  2040. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  2041. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  2042. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  2043. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  2044. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  2045. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  2046. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  2047. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  2048. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  2049. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  2050. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  2051. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  2052. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  2053. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  2054. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  2055. return this;
  2056. },
  2057. multiplyScalar: function ( s ) {
  2058. var te = this.elements;
  2059. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2060. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2061. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2062. return this;
  2063. },
  2064. determinant: function () {
  2065. var te = this.elements;
  2066. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2067. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2068. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2069. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2070. },
  2071. getInverse: function ( matrix, throwOnDegenerate ) {
  2072. if ( matrix && matrix.isMatrix4 ) {
  2073. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  2074. }
  2075. var me = matrix.elements,
  2076. te = this.elements,
  2077. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  2078. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  2079. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  2080. t11 = n33 * n22 - n32 * n23,
  2081. t12 = n32 * n13 - n33 * n12,
  2082. t13 = n23 * n12 - n22 * n13,
  2083. det = n11 * t11 + n21 * t12 + n31 * t13;
  2084. if ( det === 0 ) {
  2085. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  2086. if ( throwOnDegenerate === true ) {
  2087. throw new Error( msg );
  2088. } else {
  2089. console.warn( msg );
  2090. }
  2091. return this.identity();
  2092. }
  2093. var detInv = 1 / det;
  2094. te[ 0 ] = t11 * detInv;
  2095. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  2096. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  2097. te[ 3 ] = t12 * detInv;
  2098. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  2099. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  2100. te[ 6 ] = t13 * detInv;
  2101. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  2102. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  2103. return this;
  2104. },
  2105. transpose: function () {
  2106. var tmp, m = this.elements;
  2107. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2108. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2109. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2110. return this;
  2111. },
  2112. getNormalMatrix: function ( matrix4 ) {
  2113. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  2114. },
  2115. transposeIntoArray: function ( r ) {
  2116. var m = this.elements;
  2117. r[ 0 ] = m[ 0 ];
  2118. r[ 1 ] = m[ 3 ];
  2119. r[ 2 ] = m[ 6 ];
  2120. r[ 3 ] = m[ 1 ];
  2121. r[ 4 ] = m[ 4 ];
  2122. r[ 5 ] = m[ 7 ];
  2123. r[ 6 ] = m[ 2 ];
  2124. r[ 7 ] = m[ 5 ];
  2125. r[ 8 ] = m[ 8 ];
  2126. return this;
  2127. },
  2128. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  2129. var c = Math.cos( rotation );
  2130. var s = Math.sin( rotation );
  2131. this.set(
  2132. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  2133. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  2134. 0, 0, 1
  2135. );
  2136. },
  2137. scale: function ( sx, sy ) {
  2138. var te = this.elements;
  2139. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  2140. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  2141. return this;
  2142. },
  2143. rotate: function ( theta ) {
  2144. var c = Math.cos( theta );
  2145. var s = Math.sin( theta );
  2146. var te = this.elements;
  2147. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  2148. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  2149. te[ 0 ] = c * a11 + s * a21;
  2150. te[ 3 ] = c * a12 + s * a22;
  2151. te[ 6 ] = c * a13 + s * a23;
  2152. te[ 1 ] = - s * a11 + c * a21;
  2153. te[ 4 ] = - s * a12 + c * a22;
  2154. te[ 7 ] = - s * a13 + c * a23;
  2155. return this;
  2156. },
  2157. translate: function ( tx, ty ) {
  2158. var te = this.elements;
  2159. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  2160. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  2161. return this;
  2162. },
  2163. equals: function ( matrix ) {
  2164. var te = this.elements;
  2165. var me = matrix.elements;
  2166. for ( var i = 0; i < 9; i ++ ) {
  2167. if ( te[ i ] !== me[ i ] ) return false;
  2168. }
  2169. return true;
  2170. },
  2171. fromArray: function ( array, offset ) {
  2172. if ( offset === undefined ) offset = 0;
  2173. for ( var i = 0; i < 9; i ++ ) {
  2174. this.elements[ i ] = array[ i + offset ];
  2175. }
  2176. return this;
  2177. },
  2178. toArray: function ( array, offset ) {
  2179. if ( array === undefined ) array = [];
  2180. if ( offset === undefined ) offset = 0;
  2181. var te = this.elements;
  2182. array[ offset ] = te[ 0 ];
  2183. array[ offset + 1 ] = te[ 1 ];
  2184. array[ offset + 2 ] = te[ 2 ];
  2185. array[ offset + 3 ] = te[ 3 ];
  2186. array[ offset + 4 ] = te[ 4 ];
  2187. array[ offset + 5 ] = te[ 5 ];
  2188. array[ offset + 6 ] = te[ 6 ];
  2189. array[ offset + 7 ] = te[ 7 ];
  2190. array[ offset + 8 ] = te[ 8 ];
  2191. return array;
  2192. }
  2193. } );
  2194. /**
  2195. * @author mrdoob / http://mrdoob.com/
  2196. * @author alteredq / http://alteredqualia.com/
  2197. * @author szimek / https://github.com/szimek/
  2198. */
  2199. var textureId = 0;
  2200. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  2201. Object.defineProperty( this, 'id', { value: textureId ++ } );
  2202. this.uuid = _Math.generateUUID();
  2203. this.name = '';
  2204. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  2205. this.mipmaps = [];
  2206. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  2207. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  2208. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  2209. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  2210. this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
  2211. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  2212. this.format = format !== undefined ? format : RGBAFormat;
  2213. this.type = type !== undefined ? type : UnsignedByteType;
  2214. this.offset = new Vector2( 0, 0 );
  2215. this.repeat = new Vector2( 1, 1 );
  2216. this.center = new Vector2( 0, 0 );
  2217. this.rotation = 0;
  2218. this.matrixAutoUpdate = true;
  2219. this.matrix = new Matrix3();
  2220. this.generateMipmaps = true;
  2221. this.premultiplyAlpha = false;
  2222. this.flipY = true;
  2223. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  2224. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  2225. //
  2226. // Also changing the encoding after already used by a Material will not automatically make the Material
  2227. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  2228. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  2229. this.version = 0;
  2230. this.onUpdate = null;
  2231. }
  2232. Texture.DEFAULT_IMAGE = undefined;
  2233. Texture.DEFAULT_MAPPING = UVMapping;
  2234. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2235. constructor: Texture,
  2236. isTexture: true,
  2237. clone: function () {
  2238. return new this.constructor().copy( this );
  2239. },
  2240. copy: function ( source ) {
  2241. this.name = source.name;
  2242. this.image = source.image;
  2243. this.mipmaps = source.mipmaps.slice( 0 );
  2244. this.mapping = source.mapping;
  2245. this.wrapS = source.wrapS;
  2246. this.wrapT = source.wrapT;
  2247. this.magFilter = source.magFilter;
  2248. this.minFilter = source.minFilter;
  2249. this.anisotropy = source.anisotropy;
  2250. this.format = source.format;
  2251. this.type = source.type;
  2252. this.offset.copy( source.offset );
  2253. this.repeat.copy( source.repeat );
  2254. this.center.copy( source.center );
  2255. this.rotation = source.rotation;
  2256. this.matrixAutoUpdate = source.matrixAutoUpdate;
  2257. this.matrix.copy( source.matrix );
  2258. this.generateMipmaps = source.generateMipmaps;
  2259. this.premultiplyAlpha = source.premultiplyAlpha;
  2260. this.flipY = source.flipY;
  2261. this.unpackAlignment = source.unpackAlignment;
  2262. this.encoding = source.encoding;
  2263. return this;
  2264. },
  2265. toJSON: function ( meta ) {
  2266. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  2267. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  2268. return meta.textures[ this.uuid ];
  2269. }
  2270. function getDataURL( image ) {
  2271. var canvas;
  2272. if ( image instanceof HTMLCanvasElement ) {
  2273. canvas = image;
  2274. } else {
  2275. canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  2276. canvas.width = image.width;
  2277. canvas.height = image.height;
  2278. var context = canvas.getContext( '2d' );
  2279. if ( image instanceof ImageData ) {
  2280. context.putImageData( image, 0, 0 );
  2281. } else {
  2282. context.drawImage( image, 0, 0, image.width, image.height );
  2283. }
  2284. }
  2285. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  2286. return canvas.toDataURL( 'image/jpeg', 0.6 );
  2287. } else {
  2288. return canvas.toDataURL( 'image/png' );
  2289. }
  2290. }
  2291. var output = {
  2292. metadata: {
  2293. version: 4.5,
  2294. type: 'Texture',
  2295. generator: 'Texture.toJSON'
  2296. },
  2297. uuid: this.uuid,
  2298. name: this.name,
  2299. mapping: this.mapping,
  2300. repeat: [ this.repeat.x, this.repeat.y ],
  2301. offset: [ this.offset.x, this.offset.y ],
  2302. center: [ this.center.x, this.center.y ],
  2303. rotation: this.rotation,
  2304. wrap: [ this.wrapS, this.wrapT ],
  2305. minFilter: this.minFilter,
  2306. magFilter: this.magFilter,
  2307. anisotropy: this.anisotropy,
  2308. flipY: this.flipY
  2309. };
  2310. if ( this.image !== undefined ) {
  2311. // TODO: Move to THREE.Image
  2312. var image = this.image;
  2313. if ( image.uuid === undefined ) {
  2314. image.uuid = _Math.generateUUID(); // UGH
  2315. }
  2316. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  2317. meta.images[ image.uuid ] = {
  2318. uuid: image.uuid,
  2319. url: getDataURL( image )
  2320. };
  2321. }
  2322. output.image = image.uuid;
  2323. }
  2324. if ( ! isRootObject ) {
  2325. meta.textures[ this.uuid ] = output;
  2326. }
  2327. return output;
  2328. },
  2329. dispose: function () {
  2330. this.dispatchEvent( { type: 'dispose' } );
  2331. },
  2332. transformUv: function ( uv ) {
  2333. if ( this.mapping !== UVMapping ) return;
  2334. uv.applyMatrix3( this.matrix );
  2335. if ( uv.x < 0 || uv.x > 1 ) {
  2336. switch ( this.wrapS ) {
  2337. case RepeatWrapping:
  2338. uv.x = uv.x - Math.floor( uv.x );
  2339. break;
  2340. case ClampToEdgeWrapping:
  2341. uv.x = uv.x < 0 ? 0 : 1;
  2342. break;
  2343. case MirroredRepeatWrapping:
  2344. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  2345. uv.x = Math.ceil( uv.x ) - uv.x;
  2346. } else {
  2347. uv.x = uv.x - Math.floor( uv.x );
  2348. }
  2349. break;
  2350. }
  2351. }
  2352. if ( uv.y < 0 || uv.y > 1 ) {
  2353. switch ( this.wrapT ) {
  2354. case RepeatWrapping:
  2355. uv.y = uv.y - Math.floor( uv.y );
  2356. break;
  2357. case ClampToEdgeWrapping:
  2358. uv.y = uv.y < 0 ? 0 : 1;
  2359. break;
  2360. case MirroredRepeatWrapping:
  2361. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  2362. uv.y = Math.ceil( uv.y ) - uv.y;
  2363. } else {
  2364. uv.y = uv.y - Math.floor( uv.y );
  2365. }
  2366. break;
  2367. }
  2368. }
  2369. if ( this.flipY ) {
  2370. uv.y = 1 - uv.y;
  2371. }
  2372. }
  2373. } );
  2374. Object.defineProperty( Texture.prototype, "needsUpdate", {
  2375. set: function ( value ) {
  2376. if ( value === true ) this.version ++;
  2377. }
  2378. } );
  2379. /**
  2380. * @author supereggbert / http://www.paulbrunt.co.uk/
  2381. * @author philogb / http://blog.thejit.org/
  2382. * @author mikael emtinger / http://gomo.se/
  2383. * @author egraether / http://egraether.com/
  2384. * @author WestLangley / http://github.com/WestLangley
  2385. */
  2386. function Vector4( x, y, z, w ) {
  2387. this.x = x || 0;
  2388. this.y = y || 0;
  2389. this.z = z || 0;
  2390. this.w = ( w !== undefined ) ? w : 1;
  2391. }
  2392. Object.assign( Vector4.prototype, {
  2393. isVector4: true,
  2394. set: function ( x, y, z, w ) {
  2395. this.x = x;
  2396. this.y = y;
  2397. this.z = z;
  2398. this.w = w;
  2399. return this;
  2400. },
  2401. setScalar: function ( scalar ) {
  2402. this.x = scalar;
  2403. this.y = scalar;
  2404. this.z = scalar;
  2405. this.w = scalar;
  2406. return this;
  2407. },
  2408. setX: function ( x ) {
  2409. this.x = x;
  2410. return this;
  2411. },
  2412. setY: function ( y ) {
  2413. this.y = y;
  2414. return this;
  2415. },
  2416. setZ: function ( z ) {
  2417. this.z = z;
  2418. return this;
  2419. },
  2420. setW: function ( w ) {
  2421. this.w = w;
  2422. return this;
  2423. },
  2424. setComponent: function ( index, value ) {
  2425. switch ( index ) {
  2426. case 0: this.x = value; break;
  2427. case 1: this.y = value; break;
  2428. case 2: this.z = value; break;
  2429. case 3: this.w = value; break;
  2430. default: throw new Error( 'index is out of range: ' + index );
  2431. }
  2432. return this;
  2433. },
  2434. getComponent: function ( index ) {
  2435. switch ( index ) {
  2436. case 0: return this.x;
  2437. case 1: return this.y;
  2438. case 2: return this.z;
  2439. case 3: return this.w;
  2440. default: throw new Error( 'index is out of range: ' + index );
  2441. }
  2442. },
  2443. clone: function () {
  2444. return new this.constructor( this.x, this.y, this.z, this.w );
  2445. },
  2446. copy: function ( v ) {
  2447. this.x = v.x;
  2448. this.y = v.y;
  2449. this.z = v.z;
  2450. this.w = ( v.w !== undefined ) ? v.w : 1;
  2451. return this;
  2452. },
  2453. add: function ( v, w ) {
  2454. if ( w !== undefined ) {
  2455. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  2456. return this.addVectors( v, w );
  2457. }
  2458. this.x += v.x;
  2459. this.y += v.y;
  2460. this.z += v.z;
  2461. this.w += v.w;
  2462. return this;
  2463. },
  2464. addScalar: function ( s ) {
  2465. this.x += s;
  2466. this.y += s;
  2467. this.z += s;
  2468. this.w += s;
  2469. return this;
  2470. },
  2471. addVectors: function ( a, b ) {
  2472. this.x = a.x + b.x;
  2473. this.y = a.y + b.y;
  2474. this.z = a.z + b.z;
  2475. this.w = a.w + b.w;
  2476. return this;
  2477. },
  2478. addScaledVector: function ( v, s ) {
  2479. this.x += v.x * s;
  2480. this.y += v.y * s;
  2481. this.z += v.z * s;
  2482. this.w += v.w * s;
  2483. return this;
  2484. },
  2485. sub: function ( v, w ) {
  2486. if ( w !== undefined ) {
  2487. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  2488. return this.subVectors( v, w );
  2489. }
  2490. this.x -= v.x;
  2491. this.y -= v.y;
  2492. this.z -= v.z;
  2493. this.w -= v.w;
  2494. return this;
  2495. },
  2496. subScalar: function ( s ) {
  2497. this.x -= s;
  2498. this.y -= s;
  2499. this.z -= s;
  2500. this.w -= s;
  2501. return this;
  2502. },
  2503. subVectors: function ( a, b ) {
  2504. this.x = a.x - b.x;
  2505. this.y = a.y - b.y;
  2506. this.z = a.z - b.z;
  2507. this.w = a.w - b.w;
  2508. return this;
  2509. },
  2510. multiplyScalar: function ( scalar ) {
  2511. this.x *= scalar;
  2512. this.y *= scalar;
  2513. this.z *= scalar;
  2514. this.w *= scalar;
  2515. return this;
  2516. },
  2517. applyMatrix4: function ( m ) {
  2518. var x = this.x, y = this.y, z = this.z, w = this.w;
  2519. var e = m.elements;
  2520. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  2521. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  2522. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  2523. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  2524. return this;
  2525. },
  2526. divideScalar: function ( scalar ) {
  2527. return this.multiplyScalar( 1 / scalar );
  2528. },
  2529. setAxisAngleFromQuaternion: function ( q ) {
  2530. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2531. // q is assumed to be normalized
  2532. this.w = 2 * Math.acos( q.w );
  2533. var s = Math.sqrt( 1 - q.w * q.w );
  2534. if ( s < 0.0001 ) {
  2535. this.x = 1;
  2536. this.y = 0;
  2537. this.z = 0;
  2538. } else {
  2539. this.x = q.x / s;
  2540. this.y = q.y / s;
  2541. this.z = q.z / s;
  2542. }
  2543. return this;
  2544. },
  2545. setAxisAngleFromRotationMatrix: function ( m ) {
  2546. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2547. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2548. var angle, x, y, z, // variables for result
  2549. epsilon = 0.01, // margin to allow for rounding errors
  2550. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  2551. te = m.elements,
  2552. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2553. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2554. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2555. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  2556. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2557. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2558. // singularity found
  2559. // first check for identity matrix which must have +1 for all terms
  2560. // in leading diagonal and zero in other terms
  2561. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2562. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2563. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2564. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2565. // this singularity is identity matrix so angle = 0
  2566. this.set( 1, 0, 0, 0 );
  2567. return this; // zero angle, arbitrary axis
  2568. }
  2569. // otherwise this singularity is angle = 180
  2570. angle = Math.PI;
  2571. var xx = ( m11 + 1 ) / 2;
  2572. var yy = ( m22 + 1 ) / 2;
  2573. var zz = ( m33 + 1 ) / 2;
  2574. var xy = ( m12 + m21 ) / 4;
  2575. var xz = ( m13 + m31 ) / 4;
  2576. var yz = ( m23 + m32 ) / 4;
  2577. if ( ( xx > yy ) && ( xx > zz ) ) {
  2578. // m11 is the largest diagonal term
  2579. if ( xx < epsilon ) {
  2580. x = 0;
  2581. y = 0.707106781;
  2582. z = 0.707106781;
  2583. } else {
  2584. x = Math.sqrt( xx );
  2585. y = xy / x;
  2586. z = xz / x;
  2587. }
  2588. } else if ( yy > zz ) {
  2589. // m22 is the largest diagonal term
  2590. if ( yy < epsilon ) {
  2591. x = 0.707106781;
  2592. y = 0;
  2593. z = 0.707106781;
  2594. } else {
  2595. y = Math.sqrt( yy );
  2596. x = xy / y;
  2597. z = yz / y;
  2598. }
  2599. } else {
  2600. // m33 is the largest diagonal term so base result on this
  2601. if ( zz < epsilon ) {
  2602. x = 0.707106781;
  2603. y = 0.707106781;
  2604. z = 0;
  2605. } else {
  2606. z = Math.sqrt( zz );
  2607. x = xz / z;
  2608. y = yz / z;
  2609. }
  2610. }
  2611. this.set( x, y, z, angle );
  2612. return this; // return 180 deg rotation
  2613. }
  2614. // as we have reached here there are no singularities so we can handle normally
  2615. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2616. ( m13 - m31 ) * ( m13 - m31 ) +
  2617. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2618. if ( Math.abs( s ) < 0.001 ) s = 1;
  2619. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2620. // caught by singularity test above, but I've left it in just in case
  2621. this.x = ( m32 - m23 ) / s;
  2622. this.y = ( m13 - m31 ) / s;
  2623. this.z = ( m21 - m12 ) / s;
  2624. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2625. return this;
  2626. },
  2627. min: function ( v ) {
  2628. this.x = Math.min( this.x, v.x );
  2629. this.y = Math.min( this.y, v.y );
  2630. this.z = Math.min( this.z, v.z );
  2631. this.w = Math.min( this.w, v.w );
  2632. return this;
  2633. },
  2634. max: function ( v ) {
  2635. this.x = Math.max( this.x, v.x );
  2636. this.y = Math.max( this.y, v.y );
  2637. this.z = Math.max( this.z, v.z );
  2638. this.w = Math.max( this.w, v.w );
  2639. return this;
  2640. },
  2641. clamp: function ( min, max ) {
  2642. // assumes min < max, componentwise
  2643. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2644. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2645. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2646. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2647. return this;
  2648. },
  2649. clampScalar: function () {
  2650. var min, max;
  2651. return function clampScalar( minVal, maxVal ) {
  2652. if ( min === undefined ) {
  2653. min = new Vector4();
  2654. max = new Vector4();
  2655. }
  2656. min.set( minVal, minVal, minVal, minVal );
  2657. max.set( maxVal, maxVal, maxVal, maxVal );
  2658. return this.clamp( min, max );
  2659. };
  2660. }(),
  2661. clampLength: function ( min, max ) {
  2662. var length = this.length();
  2663. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2664. },
  2665. floor: function () {
  2666. this.x = Math.floor( this.x );
  2667. this.y = Math.floor( this.y );
  2668. this.z = Math.floor( this.z );
  2669. this.w = Math.floor( this.w );
  2670. return this;
  2671. },
  2672. ceil: function () {
  2673. this.x = Math.ceil( this.x );
  2674. this.y = Math.ceil( this.y );
  2675. this.z = Math.ceil( this.z );
  2676. this.w = Math.ceil( this.w );
  2677. return this;
  2678. },
  2679. round: function () {
  2680. this.x = Math.round( this.x );
  2681. this.y = Math.round( this.y );
  2682. this.z = Math.round( this.z );
  2683. this.w = Math.round( this.w );
  2684. return this;
  2685. },
  2686. roundToZero: function () {
  2687. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2688. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2689. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2690. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2691. return this;
  2692. },
  2693. negate: function () {
  2694. this.x = - this.x;
  2695. this.y = - this.y;
  2696. this.z = - this.z;
  2697. this.w = - this.w;
  2698. return this;
  2699. },
  2700. dot: function ( v ) {
  2701. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2702. },
  2703. lengthSq: function () {
  2704. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2705. },
  2706. length: function () {
  2707. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2708. },
  2709. manhattanLength: function () {
  2710. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2711. },
  2712. normalize: function () {
  2713. return this.divideScalar( this.length() || 1 );
  2714. },
  2715. setLength: function ( length ) {
  2716. return this.normalize().multiplyScalar( length );
  2717. },
  2718. lerp: function ( v, alpha ) {
  2719. this.x += ( v.x - this.x ) * alpha;
  2720. this.y += ( v.y - this.y ) * alpha;
  2721. this.z += ( v.z - this.z ) * alpha;
  2722. this.w += ( v.w - this.w ) * alpha;
  2723. return this;
  2724. },
  2725. lerpVectors: function ( v1, v2, alpha ) {
  2726. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2727. },
  2728. equals: function ( v ) {
  2729. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2730. },
  2731. fromArray: function ( array, offset ) {
  2732. if ( offset === undefined ) offset = 0;
  2733. this.x = array[ offset ];
  2734. this.y = array[ offset + 1 ];
  2735. this.z = array[ offset + 2 ];
  2736. this.w = array[ offset + 3 ];
  2737. return this;
  2738. },
  2739. toArray: function ( array, offset ) {
  2740. if ( array === undefined ) array = [];
  2741. if ( offset === undefined ) offset = 0;
  2742. array[ offset ] = this.x;
  2743. array[ offset + 1 ] = this.y;
  2744. array[ offset + 2 ] = this.z;
  2745. array[ offset + 3 ] = this.w;
  2746. return array;
  2747. },
  2748. fromBufferAttribute: function ( attribute, index, offset ) {
  2749. if ( offset !== undefined ) {
  2750. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2751. }
  2752. this.x = attribute.getX( index );
  2753. this.y = attribute.getY( index );
  2754. this.z = attribute.getZ( index );
  2755. this.w = attribute.getW( index );
  2756. return this;
  2757. }
  2758. } );
  2759. /**
  2760. * @author szimek / https://github.com/szimek/
  2761. * @author alteredq / http://alteredqualia.com/
  2762. * @author Marius Kintel / https://github.com/kintel
  2763. */
  2764. /*
  2765. In options, we can specify:
  2766. * Texture parameters for an auto-generated target texture
  2767. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2768. */
  2769. function WebGLRenderTarget( width, height, options ) {
  2770. this.uuid = _Math.generateUUID();
  2771. this.width = width;
  2772. this.height = height;
  2773. this.scissor = new Vector4( 0, 0, width, height );
  2774. this.scissorTest = false;
  2775. this.viewport = new Vector4( 0, 0, width, height );
  2776. options = options || {};
  2777. if ( options.minFilter === undefined ) options.minFilter = LinearFilter;
  2778. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2779. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2780. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2781. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2782. }
  2783. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2784. constructor: WebGLRenderTarget,
  2785. isWebGLRenderTarget: true,
  2786. setSize: function ( width, height ) {
  2787. if ( this.width !== width || this.height !== height ) {
  2788. this.width = width;
  2789. this.height = height;
  2790. this.dispose();
  2791. }
  2792. this.viewport.set( 0, 0, width, height );
  2793. this.scissor.set( 0, 0, width, height );
  2794. },
  2795. clone: function () {
  2796. return new this.constructor().copy( this );
  2797. },
  2798. copy: function ( source ) {
  2799. this.width = source.width;
  2800. this.height = source.height;
  2801. this.viewport.copy( source.viewport );
  2802. this.texture = source.texture.clone();
  2803. this.depthBuffer = source.depthBuffer;
  2804. this.stencilBuffer = source.stencilBuffer;
  2805. this.depthTexture = source.depthTexture;
  2806. return this;
  2807. },
  2808. dispose: function () {
  2809. this.dispatchEvent( { type: 'dispose' } );
  2810. }
  2811. } );
  2812. /**
  2813. * @author alteredq / http://alteredqualia.com
  2814. */
  2815. function WebGLRenderTargetCube( width, height, options ) {
  2816. WebGLRenderTarget.call( this, width, height, options );
  2817. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  2818. this.activeMipMapLevel = 0;
  2819. }
  2820. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  2821. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  2822. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  2823. /**
  2824. * @author alteredq / http://alteredqualia.com/
  2825. */
  2826. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  2827. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  2828. this.image = { data: data, width: width, height: height };
  2829. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  2830. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  2831. this.generateMipmaps = false;
  2832. this.flipY = false;
  2833. this.unpackAlignment = 1;
  2834. }
  2835. DataTexture.prototype = Object.create( Texture.prototype );
  2836. DataTexture.prototype.constructor = DataTexture;
  2837. DataTexture.prototype.isDataTexture = true;
  2838. /**
  2839. * @author mrdoob / http://mrdoob.com/
  2840. */
  2841. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  2842. images = images !== undefined ? images : [];
  2843. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  2844. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  2845. this.flipY = false;
  2846. }
  2847. CubeTexture.prototype = Object.create( Texture.prototype );
  2848. CubeTexture.prototype.constructor = CubeTexture;
  2849. CubeTexture.prototype.isCubeTexture = true;
  2850. Object.defineProperty( CubeTexture.prototype, 'images', {
  2851. get: function () {
  2852. return this.image;
  2853. },
  2854. set: function ( value ) {
  2855. this.image = value;
  2856. }
  2857. } );
  2858. /**
  2859. * @author tschw
  2860. *
  2861. * Uniforms of a program.
  2862. * Those form a tree structure with a special top-level container for the root,
  2863. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  2864. *
  2865. *
  2866. * Properties of inner nodes including the top-level container:
  2867. *
  2868. * .seq - array of nested uniforms
  2869. * .map - nested uniforms by name
  2870. *
  2871. *
  2872. * Methods of all nodes except the top-level container:
  2873. *
  2874. * .setValue( gl, value, [renderer] )
  2875. *
  2876. * uploads a uniform value(s)
  2877. * the 'renderer' parameter is needed for sampler uniforms
  2878. *
  2879. *
  2880. * Static methods of the top-level container (renderer factorizations):
  2881. *
  2882. * .upload( gl, seq, values, renderer )
  2883. *
  2884. * sets uniforms in 'seq' to 'values[id].value'
  2885. *
  2886. * .seqWithValue( seq, values ) : filteredSeq
  2887. *
  2888. * filters 'seq' entries with corresponding entry in values
  2889. *
  2890. *
  2891. * Methods of the top-level container (renderer factorizations):
  2892. *
  2893. * .setValue( gl, name, value )
  2894. *
  2895. * sets uniform with name 'name' to 'value'
  2896. *
  2897. * .set( gl, obj, prop )
  2898. *
  2899. * sets uniform from object and property with same name than uniform
  2900. *
  2901. * .setOptional( gl, obj, prop )
  2902. *
  2903. * like .set for an optional property of the object
  2904. *
  2905. */
  2906. var emptyTexture = new Texture();
  2907. var emptyCubeTexture = new CubeTexture();
  2908. // --- Base for inner nodes (including the root) ---
  2909. function UniformContainer() {
  2910. this.seq = [];
  2911. this.map = {};
  2912. }
  2913. // --- Utilities ---
  2914. // Array Caches (provide typed arrays for temporary by size)
  2915. var arrayCacheF32 = [];
  2916. var arrayCacheI32 = [];
  2917. // Float32Array caches used for uploading Matrix uniforms
  2918. var mat4array = new Float32Array( 16 );
  2919. var mat3array = new Float32Array( 9 );
  2920. // Flattening for arrays of vectors and matrices
  2921. function flatten( array, nBlocks, blockSize ) {
  2922. var firstElem = array[ 0 ];
  2923. if ( firstElem <= 0 || firstElem > 0 ) return array;
  2924. // unoptimized: ! isNaN( firstElem )
  2925. // see http://jacksondunstan.com/articles/983
  2926. var n = nBlocks * blockSize,
  2927. r = arrayCacheF32[ n ];
  2928. if ( r === undefined ) {
  2929. r = new Float32Array( n );
  2930. arrayCacheF32[ n ] = r;
  2931. }
  2932. if ( nBlocks !== 0 ) {
  2933. firstElem.toArray( r, 0 );
  2934. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  2935. offset += blockSize;
  2936. array[ i ].toArray( r, offset );
  2937. }
  2938. }
  2939. return r;
  2940. }
  2941. // Texture unit allocation
  2942. function allocTexUnits( renderer, n ) {
  2943. var r = arrayCacheI32[ n ];
  2944. if ( r === undefined ) {
  2945. r = new Int32Array( n );
  2946. arrayCacheI32[ n ] = r;
  2947. }
  2948. for ( var i = 0; i !== n; ++ i )
  2949. r[ i ] = renderer.allocTextureUnit();
  2950. return r;
  2951. }
  2952. // --- Setters ---
  2953. // Note: Defining these methods externally, because they come in a bunch
  2954. // and this way their names minify.
  2955. // Single scalar
  2956. function setValue1f( gl, v ) {
  2957. gl.uniform1f( this.addr, v );
  2958. }
  2959. function setValue1i( gl, v ) {
  2960. gl.uniform1i( this.addr, v );
  2961. }
  2962. // Single float vector (from flat array or THREE.VectorN)
  2963. function setValue2fv( gl, v ) {
  2964. if ( v.x === undefined ) {
  2965. gl.uniform2fv( this.addr, v );
  2966. } else {
  2967. gl.uniform2f( this.addr, v.x, v.y );
  2968. }
  2969. }
  2970. function setValue3fv( gl, v ) {
  2971. if ( v.x !== undefined ) {
  2972. gl.uniform3f( this.addr, v.x, v.y, v.z );
  2973. } else if ( v.r !== undefined ) {
  2974. gl.uniform3f( this.addr, v.r, v.g, v.b );
  2975. } else {
  2976. gl.uniform3fv( this.addr, v );
  2977. }
  2978. }
  2979. function setValue4fv( gl, v ) {
  2980. if ( v.x === undefined ) {
  2981. gl.uniform4fv( this.addr, v );
  2982. } else {
  2983. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  2984. }
  2985. }
  2986. // Single matrix (from flat array or MatrixN)
  2987. function setValue2fm( gl, v ) {
  2988. gl.uniformMatrix2fv( this.addr, false, v.elements || v );
  2989. }
  2990. function setValue3fm( gl, v ) {
  2991. if ( v.elements === undefined ) {
  2992. gl.uniformMatrix3fv( this.addr, false, v );
  2993. } else {
  2994. mat3array.set( v.elements );
  2995. gl.uniformMatrix3fv( this.addr, false, mat3array );
  2996. }
  2997. }
  2998. function setValue4fm( gl, v ) {
  2999. if ( v.elements === undefined ) {
  3000. gl.uniformMatrix4fv( this.addr, false, v );
  3001. } else {
  3002. mat4array.set( v.elements );
  3003. gl.uniformMatrix4fv( this.addr, false, mat4array );
  3004. }
  3005. }
  3006. // Single texture (2D / Cube)
  3007. function setValueT1( gl, v, renderer ) {
  3008. var unit = renderer.allocTextureUnit();
  3009. gl.uniform1i( this.addr, unit );
  3010. renderer.setTexture2D( v || emptyTexture, unit );
  3011. }
  3012. function setValueT6( gl, v, renderer ) {
  3013. var unit = renderer.allocTextureUnit();
  3014. gl.uniform1i( this.addr, unit );
  3015. renderer.setTextureCube( v || emptyCubeTexture, unit );
  3016. }
  3017. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  3018. function setValue2iv( gl, v ) {
  3019. gl.uniform2iv( this.addr, v );
  3020. }
  3021. function setValue3iv( gl, v ) {
  3022. gl.uniform3iv( this.addr, v );
  3023. }
  3024. function setValue4iv( gl, v ) {
  3025. gl.uniform4iv( this.addr, v );
  3026. }
  3027. // Helper to pick the right setter for the singular case
  3028. function getSingularSetter( type ) {
  3029. switch ( type ) {
  3030. case 0x1406: return setValue1f; // FLOAT
  3031. case 0x8b50: return setValue2fv; // _VEC2
  3032. case 0x8b51: return setValue3fv; // _VEC3
  3033. case 0x8b52: return setValue4fv; // _VEC4
  3034. case 0x8b5a: return setValue2fm; // _MAT2
  3035. case 0x8b5b: return setValue3fm; // _MAT3
  3036. case 0x8b5c: return setValue4fm; // _MAT4
  3037. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  3038. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  3039. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  3040. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  3041. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  3042. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  3043. }
  3044. }
  3045. // Array of scalars
  3046. function setValue1fv( gl, v ) {
  3047. gl.uniform1fv( this.addr, v );
  3048. }
  3049. function setValue1iv( gl, v ) {
  3050. gl.uniform1iv( this.addr, v );
  3051. }
  3052. // Array of vectors (flat or from THREE classes)
  3053. function setValueV2a( gl, v ) {
  3054. gl.uniform2fv( this.addr, flatten( v, this.size, 2 ) );
  3055. }
  3056. function setValueV3a( gl, v ) {
  3057. gl.uniform3fv( this.addr, flatten( v, this.size, 3 ) );
  3058. }
  3059. function setValueV4a( gl, v ) {
  3060. gl.uniform4fv( this.addr, flatten( v, this.size, 4 ) );
  3061. }
  3062. // Array of matrices (flat or from THREE clases)
  3063. function setValueM2a( gl, v ) {
  3064. gl.uniformMatrix2fv( this.addr, false, flatten( v, this.size, 4 ) );
  3065. }
  3066. function setValueM3a( gl, v ) {
  3067. gl.uniformMatrix3fv( this.addr, false, flatten( v, this.size, 9 ) );
  3068. }
  3069. function setValueM4a( gl, v ) {
  3070. gl.uniformMatrix4fv( this.addr, false, flatten( v, this.size, 16 ) );
  3071. }
  3072. // Array of textures (2D / Cube)
  3073. function setValueT1a( gl, v, renderer ) {
  3074. var n = v.length,
  3075. units = allocTexUnits( renderer, n );
  3076. gl.uniform1iv( this.addr, units );
  3077. for ( var i = 0; i !== n; ++ i ) {
  3078. renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
  3079. }
  3080. }
  3081. function setValueT6a( gl, v, renderer ) {
  3082. var n = v.length,
  3083. units = allocTexUnits( renderer, n );
  3084. gl.uniform1iv( this.addr, units );
  3085. for ( var i = 0; i !== n; ++ i ) {
  3086. renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  3087. }
  3088. }
  3089. // Helper to pick the right setter for a pure (bottom-level) array
  3090. function getPureArraySetter( type ) {
  3091. switch ( type ) {
  3092. case 0x1406: return setValue1fv; // FLOAT
  3093. case 0x8b50: return setValueV2a; // _VEC2
  3094. case 0x8b51: return setValueV3a; // _VEC3
  3095. case 0x8b52: return setValueV4a; // _VEC4
  3096. case 0x8b5a: return setValueM2a; // _MAT2
  3097. case 0x8b5b: return setValueM3a; // _MAT3
  3098. case 0x8b5c: return setValueM4a; // _MAT4
  3099. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  3100. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  3101. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  3102. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  3103. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  3104. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  3105. }
  3106. }
  3107. // --- Uniform Classes ---
  3108. function SingleUniform( id, activeInfo, addr ) {
  3109. this.id = id;
  3110. this.addr = addr;
  3111. this.setValue = getSingularSetter( activeInfo.type );
  3112. // this.path = activeInfo.name; // DEBUG
  3113. }
  3114. function PureArrayUniform( id, activeInfo, addr ) {
  3115. this.id = id;
  3116. this.addr = addr;
  3117. this.size = activeInfo.size;
  3118. this.setValue = getPureArraySetter( activeInfo.type );
  3119. // this.path = activeInfo.name; // DEBUG
  3120. }
  3121. function StructuredUniform( id ) {
  3122. this.id = id;
  3123. UniformContainer.call( this ); // mix-in
  3124. }
  3125. StructuredUniform.prototype.setValue = function ( gl, value ) {
  3126. // Note: Don't need an extra 'renderer' parameter, since samplers
  3127. // are not allowed in structured uniforms.
  3128. var seq = this.seq;
  3129. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  3130. var u = seq[ i ];
  3131. u.setValue( gl, value[ u.id ] );
  3132. }
  3133. };
  3134. // --- Top-level ---
  3135. // Parser - builds up the property tree from the path strings
  3136. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  3137. // extracts
  3138. // - the identifier (member name or array index)
  3139. // - followed by an optional right bracket (found when array index)
  3140. // - followed by an optional left bracket or dot (type of subscript)
  3141. //
  3142. // Note: These portions can be read in a non-overlapping fashion and
  3143. // allow straightforward parsing of the hierarchy that WebGL encodes
  3144. // in the uniform names.
  3145. function addUniform( container, uniformObject ) {
  3146. container.seq.push( uniformObject );
  3147. container.map[ uniformObject.id ] = uniformObject;
  3148. }
  3149. function parseUniform( activeInfo, addr, container ) {
  3150. var path = activeInfo.name,
  3151. pathLength = path.length;
  3152. // reset RegExp object, because of the early exit of a previous run
  3153. RePathPart.lastIndex = 0;
  3154. for ( ; ; ) {
  3155. var match = RePathPart.exec( path ),
  3156. matchEnd = RePathPart.lastIndex,
  3157. id = match[ 1 ],
  3158. idIsIndex = match[ 2 ] === ']',
  3159. subscript = match[ 3 ];
  3160. if ( idIsIndex ) id = id | 0; // convert to integer
  3161. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  3162. // bare name or "pure" bottom-level array "[0]" suffix
  3163. addUniform( container, subscript === undefined ?
  3164. new SingleUniform( id, activeInfo, addr ) :
  3165. new PureArrayUniform( id, activeInfo, addr ) );
  3166. break;
  3167. } else {
  3168. // step into inner node / create it in case it doesn't exist
  3169. var map = container.map, next = map[ id ];
  3170. if ( next === undefined ) {
  3171. next = new StructuredUniform( id );
  3172. addUniform( container, next );
  3173. }
  3174. container = next;
  3175. }
  3176. }
  3177. }
  3178. // Root Container
  3179. function WebGLUniforms( gl, program, renderer ) {
  3180. UniformContainer.call( this );
  3181. this.renderer = renderer;
  3182. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  3183. for ( var i = 0; i < n; ++ i ) {
  3184. var info = gl.getActiveUniform( program, i ),
  3185. path = info.name,
  3186. addr = gl.getUniformLocation( program, path );
  3187. parseUniform( info, addr, this );
  3188. }
  3189. }
  3190. WebGLUniforms.prototype.setValue = function ( gl, name, value ) {
  3191. var u = this.map[ name ];
  3192. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  3193. };
  3194. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  3195. var v = object[ name ];
  3196. if ( v !== undefined ) this.setValue( gl, name, v );
  3197. };
  3198. // Static interface
  3199. WebGLUniforms.upload = function ( gl, seq, values, renderer ) {
  3200. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  3201. var u = seq[ i ],
  3202. v = values[ u.id ];
  3203. if ( v.needsUpdate !== false ) {
  3204. // note: always updating when .needsUpdate is undefined
  3205. u.setValue( gl, v.value, renderer );
  3206. }
  3207. }
  3208. };
  3209. WebGLUniforms.seqWithValue = function ( seq, values ) {
  3210. var r = [];
  3211. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  3212. var u = seq[ i ];
  3213. if ( u.id in values ) r.push( u );
  3214. }
  3215. return r;
  3216. };
  3217. /**
  3218. * @author mrdoob / http://mrdoob.com/
  3219. */
  3220. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  3221. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  3222. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  3223. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  3224. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  3225. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  3226. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  3227. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  3228. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  3229. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  3230. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  3231. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  3232. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  3233. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  3234. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  3235. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  3236. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  3237. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  3238. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  3239. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  3240. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  3241. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  3242. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  3243. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  3244. function Color( r, g, b ) {
  3245. if ( g === undefined && b === undefined ) {
  3246. // r is THREE.Color, hex or string
  3247. return this.set( r );
  3248. }
  3249. return this.setRGB( r, g, b );
  3250. }
  3251. Object.assign( Color.prototype, {
  3252. isColor: true,
  3253. r: 1, g: 1, b: 1,
  3254. set: function ( value ) {
  3255. if ( value && value.isColor ) {
  3256. this.copy( value );
  3257. } else if ( typeof value === 'number' ) {
  3258. this.setHex( value );
  3259. } else if ( typeof value === 'string' ) {
  3260. this.setStyle( value );
  3261. }
  3262. return this;
  3263. },
  3264. setScalar: function ( scalar ) {
  3265. this.r = scalar;
  3266. this.g = scalar;
  3267. this.b = scalar;
  3268. return this;
  3269. },
  3270. setHex: function ( hex ) {
  3271. hex = Math.floor( hex );
  3272. this.r = ( hex >> 16 & 255 ) / 255;
  3273. this.g = ( hex >> 8 & 255 ) / 255;
  3274. this.b = ( hex & 255 ) / 255;
  3275. return this;
  3276. },
  3277. setRGB: function ( r, g, b ) {
  3278. this.r = r;
  3279. this.g = g;
  3280. this.b = b;
  3281. return this;
  3282. },
  3283. setHSL: function () {
  3284. function hue2rgb( p, q, t ) {
  3285. if ( t < 0 ) t += 1;
  3286. if ( t > 1 ) t -= 1;
  3287. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  3288. if ( t < 1 / 2 ) return q;
  3289. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  3290. return p;
  3291. }
  3292. return function setHSL( h, s, l ) {
  3293. // h,s,l ranges are in 0.0 - 1.0
  3294. h = _Math.euclideanModulo( h, 1 );
  3295. s = _Math.clamp( s, 0, 1 );
  3296. l = _Math.clamp( l, 0, 1 );
  3297. if ( s === 0 ) {
  3298. this.r = this.g = this.b = l;
  3299. } else {
  3300. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  3301. var q = ( 2 * l ) - p;
  3302. this.r = hue2rgb( q, p, h + 1 / 3 );
  3303. this.g = hue2rgb( q, p, h );
  3304. this.b = hue2rgb( q, p, h - 1 / 3 );
  3305. }
  3306. return this;
  3307. };
  3308. }(),
  3309. setStyle: function ( style ) {
  3310. function handleAlpha( string ) {
  3311. if ( string === undefined ) return;
  3312. if ( parseFloat( string ) < 1 ) {
  3313. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  3314. }
  3315. }
  3316. var m;
  3317. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  3318. // rgb / hsl
  3319. var color;
  3320. var name = m[ 1 ];
  3321. var components = m[ 2 ];
  3322. switch ( name ) {
  3323. case 'rgb':
  3324. case 'rgba':
  3325. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3326. // rgb(255,0,0) rgba(255,0,0,0.5)
  3327. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  3328. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  3329. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  3330. handleAlpha( color[ 5 ] );
  3331. return this;
  3332. }
  3333. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3334. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  3335. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  3336. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  3337. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  3338. handleAlpha( color[ 5 ] );
  3339. return this;
  3340. }
  3341. break;
  3342. case 'hsl':
  3343. case 'hsla':
  3344. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3345. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  3346. var h = parseFloat( color[ 1 ] ) / 360;
  3347. var s = parseInt( color[ 2 ], 10 ) / 100;
  3348. var l = parseInt( color[ 3 ], 10 ) / 100;
  3349. handleAlpha( color[ 5 ] );
  3350. return this.setHSL( h, s, l );
  3351. }
  3352. break;
  3353. }
  3354. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  3355. // hex color
  3356. var hex = m[ 1 ];
  3357. var size = hex.length;
  3358. if ( size === 3 ) {
  3359. // #ff0
  3360. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  3361. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  3362. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  3363. return this;
  3364. } else if ( size === 6 ) {
  3365. // #ff0000
  3366. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  3367. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  3368. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  3369. return this;
  3370. }
  3371. }
  3372. if ( style && style.length > 0 ) {
  3373. // color keywords
  3374. var hex = ColorKeywords[ style ];
  3375. if ( hex !== undefined ) {
  3376. // red
  3377. this.setHex( hex );
  3378. } else {
  3379. // unknown color
  3380. console.warn( 'THREE.Color: Unknown color ' + style );
  3381. }
  3382. }
  3383. return this;
  3384. },
  3385. clone: function () {
  3386. return new this.constructor( this.r, this.g, this.b );
  3387. },
  3388. copy: function ( color ) {
  3389. this.r = color.r;
  3390. this.g = color.g;
  3391. this.b = color.b;
  3392. return this;
  3393. },
  3394. copyGammaToLinear: function ( color, gammaFactor ) {
  3395. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  3396. this.r = Math.pow( color.r, gammaFactor );
  3397. this.g = Math.pow( color.g, gammaFactor );
  3398. this.b = Math.pow( color.b, gammaFactor );
  3399. return this;
  3400. },
  3401. copyLinearToGamma: function ( color, gammaFactor ) {
  3402. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  3403. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  3404. this.r = Math.pow( color.r, safeInverse );
  3405. this.g = Math.pow( color.g, safeInverse );
  3406. this.b = Math.pow( color.b, safeInverse );
  3407. return this;
  3408. },
  3409. convertGammaToLinear: function () {
  3410. var r = this.r, g = this.g, b = this.b;
  3411. this.r = r * r;
  3412. this.g = g * g;
  3413. this.b = b * b;
  3414. return this;
  3415. },
  3416. convertLinearToGamma: function () {
  3417. this.r = Math.sqrt( this.r );
  3418. this.g = Math.sqrt( this.g );
  3419. this.b = Math.sqrt( this.b );
  3420. return this;
  3421. },
  3422. getHex: function () {
  3423. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  3424. },
  3425. getHexString: function () {
  3426. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  3427. },
  3428. getHSL: function ( optionalTarget ) {
  3429. // h,s,l ranges are in 0.0 - 1.0
  3430. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  3431. var r = this.r, g = this.g, b = this.b;
  3432. var max = Math.max( r, g, b );
  3433. var min = Math.min( r, g, b );
  3434. var hue, saturation;
  3435. var lightness = ( min + max ) / 2.0;
  3436. if ( min === max ) {
  3437. hue = 0;
  3438. saturation = 0;
  3439. } else {
  3440. var delta = max - min;
  3441. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  3442. switch ( max ) {
  3443. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  3444. case g: hue = ( b - r ) / delta + 2; break;
  3445. case b: hue = ( r - g ) / delta + 4; break;
  3446. }
  3447. hue /= 6;
  3448. }
  3449. hsl.h = hue;
  3450. hsl.s = saturation;
  3451. hsl.l = lightness;
  3452. return hsl;
  3453. },
  3454. getStyle: function () {
  3455. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  3456. },
  3457. offsetHSL: function ( h, s, l ) {
  3458. var hsl = this.getHSL();
  3459. hsl.h += h; hsl.s += s; hsl.l += l;
  3460. this.setHSL( hsl.h, hsl.s, hsl.l );
  3461. return this;
  3462. },
  3463. add: function ( color ) {
  3464. this.r += color.r;
  3465. this.g += color.g;
  3466. this.b += color.b;
  3467. return this;
  3468. },
  3469. addColors: function ( color1, color2 ) {
  3470. this.r = color1.r + color2.r;
  3471. this.g = color1.g + color2.g;
  3472. this.b = color1.b + color2.b;
  3473. return this;
  3474. },
  3475. addScalar: function ( s ) {
  3476. this.r += s;
  3477. this.g += s;
  3478. this.b += s;
  3479. return this;
  3480. },
  3481. sub: function ( color ) {
  3482. this.r = Math.max( 0, this.r - color.r );
  3483. this.g = Math.max( 0, this.g - color.g );
  3484. this.b = Math.max( 0, this.b - color.b );
  3485. return this;
  3486. },
  3487. multiply: function ( color ) {
  3488. this.r *= color.r;
  3489. this.g *= color.g;
  3490. this.b *= color.b;
  3491. return this;
  3492. },
  3493. multiplyScalar: function ( s ) {
  3494. this.r *= s;
  3495. this.g *= s;
  3496. this.b *= s;
  3497. return this;
  3498. },
  3499. lerp: function ( color, alpha ) {
  3500. this.r += ( color.r - this.r ) * alpha;
  3501. this.g += ( color.g - this.g ) * alpha;
  3502. this.b += ( color.b - this.b ) * alpha;
  3503. return this;
  3504. },
  3505. equals: function ( c ) {
  3506. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  3507. },
  3508. fromArray: function ( array, offset ) {
  3509. if ( offset === undefined ) offset = 0;
  3510. this.r = array[ offset ];
  3511. this.g = array[ offset + 1 ];
  3512. this.b = array[ offset + 2 ];
  3513. return this;
  3514. },
  3515. toArray: function ( array, offset ) {
  3516. if ( array === undefined ) array = [];
  3517. if ( offset === undefined ) offset = 0;
  3518. array[ offset ] = this.r;
  3519. array[ offset + 1 ] = this.g;
  3520. array[ offset + 2 ] = this.b;
  3521. return array;
  3522. },
  3523. toJSON: function () {
  3524. return this.getHex();
  3525. }
  3526. } );
  3527. /**
  3528. * Uniforms library for shared webgl shaders
  3529. */
  3530. var UniformsLib = {
  3531. common: {
  3532. diffuse: { value: new Color( 0xeeeeee ) },
  3533. opacity: { value: 1.0 },
  3534. map: { value: null },
  3535. uvTransform: { value: new Matrix3() },
  3536. alphaMap: { value: null },
  3537. },
  3538. specularmap: {
  3539. specularMap: { value: null },
  3540. },
  3541. envmap: {
  3542. envMap: { value: null },
  3543. flipEnvMap: { value: - 1 },
  3544. reflectivity: { value: 1.0 },
  3545. refractionRatio: { value: 0.98 }
  3546. },
  3547. aomap: {
  3548. aoMap: { value: null },
  3549. aoMapIntensity: { value: 1 }
  3550. },
  3551. lightmap: {
  3552. lightMap: { value: null },
  3553. lightMapIntensity: { value: 1 }
  3554. },
  3555. emissivemap: {
  3556. emissiveMap: { value: null }
  3557. },
  3558. bumpmap: {
  3559. bumpMap: { value: null },
  3560. bumpScale: { value: 1 }
  3561. },
  3562. normalmap: {
  3563. normalMap: { value: null },
  3564. normalScale: { value: new Vector2( 1, 1 ) }
  3565. },
  3566. displacementmap: {
  3567. displacementMap: { value: null },
  3568. displacementScale: { value: 1 },
  3569. displacementBias: { value: 0 }
  3570. },
  3571. roughnessmap: {
  3572. roughnessMap: { value: null }
  3573. },
  3574. metalnessmap: {
  3575. metalnessMap: { value: null }
  3576. },
  3577. gradientmap: {
  3578. gradientMap: { value: null }
  3579. },
  3580. fog: {
  3581. fogDensity: { value: 0.00025 },
  3582. fogNear: { value: 1 },
  3583. fogFar: { value: 2000 },
  3584. fogColor: { value: new Color( 0xffffff ) }
  3585. },
  3586. lights: {
  3587. ambientLightColor: { value: [] },
  3588. directionalLights: { value: [], properties: {
  3589. direction: {},
  3590. color: {},
  3591. shadow: {},
  3592. shadowBias: {},
  3593. shadowRadius: {},
  3594. shadowMapSize: {}
  3595. } },
  3596. directionalShadowMap: { value: [] },
  3597. directionalShadowMatrix: { value: [] },
  3598. spotLights: { value: [], properties: {
  3599. color: {},
  3600. position: {},
  3601. direction: {},
  3602. distance: {},
  3603. coneCos: {},
  3604. penumbraCos: {},
  3605. decay: {},
  3606. shadow: {},
  3607. shadowBias: {},
  3608. shadowRadius: {},
  3609. shadowMapSize: {}
  3610. } },
  3611. spotShadowMap: { value: [] },
  3612. spotShadowMatrix: { value: [] },
  3613. pointLights: { value: [], properties: {
  3614. color: {},
  3615. position: {},
  3616. decay: {},
  3617. distance: {},
  3618. shadow: {},
  3619. shadowBias: {},
  3620. shadowRadius: {},
  3621. shadowMapSize: {},
  3622. shadowCameraNear: {},
  3623. shadowCameraFar: {}
  3624. } },
  3625. pointShadowMap: { value: [] },
  3626. pointShadowMatrix: { value: [] },
  3627. hemisphereLights: { value: [], properties: {
  3628. direction: {},
  3629. skyColor: {},
  3630. groundColor: {}
  3631. } },
  3632. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  3633. rectAreaLights: { value: [], properties: {
  3634. color: {},
  3635. position: {},
  3636. width: {},
  3637. height: {}
  3638. } }
  3639. },
  3640. points: {
  3641. diffuse: { value: new Color( 0xeeeeee ) },
  3642. opacity: { value: 1.0 },
  3643. size: { value: 1.0 },
  3644. scale: { value: 1.0 },
  3645. map: { value: null },
  3646. uvTransform: { value: new Matrix3() }
  3647. }
  3648. };
  3649. /**
  3650. * Uniform Utilities
  3651. */
  3652. var UniformsUtils = {
  3653. merge: function ( uniforms ) {
  3654. var merged = {};
  3655. for ( var u = 0; u < uniforms.length; u ++ ) {
  3656. var tmp = this.clone( uniforms[ u ] );
  3657. for ( var p in tmp ) {
  3658. merged[ p ] = tmp[ p ];
  3659. }
  3660. }
  3661. return merged;
  3662. },
  3663. clone: function ( uniforms_src ) {
  3664. var uniforms_dst = {};
  3665. for ( var u in uniforms_src ) {
  3666. uniforms_dst[ u ] = {};
  3667. for ( var p in uniforms_src[ u ] ) {
  3668. var parameter_src = uniforms_src[ u ][ p ];
  3669. if ( parameter_src && ( parameter_src.isColor ||
  3670. parameter_src.isMatrix3 || parameter_src.isMatrix4 ||
  3671. parameter_src.isVector2 || parameter_src.isVector3 || parameter_src.isVector4 ||
  3672. parameter_src.isTexture ) ) {
  3673. uniforms_dst[ u ][ p ] = parameter_src.clone();
  3674. } else if ( Array.isArray( parameter_src ) ) {
  3675. uniforms_dst[ u ][ p ] = parameter_src.slice();
  3676. } else {
  3677. uniforms_dst[ u ][ p ] = parameter_src;
  3678. }
  3679. }
  3680. }
  3681. return uniforms_dst;
  3682. }
  3683. };
  3684. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  3685. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif\n";
  3686. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  3687. var aomap_fragment = "#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_ENVMAP ) && defined( PHYSICAL )\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n\t#endif\n#endif\n";
  3688. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  3689. var begin_vertex = "\nvec3 transformed = vec3( position );\n";
  3690. var beginnormal_vertex = "\nvec3 objectNormal = vec3( normal );\n";
  3691. var bsdfs = "float punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\tif( decayExponent > 0.0 ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\t\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\t\tfloat maxDistanceCutoffFactor = pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t\treturn distanceFalloff * maxDistanceCutoffFactor;\n#else\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n#endif\n\t}\n\treturn 1.0;\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\tvec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n\treturn specularColor * AB.x + AB.y;\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n";
  3692. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 );\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif\n";
  3693. var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vViewPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vViewPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\tif ( clipped ) discard;\n\t#endif\n#endif\n";
  3694. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\t#if ! defined( PHYSICAL ) && ! defined( PHONG )\n\t\tvarying vec3 vViewPosition;\n\t#endif\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif\n";
  3695. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n\tvarying vec3 vViewPosition;\n#endif\n";
  3696. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n";
  3697. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  3698. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif\n";
  3699. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3700. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  3701. var common = "#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract(sin(sn) * c);\n}\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}\n";
  3702. var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_textureSize (1024.0)\nint getFaceFromDirection(vec3 direction) {\n\tvec3 absDirection = abs(direction);\n\tint face = -1;\n\tif( absDirection.x > absDirection.z ) {\n\t\tif(absDirection.x > absDirection.y )\n\t\t\tface = direction.x > 0.0 ? 0 : 3;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\telse {\n\t\tif(absDirection.z > absDirection.y )\n\t\t\tface = direction.z > 0.0 ? 2 : 5;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\treturn face;\n}\n#define cubeUV_maxLods1 (log2(cubeUV_textureSize*0.25) - 1.0)\n#define cubeUV_rangeClamp (exp2((6.0 - 1.0) * 2.0))\nvec2 MipLevelInfo( vec3 vec, float roughnessLevel, float roughness ) {\n\tfloat scale = exp2(cubeUV_maxLods1 - roughnessLevel);\n\tfloat dxRoughness = dFdx(roughness);\n\tfloat dyRoughness = dFdy(roughness);\n\tvec3 dx = dFdx( vec * scale * dxRoughness );\n\tvec3 dy = dFdy( vec * scale * dyRoughness );\n\tfloat d = max( dot( dx, dx ), dot( dy, dy ) );\n\td = clamp(d, 1.0, cubeUV_rangeClamp);\n\tfloat mipLevel = 0.5 * log2(d);\n\treturn vec2(floor(mipLevel), fract(mipLevel));\n}\n#define cubeUV_maxLods2 (log2(cubeUV_textureSize*0.25) - 2.0)\n#define cubeUV_rcpTextureSize (1.0 / cubeUV_textureSize)\nvec2 getCubeUV(vec3 direction, float roughnessLevel, float mipLevel) {\n\tmipLevel = roughnessLevel > cubeUV_maxLods2 - 3.0 ? 0.0 : mipLevel;\n\tfloat a = 16.0 * cubeUV_rcpTextureSize;\n\tvec2 exp2_packed = exp2( vec2( roughnessLevel, mipLevel ) );\n\tvec2 rcp_exp2_packed = vec2( 1.0 ) / exp2_packed;\n\tfloat powScale = exp2_packed.x * exp2_packed.y;\n\tfloat scale = rcp_exp2_packed.x * rcp_exp2_packed.y * 0.25;\n\tfloat mipOffset = 0.75*(1.0 - rcp_exp2_packed.y) * rcp_exp2_packed.x;\n\tbool bRes = mipLevel == 0.0;\n\tscale = bRes && (scale < a) ? a : scale;\n\tvec3 r;\n\tvec2 offset;\n\tint face = getFaceFromDirection(direction);\n\tfloat rcpPowScale = 1.0 / powScale;\n\tif( face == 0) {\n\t\tr = vec3(direction.x, -direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 1) {\n\t\tr = vec3(direction.y, direction.x, direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 2) {\n\t\tr = vec3(direction.z, direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 3) {\n\t\tr = vec3(direction.x, direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse if( face == 4) {\n\t\tr = vec3(direction.y, direction.x, -direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse {\n\t\tr = vec3(direction.z, -direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\tr = normalize(r);\n\tfloat texelOffset = 0.5 * cubeUV_rcpTextureSize;\n\tvec2 s = ( r.yz / abs( r.x ) + vec2( 1.0 ) ) * 0.5;\n\tvec2 base = offset + vec2( texelOffset );\n\treturn base + s * ( scale - 2.0 * texelOffset );\n}\n#define cubeUV_maxLods3 (log2(cubeUV_textureSize*0.25) - 3.0)\nvec4 textureCubeUV(vec3 reflectedDirection, float roughness ) {\n\tfloat roughnessVal = roughness* cubeUV_maxLods3;\n\tfloat r1 = floor(roughnessVal);\n\tfloat r2 = r1 + 1.0;\n\tfloat t = fract(roughnessVal);\n\tvec2 mipInfo = MipLevelInfo(reflectedDirection, r1, roughness);\n\tfloat s = mipInfo.y;\n\tfloat level0 = mipInfo.x;\n\tfloat level1 = level0 + 1.0;\n\tlevel1 = level1 > 5.0 ? 5.0 : level1;\n\tlevel0 += min( floor( s + 0.5 ), 5.0 );\n\tvec2 uv_10 = getCubeUV(reflectedDirection, r1, level0);\n\tvec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));\n\tvec2 uv_20 = getCubeUV(reflectedDirection, r2, level0);\n\tvec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));\n\tvec4 result = mix(color10, color20, t);\n\treturn vec4(result.rgb, 1.0);\n}\n#endif\n";
  3703. var defaultnormal_vertex = "vec3 transformedNormal = normalMatrix * objectNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n";
  3704. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif\n";
  3705. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  3706. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif\n";
  3707. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif\n";
  3708. var encodings_fragment = " gl_FragColor = linearToOutputTexel( gl_FragColor );\n";
  3709. var encodings_pars_fragment = "\nvec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );\n}\nvec4 sRGBToLinear( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.w );\n}\nvec4 RGBEToLinear( in vec4 value ) {\n\treturn vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n}\nvec4 LinearToRGBE( in vec4 value ) {\n\tfloat maxComponent = max( max( value.r, value.g ), value.b );\n\tfloat fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n\treturn vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n}\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.xyz * value.w * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.x, max( value.g, value.b ) );\n\tfloat M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n\tM = ceil( M * 255.0 ) / 255.0;\n\treturn vec4( value.rgb / ( M * maxRange ), M );\n}\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n}\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.x, max( value.g, value.b ) );\n\tfloat D = max( maxRange / maxRGB, 1.0 );\n\tD = min( floor( D ) / 255.0, 1.0 );\n\treturn vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\n}\nconst mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );\nvec4 LinearToLogLuv( in vec4 value ) {\n\tvec3 Xp_Y_XYZp = value.rgb * cLogLuvM;\n\tXp_Y_XYZp = max(Xp_Y_XYZp, vec3(1e-6, 1e-6, 1e-6));\n\tvec4 vResult;\n\tvResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\n\tfloat Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\n\tvResult.w = fract(Le);\n\tvResult.z = (Le - (floor(vResult.w*255.0))/255.0)/255.0;\n\treturn vResult;\n}\nconst mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );\nvec4 LogLuvToLinear( in vec4 value ) {\n\tfloat Le = value.z * 255.0 + value.w;\n\tvec3 Xp_Y_XYZp;\n\tXp_Y_XYZp.y = exp2((Le - 127.0) / 2.0);\n\tXp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\n\tXp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\n\tvec3 vRGB = Xp_Y_XYZp.rgb * cLogLuvInverseM;\n\treturn vec4( max(vRGB, 0.0), 1.0 );\n}\n";
  3710. var envmap_fragment = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\tvec2 sampleUV;\n\t\treflectVec = normalize( reflectVec );\n\t\tsampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n\t\tvec4 envColor = texture2D( envMap, sampleUV );\n\t#elif defined( ENVMAP_TYPE_SPHERE )\n\t\treflectVec = normalize( reflectVec );\n\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) );\n\t\tvec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\tenvColor = envMapTexelToLinear( envColor );\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif\n";
  3711. var envmap_pars_fragment = "#if defined( USE_ENVMAP ) || defined( PHYSICAL )\n\tuniform float reflectivity;\n\tuniform float envMapIntensity;\n#endif\n#ifdef USE_ENVMAP\n\t#if ! defined( PHYSICAL ) && ( defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) )\n\t\tvarying vec3 vWorldPosition;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\tuniform float flipEnvMap;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif\n";
  3712. var envmap_pars_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif\n";
  3713. var envmap_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif\n";
  3714. var fog_vertex = "\n#ifdef USE_FOG\nfogDepth = -mvPosition.z;\n#endif";
  3715. var fog_pars_vertex = "#ifdef USE_FOG\n varying float fogDepth;\n#endif\n";
  3716. var fog_fragment = "#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * fogDepth * fogDepth * LOG2 ) );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, fogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif\n";
  3717. var fog_pars_fragment = "#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float fogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif\n";
  3718. var gradientmap_pars_fragment = "#ifdef TOON\n\tuniform sampler2D gradientMap;\n\tvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\t\tfloat dotNL = dot( normal, lightDirection );\n\t\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t\t#ifdef USE_GRADIENTMAP\n\t\t\treturn texture2D( gradientMap, coord ).rgb;\n\t\t#else\n\t\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n\t\t#endif\n\t}\n#endif\n";
  3719. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  3720. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  3721. var lights_lambert_vertex = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n#endif\n#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tgetDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n\t\t#endif\n\t}\n#endif\n";
  3722. var lights_pars = "uniform vec3 ambientLightColor;\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treturn irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tdirectLight.color = directionalLight.color;\n\t\tdirectLight.direction = directionalLight.direction;\n\t\tdirectLight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t\tfloat shadowCameraNear;\n\t\tfloat shadowCameraFar;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tdirectLight.color = pointLight.color;\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n\t\tdirectLight.visible = ( directLight.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\n\t\tif ( angleCos > spotLight.coneCos ) {\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\t\tdirectLight.color = spotLight.color;\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tdirectLight.visible = true;\n\t\t} else {\n\t\t\tdirectLight.color = vec3( 0.0 );\n\t\t\tdirectLight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tirradiance *= PI;\n\t\t#endif\n\t\treturn irradiance;\n\t}\n#endif\n#if defined( USE_ENVMAP ) && defined( PHYSICAL )\n\tvec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n\t\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\tvec4 envMapColor = textureCubeUV( queryVec, 1.0 );\n\t\t#else\n\t\t\tvec4 envMapColor = vec4( 0.0 );\n\t\t#endif\n\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t}\n\tfloat getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar + 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n\t}\n\tvec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\n\t\t#endif\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\tvec4 envMapColor = textureCubeUV(queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent));\n\t\t#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\t\tvec2 sampleUV;\n\t\t\tsampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\t\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_SPHERE )\n\t\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif\n";
  3723. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  3724. var lights_phong_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n\tvec3\tdiffuseColor;\n\tvec3\tspecularColor;\n\tfloat\tspecularShininess;\n\tfloat\tspecularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\t#ifdef TOON\n\t\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\n\t#else\n\t\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\t\tvec3 irradiance = dotNL * directLight.color;\n\t#endif\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material )\t(0)\n";
  3725. var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );\n#ifdef STANDARD\n\tmaterial.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.clearCoat = saturate( clearCoat );\tmaterial.clearCoatRoughness = clamp( clearCoatRoughness, 0.04, 1.0 );\n#endif\n";
  3726. var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3\tdiffuseColor;\n\tfloat\tspecularRoughness;\n\tvec3\tspecularColor;\n\t#ifndef STANDARD\n\t\tfloat clearCoat;\n\t\tfloat clearCoatRoughness;\n\t#endif\n};\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\nfloat clearCoatDHRApprox( const in float roughness, const in float dotNL ) {\n\treturn DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.specularRoughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos - halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos + halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos + halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos - halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\t#ifndef STANDARD\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\treflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n\treflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\t#ifndef STANDARD\n\t\treflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 clearCoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t#ifndef STANDARD\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\tfloat dotNL = dotNV;\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\treflectedLight.indirectSpecular += ( 1.0 - clearCoatDHR ) * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n\t#ifndef STANDARD\n\t\treflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\n#define Material_ClearCoat_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.clearCoatRoughness )\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}\n";
  3727. var lights_template = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = normalize( vViewPosition );\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotDirectLightIrradiance( spotLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#ifdef USE_LIGHTMAP\n\t\tvec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t}\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( PHYSICAL ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tirradiance += getLightProbeIndirectIrradiance( geometry, 8 );\n\t#endif\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tvec3 radiance = getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), 8 );\n\t#ifndef STANDARD\n\t\tvec3 clearCoatRadiance = getLightProbeIndirectRadiance( geometry, Material_ClearCoat_BlinnShininessExponent( material ), 8 );\n\t#else\n\t\tvec3 clearCoatRadiance = vec3( 0.0 );\n\t#endif\n\tRE_IndirectSpecular( radiance, clearCoatRadiance, geometry, material, reflectedLight );\n#endif\n";
  3728. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  3729. var logdepthbuf_pars_fragment = "#ifdef USE_LOGDEPTHBUF\n\tuniform float logDepthBufFC;\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t#endif\n#endif\n";
  3730. var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t#endif\n\tuniform float logDepthBufFC;\n#endif";
  3731. var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t#else\n\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\tgl_Position.z *= gl_Position.w;\n\t#endif\n#endif\n";
  3732. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif\n";
  3733. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n";
  3734. var map_particle_fragment = "#ifdef USE_MAP\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n\tvec4 mapTexel = texture2D( map, uv );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n";
  3735. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif\n";
  3736. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif\n";
  3737. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  3738. var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n\tobjectNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n\tobjectNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n\tobjectNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n\tobjectNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n#endif\n";
  3739. var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\t#ifndef USE_MORPHNORMALS\n\tuniform float morphTargetInfluences[ 8 ];\n\t#else\n\tuniform float morphTargetInfluences[ 4 ];\n\t#endif\n#endif";
  3740. var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n\ttransformed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n\ttransformed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n\ttransformed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n\t#ifndef USE_MORPHNORMALS\n\ttransformed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n\ttransformed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n\ttransformed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n\ttransformed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n\t#endif\n#endif\n";
  3741. var normal_fragment = "#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n#endif\n#ifdef USE_NORMALMAP\n\tnormal = perturbNormal2Arb( -vViewPosition, normal );\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif\n";
  3742. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tvec3 S = normalize( q0 * st1.t - q1 * st0.t );\n\t\tvec3 T = normalize( -q0 * st1.s + q1 * st0.s );\n\t\tvec3 N = normalize( surf_norm );\n\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\tmapN.xy = normalScale * mapN.xy;\n\t\tmat3 tsn = mat3( S, T, N );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif\n";
  3743. var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n\treturn linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn (( near + viewZ ) * far ) / (( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\n}\n";
  3744. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif\n";
  3745. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;\n";
  3746. var dithering_fragment = "#if defined( DITHERING )\n gl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif\n";
  3747. var dithering_pars_fragment = "#if defined( DITHERING )\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif\n";
  3748. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif\n";
  3749. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  3750. var shadowmap_pars_fragment = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tfloat texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\n\t\tconst vec2 offset = vec2( 0.0, 1.0 );\n\t\tvec2 texelSize = vec2( 1.0 ) / size;\n\t\tvec2 centroidUV = floor( uv * size + 0.5 ) / size;\n\t\tfloat lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\n\t\tfloat lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\n\t\tfloat rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\n\t\tfloat rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\n\t\tvec2 f = fract( uv * size + 0.5 );\n\t\tfloat a = mix( lb, lt, f.y );\n\t\tfloat b = mix( rb, rt, f.y );\n\t\tfloat c = mix( a, b, f.x );\n\t\treturn c;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n\t\tbool inFrustum = all( inFrustumVec );\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\t\tbool frustumTest = all( frustumTestVec );\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tshadow = (\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn shadow;\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\n\t}\n#endif\n";
  3751. var shadowmap_pars_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHTS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHTS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHTS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n\t#endif\n#endif\n";
  3752. var shadowmap_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n#endif\n";
  3753. var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\tDirectionalLight directionalLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tshadow *= bool( directionalLight.shadow ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\tSpotLight spotLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tshadow *= bool( spotLight.shadow ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\tPointLight pointLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tshadow *= bool( pointLight.shadow ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#endif\n\t#endif\n\treturn shadow;\n}\n";
  3754. var skinbase_vertex = "#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";
  3755. var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif\n";
  3756. var skinning_vertex = "#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif\n";
  3757. var skinnormal_vertex = "#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n#endif\n";
  3758. var specularmap_fragment = "float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif";
  3759. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  3760. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif\n";
  3761. var tonemapping_pars_fragment = "#ifndef saturate\n\t#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nuniform float toneMappingWhitePoint;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\nvec3 Uncharted2ToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\n";
  3762. var uv_pars_fragment = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvarying vec2 vUv;\n#endif";
  3763. var uv_pars_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvarying vec2 vUv;\n\tuniform mat3 uvTransform;\n#endif\n";
  3764. var uv_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  3765. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  3766. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  3767. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  3768. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif\n";
  3769. var cube_frag = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldPosition;\nvoid main() {\n\tgl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\n\tgl_FragColor.a *= opacity;\n}\n";
  3770. var cube_vert = "varying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tvWorldPosition = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}\n";
  3771. var depth_frag = "#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <logdepthbuf_fragment>\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( gl_FragCoord.z ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( gl_FragCoord.z );\n\t#endif\n}\n";
  3772. var depth_vert = "#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n}\n";
  3773. var distanceRGBA_frag = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}\n";
  3774. var distanceRGBA_vert = "#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}\n";
  3775. var equirect_frag = "uniform sampler2D tEquirect;\nvarying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldPosition );\n\tvec2 sampleUV;\n\tsampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\tsampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\n}\n";
  3776. var equirect_vert = "varying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tvWorldPosition = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}\n";
  3777. var linedashed_frag = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}\n";
  3778. var linedashed_vert = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\tvLineDistance = scale * lineDistance;\n\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}\n";
  3779. var meshbasic_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\treflectedLight.indirectDiffuse += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}\n";
  3780. var meshbasic_vert = "#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_ENVMAP\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}\n";
  3781. var meshlambert_frag = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <bsdfs>\n#include <lights_pars>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <emissivemap_fragment>\n\treflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );\n\t#include <lightmap_fragment>\n\treflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n\t#else\n\t\treflectedLight.directDiffuse = vLightFront;\n\t#endif\n\treflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}\n";
  3782. var meshlambert_vert = "#define LAMBERT\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <lights_lambert_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  3783. var meshphong_frag = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_template>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}\n";
  3784. var meshphong_vert = "#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  3785. var meshphysical_frag = "#define PHYSICAL\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifndef STANDARD\n\tuniform float clearCoat;\n\tuniform float clearCoatRoughness;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <lights_pars>\n#include <lights_physical_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_template>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}\n";
  3786. var meshphysical_vert = "#define PHYSICAL\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  3787. var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}\n";
  3788. var normal_vert = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}\n";
  3789. var points_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}\n";
  3790. var points_vert = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\t#ifdef USE_SIZEATTENUATION\n\t\tgl_PointSize = size * ( scale / - mvPosition.z );\n\t#else\n\t\tgl_PointSize = size;\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  3791. var shadow_frag = "uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <fog_fragment>\n}\n";
  3792. var shadow_vert = "#include <fog_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  3793. var ShaderChunk = {
  3794. alphamap_fragment: alphamap_fragment,
  3795. alphamap_pars_fragment: alphamap_pars_fragment,
  3796. alphatest_fragment: alphatest_fragment,
  3797. aomap_fragment: aomap_fragment,
  3798. aomap_pars_fragment: aomap_pars_fragment,
  3799. begin_vertex: begin_vertex,
  3800. beginnormal_vertex: beginnormal_vertex,
  3801. bsdfs: bsdfs,
  3802. bumpmap_pars_fragment: bumpmap_pars_fragment,
  3803. clipping_planes_fragment: clipping_planes_fragment,
  3804. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  3805. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  3806. clipping_planes_vertex: clipping_planes_vertex,
  3807. color_fragment: color_fragment,
  3808. color_pars_fragment: color_pars_fragment,
  3809. color_pars_vertex: color_pars_vertex,
  3810. color_vertex: color_vertex,
  3811. common: common,
  3812. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  3813. defaultnormal_vertex: defaultnormal_vertex,
  3814. displacementmap_pars_vertex: displacementmap_pars_vertex,
  3815. displacementmap_vertex: displacementmap_vertex,
  3816. emissivemap_fragment: emissivemap_fragment,
  3817. emissivemap_pars_fragment: emissivemap_pars_fragment,
  3818. encodings_fragment: encodings_fragment,
  3819. encodings_pars_fragment: encodings_pars_fragment,
  3820. envmap_fragment: envmap_fragment,
  3821. envmap_pars_fragment: envmap_pars_fragment,
  3822. envmap_pars_vertex: envmap_pars_vertex,
  3823. envmap_vertex: envmap_vertex,
  3824. fog_vertex: fog_vertex,
  3825. fog_pars_vertex: fog_pars_vertex,
  3826. fog_fragment: fog_fragment,
  3827. fog_pars_fragment: fog_pars_fragment,
  3828. gradientmap_pars_fragment: gradientmap_pars_fragment,
  3829. lightmap_fragment: lightmap_fragment,
  3830. lightmap_pars_fragment: lightmap_pars_fragment,
  3831. lights_lambert_vertex: lights_lambert_vertex,
  3832. lights_pars: lights_pars,
  3833. lights_phong_fragment: lights_phong_fragment,
  3834. lights_phong_pars_fragment: lights_phong_pars_fragment,
  3835. lights_physical_fragment: lights_physical_fragment,
  3836. lights_physical_pars_fragment: lights_physical_pars_fragment,
  3837. lights_template: lights_template,
  3838. logdepthbuf_fragment: logdepthbuf_fragment,
  3839. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  3840. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  3841. logdepthbuf_vertex: logdepthbuf_vertex,
  3842. map_fragment: map_fragment,
  3843. map_pars_fragment: map_pars_fragment,
  3844. map_particle_fragment: map_particle_fragment,
  3845. map_particle_pars_fragment: map_particle_pars_fragment,
  3846. metalnessmap_fragment: metalnessmap_fragment,
  3847. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  3848. morphnormal_vertex: morphnormal_vertex,
  3849. morphtarget_pars_vertex: morphtarget_pars_vertex,
  3850. morphtarget_vertex: morphtarget_vertex,
  3851. normal_fragment: normal_fragment,
  3852. normalmap_pars_fragment: normalmap_pars_fragment,
  3853. packing: packing,
  3854. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  3855. project_vertex: project_vertex,
  3856. dithering_fragment: dithering_fragment,
  3857. dithering_pars_fragment: dithering_pars_fragment,
  3858. roughnessmap_fragment: roughnessmap_fragment,
  3859. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  3860. shadowmap_pars_fragment: shadowmap_pars_fragment,
  3861. shadowmap_pars_vertex: shadowmap_pars_vertex,
  3862. shadowmap_vertex: shadowmap_vertex,
  3863. shadowmask_pars_fragment: shadowmask_pars_fragment,
  3864. skinbase_vertex: skinbase_vertex,
  3865. skinning_pars_vertex: skinning_pars_vertex,
  3866. skinning_vertex: skinning_vertex,
  3867. skinnormal_vertex: skinnormal_vertex,
  3868. specularmap_fragment: specularmap_fragment,
  3869. specularmap_pars_fragment: specularmap_pars_fragment,
  3870. tonemapping_fragment: tonemapping_fragment,
  3871. tonemapping_pars_fragment: tonemapping_pars_fragment,
  3872. uv_pars_fragment: uv_pars_fragment,
  3873. uv_pars_vertex: uv_pars_vertex,
  3874. uv_vertex: uv_vertex,
  3875. uv2_pars_fragment: uv2_pars_fragment,
  3876. uv2_pars_vertex: uv2_pars_vertex,
  3877. uv2_vertex: uv2_vertex,
  3878. worldpos_vertex: worldpos_vertex,
  3879. cube_frag: cube_frag,
  3880. cube_vert: cube_vert,
  3881. depth_frag: depth_frag,
  3882. depth_vert: depth_vert,
  3883. distanceRGBA_frag: distanceRGBA_frag,
  3884. distanceRGBA_vert: distanceRGBA_vert,
  3885. equirect_frag: equirect_frag,
  3886. equirect_vert: equirect_vert,
  3887. linedashed_frag: linedashed_frag,
  3888. linedashed_vert: linedashed_vert,
  3889. meshbasic_frag: meshbasic_frag,
  3890. meshbasic_vert: meshbasic_vert,
  3891. meshlambert_frag: meshlambert_frag,
  3892. meshlambert_vert: meshlambert_vert,
  3893. meshphong_frag: meshphong_frag,
  3894. meshphong_vert: meshphong_vert,
  3895. meshphysical_frag: meshphysical_frag,
  3896. meshphysical_vert: meshphysical_vert,
  3897. normal_frag: normal_frag,
  3898. normal_vert: normal_vert,
  3899. points_frag: points_frag,
  3900. points_vert: points_vert,
  3901. shadow_frag: shadow_frag,
  3902. shadow_vert: shadow_vert
  3903. };
  3904. /**
  3905. * @author alteredq / http://alteredqualia.com/
  3906. * @author mrdoob / http://mrdoob.com/
  3907. * @author mikael emtinger / http://gomo.se/
  3908. */
  3909. var ShaderLib = {
  3910. basic: {
  3911. uniforms: UniformsUtils.merge( [
  3912. UniformsLib.common,
  3913. UniformsLib.specularmap,
  3914. UniformsLib.envmap,
  3915. UniformsLib.aomap,
  3916. UniformsLib.lightmap,
  3917. UniformsLib.fog
  3918. ] ),
  3919. vertexShader: ShaderChunk.meshbasic_vert,
  3920. fragmentShader: ShaderChunk.meshbasic_frag
  3921. },
  3922. lambert: {
  3923. uniforms: UniformsUtils.merge( [
  3924. UniformsLib.common,
  3925. UniformsLib.specularmap,
  3926. UniformsLib.envmap,
  3927. UniformsLib.aomap,
  3928. UniformsLib.lightmap,
  3929. UniformsLib.emissivemap,
  3930. UniformsLib.fog,
  3931. UniformsLib.lights,
  3932. {
  3933. emissive: { value: new Color( 0x000000 ) }
  3934. }
  3935. ] ),
  3936. vertexShader: ShaderChunk.meshlambert_vert,
  3937. fragmentShader: ShaderChunk.meshlambert_frag
  3938. },
  3939. phong: {
  3940. uniforms: UniformsUtils.merge( [
  3941. UniformsLib.common,
  3942. UniformsLib.specularmap,
  3943. UniformsLib.envmap,
  3944. UniformsLib.aomap,
  3945. UniformsLib.lightmap,
  3946. UniformsLib.emissivemap,
  3947. UniformsLib.bumpmap,
  3948. UniformsLib.normalmap,
  3949. UniformsLib.displacementmap,
  3950. UniformsLib.gradientmap,
  3951. UniformsLib.fog,
  3952. UniformsLib.lights,
  3953. {
  3954. emissive: { value: new Color( 0x000000 ) },
  3955. specular: { value: new Color( 0x111111 ) },
  3956. shininess: { value: 30 }
  3957. }
  3958. ] ),
  3959. vertexShader: ShaderChunk.meshphong_vert,
  3960. fragmentShader: ShaderChunk.meshphong_frag
  3961. },
  3962. standard: {
  3963. uniforms: UniformsUtils.merge( [
  3964. UniformsLib.common,
  3965. UniformsLib.envmap,
  3966. UniformsLib.aomap,
  3967. UniformsLib.lightmap,
  3968. UniformsLib.emissivemap,
  3969. UniformsLib.bumpmap,
  3970. UniformsLib.normalmap,
  3971. UniformsLib.displacementmap,
  3972. UniformsLib.roughnessmap,
  3973. UniformsLib.metalnessmap,
  3974. UniformsLib.fog,
  3975. UniformsLib.lights,
  3976. {
  3977. emissive: { value: new Color( 0x000000 ) },
  3978. roughness: { value: 0.5 },
  3979. metalness: { value: 0.5 },
  3980. envMapIntensity: { value: 1 } // temporary
  3981. }
  3982. ] ),
  3983. vertexShader: ShaderChunk.meshphysical_vert,
  3984. fragmentShader: ShaderChunk.meshphysical_frag
  3985. },
  3986. points: {
  3987. uniforms: UniformsUtils.merge( [
  3988. UniformsLib.points,
  3989. UniformsLib.fog
  3990. ] ),
  3991. vertexShader: ShaderChunk.points_vert,
  3992. fragmentShader: ShaderChunk.points_frag
  3993. },
  3994. dashed: {
  3995. uniforms: UniformsUtils.merge( [
  3996. UniformsLib.common,
  3997. UniformsLib.fog,
  3998. {
  3999. scale: { value: 1 },
  4000. dashSize: { value: 1 },
  4001. totalSize: { value: 2 }
  4002. }
  4003. ] ),
  4004. vertexShader: ShaderChunk.linedashed_vert,
  4005. fragmentShader: ShaderChunk.linedashed_frag
  4006. },
  4007. depth: {
  4008. uniforms: UniformsUtils.merge( [
  4009. UniformsLib.common,
  4010. UniformsLib.displacementmap
  4011. ] ),
  4012. vertexShader: ShaderChunk.depth_vert,
  4013. fragmentShader: ShaderChunk.depth_frag
  4014. },
  4015. normal: {
  4016. uniforms: UniformsUtils.merge( [
  4017. UniformsLib.common,
  4018. UniformsLib.bumpmap,
  4019. UniformsLib.normalmap,
  4020. UniformsLib.displacementmap,
  4021. {
  4022. opacity: { value: 1.0 }
  4023. }
  4024. ] ),
  4025. vertexShader: ShaderChunk.normal_vert,
  4026. fragmentShader: ShaderChunk.normal_frag
  4027. },
  4028. /* -------------------------------------------------------------------------
  4029. // Cube map shader
  4030. ------------------------------------------------------------------------- */
  4031. cube: {
  4032. uniforms: {
  4033. tCube: { value: null },
  4034. tFlip: { value: - 1 },
  4035. opacity: { value: 1.0 }
  4036. },
  4037. vertexShader: ShaderChunk.cube_vert,
  4038. fragmentShader: ShaderChunk.cube_frag
  4039. },
  4040. equirect: {
  4041. uniforms: {
  4042. tEquirect: { value: null },
  4043. },
  4044. vertexShader: ShaderChunk.equirect_vert,
  4045. fragmentShader: ShaderChunk.equirect_frag
  4046. },
  4047. distanceRGBA: {
  4048. uniforms: UniformsUtils.merge( [
  4049. UniformsLib.common,
  4050. UniformsLib.displacementmap,
  4051. {
  4052. referencePosition: { value: new Vector3() },
  4053. nearDistance: { value: 1 },
  4054. farDistance: { value: 1000 }
  4055. }
  4056. ] ),
  4057. vertexShader: ShaderChunk.distanceRGBA_vert,
  4058. fragmentShader: ShaderChunk.distanceRGBA_frag
  4059. },
  4060. shadow: {
  4061. uniforms: UniformsUtils.merge( [
  4062. UniformsLib.lights,
  4063. UniformsLib.fog,
  4064. {
  4065. color: { value: new Color( 0x00000 ) },
  4066. opacity: { value: 1.0 }
  4067. },
  4068. ] ),
  4069. vertexShader: ShaderChunk.shadow_vert,
  4070. fragmentShader: ShaderChunk.shadow_frag
  4071. }
  4072. };
  4073. ShaderLib.physical = {
  4074. uniforms: UniformsUtils.merge( [
  4075. ShaderLib.standard.uniforms,
  4076. {
  4077. clearCoat: { value: 0 },
  4078. clearCoatRoughness: { value: 0 }
  4079. }
  4080. ] ),
  4081. vertexShader: ShaderChunk.meshphysical_vert,
  4082. fragmentShader: ShaderChunk.meshphysical_frag
  4083. };
  4084. /**
  4085. * @author mrdoob / http://mrdoob.com/
  4086. */
  4087. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  4088. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  4089. this.needsUpdate = true;
  4090. }
  4091. CanvasTexture.prototype = Object.create( Texture.prototype );
  4092. CanvasTexture.prototype.constructor = CanvasTexture;
  4093. /**
  4094. * @author mikael emtinger / http://gomo.se/
  4095. * @author alteredq / http://alteredqualia.com/
  4096. */
  4097. function WebGLSpriteRenderer( renderer, gl, state, textures, capabilities ) {
  4098. var vertexBuffer, elementBuffer;
  4099. var program, attributes, uniforms;
  4100. var texture;
  4101. // decompose matrixWorld
  4102. var spritePosition = new Vector3();
  4103. var spriteRotation = new Quaternion();
  4104. var spriteScale = new Vector3();
  4105. function init() {
  4106. var vertices = new Float32Array( [
  4107. - 0.5, - 0.5, 0, 0,
  4108. 0.5, - 0.5, 1, 0,
  4109. 0.5, 0.5, 1, 1,
  4110. - 0.5, 0.5, 0, 1
  4111. ] );
  4112. var faces = new Uint16Array( [
  4113. 0, 1, 2,
  4114. 0, 2, 3
  4115. ] );
  4116. vertexBuffer = gl.createBuffer();
  4117. elementBuffer = gl.createBuffer();
  4118. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  4119. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  4120. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  4121. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  4122. program = createProgram();
  4123. attributes = {
  4124. position: gl.getAttribLocation( program, 'position' ),
  4125. uv: gl.getAttribLocation( program, 'uv' )
  4126. };
  4127. uniforms = {
  4128. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  4129. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  4130. rotation: gl.getUniformLocation( program, 'rotation' ),
  4131. center: gl.getUniformLocation( program, 'center' ),
  4132. scale: gl.getUniformLocation( program, 'scale' ),
  4133. color: gl.getUniformLocation( program, 'color' ),
  4134. map: gl.getUniformLocation( program, 'map' ),
  4135. opacity: gl.getUniformLocation( program, 'opacity' ),
  4136. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  4137. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  4138. fogType: gl.getUniformLocation( program, 'fogType' ),
  4139. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  4140. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  4141. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  4142. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  4143. fogDepth: gl.getUniformLocation( program, 'fogDepth' ),
  4144. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  4145. };
  4146. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  4147. canvas.width = 8;
  4148. canvas.height = 8;
  4149. var context = canvas.getContext( '2d' );
  4150. context.fillStyle = 'white';
  4151. context.fillRect( 0, 0, 8, 8 );
  4152. texture = new CanvasTexture( canvas );
  4153. }
  4154. this.render = function ( sprites, scene, camera ) {
  4155. if ( sprites.length === 0 ) return;
  4156. // setup gl
  4157. if ( program === undefined ) {
  4158. init();
  4159. }
  4160. state.useProgram( program );
  4161. state.initAttributes();
  4162. state.enableAttribute( attributes.position );
  4163. state.enableAttribute( attributes.uv );
  4164. state.disableUnusedAttributes();
  4165. state.disable( gl.CULL_FACE );
  4166. state.enable( gl.BLEND );
  4167. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  4168. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  4169. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  4170. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  4171. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  4172. state.activeTexture( gl.TEXTURE0 );
  4173. gl.uniform1i( uniforms.map, 0 );
  4174. var oldFogType = 0;
  4175. var sceneFogType = 0;
  4176. var fog = scene.fog;
  4177. if ( fog ) {
  4178. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  4179. if ( fog.isFog ) {
  4180. gl.uniform1f( uniforms.fogNear, fog.near );
  4181. gl.uniform1f( uniforms.fogFar, fog.far );
  4182. gl.uniform1i( uniforms.fogType, 1 );
  4183. oldFogType = 1;
  4184. sceneFogType = 1;
  4185. } else if ( fog.isFogExp2 ) {
  4186. gl.uniform1f( uniforms.fogDensity, fog.density );
  4187. gl.uniform1i( uniforms.fogType, 2 );
  4188. oldFogType = 2;
  4189. sceneFogType = 2;
  4190. }
  4191. } else {
  4192. gl.uniform1i( uniforms.fogType, 0 );
  4193. oldFogType = 0;
  4194. sceneFogType = 0;
  4195. }
  4196. // update positions and sort
  4197. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  4198. var sprite = sprites[ i ];
  4199. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  4200. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  4201. }
  4202. sprites.sort( painterSortStable );
  4203. // render all sprites
  4204. var scale = [];
  4205. var center = [];
  4206. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  4207. var sprite = sprites[ i ];
  4208. var material = sprite.material;
  4209. if ( material.visible === false ) continue;
  4210. sprite.onBeforeRender( renderer, scene, camera, undefined, material, undefined );
  4211. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  4212. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  4213. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  4214. scale[ 0 ] = spriteScale.x;
  4215. scale[ 1 ] = spriteScale.y;
  4216. center[ 0 ] = sprite.center.x - 0.5;
  4217. center[ 1 ] = sprite.center.y - 0.5;
  4218. var fogType = 0;
  4219. if ( scene.fog && material.fog ) {
  4220. fogType = sceneFogType;
  4221. }
  4222. if ( oldFogType !== fogType ) {
  4223. gl.uniform1i( uniforms.fogType, fogType );
  4224. oldFogType = fogType;
  4225. }
  4226. if ( material.map !== null ) {
  4227. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  4228. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  4229. } else {
  4230. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  4231. gl.uniform2f( uniforms.uvScale, 1, 1 );
  4232. }
  4233. gl.uniform1f( uniforms.opacity, material.opacity );
  4234. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  4235. gl.uniform1f( uniforms.rotation, material.rotation );
  4236. gl.uniform2fv( uniforms.center, center );
  4237. gl.uniform2fv( uniforms.scale, scale );
  4238. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  4239. state.buffers.depth.setTest( material.depthTest );
  4240. state.buffers.depth.setMask( material.depthWrite );
  4241. state.buffers.color.setMask( material.colorWrite );
  4242. textures.setTexture2D( material.map || texture, 0 );
  4243. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  4244. sprite.onAfterRender( renderer, scene, camera, undefined, material, undefined );
  4245. }
  4246. // restore gl
  4247. state.enable( gl.CULL_FACE );
  4248. state.reset();
  4249. };
  4250. function createProgram() {
  4251. var program = gl.createProgram();
  4252. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  4253. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  4254. gl.shaderSource( vertexShader, [
  4255. 'precision ' + capabilities.precision + ' float;',
  4256. '#define SHADER_NAME ' + 'SpriteMaterial',
  4257. 'uniform mat4 modelViewMatrix;',
  4258. 'uniform mat4 projectionMatrix;',
  4259. 'uniform float rotation;',
  4260. 'uniform vec2 center;',
  4261. 'uniform vec2 scale;',
  4262. 'uniform vec2 uvOffset;',
  4263. 'uniform vec2 uvScale;',
  4264. 'attribute vec2 position;',
  4265. 'attribute vec2 uv;',
  4266. 'varying vec2 vUV;',
  4267. 'varying float fogDepth;',
  4268. 'void main() {',
  4269. ' vUV = uvOffset + uv * uvScale;',
  4270. ' vec2 alignedPosition = ( position - center ) * scale;',
  4271. ' vec2 rotatedPosition;',
  4272. ' rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  4273. ' rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  4274. ' vec4 mvPosition;',
  4275. ' mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  4276. ' mvPosition.xy += rotatedPosition;',
  4277. ' gl_Position = projectionMatrix * mvPosition;',
  4278. ' fogDepth = - mvPosition.z;',
  4279. '}'
  4280. ].join( '\n' ) );
  4281. gl.shaderSource( fragmentShader, [
  4282. 'precision ' + capabilities.precision + ' float;',
  4283. '#define SHADER_NAME ' + 'SpriteMaterial',
  4284. 'uniform vec3 color;',
  4285. 'uniform sampler2D map;',
  4286. 'uniform float opacity;',
  4287. 'uniform int fogType;',
  4288. 'uniform vec3 fogColor;',
  4289. 'uniform float fogDensity;',
  4290. 'uniform float fogNear;',
  4291. 'uniform float fogFar;',
  4292. 'uniform float alphaTest;',
  4293. 'varying vec2 vUV;',
  4294. 'varying float fogDepth;',
  4295. 'void main() {',
  4296. ' vec4 texture = texture2D( map, vUV );',
  4297. ' gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  4298. ' if ( gl_FragColor.a < alphaTest ) discard;',
  4299. ' if ( fogType > 0 ) {',
  4300. ' float fogFactor = 0.0;',
  4301. ' if ( fogType == 1 ) {',
  4302. ' fogFactor = smoothstep( fogNear, fogFar, fogDepth );',
  4303. ' } else {',
  4304. ' const float LOG2 = 1.442695;',
  4305. ' fogFactor = exp2( - fogDensity * fogDensity * fogDepth * fogDepth * LOG2 );',
  4306. ' fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  4307. ' }',
  4308. ' gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );',
  4309. ' }',
  4310. '}'
  4311. ].join( '\n' ) );
  4312. gl.compileShader( vertexShader );
  4313. gl.compileShader( fragmentShader );
  4314. gl.attachShader( program, vertexShader );
  4315. gl.attachShader( program, fragmentShader );
  4316. gl.linkProgram( program );
  4317. return program;
  4318. }
  4319. function painterSortStable( a, b ) {
  4320. if ( a.renderOrder !== b.renderOrder ) {
  4321. return a.renderOrder - b.renderOrder;
  4322. } else if ( a.z !== b.z ) {
  4323. return b.z - a.z;
  4324. } else {
  4325. return b.id - a.id;
  4326. }
  4327. }
  4328. }
  4329. /**
  4330. * @author mrdoob / http://mrdoob.com/
  4331. * @author alteredq / http://alteredqualia.com/
  4332. */
  4333. var materialId = 0;
  4334. function Material() {
  4335. Object.defineProperty( this, 'id', { value: materialId ++ } );
  4336. this.uuid = _Math.generateUUID();
  4337. this.name = '';
  4338. this.type = 'Material';
  4339. this.fog = true;
  4340. this.lights = true;
  4341. this.blending = NormalBlending;
  4342. this.side = FrontSide;
  4343. this.flatShading = false;
  4344. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  4345. this.opacity = 1;
  4346. this.transparent = false;
  4347. this.blendSrc = SrcAlphaFactor;
  4348. this.blendDst = OneMinusSrcAlphaFactor;
  4349. this.blendEquation = AddEquation;
  4350. this.blendSrcAlpha = null;
  4351. this.blendDstAlpha = null;
  4352. this.blendEquationAlpha = null;
  4353. this.depthFunc = LessEqualDepth;
  4354. this.depthTest = true;
  4355. this.depthWrite = true;
  4356. this.clippingPlanes = null;
  4357. this.clipIntersection = false;
  4358. this.clipShadows = false;
  4359. this.shadowSide = null;
  4360. this.colorWrite = true;
  4361. this.precision = null; // override the renderer's default precision for this material
  4362. this.polygonOffset = false;
  4363. this.polygonOffsetFactor = 0;
  4364. this.polygonOffsetUnits = 0;
  4365. this.dithering = false;
  4366. this.alphaTest = 0;
  4367. this.premultipliedAlpha = false;
  4368. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  4369. this.visible = true;
  4370. this.userData = {};
  4371. this.needsUpdate = true;
  4372. }
  4373. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  4374. constructor: Material,
  4375. isMaterial: true,
  4376. onBeforeCompile: function () {},
  4377. setValues: function ( values ) {
  4378. if ( values === undefined ) return;
  4379. for ( var key in values ) {
  4380. var newValue = values[ key ];
  4381. if ( newValue === undefined ) {
  4382. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  4383. continue;
  4384. }
  4385. // for backward compatability if shading is set in the constructor
  4386. if ( key === 'shading' ) {
  4387. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  4388. this.flatShading = ( newValue === FlatShading ) ? true : false;
  4389. continue;
  4390. }
  4391. var currentValue = this[ key ];
  4392. if ( currentValue === undefined ) {
  4393. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  4394. continue;
  4395. }
  4396. if ( currentValue && currentValue.isColor ) {
  4397. currentValue.set( newValue );
  4398. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  4399. currentValue.copy( newValue );
  4400. } else if ( key === 'overdraw' ) {
  4401. // ensure overdraw is backwards-compatible with legacy boolean type
  4402. this[ key ] = Number( newValue );
  4403. } else {
  4404. this[ key ] = newValue;
  4405. }
  4406. }
  4407. },
  4408. toJSON: function ( meta ) {
  4409. var isRoot = ( meta === undefined || typeof meta === 'string' );
  4410. if ( isRoot ) {
  4411. meta = {
  4412. textures: {},
  4413. images: {}
  4414. };
  4415. }
  4416. var data = {
  4417. metadata: {
  4418. version: 4.5,
  4419. type: 'Material',
  4420. generator: 'Material.toJSON'
  4421. }
  4422. };
  4423. // standard Material serialization
  4424. data.uuid = this.uuid;
  4425. data.type = this.type;
  4426. if ( this.name !== '' ) data.name = this.name;
  4427. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  4428. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  4429. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  4430. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  4431. if ( this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  4432. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  4433. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  4434. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  4435. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  4436. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  4437. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  4438. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  4439. if ( this.bumpMap && this.bumpMap.isTexture ) {
  4440. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  4441. data.bumpScale = this.bumpScale;
  4442. }
  4443. if ( this.normalMap && this.normalMap.isTexture ) {
  4444. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  4445. data.normalScale = this.normalScale.toArray();
  4446. }
  4447. if ( this.displacementMap && this.displacementMap.isTexture ) {
  4448. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  4449. data.displacementScale = this.displacementScale;
  4450. data.displacementBias = this.displacementBias;
  4451. }
  4452. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  4453. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  4454. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  4455. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  4456. if ( this.envMap && this.envMap.isTexture ) {
  4457. data.envMap = this.envMap.toJSON( meta ).uuid;
  4458. data.reflectivity = this.reflectivity; // Scale behind envMap
  4459. }
  4460. if ( this.gradientMap && this.gradientMap.isTexture ) {
  4461. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  4462. }
  4463. if ( this.size !== undefined ) data.size = this.size;
  4464. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  4465. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  4466. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  4467. if ( this.side !== FrontSide ) data.side = this.side;
  4468. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  4469. if ( this.opacity < 1 ) data.opacity = this.opacity;
  4470. if ( this.transparent === true ) data.transparent = this.transparent;
  4471. data.depthFunc = this.depthFunc;
  4472. data.depthTest = this.depthTest;
  4473. data.depthWrite = this.depthWrite;
  4474. // rotation (SpriteMaterial)
  4475. if ( this.rotation !== 0 ) data.rotation = this.rotation;
  4476. if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
  4477. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  4478. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  4479. if ( this.scale !== undefined ) data.scale = this.scale;
  4480. if ( this.dithering === true ) data.dithering = true;
  4481. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  4482. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  4483. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  4484. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  4485. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  4486. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  4487. if ( this.morphTargets === true ) data.morphTargets = true;
  4488. if ( this.skinning === true ) data.skinning = true;
  4489. if ( this.visible === false ) data.visible = false;
  4490. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  4491. // TODO: Copied from Object3D.toJSON
  4492. function extractFromCache( cache ) {
  4493. var values = [];
  4494. for ( var key in cache ) {
  4495. var data = cache[ key ];
  4496. delete data.metadata;
  4497. values.push( data );
  4498. }
  4499. return values;
  4500. }
  4501. if ( isRoot ) {
  4502. var textures = extractFromCache( meta.textures );
  4503. var images = extractFromCache( meta.images );
  4504. if ( textures.length > 0 ) data.textures = textures;
  4505. if ( images.length > 0 ) data.images = images;
  4506. }
  4507. return data;
  4508. },
  4509. clone: function () {
  4510. return new this.constructor().copy( this );
  4511. },
  4512. copy: function ( source ) {
  4513. this.name = source.name;
  4514. this.fog = source.fog;
  4515. this.lights = source.lights;
  4516. this.blending = source.blending;
  4517. this.side = source.side;
  4518. this.flatShading = source.flatShading;
  4519. this.vertexColors = source.vertexColors;
  4520. this.opacity = source.opacity;
  4521. this.transparent = source.transparent;
  4522. this.blendSrc = source.blendSrc;
  4523. this.blendDst = source.blendDst;
  4524. this.blendEquation = source.blendEquation;
  4525. this.blendSrcAlpha = source.blendSrcAlpha;
  4526. this.blendDstAlpha = source.blendDstAlpha;
  4527. this.blendEquationAlpha = source.blendEquationAlpha;
  4528. this.depthFunc = source.depthFunc;
  4529. this.depthTest = source.depthTest;
  4530. this.depthWrite = source.depthWrite;
  4531. this.colorWrite = source.colorWrite;
  4532. this.precision = source.precision;
  4533. this.polygonOffset = source.polygonOffset;
  4534. this.polygonOffsetFactor = source.polygonOffsetFactor;
  4535. this.polygonOffsetUnits = source.polygonOffsetUnits;
  4536. this.dithering = source.dithering;
  4537. this.alphaTest = source.alphaTest;
  4538. this.premultipliedAlpha = source.premultipliedAlpha;
  4539. this.overdraw = source.overdraw;
  4540. this.visible = source.visible;
  4541. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4542. this.clipShadows = source.clipShadows;
  4543. this.clipIntersection = source.clipIntersection;
  4544. var srcPlanes = source.clippingPlanes,
  4545. dstPlanes = null;
  4546. if ( srcPlanes !== null ) {
  4547. var n = srcPlanes.length;
  4548. dstPlanes = new Array( n );
  4549. for ( var i = 0; i !== n; ++ i )
  4550. dstPlanes[ i ] = srcPlanes[ i ].clone();
  4551. }
  4552. this.clippingPlanes = dstPlanes;
  4553. this.shadowSide = source.shadowSide;
  4554. return this;
  4555. },
  4556. dispose: function () {
  4557. this.dispatchEvent( { type: 'dispose' } );
  4558. }
  4559. } );
  4560. /**
  4561. * @author mrdoob / http://mrdoob.com/
  4562. * @author alteredq / http://alteredqualia.com/
  4563. * @author bhouston / https://clara.io
  4564. * @author WestLangley / http://github.com/WestLangley
  4565. *
  4566. * parameters = {
  4567. *
  4568. * opacity: <float>,
  4569. *
  4570. * map: new THREE.Texture( <Image> ),
  4571. *
  4572. * alphaMap: new THREE.Texture( <Image> ),
  4573. *
  4574. * displacementMap: new THREE.Texture( <Image> ),
  4575. * displacementScale: <float>,
  4576. * displacementBias: <float>,
  4577. *
  4578. * wireframe: <boolean>,
  4579. * wireframeLinewidth: <float>
  4580. * }
  4581. */
  4582. function MeshDepthMaterial( parameters ) {
  4583. Material.call( this );
  4584. this.type = 'MeshDepthMaterial';
  4585. this.depthPacking = BasicDepthPacking;
  4586. this.skinning = false;
  4587. this.morphTargets = false;
  4588. this.map = null;
  4589. this.alphaMap = null;
  4590. this.displacementMap = null;
  4591. this.displacementScale = 1;
  4592. this.displacementBias = 0;
  4593. this.wireframe = false;
  4594. this.wireframeLinewidth = 1;
  4595. this.fog = false;
  4596. this.lights = false;
  4597. this.setValues( parameters );
  4598. }
  4599. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  4600. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  4601. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  4602. MeshDepthMaterial.prototype.copy = function ( source ) {
  4603. Material.prototype.copy.call( this, source );
  4604. this.depthPacking = source.depthPacking;
  4605. this.skinning = source.skinning;
  4606. this.morphTargets = source.morphTargets;
  4607. this.map = source.map;
  4608. this.alphaMap = source.alphaMap;
  4609. this.displacementMap = source.displacementMap;
  4610. this.displacementScale = source.displacementScale;
  4611. this.displacementBias = source.displacementBias;
  4612. this.wireframe = source.wireframe;
  4613. this.wireframeLinewidth = source.wireframeLinewidth;
  4614. return this;
  4615. };
  4616. /**
  4617. * @author WestLangley / http://github.com/WestLangley
  4618. *
  4619. * parameters = {
  4620. *
  4621. * referencePosition: <float>,
  4622. * nearDistance: <float>,
  4623. * farDistance: <float>,
  4624. *
  4625. * skinning: <bool>,
  4626. * morphTargets: <bool>,
  4627. *
  4628. * map: new THREE.Texture( <Image> ),
  4629. *
  4630. * alphaMap: new THREE.Texture( <Image> ),
  4631. *
  4632. * displacementMap: new THREE.Texture( <Image> ),
  4633. * displacementScale: <float>,
  4634. * displacementBias: <float>
  4635. *
  4636. * }
  4637. */
  4638. function MeshDistanceMaterial( parameters ) {
  4639. Material.call( this );
  4640. this.type = 'MeshDistanceMaterial';
  4641. this.referencePosition = new Vector3();
  4642. this.nearDistance = 1;
  4643. this.farDistance = 1000;
  4644. this.skinning = false;
  4645. this.morphTargets = false;
  4646. this.map = null;
  4647. this.alphaMap = null;
  4648. this.displacementMap = null;
  4649. this.displacementScale = 1;
  4650. this.displacementBias = 0;
  4651. this.fog = false;
  4652. this.lights = false;
  4653. this.setValues( parameters );
  4654. }
  4655. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  4656. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  4657. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  4658. MeshDistanceMaterial.prototype.copy = function ( source ) {
  4659. Material.prototype.copy.call( this, source );
  4660. this.referencePosition.copy( source.referencePosition );
  4661. this.nearDistance = source.nearDistance;
  4662. this.farDistance = source.farDistance;
  4663. this.skinning = source.skinning;
  4664. this.morphTargets = source.morphTargets;
  4665. this.map = source.map;
  4666. this.alphaMap = source.alphaMap;
  4667. this.displacementMap = source.displacementMap;
  4668. this.displacementScale = source.displacementScale;
  4669. this.displacementBias = source.displacementBias;
  4670. return this;
  4671. };
  4672. /**
  4673. * @author bhouston / http://clara.io
  4674. * @author WestLangley / http://github.com/WestLangley
  4675. */
  4676. function Box3( min, max ) {
  4677. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  4678. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  4679. }
  4680. Object.assign( Box3.prototype, {
  4681. isBox3: true,
  4682. set: function ( min, max ) {
  4683. this.min.copy( min );
  4684. this.max.copy( max );
  4685. return this;
  4686. },
  4687. setFromArray: function ( array ) {
  4688. var minX = + Infinity;
  4689. var minY = + Infinity;
  4690. var minZ = + Infinity;
  4691. var maxX = - Infinity;
  4692. var maxY = - Infinity;
  4693. var maxZ = - Infinity;
  4694. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  4695. var x = array[ i ];
  4696. var y = array[ i + 1 ];
  4697. var z = array[ i + 2 ];
  4698. if ( x < minX ) minX = x;
  4699. if ( y < minY ) minY = y;
  4700. if ( z < minZ ) minZ = z;
  4701. if ( x > maxX ) maxX = x;
  4702. if ( y > maxY ) maxY = y;
  4703. if ( z > maxZ ) maxZ = z;
  4704. }
  4705. this.min.set( minX, minY, minZ );
  4706. this.max.set( maxX, maxY, maxZ );
  4707. return this;
  4708. },
  4709. setFromBufferAttribute: function ( attribute ) {
  4710. var minX = + Infinity;
  4711. var minY = + Infinity;
  4712. var minZ = + Infinity;
  4713. var maxX = - Infinity;
  4714. var maxY = - Infinity;
  4715. var maxZ = - Infinity;
  4716. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  4717. var x = attribute.getX( i );
  4718. var y = attribute.getY( i );
  4719. var z = attribute.getZ( i );
  4720. if ( x < minX ) minX = x;
  4721. if ( y < minY ) minY = y;
  4722. if ( z < minZ ) minZ = z;
  4723. if ( x > maxX ) maxX = x;
  4724. if ( y > maxY ) maxY = y;
  4725. if ( z > maxZ ) maxZ = z;
  4726. }
  4727. this.min.set( minX, minY, minZ );
  4728. this.max.set( maxX, maxY, maxZ );
  4729. return this;
  4730. },
  4731. setFromPoints: function ( points ) {
  4732. this.makeEmpty();
  4733. for ( var i = 0, il = points.length; i < il; i ++ ) {
  4734. this.expandByPoint( points[ i ] );
  4735. }
  4736. return this;
  4737. },
  4738. setFromCenterAndSize: function () {
  4739. var v1 = new Vector3();
  4740. return function setFromCenterAndSize( center, size ) {
  4741. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  4742. this.min.copy( center ).sub( halfSize );
  4743. this.max.copy( center ).add( halfSize );
  4744. return this;
  4745. };
  4746. }(),
  4747. setFromObject: function ( object ) {
  4748. this.makeEmpty();
  4749. return this.expandByObject( object );
  4750. },
  4751. clone: function () {
  4752. return new this.constructor().copy( this );
  4753. },
  4754. copy: function ( box ) {
  4755. this.min.copy( box.min );
  4756. this.max.copy( box.max );
  4757. return this;
  4758. },
  4759. makeEmpty: function () {
  4760. this.min.x = this.min.y = this.min.z = + Infinity;
  4761. this.max.x = this.max.y = this.max.z = - Infinity;
  4762. return this;
  4763. },
  4764. isEmpty: function () {
  4765. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  4766. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  4767. },
  4768. getCenter: function ( optionalTarget ) {
  4769. var result = optionalTarget || new Vector3();
  4770. return this.isEmpty() ? result.set( 0, 0, 0 ) : result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  4771. },
  4772. getSize: function ( optionalTarget ) {
  4773. var result = optionalTarget || new Vector3();
  4774. return this.isEmpty() ? result.set( 0, 0, 0 ) : result.subVectors( this.max, this.min );
  4775. },
  4776. expandByPoint: function ( point ) {
  4777. this.min.min( point );
  4778. this.max.max( point );
  4779. return this;
  4780. },
  4781. expandByVector: function ( vector ) {
  4782. this.min.sub( vector );
  4783. this.max.add( vector );
  4784. return this;
  4785. },
  4786. expandByScalar: function ( scalar ) {
  4787. this.min.addScalar( - scalar );
  4788. this.max.addScalar( scalar );
  4789. return this;
  4790. },
  4791. expandByObject: function () {
  4792. // Computes the world-axis-aligned bounding box of an object (including its children),
  4793. // accounting for both the object's, and children's, world transforms
  4794. var scope, i, l;
  4795. var v1 = new Vector3();
  4796. function traverse( node ) {
  4797. var geometry = node.geometry;
  4798. if ( geometry !== undefined ) {
  4799. if ( geometry.isGeometry ) {
  4800. var vertices = geometry.vertices;
  4801. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  4802. v1.copy( vertices[ i ] );
  4803. v1.applyMatrix4( node.matrixWorld );
  4804. scope.expandByPoint( v1 );
  4805. }
  4806. } else if ( geometry.isBufferGeometry ) {
  4807. var attribute = geometry.attributes.position;
  4808. if ( attribute !== undefined ) {
  4809. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  4810. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  4811. scope.expandByPoint( v1 );
  4812. }
  4813. }
  4814. }
  4815. }
  4816. }
  4817. return function expandByObject( object ) {
  4818. scope = this;
  4819. object.updateMatrixWorld( true );
  4820. object.traverse( traverse );
  4821. return this;
  4822. };
  4823. }(),
  4824. containsPoint: function ( point ) {
  4825. return point.x < this.min.x || point.x > this.max.x ||
  4826. point.y < this.min.y || point.y > this.max.y ||
  4827. point.z < this.min.z || point.z > this.max.z ? false : true;
  4828. },
  4829. containsBox: function ( box ) {
  4830. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  4831. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  4832. this.min.z <= box.min.z && box.max.z <= this.max.z;
  4833. },
  4834. getParameter: function ( point, optionalTarget ) {
  4835. // This can potentially have a divide by zero if the box
  4836. // has a size dimension of 0.
  4837. var result = optionalTarget || new Vector3();
  4838. return result.set(
  4839. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  4840. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  4841. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  4842. );
  4843. },
  4844. intersectsBox: function ( box ) {
  4845. // using 6 splitting planes to rule out intersections.
  4846. return box.max.x < this.min.x || box.min.x > this.max.x ||
  4847. box.max.y < this.min.y || box.min.y > this.max.y ||
  4848. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  4849. },
  4850. intersectsSphere: ( function () {
  4851. var closestPoint = new Vector3();
  4852. return function intersectsSphere( sphere ) {
  4853. // Find the point on the AABB closest to the sphere center.
  4854. this.clampPoint( sphere.center, closestPoint );
  4855. // If that point is inside the sphere, the AABB and sphere intersect.
  4856. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  4857. };
  4858. } )(),
  4859. intersectsPlane: function ( plane ) {
  4860. // We compute the minimum and maximum dot product values. If those values
  4861. // are on the same side (back or front) of the plane, then there is no intersection.
  4862. var min, max;
  4863. if ( plane.normal.x > 0 ) {
  4864. min = plane.normal.x * this.min.x;
  4865. max = plane.normal.x * this.max.x;
  4866. } else {
  4867. min = plane.normal.x * this.max.x;
  4868. max = plane.normal.x * this.min.x;
  4869. }
  4870. if ( plane.normal.y > 0 ) {
  4871. min += plane.normal.y * this.min.y;
  4872. max += plane.normal.y * this.max.y;
  4873. } else {
  4874. min += plane.normal.y * this.max.y;
  4875. max += plane.normal.y * this.min.y;
  4876. }
  4877. if ( plane.normal.z > 0 ) {
  4878. min += plane.normal.z * this.min.z;
  4879. max += plane.normal.z * this.max.z;
  4880. } else {
  4881. min += plane.normal.z * this.max.z;
  4882. max += plane.normal.z * this.min.z;
  4883. }
  4884. return ( min <= plane.constant && max >= plane.constant );
  4885. },
  4886. intersectsTriangle: ( function () {
  4887. // triangle centered vertices
  4888. var v0 = new Vector3();
  4889. var v1 = new Vector3();
  4890. var v2 = new Vector3();
  4891. // triangle edge vectors
  4892. var f0 = new Vector3();
  4893. var f1 = new Vector3();
  4894. var f2 = new Vector3();
  4895. var testAxis = new Vector3();
  4896. var center = new Vector3();
  4897. var extents = new Vector3();
  4898. var triangleNormal = new Vector3();
  4899. function satForAxes( axes ) {
  4900. var i, j;
  4901. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  4902. testAxis.fromArray( axes, i );
  4903. // project the aabb onto the seperating axis
  4904. var r = extents.x * Math.abs( testAxis.x ) + extents.y * Math.abs( testAxis.y ) + extents.z * Math.abs( testAxis.z );
  4905. // project all 3 vertices of the triangle onto the seperating axis
  4906. var p0 = v0.dot( testAxis );
  4907. var p1 = v1.dot( testAxis );
  4908. var p2 = v2.dot( testAxis );
  4909. // actual test, basically see if either of the most extreme of the triangle points intersects r
  4910. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  4911. // points of the projected triangle are outside the projected half-length of the aabb
  4912. // the axis is seperating and we can exit
  4913. return false;
  4914. }
  4915. }
  4916. return true;
  4917. }
  4918. return function intersectsTriangle( triangle ) {
  4919. if ( this.isEmpty() ) {
  4920. return false;
  4921. }
  4922. // compute box center and extents
  4923. this.getCenter( center );
  4924. extents.subVectors( this.max, center );
  4925. // translate triangle to aabb origin
  4926. v0.subVectors( triangle.a, center );
  4927. v1.subVectors( triangle.b, center );
  4928. v2.subVectors( triangle.c, center );
  4929. // compute edge vectors for triangle
  4930. f0.subVectors( v1, v0 );
  4931. f1.subVectors( v2, v1 );
  4932. f2.subVectors( v0, v2 );
  4933. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  4934. // make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
  4935. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  4936. var axes = [
  4937. 0, - f0.z, f0.y, 0, - f1.z, f1.y, 0, - f2.z, f2.y,
  4938. f0.z, 0, - f0.x, f1.z, 0, - f1.x, f2.z, 0, - f2.x,
  4939. - f0.y, f0.x, 0, - f1.y, f1.x, 0, - f2.y, f2.x, 0
  4940. ];
  4941. if ( ! satForAxes( axes ) ) {
  4942. return false;
  4943. }
  4944. // test 3 face normals from the aabb
  4945. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  4946. if ( ! satForAxes( axes ) ) {
  4947. return false;
  4948. }
  4949. // finally testing the face normal of the triangle
  4950. // use already existing triangle edge vectors here
  4951. triangleNormal.crossVectors( f0, f1 );
  4952. axes = [ triangleNormal.x, triangleNormal.y, triangleNormal.z ];
  4953. return satForAxes( axes );
  4954. };
  4955. } )(),
  4956. clampPoint: function ( point, optionalTarget ) {
  4957. var result = optionalTarget || new Vector3();
  4958. return result.copy( point ).clamp( this.min, this.max );
  4959. },
  4960. distanceToPoint: function () {
  4961. var v1 = new Vector3();
  4962. return function distanceToPoint( point ) {
  4963. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  4964. return clampedPoint.sub( point ).length();
  4965. };
  4966. }(),
  4967. getBoundingSphere: function () {
  4968. var v1 = new Vector3();
  4969. return function getBoundingSphere( optionalTarget ) {
  4970. var result = optionalTarget || new Sphere();
  4971. this.getCenter( result.center );
  4972. result.radius = this.getSize( v1 ).length() * 0.5;
  4973. return result;
  4974. };
  4975. }(),
  4976. intersect: function ( box ) {
  4977. this.min.max( box.min );
  4978. this.max.min( box.max );
  4979. // ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values.
  4980. if ( this.isEmpty() ) this.makeEmpty();
  4981. return this;
  4982. },
  4983. union: function ( box ) {
  4984. this.min.min( box.min );
  4985. this.max.max( box.max );
  4986. return this;
  4987. },
  4988. applyMatrix4: function () {
  4989. var points = [
  4990. new Vector3(),
  4991. new Vector3(),
  4992. new Vector3(),
  4993. new Vector3(),
  4994. new Vector3(),
  4995. new Vector3(),
  4996. new Vector3(),
  4997. new Vector3()
  4998. ];
  4999. return function applyMatrix4( matrix ) {
  5000. // transform of empty box is an empty box.
  5001. if ( this.isEmpty() ) return this;
  5002. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  5003. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  5004. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  5005. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  5006. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  5007. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  5008. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  5009. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  5010. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  5011. this.setFromPoints( points );
  5012. return this;
  5013. };
  5014. }(),
  5015. translate: function ( offset ) {
  5016. this.min.add( offset );
  5017. this.max.add( offset );
  5018. return this;
  5019. },
  5020. equals: function ( box ) {
  5021. return box.min.equals( this.min ) && box.max.equals( this.max );
  5022. }
  5023. } );
  5024. /**
  5025. * @author bhouston / http://clara.io
  5026. * @author mrdoob / http://mrdoob.com/
  5027. */
  5028. function Sphere( center, radius ) {
  5029. this.center = ( center !== undefined ) ? center : new Vector3();
  5030. this.radius = ( radius !== undefined ) ? radius : 0;
  5031. }
  5032. Object.assign( Sphere.prototype, {
  5033. set: function ( center, radius ) {
  5034. this.center.copy( center );
  5035. this.radius = radius;
  5036. return this;
  5037. },
  5038. setFromPoints: function () {
  5039. var box = new Box3();
  5040. return function setFromPoints( points, optionalCenter ) {
  5041. var center = this.center;
  5042. if ( optionalCenter !== undefined ) {
  5043. center.copy( optionalCenter );
  5044. } else {
  5045. box.setFromPoints( points ).getCenter( center );
  5046. }
  5047. var maxRadiusSq = 0;
  5048. for ( var i = 0, il = points.length; i < il; i ++ ) {
  5049. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  5050. }
  5051. this.radius = Math.sqrt( maxRadiusSq );
  5052. return this;
  5053. };
  5054. }(),
  5055. clone: function () {
  5056. return new this.constructor().copy( this );
  5057. },
  5058. copy: function ( sphere ) {
  5059. this.center.copy( sphere.center );
  5060. this.radius = sphere.radius;
  5061. return this;
  5062. },
  5063. empty: function () {
  5064. return ( this.radius <= 0 );
  5065. },
  5066. containsPoint: function ( point ) {
  5067. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  5068. },
  5069. distanceToPoint: function ( point ) {
  5070. return ( point.distanceTo( this.center ) - this.radius );
  5071. },
  5072. intersectsSphere: function ( sphere ) {
  5073. var radiusSum = this.radius + sphere.radius;
  5074. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  5075. },
  5076. intersectsBox: function ( box ) {
  5077. return box.intersectsSphere( this );
  5078. },
  5079. intersectsPlane: function ( plane ) {
  5080. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  5081. },
  5082. clampPoint: function ( point, optionalTarget ) {
  5083. var deltaLengthSq = this.center.distanceToSquared( point );
  5084. var result = optionalTarget || new Vector3();
  5085. result.copy( point );
  5086. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  5087. result.sub( this.center ).normalize();
  5088. result.multiplyScalar( this.radius ).add( this.center );
  5089. }
  5090. return result;
  5091. },
  5092. getBoundingBox: function ( optionalTarget ) {
  5093. var box = optionalTarget || new Box3();
  5094. box.set( this.center, this.center );
  5095. box.expandByScalar( this.radius );
  5096. return box;
  5097. },
  5098. applyMatrix4: function ( matrix ) {
  5099. this.center.applyMatrix4( matrix );
  5100. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  5101. return this;
  5102. },
  5103. translate: function ( offset ) {
  5104. this.center.add( offset );
  5105. return this;
  5106. },
  5107. equals: function ( sphere ) {
  5108. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  5109. }
  5110. } );
  5111. /**
  5112. * @author bhouston / http://clara.io
  5113. */
  5114. function Plane( normal, constant ) {
  5115. // normal is assumed to be normalized
  5116. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  5117. this.constant = ( constant !== undefined ) ? constant : 0;
  5118. }
  5119. Object.assign( Plane.prototype, {
  5120. set: function ( normal, constant ) {
  5121. this.normal.copy( normal );
  5122. this.constant = constant;
  5123. return this;
  5124. },
  5125. setComponents: function ( x, y, z, w ) {
  5126. this.normal.set( x, y, z );
  5127. this.constant = w;
  5128. return this;
  5129. },
  5130. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  5131. this.normal.copy( normal );
  5132. this.constant = - point.dot( this.normal );
  5133. return this;
  5134. },
  5135. setFromCoplanarPoints: function () {
  5136. var v1 = new Vector3();
  5137. var v2 = new Vector3();
  5138. return function setFromCoplanarPoints( a, b, c ) {
  5139. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  5140. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  5141. this.setFromNormalAndCoplanarPoint( normal, a );
  5142. return this;
  5143. };
  5144. }(),
  5145. clone: function () {
  5146. return new this.constructor().copy( this );
  5147. },
  5148. copy: function ( plane ) {
  5149. this.normal.copy( plane.normal );
  5150. this.constant = plane.constant;
  5151. return this;
  5152. },
  5153. normalize: function () {
  5154. // Note: will lead to a divide by zero if the plane is invalid.
  5155. var inverseNormalLength = 1.0 / this.normal.length();
  5156. this.normal.multiplyScalar( inverseNormalLength );
  5157. this.constant *= inverseNormalLength;
  5158. return this;
  5159. },
  5160. negate: function () {
  5161. this.constant *= - 1;
  5162. this.normal.negate();
  5163. return this;
  5164. },
  5165. distanceToPoint: function ( point ) {
  5166. return this.normal.dot( point ) + this.constant;
  5167. },
  5168. distanceToSphere: function ( sphere ) {
  5169. return this.distanceToPoint( sphere.center ) - sphere.radius;
  5170. },
  5171. projectPoint: function ( point, optionalTarget ) {
  5172. var result = optionalTarget || new Vector3();
  5173. return result.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  5174. },
  5175. intersectLine: function () {
  5176. var v1 = new Vector3();
  5177. return function intersectLine( line, optionalTarget ) {
  5178. var result = optionalTarget || new Vector3();
  5179. var direction = line.delta( v1 );
  5180. var denominator = this.normal.dot( direction );
  5181. if ( denominator === 0 ) {
  5182. // line is coplanar, return origin
  5183. if ( this.distanceToPoint( line.start ) === 0 ) {
  5184. return result.copy( line.start );
  5185. }
  5186. // Unsure if this is the correct method to handle this case.
  5187. return undefined;
  5188. }
  5189. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  5190. if ( t < 0 || t > 1 ) {
  5191. return undefined;
  5192. }
  5193. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  5194. };
  5195. }(),
  5196. intersectsLine: function ( line ) {
  5197. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  5198. var startSign = this.distanceToPoint( line.start );
  5199. var endSign = this.distanceToPoint( line.end );
  5200. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  5201. },
  5202. intersectsBox: function ( box ) {
  5203. return box.intersectsPlane( this );
  5204. },
  5205. intersectsSphere: function ( sphere ) {
  5206. return sphere.intersectsPlane( this );
  5207. },
  5208. coplanarPoint: function ( optionalTarget ) {
  5209. var result = optionalTarget || new Vector3();
  5210. return result.copy( this.normal ).multiplyScalar( - this.constant );
  5211. },
  5212. applyMatrix4: function () {
  5213. var v1 = new Vector3();
  5214. var m1 = new Matrix3();
  5215. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  5216. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  5217. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  5218. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  5219. this.constant = - referencePoint.dot( normal );
  5220. return this;
  5221. };
  5222. }(),
  5223. translate: function ( offset ) {
  5224. this.constant -= offset.dot( this.normal );
  5225. return this;
  5226. },
  5227. equals: function ( plane ) {
  5228. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  5229. }
  5230. } );
  5231. /**
  5232. * @author mrdoob / http://mrdoob.com/
  5233. * @author alteredq / http://alteredqualia.com/
  5234. * @author bhouston / http://clara.io
  5235. */
  5236. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  5237. this.planes = [
  5238. ( p0 !== undefined ) ? p0 : new Plane(),
  5239. ( p1 !== undefined ) ? p1 : new Plane(),
  5240. ( p2 !== undefined ) ? p2 : new Plane(),
  5241. ( p3 !== undefined ) ? p3 : new Plane(),
  5242. ( p4 !== undefined ) ? p4 : new Plane(),
  5243. ( p5 !== undefined ) ? p5 : new Plane()
  5244. ];
  5245. }
  5246. Object.assign( Frustum.prototype, {
  5247. set: function ( p0, p1, p2, p3, p4, p5 ) {
  5248. var planes = this.planes;
  5249. planes[ 0 ].copy( p0 );
  5250. planes[ 1 ].copy( p1 );
  5251. planes[ 2 ].copy( p2 );
  5252. planes[ 3 ].copy( p3 );
  5253. planes[ 4 ].copy( p4 );
  5254. planes[ 5 ].copy( p5 );
  5255. return this;
  5256. },
  5257. clone: function () {
  5258. return new this.constructor().copy( this );
  5259. },
  5260. copy: function ( frustum ) {
  5261. var planes = this.planes;
  5262. for ( var i = 0; i < 6; i ++ ) {
  5263. planes[ i ].copy( frustum.planes[ i ] );
  5264. }
  5265. return this;
  5266. },
  5267. setFromMatrix: function ( m ) {
  5268. var planes = this.planes;
  5269. var me = m.elements;
  5270. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  5271. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  5272. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  5273. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  5274. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  5275. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  5276. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  5277. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  5278. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  5279. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  5280. return this;
  5281. },
  5282. intersectsObject: function () {
  5283. var sphere = new Sphere();
  5284. return function intersectsObject( object ) {
  5285. var geometry = object.geometry;
  5286. if ( geometry.boundingSphere === null )
  5287. geometry.computeBoundingSphere();
  5288. sphere.copy( geometry.boundingSphere )
  5289. .applyMatrix4( object.matrixWorld );
  5290. return this.intersectsSphere( sphere );
  5291. };
  5292. }(),
  5293. intersectsSprite: function () {
  5294. var sphere = new Sphere();
  5295. return function intersectsSprite( sprite ) {
  5296. sphere.center.set( 0, 0, 0 );
  5297. sphere.radius = 0.7071067811865476;
  5298. sphere.applyMatrix4( sprite.matrixWorld );
  5299. return this.intersectsSphere( sphere );
  5300. };
  5301. }(),
  5302. intersectsSphere: function ( sphere ) {
  5303. var planes = this.planes;
  5304. var center = sphere.center;
  5305. var negRadius = - sphere.radius;
  5306. for ( var i = 0; i < 6; i ++ ) {
  5307. var distance = planes[ i ].distanceToPoint( center );
  5308. if ( distance < negRadius ) {
  5309. return false;
  5310. }
  5311. }
  5312. return true;
  5313. },
  5314. intersectsBox: function () {
  5315. var p1 = new Vector3(),
  5316. p2 = new Vector3();
  5317. return function intersectsBox( box ) {
  5318. var planes = this.planes;
  5319. for ( var i = 0; i < 6; i ++ ) {
  5320. var plane = planes[ i ];
  5321. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  5322. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  5323. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  5324. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  5325. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  5326. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  5327. var d1 = plane.distanceToPoint( p1 );
  5328. var d2 = plane.distanceToPoint( p2 );
  5329. // if both outside plane, no intersection
  5330. if ( d1 < 0 && d2 < 0 ) {
  5331. return false;
  5332. }
  5333. }
  5334. return true;
  5335. };
  5336. }(),
  5337. containsPoint: function ( point ) {
  5338. var planes = this.planes;
  5339. for ( var i = 0; i < 6; i ++ ) {
  5340. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  5341. return false;
  5342. }
  5343. }
  5344. return true;
  5345. }
  5346. } );
  5347. /**
  5348. * @author alteredq / http://alteredqualia.com/
  5349. * @author mrdoob / http://mrdoob.com/
  5350. */
  5351. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  5352. var _frustum = new Frustum(),
  5353. _projScreenMatrix = new Matrix4(),
  5354. _shadowMapSize = new Vector2(),
  5355. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  5356. _lookTarget = new Vector3(),
  5357. _lightPositionWorld = new Vector3(),
  5358. _MorphingFlag = 1,
  5359. _SkinningFlag = 2,
  5360. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  5361. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  5362. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  5363. _materialCache = {};
  5364. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  5365. var cubeDirections = [
  5366. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  5367. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  5368. ];
  5369. var cubeUps = [
  5370. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  5371. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  5372. ];
  5373. var cube2DViewPorts = [
  5374. new Vector4(), new Vector4(), new Vector4(),
  5375. new Vector4(), new Vector4(), new Vector4()
  5376. ];
  5377. // init
  5378. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  5379. var useMorphing = ( i & _MorphingFlag ) !== 0;
  5380. var useSkinning = ( i & _SkinningFlag ) !== 0;
  5381. var depthMaterial = new MeshDepthMaterial( {
  5382. depthPacking: RGBADepthPacking,
  5383. morphTargets: useMorphing,
  5384. skinning: useSkinning
  5385. } );
  5386. _depthMaterials[ i ] = depthMaterial;
  5387. //
  5388. var distanceMaterial = new MeshDistanceMaterial( {
  5389. morphTargets: useMorphing,
  5390. skinning: useSkinning
  5391. } );
  5392. _distanceMaterials[ i ] = distanceMaterial;
  5393. }
  5394. //
  5395. var scope = this;
  5396. this.enabled = false;
  5397. this.autoUpdate = true;
  5398. this.needsUpdate = false;
  5399. this.type = PCFShadowMap;
  5400. this.render = function ( lights, scene, camera ) {
  5401. if ( scope.enabled === false ) return;
  5402. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  5403. if ( lights.length === 0 ) return;
  5404. // TODO Clean up (needed in case of contextlost)
  5405. var _gl = _renderer.context;
  5406. var _state = _renderer.state;
  5407. // Set GL state for depth map.
  5408. _state.disable( _gl.BLEND );
  5409. _state.buffers.color.setClear( 1, 1, 1, 1 );
  5410. _state.buffers.depth.setTest( true );
  5411. _state.setScissorTest( false );
  5412. // render depth map
  5413. var faceCount;
  5414. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  5415. var light = lights[ i ];
  5416. var shadow = light.shadow;
  5417. var isPointLight = light && light.isPointLight;
  5418. if ( shadow === undefined ) {
  5419. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  5420. continue;
  5421. }
  5422. var shadowCamera = shadow.camera;
  5423. _shadowMapSize.copy( shadow.mapSize );
  5424. _shadowMapSize.min( _maxShadowMapSize );
  5425. if ( isPointLight ) {
  5426. var vpWidth = _shadowMapSize.x;
  5427. var vpHeight = _shadowMapSize.y;
  5428. // These viewports map a cube-map onto a 2D texture with the
  5429. // following orientation:
  5430. //
  5431. // xzXZ
  5432. // y Y
  5433. //
  5434. // X - Positive x direction
  5435. // x - Negative x direction
  5436. // Y - Positive y direction
  5437. // y - Negative y direction
  5438. // Z - Positive z direction
  5439. // z - Negative z direction
  5440. // positive X
  5441. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  5442. // negative X
  5443. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  5444. // positive Z
  5445. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  5446. // negative Z
  5447. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  5448. // positive Y
  5449. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  5450. // negative Y
  5451. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  5452. _shadowMapSize.x *= 4.0;
  5453. _shadowMapSize.y *= 2.0;
  5454. }
  5455. if ( shadow.map === null ) {
  5456. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  5457. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  5458. shadow.map.texture.name = light.name + ".shadowMap";
  5459. shadowCamera.updateProjectionMatrix();
  5460. }
  5461. if ( shadow.isSpotLightShadow ) {
  5462. shadow.update( light );
  5463. }
  5464. var shadowMap = shadow.map;
  5465. var shadowMatrix = shadow.matrix;
  5466. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  5467. shadowCamera.position.copy( _lightPositionWorld );
  5468. if ( isPointLight ) {
  5469. faceCount = 6;
  5470. // for point lights we set the shadow matrix to be a translation-only matrix
  5471. // equal to inverse of the light's position
  5472. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  5473. } else {
  5474. faceCount = 1;
  5475. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  5476. shadowCamera.lookAt( _lookTarget );
  5477. shadowCamera.updateMatrixWorld();
  5478. // compute shadow matrix
  5479. shadowMatrix.set(
  5480. 0.5, 0.0, 0.0, 0.5,
  5481. 0.0, 0.5, 0.0, 0.5,
  5482. 0.0, 0.0, 0.5, 0.5,
  5483. 0.0, 0.0, 0.0, 1.0
  5484. );
  5485. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  5486. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  5487. }
  5488. _renderer.setRenderTarget( shadowMap );
  5489. _renderer.clear();
  5490. // render shadow map for each cube face (if omni-directional) or
  5491. // run a single pass if not
  5492. for ( var face = 0; face < faceCount; face ++ ) {
  5493. if ( isPointLight ) {
  5494. _lookTarget.copy( shadowCamera.position );
  5495. _lookTarget.add( cubeDirections[ face ] );
  5496. shadowCamera.up.copy( cubeUps[ face ] );
  5497. shadowCamera.lookAt( _lookTarget );
  5498. shadowCamera.updateMatrixWorld();
  5499. var vpDimensions = cube2DViewPorts[ face ];
  5500. _state.viewport( vpDimensions );
  5501. }
  5502. // update camera matrices and frustum
  5503. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  5504. _frustum.setFromMatrix( _projScreenMatrix );
  5505. // set object matrices & frustum culling
  5506. renderObject( scene, camera, shadowCamera, isPointLight );
  5507. }
  5508. }
  5509. scope.needsUpdate = false;
  5510. };
  5511. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  5512. var geometry = object.geometry;
  5513. var result = null;
  5514. var materialVariants = _depthMaterials;
  5515. var customMaterial = object.customDepthMaterial;
  5516. if ( isPointLight ) {
  5517. materialVariants = _distanceMaterials;
  5518. customMaterial = object.customDistanceMaterial;
  5519. }
  5520. if ( ! customMaterial ) {
  5521. var useMorphing = false;
  5522. if ( material.morphTargets ) {
  5523. if ( geometry && geometry.isBufferGeometry ) {
  5524. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  5525. } else if ( geometry && geometry.isGeometry ) {
  5526. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  5527. }
  5528. }
  5529. if ( object.isSkinnedMesh && material.skinning === false ) {
  5530. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  5531. }
  5532. var useSkinning = object.isSkinnedMesh && material.skinning;
  5533. var variantIndex = 0;
  5534. if ( useMorphing ) variantIndex |= _MorphingFlag;
  5535. if ( useSkinning ) variantIndex |= _SkinningFlag;
  5536. result = materialVariants[ variantIndex ];
  5537. } else {
  5538. result = customMaterial;
  5539. }
  5540. if ( _renderer.localClippingEnabled &&
  5541. material.clipShadows === true &&
  5542. material.clippingPlanes.length !== 0 ) {
  5543. // in this case we need a unique material instance reflecting the
  5544. // appropriate state
  5545. var keyA = result.uuid, keyB = material.uuid;
  5546. var materialsForVariant = _materialCache[ keyA ];
  5547. if ( materialsForVariant === undefined ) {
  5548. materialsForVariant = {};
  5549. _materialCache[ keyA ] = materialsForVariant;
  5550. }
  5551. var cachedMaterial = materialsForVariant[ keyB ];
  5552. if ( cachedMaterial === undefined ) {
  5553. cachedMaterial = result.clone();
  5554. materialsForVariant[ keyB ] = cachedMaterial;
  5555. }
  5556. result = cachedMaterial;
  5557. }
  5558. result.visible = material.visible;
  5559. result.wireframe = material.wireframe;
  5560. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  5561. result.clipShadows = material.clipShadows;
  5562. result.clippingPlanes = material.clippingPlanes;
  5563. result.clipIntersection = material.clipIntersection;
  5564. result.wireframeLinewidth = material.wireframeLinewidth;
  5565. result.linewidth = material.linewidth;
  5566. if ( isPointLight && result.isMeshDistanceMaterial ) {
  5567. result.referencePosition.copy( lightPositionWorld );
  5568. result.nearDistance = shadowCameraNear;
  5569. result.farDistance = shadowCameraFar;
  5570. }
  5571. return result;
  5572. }
  5573. function renderObject( object, camera, shadowCamera, isPointLight ) {
  5574. if ( object.visible === false ) return;
  5575. var visible = object.layers.test( camera.layers );
  5576. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  5577. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  5578. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  5579. var geometry = _objects.update( object );
  5580. var material = object.material;
  5581. if ( Array.isArray( material ) ) {
  5582. var groups = geometry.groups;
  5583. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  5584. var group = groups[ k ];
  5585. var groupMaterial = material[ group.materialIndex ];
  5586. if ( groupMaterial && groupMaterial.visible ) {
  5587. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  5588. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  5589. }
  5590. }
  5591. } else if ( material.visible ) {
  5592. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  5593. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  5594. }
  5595. }
  5596. }
  5597. var children = object.children;
  5598. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5599. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  5600. }
  5601. }
  5602. }
  5603. /**
  5604. * @author mrdoob / http://mrdoob.com/
  5605. */
  5606. function WebGLAttributes( gl ) {
  5607. var buffers = {};
  5608. function createBuffer( attribute, bufferType ) {
  5609. var array = attribute.array;
  5610. var usage = attribute.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  5611. var buffer = gl.createBuffer();
  5612. gl.bindBuffer( bufferType, buffer );
  5613. gl.bufferData( bufferType, array, usage );
  5614. attribute.onUploadCallback();
  5615. var type = gl.FLOAT;
  5616. if ( array instanceof Float32Array ) {
  5617. type = gl.FLOAT;
  5618. } else if ( array instanceof Float64Array ) {
  5619. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  5620. } else if ( array instanceof Uint16Array ) {
  5621. type = gl.UNSIGNED_SHORT;
  5622. } else if ( array instanceof Int16Array ) {
  5623. type = gl.SHORT;
  5624. } else if ( array instanceof Uint32Array ) {
  5625. type = gl.UNSIGNED_INT;
  5626. } else if ( array instanceof Int32Array ) {
  5627. type = gl.INT;
  5628. } else if ( array instanceof Int8Array ) {
  5629. type = gl.BYTE;
  5630. } else if ( array instanceof Uint8Array ) {
  5631. type = gl.UNSIGNED_BYTE;
  5632. }
  5633. return {
  5634. buffer: buffer,
  5635. type: type,
  5636. bytesPerElement: array.BYTES_PER_ELEMENT,
  5637. version: attribute.version
  5638. };
  5639. }
  5640. function updateBuffer( buffer, attribute, bufferType ) {
  5641. var array = attribute.array;
  5642. var updateRange = attribute.updateRange;
  5643. gl.bindBuffer( bufferType, buffer );
  5644. if ( attribute.dynamic === false ) {
  5645. gl.bufferData( bufferType, array, gl.STATIC_DRAW );
  5646. } else if ( updateRange.count === - 1 ) {
  5647. // Not using update ranges
  5648. gl.bufferSubData( bufferType, 0, array );
  5649. } else if ( updateRange.count === 0 ) {
  5650. console.error( 'THREE.WebGLObjects.updateBuffer: dynamic THREE.BufferAttribute marked as needsUpdate but updateRange.count is 0, ensure you are using set methods or updating manually.' );
  5651. } else {
  5652. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  5653. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  5654. updateRange.count = - 1; // reset range
  5655. }
  5656. }
  5657. //
  5658. function get( attribute ) {
  5659. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  5660. return buffers[ attribute.uuid ];
  5661. }
  5662. function remove( attribute ) {
  5663. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  5664. var data = buffers[ attribute.uuid ];
  5665. if ( data ) {
  5666. gl.deleteBuffer( data.buffer );
  5667. delete buffers[ attribute.uuid ];
  5668. }
  5669. }
  5670. function update( attribute, bufferType ) {
  5671. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  5672. var data = buffers[ attribute.uuid ];
  5673. if ( data === undefined ) {
  5674. buffers[ attribute.uuid ] = createBuffer( attribute, bufferType );
  5675. } else if ( data.version < attribute.version ) {
  5676. updateBuffer( data.buffer, attribute, bufferType );
  5677. data.version = attribute.version;
  5678. }
  5679. }
  5680. return {
  5681. get: get,
  5682. remove: remove,
  5683. update: update
  5684. };
  5685. }
  5686. /**
  5687. * @author mrdoob / http://mrdoob.com/
  5688. * @author WestLangley / http://github.com/WestLangley
  5689. * @author bhouston / http://clara.io
  5690. */
  5691. function Euler( x, y, z, order ) {
  5692. this._x = x || 0;
  5693. this._y = y || 0;
  5694. this._z = z || 0;
  5695. this._order = order || Euler.DefaultOrder;
  5696. }
  5697. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  5698. Euler.DefaultOrder = 'XYZ';
  5699. Object.defineProperties( Euler.prototype, {
  5700. x: {
  5701. get: function () {
  5702. return this._x;
  5703. },
  5704. set: function ( value ) {
  5705. this._x = value;
  5706. this.onChangeCallback();
  5707. }
  5708. },
  5709. y: {
  5710. get: function () {
  5711. return this._y;
  5712. },
  5713. set: function ( value ) {
  5714. this._y = value;
  5715. this.onChangeCallback();
  5716. }
  5717. },
  5718. z: {
  5719. get: function () {
  5720. return this._z;
  5721. },
  5722. set: function ( value ) {
  5723. this._z = value;
  5724. this.onChangeCallback();
  5725. }
  5726. },
  5727. order: {
  5728. get: function () {
  5729. return this._order;
  5730. },
  5731. set: function ( value ) {
  5732. this._order = value;
  5733. this.onChangeCallback();
  5734. }
  5735. }
  5736. } );
  5737. Object.assign( Euler.prototype, {
  5738. isEuler: true,
  5739. set: function ( x, y, z, order ) {
  5740. this._x = x;
  5741. this._y = y;
  5742. this._z = z;
  5743. this._order = order || this._order;
  5744. this.onChangeCallback();
  5745. return this;
  5746. },
  5747. clone: function () {
  5748. return new this.constructor( this._x, this._y, this._z, this._order );
  5749. },
  5750. copy: function ( euler ) {
  5751. this._x = euler._x;
  5752. this._y = euler._y;
  5753. this._z = euler._z;
  5754. this._order = euler._order;
  5755. this.onChangeCallback();
  5756. return this;
  5757. },
  5758. setFromRotationMatrix: function ( m, order, update ) {
  5759. var clamp = _Math.clamp;
  5760. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5761. var te = m.elements;
  5762. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  5763. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  5764. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  5765. order = order || this._order;
  5766. if ( order === 'XYZ' ) {
  5767. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  5768. if ( Math.abs( m13 ) < 0.99999 ) {
  5769. this._x = Math.atan2( - m23, m33 );
  5770. this._z = Math.atan2( - m12, m11 );
  5771. } else {
  5772. this._x = Math.atan2( m32, m22 );
  5773. this._z = 0;
  5774. }
  5775. } else if ( order === 'YXZ' ) {
  5776. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  5777. if ( Math.abs( m23 ) < 0.99999 ) {
  5778. this._y = Math.atan2( m13, m33 );
  5779. this._z = Math.atan2( m21, m22 );
  5780. } else {
  5781. this._y = Math.atan2( - m31, m11 );
  5782. this._z = 0;
  5783. }
  5784. } else if ( order === 'ZXY' ) {
  5785. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  5786. if ( Math.abs( m32 ) < 0.99999 ) {
  5787. this._y = Math.atan2( - m31, m33 );
  5788. this._z = Math.atan2( - m12, m22 );
  5789. } else {
  5790. this._y = 0;
  5791. this._z = Math.atan2( m21, m11 );
  5792. }
  5793. } else if ( order === 'ZYX' ) {
  5794. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  5795. if ( Math.abs( m31 ) < 0.99999 ) {
  5796. this._x = Math.atan2( m32, m33 );
  5797. this._z = Math.atan2( m21, m11 );
  5798. } else {
  5799. this._x = 0;
  5800. this._z = Math.atan2( - m12, m22 );
  5801. }
  5802. } else if ( order === 'YZX' ) {
  5803. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  5804. if ( Math.abs( m21 ) < 0.99999 ) {
  5805. this._x = Math.atan2( - m23, m22 );
  5806. this._y = Math.atan2( - m31, m11 );
  5807. } else {
  5808. this._x = 0;
  5809. this._y = Math.atan2( m13, m33 );
  5810. }
  5811. } else if ( order === 'XZY' ) {
  5812. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  5813. if ( Math.abs( m12 ) < 0.99999 ) {
  5814. this._x = Math.atan2( m32, m22 );
  5815. this._y = Math.atan2( m13, m11 );
  5816. } else {
  5817. this._x = Math.atan2( - m23, m33 );
  5818. this._y = 0;
  5819. }
  5820. } else {
  5821. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  5822. }
  5823. this._order = order;
  5824. if ( update !== false ) this.onChangeCallback();
  5825. return this;
  5826. },
  5827. setFromQuaternion: function () {
  5828. var matrix = new Matrix4();
  5829. return function setFromQuaternion( q, order, update ) {
  5830. matrix.makeRotationFromQuaternion( q );
  5831. return this.setFromRotationMatrix( matrix, order, update );
  5832. };
  5833. }(),
  5834. setFromVector3: function ( v, order ) {
  5835. return this.set( v.x, v.y, v.z, order || this._order );
  5836. },
  5837. reorder: function () {
  5838. // WARNING: this discards revolution information -bhouston
  5839. var q = new Quaternion();
  5840. return function reorder( newOrder ) {
  5841. q.setFromEuler( this );
  5842. return this.setFromQuaternion( q, newOrder );
  5843. };
  5844. }(),
  5845. equals: function ( euler ) {
  5846. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  5847. },
  5848. fromArray: function ( array ) {
  5849. this._x = array[ 0 ];
  5850. this._y = array[ 1 ];
  5851. this._z = array[ 2 ];
  5852. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  5853. this.onChangeCallback();
  5854. return this;
  5855. },
  5856. toArray: function ( array, offset ) {
  5857. if ( array === undefined ) array = [];
  5858. if ( offset === undefined ) offset = 0;
  5859. array[ offset ] = this._x;
  5860. array[ offset + 1 ] = this._y;
  5861. array[ offset + 2 ] = this._z;
  5862. array[ offset + 3 ] = this._order;
  5863. return array;
  5864. },
  5865. toVector3: function ( optionalResult ) {
  5866. if ( optionalResult ) {
  5867. return optionalResult.set( this._x, this._y, this._z );
  5868. } else {
  5869. return new Vector3( this._x, this._y, this._z );
  5870. }
  5871. },
  5872. onChange: function ( callback ) {
  5873. this.onChangeCallback = callback;
  5874. return this;
  5875. },
  5876. onChangeCallback: function () {}
  5877. } );
  5878. /**
  5879. * @author mrdoob / http://mrdoob.com/
  5880. */
  5881. function Layers() {
  5882. this.mask = 1 | 0;
  5883. }
  5884. Object.assign( Layers.prototype, {
  5885. set: function ( channel ) {
  5886. this.mask = 1 << channel | 0;
  5887. },
  5888. enable: function ( channel ) {
  5889. this.mask |= 1 << channel | 0;
  5890. },
  5891. toggle: function ( channel ) {
  5892. this.mask ^= 1 << channel | 0;
  5893. },
  5894. disable: function ( channel ) {
  5895. this.mask &= ~ ( 1 << channel | 0 );
  5896. },
  5897. test: function ( layers ) {
  5898. return ( this.mask & layers.mask ) !== 0;
  5899. }
  5900. } );
  5901. /**
  5902. * @author mrdoob / http://mrdoob.com/
  5903. * @author mikael emtinger / http://gomo.se/
  5904. * @author alteredq / http://alteredqualia.com/
  5905. * @author WestLangley / http://github.com/WestLangley
  5906. * @author elephantatwork / www.elephantatwork.ch
  5907. */
  5908. var object3DId = 0;
  5909. function Object3D() {
  5910. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  5911. this.uuid = _Math.generateUUID();
  5912. this.name = '';
  5913. this.type = 'Object3D';
  5914. this.parent = null;
  5915. this.children = [];
  5916. this.up = Object3D.DefaultUp.clone();
  5917. var position = new Vector3();
  5918. var rotation = new Euler();
  5919. var quaternion = new Quaternion();
  5920. var scale = new Vector3( 1, 1, 1 );
  5921. function onRotationChange() {
  5922. quaternion.setFromEuler( rotation, false );
  5923. }
  5924. function onQuaternionChange() {
  5925. rotation.setFromQuaternion( quaternion, undefined, false );
  5926. }
  5927. rotation.onChange( onRotationChange );
  5928. quaternion.onChange( onQuaternionChange );
  5929. Object.defineProperties( this, {
  5930. position: {
  5931. enumerable: true,
  5932. value: position
  5933. },
  5934. rotation: {
  5935. enumerable: true,
  5936. value: rotation
  5937. },
  5938. quaternion: {
  5939. enumerable: true,
  5940. value: quaternion
  5941. },
  5942. scale: {
  5943. enumerable: true,
  5944. value: scale
  5945. },
  5946. modelViewMatrix: {
  5947. value: new Matrix4()
  5948. },
  5949. normalMatrix: {
  5950. value: new Matrix3()
  5951. }
  5952. } );
  5953. this.matrix = new Matrix4();
  5954. this.matrixWorld = new Matrix4();
  5955. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5956. this.matrixWorldNeedsUpdate = false;
  5957. this.layers = new Layers();
  5958. this.visible = true;
  5959. this.castShadow = false;
  5960. this.receiveShadow = false;
  5961. this.frustumCulled = true;
  5962. this.renderOrder = 0;
  5963. this.userData = {};
  5964. }
  5965. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  5966. Object3D.DefaultMatrixAutoUpdate = true;
  5967. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5968. constructor: Object3D,
  5969. isObject3D: true,
  5970. onBeforeRender: function () {},
  5971. onAfterRender: function () {},
  5972. applyMatrix: function ( matrix ) {
  5973. this.matrix.multiplyMatrices( matrix, this.matrix );
  5974. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5975. },
  5976. applyQuaternion: function ( q ) {
  5977. this.quaternion.premultiply( q );
  5978. return this;
  5979. },
  5980. setRotationFromAxisAngle: function ( axis, angle ) {
  5981. // assumes axis is normalized
  5982. this.quaternion.setFromAxisAngle( axis, angle );
  5983. },
  5984. setRotationFromEuler: function ( euler ) {
  5985. this.quaternion.setFromEuler( euler, true );
  5986. },
  5987. setRotationFromMatrix: function ( m ) {
  5988. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5989. this.quaternion.setFromRotationMatrix( m );
  5990. },
  5991. setRotationFromQuaternion: function ( q ) {
  5992. // assumes q is normalized
  5993. this.quaternion.copy( q );
  5994. },
  5995. rotateOnAxis: function () {
  5996. // rotate object on axis in object space
  5997. // axis is assumed to be normalized
  5998. var q1 = new Quaternion();
  5999. return function rotateOnAxis( axis, angle ) {
  6000. q1.setFromAxisAngle( axis, angle );
  6001. this.quaternion.multiply( q1 );
  6002. return this;
  6003. };
  6004. }(),
  6005. rotateOnWorldAxis: function () {
  6006. // rotate object on axis in world space
  6007. // axis is assumed to be normalized
  6008. // method assumes no rotated parent
  6009. var q1 = new Quaternion();
  6010. return function rotateOnWorldAxis( axis, angle ) {
  6011. q1.setFromAxisAngle( axis, angle );
  6012. this.quaternion.premultiply( q1 );
  6013. return this;
  6014. };
  6015. }(),
  6016. rotateX: function () {
  6017. var v1 = new Vector3( 1, 0, 0 );
  6018. return function rotateX( angle ) {
  6019. return this.rotateOnAxis( v1, angle );
  6020. };
  6021. }(),
  6022. rotateY: function () {
  6023. var v1 = new Vector3( 0, 1, 0 );
  6024. return function rotateY( angle ) {
  6025. return this.rotateOnAxis( v1, angle );
  6026. };
  6027. }(),
  6028. rotateZ: function () {
  6029. var v1 = new Vector3( 0, 0, 1 );
  6030. return function rotateZ( angle ) {
  6031. return this.rotateOnAxis( v1, angle );
  6032. };
  6033. }(),
  6034. translateOnAxis: function () {
  6035. // translate object by distance along axis in object space
  6036. // axis is assumed to be normalized
  6037. var v1 = new Vector3();
  6038. return function translateOnAxis( axis, distance ) {
  6039. v1.copy( axis ).applyQuaternion( this.quaternion );
  6040. this.position.add( v1.multiplyScalar( distance ) );
  6041. return this;
  6042. };
  6043. }(),
  6044. translateX: function () {
  6045. var v1 = new Vector3( 1, 0, 0 );
  6046. return function translateX( distance ) {
  6047. return this.translateOnAxis( v1, distance );
  6048. };
  6049. }(),
  6050. translateY: function () {
  6051. var v1 = new Vector3( 0, 1, 0 );
  6052. return function translateY( distance ) {
  6053. return this.translateOnAxis( v1, distance );
  6054. };
  6055. }(),
  6056. translateZ: function () {
  6057. var v1 = new Vector3( 0, 0, 1 );
  6058. return function translateZ( distance ) {
  6059. return this.translateOnAxis( v1, distance );
  6060. };
  6061. }(),
  6062. localToWorld: function ( vector ) {
  6063. return vector.applyMatrix4( this.matrixWorld );
  6064. },
  6065. worldToLocal: function () {
  6066. var m1 = new Matrix4();
  6067. return function worldToLocal( vector ) {
  6068. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  6069. };
  6070. }(),
  6071. lookAt: function () {
  6072. // This method does not support objects with rotated and/or translated parent(s)
  6073. var m1 = new Matrix4();
  6074. var vector = new Vector3();
  6075. return function lookAt( x, y, z ) {
  6076. if ( x.isVector3 ) {
  6077. vector.copy( x );
  6078. } else {
  6079. vector.set( x, y, z );
  6080. }
  6081. if ( this.isCamera ) {
  6082. m1.lookAt( this.position, vector, this.up );
  6083. } else {
  6084. m1.lookAt( vector, this.position, this.up );
  6085. }
  6086. this.quaternion.setFromRotationMatrix( m1 );
  6087. };
  6088. }(),
  6089. add: function ( object ) {
  6090. if ( arguments.length > 1 ) {
  6091. for ( var i = 0; i < arguments.length; i ++ ) {
  6092. this.add( arguments[ i ] );
  6093. }
  6094. return this;
  6095. }
  6096. if ( object === this ) {
  6097. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  6098. return this;
  6099. }
  6100. if ( ( object && object.isObject3D ) ) {
  6101. if ( object.parent !== null ) {
  6102. object.parent.remove( object );
  6103. }
  6104. object.parent = this;
  6105. object.dispatchEvent( { type: 'added' } );
  6106. this.children.push( object );
  6107. } else {
  6108. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  6109. }
  6110. return this;
  6111. },
  6112. remove: function ( object ) {
  6113. if ( arguments.length > 1 ) {
  6114. for ( var i = 0; i < arguments.length; i ++ ) {
  6115. this.remove( arguments[ i ] );
  6116. }
  6117. return this;
  6118. }
  6119. var index = this.children.indexOf( object );
  6120. if ( index !== - 1 ) {
  6121. object.parent = null;
  6122. object.dispatchEvent( { type: 'removed' } );
  6123. this.children.splice( index, 1 );
  6124. }
  6125. return this;
  6126. },
  6127. getObjectById: function ( id ) {
  6128. return this.getObjectByProperty( 'id', id );
  6129. },
  6130. getObjectByName: function ( name ) {
  6131. return this.getObjectByProperty( 'name', name );
  6132. },
  6133. getObjectByProperty: function ( name, value ) {
  6134. if ( this[ name ] === value ) return this;
  6135. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  6136. var child = this.children[ i ];
  6137. var object = child.getObjectByProperty( name, value );
  6138. if ( object !== undefined ) {
  6139. return object;
  6140. }
  6141. }
  6142. return undefined;
  6143. },
  6144. getWorldPosition: function ( optionalTarget ) {
  6145. var result = optionalTarget || new Vector3();
  6146. this.updateMatrixWorld( true );
  6147. return result.setFromMatrixPosition( this.matrixWorld );
  6148. },
  6149. getWorldQuaternion: function () {
  6150. var position = new Vector3();
  6151. var scale = new Vector3();
  6152. return function getWorldQuaternion( optionalTarget ) {
  6153. var result = optionalTarget || new Quaternion();
  6154. this.updateMatrixWorld( true );
  6155. this.matrixWorld.decompose( position, result, scale );
  6156. return result;
  6157. };
  6158. }(),
  6159. getWorldRotation: function () {
  6160. var quaternion = new Quaternion();
  6161. return function getWorldRotation( optionalTarget ) {
  6162. var result = optionalTarget || new Euler();
  6163. this.getWorldQuaternion( quaternion );
  6164. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  6165. };
  6166. }(),
  6167. getWorldScale: function () {
  6168. var position = new Vector3();
  6169. var quaternion = new Quaternion();
  6170. return function getWorldScale( optionalTarget ) {
  6171. var result = optionalTarget || new Vector3();
  6172. this.updateMatrixWorld( true );
  6173. this.matrixWorld.decompose( position, quaternion, result );
  6174. return result;
  6175. };
  6176. }(),
  6177. getWorldDirection: function () {
  6178. var quaternion = new Quaternion();
  6179. return function getWorldDirection( optionalTarget ) {
  6180. var result = optionalTarget || new Vector3();
  6181. this.getWorldQuaternion( quaternion );
  6182. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  6183. };
  6184. }(),
  6185. raycast: function () {},
  6186. traverse: function ( callback ) {
  6187. callback( this );
  6188. var children = this.children;
  6189. for ( var i = 0, l = children.length; i < l; i ++ ) {
  6190. children[ i ].traverse( callback );
  6191. }
  6192. },
  6193. traverseVisible: function ( callback ) {
  6194. if ( this.visible === false ) return;
  6195. callback( this );
  6196. var children = this.children;
  6197. for ( var i = 0, l = children.length; i < l; i ++ ) {
  6198. children[ i ].traverseVisible( callback );
  6199. }
  6200. },
  6201. traverseAncestors: function ( callback ) {
  6202. var parent = this.parent;
  6203. if ( parent !== null ) {
  6204. callback( parent );
  6205. parent.traverseAncestors( callback );
  6206. }
  6207. },
  6208. updateMatrix: function () {
  6209. this.matrix.compose( this.position, this.quaternion, this.scale );
  6210. this.matrixWorldNeedsUpdate = true;
  6211. },
  6212. updateMatrixWorld: function ( force ) {
  6213. if ( this.matrixAutoUpdate ) this.updateMatrix();
  6214. if ( this.matrixWorldNeedsUpdate || force ) {
  6215. if ( this.parent === null ) {
  6216. this.matrixWorld.copy( this.matrix );
  6217. } else {
  6218. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  6219. }
  6220. this.matrixWorldNeedsUpdate = false;
  6221. force = true;
  6222. }
  6223. // update children
  6224. var children = this.children;
  6225. for ( var i = 0, l = children.length; i < l; i ++ ) {
  6226. children[ i ].updateMatrixWorld( force );
  6227. }
  6228. },
  6229. toJSON: function ( meta ) {
  6230. // meta is a string when called from JSON.stringify
  6231. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  6232. var output = {};
  6233. // meta is a hash used to collect geometries, materials.
  6234. // not providing it implies that this is the root object
  6235. // being serialized.
  6236. if ( isRootObject ) {
  6237. // initialize meta obj
  6238. meta = {
  6239. geometries: {},
  6240. materials: {},
  6241. textures: {},
  6242. images: {},
  6243. shapes: {}
  6244. };
  6245. output.metadata = {
  6246. version: 4.5,
  6247. type: 'Object',
  6248. generator: 'Object3D.toJSON'
  6249. };
  6250. }
  6251. // standard Object3D serialization
  6252. var object = {};
  6253. object.uuid = this.uuid;
  6254. object.type = this.type;
  6255. if ( this.name !== '' ) object.name = this.name;
  6256. if ( this.castShadow === true ) object.castShadow = true;
  6257. if ( this.receiveShadow === true ) object.receiveShadow = true;
  6258. if ( this.visible === false ) object.visible = false;
  6259. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  6260. object.matrix = this.matrix.toArray();
  6261. //
  6262. function serialize( library, element ) {
  6263. if ( library[ element.uuid ] === undefined ) {
  6264. library[ element.uuid ] = element.toJSON( meta );
  6265. }
  6266. return element.uuid;
  6267. }
  6268. if ( this.geometry !== undefined ) {
  6269. object.geometry = serialize( meta.geometries, this.geometry );
  6270. var parameters = this.geometry.parameters;
  6271. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  6272. var shapes = parameters.shapes;
  6273. if ( Array.isArray( shapes ) ) {
  6274. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  6275. var shape = shapes[ i ];
  6276. serialize( meta.shapes, shape );
  6277. }
  6278. } else {
  6279. serialize( meta.shapes, shapes );
  6280. }
  6281. }
  6282. }
  6283. if ( this.material !== undefined ) {
  6284. if ( Array.isArray( this.material ) ) {
  6285. var uuids = [];
  6286. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  6287. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  6288. }
  6289. object.material = uuids;
  6290. } else {
  6291. object.material = serialize( meta.materials, this.material );
  6292. }
  6293. }
  6294. //
  6295. if ( this.children.length > 0 ) {
  6296. object.children = [];
  6297. for ( var i = 0; i < this.children.length; i ++ ) {
  6298. object.children.push( this.children[ i ].toJSON( meta ).object );
  6299. }
  6300. }
  6301. if ( isRootObject ) {
  6302. var geometries = extractFromCache( meta.geometries );
  6303. var materials = extractFromCache( meta.materials );
  6304. var textures = extractFromCache( meta.textures );
  6305. var images = extractFromCache( meta.images );
  6306. var shapes = extractFromCache( meta.shapes );
  6307. if ( geometries.length > 0 ) output.geometries = geometries;
  6308. if ( materials.length > 0 ) output.materials = materials;
  6309. if ( textures.length > 0 ) output.textures = textures;
  6310. if ( images.length > 0 ) output.images = images;
  6311. if ( shapes.length > 0 ) output.shapes = shapes;
  6312. }
  6313. output.object = object;
  6314. return output;
  6315. // extract data from the cache hash
  6316. // remove metadata on each item
  6317. // and return as array
  6318. function extractFromCache( cache ) {
  6319. var values = [];
  6320. for ( var key in cache ) {
  6321. var data = cache[ key ];
  6322. delete data.metadata;
  6323. values.push( data );
  6324. }
  6325. return values;
  6326. }
  6327. },
  6328. clone: function ( recursive ) {
  6329. return new this.constructor().copy( this, recursive );
  6330. },
  6331. copy: function ( source, recursive ) {
  6332. if ( recursive === undefined ) recursive = true;
  6333. this.name = source.name;
  6334. this.up.copy( source.up );
  6335. this.position.copy( source.position );
  6336. this.quaternion.copy( source.quaternion );
  6337. this.scale.copy( source.scale );
  6338. this.matrix.copy( source.matrix );
  6339. this.matrixWorld.copy( source.matrixWorld );
  6340. this.matrixAutoUpdate = source.matrixAutoUpdate;
  6341. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  6342. this.layers.mask = source.layers.mask;
  6343. this.visible = source.visible;
  6344. this.castShadow = source.castShadow;
  6345. this.receiveShadow = source.receiveShadow;
  6346. this.frustumCulled = source.frustumCulled;
  6347. this.renderOrder = source.renderOrder;
  6348. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  6349. if ( recursive === true ) {
  6350. for ( var i = 0; i < source.children.length; i ++ ) {
  6351. var child = source.children[ i ];
  6352. this.add( child.clone() );
  6353. }
  6354. }
  6355. return this;
  6356. }
  6357. } );
  6358. /**
  6359. * @author mrdoob / http://mrdoob.com/
  6360. * @author mikael emtinger / http://gomo.se/
  6361. * @author WestLangley / http://github.com/WestLangley
  6362. */
  6363. function Camera() {
  6364. Object3D.call( this );
  6365. this.type = 'Camera';
  6366. this.matrixWorldInverse = new Matrix4();
  6367. this.projectionMatrix = new Matrix4();
  6368. }
  6369. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  6370. constructor: Camera,
  6371. isCamera: true,
  6372. copy: function ( source, recursive ) {
  6373. Object3D.prototype.copy.call( this, source, recursive );
  6374. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  6375. this.projectionMatrix.copy( source.projectionMatrix );
  6376. return this;
  6377. },
  6378. getWorldDirection: function () {
  6379. var quaternion = new Quaternion();
  6380. return function getWorldDirection( optionalTarget ) {
  6381. var result = optionalTarget || new Vector3();
  6382. this.getWorldQuaternion( quaternion );
  6383. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  6384. };
  6385. }(),
  6386. updateMatrixWorld: function ( force ) {
  6387. Object3D.prototype.updateMatrixWorld.call( this, force );
  6388. this.matrixWorldInverse.getInverse( this.matrixWorld );
  6389. },
  6390. clone: function () {
  6391. return new this.constructor().copy( this );
  6392. }
  6393. } );
  6394. /**
  6395. * @author alteredq / http://alteredqualia.com/
  6396. * @author arose / http://github.com/arose
  6397. */
  6398. function OrthographicCamera( left, right, top, bottom, near, far ) {
  6399. Camera.call( this );
  6400. this.type = 'OrthographicCamera';
  6401. this.zoom = 1;
  6402. this.view = null;
  6403. this.left = left;
  6404. this.right = right;
  6405. this.top = top;
  6406. this.bottom = bottom;
  6407. this.near = ( near !== undefined ) ? near : 0.1;
  6408. this.far = ( far !== undefined ) ? far : 2000;
  6409. this.updateProjectionMatrix();
  6410. }
  6411. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  6412. constructor: OrthographicCamera,
  6413. isOrthographicCamera: true,
  6414. copy: function ( source, recursive ) {
  6415. Camera.prototype.copy.call( this, source, recursive );
  6416. this.left = source.left;
  6417. this.right = source.right;
  6418. this.top = source.top;
  6419. this.bottom = source.bottom;
  6420. this.near = source.near;
  6421. this.far = source.far;
  6422. this.zoom = source.zoom;
  6423. this.view = source.view === null ? null : Object.assign( {}, source.view );
  6424. return this;
  6425. },
  6426. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  6427. if ( this.view === null ) {
  6428. this.view = {
  6429. enabled: true,
  6430. fullWidth: 1,
  6431. fullHeight: 1,
  6432. offsetX: 0,
  6433. offsetY: 0,
  6434. width: 1,
  6435. height: 1
  6436. };
  6437. }
  6438. this.view.enabled = true;
  6439. this.view.fullWidth = fullWidth;
  6440. this.view.fullHeight = fullHeight;
  6441. this.view.offsetX = x;
  6442. this.view.offsetY = y;
  6443. this.view.width = width;
  6444. this.view.height = height;
  6445. this.updateProjectionMatrix();
  6446. },
  6447. clearViewOffset: function () {
  6448. if ( this.view !== null ) {
  6449. this.view.enabled = false;
  6450. }
  6451. this.updateProjectionMatrix();
  6452. },
  6453. updateProjectionMatrix: function () {
  6454. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  6455. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  6456. var cx = ( this.right + this.left ) / 2;
  6457. var cy = ( this.top + this.bottom ) / 2;
  6458. var left = cx - dx;
  6459. var right = cx + dx;
  6460. var top = cy + dy;
  6461. var bottom = cy - dy;
  6462. if ( this.view !== null && this.view.enabled ) {
  6463. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  6464. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  6465. var scaleW = ( this.right - this.left ) / this.view.width;
  6466. var scaleH = ( this.top - this.bottom ) / this.view.height;
  6467. left += scaleW * ( this.view.offsetX / zoomW );
  6468. right = left + scaleW * ( this.view.width / zoomW );
  6469. top -= scaleH * ( this.view.offsetY / zoomH );
  6470. bottom = top - scaleH * ( this.view.height / zoomH );
  6471. }
  6472. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  6473. },
  6474. toJSON: function ( meta ) {
  6475. var data = Object3D.prototype.toJSON.call( this, meta );
  6476. data.object.zoom = this.zoom;
  6477. data.object.left = this.left;
  6478. data.object.right = this.right;
  6479. data.object.top = this.top;
  6480. data.object.bottom = this.bottom;
  6481. data.object.near = this.near;
  6482. data.object.far = this.far;
  6483. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  6484. return data;
  6485. }
  6486. } );
  6487. /**
  6488. * @author mrdoob / http://mrdoob.com/
  6489. * @author alteredq / http://alteredqualia.com/
  6490. */
  6491. function Face3( a, b, c, normal, color, materialIndex ) {
  6492. this.a = a;
  6493. this.b = b;
  6494. this.c = c;
  6495. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  6496. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  6497. this.color = ( color && color.isColor ) ? color : new Color();
  6498. this.vertexColors = Array.isArray( color ) ? color : [];
  6499. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  6500. }
  6501. Object.assign( Face3.prototype, {
  6502. clone: function () {
  6503. return new this.constructor().copy( this );
  6504. },
  6505. copy: function ( source ) {
  6506. this.a = source.a;
  6507. this.b = source.b;
  6508. this.c = source.c;
  6509. this.normal.copy( source.normal );
  6510. this.color.copy( source.color );
  6511. this.materialIndex = source.materialIndex;
  6512. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  6513. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  6514. }
  6515. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  6516. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  6517. }
  6518. return this;
  6519. }
  6520. } );
  6521. /**
  6522. * @author mrdoob / http://mrdoob.com/
  6523. * @author kile / http://kile.stravaganza.org/
  6524. * @author alteredq / http://alteredqualia.com/
  6525. * @author mikael emtinger / http://gomo.se/
  6526. * @author zz85 / http://www.lab4games.net/zz85/blog
  6527. * @author bhouston / http://clara.io
  6528. */
  6529. var geometryId = 0; // Geometry uses even numbers as Id
  6530. function Geometry() {
  6531. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  6532. this.uuid = _Math.generateUUID();
  6533. this.name = '';
  6534. this.type = 'Geometry';
  6535. this.vertices = [];
  6536. this.colors = [];
  6537. this.faces = [];
  6538. this.faceVertexUvs = [[]];
  6539. this.morphTargets = [];
  6540. this.morphNormals = [];
  6541. this.skinWeights = [];
  6542. this.skinIndices = [];
  6543. this.lineDistances = [];
  6544. this.boundingBox = null;
  6545. this.boundingSphere = null;
  6546. // update flags
  6547. this.elementsNeedUpdate = false;
  6548. this.verticesNeedUpdate = false;
  6549. this.uvsNeedUpdate = false;
  6550. this.normalsNeedUpdate = false;
  6551. this.colorsNeedUpdate = false;
  6552. this.lineDistancesNeedUpdate = false;
  6553. this.groupsNeedUpdate = false;
  6554. }
  6555. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6556. constructor: Geometry,
  6557. isGeometry: true,
  6558. applyMatrix: function ( matrix ) {
  6559. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6560. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  6561. var vertex = this.vertices[ i ];
  6562. vertex.applyMatrix4( matrix );
  6563. }
  6564. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  6565. var face = this.faces[ i ];
  6566. face.normal.applyMatrix3( normalMatrix ).normalize();
  6567. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  6568. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  6569. }
  6570. }
  6571. if ( this.boundingBox !== null ) {
  6572. this.computeBoundingBox();
  6573. }
  6574. if ( this.boundingSphere !== null ) {
  6575. this.computeBoundingSphere();
  6576. }
  6577. this.verticesNeedUpdate = true;
  6578. this.normalsNeedUpdate = true;
  6579. return this;
  6580. },
  6581. rotateX: function () {
  6582. // rotate geometry around world x-axis
  6583. var m1 = new Matrix4();
  6584. return function rotateX( angle ) {
  6585. m1.makeRotationX( angle );
  6586. this.applyMatrix( m1 );
  6587. return this;
  6588. };
  6589. }(),
  6590. rotateY: function () {
  6591. // rotate geometry around world y-axis
  6592. var m1 = new Matrix4();
  6593. return function rotateY( angle ) {
  6594. m1.makeRotationY( angle );
  6595. this.applyMatrix( m1 );
  6596. return this;
  6597. };
  6598. }(),
  6599. rotateZ: function () {
  6600. // rotate geometry around world z-axis
  6601. var m1 = new Matrix4();
  6602. return function rotateZ( angle ) {
  6603. m1.makeRotationZ( angle );
  6604. this.applyMatrix( m1 );
  6605. return this;
  6606. };
  6607. }(),
  6608. translate: function () {
  6609. // translate geometry
  6610. var m1 = new Matrix4();
  6611. return function translate( x, y, z ) {
  6612. m1.makeTranslation( x, y, z );
  6613. this.applyMatrix( m1 );
  6614. return this;
  6615. };
  6616. }(),
  6617. scale: function () {
  6618. // scale geometry
  6619. var m1 = new Matrix4();
  6620. return function scale( x, y, z ) {
  6621. m1.makeScale( x, y, z );
  6622. this.applyMatrix( m1 );
  6623. return this;
  6624. };
  6625. }(),
  6626. lookAt: function () {
  6627. var obj = new Object3D();
  6628. return function lookAt( vector ) {
  6629. obj.lookAt( vector );
  6630. obj.updateMatrix();
  6631. this.applyMatrix( obj.matrix );
  6632. };
  6633. }(),
  6634. fromBufferGeometry: function ( geometry ) {
  6635. var scope = this;
  6636. var indices = geometry.index !== null ? geometry.index.array : undefined;
  6637. var attributes = geometry.attributes;
  6638. var positions = attributes.position.array;
  6639. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  6640. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  6641. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  6642. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  6643. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  6644. var tempNormals = [];
  6645. var tempUVs = [];
  6646. var tempUVs2 = [];
  6647. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  6648. scope.vertices.push( new Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  6649. if ( normals !== undefined ) {
  6650. tempNormals.push( new Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  6651. }
  6652. if ( colors !== undefined ) {
  6653. scope.colors.push( new Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  6654. }
  6655. if ( uvs !== undefined ) {
  6656. tempUVs.push( new Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  6657. }
  6658. if ( uvs2 !== undefined ) {
  6659. tempUVs2.push( new Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  6660. }
  6661. }
  6662. function addFace( a, b, c, materialIndex ) {
  6663. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  6664. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  6665. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  6666. scope.faces.push( face );
  6667. if ( uvs !== undefined ) {
  6668. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  6669. }
  6670. if ( uvs2 !== undefined ) {
  6671. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  6672. }
  6673. }
  6674. var groups = geometry.groups;
  6675. if ( groups.length > 0 ) {
  6676. for ( var i = 0; i < groups.length; i ++ ) {
  6677. var group = groups[ i ];
  6678. var start = group.start;
  6679. var count = group.count;
  6680. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  6681. if ( indices !== undefined ) {
  6682. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  6683. } else {
  6684. addFace( j, j + 1, j + 2, group.materialIndex );
  6685. }
  6686. }
  6687. }
  6688. } else {
  6689. if ( indices !== undefined ) {
  6690. for ( var i = 0; i < indices.length; i += 3 ) {
  6691. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  6692. }
  6693. } else {
  6694. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  6695. addFace( i, i + 1, i + 2 );
  6696. }
  6697. }
  6698. }
  6699. this.computeFaceNormals();
  6700. if ( geometry.boundingBox !== null ) {
  6701. this.boundingBox = geometry.boundingBox.clone();
  6702. }
  6703. if ( geometry.boundingSphere !== null ) {
  6704. this.boundingSphere = geometry.boundingSphere.clone();
  6705. }
  6706. return this;
  6707. },
  6708. center: function () {
  6709. this.computeBoundingBox();
  6710. var offset = this.boundingBox.getCenter().negate();
  6711. this.translate( offset.x, offset.y, offset.z );
  6712. return offset;
  6713. },
  6714. normalize: function () {
  6715. this.computeBoundingSphere();
  6716. var center = this.boundingSphere.center;
  6717. var radius = this.boundingSphere.radius;
  6718. var s = radius === 0 ? 1 : 1.0 / radius;
  6719. var matrix = new Matrix4();
  6720. matrix.set(
  6721. s, 0, 0, - s * center.x,
  6722. 0, s, 0, - s * center.y,
  6723. 0, 0, s, - s * center.z,
  6724. 0, 0, 0, 1
  6725. );
  6726. this.applyMatrix( matrix );
  6727. return this;
  6728. },
  6729. computeFaceNormals: function () {
  6730. var cb = new Vector3(), ab = new Vector3();
  6731. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6732. var face = this.faces[ f ];
  6733. var vA = this.vertices[ face.a ];
  6734. var vB = this.vertices[ face.b ];
  6735. var vC = this.vertices[ face.c ];
  6736. cb.subVectors( vC, vB );
  6737. ab.subVectors( vA, vB );
  6738. cb.cross( ab );
  6739. cb.normalize();
  6740. face.normal.copy( cb );
  6741. }
  6742. },
  6743. computeVertexNormals: function ( areaWeighted ) {
  6744. if ( areaWeighted === undefined ) areaWeighted = true;
  6745. var v, vl, f, fl, face, vertices;
  6746. vertices = new Array( this.vertices.length );
  6747. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6748. vertices[ v ] = new Vector3();
  6749. }
  6750. if ( areaWeighted ) {
  6751. // vertex normals weighted by triangle areas
  6752. // http://www.iquilezles.org/www/articles/normals/normals.htm
  6753. var vA, vB, vC;
  6754. var cb = new Vector3(), ab = new Vector3();
  6755. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6756. face = this.faces[ f ];
  6757. vA = this.vertices[ face.a ];
  6758. vB = this.vertices[ face.b ];
  6759. vC = this.vertices[ face.c ];
  6760. cb.subVectors( vC, vB );
  6761. ab.subVectors( vA, vB );
  6762. cb.cross( ab );
  6763. vertices[ face.a ].add( cb );
  6764. vertices[ face.b ].add( cb );
  6765. vertices[ face.c ].add( cb );
  6766. }
  6767. } else {
  6768. this.computeFaceNormals();
  6769. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6770. face = this.faces[ f ];
  6771. vertices[ face.a ].add( face.normal );
  6772. vertices[ face.b ].add( face.normal );
  6773. vertices[ face.c ].add( face.normal );
  6774. }
  6775. }
  6776. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6777. vertices[ v ].normalize();
  6778. }
  6779. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6780. face = this.faces[ f ];
  6781. var vertexNormals = face.vertexNormals;
  6782. if ( vertexNormals.length === 3 ) {
  6783. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  6784. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  6785. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  6786. } else {
  6787. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  6788. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  6789. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  6790. }
  6791. }
  6792. if ( this.faces.length > 0 ) {
  6793. this.normalsNeedUpdate = true;
  6794. }
  6795. },
  6796. computeFlatVertexNormals: function () {
  6797. var f, fl, face;
  6798. this.computeFaceNormals();
  6799. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6800. face = this.faces[ f ];
  6801. var vertexNormals = face.vertexNormals;
  6802. if ( vertexNormals.length === 3 ) {
  6803. vertexNormals[ 0 ].copy( face.normal );
  6804. vertexNormals[ 1 ].copy( face.normal );
  6805. vertexNormals[ 2 ].copy( face.normal );
  6806. } else {
  6807. vertexNormals[ 0 ] = face.normal.clone();
  6808. vertexNormals[ 1 ] = face.normal.clone();
  6809. vertexNormals[ 2 ] = face.normal.clone();
  6810. }
  6811. }
  6812. if ( this.faces.length > 0 ) {
  6813. this.normalsNeedUpdate = true;
  6814. }
  6815. },
  6816. computeMorphNormals: function () {
  6817. var i, il, f, fl, face;
  6818. // save original normals
  6819. // - create temp variables on first access
  6820. // otherwise just copy (for faster repeated calls)
  6821. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6822. face = this.faces[ f ];
  6823. if ( ! face.__originalFaceNormal ) {
  6824. face.__originalFaceNormal = face.normal.clone();
  6825. } else {
  6826. face.__originalFaceNormal.copy( face.normal );
  6827. }
  6828. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  6829. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  6830. if ( ! face.__originalVertexNormals[ i ] ) {
  6831. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  6832. } else {
  6833. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  6834. }
  6835. }
  6836. }
  6837. // use temp geometry to compute face and vertex normals for each morph
  6838. var tmpGeo = new Geometry();
  6839. tmpGeo.faces = this.faces;
  6840. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  6841. // create on first access
  6842. if ( ! this.morphNormals[ i ] ) {
  6843. this.morphNormals[ i ] = {};
  6844. this.morphNormals[ i ].faceNormals = [];
  6845. this.morphNormals[ i ].vertexNormals = [];
  6846. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  6847. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  6848. var faceNormal, vertexNormals;
  6849. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6850. faceNormal = new Vector3();
  6851. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  6852. dstNormalsFace.push( faceNormal );
  6853. dstNormalsVertex.push( vertexNormals );
  6854. }
  6855. }
  6856. var morphNormals = this.morphNormals[ i ];
  6857. // set vertices to morph target
  6858. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  6859. // compute morph normals
  6860. tmpGeo.computeFaceNormals();
  6861. tmpGeo.computeVertexNormals();
  6862. // store morph normals
  6863. var faceNormal, vertexNormals;
  6864. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6865. face = this.faces[ f ];
  6866. faceNormal = morphNormals.faceNormals[ f ];
  6867. vertexNormals = morphNormals.vertexNormals[ f ];
  6868. faceNormal.copy( face.normal );
  6869. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  6870. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  6871. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  6872. }
  6873. }
  6874. // restore original normals
  6875. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6876. face = this.faces[ f ];
  6877. face.normal = face.__originalFaceNormal;
  6878. face.vertexNormals = face.__originalVertexNormals;
  6879. }
  6880. },
  6881. computeLineDistances: function () {
  6882. var d = 0;
  6883. var vertices = this.vertices;
  6884. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6885. if ( i > 0 ) {
  6886. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  6887. }
  6888. this.lineDistances[ i ] = d;
  6889. }
  6890. },
  6891. computeBoundingBox: function () {
  6892. if ( this.boundingBox === null ) {
  6893. this.boundingBox = new Box3();
  6894. }
  6895. this.boundingBox.setFromPoints( this.vertices );
  6896. },
  6897. computeBoundingSphere: function () {
  6898. if ( this.boundingSphere === null ) {
  6899. this.boundingSphere = new Sphere();
  6900. }
  6901. this.boundingSphere.setFromPoints( this.vertices );
  6902. },
  6903. merge: function ( geometry, matrix, materialIndexOffset ) {
  6904. if ( ! ( geometry && geometry.isGeometry ) ) {
  6905. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  6906. return;
  6907. }
  6908. var normalMatrix,
  6909. vertexOffset = this.vertices.length,
  6910. vertices1 = this.vertices,
  6911. vertices2 = geometry.vertices,
  6912. faces1 = this.faces,
  6913. faces2 = geometry.faces,
  6914. uvs1 = this.faceVertexUvs[ 0 ],
  6915. uvs2 = geometry.faceVertexUvs[ 0 ],
  6916. colors1 = this.colors,
  6917. colors2 = geometry.colors;
  6918. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  6919. if ( matrix !== undefined ) {
  6920. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6921. }
  6922. // vertices
  6923. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  6924. var vertex = vertices2[ i ];
  6925. var vertexCopy = vertex.clone();
  6926. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  6927. vertices1.push( vertexCopy );
  6928. }
  6929. // colors
  6930. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  6931. colors1.push( colors2[ i ].clone() );
  6932. }
  6933. // faces
  6934. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  6935. var face = faces2[ i ], faceCopy, normal, color,
  6936. faceVertexNormals = face.vertexNormals,
  6937. faceVertexColors = face.vertexColors;
  6938. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  6939. faceCopy.normal.copy( face.normal );
  6940. if ( normalMatrix !== undefined ) {
  6941. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  6942. }
  6943. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  6944. normal = faceVertexNormals[ j ].clone();
  6945. if ( normalMatrix !== undefined ) {
  6946. normal.applyMatrix3( normalMatrix ).normalize();
  6947. }
  6948. faceCopy.vertexNormals.push( normal );
  6949. }
  6950. faceCopy.color.copy( face.color );
  6951. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  6952. color = faceVertexColors[ j ];
  6953. faceCopy.vertexColors.push( color.clone() );
  6954. }
  6955. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  6956. faces1.push( faceCopy );
  6957. }
  6958. // uvs
  6959. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  6960. var uv = uvs2[ i ], uvCopy = [];
  6961. if ( uv === undefined ) {
  6962. continue;
  6963. }
  6964. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  6965. uvCopy.push( uv[ j ].clone() );
  6966. }
  6967. uvs1.push( uvCopy );
  6968. }
  6969. },
  6970. mergeMesh: function ( mesh ) {
  6971. if ( ! ( mesh && mesh.isMesh ) ) {
  6972. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  6973. return;
  6974. }
  6975. mesh.matrixAutoUpdate && mesh.updateMatrix();
  6976. this.merge( mesh.geometry, mesh.matrix );
  6977. },
  6978. /*
  6979. * Checks for duplicate vertices with hashmap.
  6980. * Duplicated vertices are removed
  6981. * and faces' vertices are updated.
  6982. */
  6983. mergeVertices: function () {
  6984. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  6985. var unique = [], changes = [];
  6986. var v, key;
  6987. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  6988. var precision = Math.pow( 10, precisionPoints );
  6989. var i, il, face;
  6990. var indices, j, jl;
  6991. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  6992. v = this.vertices[ i ];
  6993. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  6994. if ( verticesMap[ key ] === undefined ) {
  6995. verticesMap[ key ] = i;
  6996. unique.push( this.vertices[ i ] );
  6997. changes[ i ] = unique.length - 1;
  6998. } else {
  6999. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  7000. changes[ i ] = changes[ verticesMap[ key ] ];
  7001. }
  7002. }
  7003. // if faces are completely degenerate after merging vertices, we
  7004. // have to remove them from the geometry.
  7005. var faceIndicesToRemove = [];
  7006. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  7007. face = this.faces[ i ];
  7008. face.a = changes[ face.a ];
  7009. face.b = changes[ face.b ];
  7010. face.c = changes[ face.c ];
  7011. indices = [ face.a, face.b, face.c ];
  7012. // if any duplicate vertices are found in a Face3
  7013. // we have to remove the face as nothing can be saved
  7014. for ( var n = 0; n < 3; n ++ ) {
  7015. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  7016. faceIndicesToRemove.push( i );
  7017. break;
  7018. }
  7019. }
  7020. }
  7021. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  7022. var idx = faceIndicesToRemove[ i ];
  7023. this.faces.splice( idx, 1 );
  7024. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  7025. this.faceVertexUvs[ j ].splice( idx, 1 );
  7026. }
  7027. }
  7028. // Use unique set of vertices
  7029. var diff = this.vertices.length - unique.length;
  7030. this.vertices = unique;
  7031. return diff;
  7032. },
  7033. setFromPoints: function ( points ) {
  7034. this.vertices = [];
  7035. for ( var i = 0, l = points.length; i < l; i ++ ) {
  7036. var point = points[ i ];
  7037. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  7038. }
  7039. return this;
  7040. },
  7041. sortFacesByMaterialIndex: function () {
  7042. var faces = this.faces;
  7043. var length = faces.length;
  7044. // tag faces
  7045. for ( var i = 0; i < length; i ++ ) {
  7046. faces[ i ]._id = i;
  7047. }
  7048. // sort faces
  7049. function materialIndexSort( a, b ) {
  7050. return a.materialIndex - b.materialIndex;
  7051. }
  7052. faces.sort( materialIndexSort );
  7053. // sort uvs
  7054. var uvs1 = this.faceVertexUvs[ 0 ];
  7055. var uvs2 = this.faceVertexUvs[ 1 ];
  7056. var newUvs1, newUvs2;
  7057. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  7058. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  7059. for ( var i = 0; i < length; i ++ ) {
  7060. var id = faces[ i ]._id;
  7061. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  7062. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  7063. }
  7064. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  7065. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  7066. },
  7067. toJSON: function () {
  7068. var data = {
  7069. metadata: {
  7070. version: 4.5,
  7071. type: 'Geometry',
  7072. generator: 'Geometry.toJSON'
  7073. }
  7074. };
  7075. // standard Geometry serialization
  7076. data.uuid = this.uuid;
  7077. data.type = this.type;
  7078. if ( this.name !== '' ) data.name = this.name;
  7079. if ( this.parameters !== undefined ) {
  7080. var parameters = this.parameters;
  7081. for ( var key in parameters ) {
  7082. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7083. }
  7084. return data;
  7085. }
  7086. var vertices = [];
  7087. for ( var i = 0; i < this.vertices.length; i ++ ) {
  7088. var vertex = this.vertices[ i ];
  7089. vertices.push( vertex.x, vertex.y, vertex.z );
  7090. }
  7091. var faces = [];
  7092. var normals = [];
  7093. var normalsHash = {};
  7094. var colors = [];
  7095. var colorsHash = {};
  7096. var uvs = [];
  7097. var uvsHash = {};
  7098. for ( var i = 0; i < this.faces.length; i ++ ) {
  7099. var face = this.faces[ i ];
  7100. var hasMaterial = true;
  7101. var hasFaceUv = false; // deprecated
  7102. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  7103. var hasFaceNormal = face.normal.length() > 0;
  7104. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  7105. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  7106. var hasFaceVertexColor = face.vertexColors.length > 0;
  7107. var faceType = 0;
  7108. faceType = setBit( faceType, 0, 0 ); // isQuad
  7109. faceType = setBit( faceType, 1, hasMaterial );
  7110. faceType = setBit( faceType, 2, hasFaceUv );
  7111. faceType = setBit( faceType, 3, hasFaceVertexUv );
  7112. faceType = setBit( faceType, 4, hasFaceNormal );
  7113. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  7114. faceType = setBit( faceType, 6, hasFaceColor );
  7115. faceType = setBit( faceType, 7, hasFaceVertexColor );
  7116. faces.push( faceType );
  7117. faces.push( face.a, face.b, face.c );
  7118. faces.push( face.materialIndex );
  7119. if ( hasFaceVertexUv ) {
  7120. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  7121. faces.push(
  7122. getUvIndex( faceVertexUvs[ 0 ] ),
  7123. getUvIndex( faceVertexUvs[ 1 ] ),
  7124. getUvIndex( faceVertexUvs[ 2 ] )
  7125. );
  7126. }
  7127. if ( hasFaceNormal ) {
  7128. faces.push( getNormalIndex( face.normal ) );
  7129. }
  7130. if ( hasFaceVertexNormal ) {
  7131. var vertexNormals = face.vertexNormals;
  7132. faces.push(
  7133. getNormalIndex( vertexNormals[ 0 ] ),
  7134. getNormalIndex( vertexNormals[ 1 ] ),
  7135. getNormalIndex( vertexNormals[ 2 ] )
  7136. );
  7137. }
  7138. if ( hasFaceColor ) {
  7139. faces.push( getColorIndex( face.color ) );
  7140. }
  7141. if ( hasFaceVertexColor ) {
  7142. var vertexColors = face.vertexColors;
  7143. faces.push(
  7144. getColorIndex( vertexColors[ 0 ] ),
  7145. getColorIndex( vertexColors[ 1 ] ),
  7146. getColorIndex( vertexColors[ 2 ] )
  7147. );
  7148. }
  7149. }
  7150. function setBit( value, position, enabled ) {
  7151. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  7152. }
  7153. function getNormalIndex( normal ) {
  7154. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  7155. if ( normalsHash[ hash ] !== undefined ) {
  7156. return normalsHash[ hash ];
  7157. }
  7158. normalsHash[ hash ] = normals.length / 3;
  7159. normals.push( normal.x, normal.y, normal.z );
  7160. return normalsHash[ hash ];
  7161. }
  7162. function getColorIndex( color ) {
  7163. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  7164. if ( colorsHash[ hash ] !== undefined ) {
  7165. return colorsHash[ hash ];
  7166. }
  7167. colorsHash[ hash ] = colors.length;
  7168. colors.push( color.getHex() );
  7169. return colorsHash[ hash ];
  7170. }
  7171. function getUvIndex( uv ) {
  7172. var hash = uv.x.toString() + uv.y.toString();
  7173. if ( uvsHash[ hash ] !== undefined ) {
  7174. return uvsHash[ hash ];
  7175. }
  7176. uvsHash[ hash ] = uvs.length / 2;
  7177. uvs.push( uv.x, uv.y );
  7178. return uvsHash[ hash ];
  7179. }
  7180. data.data = {};
  7181. data.data.vertices = vertices;
  7182. data.data.normals = normals;
  7183. if ( colors.length > 0 ) data.data.colors = colors;
  7184. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  7185. data.data.faces = faces;
  7186. return data;
  7187. },
  7188. clone: function () {
  7189. /*
  7190. // Handle primitives
  7191. var parameters = this.parameters;
  7192. if ( parameters !== undefined ) {
  7193. var values = [];
  7194. for ( var key in parameters ) {
  7195. values.push( parameters[ key ] );
  7196. }
  7197. var geometry = Object.create( this.constructor.prototype );
  7198. this.constructor.apply( geometry, values );
  7199. return geometry;
  7200. }
  7201. return new this.constructor().copy( this );
  7202. */
  7203. return new Geometry().copy( this );
  7204. },
  7205. copy: function ( source ) {
  7206. var i, il, j, jl, k, kl;
  7207. // reset
  7208. this.vertices = [];
  7209. this.colors = [];
  7210. this.faces = [];
  7211. this.faceVertexUvs = [[]];
  7212. this.morphTargets = [];
  7213. this.morphNormals = [];
  7214. this.skinWeights = [];
  7215. this.skinIndices = [];
  7216. this.lineDistances = [];
  7217. this.boundingBox = null;
  7218. this.boundingSphere = null;
  7219. // name
  7220. this.name = source.name;
  7221. // vertices
  7222. var vertices = source.vertices;
  7223. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  7224. this.vertices.push( vertices[ i ].clone() );
  7225. }
  7226. // colors
  7227. var colors = source.colors;
  7228. for ( i = 0, il = colors.length; i < il; i ++ ) {
  7229. this.colors.push( colors[ i ].clone() );
  7230. }
  7231. // faces
  7232. var faces = source.faces;
  7233. for ( i = 0, il = faces.length; i < il; i ++ ) {
  7234. this.faces.push( faces[ i ].clone() );
  7235. }
  7236. // face vertex uvs
  7237. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  7238. var faceVertexUvs = source.faceVertexUvs[ i ];
  7239. if ( this.faceVertexUvs[ i ] === undefined ) {
  7240. this.faceVertexUvs[ i ] = [];
  7241. }
  7242. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  7243. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  7244. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  7245. var uv = uvs[ k ];
  7246. uvsCopy.push( uv.clone() );
  7247. }
  7248. this.faceVertexUvs[ i ].push( uvsCopy );
  7249. }
  7250. }
  7251. // morph targets
  7252. var morphTargets = source.morphTargets;
  7253. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  7254. var morphTarget = {};
  7255. morphTarget.name = morphTargets[ i ].name;
  7256. // vertices
  7257. if ( morphTargets[ i ].vertices !== undefined ) {
  7258. morphTarget.vertices = [];
  7259. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  7260. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  7261. }
  7262. }
  7263. // normals
  7264. if ( morphTargets[ i ].normals !== undefined ) {
  7265. morphTarget.normals = [];
  7266. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  7267. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  7268. }
  7269. }
  7270. this.morphTargets.push( morphTarget );
  7271. }
  7272. // morph normals
  7273. var morphNormals = source.morphNormals;
  7274. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  7275. var morphNormal = {};
  7276. // vertex normals
  7277. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  7278. morphNormal.vertexNormals = [];
  7279. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  7280. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  7281. var destVertexNormal = {};
  7282. destVertexNormal.a = srcVertexNormal.a.clone();
  7283. destVertexNormal.b = srcVertexNormal.b.clone();
  7284. destVertexNormal.c = srcVertexNormal.c.clone();
  7285. morphNormal.vertexNormals.push( destVertexNormal );
  7286. }
  7287. }
  7288. // face normals
  7289. if ( morphNormals[ i ].faceNormals !== undefined ) {
  7290. morphNormal.faceNormals = [];
  7291. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  7292. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  7293. }
  7294. }
  7295. this.morphNormals.push( morphNormal );
  7296. }
  7297. // skin weights
  7298. var skinWeights = source.skinWeights;
  7299. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  7300. this.skinWeights.push( skinWeights[ i ].clone() );
  7301. }
  7302. // skin indices
  7303. var skinIndices = source.skinIndices;
  7304. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  7305. this.skinIndices.push( skinIndices[ i ].clone() );
  7306. }
  7307. // line distances
  7308. var lineDistances = source.lineDistances;
  7309. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  7310. this.lineDistances.push( lineDistances[ i ] );
  7311. }
  7312. // bounding box
  7313. var boundingBox = source.boundingBox;
  7314. if ( boundingBox !== null ) {
  7315. this.boundingBox = boundingBox.clone();
  7316. }
  7317. // bounding sphere
  7318. var boundingSphere = source.boundingSphere;
  7319. if ( boundingSphere !== null ) {
  7320. this.boundingSphere = boundingSphere.clone();
  7321. }
  7322. // update flags
  7323. this.elementsNeedUpdate = source.elementsNeedUpdate;
  7324. this.verticesNeedUpdate = source.verticesNeedUpdate;
  7325. this.uvsNeedUpdate = source.uvsNeedUpdate;
  7326. this.normalsNeedUpdate = source.normalsNeedUpdate;
  7327. this.colorsNeedUpdate = source.colorsNeedUpdate;
  7328. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  7329. this.groupsNeedUpdate = source.groupsNeedUpdate;
  7330. return this;
  7331. },
  7332. dispose: function () {
  7333. this.dispatchEvent( { type: 'dispose' } );
  7334. }
  7335. } );
  7336. /**
  7337. * @author mrdoob / http://mrdoob.com/
  7338. */
  7339. function BufferAttribute( array, itemSize, normalized ) {
  7340. if ( Array.isArray( array ) ) {
  7341. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  7342. }
  7343. this.uuid = _Math.generateUUID();
  7344. this.name = '';
  7345. this.array = array;
  7346. this.itemSize = itemSize;
  7347. this.count = array !== undefined ? array.length / itemSize : 0;
  7348. this.normalized = normalized === true;
  7349. this.dynamic = false;
  7350. this.updateRange = { offset: 0, count: - 1 };
  7351. this.onUploadCallback = function () {};
  7352. this.version = 0;
  7353. }
  7354. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  7355. set: function ( value ) {
  7356. if ( value === true ) this.version ++;
  7357. }
  7358. } );
  7359. Object.assign( BufferAttribute.prototype, {
  7360. isBufferAttribute: true,
  7361. setArray: function ( array ) {
  7362. if ( Array.isArray( array ) ) {
  7363. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  7364. }
  7365. this.count = array !== undefined ? array.length / this.itemSize : 0;
  7366. this.array = array;
  7367. },
  7368. setDynamic: function ( value ) {
  7369. this.dynamic = value;
  7370. return this;
  7371. },
  7372. copy: function ( source ) {
  7373. this.array = new source.array.constructor( source.array );
  7374. this.itemSize = source.itemSize;
  7375. this.count = source.count;
  7376. this.normalized = source.normalized;
  7377. this.dynamic = source.dynamic;
  7378. return this;
  7379. },
  7380. copyAt: function ( index1, attribute, index2 ) {
  7381. index1 *= this.itemSize;
  7382. index2 *= attribute.itemSize;
  7383. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  7384. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  7385. }
  7386. return this;
  7387. },
  7388. copyArray: function ( array ) {
  7389. this.array.set( array );
  7390. return this;
  7391. },
  7392. copyColorsArray: function ( colors ) {
  7393. var array = this.array, offset = 0;
  7394. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  7395. var color = colors[ i ];
  7396. if ( color === undefined ) {
  7397. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  7398. color = new Color();
  7399. }
  7400. array[ offset ++ ] = color.r;
  7401. array[ offset ++ ] = color.g;
  7402. array[ offset ++ ] = color.b;
  7403. }
  7404. return this;
  7405. },
  7406. copyIndicesArray: function ( indices ) {
  7407. var array = this.array, offset = 0;
  7408. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7409. var index = indices[ i ];
  7410. array[ offset ++ ] = index.a;
  7411. array[ offset ++ ] = index.b;
  7412. array[ offset ++ ] = index.c;
  7413. }
  7414. return this;
  7415. },
  7416. copyVector2sArray: function ( vectors ) {
  7417. var array = this.array, offset = 0;
  7418. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  7419. var vector = vectors[ i ];
  7420. if ( vector === undefined ) {
  7421. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  7422. vector = new Vector2();
  7423. }
  7424. array[ offset ++ ] = vector.x;
  7425. array[ offset ++ ] = vector.y;
  7426. }
  7427. return this;
  7428. },
  7429. copyVector3sArray: function ( vectors ) {
  7430. var array = this.array, offset = 0;
  7431. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  7432. var vector = vectors[ i ];
  7433. if ( vector === undefined ) {
  7434. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  7435. vector = new Vector3();
  7436. }
  7437. array[ offset ++ ] = vector.x;
  7438. array[ offset ++ ] = vector.y;
  7439. array[ offset ++ ] = vector.z;
  7440. }
  7441. return this;
  7442. },
  7443. copyVector4sArray: function ( vectors ) {
  7444. var array = this.array, offset = 0;
  7445. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  7446. var vector = vectors[ i ];
  7447. if ( vector === undefined ) {
  7448. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  7449. vector = new Vector4();
  7450. }
  7451. array[ offset ++ ] = vector.x;
  7452. array[ offset ++ ] = vector.y;
  7453. array[ offset ++ ] = vector.z;
  7454. array[ offset ++ ] = vector.w;
  7455. }
  7456. return this;
  7457. },
  7458. set: function ( value, offset ) {
  7459. if ( offset === undefined ) offset = 0;
  7460. this.array.set( value, offset );
  7461. return this;
  7462. },
  7463. getX: function ( index ) {
  7464. return this.array[ index * this.itemSize ];
  7465. },
  7466. setX: function ( index, x ) {
  7467. this.array[ index * this.itemSize ] = x;
  7468. return this;
  7469. },
  7470. getY: function ( index ) {
  7471. return this.array[ index * this.itemSize + 1 ];
  7472. },
  7473. setY: function ( index, y ) {
  7474. this.array[ index * this.itemSize + 1 ] = y;
  7475. return this;
  7476. },
  7477. getZ: function ( index ) {
  7478. return this.array[ index * this.itemSize + 2 ];
  7479. },
  7480. setZ: function ( index, z ) {
  7481. this.array[ index * this.itemSize + 2 ] = z;
  7482. return this;
  7483. },
  7484. getW: function ( index ) {
  7485. return this.array[ index * this.itemSize + 3 ];
  7486. },
  7487. setW: function ( index, w ) {
  7488. this.array[ index * this.itemSize + 3 ] = w;
  7489. return this;
  7490. },
  7491. setXY: function ( index, x, y ) {
  7492. index *= this.itemSize;
  7493. this.array[ index + 0 ] = x;
  7494. this.array[ index + 1 ] = y;
  7495. return this;
  7496. },
  7497. setXYZ: function ( index, x, y, z ) {
  7498. index *= this.itemSize;
  7499. this.array[ index + 0 ] = x;
  7500. this.array[ index + 1 ] = y;
  7501. this.array[ index + 2 ] = z;
  7502. return this;
  7503. },
  7504. setXYZW: function ( index, x, y, z, w ) {
  7505. index *= this.itemSize;
  7506. this.array[ index + 0 ] = x;
  7507. this.array[ index + 1 ] = y;
  7508. this.array[ index + 2 ] = z;
  7509. this.array[ index + 3 ] = w;
  7510. return this;
  7511. },
  7512. onUpload: function ( callback ) {
  7513. this.onUploadCallback = callback;
  7514. return this;
  7515. },
  7516. clone: function () {
  7517. return new this.constructor( this.array, this.itemSize ).copy( this );
  7518. }
  7519. } );
  7520. //
  7521. function Int8BufferAttribute( array, itemSize, normalized ) {
  7522. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  7523. }
  7524. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7525. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  7526. function Uint8BufferAttribute( array, itemSize, normalized ) {
  7527. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  7528. }
  7529. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7530. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  7531. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  7532. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  7533. }
  7534. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7535. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  7536. function Int16BufferAttribute( array, itemSize, normalized ) {
  7537. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  7538. }
  7539. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7540. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  7541. function Uint16BufferAttribute( array, itemSize, normalized ) {
  7542. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  7543. }
  7544. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7545. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  7546. function Int32BufferAttribute( array, itemSize, normalized ) {
  7547. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  7548. }
  7549. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7550. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  7551. function Uint32BufferAttribute( array, itemSize, normalized ) {
  7552. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  7553. }
  7554. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7555. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  7556. function Float32BufferAttribute( array, itemSize, normalized ) {
  7557. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  7558. }
  7559. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7560. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  7561. function Float64BufferAttribute( array, itemSize, normalized ) {
  7562. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  7563. }
  7564. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7565. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  7566. /**
  7567. * @author mrdoob / http://mrdoob.com/
  7568. */
  7569. function DirectGeometry() {
  7570. this.indices = [];
  7571. this.vertices = [];
  7572. this.normals = [];
  7573. this.colors = [];
  7574. this.uvs = [];
  7575. this.uvs2 = [];
  7576. this.groups = [];
  7577. this.morphTargets = {};
  7578. this.skinWeights = [];
  7579. this.skinIndices = [];
  7580. // this.lineDistances = [];
  7581. this.boundingBox = null;
  7582. this.boundingSphere = null;
  7583. // update flags
  7584. this.verticesNeedUpdate = false;
  7585. this.normalsNeedUpdate = false;
  7586. this.colorsNeedUpdate = false;
  7587. this.uvsNeedUpdate = false;
  7588. this.groupsNeedUpdate = false;
  7589. }
  7590. Object.assign( DirectGeometry.prototype, {
  7591. computeGroups: function ( geometry ) {
  7592. var group;
  7593. var groups = [];
  7594. var materialIndex = undefined;
  7595. var faces = geometry.faces;
  7596. for ( var i = 0; i < faces.length; i ++ ) {
  7597. var face = faces[ i ];
  7598. // materials
  7599. if ( face.materialIndex !== materialIndex ) {
  7600. materialIndex = face.materialIndex;
  7601. if ( group !== undefined ) {
  7602. group.count = ( i * 3 ) - group.start;
  7603. groups.push( group );
  7604. }
  7605. group = {
  7606. start: i * 3,
  7607. materialIndex: materialIndex
  7608. };
  7609. }
  7610. }
  7611. if ( group !== undefined ) {
  7612. group.count = ( i * 3 ) - group.start;
  7613. groups.push( group );
  7614. }
  7615. this.groups = groups;
  7616. },
  7617. fromGeometry: function ( geometry ) {
  7618. var faces = geometry.faces;
  7619. var vertices = geometry.vertices;
  7620. var faceVertexUvs = geometry.faceVertexUvs;
  7621. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  7622. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  7623. // morphs
  7624. var morphTargets = geometry.morphTargets;
  7625. var morphTargetsLength = morphTargets.length;
  7626. var morphTargetsPosition;
  7627. if ( morphTargetsLength > 0 ) {
  7628. morphTargetsPosition = [];
  7629. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  7630. morphTargetsPosition[ i ] = [];
  7631. }
  7632. this.morphTargets.position = morphTargetsPosition;
  7633. }
  7634. var morphNormals = geometry.morphNormals;
  7635. var morphNormalsLength = morphNormals.length;
  7636. var morphTargetsNormal;
  7637. if ( morphNormalsLength > 0 ) {
  7638. morphTargetsNormal = [];
  7639. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  7640. morphTargetsNormal[ i ] = [];
  7641. }
  7642. this.morphTargets.normal = morphTargetsNormal;
  7643. }
  7644. // skins
  7645. var skinIndices = geometry.skinIndices;
  7646. var skinWeights = geometry.skinWeights;
  7647. var hasSkinIndices = skinIndices.length === vertices.length;
  7648. var hasSkinWeights = skinWeights.length === vertices.length;
  7649. //
  7650. for ( var i = 0; i < faces.length; i ++ ) {
  7651. var face = faces[ i ];
  7652. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  7653. var vertexNormals = face.vertexNormals;
  7654. if ( vertexNormals.length === 3 ) {
  7655. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  7656. } else {
  7657. var normal = face.normal;
  7658. this.normals.push( normal, normal, normal );
  7659. }
  7660. var vertexColors = face.vertexColors;
  7661. if ( vertexColors.length === 3 ) {
  7662. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  7663. } else {
  7664. var color = face.color;
  7665. this.colors.push( color, color, color );
  7666. }
  7667. if ( hasFaceVertexUv === true ) {
  7668. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  7669. if ( vertexUvs !== undefined ) {
  7670. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  7671. } else {
  7672. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  7673. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  7674. }
  7675. }
  7676. if ( hasFaceVertexUv2 === true ) {
  7677. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  7678. if ( vertexUvs !== undefined ) {
  7679. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  7680. } else {
  7681. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  7682. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  7683. }
  7684. }
  7685. // morphs
  7686. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  7687. var morphTarget = morphTargets[ j ].vertices;
  7688. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  7689. }
  7690. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  7691. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  7692. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  7693. }
  7694. // skins
  7695. if ( hasSkinIndices ) {
  7696. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  7697. }
  7698. if ( hasSkinWeights ) {
  7699. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  7700. }
  7701. }
  7702. this.computeGroups( geometry );
  7703. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  7704. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  7705. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  7706. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  7707. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  7708. return this;
  7709. }
  7710. } );
  7711. /**
  7712. * @author mrdoob / http://mrdoob.com/
  7713. */
  7714. function arrayMax( array ) {
  7715. if ( array.length === 0 ) return - Infinity;
  7716. var max = array[ 0 ];
  7717. for ( var i = 1, l = array.length; i < l; ++ i ) {
  7718. if ( array[ i ] > max ) max = array[ i ];
  7719. }
  7720. return max;
  7721. }
  7722. /**
  7723. * @author alteredq / http://alteredqualia.com/
  7724. * @author mrdoob / http://mrdoob.com/
  7725. */
  7726. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  7727. function BufferGeometry() {
  7728. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  7729. this.uuid = _Math.generateUUID();
  7730. this.name = '';
  7731. this.type = 'BufferGeometry';
  7732. this.index = null;
  7733. this.attributes = {};
  7734. this.morphAttributes = {};
  7735. this.groups = [];
  7736. this.boundingBox = null;
  7737. this.boundingSphere = null;
  7738. this.drawRange = { start: 0, count: Infinity };
  7739. }
  7740. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  7741. constructor: BufferGeometry,
  7742. isBufferGeometry: true,
  7743. getIndex: function () {
  7744. return this.index;
  7745. },
  7746. setIndex: function ( index ) {
  7747. if ( Array.isArray( index ) ) {
  7748. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  7749. } else {
  7750. this.index = index;
  7751. }
  7752. },
  7753. addAttribute: function ( name, attribute ) {
  7754. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  7755. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  7756. this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  7757. return;
  7758. }
  7759. if ( name === 'index' ) {
  7760. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  7761. this.setIndex( attribute );
  7762. return;
  7763. }
  7764. this.attributes[ name ] = attribute;
  7765. return this;
  7766. },
  7767. getAttribute: function ( name ) {
  7768. return this.attributes[ name ];
  7769. },
  7770. removeAttribute: function ( name ) {
  7771. delete this.attributes[ name ];
  7772. return this;
  7773. },
  7774. addGroup: function ( start, count, materialIndex ) {
  7775. this.groups.push( {
  7776. start: start,
  7777. count: count,
  7778. materialIndex: materialIndex !== undefined ? materialIndex : 0
  7779. } );
  7780. },
  7781. clearGroups: function () {
  7782. this.groups = [];
  7783. },
  7784. setDrawRange: function ( start, count ) {
  7785. this.drawRange.start = start;
  7786. this.drawRange.count = count;
  7787. },
  7788. applyMatrix: function ( matrix ) {
  7789. var position = this.attributes.position;
  7790. if ( position !== undefined ) {
  7791. matrix.applyToBufferAttribute( position );
  7792. position.needsUpdate = true;
  7793. }
  7794. var normal = this.attributes.normal;
  7795. if ( normal !== undefined ) {
  7796. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7797. normalMatrix.applyToBufferAttribute( normal );
  7798. normal.needsUpdate = true;
  7799. }
  7800. if ( this.boundingBox !== null ) {
  7801. this.computeBoundingBox();
  7802. }
  7803. if ( this.boundingSphere !== null ) {
  7804. this.computeBoundingSphere();
  7805. }
  7806. return this;
  7807. },
  7808. rotateX: function () {
  7809. // rotate geometry around world x-axis
  7810. var m1 = new Matrix4();
  7811. return function rotateX( angle ) {
  7812. m1.makeRotationX( angle );
  7813. this.applyMatrix( m1 );
  7814. return this;
  7815. };
  7816. }(),
  7817. rotateY: function () {
  7818. // rotate geometry around world y-axis
  7819. var m1 = new Matrix4();
  7820. return function rotateY( angle ) {
  7821. m1.makeRotationY( angle );
  7822. this.applyMatrix( m1 );
  7823. return this;
  7824. };
  7825. }(),
  7826. rotateZ: function () {
  7827. // rotate geometry around world z-axis
  7828. var m1 = new Matrix4();
  7829. return function rotateZ( angle ) {
  7830. m1.makeRotationZ( angle );
  7831. this.applyMatrix( m1 );
  7832. return this;
  7833. };
  7834. }(),
  7835. translate: function () {
  7836. // translate geometry
  7837. var m1 = new Matrix4();
  7838. return function translate( x, y, z ) {
  7839. m1.makeTranslation( x, y, z );
  7840. this.applyMatrix( m1 );
  7841. return this;
  7842. };
  7843. }(),
  7844. scale: function () {
  7845. // scale geometry
  7846. var m1 = new Matrix4();
  7847. return function scale( x, y, z ) {
  7848. m1.makeScale( x, y, z );
  7849. this.applyMatrix( m1 );
  7850. return this;
  7851. };
  7852. }(),
  7853. lookAt: function () {
  7854. var obj = new Object3D();
  7855. return function lookAt( vector ) {
  7856. obj.lookAt( vector );
  7857. obj.updateMatrix();
  7858. this.applyMatrix( obj.matrix );
  7859. };
  7860. }(),
  7861. center: function () {
  7862. this.computeBoundingBox();
  7863. var offset = this.boundingBox.getCenter().negate();
  7864. this.translate( offset.x, offset.y, offset.z );
  7865. return offset;
  7866. },
  7867. setFromObject: function ( object ) {
  7868. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  7869. var geometry = object.geometry;
  7870. if ( object.isPoints || object.isLine ) {
  7871. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  7872. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  7873. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  7874. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  7875. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  7876. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  7877. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  7878. }
  7879. if ( geometry.boundingSphere !== null ) {
  7880. this.boundingSphere = geometry.boundingSphere.clone();
  7881. }
  7882. if ( geometry.boundingBox !== null ) {
  7883. this.boundingBox = geometry.boundingBox.clone();
  7884. }
  7885. } else if ( object.isMesh ) {
  7886. if ( geometry && geometry.isGeometry ) {
  7887. this.fromGeometry( geometry );
  7888. }
  7889. }
  7890. return this;
  7891. },
  7892. setFromPoints: function ( points ) {
  7893. var position = [];
  7894. for ( var i = 0, l = points.length; i < l; i ++ ) {
  7895. var point = points[ i ];
  7896. position.push( point.x, point.y, point.z || 0 );
  7897. }
  7898. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  7899. return this;
  7900. },
  7901. updateFromObject: function ( object ) {
  7902. var geometry = object.geometry;
  7903. if ( object.isMesh ) {
  7904. var direct = geometry.__directGeometry;
  7905. if ( geometry.elementsNeedUpdate === true ) {
  7906. direct = undefined;
  7907. geometry.elementsNeedUpdate = false;
  7908. }
  7909. if ( direct === undefined ) {
  7910. return this.fromGeometry( geometry );
  7911. }
  7912. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  7913. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  7914. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  7915. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  7916. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  7917. geometry.verticesNeedUpdate = false;
  7918. geometry.normalsNeedUpdate = false;
  7919. geometry.colorsNeedUpdate = false;
  7920. geometry.uvsNeedUpdate = false;
  7921. geometry.groupsNeedUpdate = false;
  7922. geometry = direct;
  7923. }
  7924. var attribute;
  7925. if ( geometry.verticesNeedUpdate === true ) {
  7926. attribute = this.attributes.position;
  7927. if ( attribute !== undefined ) {
  7928. attribute.copyVector3sArray( geometry.vertices );
  7929. attribute.needsUpdate = true;
  7930. }
  7931. geometry.verticesNeedUpdate = false;
  7932. }
  7933. if ( geometry.normalsNeedUpdate === true ) {
  7934. attribute = this.attributes.normal;
  7935. if ( attribute !== undefined ) {
  7936. attribute.copyVector3sArray( geometry.normals );
  7937. attribute.needsUpdate = true;
  7938. }
  7939. geometry.normalsNeedUpdate = false;
  7940. }
  7941. if ( geometry.colorsNeedUpdate === true ) {
  7942. attribute = this.attributes.color;
  7943. if ( attribute !== undefined ) {
  7944. attribute.copyColorsArray( geometry.colors );
  7945. attribute.needsUpdate = true;
  7946. }
  7947. geometry.colorsNeedUpdate = false;
  7948. }
  7949. if ( geometry.uvsNeedUpdate ) {
  7950. attribute = this.attributes.uv;
  7951. if ( attribute !== undefined ) {
  7952. attribute.copyVector2sArray( geometry.uvs );
  7953. attribute.needsUpdate = true;
  7954. }
  7955. geometry.uvsNeedUpdate = false;
  7956. }
  7957. if ( geometry.lineDistancesNeedUpdate ) {
  7958. attribute = this.attributes.lineDistance;
  7959. if ( attribute !== undefined ) {
  7960. attribute.copyArray( geometry.lineDistances );
  7961. attribute.needsUpdate = true;
  7962. }
  7963. geometry.lineDistancesNeedUpdate = false;
  7964. }
  7965. if ( geometry.groupsNeedUpdate ) {
  7966. geometry.computeGroups( object.geometry );
  7967. this.groups = geometry.groups;
  7968. geometry.groupsNeedUpdate = false;
  7969. }
  7970. return this;
  7971. },
  7972. fromGeometry: function ( geometry ) {
  7973. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  7974. return this.fromDirectGeometry( geometry.__directGeometry );
  7975. },
  7976. fromDirectGeometry: function ( geometry ) {
  7977. var positions = new Float32Array( geometry.vertices.length * 3 );
  7978. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  7979. if ( geometry.normals.length > 0 ) {
  7980. var normals = new Float32Array( geometry.normals.length * 3 );
  7981. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  7982. }
  7983. if ( geometry.colors.length > 0 ) {
  7984. var colors = new Float32Array( geometry.colors.length * 3 );
  7985. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  7986. }
  7987. if ( geometry.uvs.length > 0 ) {
  7988. var uvs = new Float32Array( geometry.uvs.length * 2 );
  7989. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  7990. }
  7991. if ( geometry.uvs2.length > 0 ) {
  7992. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  7993. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  7994. }
  7995. if ( geometry.indices.length > 0 ) {
  7996. var TypeArray = arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array;
  7997. var indices = new TypeArray( geometry.indices.length * 3 );
  7998. this.setIndex( new BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  7999. }
  8000. // groups
  8001. this.groups = geometry.groups;
  8002. // morphs
  8003. for ( var name in geometry.morphTargets ) {
  8004. var array = [];
  8005. var morphTargets = geometry.morphTargets[ name ];
  8006. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  8007. var morphTarget = morphTargets[ i ];
  8008. var attribute = new Float32BufferAttribute( morphTarget.length * 3, 3 );
  8009. array.push( attribute.copyVector3sArray( morphTarget ) );
  8010. }
  8011. this.morphAttributes[ name ] = array;
  8012. }
  8013. // skinning
  8014. if ( geometry.skinIndices.length > 0 ) {
  8015. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  8016. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  8017. }
  8018. if ( geometry.skinWeights.length > 0 ) {
  8019. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  8020. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  8021. }
  8022. //
  8023. if ( geometry.boundingSphere !== null ) {
  8024. this.boundingSphere = geometry.boundingSphere.clone();
  8025. }
  8026. if ( geometry.boundingBox !== null ) {
  8027. this.boundingBox = geometry.boundingBox.clone();
  8028. }
  8029. return this;
  8030. },
  8031. computeBoundingBox: function () {
  8032. if ( this.boundingBox === null ) {
  8033. this.boundingBox = new Box3();
  8034. }
  8035. var position = this.attributes.position;
  8036. if ( position !== undefined ) {
  8037. this.boundingBox.setFromBufferAttribute( position );
  8038. } else {
  8039. this.boundingBox.makeEmpty();
  8040. }
  8041. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  8042. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  8043. }
  8044. },
  8045. computeBoundingSphere: function () {
  8046. var box = new Box3();
  8047. var vector = new Vector3();
  8048. return function computeBoundingSphere() {
  8049. if ( this.boundingSphere === null ) {
  8050. this.boundingSphere = new Sphere();
  8051. }
  8052. var position = this.attributes.position;
  8053. if ( position ) {
  8054. var center = this.boundingSphere.center;
  8055. box.setFromBufferAttribute( position );
  8056. box.getCenter( center );
  8057. // hoping to find a boundingSphere with a radius smaller than the
  8058. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  8059. var maxRadiusSq = 0;
  8060. for ( var i = 0, il = position.count; i < il; i ++ ) {
  8061. vector.x = position.getX( i );
  8062. vector.y = position.getY( i );
  8063. vector.z = position.getZ( i );
  8064. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  8065. }
  8066. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  8067. if ( isNaN( this.boundingSphere.radius ) ) {
  8068. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  8069. }
  8070. }
  8071. };
  8072. }(),
  8073. computeFaceNormals: function () {
  8074. // backwards compatibility
  8075. },
  8076. computeVertexNormals: function () {
  8077. var index = this.index;
  8078. var attributes = this.attributes;
  8079. var groups = this.groups;
  8080. if ( attributes.position ) {
  8081. var positions = attributes.position.array;
  8082. if ( attributes.normal === undefined ) {
  8083. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  8084. } else {
  8085. // reset existing normals to zero
  8086. var array = attributes.normal.array;
  8087. for ( var i = 0, il = array.length; i < il; i ++ ) {
  8088. array[ i ] = 0;
  8089. }
  8090. }
  8091. var normals = attributes.normal.array;
  8092. var vA, vB, vC;
  8093. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  8094. var cb = new Vector3(), ab = new Vector3();
  8095. // indexed elements
  8096. if ( index ) {
  8097. var indices = index.array;
  8098. if ( groups.length === 0 ) {
  8099. this.addGroup( 0, indices.length );
  8100. }
  8101. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  8102. var group = groups[ j ];
  8103. var start = group.start;
  8104. var count = group.count;
  8105. for ( var i = start, il = start + count; i < il; i += 3 ) {
  8106. vA = indices[ i + 0 ] * 3;
  8107. vB = indices[ i + 1 ] * 3;
  8108. vC = indices[ i + 2 ] * 3;
  8109. pA.fromArray( positions, vA );
  8110. pB.fromArray( positions, vB );
  8111. pC.fromArray( positions, vC );
  8112. cb.subVectors( pC, pB );
  8113. ab.subVectors( pA, pB );
  8114. cb.cross( ab );
  8115. normals[ vA ] += cb.x;
  8116. normals[ vA + 1 ] += cb.y;
  8117. normals[ vA + 2 ] += cb.z;
  8118. normals[ vB ] += cb.x;
  8119. normals[ vB + 1 ] += cb.y;
  8120. normals[ vB + 2 ] += cb.z;
  8121. normals[ vC ] += cb.x;
  8122. normals[ vC + 1 ] += cb.y;
  8123. normals[ vC + 2 ] += cb.z;
  8124. }
  8125. }
  8126. } else {
  8127. // non-indexed elements (unconnected triangle soup)
  8128. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  8129. pA.fromArray( positions, i );
  8130. pB.fromArray( positions, i + 3 );
  8131. pC.fromArray( positions, i + 6 );
  8132. cb.subVectors( pC, pB );
  8133. ab.subVectors( pA, pB );
  8134. cb.cross( ab );
  8135. normals[ i ] = cb.x;
  8136. normals[ i + 1 ] = cb.y;
  8137. normals[ i + 2 ] = cb.z;
  8138. normals[ i + 3 ] = cb.x;
  8139. normals[ i + 4 ] = cb.y;
  8140. normals[ i + 5 ] = cb.z;
  8141. normals[ i + 6 ] = cb.x;
  8142. normals[ i + 7 ] = cb.y;
  8143. normals[ i + 8 ] = cb.z;
  8144. }
  8145. }
  8146. this.normalizeNormals();
  8147. attributes.normal.needsUpdate = true;
  8148. }
  8149. },
  8150. merge: function ( geometry, offset ) {
  8151. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  8152. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  8153. return;
  8154. }
  8155. if ( offset === undefined ) offset = 0;
  8156. var attributes = this.attributes;
  8157. for ( var key in attributes ) {
  8158. if ( geometry.attributes[ key ] === undefined ) continue;
  8159. var attribute1 = attributes[ key ];
  8160. var attributeArray1 = attribute1.array;
  8161. var attribute2 = geometry.attributes[ key ];
  8162. var attributeArray2 = attribute2.array;
  8163. var attributeSize = attribute2.itemSize;
  8164. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  8165. attributeArray1[ j ] = attributeArray2[ i ];
  8166. }
  8167. }
  8168. return this;
  8169. },
  8170. normalizeNormals: function () {
  8171. var vector = new Vector3();
  8172. return function normalizeNormals() {
  8173. var normals = this.attributes.normal;
  8174. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  8175. vector.x = normals.getX( i );
  8176. vector.y = normals.getY( i );
  8177. vector.z = normals.getZ( i );
  8178. vector.normalize();
  8179. normals.setXYZ( i, vector.x, vector.y, vector.z );
  8180. }
  8181. };
  8182. }(),
  8183. toNonIndexed: function () {
  8184. if ( this.index === null ) {
  8185. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  8186. return this;
  8187. }
  8188. var geometry2 = new BufferGeometry();
  8189. var indices = this.index.array;
  8190. var attributes = this.attributes;
  8191. for ( var name in attributes ) {
  8192. var attribute = attributes[ name ];
  8193. var array = attribute.array;
  8194. var itemSize = attribute.itemSize;
  8195. var array2 = new array.constructor( indices.length * itemSize );
  8196. var index = 0, index2 = 0;
  8197. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  8198. index = indices[ i ] * itemSize;
  8199. for ( var j = 0; j < itemSize; j ++ ) {
  8200. array2[ index2 ++ ] = array[ index ++ ];
  8201. }
  8202. }
  8203. geometry2.addAttribute( name, new BufferAttribute( array2, itemSize ) );
  8204. }
  8205. return geometry2;
  8206. },
  8207. toJSON: function () {
  8208. var data = {
  8209. metadata: {
  8210. version: 4.5,
  8211. type: 'BufferGeometry',
  8212. generator: 'BufferGeometry.toJSON'
  8213. }
  8214. };
  8215. // standard BufferGeometry serialization
  8216. data.uuid = this.uuid;
  8217. data.type = this.type;
  8218. if ( this.name !== '' ) data.name = this.name;
  8219. if ( this.parameters !== undefined ) {
  8220. var parameters = this.parameters;
  8221. for ( var key in parameters ) {
  8222. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  8223. }
  8224. return data;
  8225. }
  8226. data.data = { attributes: {} };
  8227. var index = this.index;
  8228. if ( index !== null ) {
  8229. var array = Array.prototype.slice.call( index.array );
  8230. data.data.index = {
  8231. type: index.array.constructor.name,
  8232. array: array
  8233. };
  8234. }
  8235. var attributes = this.attributes;
  8236. for ( var key in attributes ) {
  8237. var attribute = attributes[ key ];
  8238. var array = Array.prototype.slice.call( attribute.array );
  8239. data.data.attributes[ key ] = {
  8240. itemSize: attribute.itemSize,
  8241. type: attribute.array.constructor.name,
  8242. array: array,
  8243. normalized: attribute.normalized
  8244. };
  8245. }
  8246. var groups = this.groups;
  8247. if ( groups.length > 0 ) {
  8248. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  8249. }
  8250. var boundingSphere = this.boundingSphere;
  8251. if ( boundingSphere !== null ) {
  8252. data.data.boundingSphere = {
  8253. center: boundingSphere.center.toArray(),
  8254. radius: boundingSphere.radius
  8255. };
  8256. }
  8257. return data;
  8258. },
  8259. clone: function () {
  8260. /*
  8261. // Handle primitives
  8262. var parameters = this.parameters;
  8263. if ( parameters !== undefined ) {
  8264. var values = [];
  8265. for ( var key in parameters ) {
  8266. values.push( parameters[ key ] );
  8267. }
  8268. var geometry = Object.create( this.constructor.prototype );
  8269. this.constructor.apply( geometry, values );
  8270. return geometry;
  8271. }
  8272. return new this.constructor().copy( this );
  8273. */
  8274. return new BufferGeometry().copy( this );
  8275. },
  8276. copy: function ( source ) {
  8277. var name, i, l;
  8278. // reset
  8279. this.index = null;
  8280. this.attributes = {};
  8281. this.morphAttributes = {};
  8282. this.groups = [];
  8283. this.boundingBox = null;
  8284. this.boundingSphere = null;
  8285. // name
  8286. this.name = source.name;
  8287. // index
  8288. var index = source.index;
  8289. if ( index !== null ) {
  8290. this.setIndex( index.clone() );
  8291. }
  8292. // attributes
  8293. var attributes = source.attributes;
  8294. for ( name in attributes ) {
  8295. var attribute = attributes[ name ];
  8296. this.addAttribute( name, attribute.clone() );
  8297. }
  8298. // morph attributes
  8299. var morphAttributes = source.morphAttributes;
  8300. for ( name in morphAttributes ) {
  8301. var array = [];
  8302. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  8303. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  8304. array.push( morphAttribute[ i ].clone() );
  8305. }
  8306. this.morphAttributes[ name ] = array;
  8307. }
  8308. // groups
  8309. var groups = source.groups;
  8310. for ( i = 0, l = groups.length; i < l; i ++ ) {
  8311. var group = groups[ i ];
  8312. this.addGroup( group.start, group.count, group.materialIndex );
  8313. }
  8314. // bounding box
  8315. var boundingBox = source.boundingBox;
  8316. if ( boundingBox !== null ) {
  8317. this.boundingBox = boundingBox.clone();
  8318. }
  8319. // bounding sphere
  8320. var boundingSphere = source.boundingSphere;
  8321. if ( boundingSphere !== null ) {
  8322. this.boundingSphere = boundingSphere.clone();
  8323. }
  8324. // draw range
  8325. this.drawRange.start = source.drawRange.start;
  8326. this.drawRange.count = source.drawRange.count;
  8327. return this;
  8328. },
  8329. dispose: function () {
  8330. this.dispatchEvent( { type: 'dispose' } );
  8331. }
  8332. } );
  8333. /**
  8334. * @author mrdoob / http://mrdoob.com/
  8335. * @author Mugen87 / https://github.com/Mugen87
  8336. */
  8337. // BoxGeometry
  8338. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  8339. Geometry.call( this );
  8340. this.type = 'BoxGeometry';
  8341. this.parameters = {
  8342. width: width,
  8343. height: height,
  8344. depth: depth,
  8345. widthSegments: widthSegments,
  8346. heightSegments: heightSegments,
  8347. depthSegments: depthSegments
  8348. };
  8349. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  8350. this.mergeVertices();
  8351. }
  8352. BoxGeometry.prototype = Object.create( Geometry.prototype );
  8353. BoxGeometry.prototype.constructor = BoxGeometry;
  8354. // BoxBufferGeometry
  8355. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  8356. BufferGeometry.call( this );
  8357. this.type = 'BoxBufferGeometry';
  8358. this.parameters = {
  8359. width: width,
  8360. height: height,
  8361. depth: depth,
  8362. widthSegments: widthSegments,
  8363. heightSegments: heightSegments,
  8364. depthSegments: depthSegments
  8365. };
  8366. var scope = this;
  8367. width = width || 1;
  8368. height = height || 1;
  8369. depth = depth || 1;
  8370. // segments
  8371. widthSegments = Math.floor( widthSegments ) || 1;
  8372. heightSegments = Math.floor( heightSegments ) || 1;
  8373. depthSegments = Math.floor( depthSegments ) || 1;
  8374. // buffers
  8375. var indices = [];
  8376. var vertices = [];
  8377. var normals = [];
  8378. var uvs = [];
  8379. // helper variables
  8380. var numberOfVertices = 0;
  8381. var groupStart = 0;
  8382. // build each side of the box geometry
  8383. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  8384. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  8385. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  8386. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  8387. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  8388. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  8389. // build geometry
  8390. this.setIndex( indices );
  8391. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  8392. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  8393. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  8394. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  8395. var segmentWidth = width / gridX;
  8396. var segmentHeight = height / gridY;
  8397. var widthHalf = width / 2;
  8398. var heightHalf = height / 2;
  8399. var depthHalf = depth / 2;
  8400. var gridX1 = gridX + 1;
  8401. var gridY1 = gridY + 1;
  8402. var vertexCounter = 0;
  8403. var groupCount = 0;
  8404. var ix, iy;
  8405. var vector = new Vector3();
  8406. // generate vertices, normals and uvs
  8407. for ( iy = 0; iy < gridY1; iy ++ ) {
  8408. var y = iy * segmentHeight - heightHalf;
  8409. for ( ix = 0; ix < gridX1; ix ++ ) {
  8410. var x = ix * segmentWidth - widthHalf;
  8411. // set values to correct vector component
  8412. vector[ u ] = x * udir;
  8413. vector[ v ] = y * vdir;
  8414. vector[ w ] = depthHalf;
  8415. // now apply vector to vertex buffer
  8416. vertices.push( vector.x, vector.y, vector.z );
  8417. // set values to correct vector component
  8418. vector[ u ] = 0;
  8419. vector[ v ] = 0;
  8420. vector[ w ] = depth > 0 ? 1 : - 1;
  8421. // now apply vector to normal buffer
  8422. normals.push( vector.x, vector.y, vector.z );
  8423. // uvs
  8424. uvs.push( ix / gridX );
  8425. uvs.push( 1 - ( iy / gridY ) );
  8426. // counters
  8427. vertexCounter += 1;
  8428. }
  8429. }
  8430. // indices
  8431. // 1. you need three indices to draw a single face
  8432. // 2. a single segment consists of two faces
  8433. // 3. so we need to generate six (2*3) indices per segment
  8434. for ( iy = 0; iy < gridY; iy ++ ) {
  8435. for ( ix = 0; ix < gridX; ix ++ ) {
  8436. var a = numberOfVertices + ix + gridX1 * iy;
  8437. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  8438. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  8439. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  8440. // faces
  8441. indices.push( a, b, d );
  8442. indices.push( b, c, d );
  8443. // increase counter
  8444. groupCount += 6;
  8445. }
  8446. }
  8447. // add a group to the geometry. this will ensure multi material support
  8448. scope.addGroup( groupStart, groupCount, materialIndex );
  8449. // calculate new start value for groups
  8450. groupStart += groupCount;
  8451. // update total number of vertices
  8452. numberOfVertices += vertexCounter;
  8453. }
  8454. }
  8455. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  8456. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  8457. /**
  8458. * @author mrdoob / http://mrdoob.com/
  8459. * @author Mugen87 / https://github.com/Mugen87
  8460. */
  8461. // PlaneGeometry
  8462. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  8463. Geometry.call( this );
  8464. this.type = 'PlaneGeometry';
  8465. this.parameters = {
  8466. width: width,
  8467. height: height,
  8468. widthSegments: widthSegments,
  8469. heightSegments: heightSegments
  8470. };
  8471. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  8472. this.mergeVertices();
  8473. }
  8474. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  8475. PlaneGeometry.prototype.constructor = PlaneGeometry;
  8476. // PlaneBufferGeometry
  8477. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  8478. BufferGeometry.call( this );
  8479. this.type = 'PlaneBufferGeometry';
  8480. this.parameters = {
  8481. width: width,
  8482. height: height,
  8483. widthSegments: widthSegments,
  8484. heightSegments: heightSegments
  8485. };
  8486. width = width || 1;
  8487. height = height || 1;
  8488. var width_half = width / 2;
  8489. var height_half = height / 2;
  8490. var gridX = Math.floor( widthSegments ) || 1;
  8491. var gridY = Math.floor( heightSegments ) || 1;
  8492. var gridX1 = gridX + 1;
  8493. var gridY1 = gridY + 1;
  8494. var segment_width = width / gridX;
  8495. var segment_height = height / gridY;
  8496. var ix, iy;
  8497. // buffers
  8498. var indices = [];
  8499. var vertices = [];
  8500. var normals = [];
  8501. var uvs = [];
  8502. // generate vertices, normals and uvs
  8503. for ( iy = 0; iy < gridY1; iy ++ ) {
  8504. var y = iy * segment_height - height_half;
  8505. for ( ix = 0; ix < gridX1; ix ++ ) {
  8506. var x = ix * segment_width - width_half;
  8507. vertices.push( x, - y, 0 );
  8508. normals.push( 0, 0, 1 );
  8509. uvs.push( ix / gridX );
  8510. uvs.push( 1 - ( iy / gridY ) );
  8511. }
  8512. }
  8513. // indices
  8514. for ( iy = 0; iy < gridY; iy ++ ) {
  8515. for ( ix = 0; ix < gridX; ix ++ ) {
  8516. var a = ix + gridX1 * iy;
  8517. var b = ix + gridX1 * ( iy + 1 );
  8518. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  8519. var d = ( ix + 1 ) + gridX1 * iy;
  8520. // faces
  8521. indices.push( a, b, d );
  8522. indices.push( b, c, d );
  8523. }
  8524. }
  8525. // build geometry
  8526. this.setIndex( indices );
  8527. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  8528. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  8529. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  8530. }
  8531. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  8532. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  8533. /**
  8534. * @author mrdoob / http://mrdoob.com/
  8535. * @author alteredq / http://alteredqualia.com/
  8536. *
  8537. * parameters = {
  8538. * color: <hex>,
  8539. * opacity: <float>,
  8540. * map: new THREE.Texture( <Image> ),
  8541. *
  8542. * lightMap: new THREE.Texture( <Image> ),
  8543. * lightMapIntensity: <float>
  8544. *
  8545. * aoMap: new THREE.Texture( <Image> ),
  8546. * aoMapIntensity: <float>
  8547. *
  8548. * specularMap: new THREE.Texture( <Image> ),
  8549. *
  8550. * alphaMap: new THREE.Texture( <Image> ),
  8551. *
  8552. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  8553. * combine: THREE.Multiply,
  8554. * reflectivity: <float>,
  8555. * refractionRatio: <float>,
  8556. *
  8557. * depthTest: <bool>,
  8558. * depthWrite: <bool>,
  8559. *
  8560. * wireframe: <boolean>,
  8561. * wireframeLinewidth: <float>,
  8562. *
  8563. * skinning: <bool>,
  8564. * morphTargets: <bool>
  8565. * }
  8566. */
  8567. function MeshBasicMaterial( parameters ) {
  8568. Material.call( this );
  8569. this.type = 'MeshBasicMaterial';
  8570. this.color = new Color( 0xffffff ); // emissive
  8571. this.map = null;
  8572. this.lightMap = null;
  8573. this.lightMapIntensity = 1.0;
  8574. this.aoMap = null;
  8575. this.aoMapIntensity = 1.0;
  8576. this.specularMap = null;
  8577. this.alphaMap = null;
  8578. this.envMap = null;
  8579. this.combine = MultiplyOperation;
  8580. this.reflectivity = 1;
  8581. this.refractionRatio = 0.98;
  8582. this.wireframe = false;
  8583. this.wireframeLinewidth = 1;
  8584. this.wireframeLinecap = 'round';
  8585. this.wireframeLinejoin = 'round';
  8586. this.skinning = false;
  8587. this.morphTargets = false;
  8588. this.lights = false;
  8589. this.setValues( parameters );
  8590. }
  8591. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  8592. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  8593. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  8594. MeshBasicMaterial.prototype.copy = function ( source ) {
  8595. Material.prototype.copy.call( this, source );
  8596. this.color.copy( source.color );
  8597. this.map = source.map;
  8598. this.lightMap = source.lightMap;
  8599. this.lightMapIntensity = source.lightMapIntensity;
  8600. this.aoMap = source.aoMap;
  8601. this.aoMapIntensity = source.aoMapIntensity;
  8602. this.specularMap = source.specularMap;
  8603. this.alphaMap = source.alphaMap;
  8604. this.envMap = source.envMap;
  8605. this.combine = source.combine;
  8606. this.reflectivity = source.reflectivity;
  8607. this.refractionRatio = source.refractionRatio;
  8608. this.wireframe = source.wireframe;
  8609. this.wireframeLinewidth = source.wireframeLinewidth;
  8610. this.wireframeLinecap = source.wireframeLinecap;
  8611. this.wireframeLinejoin = source.wireframeLinejoin;
  8612. this.skinning = source.skinning;
  8613. this.morphTargets = source.morphTargets;
  8614. return this;
  8615. };
  8616. /**
  8617. * @author alteredq / http://alteredqualia.com/
  8618. *
  8619. * parameters = {
  8620. * defines: { "label" : "value" },
  8621. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  8622. *
  8623. * fragmentShader: <string>,
  8624. * vertexShader: <string>,
  8625. *
  8626. * wireframe: <boolean>,
  8627. * wireframeLinewidth: <float>,
  8628. *
  8629. * lights: <bool>,
  8630. *
  8631. * skinning: <bool>,
  8632. * morphTargets: <bool>,
  8633. * morphNormals: <bool>
  8634. * }
  8635. */
  8636. function ShaderMaterial( parameters ) {
  8637. Material.call( this );
  8638. this.type = 'ShaderMaterial';
  8639. this.defines = {};
  8640. this.uniforms = {};
  8641. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  8642. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  8643. this.linewidth = 1;
  8644. this.wireframe = false;
  8645. this.wireframeLinewidth = 1;
  8646. this.fog = false; // set to use scene fog
  8647. this.lights = false; // set to use scene lights
  8648. this.clipping = false; // set to use user-defined clipping planes
  8649. this.skinning = false; // set to use skinning attribute streams
  8650. this.morphTargets = false; // set to use morph targets
  8651. this.morphNormals = false; // set to use morph normals
  8652. this.extensions = {
  8653. derivatives: false, // set to use derivatives
  8654. fragDepth: false, // set to use fragment depth values
  8655. drawBuffers: false, // set to use draw buffers
  8656. shaderTextureLOD: false // set to use shader texture LOD
  8657. };
  8658. // When rendered geometry doesn't include these attributes but the material does,
  8659. // use these default values in WebGL. This avoids errors when buffer data is missing.
  8660. this.defaultAttributeValues = {
  8661. 'color': [ 1, 1, 1 ],
  8662. 'uv': [ 0, 0 ],
  8663. 'uv2': [ 0, 0 ]
  8664. };
  8665. this.index0AttributeName = undefined;
  8666. if ( parameters !== undefined ) {
  8667. if ( parameters.attributes !== undefined ) {
  8668. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  8669. }
  8670. this.setValues( parameters );
  8671. }
  8672. }
  8673. ShaderMaterial.prototype = Object.create( Material.prototype );
  8674. ShaderMaterial.prototype.constructor = ShaderMaterial;
  8675. ShaderMaterial.prototype.isShaderMaterial = true;
  8676. ShaderMaterial.prototype.copy = function ( source ) {
  8677. Material.prototype.copy.call( this, source );
  8678. this.fragmentShader = source.fragmentShader;
  8679. this.vertexShader = source.vertexShader;
  8680. this.uniforms = UniformsUtils.clone( source.uniforms );
  8681. this.defines = source.defines;
  8682. this.wireframe = source.wireframe;
  8683. this.wireframeLinewidth = source.wireframeLinewidth;
  8684. this.lights = source.lights;
  8685. this.clipping = source.clipping;
  8686. this.skinning = source.skinning;
  8687. this.morphTargets = source.morphTargets;
  8688. this.morphNormals = source.morphNormals;
  8689. this.extensions = source.extensions;
  8690. return this;
  8691. };
  8692. ShaderMaterial.prototype.toJSON = function ( meta ) {
  8693. var data = Material.prototype.toJSON.call( this, meta );
  8694. data.uniforms = this.uniforms;
  8695. data.vertexShader = this.vertexShader;
  8696. data.fragmentShader = this.fragmentShader;
  8697. return data;
  8698. };
  8699. /**
  8700. * @author bhouston / http://clara.io
  8701. */
  8702. function Ray( origin, direction ) {
  8703. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  8704. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  8705. }
  8706. Object.assign( Ray.prototype, {
  8707. set: function ( origin, direction ) {
  8708. this.origin.copy( origin );
  8709. this.direction.copy( direction );
  8710. return this;
  8711. },
  8712. clone: function () {
  8713. return new this.constructor().copy( this );
  8714. },
  8715. copy: function ( ray ) {
  8716. this.origin.copy( ray.origin );
  8717. this.direction.copy( ray.direction );
  8718. return this;
  8719. },
  8720. at: function ( t, optionalTarget ) {
  8721. var result = optionalTarget || new Vector3();
  8722. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  8723. },
  8724. lookAt: function ( v ) {
  8725. this.direction.copy( v ).sub( this.origin ).normalize();
  8726. return this;
  8727. },
  8728. recast: function () {
  8729. var v1 = new Vector3();
  8730. return function recast( t ) {
  8731. this.origin.copy( this.at( t, v1 ) );
  8732. return this;
  8733. };
  8734. }(),
  8735. closestPointToPoint: function ( point, optionalTarget ) {
  8736. var result = optionalTarget || new Vector3();
  8737. result.subVectors( point, this.origin );
  8738. var directionDistance = result.dot( this.direction );
  8739. if ( directionDistance < 0 ) {
  8740. return result.copy( this.origin );
  8741. }
  8742. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  8743. },
  8744. distanceToPoint: function ( point ) {
  8745. return Math.sqrt( this.distanceSqToPoint( point ) );
  8746. },
  8747. distanceSqToPoint: function () {
  8748. var v1 = new Vector3();
  8749. return function distanceSqToPoint( point ) {
  8750. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  8751. // point behind the ray
  8752. if ( directionDistance < 0 ) {
  8753. return this.origin.distanceToSquared( point );
  8754. }
  8755. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  8756. return v1.distanceToSquared( point );
  8757. };
  8758. }(),
  8759. distanceSqToSegment: function () {
  8760. var segCenter = new Vector3();
  8761. var segDir = new Vector3();
  8762. var diff = new Vector3();
  8763. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  8764. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  8765. // It returns the min distance between the ray and the segment
  8766. // defined by v0 and v1
  8767. // It can also set two optional targets :
  8768. // - The closest point on the ray
  8769. // - The closest point on the segment
  8770. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  8771. segDir.copy( v1 ).sub( v0 ).normalize();
  8772. diff.copy( this.origin ).sub( segCenter );
  8773. var segExtent = v0.distanceTo( v1 ) * 0.5;
  8774. var a01 = - this.direction.dot( segDir );
  8775. var b0 = diff.dot( this.direction );
  8776. var b1 = - diff.dot( segDir );
  8777. var c = diff.lengthSq();
  8778. var det = Math.abs( 1 - a01 * a01 );
  8779. var s0, s1, sqrDist, extDet;
  8780. if ( det > 0 ) {
  8781. // The ray and segment are not parallel.
  8782. s0 = a01 * b1 - b0;
  8783. s1 = a01 * b0 - b1;
  8784. extDet = segExtent * det;
  8785. if ( s0 >= 0 ) {
  8786. if ( s1 >= - extDet ) {
  8787. if ( s1 <= extDet ) {
  8788. // region 0
  8789. // Minimum at interior points of ray and segment.
  8790. var invDet = 1 / det;
  8791. s0 *= invDet;
  8792. s1 *= invDet;
  8793. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  8794. } else {
  8795. // region 1
  8796. s1 = segExtent;
  8797. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8798. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8799. }
  8800. } else {
  8801. // region 5
  8802. s1 = - segExtent;
  8803. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8804. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8805. }
  8806. } else {
  8807. if ( s1 <= - extDet ) {
  8808. // region 4
  8809. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  8810. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8811. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8812. } else if ( s1 <= extDet ) {
  8813. // region 3
  8814. s0 = 0;
  8815. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8816. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  8817. } else {
  8818. // region 2
  8819. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  8820. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8821. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8822. }
  8823. }
  8824. } else {
  8825. // Ray and segment are parallel.
  8826. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  8827. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8828. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8829. }
  8830. if ( optionalPointOnRay ) {
  8831. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  8832. }
  8833. if ( optionalPointOnSegment ) {
  8834. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  8835. }
  8836. return sqrDist;
  8837. };
  8838. }(),
  8839. intersectSphere: function () {
  8840. var v1 = new Vector3();
  8841. return function intersectSphere( sphere, optionalTarget ) {
  8842. v1.subVectors( sphere.center, this.origin );
  8843. var tca = v1.dot( this.direction );
  8844. var d2 = v1.dot( v1 ) - tca * tca;
  8845. var radius2 = sphere.radius * sphere.radius;
  8846. if ( d2 > radius2 ) return null;
  8847. var thc = Math.sqrt( radius2 - d2 );
  8848. // t0 = first intersect point - entrance on front of sphere
  8849. var t0 = tca - thc;
  8850. // t1 = second intersect point - exit point on back of sphere
  8851. var t1 = tca + thc;
  8852. // test to see if both t0 and t1 are behind the ray - if so, return null
  8853. if ( t0 < 0 && t1 < 0 ) return null;
  8854. // test to see if t0 is behind the ray:
  8855. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  8856. // in order to always return an intersect point that is in front of the ray.
  8857. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  8858. // else t0 is in front of the ray, so return the first collision point scaled by t0
  8859. return this.at( t0, optionalTarget );
  8860. };
  8861. }(),
  8862. intersectsSphere: function ( sphere ) {
  8863. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  8864. },
  8865. distanceToPlane: function ( plane ) {
  8866. var denominator = plane.normal.dot( this.direction );
  8867. if ( denominator === 0 ) {
  8868. // line is coplanar, return origin
  8869. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  8870. return 0;
  8871. }
  8872. // Null is preferable to undefined since undefined means.... it is undefined
  8873. return null;
  8874. }
  8875. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  8876. // Return if the ray never intersects the plane
  8877. return t >= 0 ? t : null;
  8878. },
  8879. intersectPlane: function ( plane, optionalTarget ) {
  8880. var t = this.distanceToPlane( plane );
  8881. if ( t === null ) {
  8882. return null;
  8883. }
  8884. return this.at( t, optionalTarget );
  8885. },
  8886. intersectsPlane: function ( plane ) {
  8887. // check if the ray lies on the plane first
  8888. var distToPoint = plane.distanceToPoint( this.origin );
  8889. if ( distToPoint === 0 ) {
  8890. return true;
  8891. }
  8892. var denominator = plane.normal.dot( this.direction );
  8893. if ( denominator * distToPoint < 0 ) {
  8894. return true;
  8895. }
  8896. // ray origin is behind the plane (and is pointing behind it)
  8897. return false;
  8898. },
  8899. intersectBox: function ( box, optionalTarget ) {
  8900. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  8901. var invdirx = 1 / this.direction.x,
  8902. invdiry = 1 / this.direction.y,
  8903. invdirz = 1 / this.direction.z;
  8904. var origin = this.origin;
  8905. if ( invdirx >= 0 ) {
  8906. tmin = ( box.min.x - origin.x ) * invdirx;
  8907. tmax = ( box.max.x - origin.x ) * invdirx;
  8908. } else {
  8909. tmin = ( box.max.x - origin.x ) * invdirx;
  8910. tmax = ( box.min.x - origin.x ) * invdirx;
  8911. }
  8912. if ( invdiry >= 0 ) {
  8913. tymin = ( box.min.y - origin.y ) * invdiry;
  8914. tymax = ( box.max.y - origin.y ) * invdiry;
  8915. } else {
  8916. tymin = ( box.max.y - origin.y ) * invdiry;
  8917. tymax = ( box.min.y - origin.y ) * invdiry;
  8918. }
  8919. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  8920. // These lines also handle the case where tmin or tmax is NaN
  8921. // (result of 0 * Infinity). x !== x returns true if x is NaN
  8922. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  8923. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  8924. if ( invdirz >= 0 ) {
  8925. tzmin = ( box.min.z - origin.z ) * invdirz;
  8926. tzmax = ( box.max.z - origin.z ) * invdirz;
  8927. } else {
  8928. tzmin = ( box.max.z - origin.z ) * invdirz;
  8929. tzmax = ( box.min.z - origin.z ) * invdirz;
  8930. }
  8931. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  8932. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  8933. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  8934. //return point closest to the ray (positive side)
  8935. if ( tmax < 0 ) return null;
  8936. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  8937. },
  8938. intersectsBox: ( function () {
  8939. var v = new Vector3();
  8940. return function intersectsBox( box ) {
  8941. return this.intersectBox( box, v ) !== null;
  8942. };
  8943. } )(),
  8944. intersectTriangle: function () {
  8945. // Compute the offset origin, edges, and normal.
  8946. var diff = new Vector3();
  8947. var edge1 = new Vector3();
  8948. var edge2 = new Vector3();
  8949. var normal = new Vector3();
  8950. return function intersectTriangle( a, b, c, backfaceCulling, optionalTarget ) {
  8951. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  8952. edge1.subVectors( b, a );
  8953. edge2.subVectors( c, a );
  8954. normal.crossVectors( edge1, edge2 );
  8955. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  8956. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  8957. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  8958. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  8959. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  8960. var DdN = this.direction.dot( normal );
  8961. var sign;
  8962. if ( DdN > 0 ) {
  8963. if ( backfaceCulling ) return null;
  8964. sign = 1;
  8965. } else if ( DdN < 0 ) {
  8966. sign = - 1;
  8967. DdN = - DdN;
  8968. } else {
  8969. return null;
  8970. }
  8971. diff.subVectors( this.origin, a );
  8972. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  8973. // b1 < 0, no intersection
  8974. if ( DdQxE2 < 0 ) {
  8975. return null;
  8976. }
  8977. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  8978. // b2 < 0, no intersection
  8979. if ( DdE1xQ < 0 ) {
  8980. return null;
  8981. }
  8982. // b1+b2 > 1, no intersection
  8983. if ( DdQxE2 + DdE1xQ > DdN ) {
  8984. return null;
  8985. }
  8986. // Line intersects triangle, check if ray does.
  8987. var QdN = - sign * diff.dot( normal );
  8988. // t < 0, no intersection
  8989. if ( QdN < 0 ) {
  8990. return null;
  8991. }
  8992. // Ray intersects triangle.
  8993. return this.at( QdN / DdN, optionalTarget );
  8994. };
  8995. }(),
  8996. applyMatrix4: function ( matrix4 ) {
  8997. this.origin.applyMatrix4( matrix4 );
  8998. this.direction.transformDirection( matrix4 );
  8999. return this;
  9000. },
  9001. equals: function ( ray ) {
  9002. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  9003. }
  9004. } );
  9005. /**
  9006. * @author bhouston / http://clara.io
  9007. */
  9008. function Line3( start, end ) {
  9009. this.start = ( start !== undefined ) ? start : new Vector3();
  9010. this.end = ( end !== undefined ) ? end : new Vector3();
  9011. }
  9012. Object.assign( Line3.prototype, {
  9013. set: function ( start, end ) {
  9014. this.start.copy( start );
  9015. this.end.copy( end );
  9016. return this;
  9017. },
  9018. clone: function () {
  9019. return new this.constructor().copy( this );
  9020. },
  9021. copy: function ( line ) {
  9022. this.start.copy( line.start );
  9023. this.end.copy( line.end );
  9024. return this;
  9025. },
  9026. getCenter: function ( optionalTarget ) {
  9027. var result = optionalTarget || new Vector3();
  9028. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  9029. },
  9030. delta: function ( optionalTarget ) {
  9031. var result = optionalTarget || new Vector3();
  9032. return result.subVectors( this.end, this.start );
  9033. },
  9034. distanceSq: function () {
  9035. return this.start.distanceToSquared( this.end );
  9036. },
  9037. distance: function () {
  9038. return this.start.distanceTo( this.end );
  9039. },
  9040. at: function ( t, optionalTarget ) {
  9041. var result = optionalTarget || new Vector3();
  9042. return this.delta( result ).multiplyScalar( t ).add( this.start );
  9043. },
  9044. closestPointToPointParameter: function () {
  9045. var startP = new Vector3();
  9046. var startEnd = new Vector3();
  9047. return function closestPointToPointParameter( point, clampToLine ) {
  9048. startP.subVectors( point, this.start );
  9049. startEnd.subVectors( this.end, this.start );
  9050. var startEnd2 = startEnd.dot( startEnd );
  9051. var startEnd_startP = startEnd.dot( startP );
  9052. var t = startEnd_startP / startEnd2;
  9053. if ( clampToLine ) {
  9054. t = _Math.clamp( t, 0, 1 );
  9055. }
  9056. return t;
  9057. };
  9058. }(),
  9059. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  9060. var t = this.closestPointToPointParameter( point, clampToLine );
  9061. var result = optionalTarget || new Vector3();
  9062. return this.delta( result ).multiplyScalar( t ).add( this.start );
  9063. },
  9064. applyMatrix4: function ( matrix ) {
  9065. this.start.applyMatrix4( matrix );
  9066. this.end.applyMatrix4( matrix );
  9067. return this;
  9068. },
  9069. equals: function ( line ) {
  9070. return line.start.equals( this.start ) && line.end.equals( this.end );
  9071. }
  9072. } );
  9073. /**
  9074. * @author bhouston / http://clara.io
  9075. * @author mrdoob / http://mrdoob.com/
  9076. */
  9077. function Triangle( a, b, c ) {
  9078. this.a = ( a !== undefined ) ? a : new Vector3();
  9079. this.b = ( b !== undefined ) ? b : new Vector3();
  9080. this.c = ( c !== undefined ) ? c : new Vector3();
  9081. }
  9082. Object.assign( Triangle, {
  9083. normal: function () {
  9084. var v0 = new Vector3();
  9085. return function normal( a, b, c, optionalTarget ) {
  9086. var result = optionalTarget || new Vector3();
  9087. result.subVectors( c, b );
  9088. v0.subVectors( a, b );
  9089. result.cross( v0 );
  9090. var resultLengthSq = result.lengthSq();
  9091. if ( resultLengthSq > 0 ) {
  9092. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  9093. }
  9094. return result.set( 0, 0, 0 );
  9095. };
  9096. }(),
  9097. // static/instance method to calculate barycentric coordinates
  9098. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  9099. barycoordFromPoint: function () {
  9100. var v0 = new Vector3();
  9101. var v1 = new Vector3();
  9102. var v2 = new Vector3();
  9103. return function barycoordFromPoint( point, a, b, c, optionalTarget ) {
  9104. v0.subVectors( c, a );
  9105. v1.subVectors( b, a );
  9106. v2.subVectors( point, a );
  9107. var dot00 = v0.dot( v0 );
  9108. var dot01 = v0.dot( v1 );
  9109. var dot02 = v0.dot( v2 );
  9110. var dot11 = v1.dot( v1 );
  9111. var dot12 = v1.dot( v2 );
  9112. var denom = ( dot00 * dot11 - dot01 * dot01 );
  9113. var result = optionalTarget || new Vector3();
  9114. // collinear or singular triangle
  9115. if ( denom === 0 ) {
  9116. // arbitrary location outside of triangle?
  9117. // not sure if this is the best idea, maybe should be returning undefined
  9118. return result.set( - 2, - 1, - 1 );
  9119. }
  9120. var invDenom = 1 / denom;
  9121. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  9122. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  9123. // barycentric coordinates must always sum to 1
  9124. return result.set( 1 - u - v, v, u );
  9125. };
  9126. }(),
  9127. containsPoint: function () {
  9128. var v1 = new Vector3();
  9129. return function containsPoint( point, a, b, c ) {
  9130. var result = Triangle.barycoordFromPoint( point, a, b, c, v1 );
  9131. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  9132. };
  9133. }()
  9134. } );
  9135. Object.assign( Triangle.prototype, {
  9136. set: function ( a, b, c ) {
  9137. this.a.copy( a );
  9138. this.b.copy( b );
  9139. this.c.copy( c );
  9140. return this;
  9141. },
  9142. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  9143. this.a.copy( points[ i0 ] );
  9144. this.b.copy( points[ i1 ] );
  9145. this.c.copy( points[ i2 ] );
  9146. return this;
  9147. },
  9148. clone: function () {
  9149. return new this.constructor().copy( this );
  9150. },
  9151. copy: function ( triangle ) {
  9152. this.a.copy( triangle.a );
  9153. this.b.copy( triangle.b );
  9154. this.c.copy( triangle.c );
  9155. return this;
  9156. },
  9157. area: function () {
  9158. var v0 = new Vector3();
  9159. var v1 = new Vector3();
  9160. return function area() {
  9161. v0.subVectors( this.c, this.b );
  9162. v1.subVectors( this.a, this.b );
  9163. return v0.cross( v1 ).length() * 0.5;
  9164. };
  9165. }(),
  9166. midpoint: function ( optionalTarget ) {
  9167. var result = optionalTarget || new Vector3();
  9168. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  9169. },
  9170. normal: function ( optionalTarget ) {
  9171. return Triangle.normal( this.a, this.b, this.c, optionalTarget );
  9172. },
  9173. plane: function ( optionalTarget ) {
  9174. var result = optionalTarget || new Plane();
  9175. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  9176. },
  9177. barycoordFromPoint: function ( point, optionalTarget ) {
  9178. return Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  9179. },
  9180. containsPoint: function ( point ) {
  9181. return Triangle.containsPoint( point, this.a, this.b, this.c );
  9182. },
  9183. intersectsBox: function ( box ) {
  9184. return box.intersectsTriangle( this );
  9185. },
  9186. closestPointToPoint: function () {
  9187. var plane = new Plane();
  9188. var edgeList = [ new Line3(), new Line3(), new Line3() ];
  9189. var projectedPoint = new Vector3();
  9190. var closestPoint = new Vector3();
  9191. return function closestPointToPoint( point, optionalTarget ) {
  9192. var result = optionalTarget || new Vector3();
  9193. var minDistance = Infinity;
  9194. // project the point onto the plane of the triangle
  9195. plane.setFromCoplanarPoints( this.a, this.b, this.c );
  9196. plane.projectPoint( point, projectedPoint );
  9197. // check if the projection lies within the triangle
  9198. if ( this.containsPoint( projectedPoint ) === true ) {
  9199. // if so, this is the closest point
  9200. result.copy( projectedPoint );
  9201. } else {
  9202. // if not, the point falls outside the triangle. the result is the closest point to the triangle's edges or vertices
  9203. edgeList[ 0 ].set( this.a, this.b );
  9204. edgeList[ 1 ].set( this.b, this.c );
  9205. edgeList[ 2 ].set( this.c, this.a );
  9206. for ( var i = 0; i < edgeList.length; i ++ ) {
  9207. edgeList[ i ].closestPointToPoint( projectedPoint, true, closestPoint );
  9208. var distance = projectedPoint.distanceToSquared( closestPoint );
  9209. if ( distance < minDistance ) {
  9210. minDistance = distance;
  9211. result.copy( closestPoint );
  9212. }
  9213. }
  9214. }
  9215. return result;
  9216. };
  9217. }(),
  9218. equals: function ( triangle ) {
  9219. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  9220. }
  9221. } );
  9222. /**
  9223. * @author mrdoob / http://mrdoob.com/
  9224. * @author alteredq / http://alteredqualia.com/
  9225. * @author mikael emtinger / http://gomo.se/
  9226. * @author jonobr1 / http://jonobr1.com/
  9227. */
  9228. function Mesh( geometry, material ) {
  9229. Object3D.call( this );
  9230. this.type = 'Mesh';
  9231. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  9232. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  9233. this.drawMode = TrianglesDrawMode;
  9234. this.updateMorphTargets();
  9235. }
  9236. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  9237. constructor: Mesh,
  9238. isMesh: true,
  9239. setDrawMode: function ( value ) {
  9240. this.drawMode = value;
  9241. },
  9242. copy: function ( source ) {
  9243. Object3D.prototype.copy.call( this, source );
  9244. this.drawMode = source.drawMode;
  9245. if ( source.morphTargetInfluences !== undefined ) {
  9246. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  9247. }
  9248. if ( source.morphTargetDictionary !== undefined ) {
  9249. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  9250. }
  9251. return this;
  9252. },
  9253. updateMorphTargets: function () {
  9254. var geometry = this.geometry;
  9255. var m, ml, name;
  9256. if ( geometry.isBufferGeometry ) {
  9257. var morphAttributes = geometry.morphAttributes;
  9258. var keys = Object.keys( morphAttributes );
  9259. if ( keys.length > 0 ) {
  9260. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  9261. if ( morphAttribute !== undefined ) {
  9262. this.morphTargetInfluences = [];
  9263. this.morphTargetDictionary = {};
  9264. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  9265. name = morphAttribute[ m ].name || String( m );
  9266. this.morphTargetInfluences.push( 0 );
  9267. this.morphTargetDictionary[ name ] = m;
  9268. }
  9269. }
  9270. }
  9271. } else {
  9272. var morphTargets = geometry.morphTargets;
  9273. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  9274. this.morphTargetInfluences = [];
  9275. this.morphTargetDictionary = {};
  9276. for ( m = 0, ml = morphTargets.length; m < ml; m ++ ) {
  9277. name = morphTargets[ m ].name || String( m );
  9278. this.morphTargetInfluences.push( 0 );
  9279. this.morphTargetDictionary[ name ] = m;
  9280. }
  9281. }
  9282. }
  9283. },
  9284. raycast: ( function () {
  9285. var inverseMatrix = new Matrix4();
  9286. var ray = new Ray();
  9287. var sphere = new Sphere();
  9288. var vA = new Vector3();
  9289. var vB = new Vector3();
  9290. var vC = new Vector3();
  9291. var tempA = new Vector3();
  9292. var tempB = new Vector3();
  9293. var tempC = new Vector3();
  9294. var uvA = new Vector2();
  9295. var uvB = new Vector2();
  9296. var uvC = new Vector2();
  9297. var barycoord = new Vector3();
  9298. var intersectionPoint = new Vector3();
  9299. var intersectionPointWorld = new Vector3();
  9300. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  9301. Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  9302. uv1.multiplyScalar( barycoord.x );
  9303. uv2.multiplyScalar( barycoord.y );
  9304. uv3.multiplyScalar( barycoord.z );
  9305. uv1.add( uv2 ).add( uv3 );
  9306. return uv1.clone();
  9307. }
  9308. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  9309. var intersect;
  9310. if ( material.side === BackSide ) {
  9311. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  9312. } else {
  9313. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  9314. }
  9315. if ( intersect === null ) return null;
  9316. intersectionPointWorld.copy( point );
  9317. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  9318. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  9319. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  9320. return {
  9321. distance: distance,
  9322. point: intersectionPointWorld.clone(),
  9323. object: object
  9324. };
  9325. }
  9326. function checkBufferGeometryIntersection( object, raycaster, ray, position, uv, a, b, c ) {
  9327. vA.fromBufferAttribute( position, a );
  9328. vB.fromBufferAttribute( position, b );
  9329. vC.fromBufferAttribute( position, c );
  9330. var intersection = checkIntersection( object, object.material, raycaster, ray, vA, vB, vC, intersectionPoint );
  9331. if ( intersection ) {
  9332. if ( uv ) {
  9333. uvA.fromBufferAttribute( uv, a );
  9334. uvB.fromBufferAttribute( uv, b );
  9335. uvC.fromBufferAttribute( uv, c );
  9336. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  9337. }
  9338. intersection.face = new Face3( a, b, c, Triangle.normal( vA, vB, vC ) );
  9339. intersection.faceIndex = a;
  9340. }
  9341. return intersection;
  9342. }
  9343. return function raycast( raycaster, intersects ) {
  9344. var geometry = this.geometry;
  9345. var material = this.material;
  9346. var matrixWorld = this.matrixWorld;
  9347. if ( material === undefined ) return;
  9348. // Checking boundingSphere distance to ray
  9349. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9350. sphere.copy( geometry.boundingSphere );
  9351. sphere.applyMatrix4( matrixWorld );
  9352. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  9353. //
  9354. inverseMatrix.getInverse( matrixWorld );
  9355. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9356. // Check boundingBox before continuing
  9357. if ( geometry.boundingBox !== null ) {
  9358. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  9359. }
  9360. var intersection;
  9361. if ( geometry.isBufferGeometry ) {
  9362. var a, b, c;
  9363. var index = geometry.index;
  9364. var position = geometry.attributes.position;
  9365. var uv = geometry.attributes.uv;
  9366. var i, l;
  9367. if ( index !== null ) {
  9368. // indexed buffer geometry
  9369. for ( i = 0, l = index.count; i < l; i += 3 ) {
  9370. a = index.getX( i );
  9371. b = index.getX( i + 1 );
  9372. c = index.getX( i + 2 );
  9373. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  9374. if ( intersection ) {
  9375. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  9376. intersects.push( intersection );
  9377. }
  9378. }
  9379. } else if ( position !== undefined ) {
  9380. // non-indexed buffer geometry
  9381. for ( i = 0, l = position.count; i < l; i += 3 ) {
  9382. a = i;
  9383. b = i + 1;
  9384. c = i + 2;
  9385. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  9386. if ( intersection ) {
  9387. intersection.index = a; // triangle number in positions buffer semantics
  9388. intersects.push( intersection );
  9389. }
  9390. }
  9391. }
  9392. } else if ( geometry.isGeometry ) {
  9393. var fvA, fvB, fvC;
  9394. var isMultiMaterial = Array.isArray( material );
  9395. var vertices = geometry.vertices;
  9396. var faces = geometry.faces;
  9397. var uvs;
  9398. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  9399. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  9400. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  9401. var face = faces[ f ];
  9402. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  9403. if ( faceMaterial === undefined ) continue;
  9404. fvA = vertices[ face.a ];
  9405. fvB = vertices[ face.b ];
  9406. fvC = vertices[ face.c ];
  9407. if ( faceMaterial.morphTargets === true ) {
  9408. var morphTargets = geometry.morphTargets;
  9409. var morphInfluences = this.morphTargetInfluences;
  9410. vA.set( 0, 0, 0 );
  9411. vB.set( 0, 0, 0 );
  9412. vC.set( 0, 0, 0 );
  9413. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  9414. var influence = morphInfluences[ t ];
  9415. if ( influence === 0 ) continue;
  9416. var targets = morphTargets[ t ].vertices;
  9417. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  9418. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  9419. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  9420. }
  9421. vA.add( fvA );
  9422. vB.add( fvB );
  9423. vC.add( fvC );
  9424. fvA = vA;
  9425. fvB = vB;
  9426. fvC = vC;
  9427. }
  9428. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  9429. if ( intersection ) {
  9430. if ( uvs && uvs[ f ] ) {
  9431. var uvs_f = uvs[ f ];
  9432. uvA.copy( uvs_f[ 0 ] );
  9433. uvB.copy( uvs_f[ 1 ] );
  9434. uvC.copy( uvs_f[ 2 ] );
  9435. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  9436. }
  9437. intersection.face = face;
  9438. intersection.faceIndex = f;
  9439. intersects.push( intersection );
  9440. }
  9441. }
  9442. }
  9443. };
  9444. }() ),
  9445. clone: function () {
  9446. return new this.constructor( this.geometry, this.material ).copy( this );
  9447. }
  9448. } );
  9449. /**
  9450. * @author mrdoob / http://mrdoob.com/
  9451. */
  9452. function WebGLBackground( renderer, state, geometries, premultipliedAlpha ) {
  9453. var clearColor = new Color( 0x000000 );
  9454. var clearAlpha = 0;
  9455. var planeCamera, planeMesh;
  9456. var boxMesh;
  9457. function render( renderList, scene, camera, forceClear ) {
  9458. var background = scene.background;
  9459. if ( background === null ) {
  9460. setClear( clearColor, clearAlpha );
  9461. } else if ( background && background.isColor ) {
  9462. setClear( background, 1 );
  9463. forceClear = true;
  9464. }
  9465. if ( renderer.autoClear || forceClear ) {
  9466. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  9467. }
  9468. if ( background && background.isCubeTexture ) {
  9469. if ( boxMesh === undefined ) {
  9470. boxMesh = new Mesh(
  9471. new BoxBufferGeometry( 1, 1, 1 ),
  9472. new ShaderMaterial( {
  9473. uniforms: ShaderLib.cube.uniforms,
  9474. vertexShader: ShaderLib.cube.vertexShader,
  9475. fragmentShader: ShaderLib.cube.fragmentShader,
  9476. side: BackSide,
  9477. depthTest: true,
  9478. depthWrite: false,
  9479. fog: false
  9480. } )
  9481. );
  9482. boxMesh.geometry.removeAttribute( 'normal' );
  9483. boxMesh.geometry.removeAttribute( 'uv' );
  9484. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  9485. this.matrixWorld.copyPosition( camera.matrixWorld );
  9486. };
  9487. geometries.update( boxMesh.geometry );
  9488. }
  9489. boxMesh.material.uniforms.tCube.value = background;
  9490. renderList.push( boxMesh, boxMesh.geometry, boxMesh.material, 0, null );
  9491. } else if ( background && background.isTexture ) {
  9492. if ( planeCamera === undefined ) {
  9493. planeCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  9494. planeMesh = new Mesh(
  9495. new PlaneBufferGeometry( 2, 2 ),
  9496. new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
  9497. );
  9498. geometries.update( planeMesh.geometry );
  9499. }
  9500. planeMesh.material.map = background;
  9501. // TODO Push this to renderList
  9502. renderer.renderBufferDirect( planeCamera, null, planeMesh.geometry, planeMesh.material, planeMesh, null );
  9503. }
  9504. }
  9505. function setClear( color, alpha ) {
  9506. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  9507. }
  9508. return {
  9509. getClearColor: function () {
  9510. return clearColor;
  9511. },
  9512. setClearColor: function ( color, alpha ) {
  9513. clearColor.set( color );
  9514. clearAlpha = alpha !== undefined ? alpha : 1;
  9515. setClear( clearColor, clearAlpha );
  9516. },
  9517. getClearAlpha: function () {
  9518. return clearAlpha;
  9519. },
  9520. setClearAlpha: function ( alpha ) {
  9521. clearAlpha = alpha;
  9522. setClear( clearColor, clearAlpha );
  9523. },
  9524. render: render
  9525. };
  9526. }
  9527. /**
  9528. * @author mrdoob / http://mrdoob.com/
  9529. */
  9530. function painterSortStable( a, b ) {
  9531. if ( a.renderOrder !== b.renderOrder ) {
  9532. return a.renderOrder - b.renderOrder;
  9533. } else if ( a.program && b.program && a.program !== b.program ) {
  9534. return a.program.id - b.program.id;
  9535. } else if ( a.material.id !== b.material.id ) {
  9536. return a.material.id - b.material.id;
  9537. } else if ( a.z !== b.z ) {
  9538. return a.z - b.z;
  9539. } else {
  9540. return a.id - b.id;
  9541. }
  9542. }
  9543. function reversePainterSortStable( a, b ) {
  9544. if ( a.renderOrder !== b.renderOrder ) {
  9545. return a.renderOrder - b.renderOrder;
  9546. } if ( a.z !== b.z ) {
  9547. return b.z - a.z;
  9548. } else {
  9549. return a.id - b.id;
  9550. }
  9551. }
  9552. function WebGLRenderList() {
  9553. var renderItems = [];
  9554. var renderItemsIndex = 0;
  9555. var opaque = [];
  9556. var transparent = [];
  9557. function init() {
  9558. renderItemsIndex = 0;
  9559. opaque.length = 0;
  9560. transparent.length = 0;
  9561. }
  9562. function push( object, geometry, material, z, group ) {
  9563. var renderItem = renderItems[ renderItemsIndex ];
  9564. if ( renderItem === undefined ) {
  9565. renderItem = {
  9566. id: object.id,
  9567. object: object,
  9568. geometry: geometry,
  9569. material: material,
  9570. program: material.program,
  9571. renderOrder: object.renderOrder,
  9572. z: z,
  9573. group: group
  9574. };
  9575. renderItems[ renderItemsIndex ] = renderItem;
  9576. } else {
  9577. renderItem.id = object.id;
  9578. renderItem.object = object;
  9579. renderItem.geometry = geometry;
  9580. renderItem.material = material;
  9581. renderItem.program = material.program;
  9582. renderItem.renderOrder = object.renderOrder;
  9583. renderItem.z = z;
  9584. renderItem.group = group;
  9585. }
  9586. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  9587. renderItemsIndex ++;
  9588. }
  9589. function sort() {
  9590. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  9591. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  9592. }
  9593. return {
  9594. opaque: opaque,
  9595. transparent: transparent,
  9596. init: init,
  9597. push: push,
  9598. sort: sort
  9599. };
  9600. }
  9601. function WebGLRenderLists() {
  9602. var lists = {};
  9603. function get( scene, camera ) {
  9604. var hash = scene.id + ',' + camera.id;
  9605. var list = lists[ hash ];
  9606. if ( list === undefined ) {
  9607. // console.log( 'THREE.WebGLRenderLists:', hash );
  9608. list = new WebGLRenderList();
  9609. lists[ hash ] = list;
  9610. }
  9611. return list;
  9612. }
  9613. function dispose() {
  9614. lists = {};
  9615. }
  9616. return {
  9617. get: get,
  9618. dispose: dispose
  9619. };
  9620. }
  9621. /**
  9622. * @author mrdoob / http://mrdoob.com/
  9623. */
  9624. function absNumericalSort( a, b ) {
  9625. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9626. }
  9627. function WebGLMorphtargets( gl ) {
  9628. var influencesList = {};
  9629. var morphInfluences = new Float32Array( 8 );
  9630. function update( object, geometry, material, program ) {
  9631. var objectInfluences = object.morphTargetInfluences;
  9632. var length = objectInfluences.length;
  9633. var influences = influencesList[ geometry.id ];
  9634. if ( influences === undefined ) {
  9635. // initialise list
  9636. influences = [];
  9637. for ( var i = 0; i < length; i ++ ) {
  9638. influences[ i ] = [ i, 0 ];
  9639. }
  9640. influencesList[ geometry.id ] = influences;
  9641. }
  9642. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9643. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9644. // Remove current morphAttributes
  9645. for ( var i = 0; i < length; i ++ ) {
  9646. var influence = influences[ i ];
  9647. if ( influence[ 1 ] !== 0 ) {
  9648. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  9649. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  9650. }
  9651. }
  9652. // Collect influences
  9653. for ( var i = 0; i < length; i ++ ) {
  9654. var influence = influences[ i ];
  9655. influence[ 0 ] = i;
  9656. influence[ 1 ] = objectInfluences[ i ];
  9657. }
  9658. influences.sort( absNumericalSort );
  9659. // Add morphAttributes
  9660. for ( var i = 0; i < 8; i ++ ) {
  9661. var influence = influences[ i ];
  9662. if ( influence ) {
  9663. var index = influence[ 0 ];
  9664. var value = influence[ 1 ];
  9665. if ( value ) {
  9666. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9667. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9668. morphInfluences[ i ] = value;
  9669. continue;
  9670. }
  9671. }
  9672. morphInfluences[ i ] = 0;
  9673. }
  9674. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9675. }
  9676. return {
  9677. update: update
  9678. };
  9679. }
  9680. /**
  9681. * @author mrdoob / http://mrdoob.com/
  9682. */
  9683. function WebGLIndexedBufferRenderer( gl, extensions, infoRender ) {
  9684. var mode;
  9685. function setMode( value ) {
  9686. mode = value;
  9687. }
  9688. var type, bytesPerElement;
  9689. function setIndex( value ) {
  9690. type = value.type;
  9691. bytesPerElement = value.bytesPerElement;
  9692. }
  9693. function render( start, count ) {
  9694. gl.drawElements( mode, count, type, start * bytesPerElement );
  9695. infoRender.calls ++;
  9696. infoRender.vertices += count;
  9697. if ( mode === gl.TRIANGLES ) infoRender.faces += count / 3;
  9698. else if ( mode === gl.POINTS ) infoRender.points += count;
  9699. }
  9700. function renderInstances( geometry, start, count ) {
  9701. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9702. if ( extension === null ) {
  9703. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9704. return;
  9705. }
  9706. extension.drawElementsInstancedANGLE( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  9707. infoRender.calls ++;
  9708. infoRender.vertices += count * geometry.maxInstancedCount;
  9709. if ( mode === gl.TRIANGLES ) infoRender.faces += geometry.maxInstancedCount * count / 3;
  9710. else if ( mode === gl.POINTS ) infoRender.points += geometry.maxInstancedCount * count;
  9711. }
  9712. //
  9713. this.setMode = setMode;
  9714. this.setIndex = setIndex;
  9715. this.render = render;
  9716. this.renderInstances = renderInstances;
  9717. }
  9718. /**
  9719. * @author mrdoob / http://mrdoob.com/
  9720. */
  9721. function WebGLBufferRenderer( gl, extensions, infoRender ) {
  9722. var mode;
  9723. function setMode( value ) {
  9724. mode = value;
  9725. }
  9726. function render( start, count ) {
  9727. gl.drawArrays( mode, start, count );
  9728. infoRender.calls ++;
  9729. infoRender.vertices += count;
  9730. if ( mode === gl.TRIANGLES ) infoRender.faces += count / 3;
  9731. else if ( mode === gl.POINTS ) infoRender.points += count;
  9732. }
  9733. function renderInstances( geometry, start, count ) {
  9734. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9735. if ( extension === null ) {
  9736. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9737. return;
  9738. }
  9739. var position = geometry.attributes.position;
  9740. if ( position.isInterleavedBufferAttribute ) {
  9741. count = position.data.count;
  9742. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  9743. } else {
  9744. extension.drawArraysInstancedANGLE( mode, start, count, geometry.maxInstancedCount );
  9745. }
  9746. infoRender.calls ++;
  9747. infoRender.vertices += count * geometry.maxInstancedCount;
  9748. if ( mode === gl.TRIANGLES ) infoRender.faces += geometry.maxInstancedCount * count / 3;
  9749. else if ( mode === gl.POINTS ) infoRender.points += geometry.maxInstancedCount * count;
  9750. }
  9751. //
  9752. this.setMode = setMode;
  9753. this.render = render;
  9754. this.renderInstances = renderInstances;
  9755. }
  9756. /**
  9757. * @author mrdoob / http://mrdoob.com/
  9758. */
  9759. function WebGLGeometries( gl, attributes, infoMemory ) {
  9760. var geometries = {};
  9761. var wireframeAttributes = {};
  9762. function onGeometryDispose( event ) {
  9763. var geometry = event.target;
  9764. var buffergeometry = geometries[ geometry.id ];
  9765. if ( buffergeometry.index !== null ) {
  9766. attributes.remove( buffergeometry.index );
  9767. }
  9768. for ( var name in buffergeometry.attributes ) {
  9769. attributes.remove( buffergeometry.attributes[ name ] );
  9770. }
  9771. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9772. delete geometries[ geometry.id ];
  9773. // TODO Remove duplicate code
  9774. var attribute = wireframeAttributes[ geometry.id ];
  9775. if ( attribute ) {
  9776. attributes.remove( attribute );
  9777. delete wireframeAttributes[ geometry.id ];
  9778. }
  9779. attribute = wireframeAttributes[ buffergeometry.id ];
  9780. if ( attribute ) {
  9781. attributes.remove( attribute );
  9782. delete wireframeAttributes[ buffergeometry.id ];
  9783. }
  9784. //
  9785. infoMemory.geometries --;
  9786. }
  9787. function get( object, geometry ) {
  9788. var buffergeometry = geometries[ geometry.id ];
  9789. if ( buffergeometry ) return buffergeometry;
  9790. geometry.addEventListener( 'dispose', onGeometryDispose );
  9791. if ( geometry.isBufferGeometry ) {
  9792. buffergeometry = geometry;
  9793. } else if ( geometry.isGeometry ) {
  9794. if ( geometry._bufferGeometry === undefined ) {
  9795. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9796. }
  9797. buffergeometry = geometry._bufferGeometry;
  9798. }
  9799. geometries[ geometry.id ] = buffergeometry;
  9800. infoMemory.geometries ++;
  9801. return buffergeometry;
  9802. }
  9803. function update( geometry ) {
  9804. var index = geometry.index;
  9805. var geometryAttributes = geometry.attributes;
  9806. if ( index !== null ) {
  9807. attributes.update( index, gl.ELEMENT_ARRAY_BUFFER );
  9808. }
  9809. for ( var name in geometryAttributes ) {
  9810. attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER );
  9811. }
  9812. // morph targets
  9813. var morphAttributes = geometry.morphAttributes;
  9814. for ( var name in morphAttributes ) {
  9815. var array = morphAttributes[ name ];
  9816. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9817. attributes.update( array[ i ], gl.ARRAY_BUFFER );
  9818. }
  9819. }
  9820. }
  9821. function getWireframeAttribute( geometry ) {
  9822. var attribute = wireframeAttributes[ geometry.id ];
  9823. if ( attribute ) return attribute;
  9824. var indices = [];
  9825. var geometryIndex = geometry.index;
  9826. var geometryAttributes = geometry.attributes;
  9827. // console.time( 'wireframe' );
  9828. if ( geometryIndex !== null ) {
  9829. var array = geometryIndex.array;
  9830. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9831. var a = array[ i + 0 ];
  9832. var b = array[ i + 1 ];
  9833. var c = array[ i + 2 ];
  9834. indices.push( a, b, b, c, c, a );
  9835. }
  9836. } else {
  9837. var array = geometryAttributes.position.array;
  9838. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9839. var a = i + 0;
  9840. var b = i + 1;
  9841. var c = i + 2;
  9842. indices.push( a, b, b, c, c, a );
  9843. }
  9844. }
  9845. // console.timeEnd( 'wireframe' );
  9846. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9847. attributes.update( attribute, gl.ELEMENT_ARRAY_BUFFER );
  9848. wireframeAttributes[ geometry.id ] = attribute;
  9849. return attribute;
  9850. }
  9851. return {
  9852. get: get,
  9853. update: update,
  9854. getWireframeAttribute: getWireframeAttribute
  9855. };
  9856. }
  9857. /**
  9858. * @author mrdoob / http://mrdoob.com/
  9859. */
  9860. function WebGLObjects( geometries, infoRender ) {
  9861. var updateList = {};
  9862. function update( object ) {
  9863. var frame = infoRender.frame;
  9864. var geometry = object.geometry;
  9865. var buffergeometry = geometries.get( object, geometry );
  9866. // Update once per frame
  9867. if ( updateList[ buffergeometry.id ] !== frame ) {
  9868. if ( geometry.isGeometry ) {
  9869. buffergeometry.updateFromObject( object );
  9870. }
  9871. geometries.update( buffergeometry );
  9872. updateList[ buffergeometry.id ] = frame;
  9873. }
  9874. return buffergeometry;
  9875. }
  9876. function dispose() {
  9877. updateList = {};
  9878. }
  9879. return {
  9880. update: update,
  9881. dispose: dispose
  9882. };
  9883. }
  9884. /**
  9885. * @author mrdoob / http://mrdoob.com/
  9886. */
  9887. function addLineNumbers( string ) {
  9888. var lines = string.split( '\n' );
  9889. for ( var i = 0; i < lines.length; i ++ ) {
  9890. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  9891. }
  9892. return lines.join( '\n' );
  9893. }
  9894. function WebGLShader( gl, type, string ) {
  9895. var shader = gl.createShader( type );
  9896. gl.shaderSource( shader, string );
  9897. gl.compileShader( shader );
  9898. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  9899. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  9900. }
  9901. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  9902. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  9903. }
  9904. // --enable-privileged-webgl-extension
  9905. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  9906. return shader;
  9907. }
  9908. /**
  9909. * @author mrdoob / http://mrdoob.com/
  9910. */
  9911. var programIdCount = 0;
  9912. function getEncodingComponents( encoding ) {
  9913. switch ( encoding ) {
  9914. case LinearEncoding:
  9915. return [ 'Linear', '( value )' ];
  9916. case sRGBEncoding:
  9917. return [ 'sRGB', '( value )' ];
  9918. case RGBEEncoding:
  9919. return [ 'RGBE', '( value )' ];
  9920. case RGBM7Encoding:
  9921. return [ 'RGBM', '( value, 7.0 )' ];
  9922. case RGBM16Encoding:
  9923. return [ 'RGBM', '( value, 16.0 )' ];
  9924. case RGBDEncoding:
  9925. return [ 'RGBD', '( value, 256.0 )' ];
  9926. case GammaEncoding:
  9927. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  9928. default:
  9929. throw new Error( 'unsupported encoding: ' + encoding );
  9930. }
  9931. }
  9932. function getTexelDecodingFunction( functionName, encoding ) {
  9933. var components = getEncodingComponents( encoding );
  9934. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  9935. }
  9936. function getTexelEncodingFunction( functionName, encoding ) {
  9937. var components = getEncodingComponents( encoding );
  9938. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  9939. }
  9940. function getToneMappingFunction( functionName, toneMapping ) {
  9941. var toneMappingName;
  9942. switch ( toneMapping ) {
  9943. case LinearToneMapping:
  9944. toneMappingName = 'Linear';
  9945. break;
  9946. case ReinhardToneMapping:
  9947. toneMappingName = 'Reinhard';
  9948. break;
  9949. case Uncharted2ToneMapping:
  9950. toneMappingName = 'Uncharted2';
  9951. break;
  9952. case CineonToneMapping:
  9953. toneMappingName = 'OptimizedCineon';
  9954. break;
  9955. default:
  9956. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  9957. }
  9958. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  9959. }
  9960. function generateExtensions( extensions, parameters, rendererExtensions ) {
  9961. extensions = extensions || {};
  9962. var chunks = [
  9963. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  9964. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  9965. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  9966. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  9967. ];
  9968. return chunks.filter( filterEmptyLine ).join( '\n' );
  9969. }
  9970. function generateDefines( defines ) {
  9971. var chunks = [];
  9972. for ( var name in defines ) {
  9973. var value = defines[ name ];
  9974. if ( value === false ) continue;
  9975. chunks.push( '#define ' + name + ' ' + value );
  9976. }
  9977. return chunks.join( '\n' );
  9978. }
  9979. function fetchAttributeLocations( gl, program ) {
  9980. var attributes = {};
  9981. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  9982. for ( var i = 0; i < n; i ++ ) {
  9983. var info = gl.getActiveAttrib( program, i );
  9984. var name = info.name;
  9985. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  9986. attributes[ name ] = gl.getAttribLocation( program, name );
  9987. }
  9988. return attributes;
  9989. }
  9990. function filterEmptyLine( string ) {
  9991. return string !== '';
  9992. }
  9993. function replaceLightNums( string, parameters ) {
  9994. return string
  9995. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  9996. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  9997. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  9998. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  9999. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  10000. }
  10001. function replaceClippingPlaneNums( string, parameters ) {
  10002. return string
  10003. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10004. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10005. }
  10006. function parseIncludes( string ) {
  10007. var pattern = /^[ \t]*#include +<([\w\d.]+)>/gm;
  10008. function replace( match, include ) {
  10009. var replace = ShaderChunk[ include ];
  10010. if ( replace === undefined ) {
  10011. throw new Error( 'Can not resolve #include <' + include + '>' );
  10012. }
  10013. return parseIncludes( replace );
  10014. }
  10015. return string.replace( pattern, replace );
  10016. }
  10017. function unrollLoops( string ) {
  10018. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10019. function replace( match, start, end, snippet ) {
  10020. var unroll = '';
  10021. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10022. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  10023. }
  10024. return unroll;
  10025. }
  10026. return string.replace( pattern, replace );
  10027. }
  10028. function WebGLProgram( renderer, extensions, code, material, shader, parameters ) {
  10029. var gl = renderer.context;
  10030. var defines = material.defines;
  10031. var vertexShader = shader.vertexShader;
  10032. var fragmentShader = shader.fragmentShader;
  10033. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10034. if ( parameters.shadowMapType === PCFShadowMap ) {
  10035. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10036. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10037. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10038. }
  10039. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10040. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10041. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10042. if ( parameters.envMap ) {
  10043. switch ( material.envMap.mapping ) {
  10044. case CubeReflectionMapping:
  10045. case CubeRefractionMapping:
  10046. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10047. break;
  10048. case CubeUVReflectionMapping:
  10049. case CubeUVRefractionMapping:
  10050. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10051. break;
  10052. case EquirectangularReflectionMapping:
  10053. case EquirectangularRefractionMapping:
  10054. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10055. break;
  10056. case SphericalReflectionMapping:
  10057. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10058. break;
  10059. }
  10060. switch ( material.envMap.mapping ) {
  10061. case CubeRefractionMapping:
  10062. case EquirectangularRefractionMapping:
  10063. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10064. break;
  10065. }
  10066. switch ( material.combine ) {
  10067. case MultiplyOperation:
  10068. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10069. break;
  10070. case MixOperation:
  10071. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10072. break;
  10073. case AddOperation:
  10074. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10075. break;
  10076. }
  10077. }
  10078. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10079. // console.log( 'building new program ' );
  10080. //
  10081. var customExtensions = generateExtensions( material.extensions, parameters, extensions );
  10082. var customDefines = generateDefines( defines );
  10083. //
  10084. var program = gl.createProgram();
  10085. var prefixVertex, prefixFragment;
  10086. if ( material.isRawShaderMaterial ) {
  10087. prefixVertex = [
  10088. customDefines
  10089. ].filter( filterEmptyLine ).join( '\n' );
  10090. if ( prefixVertex.length > 0 ) {
  10091. prefixVertex += '\n';
  10092. }
  10093. prefixFragment = [
  10094. customExtensions,
  10095. customDefines
  10096. ].filter( filterEmptyLine ).join( '\n' );
  10097. if ( prefixFragment.length > 0 ) {
  10098. prefixFragment += '\n';
  10099. }
  10100. } else {
  10101. prefixVertex = [
  10102. 'precision ' + parameters.precision + ' float;',
  10103. 'precision ' + parameters.precision + ' int;',
  10104. '#define SHADER_NAME ' + shader.name,
  10105. customDefines,
  10106. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10107. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10108. '#define MAX_BONES ' + parameters.maxBones,
  10109. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10110. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10111. parameters.map ? '#define USE_MAP' : '',
  10112. parameters.envMap ? '#define USE_ENVMAP' : '',
  10113. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10114. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10115. parameters.aoMap ? '#define USE_AOMAP' : '',
  10116. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10117. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10118. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10119. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10120. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10121. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10122. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10123. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10124. parameters.vertexColors ? '#define USE_COLOR' : '',
  10125. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10126. parameters.skinning ? '#define USE_SKINNING' : '',
  10127. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10128. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10129. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10130. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10131. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10132. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10133. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10134. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10135. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10136. parameters.logarithmicDepthBuffer && extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10137. 'uniform mat4 modelMatrix;',
  10138. 'uniform mat4 modelViewMatrix;',
  10139. 'uniform mat4 projectionMatrix;',
  10140. 'uniform mat4 viewMatrix;',
  10141. 'uniform mat3 normalMatrix;',
  10142. 'uniform vec3 cameraPosition;',
  10143. 'attribute vec3 position;',
  10144. 'attribute vec3 normal;',
  10145. 'attribute vec2 uv;',
  10146. '#ifdef USE_COLOR',
  10147. ' attribute vec3 color;',
  10148. '#endif',
  10149. '#ifdef USE_MORPHTARGETS',
  10150. ' attribute vec3 morphTarget0;',
  10151. ' attribute vec3 morphTarget1;',
  10152. ' attribute vec3 morphTarget2;',
  10153. ' attribute vec3 morphTarget3;',
  10154. ' #ifdef USE_MORPHNORMALS',
  10155. ' attribute vec3 morphNormal0;',
  10156. ' attribute vec3 morphNormal1;',
  10157. ' attribute vec3 morphNormal2;',
  10158. ' attribute vec3 morphNormal3;',
  10159. ' #else',
  10160. ' attribute vec3 morphTarget4;',
  10161. ' attribute vec3 morphTarget5;',
  10162. ' attribute vec3 morphTarget6;',
  10163. ' attribute vec3 morphTarget7;',
  10164. ' #endif',
  10165. '#endif',
  10166. '#ifdef USE_SKINNING',
  10167. ' attribute vec4 skinIndex;',
  10168. ' attribute vec4 skinWeight;',
  10169. '#endif',
  10170. '\n'
  10171. ].filter( filterEmptyLine ).join( '\n' );
  10172. prefixFragment = [
  10173. customExtensions,
  10174. 'precision ' + parameters.precision + ' float;',
  10175. 'precision ' + parameters.precision + ' int;',
  10176. '#define SHADER_NAME ' + shader.name,
  10177. customDefines,
  10178. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  10179. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10180. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10181. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10182. parameters.map ? '#define USE_MAP' : '',
  10183. parameters.envMap ? '#define USE_ENVMAP' : '',
  10184. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10185. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10186. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10187. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10188. parameters.aoMap ? '#define USE_AOMAP' : '',
  10189. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10190. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10191. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10192. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10193. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10194. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10195. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10196. parameters.vertexColors ? '#define USE_COLOR' : '',
  10197. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10198. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10199. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10200. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10201. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10202. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10203. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10204. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10205. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10206. parameters.logarithmicDepthBuffer && extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10207. parameters.envMap && extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  10208. 'uniform mat4 viewMatrix;',
  10209. 'uniform vec3 cameraPosition;',
  10210. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10211. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10212. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10213. parameters.dithering ? '#define DITHERING' : '',
  10214. ( parameters.outputEncoding || parameters.mapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ? ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  10215. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10216. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10217. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10218. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  10219. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  10220. '\n'
  10221. ].filter( filterEmptyLine ).join( '\n' );
  10222. }
  10223. vertexShader = parseIncludes( vertexShader );
  10224. vertexShader = replaceLightNums( vertexShader, parameters );
  10225. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10226. fragmentShader = parseIncludes( fragmentShader );
  10227. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10228. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10229. vertexShader = unrollLoops( vertexShader );
  10230. fragmentShader = unrollLoops( fragmentShader );
  10231. var vertexGlsl = prefixVertex + vertexShader;
  10232. var fragmentGlsl = prefixFragment + fragmentShader;
  10233. // console.log( '*VERTEX*', vertexGlsl );
  10234. // console.log( '*FRAGMENT*', fragmentGlsl );
  10235. var glVertexShader = WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  10236. var glFragmentShader = WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  10237. gl.attachShader( program, glVertexShader );
  10238. gl.attachShader( program, glFragmentShader );
  10239. // Force a particular attribute to index 0.
  10240. if ( material.index0AttributeName !== undefined ) {
  10241. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10242. } else if ( parameters.morphTargets === true ) {
  10243. // programs with morphTargets displace position out of attribute 0
  10244. gl.bindAttribLocation( program, 0, 'position' );
  10245. }
  10246. gl.linkProgram( program );
  10247. var programLog = gl.getProgramInfoLog( program ).trim();
  10248. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10249. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10250. var runnable = true;
  10251. var haveDiagnostics = true;
  10252. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  10253. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  10254. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  10255. runnable = false;
  10256. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  10257. } else if ( programLog !== '' ) {
  10258. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10259. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10260. haveDiagnostics = false;
  10261. }
  10262. if ( haveDiagnostics ) {
  10263. this.diagnostics = {
  10264. runnable: runnable,
  10265. material: material,
  10266. programLog: programLog,
  10267. vertexShader: {
  10268. log: vertexLog,
  10269. prefix: prefixVertex
  10270. },
  10271. fragmentShader: {
  10272. log: fragmentLog,
  10273. prefix: prefixFragment
  10274. }
  10275. };
  10276. }
  10277. // clean up
  10278. gl.deleteShader( glVertexShader );
  10279. gl.deleteShader( glFragmentShader );
  10280. // set up caching for uniform locations
  10281. var cachedUniforms;
  10282. this.getUniforms = function () {
  10283. if ( cachedUniforms === undefined ) {
  10284. cachedUniforms = new WebGLUniforms( gl, program, renderer );
  10285. }
  10286. return cachedUniforms;
  10287. };
  10288. // set up caching for attribute locations
  10289. var cachedAttributes;
  10290. this.getAttributes = function () {
  10291. if ( cachedAttributes === undefined ) {
  10292. cachedAttributes = fetchAttributeLocations( gl, program );
  10293. }
  10294. return cachedAttributes;
  10295. };
  10296. // free resource
  10297. this.destroy = function () {
  10298. gl.deleteProgram( program );
  10299. this.program = undefined;
  10300. };
  10301. // DEPRECATED
  10302. Object.defineProperties( this, {
  10303. uniforms: {
  10304. get: function () {
  10305. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  10306. return this.getUniforms();
  10307. }
  10308. },
  10309. attributes: {
  10310. get: function () {
  10311. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  10312. return this.getAttributes();
  10313. }
  10314. }
  10315. } );
  10316. //
  10317. this.id = programIdCount ++;
  10318. this.code = code;
  10319. this.usedTimes = 1;
  10320. this.program = program;
  10321. this.vertexShader = glVertexShader;
  10322. this.fragmentShader = glFragmentShader;
  10323. return this;
  10324. }
  10325. /**
  10326. * @author mrdoob / http://mrdoob.com/
  10327. */
  10328. function WebGLPrograms( renderer, extensions, capabilities ) {
  10329. var programs = [];
  10330. var shaderIDs = {
  10331. MeshDepthMaterial: 'depth',
  10332. MeshDistanceMaterial: 'distanceRGBA',
  10333. MeshNormalMaterial: 'normal',
  10334. MeshBasicMaterial: 'basic',
  10335. MeshLambertMaterial: 'lambert',
  10336. MeshPhongMaterial: 'phong',
  10337. MeshToonMaterial: 'phong',
  10338. MeshStandardMaterial: 'physical',
  10339. MeshPhysicalMaterial: 'physical',
  10340. LineBasicMaterial: 'basic',
  10341. LineDashedMaterial: 'dashed',
  10342. PointsMaterial: 'points',
  10343. ShadowMaterial: 'shadow'
  10344. };
  10345. var parameterNames = [
  10346. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10347. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  10348. "roughnessMap", "metalnessMap", "gradientMap",
  10349. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  10350. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10351. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10352. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10353. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10354. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10355. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10356. ];
  10357. function allocateBones( object ) {
  10358. var skeleton = object.skeleton;
  10359. var bones = skeleton.bones;
  10360. if ( capabilities.floatVertexTextures ) {
  10361. return 1024;
  10362. } else {
  10363. // default for when object is not specified
  10364. // ( for example when prebuilding shader to be used with multiple objects )
  10365. //
  10366. // - leave some extra space for other uniforms
  10367. // - limit here is ANGLE's 254 max uniform vectors
  10368. // (up to 54 should be safe)
  10369. var nVertexUniforms = capabilities.maxVertexUniforms;
  10370. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10371. var maxBones = Math.min( nVertexMatrices, bones.length );
  10372. if ( maxBones < bones.length ) {
  10373. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10374. return 0;
  10375. }
  10376. return maxBones;
  10377. }
  10378. }
  10379. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10380. var encoding;
  10381. if ( ! map ) {
  10382. encoding = LinearEncoding;
  10383. } else if ( map.isTexture ) {
  10384. encoding = map.encoding;
  10385. } else if ( map.isWebGLRenderTarget ) {
  10386. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10387. encoding = map.texture.encoding;
  10388. }
  10389. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10390. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10391. encoding = GammaEncoding;
  10392. }
  10393. return encoding;
  10394. }
  10395. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  10396. var shaderID = shaderIDs[ material.type ];
  10397. // heuristics to create shader parameters according to lights in the scene
  10398. // (not to blow over maxLights budget)
  10399. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10400. var precision = capabilities.precision;
  10401. if ( material.precision !== null ) {
  10402. precision = capabilities.getMaxPrecision( material.precision );
  10403. if ( precision !== material.precision ) {
  10404. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10405. }
  10406. }
  10407. var currentRenderTarget = renderer.getRenderTarget();
  10408. var parameters = {
  10409. shaderID: shaderID,
  10410. precision: precision,
  10411. supportsVertexTextures: capabilities.vertexTextures,
  10412. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  10413. map: !! material.map,
  10414. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  10415. envMap: !! material.envMap,
  10416. envMapMode: material.envMap && material.envMap.mapping,
  10417. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  10418. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  10419. lightMap: !! material.lightMap,
  10420. aoMap: !! material.aoMap,
  10421. emissiveMap: !! material.emissiveMap,
  10422. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  10423. bumpMap: !! material.bumpMap,
  10424. normalMap: !! material.normalMap,
  10425. displacementMap: !! material.displacementMap,
  10426. roughnessMap: !! material.roughnessMap,
  10427. metalnessMap: !! material.metalnessMap,
  10428. specularMap: !! material.specularMap,
  10429. alphaMap: !! material.alphaMap,
  10430. gradientMap: !! material.gradientMap,
  10431. combine: material.combine,
  10432. vertexColors: material.vertexColors,
  10433. fog: !! fog,
  10434. useFog: material.fog,
  10435. fogExp: ( fog && fog.isFogExp2 ),
  10436. flatShading: material.flatShading,
  10437. sizeAttenuation: material.sizeAttenuation,
  10438. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  10439. skinning: material.skinning && maxBones > 0,
  10440. maxBones: maxBones,
  10441. useVertexTexture: capabilities.floatVertexTextures,
  10442. morphTargets: material.morphTargets,
  10443. morphNormals: material.morphNormals,
  10444. maxMorphTargets: renderer.maxMorphTargets,
  10445. maxMorphNormals: renderer.maxMorphNormals,
  10446. numDirLights: lights.directional.length,
  10447. numPointLights: lights.point.length,
  10448. numSpotLights: lights.spot.length,
  10449. numRectAreaLights: lights.rectArea.length,
  10450. numHemiLights: lights.hemi.length,
  10451. numClippingPlanes: nClipPlanes,
  10452. numClipIntersection: nClipIntersection,
  10453. dithering: material.dithering,
  10454. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  10455. shadowMapType: renderer.shadowMap.type,
  10456. toneMapping: renderer.toneMapping,
  10457. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10458. premultipliedAlpha: material.premultipliedAlpha,
  10459. alphaTest: material.alphaTest,
  10460. doubleSided: material.side === DoubleSide,
  10461. flipSided: material.side === BackSide,
  10462. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  10463. };
  10464. return parameters;
  10465. };
  10466. this.getProgramCode = function ( material, parameters ) {
  10467. var array = [];
  10468. if ( parameters.shaderID ) {
  10469. array.push( parameters.shaderID );
  10470. } else {
  10471. array.push( material.fragmentShader );
  10472. array.push( material.vertexShader );
  10473. }
  10474. if ( material.defines !== undefined ) {
  10475. for ( var name in material.defines ) {
  10476. array.push( name );
  10477. array.push( material.defines[ name ] );
  10478. }
  10479. }
  10480. for ( var i = 0; i < parameterNames.length; i ++ ) {
  10481. array.push( parameters[ parameterNames[ i ] ] );
  10482. }
  10483. array.push( material.onBeforeCompile.toString() );
  10484. array.push( renderer.gammaOutput );
  10485. return array.join();
  10486. };
  10487. this.acquireProgram = function ( material, shader, parameters, code ) {
  10488. var program;
  10489. // Check if code has been already compiled
  10490. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  10491. var programInfo = programs[ p ];
  10492. if ( programInfo.code === code ) {
  10493. program = programInfo;
  10494. ++ program.usedTimes;
  10495. break;
  10496. }
  10497. }
  10498. if ( program === undefined ) {
  10499. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters );
  10500. programs.push( program );
  10501. }
  10502. return program;
  10503. };
  10504. this.releaseProgram = function ( program ) {
  10505. if ( -- program.usedTimes === 0 ) {
  10506. // Remove from unordered set
  10507. var i = programs.indexOf( program );
  10508. programs[ i ] = programs[ programs.length - 1 ];
  10509. programs.pop();
  10510. // Free WebGL resources
  10511. program.destroy();
  10512. }
  10513. };
  10514. // Exposed for resource monitoring & error feedback via renderer.info:
  10515. this.programs = programs;
  10516. }
  10517. /**
  10518. * @author mrdoob / http://mrdoob.com/
  10519. */
  10520. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, infoMemory, infoRender ) {
  10521. var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext );
  10522. var _videoTextures = {};
  10523. var _canvas;
  10524. //
  10525. function clampToMaxSize( image, maxSize ) {
  10526. if ( image.width > maxSize || image.height > maxSize ) {
  10527. // Warning: Scaling through the canvas will only work with images that use
  10528. // premultiplied alpha.
  10529. var scale = maxSize / Math.max( image.width, image.height );
  10530. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  10531. canvas.width = Math.floor( image.width * scale );
  10532. canvas.height = Math.floor( image.height * scale );
  10533. var context = canvas.getContext( '2d' );
  10534. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  10535. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  10536. return canvas;
  10537. }
  10538. return image;
  10539. }
  10540. function isPowerOfTwo( image ) {
  10541. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  10542. }
  10543. function makePowerOfTwo( image ) {
  10544. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof ImageBitmap ) {
  10545. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  10546. _canvas.width = _Math.floorPowerOfTwo( image.width );
  10547. _canvas.height = _Math.floorPowerOfTwo( image.height );
  10548. var context = _canvas.getContext( '2d' );
  10549. context.drawImage( image, 0, 0, _canvas.width, _canvas.height );
  10550. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + _canvas.width + 'x' + _canvas.height, image );
  10551. return _canvas;
  10552. }
  10553. return image;
  10554. }
  10555. function textureNeedsPowerOfTwo( texture ) {
  10556. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  10557. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  10558. }
  10559. function textureNeedsGenerateMipmaps( texture, isPowerOfTwo ) {
  10560. return texture.generateMipmaps && isPowerOfTwo &&
  10561. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  10562. }
  10563. // Fallback filters for non-power-of-2 textures
  10564. function filterFallback( f ) {
  10565. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  10566. return _gl.NEAREST;
  10567. }
  10568. return _gl.LINEAR;
  10569. }
  10570. //
  10571. function onTextureDispose( event ) {
  10572. var texture = event.target;
  10573. texture.removeEventListener( 'dispose', onTextureDispose );
  10574. deallocateTexture( texture );
  10575. if ( texture.isVideoTexture ) {
  10576. delete _videoTextures[ texture.id ];
  10577. }
  10578. infoMemory.textures --;
  10579. }
  10580. function onRenderTargetDispose( event ) {
  10581. var renderTarget = event.target;
  10582. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  10583. deallocateRenderTarget( renderTarget );
  10584. infoMemory.textures --;
  10585. }
  10586. //
  10587. function deallocateTexture( texture ) {
  10588. var textureProperties = properties.get( texture );
  10589. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  10590. // cube texture
  10591. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  10592. } else {
  10593. // 2D texture
  10594. if ( textureProperties.__webglInit === undefined ) return;
  10595. _gl.deleteTexture( textureProperties.__webglTexture );
  10596. }
  10597. // remove all webgl properties
  10598. properties.remove( texture );
  10599. }
  10600. function deallocateRenderTarget( renderTarget ) {
  10601. var renderTargetProperties = properties.get( renderTarget );
  10602. var textureProperties = properties.get( renderTarget.texture );
  10603. if ( ! renderTarget ) return;
  10604. if ( textureProperties.__webglTexture !== undefined ) {
  10605. _gl.deleteTexture( textureProperties.__webglTexture );
  10606. }
  10607. if ( renderTarget.depthTexture ) {
  10608. renderTarget.depthTexture.dispose();
  10609. }
  10610. if ( renderTarget.isWebGLRenderTargetCube ) {
  10611. for ( var i = 0; i < 6; i ++ ) {
  10612. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  10613. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  10614. }
  10615. } else {
  10616. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  10617. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  10618. }
  10619. properties.remove( renderTarget.texture );
  10620. properties.remove( renderTarget );
  10621. }
  10622. //
  10623. function setTexture2D( texture, slot ) {
  10624. var textureProperties = properties.get( texture );
  10625. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  10626. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  10627. var image = texture.image;
  10628. if ( image === undefined ) {
  10629. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  10630. } else if ( image.complete === false ) {
  10631. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  10632. } else {
  10633. uploadTexture( textureProperties, texture, slot );
  10634. return;
  10635. }
  10636. }
  10637. state.activeTexture( _gl.TEXTURE0 + slot );
  10638. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  10639. }
  10640. function setTextureCube( texture, slot ) {
  10641. var textureProperties = properties.get( texture );
  10642. if ( texture.image.length === 6 ) {
  10643. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  10644. if ( ! textureProperties.__image__webglTextureCube ) {
  10645. texture.addEventListener( 'dispose', onTextureDispose );
  10646. textureProperties.__image__webglTextureCube = _gl.createTexture();
  10647. infoMemory.textures ++;
  10648. }
  10649. state.activeTexture( _gl.TEXTURE0 + slot );
  10650. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  10651. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  10652. var isCompressed = ( texture && texture.isCompressedTexture );
  10653. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  10654. var cubeImage = [];
  10655. for ( var i = 0; i < 6; i ++ ) {
  10656. if ( ! isCompressed && ! isDataTexture ) {
  10657. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  10658. } else {
  10659. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  10660. }
  10661. }
  10662. var image = cubeImage[ 0 ],
  10663. isPowerOfTwoImage = isPowerOfTwo( image ),
  10664. glFormat = utils.convert( texture.format ),
  10665. glType = utils.convert( texture.type );
  10666. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  10667. for ( var i = 0; i < 6; i ++ ) {
  10668. if ( ! isCompressed ) {
  10669. if ( isDataTexture ) {
  10670. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  10671. } else {
  10672. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  10673. }
  10674. } else {
  10675. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  10676. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  10677. mipmap = mipmaps[ j ];
  10678. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  10679. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  10680. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  10681. } else {
  10682. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  10683. }
  10684. } else {
  10685. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  10686. }
  10687. }
  10688. }
  10689. }
  10690. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
  10691. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  10692. }
  10693. textureProperties.__version = texture.version;
  10694. if ( texture.onUpdate ) texture.onUpdate( texture );
  10695. } else {
  10696. state.activeTexture( _gl.TEXTURE0 + slot );
  10697. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  10698. }
  10699. }
  10700. }
  10701. function setTextureCubeDynamic( texture, slot ) {
  10702. state.activeTexture( _gl.TEXTURE0 + slot );
  10703. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  10704. }
  10705. function setTextureParameters( textureType, texture, isPowerOfTwoImage ) {
  10706. var extension;
  10707. if ( isPowerOfTwoImage ) {
  10708. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, utils.convert( texture.wrapS ) );
  10709. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, utils.convert( texture.wrapT ) );
  10710. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, utils.convert( texture.magFilter ) );
  10711. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, utils.convert( texture.minFilter ) );
  10712. } else {
  10713. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  10714. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  10715. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  10716. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  10717. }
  10718. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  10719. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  10720. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  10721. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  10722. }
  10723. }
  10724. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  10725. if ( extension ) {
  10726. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  10727. if ( texture.type === HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  10728. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  10729. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  10730. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  10731. }
  10732. }
  10733. }
  10734. function uploadTexture( textureProperties, texture, slot ) {
  10735. if ( textureProperties.__webglInit === undefined ) {
  10736. textureProperties.__webglInit = true;
  10737. texture.addEventListener( 'dispose', onTextureDispose );
  10738. textureProperties.__webglTexture = _gl.createTexture();
  10739. infoMemory.textures ++;
  10740. }
  10741. state.activeTexture( _gl.TEXTURE0 + slot );
  10742. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  10743. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  10744. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  10745. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  10746. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  10747. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  10748. image = makePowerOfTwo( image );
  10749. }
  10750. var isPowerOfTwoImage = isPowerOfTwo( image ),
  10751. glFormat = utils.convert( texture.format ),
  10752. glType = utils.convert( texture.type );
  10753. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  10754. var mipmap, mipmaps = texture.mipmaps;
  10755. if ( texture.isDepthTexture ) {
  10756. // populate depth texture with dummy data
  10757. var internalFormat = _gl.DEPTH_COMPONENT;
  10758. if ( texture.type === FloatType ) {
  10759. if ( ! _isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  10760. internalFormat = _gl.DEPTH_COMPONENT32F;
  10761. } else if ( _isWebGL2 ) {
  10762. // WebGL 2.0 requires signed internalformat for glTexImage2D
  10763. internalFormat = _gl.DEPTH_COMPONENT16;
  10764. }
  10765. if ( texture.format === DepthFormat && internalFormat === _gl.DEPTH_COMPONENT ) {
  10766. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  10767. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  10768. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  10769. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  10770. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  10771. texture.type = UnsignedShortType;
  10772. glType = utils.convert( texture.type );
  10773. }
  10774. }
  10775. // Depth stencil textures need the DEPTH_STENCIL internal format
  10776. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  10777. if ( texture.format === DepthStencilFormat ) {
  10778. internalFormat = _gl.DEPTH_STENCIL;
  10779. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  10780. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  10781. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  10782. if ( texture.type !== UnsignedInt248Type ) {
  10783. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  10784. texture.type = UnsignedInt248Type;
  10785. glType = utils.convert( texture.type );
  10786. }
  10787. }
  10788. state.texImage2D( _gl.TEXTURE_2D, 0, internalFormat, image.width, image.height, 0, glFormat, glType, null );
  10789. } else if ( texture.isDataTexture ) {
  10790. // use manually created mipmaps if available
  10791. // if there are no manual mipmaps
  10792. // set 0 level mipmap and then use GL to generate other mipmap levels
  10793. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  10794. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  10795. mipmap = mipmaps[ i ];
  10796. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  10797. }
  10798. texture.generateMipmaps = false;
  10799. } else {
  10800. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  10801. }
  10802. } else if ( texture.isCompressedTexture ) {
  10803. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  10804. mipmap = mipmaps[ i ];
  10805. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  10806. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  10807. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  10808. } else {
  10809. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  10810. }
  10811. } else {
  10812. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  10813. }
  10814. }
  10815. } else {
  10816. // regular Texture (image, video, canvas)
  10817. // use manually created mipmaps if available
  10818. // if there are no manual mipmaps
  10819. // set 0 level mipmap and then use GL to generate other mipmap levels
  10820. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  10821. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  10822. mipmap = mipmaps[ i ];
  10823. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  10824. }
  10825. texture.generateMipmaps = false;
  10826. } else {
  10827. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  10828. }
  10829. }
  10830. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) _gl.generateMipmap( _gl.TEXTURE_2D );
  10831. textureProperties.__version = texture.version;
  10832. if ( texture.onUpdate ) texture.onUpdate( texture );
  10833. }
  10834. // Render targets
  10835. // Setup storage for target texture and bind it to correct framebuffer
  10836. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  10837. var glFormat = utils.convert( renderTarget.texture.format );
  10838. var glType = utils.convert( renderTarget.texture.type );
  10839. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  10840. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  10841. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  10842. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  10843. }
  10844. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  10845. function setupRenderBufferStorage( renderbuffer, renderTarget ) {
  10846. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  10847. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  10848. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  10849. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  10850. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  10851. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  10852. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  10853. } else {
  10854. // FIXME: We don't support !depth !stencil
  10855. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  10856. }
  10857. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  10858. }
  10859. // Setup resources for a Depth Texture for a FBO (needs an extension)
  10860. function setupDepthTexture( framebuffer, renderTarget ) {
  10861. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  10862. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  10863. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  10864. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  10865. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  10866. }
  10867. // upload an empty depth texture with framebuffer size
  10868. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  10869. renderTarget.depthTexture.image.width !== renderTarget.width ||
  10870. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  10871. renderTarget.depthTexture.image.width = renderTarget.width;
  10872. renderTarget.depthTexture.image.height = renderTarget.height;
  10873. renderTarget.depthTexture.needsUpdate = true;
  10874. }
  10875. setTexture2D( renderTarget.depthTexture, 0 );
  10876. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  10877. if ( renderTarget.depthTexture.format === DepthFormat ) {
  10878. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  10879. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  10880. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  10881. } else {
  10882. throw new Error( 'Unknown depthTexture format' );
  10883. }
  10884. }
  10885. // Setup GL resources for a non-texture depth buffer
  10886. function setupDepthRenderbuffer( renderTarget ) {
  10887. var renderTargetProperties = properties.get( renderTarget );
  10888. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  10889. if ( renderTarget.depthTexture ) {
  10890. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  10891. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  10892. } else {
  10893. if ( isCube ) {
  10894. renderTargetProperties.__webglDepthbuffer = [];
  10895. for ( var i = 0; i < 6; i ++ ) {
  10896. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  10897. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  10898. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  10899. }
  10900. } else {
  10901. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  10902. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  10903. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  10904. }
  10905. }
  10906. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  10907. }
  10908. // Set up GL resources for the render target
  10909. function setupRenderTarget( renderTarget ) {
  10910. var renderTargetProperties = properties.get( renderTarget );
  10911. var textureProperties = properties.get( renderTarget.texture );
  10912. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  10913. textureProperties.__webglTexture = _gl.createTexture();
  10914. infoMemory.textures ++;
  10915. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  10916. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  10917. // Setup framebuffer
  10918. if ( isCube ) {
  10919. renderTargetProperties.__webglFramebuffer = [];
  10920. for ( var i = 0; i < 6; i ++ ) {
  10921. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  10922. }
  10923. } else {
  10924. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  10925. }
  10926. // Setup color buffer
  10927. if ( isCube ) {
  10928. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  10929. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  10930. for ( var i = 0; i < 6; i ++ ) {
  10931. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  10932. }
  10933. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  10934. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  10935. } else {
  10936. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  10937. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  10938. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  10939. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) _gl.generateMipmap( _gl.TEXTURE_2D );
  10940. state.bindTexture( _gl.TEXTURE_2D, null );
  10941. }
  10942. // Setup depth and stencil buffers
  10943. if ( renderTarget.depthBuffer ) {
  10944. setupDepthRenderbuffer( renderTarget );
  10945. }
  10946. }
  10947. function updateRenderTargetMipmap( renderTarget ) {
  10948. var texture = renderTarget.texture;
  10949. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  10950. if ( textureNeedsGenerateMipmaps( texture, isTargetPowerOfTwo ) ) {
  10951. var target = renderTarget.isWebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  10952. var webglTexture = properties.get( texture ).__webglTexture;
  10953. state.bindTexture( target, webglTexture );
  10954. _gl.generateMipmap( target );
  10955. state.bindTexture( target, null );
  10956. }
  10957. }
  10958. function updateVideoTexture( texture ) {
  10959. var id = texture.id;
  10960. var frame = infoRender.frame;
  10961. // Check the last frame we updated the VideoTexture
  10962. if ( _videoTextures[ id ] !== frame ) {
  10963. _videoTextures[ id ] = frame;
  10964. texture.update();
  10965. }
  10966. }
  10967. this.setTexture2D = setTexture2D;
  10968. this.setTextureCube = setTextureCube;
  10969. this.setTextureCubeDynamic = setTextureCubeDynamic;
  10970. this.setupRenderTarget = setupRenderTarget;
  10971. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  10972. }
  10973. /**
  10974. * @author fordacious / fordacious.github.io
  10975. */
  10976. function WebGLProperties() {
  10977. var properties = {};
  10978. function get( object ) {
  10979. var uuid = object.uuid;
  10980. var map = properties[ uuid ];
  10981. if ( map === undefined ) {
  10982. map = {};
  10983. properties[ uuid ] = map;
  10984. }
  10985. return map;
  10986. }
  10987. function remove( object ) {
  10988. delete properties[ object.uuid ];
  10989. }
  10990. function update( object, key, value ) {
  10991. var uuid = object.uuid;
  10992. var map = properties[ uuid ];
  10993. map[ key ] = value;
  10994. }
  10995. function dispose() {
  10996. properties = {};
  10997. }
  10998. return {
  10999. get: get,
  11000. remove: remove,
  11001. update: update,
  11002. dispose: dispose
  11003. };
  11004. }
  11005. /**
  11006. * @author mrdoob / http://mrdoob.com/
  11007. */
  11008. function WebGLState( gl, extensions, utils ) {
  11009. function ColorBuffer() {
  11010. var locked = false;
  11011. var color = new Vector4();
  11012. var currentColorMask = null;
  11013. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  11014. return {
  11015. setMask: function ( colorMask ) {
  11016. if ( currentColorMask !== colorMask && ! locked ) {
  11017. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11018. currentColorMask = colorMask;
  11019. }
  11020. },
  11021. setLocked: function ( lock ) {
  11022. locked = lock;
  11023. },
  11024. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11025. if ( premultipliedAlpha === true ) {
  11026. r *= a; g *= a; b *= a;
  11027. }
  11028. color.set( r, g, b, a );
  11029. if ( currentColorClear.equals( color ) === false ) {
  11030. gl.clearColor( r, g, b, a );
  11031. currentColorClear.copy( color );
  11032. }
  11033. },
  11034. reset: function () {
  11035. locked = false;
  11036. currentColorMask = null;
  11037. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11038. }
  11039. };
  11040. }
  11041. function DepthBuffer() {
  11042. var locked = false;
  11043. var currentDepthMask = null;
  11044. var currentDepthFunc = null;
  11045. var currentDepthClear = null;
  11046. return {
  11047. setTest: function ( depthTest ) {
  11048. if ( depthTest ) {
  11049. enable( gl.DEPTH_TEST );
  11050. } else {
  11051. disable( gl.DEPTH_TEST );
  11052. }
  11053. },
  11054. setMask: function ( depthMask ) {
  11055. if ( currentDepthMask !== depthMask && ! locked ) {
  11056. gl.depthMask( depthMask );
  11057. currentDepthMask = depthMask;
  11058. }
  11059. },
  11060. setFunc: function ( depthFunc ) {
  11061. if ( currentDepthFunc !== depthFunc ) {
  11062. if ( depthFunc ) {
  11063. switch ( depthFunc ) {
  11064. case NeverDepth:
  11065. gl.depthFunc( gl.NEVER );
  11066. break;
  11067. case AlwaysDepth:
  11068. gl.depthFunc( gl.ALWAYS );
  11069. break;
  11070. case LessDepth:
  11071. gl.depthFunc( gl.LESS );
  11072. break;
  11073. case LessEqualDepth:
  11074. gl.depthFunc( gl.LEQUAL );
  11075. break;
  11076. case EqualDepth:
  11077. gl.depthFunc( gl.EQUAL );
  11078. break;
  11079. case GreaterEqualDepth:
  11080. gl.depthFunc( gl.GEQUAL );
  11081. break;
  11082. case GreaterDepth:
  11083. gl.depthFunc( gl.GREATER );
  11084. break;
  11085. case NotEqualDepth:
  11086. gl.depthFunc( gl.NOTEQUAL );
  11087. break;
  11088. default:
  11089. gl.depthFunc( gl.LEQUAL );
  11090. }
  11091. } else {
  11092. gl.depthFunc( gl.LEQUAL );
  11093. }
  11094. currentDepthFunc = depthFunc;
  11095. }
  11096. },
  11097. setLocked: function ( lock ) {
  11098. locked = lock;
  11099. },
  11100. setClear: function ( depth ) {
  11101. if ( currentDepthClear !== depth ) {
  11102. gl.clearDepth( depth );
  11103. currentDepthClear = depth;
  11104. }
  11105. },
  11106. reset: function () {
  11107. locked = false;
  11108. currentDepthMask = null;
  11109. currentDepthFunc = null;
  11110. currentDepthClear = null;
  11111. }
  11112. };
  11113. }
  11114. function StencilBuffer() {
  11115. var locked = false;
  11116. var currentStencilMask = null;
  11117. var currentStencilFunc = null;
  11118. var currentStencilRef = null;
  11119. var currentStencilFuncMask = null;
  11120. var currentStencilFail = null;
  11121. var currentStencilZFail = null;
  11122. var currentStencilZPass = null;
  11123. var currentStencilClear = null;
  11124. return {
  11125. setTest: function ( stencilTest ) {
  11126. if ( stencilTest ) {
  11127. enable( gl.STENCIL_TEST );
  11128. } else {
  11129. disable( gl.STENCIL_TEST );
  11130. }
  11131. },
  11132. setMask: function ( stencilMask ) {
  11133. if ( currentStencilMask !== stencilMask && ! locked ) {
  11134. gl.stencilMask( stencilMask );
  11135. currentStencilMask = stencilMask;
  11136. }
  11137. },
  11138. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11139. if ( currentStencilFunc !== stencilFunc ||
  11140. currentStencilRef !== stencilRef ||
  11141. currentStencilFuncMask !== stencilMask ) {
  11142. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11143. currentStencilFunc = stencilFunc;
  11144. currentStencilRef = stencilRef;
  11145. currentStencilFuncMask = stencilMask;
  11146. }
  11147. },
  11148. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11149. if ( currentStencilFail !== stencilFail ||
  11150. currentStencilZFail !== stencilZFail ||
  11151. currentStencilZPass !== stencilZPass ) {
  11152. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11153. currentStencilFail = stencilFail;
  11154. currentStencilZFail = stencilZFail;
  11155. currentStencilZPass = stencilZPass;
  11156. }
  11157. },
  11158. setLocked: function ( lock ) {
  11159. locked = lock;
  11160. },
  11161. setClear: function ( stencil ) {
  11162. if ( currentStencilClear !== stencil ) {
  11163. gl.clearStencil( stencil );
  11164. currentStencilClear = stencil;
  11165. }
  11166. },
  11167. reset: function () {
  11168. locked = false;
  11169. currentStencilMask = null;
  11170. currentStencilFunc = null;
  11171. currentStencilRef = null;
  11172. currentStencilFuncMask = null;
  11173. currentStencilFail = null;
  11174. currentStencilZFail = null;
  11175. currentStencilZPass = null;
  11176. currentStencilClear = null;
  11177. }
  11178. };
  11179. }
  11180. //
  11181. var colorBuffer = new ColorBuffer();
  11182. var depthBuffer = new DepthBuffer();
  11183. var stencilBuffer = new StencilBuffer();
  11184. var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  11185. var newAttributes = new Uint8Array( maxVertexAttributes );
  11186. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  11187. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  11188. var capabilities = {};
  11189. var compressedTextureFormats = null;
  11190. var currentProgram = null;
  11191. var currentBlending = null;
  11192. var currentBlendEquation = null;
  11193. var currentBlendSrc = null;
  11194. var currentBlendDst = null;
  11195. var currentBlendEquationAlpha = null;
  11196. var currentBlendSrcAlpha = null;
  11197. var currentBlendDstAlpha = null;
  11198. var currentPremultipledAlpha = false;
  11199. var currentFlipSided = null;
  11200. var currentCullFace = null;
  11201. var currentLineWidth = null;
  11202. var currentPolygonOffsetFactor = null;
  11203. var currentPolygonOffsetUnits = null;
  11204. var maxTextures = gl.getParameter( gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS );
  11205. var lineWidthAvailable = false;
  11206. var version = 0;
  11207. var glVersion = gl.getParameter( gl.VERSION );
  11208. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  11209. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  11210. lineWidthAvailable = ( version >= 1.0 );
  11211. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  11212. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  11213. lineWidthAvailable = ( version >= 2.0 );
  11214. }
  11215. var currentTextureSlot = null;
  11216. var currentBoundTextures = {};
  11217. var currentScissor = new Vector4();
  11218. var currentViewport = new Vector4();
  11219. function createTexture( type, target, count ) {
  11220. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11221. var texture = gl.createTexture();
  11222. gl.bindTexture( type, texture );
  11223. gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  11224. gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  11225. for ( var i = 0; i < count; i ++ ) {
  11226. gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
  11227. }
  11228. return texture;
  11229. }
  11230. var emptyTextures = {};
  11231. emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
  11232. emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
  11233. // init
  11234. colorBuffer.setClear( 0, 0, 0, 1 );
  11235. depthBuffer.setClear( 1 );
  11236. stencilBuffer.setClear( 0 );
  11237. enable( gl.DEPTH_TEST );
  11238. depthBuffer.setFunc( LessEqualDepth );
  11239. setFlipSided( false );
  11240. setCullFace( CullFaceBack );
  11241. enable( gl.CULL_FACE );
  11242. enable( gl.BLEND );
  11243. setBlending( NormalBlending );
  11244. //
  11245. function initAttributes() {
  11246. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  11247. newAttributes[ i ] = 0;
  11248. }
  11249. }
  11250. function enableAttribute( attribute ) {
  11251. newAttributes[ attribute ] = 1;
  11252. if ( enabledAttributes[ attribute ] === 0 ) {
  11253. gl.enableVertexAttribArray( attribute );
  11254. enabledAttributes[ attribute ] = 1;
  11255. }
  11256. if ( attributeDivisors[ attribute ] !== 0 ) {
  11257. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  11258. extension.vertexAttribDivisorANGLE( attribute, 0 );
  11259. attributeDivisors[ attribute ] = 0;
  11260. }
  11261. }
  11262. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  11263. newAttributes[ attribute ] = 1;
  11264. if ( enabledAttributes[ attribute ] === 0 ) {
  11265. gl.enableVertexAttribArray( attribute );
  11266. enabledAttributes[ attribute ] = 1;
  11267. }
  11268. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  11269. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  11270. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  11271. attributeDivisors[ attribute ] = meshPerAttribute;
  11272. }
  11273. }
  11274. function disableUnusedAttributes() {
  11275. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  11276. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  11277. gl.disableVertexAttribArray( i );
  11278. enabledAttributes[ i ] = 0;
  11279. }
  11280. }
  11281. }
  11282. function enable( id ) {
  11283. if ( capabilities[ id ] !== true ) {
  11284. gl.enable( id );
  11285. capabilities[ id ] = true;
  11286. }
  11287. }
  11288. function disable( id ) {
  11289. if ( capabilities[ id ] !== false ) {
  11290. gl.disable( id );
  11291. capabilities[ id ] = false;
  11292. }
  11293. }
  11294. function getCompressedTextureFormats() {
  11295. if ( compressedTextureFormats === null ) {
  11296. compressedTextureFormats = [];
  11297. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  11298. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  11299. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  11300. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  11301. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  11302. for ( var i = 0; i < formats.length; i ++ ) {
  11303. compressedTextureFormats.push( formats[ i ] );
  11304. }
  11305. }
  11306. }
  11307. return compressedTextureFormats;
  11308. }
  11309. function useProgram( program ) {
  11310. if ( currentProgram !== program ) {
  11311. gl.useProgram( program );
  11312. currentProgram = program;
  11313. return true;
  11314. }
  11315. return false;
  11316. }
  11317. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11318. if ( blending !== NoBlending ) {
  11319. enable( gl.BLEND );
  11320. } else {
  11321. disable( gl.BLEND );
  11322. }
  11323. if ( blending !== CustomBlending ) {
  11324. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  11325. switch ( blending ) {
  11326. case AdditiveBlending:
  11327. if ( premultipliedAlpha ) {
  11328. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11329. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  11330. } else {
  11331. gl.blendEquation( gl.FUNC_ADD );
  11332. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  11333. }
  11334. break;
  11335. case SubtractiveBlending:
  11336. if ( premultipliedAlpha ) {
  11337. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11338. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  11339. } else {
  11340. gl.blendEquation( gl.FUNC_ADD );
  11341. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  11342. }
  11343. break;
  11344. case MultiplyBlending:
  11345. if ( premultipliedAlpha ) {
  11346. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11347. gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
  11348. } else {
  11349. gl.blendEquation( gl.FUNC_ADD );
  11350. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  11351. }
  11352. break;
  11353. default:
  11354. if ( premultipliedAlpha ) {
  11355. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11356. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  11357. } else {
  11358. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11359. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  11360. }
  11361. }
  11362. }
  11363. currentBlendEquation = null;
  11364. currentBlendSrc = null;
  11365. currentBlendDst = null;
  11366. currentBlendEquationAlpha = null;
  11367. currentBlendSrcAlpha = null;
  11368. currentBlendDstAlpha = null;
  11369. } else {
  11370. blendEquationAlpha = blendEquationAlpha || blendEquation;
  11371. blendSrcAlpha = blendSrcAlpha || blendSrc;
  11372. blendDstAlpha = blendDstAlpha || blendDst;
  11373. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  11374. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  11375. currentBlendEquation = blendEquation;
  11376. currentBlendEquationAlpha = blendEquationAlpha;
  11377. }
  11378. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  11379. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  11380. currentBlendSrc = blendSrc;
  11381. currentBlendDst = blendDst;
  11382. currentBlendSrcAlpha = blendSrcAlpha;
  11383. currentBlendDstAlpha = blendDstAlpha;
  11384. }
  11385. }
  11386. currentBlending = blending;
  11387. currentPremultipledAlpha = premultipliedAlpha;
  11388. }
  11389. function setMaterial( material, frontFaceCW ) {
  11390. material.side === DoubleSide
  11391. ? disable( gl.CULL_FACE )
  11392. : enable( gl.CULL_FACE );
  11393. var flipSided = ( material.side === BackSide );
  11394. if ( frontFaceCW ) flipSided = ! flipSided;
  11395. setFlipSided( flipSided );
  11396. material.transparent === true
  11397. ? setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha )
  11398. : setBlending( NoBlending );
  11399. depthBuffer.setFunc( material.depthFunc );
  11400. depthBuffer.setTest( material.depthTest );
  11401. depthBuffer.setMask( material.depthWrite );
  11402. colorBuffer.setMask( material.colorWrite );
  11403. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  11404. }
  11405. //
  11406. function setFlipSided( flipSided ) {
  11407. if ( currentFlipSided !== flipSided ) {
  11408. if ( flipSided ) {
  11409. gl.frontFace( gl.CW );
  11410. } else {
  11411. gl.frontFace( gl.CCW );
  11412. }
  11413. currentFlipSided = flipSided;
  11414. }
  11415. }
  11416. function setCullFace( cullFace ) {
  11417. if ( cullFace !== CullFaceNone ) {
  11418. enable( gl.CULL_FACE );
  11419. if ( cullFace !== currentCullFace ) {
  11420. if ( cullFace === CullFaceBack ) {
  11421. gl.cullFace( gl.BACK );
  11422. } else if ( cullFace === CullFaceFront ) {
  11423. gl.cullFace( gl.FRONT );
  11424. } else {
  11425. gl.cullFace( gl.FRONT_AND_BACK );
  11426. }
  11427. }
  11428. } else {
  11429. disable( gl.CULL_FACE );
  11430. }
  11431. currentCullFace = cullFace;
  11432. }
  11433. function setLineWidth( width ) {
  11434. if ( width !== currentLineWidth ) {
  11435. if ( lineWidthAvailable ) gl.lineWidth( width );
  11436. currentLineWidth = width;
  11437. }
  11438. }
  11439. function setPolygonOffset( polygonOffset, factor, units ) {
  11440. if ( polygonOffset ) {
  11441. enable( gl.POLYGON_OFFSET_FILL );
  11442. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  11443. gl.polygonOffset( factor, units );
  11444. currentPolygonOffsetFactor = factor;
  11445. currentPolygonOffsetUnits = units;
  11446. }
  11447. } else {
  11448. disable( gl.POLYGON_OFFSET_FILL );
  11449. }
  11450. }
  11451. function setScissorTest( scissorTest ) {
  11452. if ( scissorTest ) {
  11453. enable( gl.SCISSOR_TEST );
  11454. } else {
  11455. disable( gl.SCISSOR_TEST );
  11456. }
  11457. }
  11458. // texture
  11459. function activeTexture( webglSlot ) {
  11460. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  11461. if ( currentTextureSlot !== webglSlot ) {
  11462. gl.activeTexture( webglSlot );
  11463. currentTextureSlot = webglSlot;
  11464. }
  11465. }
  11466. function bindTexture( webglType, webglTexture ) {
  11467. if ( currentTextureSlot === null ) {
  11468. activeTexture();
  11469. }
  11470. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  11471. if ( boundTexture === undefined ) {
  11472. boundTexture = { type: undefined, texture: undefined };
  11473. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  11474. }
  11475. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  11476. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  11477. boundTexture.type = webglType;
  11478. boundTexture.texture = webglTexture;
  11479. }
  11480. }
  11481. function compressedTexImage2D() {
  11482. try {
  11483. gl.compressedTexImage2D.apply( gl, arguments );
  11484. } catch ( error ) {
  11485. console.error( 'THREE.WebGLState:', error );
  11486. }
  11487. }
  11488. function texImage2D() {
  11489. try {
  11490. gl.texImage2D.apply( gl, arguments );
  11491. } catch ( error ) {
  11492. console.error( 'THREE.WebGLState:', error );
  11493. }
  11494. }
  11495. //
  11496. function scissor( scissor ) {
  11497. if ( currentScissor.equals( scissor ) === false ) {
  11498. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  11499. currentScissor.copy( scissor );
  11500. }
  11501. }
  11502. function viewport( viewport ) {
  11503. if ( currentViewport.equals( viewport ) === false ) {
  11504. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  11505. currentViewport.copy( viewport );
  11506. }
  11507. }
  11508. //
  11509. function reset() {
  11510. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  11511. if ( enabledAttributes[ i ] === 1 ) {
  11512. gl.disableVertexAttribArray( i );
  11513. enabledAttributes[ i ] = 0;
  11514. }
  11515. }
  11516. capabilities = {};
  11517. compressedTextureFormats = null;
  11518. currentTextureSlot = null;
  11519. currentBoundTextures = {};
  11520. currentProgram = null;
  11521. currentBlending = null;
  11522. currentFlipSided = null;
  11523. currentCullFace = null;
  11524. colorBuffer.reset();
  11525. depthBuffer.reset();
  11526. stencilBuffer.reset();
  11527. }
  11528. return {
  11529. buffers: {
  11530. color: colorBuffer,
  11531. depth: depthBuffer,
  11532. stencil: stencilBuffer
  11533. },
  11534. initAttributes: initAttributes,
  11535. enableAttribute: enableAttribute,
  11536. enableAttributeAndDivisor: enableAttributeAndDivisor,
  11537. disableUnusedAttributes: disableUnusedAttributes,
  11538. enable: enable,
  11539. disable: disable,
  11540. getCompressedTextureFormats: getCompressedTextureFormats,
  11541. useProgram: useProgram,
  11542. setBlending: setBlending,
  11543. setMaterial: setMaterial,
  11544. setFlipSided: setFlipSided,
  11545. setCullFace: setCullFace,
  11546. setLineWidth: setLineWidth,
  11547. setPolygonOffset: setPolygonOffset,
  11548. setScissorTest: setScissorTest,
  11549. activeTexture: activeTexture,
  11550. bindTexture: bindTexture,
  11551. compressedTexImage2D: compressedTexImage2D,
  11552. texImage2D: texImage2D,
  11553. scissor: scissor,
  11554. viewport: viewport,
  11555. reset: reset
  11556. };
  11557. }
  11558. /**
  11559. * @author mrdoob / http://mrdoob.com/
  11560. */
  11561. function WebGLCapabilities( gl, extensions, parameters ) {
  11562. var maxAnisotropy;
  11563. function getMaxAnisotropy() {
  11564. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  11565. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  11566. if ( extension !== null ) {
  11567. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  11568. } else {
  11569. maxAnisotropy = 0;
  11570. }
  11571. return maxAnisotropy;
  11572. }
  11573. function getMaxPrecision( precision ) {
  11574. if ( precision === 'highp' ) {
  11575. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  11576. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  11577. return 'highp';
  11578. }
  11579. precision = 'mediump';
  11580. }
  11581. if ( precision === 'mediump' ) {
  11582. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  11583. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  11584. return 'mediump';
  11585. }
  11586. }
  11587. return 'lowp';
  11588. }
  11589. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  11590. var maxPrecision = getMaxPrecision( precision );
  11591. if ( maxPrecision !== precision ) {
  11592. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  11593. precision = maxPrecision;
  11594. }
  11595. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  11596. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  11597. var maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  11598. var maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  11599. var maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  11600. var maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  11601. var maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  11602. var maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  11603. var maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  11604. var vertexTextures = maxVertexTextures > 0;
  11605. var floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  11606. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  11607. return {
  11608. getMaxAnisotropy: getMaxAnisotropy,
  11609. getMaxPrecision: getMaxPrecision,
  11610. precision: precision,
  11611. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11612. maxTextures: maxTextures,
  11613. maxVertexTextures: maxVertexTextures,
  11614. maxTextureSize: maxTextureSize,
  11615. maxCubemapSize: maxCubemapSize,
  11616. maxAttributes: maxAttributes,
  11617. maxVertexUniforms: maxVertexUniforms,
  11618. maxVaryings: maxVaryings,
  11619. maxFragmentUniforms: maxFragmentUniforms,
  11620. vertexTextures: vertexTextures,
  11621. floatFragmentTextures: floatFragmentTextures,
  11622. floatVertexTextures: floatVertexTextures
  11623. };
  11624. }
  11625. /**
  11626. * @author mrdoob / http://mrdoob.com/
  11627. * @author greggman / http://games.greggman.com/
  11628. * @author zz85 / http://www.lab4games.net/zz85/blog
  11629. * @author tschw
  11630. */
  11631. function PerspectiveCamera( fov, aspect, near, far ) {
  11632. Camera.call( this );
  11633. this.type = 'PerspectiveCamera';
  11634. this.fov = fov !== undefined ? fov : 50;
  11635. this.zoom = 1;
  11636. this.near = near !== undefined ? near : 0.1;
  11637. this.far = far !== undefined ? far : 2000;
  11638. this.focus = 10;
  11639. this.aspect = aspect !== undefined ? aspect : 1;
  11640. this.view = null;
  11641. this.filmGauge = 35; // width of the film (default in millimeters)
  11642. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  11643. this.updateProjectionMatrix();
  11644. }
  11645. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  11646. constructor: PerspectiveCamera,
  11647. isPerspectiveCamera: true,
  11648. copy: function ( source, recursive ) {
  11649. Camera.prototype.copy.call( this, source, recursive );
  11650. this.fov = source.fov;
  11651. this.zoom = source.zoom;
  11652. this.near = source.near;
  11653. this.far = source.far;
  11654. this.focus = source.focus;
  11655. this.aspect = source.aspect;
  11656. this.view = source.view === null ? null : Object.assign( {}, source.view );
  11657. this.filmGauge = source.filmGauge;
  11658. this.filmOffset = source.filmOffset;
  11659. return this;
  11660. },
  11661. /**
  11662. * Sets the FOV by focal length in respect to the current .filmGauge.
  11663. *
  11664. * The default film gauge is 35, so that the focal length can be specified for
  11665. * a 35mm (full frame) camera.
  11666. *
  11667. * Values for focal length and film gauge must have the same unit.
  11668. */
  11669. setFocalLength: function ( focalLength ) {
  11670. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  11671. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  11672. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  11673. this.updateProjectionMatrix();
  11674. },
  11675. /**
  11676. * Calculates the focal length from the current .fov and .filmGauge.
  11677. */
  11678. getFocalLength: function () {
  11679. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  11680. return 0.5 * this.getFilmHeight() / vExtentSlope;
  11681. },
  11682. getEffectiveFOV: function () {
  11683. return _Math.RAD2DEG * 2 * Math.atan(
  11684. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  11685. },
  11686. getFilmWidth: function () {
  11687. // film not completely covered in portrait format (aspect < 1)
  11688. return this.filmGauge * Math.min( this.aspect, 1 );
  11689. },
  11690. getFilmHeight: function () {
  11691. // film not completely covered in landscape format (aspect > 1)
  11692. return this.filmGauge / Math.max( this.aspect, 1 );
  11693. },
  11694. /**
  11695. * Sets an offset in a larger frustum. This is useful for multi-window or
  11696. * multi-monitor/multi-machine setups.
  11697. *
  11698. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  11699. * the monitors are in grid like this
  11700. *
  11701. * +---+---+---+
  11702. * | A | B | C |
  11703. * +---+---+---+
  11704. * | D | E | F |
  11705. * +---+---+---+
  11706. *
  11707. * then for each monitor you would call it like this
  11708. *
  11709. * var w = 1920;
  11710. * var h = 1080;
  11711. * var fullWidth = w * 3;
  11712. * var fullHeight = h * 2;
  11713. *
  11714. * --A--
  11715. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  11716. * --B--
  11717. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  11718. * --C--
  11719. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  11720. * --D--
  11721. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  11722. * --E--
  11723. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  11724. * --F--
  11725. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  11726. *
  11727. * Note there is no reason monitors have to be the same size or in a grid.
  11728. */
  11729. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  11730. this.aspect = fullWidth / fullHeight;
  11731. if ( this.view === null ) {
  11732. this.view = {
  11733. enabled: true,
  11734. fullWidth: 1,
  11735. fullHeight: 1,
  11736. offsetX: 0,
  11737. offsetY: 0,
  11738. width: 1,
  11739. height: 1
  11740. };
  11741. }
  11742. this.view.enabled = true;
  11743. this.view.fullWidth = fullWidth;
  11744. this.view.fullHeight = fullHeight;
  11745. this.view.offsetX = x;
  11746. this.view.offsetY = y;
  11747. this.view.width = width;
  11748. this.view.height = height;
  11749. this.updateProjectionMatrix();
  11750. },
  11751. clearViewOffset: function () {
  11752. if ( this.view !== null ) {
  11753. this.view.enabled = false;
  11754. }
  11755. this.updateProjectionMatrix();
  11756. },
  11757. updateProjectionMatrix: function () {
  11758. var near = this.near,
  11759. top = near * Math.tan(
  11760. _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  11761. height = 2 * top,
  11762. width = this.aspect * height,
  11763. left = - 0.5 * width,
  11764. view = this.view;
  11765. if ( this.view !== null && this.view.enabled ) {
  11766. var fullWidth = view.fullWidth,
  11767. fullHeight = view.fullHeight;
  11768. left += view.offsetX * width / fullWidth;
  11769. top -= view.offsetY * height / fullHeight;
  11770. width *= view.width / fullWidth;
  11771. height *= view.height / fullHeight;
  11772. }
  11773. var skew = this.filmOffset;
  11774. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  11775. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  11776. },
  11777. toJSON: function ( meta ) {
  11778. var data = Object3D.prototype.toJSON.call( this, meta );
  11779. data.object.fov = this.fov;
  11780. data.object.zoom = this.zoom;
  11781. data.object.near = this.near;
  11782. data.object.far = this.far;
  11783. data.object.focus = this.focus;
  11784. data.object.aspect = this.aspect;
  11785. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  11786. data.object.filmGauge = this.filmGauge;
  11787. data.object.filmOffset = this.filmOffset;
  11788. return data;
  11789. }
  11790. } );
  11791. /**
  11792. * @author mrdoob / http://mrdoob.com/
  11793. */
  11794. function ArrayCamera( array ) {
  11795. PerspectiveCamera.call( this );
  11796. this.cameras = array || [];
  11797. }
  11798. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  11799. constructor: ArrayCamera,
  11800. isArrayCamera: true
  11801. } );
  11802. /**
  11803. * @author mrdoob / http://mrdoob.com/
  11804. */
  11805. function WebVRManager( renderer ) {
  11806. var scope = this;
  11807. var device = null;
  11808. var frameData = null;
  11809. var poseTarget = null;
  11810. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  11811. frameData = new window.VRFrameData();
  11812. }
  11813. var matrixWorldInverse = new Matrix4();
  11814. var cameraL = new PerspectiveCamera();
  11815. cameraL.bounds = new Vector4( 0.0, 0.0, 0.5, 1.0 );
  11816. cameraL.layers.enable( 1 );
  11817. var cameraR = new PerspectiveCamera();
  11818. cameraR.bounds = new Vector4( 0.5, 0.0, 0.5, 1.0 );
  11819. cameraR.layers.enable( 2 );
  11820. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  11821. cameraVR.layers.enable( 1 );
  11822. cameraVR.layers.enable( 2 );
  11823. //
  11824. var currentSize, currentPixelRatio;
  11825. function onVRDisplayPresentChange() {
  11826. if ( device !== null && device.isPresenting ) {
  11827. var eyeParameters = device.getEyeParameters( 'left' );
  11828. var renderWidth = eyeParameters.renderWidth;
  11829. var renderHeight = eyeParameters.renderHeight;
  11830. currentPixelRatio = renderer.getPixelRatio();
  11831. currentSize = renderer.getSize();
  11832. renderer.setDrawingBufferSize( renderWidth * 2, renderHeight, 1 );
  11833. } else if ( scope.enabled ) {
  11834. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  11835. }
  11836. }
  11837. if ( typeof window !== 'undefined' ) {
  11838. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  11839. }
  11840. //
  11841. this.enabled = false;
  11842. this.getDevice = function () {
  11843. return device;
  11844. };
  11845. this.setDevice = function ( value ) {
  11846. if ( value !== undefined ) device = value;
  11847. };
  11848. this.setPoseTarget = function ( object ) {
  11849. if ( object !== undefined ) poseTarget = object;
  11850. };
  11851. this.getCamera = function ( camera ) {
  11852. if ( device === null ) return camera;
  11853. device.depthNear = camera.near;
  11854. device.depthFar = camera.far;
  11855. device.getFrameData( frameData );
  11856. //
  11857. var pose = frameData.pose;
  11858. var poseObject = poseTarget !== null ? poseTarget : camera;
  11859. if ( pose.position !== null ) {
  11860. poseObject.position.fromArray( pose.position );
  11861. } else {
  11862. poseObject.position.set( 0, 0, 0 );
  11863. }
  11864. if ( pose.orientation !== null ) {
  11865. poseObject.quaternion.fromArray( pose.orientation );
  11866. }
  11867. poseObject.updateMatrixWorld();
  11868. if ( device.isPresenting === false ) return camera;
  11869. //
  11870. cameraL.near = camera.near;
  11871. cameraR.near = camera.near;
  11872. cameraL.far = camera.far;
  11873. cameraR.far = camera.far;
  11874. cameraVR.matrixWorld.copy( camera.matrixWorld );
  11875. cameraVR.matrixWorldInverse.copy( camera.matrixWorldInverse );
  11876. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  11877. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  11878. var parent = poseObject.parent;
  11879. if ( parent !== null ) {
  11880. matrixWorldInverse.getInverse( parent.matrixWorld );
  11881. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  11882. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  11883. }
  11884. // envMap and Mirror needs camera.matrixWorld
  11885. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  11886. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  11887. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  11888. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  11889. // HACK @mrdoob
  11890. // https://github.com/w3c/webvr/issues/203
  11891. cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
  11892. //
  11893. var layers = device.getLayers();
  11894. if ( layers.length ) {
  11895. var layer = layers[ 0 ];
  11896. if ( layer.leftBounds !== null && layer.leftBounds.length === 4 ) {
  11897. cameraL.bounds.fromArray( layer.leftBounds );
  11898. }
  11899. if ( layer.rightBounds !== null && layer.rightBounds.length === 4 ) {
  11900. cameraR.bounds.fromArray( layer.rightBounds );
  11901. }
  11902. }
  11903. return cameraVR;
  11904. };
  11905. this.submitFrame = function () {
  11906. if ( device && device.isPresenting ) device.submitFrame();
  11907. };
  11908. this.dispose = function () {
  11909. if ( typeof window !== 'undefined' ) {
  11910. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  11911. }
  11912. };
  11913. }
  11914. /**
  11915. * @author mrdoob / http://mrdoob.com/
  11916. */
  11917. function WebGLExtensions( gl ) {
  11918. var extensions = {};
  11919. return {
  11920. get: function ( name ) {
  11921. if ( extensions[ name ] !== undefined ) {
  11922. return extensions[ name ];
  11923. }
  11924. var extension;
  11925. switch ( name ) {
  11926. case 'WEBGL_depth_texture':
  11927. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  11928. break;
  11929. case 'EXT_texture_filter_anisotropic':
  11930. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  11931. break;
  11932. case 'WEBGL_compressed_texture_s3tc':
  11933. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  11934. break;
  11935. case 'WEBGL_compressed_texture_pvrtc':
  11936. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  11937. break;
  11938. case 'WEBGL_compressed_texture_etc1':
  11939. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  11940. break;
  11941. default:
  11942. extension = gl.getExtension( name );
  11943. }
  11944. if ( extension === null ) {
  11945. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  11946. }
  11947. extensions[ name ] = extension;
  11948. return extension;
  11949. }
  11950. };
  11951. }
  11952. /**
  11953. * @author tschw
  11954. */
  11955. function WebGLClipping() {
  11956. var scope = this,
  11957. globalState = null,
  11958. numGlobalPlanes = 0,
  11959. localClippingEnabled = false,
  11960. renderingShadows = false,
  11961. plane = new Plane(),
  11962. viewNormalMatrix = new Matrix3(),
  11963. uniform = { value: null, needsUpdate: false };
  11964. this.uniform = uniform;
  11965. this.numPlanes = 0;
  11966. this.numIntersection = 0;
  11967. this.init = function ( planes, enableLocalClipping, camera ) {
  11968. var enabled =
  11969. planes.length !== 0 ||
  11970. enableLocalClipping ||
  11971. // enable state of previous frame - the clipping code has to
  11972. // run another frame in order to reset the state:
  11973. numGlobalPlanes !== 0 ||
  11974. localClippingEnabled;
  11975. localClippingEnabled = enableLocalClipping;
  11976. globalState = projectPlanes( planes, camera, 0 );
  11977. numGlobalPlanes = planes.length;
  11978. return enabled;
  11979. };
  11980. this.beginShadows = function () {
  11981. renderingShadows = true;
  11982. projectPlanes( null );
  11983. };
  11984. this.endShadows = function () {
  11985. renderingShadows = false;
  11986. resetGlobalState();
  11987. };
  11988. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  11989. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  11990. // there's no local clipping
  11991. if ( renderingShadows ) {
  11992. // there's no global clipping
  11993. projectPlanes( null );
  11994. } else {
  11995. resetGlobalState();
  11996. }
  11997. } else {
  11998. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  11999. lGlobal = nGlobal * 4,
  12000. dstArray = cache.clippingState || null;
  12001. uniform.value = dstArray; // ensure unique state
  12002. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  12003. for ( var i = 0; i !== lGlobal; ++ i ) {
  12004. dstArray[ i ] = globalState[ i ];
  12005. }
  12006. cache.clippingState = dstArray;
  12007. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  12008. this.numPlanes += nGlobal;
  12009. }
  12010. };
  12011. function resetGlobalState() {
  12012. if ( uniform.value !== globalState ) {
  12013. uniform.value = globalState;
  12014. uniform.needsUpdate = numGlobalPlanes > 0;
  12015. }
  12016. scope.numPlanes = numGlobalPlanes;
  12017. scope.numIntersection = 0;
  12018. }
  12019. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  12020. var nPlanes = planes !== null ? planes.length : 0,
  12021. dstArray = null;
  12022. if ( nPlanes !== 0 ) {
  12023. dstArray = uniform.value;
  12024. if ( skipTransform !== true || dstArray === null ) {
  12025. var flatSize = dstOffset + nPlanes * 4,
  12026. viewMatrix = camera.matrixWorldInverse;
  12027. viewNormalMatrix.getNormalMatrix( viewMatrix );
  12028. if ( dstArray === null || dstArray.length < flatSize ) {
  12029. dstArray = new Float32Array( flatSize );
  12030. }
  12031. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  12032. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  12033. plane.normal.toArray( dstArray, i4 );
  12034. dstArray[ i4 + 3 ] = plane.constant;
  12035. }
  12036. }
  12037. uniform.value = dstArray;
  12038. uniform.needsUpdate = true;
  12039. }
  12040. scope.numPlanes = nPlanes;
  12041. return dstArray;
  12042. }
  12043. }
  12044. /**
  12045. * @author thespite / http://www.twitter.com/thespite
  12046. */
  12047. function WebGLUtils( gl, extensions ) {
  12048. function convert( p ) {
  12049. var extension;
  12050. if ( p === RepeatWrapping ) return gl.REPEAT;
  12051. if ( p === ClampToEdgeWrapping ) return gl.CLAMP_TO_EDGE;
  12052. if ( p === MirroredRepeatWrapping ) return gl.MIRRORED_REPEAT;
  12053. if ( p === NearestFilter ) return gl.NEAREST;
  12054. if ( p === NearestMipMapNearestFilter ) return gl.NEAREST_MIPMAP_NEAREST;
  12055. if ( p === NearestMipMapLinearFilter ) return gl.NEAREST_MIPMAP_LINEAR;
  12056. if ( p === LinearFilter ) return gl.LINEAR;
  12057. if ( p === LinearMipMapNearestFilter ) return gl.LINEAR_MIPMAP_NEAREST;
  12058. if ( p === LinearMipMapLinearFilter ) return gl.LINEAR_MIPMAP_LINEAR;
  12059. if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE;
  12060. if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4;
  12061. if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1;
  12062. if ( p === UnsignedShort565Type ) return gl.UNSIGNED_SHORT_5_6_5;
  12063. if ( p === ByteType ) return gl.BYTE;
  12064. if ( p === ShortType ) return gl.SHORT;
  12065. if ( p === UnsignedShortType ) return gl.UNSIGNED_SHORT;
  12066. if ( p === IntType ) return gl.INT;
  12067. if ( p === UnsignedIntType ) return gl.UNSIGNED_INT;
  12068. if ( p === FloatType ) return gl.FLOAT;
  12069. if ( p === HalfFloatType ) {
  12070. extension = extensions.get( 'OES_texture_half_float' );
  12071. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  12072. }
  12073. if ( p === AlphaFormat ) return gl.ALPHA;
  12074. if ( p === RGBFormat ) return gl.RGB;
  12075. if ( p === RGBAFormat ) return gl.RGBA;
  12076. if ( p === LuminanceFormat ) return gl.LUMINANCE;
  12077. if ( p === LuminanceAlphaFormat ) return gl.LUMINANCE_ALPHA;
  12078. if ( p === DepthFormat ) return gl.DEPTH_COMPONENT;
  12079. if ( p === DepthStencilFormat ) return gl.DEPTH_STENCIL;
  12080. if ( p === AddEquation ) return gl.FUNC_ADD;
  12081. if ( p === SubtractEquation ) return gl.FUNC_SUBTRACT;
  12082. if ( p === ReverseSubtractEquation ) return gl.FUNC_REVERSE_SUBTRACT;
  12083. if ( p === ZeroFactor ) return gl.ZERO;
  12084. if ( p === OneFactor ) return gl.ONE;
  12085. if ( p === SrcColorFactor ) return gl.SRC_COLOR;
  12086. if ( p === OneMinusSrcColorFactor ) return gl.ONE_MINUS_SRC_COLOR;
  12087. if ( p === SrcAlphaFactor ) return gl.SRC_ALPHA;
  12088. if ( p === OneMinusSrcAlphaFactor ) return gl.ONE_MINUS_SRC_ALPHA;
  12089. if ( p === DstAlphaFactor ) return gl.DST_ALPHA;
  12090. if ( p === OneMinusDstAlphaFactor ) return gl.ONE_MINUS_DST_ALPHA;
  12091. if ( p === DstColorFactor ) return gl.DST_COLOR;
  12092. if ( p === OneMinusDstColorFactor ) return gl.ONE_MINUS_DST_COLOR;
  12093. if ( p === SrcAlphaSaturateFactor ) return gl.SRC_ALPHA_SATURATE;
  12094. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  12095. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  12096. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  12097. if ( extension !== null ) {
  12098. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  12099. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  12100. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  12101. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  12102. }
  12103. }
  12104. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  12105. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  12106. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  12107. if ( extension !== null ) {
  12108. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  12109. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  12110. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  12111. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  12112. }
  12113. }
  12114. if ( p === RGB_ETC1_Format ) {
  12115. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  12116. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  12117. }
  12118. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  12119. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  12120. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  12121. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  12122. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  12123. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  12124. if ( extension !== null ) {
  12125. return p;
  12126. }
  12127. }
  12128. if ( p === MinEquation || p === MaxEquation ) {
  12129. extension = extensions.get( 'EXT_blend_minmax' );
  12130. if ( extension !== null ) {
  12131. if ( p === MinEquation ) return extension.MIN_EXT;
  12132. if ( p === MaxEquation ) return extension.MAX_EXT;
  12133. }
  12134. }
  12135. if ( p === UnsignedInt248Type ) {
  12136. extension = extensions.get( 'WEBGL_depth_texture' );
  12137. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  12138. }
  12139. return 0;
  12140. }
  12141. return { convert: convert };
  12142. }
  12143. /**
  12144. * @author mrdoob / http://mrdoob.com/
  12145. */
  12146. function UniformsCache() {
  12147. var lights = {};
  12148. return {
  12149. get: function ( light ) {
  12150. if ( lights[ light.id ] !== undefined ) {
  12151. return lights[ light.id ];
  12152. }
  12153. var uniforms;
  12154. switch ( light.type ) {
  12155. case 'DirectionalLight':
  12156. uniforms = {
  12157. direction: new Vector3(),
  12158. color: new Color(),
  12159. shadow: false,
  12160. shadowBias: 0,
  12161. shadowRadius: 1,
  12162. shadowMapSize: new Vector2()
  12163. };
  12164. break;
  12165. case 'SpotLight':
  12166. uniforms = {
  12167. position: new Vector3(),
  12168. direction: new Vector3(),
  12169. color: new Color(),
  12170. distance: 0,
  12171. coneCos: 0,
  12172. penumbraCos: 0,
  12173. decay: 0,
  12174. shadow: false,
  12175. shadowBias: 0,
  12176. shadowRadius: 1,
  12177. shadowMapSize: new Vector2()
  12178. };
  12179. break;
  12180. case 'PointLight':
  12181. uniforms = {
  12182. position: new Vector3(),
  12183. color: new Color(),
  12184. distance: 0,
  12185. decay: 0,
  12186. shadow: false,
  12187. shadowBias: 0,
  12188. shadowRadius: 1,
  12189. shadowMapSize: new Vector2(),
  12190. shadowCameraNear: 1,
  12191. shadowCameraFar: 1000
  12192. };
  12193. break;
  12194. case 'HemisphereLight':
  12195. uniforms = {
  12196. direction: new Vector3(),
  12197. skyColor: new Color(),
  12198. groundColor: new Color()
  12199. };
  12200. break;
  12201. case 'RectAreaLight':
  12202. uniforms = {
  12203. color: new Color(),
  12204. position: new Vector3(),
  12205. halfWidth: new Vector3(),
  12206. halfHeight: new Vector3()
  12207. // TODO (abelnation): set RectAreaLight shadow uniforms
  12208. };
  12209. break;
  12210. }
  12211. lights[ light.id ] = uniforms;
  12212. return uniforms;
  12213. }
  12214. };
  12215. }
  12216. function WebGLLights( stateId ) {
  12217. var cache = new UniformsCache();
  12218. var state = {
  12219. hash: '',
  12220. ambient: [ 0, 0, 0 ],
  12221. directional: [],
  12222. directionalShadowMap: [],
  12223. directionalShadowMatrix: [],
  12224. spot: [],
  12225. spotShadowMap: [],
  12226. spotShadowMatrix: [],
  12227. rectArea: [],
  12228. point: [],
  12229. pointShadowMap: [],
  12230. pointShadowMatrix: [],
  12231. hemi: []
  12232. };
  12233. var vector3 = new Vector3();
  12234. var matrix4 = new Matrix4();
  12235. var matrix42 = new Matrix4();
  12236. function setup( lights, shadows, camera ) {
  12237. var r = 0, g = 0, b = 0;
  12238. var directionalLength = 0;
  12239. var pointLength = 0;
  12240. var spotLength = 0;
  12241. var rectAreaLength = 0;
  12242. var hemiLength = 0;
  12243. var viewMatrix = camera.matrixWorldInverse;
  12244. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  12245. var light = lights[ i ];
  12246. var color = light.color;
  12247. var intensity = light.intensity;
  12248. var distance = light.distance;
  12249. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  12250. if ( light.isAmbientLight ) {
  12251. r += color.r * intensity;
  12252. g += color.g * intensity;
  12253. b += color.b * intensity;
  12254. } else if ( light.isDirectionalLight ) {
  12255. var uniforms = cache.get( light );
  12256. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  12257. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  12258. vector3.setFromMatrixPosition( light.target.matrixWorld );
  12259. uniforms.direction.sub( vector3 );
  12260. uniforms.direction.transformDirection( viewMatrix );
  12261. uniforms.shadow = light.castShadow;
  12262. if ( light.castShadow ) {
  12263. var shadow = light.shadow;
  12264. uniforms.shadowBias = shadow.bias;
  12265. uniforms.shadowRadius = shadow.radius;
  12266. uniforms.shadowMapSize = shadow.mapSize;
  12267. }
  12268. state.directionalShadowMap[ directionalLength ] = shadowMap;
  12269. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  12270. state.directional[ directionalLength ] = uniforms;
  12271. directionalLength ++;
  12272. } else if ( light.isSpotLight ) {
  12273. var uniforms = cache.get( light );
  12274. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  12275. uniforms.position.applyMatrix4( viewMatrix );
  12276. uniforms.color.copy( color ).multiplyScalar( intensity );
  12277. uniforms.distance = distance;
  12278. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  12279. vector3.setFromMatrixPosition( light.target.matrixWorld );
  12280. uniforms.direction.sub( vector3 );
  12281. uniforms.direction.transformDirection( viewMatrix );
  12282. uniforms.coneCos = Math.cos( light.angle );
  12283. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  12284. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  12285. uniforms.shadow = light.castShadow;
  12286. if ( light.castShadow ) {
  12287. var shadow = light.shadow;
  12288. uniforms.shadowBias = shadow.bias;
  12289. uniforms.shadowRadius = shadow.radius;
  12290. uniforms.shadowMapSize = shadow.mapSize;
  12291. }
  12292. state.spotShadowMap[ spotLength ] = shadowMap;
  12293. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  12294. state.spot[ spotLength ] = uniforms;
  12295. spotLength ++;
  12296. } else if ( light.isRectAreaLight ) {
  12297. var uniforms = cache.get( light );
  12298. // (a) intensity is the total visible light emitted
  12299. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  12300. // (b) intensity is the brightness of the light
  12301. uniforms.color.copy( color ).multiplyScalar( intensity );
  12302. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  12303. uniforms.position.applyMatrix4( viewMatrix );
  12304. // extract local rotation of light to derive width/height half vectors
  12305. matrix42.identity();
  12306. matrix4.copy( light.matrixWorld );
  12307. matrix4.premultiply( viewMatrix );
  12308. matrix42.extractRotation( matrix4 );
  12309. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  12310. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  12311. uniforms.halfWidth.applyMatrix4( matrix42 );
  12312. uniforms.halfHeight.applyMatrix4( matrix42 );
  12313. // TODO (abelnation): RectAreaLight distance?
  12314. // uniforms.distance = distance;
  12315. state.rectArea[ rectAreaLength ] = uniforms;
  12316. rectAreaLength ++;
  12317. } else if ( light.isPointLight ) {
  12318. var uniforms = cache.get( light );
  12319. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  12320. uniforms.position.applyMatrix4( viewMatrix );
  12321. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  12322. uniforms.distance = light.distance;
  12323. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  12324. uniforms.shadow = light.castShadow;
  12325. if ( light.castShadow ) {
  12326. var shadow = light.shadow;
  12327. uniforms.shadowBias = shadow.bias;
  12328. uniforms.shadowRadius = shadow.radius;
  12329. uniforms.shadowMapSize = shadow.mapSize;
  12330. uniforms.shadowCameraNear = shadow.camera.near;
  12331. uniforms.shadowCameraFar = shadow.camera.far;
  12332. }
  12333. state.pointShadowMap[ pointLength ] = shadowMap;
  12334. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  12335. state.point[ pointLength ] = uniforms;
  12336. pointLength ++;
  12337. } else if ( light.isHemisphereLight ) {
  12338. var uniforms = cache.get( light );
  12339. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  12340. uniforms.direction.transformDirection( viewMatrix );
  12341. uniforms.direction.normalize();
  12342. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  12343. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  12344. state.hemi[ hemiLength ] = uniforms;
  12345. hemiLength ++;
  12346. }
  12347. }
  12348. state.ambient[ 0 ] = r;
  12349. state.ambient[ 1 ] = g;
  12350. state.ambient[ 2 ] = b;
  12351. state.directional.length = directionalLength;
  12352. state.spot.length = spotLength;
  12353. state.rectArea.length = rectAreaLength;
  12354. state.point.length = pointLength;
  12355. state.hemi.length = hemiLength;
  12356. // TODO (sam-g-steel) why aren't we using join
  12357. state.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + rectAreaLength + ',' + hemiLength + ',' + shadows.length + ',' + stateId;
  12358. }
  12359. return {
  12360. setup: setup,
  12361. state: state
  12362. };
  12363. }
  12364. /**
  12365. * @author Mugen87 / https://github.com/Mugen87
  12366. */
  12367. var count = 0;
  12368. function WebGLRenderState() {
  12369. var id = count ++;
  12370. var lights = new WebGLLights( id );
  12371. var lightsArray = [];
  12372. var shadowsArray = [];
  12373. var spritesArray = [];
  12374. function init() {
  12375. lightsArray.length = 0;
  12376. shadowsArray.length = 0;
  12377. spritesArray.length = 0;
  12378. }
  12379. function pushLight( light ) {
  12380. lightsArray.push( light );
  12381. }
  12382. function pushShadow( shadowLight ) {
  12383. shadowsArray.push( shadowLight );
  12384. }
  12385. function pushSprite( shadowLight ) {
  12386. spritesArray.push( shadowLight );
  12387. }
  12388. function setupLights( camera ) {
  12389. lights.setup( lightsArray, shadowsArray, camera );
  12390. }
  12391. var state = {
  12392. lightsArray: lightsArray,
  12393. shadowsArray: shadowsArray,
  12394. spritesArray: spritesArray,
  12395. lights: lights
  12396. };
  12397. return {
  12398. init: init,
  12399. state: state,
  12400. setupLights: setupLights,
  12401. pushLight: pushLight,
  12402. pushShadow: pushShadow,
  12403. pushSprite: pushSprite
  12404. };
  12405. }
  12406. function WebGLRenderStates() {
  12407. var renderStates = {};
  12408. function get( scene, camera ) {
  12409. var hash = scene.id + ',' + camera.id;
  12410. var renderState = renderStates[ hash ];
  12411. if ( renderState === undefined ) {
  12412. renderState = new WebGLRenderState();
  12413. renderStates[ hash ] = renderState;
  12414. }
  12415. return renderState;
  12416. }
  12417. function dispose() {
  12418. renderStates = {};
  12419. }
  12420. return {
  12421. get: get,
  12422. dispose: dispose
  12423. };
  12424. }
  12425. /**
  12426. * @author supereggbert / http://www.paulbrunt.co.uk/
  12427. * @author mrdoob / http://mrdoob.com/
  12428. * @author alteredq / http://alteredqualia.com/
  12429. * @author szimek / https://github.com/szimek/
  12430. * @author tschw
  12431. */
  12432. function WebGLRenderer( parameters ) {
  12433. console.log( 'THREE.WebGLRenderer', REVISION );
  12434. parameters = parameters || {};
  12435. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  12436. _context = parameters.context !== undefined ? parameters.context : null,
  12437. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  12438. _depth = parameters.depth !== undefined ? parameters.depth : true,
  12439. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  12440. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  12441. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  12442. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  12443. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default';
  12444. var currentRenderList = null;
  12445. var currentRenderState = null;
  12446. // public properties
  12447. this.domElement = _canvas;
  12448. this.context = null;
  12449. // clearing
  12450. this.autoClear = true;
  12451. this.autoClearColor = true;
  12452. this.autoClearDepth = true;
  12453. this.autoClearStencil = true;
  12454. // scene graph
  12455. this.sortObjects = true;
  12456. // user-defined clipping
  12457. this.clippingPlanes = [];
  12458. this.localClippingEnabled = false;
  12459. // physically based shading
  12460. this.gammaFactor = 2.0; // for backwards compatibility
  12461. this.gammaInput = false;
  12462. this.gammaOutput = false;
  12463. // physical lights
  12464. this.physicallyCorrectLights = false;
  12465. // tone mapping
  12466. this.toneMapping = LinearToneMapping;
  12467. this.toneMappingExposure = 1.0;
  12468. this.toneMappingWhitePoint = 1.0;
  12469. // morphs
  12470. this.maxMorphTargets = 8;
  12471. this.maxMorphNormals = 4;
  12472. // internal properties
  12473. var _this = this,
  12474. _isContextLost = false,
  12475. // internal state cache
  12476. _currentRenderTarget = null,
  12477. _currentFramebuffer = null,
  12478. _currentMaterialId = - 1,
  12479. _currentGeometryProgram = '',
  12480. _currentCamera = null,
  12481. _currentArrayCamera = null,
  12482. _currentViewport = new Vector4(),
  12483. _currentScissor = new Vector4(),
  12484. _currentScissorTest = null,
  12485. //
  12486. _usedTextureUnits = 0,
  12487. //
  12488. _width = _canvas.width,
  12489. _height = _canvas.height,
  12490. _pixelRatio = 1,
  12491. _viewport = new Vector4( 0, 0, _width, _height ),
  12492. _scissor = new Vector4( 0, 0, _width, _height ),
  12493. _scissorTest = false,
  12494. // frustum
  12495. _frustum = new Frustum(),
  12496. // clipping
  12497. _clipping = new WebGLClipping(),
  12498. _clippingEnabled = false,
  12499. _localClippingEnabled = false,
  12500. // camera matrices cache
  12501. _projScreenMatrix = new Matrix4(),
  12502. _vector3 = new Vector3(),
  12503. // info
  12504. _infoMemory = {
  12505. geometries: 0,
  12506. textures: 0
  12507. },
  12508. _infoRender = {
  12509. frame: 0,
  12510. calls: 0,
  12511. vertices: 0,
  12512. faces: 0,
  12513. points: 0
  12514. };
  12515. this.info = {
  12516. render: _infoRender,
  12517. memory: _infoMemory,
  12518. programs: null,
  12519. autoReset: true,
  12520. reset: resetInfo
  12521. };
  12522. function resetInfo() {
  12523. _infoRender.frame ++;
  12524. _infoRender.calls = 0;
  12525. _infoRender.vertices = 0;
  12526. _infoRender.faces = 0;
  12527. _infoRender.points = 0;
  12528. }
  12529. function getTargetPixelRatio() {
  12530. return _currentRenderTarget === null ? _pixelRatio : 1;
  12531. }
  12532. // initialize
  12533. var _gl;
  12534. try {
  12535. var contextAttributes = {
  12536. alpha: _alpha,
  12537. depth: _depth,
  12538. stencil: _stencil,
  12539. antialias: _antialias,
  12540. premultipliedAlpha: _premultipliedAlpha,
  12541. preserveDrawingBuffer: _preserveDrawingBuffer,
  12542. powerPreference: _powerPreference
  12543. };
  12544. // event listeners must be registered before WebGL context is created, see #12753
  12545. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  12546. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  12547. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  12548. if ( _gl === null ) {
  12549. if ( _canvas.getContext( 'webgl' ) !== null ) {
  12550. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  12551. } else {
  12552. throw new Error( 'Error creating WebGL context.' );
  12553. }
  12554. }
  12555. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  12556. if ( _gl.getShaderPrecisionFormat === undefined ) {
  12557. _gl.getShaderPrecisionFormat = function () {
  12558. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  12559. };
  12560. }
  12561. } catch ( error ) {
  12562. console.error( 'THREE.WebGLRenderer: ' + error.message );
  12563. }
  12564. var extensions, capabilities, state;
  12565. var properties, textures, attributes, geometries, objects;
  12566. var programCache, renderLists, renderStates;
  12567. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  12568. var spriteRenderer;
  12569. var utils;
  12570. function initGLContext() {
  12571. extensions = new WebGLExtensions( _gl );
  12572. extensions.get( 'WEBGL_depth_texture' );
  12573. extensions.get( 'OES_texture_float' );
  12574. extensions.get( 'OES_texture_float_linear' );
  12575. extensions.get( 'OES_texture_half_float' );
  12576. extensions.get( 'OES_texture_half_float_linear' );
  12577. extensions.get( 'OES_standard_derivatives' );
  12578. extensions.get( 'OES_element_index_uint' );
  12579. extensions.get( 'ANGLE_instanced_arrays' );
  12580. utils = new WebGLUtils( _gl, extensions );
  12581. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  12582. state = new WebGLState( _gl, extensions, utils );
  12583. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  12584. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  12585. properties = new WebGLProperties();
  12586. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, _infoMemory, _infoRender );
  12587. attributes = new WebGLAttributes( _gl );
  12588. geometries = new WebGLGeometries( _gl, attributes, _infoMemory );
  12589. objects = new WebGLObjects( geometries, _infoRender );
  12590. morphtargets = new WebGLMorphtargets( _gl );
  12591. programCache = new WebGLPrograms( _this, extensions, capabilities );
  12592. renderLists = new WebGLRenderLists();
  12593. renderStates = new WebGLRenderStates();
  12594. background = new WebGLBackground( _this, state, geometries, _premultipliedAlpha );
  12595. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, _infoRender );
  12596. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  12597. spriteRenderer = new WebGLSpriteRenderer( _this, _gl, state, textures, capabilities );
  12598. _this.info.programs = programCache.programs;
  12599. _this.context = _gl;
  12600. _this.capabilities = capabilities;
  12601. _this.extensions = extensions;
  12602. _this.properties = properties;
  12603. _this.renderLists = renderLists;
  12604. _this.state = state;
  12605. }
  12606. initGLContext();
  12607. // vr
  12608. var vr = new WebVRManager( _this );
  12609. this.vr = vr;
  12610. // shadow map
  12611. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  12612. this.shadowMap = shadowMap;
  12613. // API
  12614. this.getContext = function () {
  12615. return _gl;
  12616. };
  12617. this.getContextAttributes = function () {
  12618. return _gl.getContextAttributes();
  12619. };
  12620. this.forceContextLoss = function () {
  12621. var extension = extensions.get( 'WEBGL_lose_context' );
  12622. if ( extension ) extension.loseContext();
  12623. };
  12624. this.forceContextRestore = function () {
  12625. var extension = extensions.get( 'WEBGL_lose_context' );
  12626. if ( extension ) extension.restoreContext();
  12627. };
  12628. this.getPixelRatio = function () {
  12629. return _pixelRatio;
  12630. };
  12631. this.setPixelRatio = function ( value ) {
  12632. if ( value === undefined ) return;
  12633. _pixelRatio = value;
  12634. this.setSize( _width, _height, false );
  12635. };
  12636. this.getSize = function () {
  12637. return {
  12638. width: _width,
  12639. height: _height
  12640. };
  12641. };
  12642. this.setSize = function ( width, height, updateStyle ) {
  12643. var device = vr.getDevice();
  12644. if ( device && device.isPresenting ) {
  12645. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  12646. return;
  12647. }
  12648. _width = width;
  12649. _height = height;
  12650. _canvas.width = width * _pixelRatio;
  12651. _canvas.height = height * _pixelRatio;
  12652. if ( updateStyle !== false ) {
  12653. _canvas.style.width = width + 'px';
  12654. _canvas.style.height = height + 'px';
  12655. }
  12656. this.setViewport( 0, 0, width, height );
  12657. };
  12658. this.getDrawingBufferSize = function () {
  12659. return {
  12660. width: _width * _pixelRatio,
  12661. height: _height * _pixelRatio
  12662. };
  12663. };
  12664. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  12665. _width = width;
  12666. _height = height;
  12667. _pixelRatio = pixelRatio;
  12668. _canvas.width = width * pixelRatio;
  12669. _canvas.height = height * pixelRatio;
  12670. this.setViewport( 0, 0, width, height );
  12671. };
  12672. this.getCurrentViewport = function () {
  12673. return _currentViewport;
  12674. };
  12675. this.setViewport = function ( x, y, width, height ) {
  12676. _viewport.set( x, _height - y - height, width, height );
  12677. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  12678. };
  12679. this.setScissor = function ( x, y, width, height ) {
  12680. _scissor.set( x, _height - y - height, width, height );
  12681. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  12682. };
  12683. this.setScissorTest = function ( boolean ) {
  12684. state.setScissorTest( _scissorTest = boolean );
  12685. };
  12686. // Clearing
  12687. this.getClearColor = function () {
  12688. return background.getClearColor();
  12689. };
  12690. this.setClearColor = function () {
  12691. background.setClearColor.apply( background, arguments );
  12692. };
  12693. this.getClearAlpha = function () {
  12694. return background.getClearAlpha();
  12695. };
  12696. this.setClearAlpha = function () {
  12697. background.setClearAlpha.apply( background, arguments );
  12698. };
  12699. this.clear = function ( color, depth, stencil ) {
  12700. var bits = 0;
  12701. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  12702. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  12703. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  12704. _gl.clear( bits );
  12705. };
  12706. this.clearColor = function () {
  12707. this.clear( true, false, false );
  12708. };
  12709. this.clearDepth = function () {
  12710. this.clear( false, true, false );
  12711. };
  12712. this.clearStencil = function () {
  12713. this.clear( false, false, true );
  12714. };
  12715. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  12716. this.setRenderTarget( renderTarget );
  12717. this.clear( color, depth, stencil );
  12718. };
  12719. //
  12720. this.dispose = function () {
  12721. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  12722. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  12723. renderLists.dispose();
  12724. renderStates.dispose();
  12725. properties.dispose();
  12726. objects.dispose();
  12727. vr.dispose();
  12728. stopAnimation();
  12729. };
  12730. // Events
  12731. function onContextLost( event ) {
  12732. event.preventDefault();
  12733. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  12734. _isContextLost = true;
  12735. }
  12736. function onContextRestore( /* event */ ) {
  12737. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  12738. _isContextLost = false;
  12739. initGLContext();
  12740. }
  12741. function onMaterialDispose( event ) {
  12742. var material = event.target;
  12743. material.removeEventListener( 'dispose', onMaterialDispose );
  12744. deallocateMaterial( material );
  12745. }
  12746. // Buffer deallocation
  12747. function deallocateMaterial( material ) {
  12748. releaseMaterialProgramReference( material );
  12749. properties.remove( material );
  12750. }
  12751. function releaseMaterialProgramReference( material ) {
  12752. var programInfo = properties.get( material ).program;
  12753. material.program = undefined;
  12754. if ( programInfo !== undefined ) {
  12755. programCache.releaseProgram( programInfo );
  12756. }
  12757. }
  12758. // Buffer rendering
  12759. function renderObjectImmediate( object, program, material ) {
  12760. object.render( function ( object ) {
  12761. _this.renderBufferImmediate( object, program, material );
  12762. } );
  12763. }
  12764. this.renderBufferImmediate = function ( object, program, material ) {
  12765. state.initAttributes();
  12766. var buffers = properties.get( object );
  12767. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  12768. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  12769. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  12770. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  12771. var programAttributes = program.getAttributes();
  12772. if ( object.hasPositions ) {
  12773. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  12774. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  12775. state.enableAttribute( programAttributes.position );
  12776. _gl.vertexAttribPointer( programAttributes.position, 3, _gl.FLOAT, false, 0, 0 );
  12777. }
  12778. if ( object.hasNormals ) {
  12779. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  12780. if ( ! material.isMeshPhongMaterial &&
  12781. ! material.isMeshStandardMaterial &&
  12782. ! material.isMeshNormalMaterial &&
  12783. material.flatShading === true ) {
  12784. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  12785. var array = object.normalArray;
  12786. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  12787. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  12788. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  12789. array[ i + 0 ] = nx;
  12790. array[ i + 1 ] = ny;
  12791. array[ i + 2 ] = nz;
  12792. array[ i + 3 ] = nx;
  12793. array[ i + 4 ] = ny;
  12794. array[ i + 5 ] = nz;
  12795. array[ i + 6 ] = nx;
  12796. array[ i + 7 ] = ny;
  12797. array[ i + 8 ] = nz;
  12798. }
  12799. }
  12800. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  12801. state.enableAttribute( programAttributes.normal );
  12802. _gl.vertexAttribPointer( programAttributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  12803. }
  12804. if ( object.hasUvs && material.map ) {
  12805. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  12806. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  12807. state.enableAttribute( programAttributes.uv );
  12808. _gl.vertexAttribPointer( programAttributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  12809. }
  12810. if ( object.hasColors && material.vertexColors !== NoColors ) {
  12811. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  12812. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  12813. state.enableAttribute( programAttributes.color );
  12814. _gl.vertexAttribPointer( programAttributes.color, 3, _gl.FLOAT, false, 0, 0 );
  12815. }
  12816. state.disableUnusedAttributes();
  12817. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  12818. object.count = 0;
  12819. };
  12820. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  12821. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  12822. state.setMaterial( material, frontFaceCW );
  12823. var program = setProgram( camera, fog, material, object );
  12824. var geometryProgram = geometry.id + '_' + program.id + '_' + ( material.wireframe === true );
  12825. var updateBuffers = false;
  12826. if ( geometryProgram !== _currentGeometryProgram ) {
  12827. _currentGeometryProgram = geometryProgram;
  12828. updateBuffers = true;
  12829. }
  12830. if ( object.morphTargetInfluences ) {
  12831. morphtargets.update( object, geometry, material, program );
  12832. updateBuffers = true;
  12833. }
  12834. //
  12835. var index = geometry.index;
  12836. var position = geometry.attributes.position;
  12837. var rangeFactor = 1;
  12838. if ( material.wireframe === true ) {
  12839. index = geometries.getWireframeAttribute( geometry );
  12840. rangeFactor = 2;
  12841. }
  12842. var attribute;
  12843. var renderer = bufferRenderer;
  12844. if ( index !== null ) {
  12845. attribute = attributes.get( index );
  12846. renderer = indexedBufferRenderer;
  12847. renderer.setIndex( attribute );
  12848. }
  12849. if ( updateBuffers ) {
  12850. setupVertexAttributes( material, program, geometry );
  12851. if ( index !== null ) {
  12852. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, attribute.buffer );
  12853. }
  12854. }
  12855. //
  12856. var dataCount = Infinity;
  12857. if ( index !== null ) {
  12858. dataCount = index.count;
  12859. } else if ( position !== undefined ) {
  12860. dataCount = position.count;
  12861. }
  12862. var rangeStart = geometry.drawRange.start * rangeFactor;
  12863. var rangeCount = geometry.drawRange.count * rangeFactor;
  12864. var groupStart = group !== null ? group.start * rangeFactor : 0;
  12865. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  12866. var drawStart = Math.max( rangeStart, groupStart );
  12867. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  12868. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  12869. if ( drawCount === 0 ) return;
  12870. //
  12871. if ( object.isMesh ) {
  12872. if ( material.wireframe === true ) {
  12873. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  12874. renderer.setMode( _gl.LINES );
  12875. } else {
  12876. switch ( object.drawMode ) {
  12877. case TrianglesDrawMode:
  12878. renderer.setMode( _gl.TRIANGLES );
  12879. break;
  12880. case TriangleStripDrawMode:
  12881. renderer.setMode( _gl.TRIANGLE_STRIP );
  12882. break;
  12883. case TriangleFanDrawMode:
  12884. renderer.setMode( _gl.TRIANGLE_FAN );
  12885. break;
  12886. }
  12887. }
  12888. } else if ( object.isLine ) {
  12889. var lineWidth = material.linewidth;
  12890. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  12891. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  12892. if ( object.isLineSegments ) {
  12893. renderer.setMode( _gl.LINES );
  12894. } else if ( object.isLineLoop ) {
  12895. renderer.setMode( _gl.LINE_LOOP );
  12896. } else {
  12897. renderer.setMode( _gl.LINE_STRIP );
  12898. }
  12899. } else if ( object.isPoints ) {
  12900. renderer.setMode( _gl.POINTS );
  12901. }
  12902. if ( geometry && geometry.isInstancedBufferGeometry ) {
  12903. if ( geometry.maxInstancedCount > 0 ) {
  12904. renderer.renderInstances( geometry, drawStart, drawCount );
  12905. }
  12906. } else {
  12907. renderer.render( drawStart, drawCount );
  12908. }
  12909. };
  12910. function setupVertexAttributes( material, program, geometry, startIndex ) {
  12911. if ( geometry && geometry.isInstancedBufferGeometry ) {
  12912. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  12913. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12914. return;
  12915. }
  12916. }
  12917. if ( startIndex === undefined ) startIndex = 0;
  12918. state.initAttributes();
  12919. var geometryAttributes = geometry.attributes;
  12920. var programAttributes = program.getAttributes();
  12921. var materialDefaultAttributeValues = material.defaultAttributeValues;
  12922. for ( var name in programAttributes ) {
  12923. var programAttribute = programAttributes[ name ];
  12924. if ( programAttribute >= 0 ) {
  12925. var geometryAttribute = geometryAttributes[ name ];
  12926. if ( geometryAttribute !== undefined ) {
  12927. var normalized = geometryAttribute.normalized;
  12928. var size = geometryAttribute.itemSize;
  12929. var attribute = attributes.get( geometryAttribute );
  12930. // TODO Attribute may not be available on context restore
  12931. if ( attribute === undefined ) continue;
  12932. var buffer = attribute.buffer;
  12933. var type = attribute.type;
  12934. var bytesPerElement = attribute.bytesPerElement;
  12935. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  12936. var data = geometryAttribute.data;
  12937. var stride = data.stride;
  12938. var offset = geometryAttribute.offset;
  12939. if ( data && data.isInstancedInterleavedBuffer ) {
  12940. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  12941. if ( geometry.maxInstancedCount === undefined ) {
  12942. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  12943. }
  12944. } else {
  12945. state.enableAttribute( programAttribute );
  12946. }
  12947. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  12948. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, ( startIndex * stride + offset ) * bytesPerElement );
  12949. } else {
  12950. if ( geometryAttribute.isInstancedBufferAttribute ) {
  12951. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  12952. if ( geometry.maxInstancedCount === undefined ) {
  12953. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  12954. }
  12955. } else {
  12956. state.enableAttribute( programAttribute );
  12957. }
  12958. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  12959. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * bytesPerElement );
  12960. }
  12961. } else if ( materialDefaultAttributeValues !== undefined ) {
  12962. var value = materialDefaultAttributeValues[ name ];
  12963. if ( value !== undefined ) {
  12964. switch ( value.length ) {
  12965. case 2:
  12966. _gl.vertexAttrib2fv( programAttribute, value );
  12967. break;
  12968. case 3:
  12969. _gl.vertexAttrib3fv( programAttribute, value );
  12970. break;
  12971. case 4:
  12972. _gl.vertexAttrib4fv( programAttribute, value );
  12973. break;
  12974. default:
  12975. _gl.vertexAttrib1fv( programAttribute, value );
  12976. }
  12977. }
  12978. }
  12979. }
  12980. }
  12981. state.disableUnusedAttributes();
  12982. }
  12983. // Compile
  12984. this.compile = function ( scene, camera ) {
  12985. currentRenderState.init();
  12986. scene.traverse( function ( object ) {
  12987. if ( object.isLight ) {
  12988. currentRenderState.pushLight( object );
  12989. if ( object.castShadow ) {
  12990. currentRenderState.pushShadow( object );
  12991. }
  12992. }
  12993. } );
  12994. currentRenderState.setupLights( camera );
  12995. scene.traverse( function ( object ) {
  12996. if ( object.material ) {
  12997. if ( Array.isArray( object.material ) ) {
  12998. for ( var i = 0; i < object.material.length; i ++ ) {
  12999. initMaterial( object.material[ i ], scene.fog, object );
  13000. }
  13001. } else {
  13002. initMaterial( object.material, scene.fog, object );
  13003. }
  13004. }
  13005. } );
  13006. };
  13007. // Animation Loop
  13008. var isAnimating = false;
  13009. var onAnimationFrame = null;
  13010. function startAnimation() {
  13011. if ( isAnimating ) return;
  13012. requestAnimationLoopFrame();
  13013. isAnimating = true;
  13014. }
  13015. function stopAnimation() {
  13016. isAnimating = false;
  13017. }
  13018. function requestAnimationLoopFrame() {
  13019. var device = vr.getDevice();
  13020. if ( device && device.isPresenting ) {
  13021. device.requestAnimationFrame( animationLoop );
  13022. } else {
  13023. window.requestAnimationFrame( animationLoop );
  13024. }
  13025. }
  13026. function animationLoop( time ) {
  13027. if ( isAnimating === false ) return;
  13028. onAnimationFrame( time );
  13029. requestAnimationLoopFrame();
  13030. }
  13031. this.animate = function ( callback ) {
  13032. onAnimationFrame = callback;
  13033. onAnimationFrame !== null ? startAnimation() : stopAnimation();
  13034. };
  13035. // Rendering
  13036. this.render = function ( scene, camera, renderTarget, forceClear ) {
  13037. if ( ! ( camera && camera.isCamera ) ) {
  13038. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  13039. return;
  13040. }
  13041. if ( _isContextLost ) return;
  13042. // reset caching for this frame
  13043. _currentGeometryProgram = '';
  13044. _currentMaterialId = - 1;
  13045. _currentCamera = null;
  13046. // update scene graph
  13047. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  13048. // update camera matrices and frustum
  13049. if ( camera.parent === null ) camera.updateMatrixWorld();
  13050. if ( vr.enabled ) {
  13051. camera = vr.getCamera( camera );
  13052. }
  13053. //
  13054. currentRenderState = renderStates.get( scene, camera );
  13055. currentRenderState.init();
  13056. scene.onBeforeRender( _this, scene, camera, renderTarget );
  13057. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  13058. _frustum.setFromMatrix( _projScreenMatrix );
  13059. _localClippingEnabled = this.localClippingEnabled;
  13060. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  13061. currentRenderList = renderLists.get( scene, camera );
  13062. currentRenderList.init();
  13063. projectObject( scene, camera, _this.sortObjects );
  13064. if ( _this.sortObjects === true ) {
  13065. currentRenderList.sort();
  13066. }
  13067. //
  13068. if ( _clippingEnabled ) _clipping.beginShadows();
  13069. var shadowsArray = currentRenderState.state.shadowsArray;
  13070. shadowMap.render( shadowsArray, scene, camera );
  13071. currentRenderState.setupLights( camera );
  13072. if ( _clippingEnabled ) _clipping.endShadows();
  13073. //
  13074. if ( this.info.autoReset ) this.info.reset();
  13075. if ( renderTarget === undefined ) {
  13076. renderTarget = null;
  13077. }
  13078. this.setRenderTarget( renderTarget );
  13079. //
  13080. background.render( currentRenderList, scene, camera, forceClear );
  13081. // render scene
  13082. var opaqueObjects = currentRenderList.opaque;
  13083. var transparentObjects = currentRenderList.transparent;
  13084. if ( scene.overrideMaterial ) {
  13085. var overrideMaterial = scene.overrideMaterial;
  13086. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  13087. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  13088. } else {
  13089. // opaque pass (front-to-back order)
  13090. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  13091. // transparent pass (back-to-front order)
  13092. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  13093. }
  13094. // custom renderers
  13095. var spritesArray = currentRenderState.state.spritesArray;
  13096. spriteRenderer.render( spritesArray, scene, camera );
  13097. // Generate mipmap if we're using any kind of mipmap filtering
  13098. if ( renderTarget ) {
  13099. textures.updateRenderTargetMipmap( renderTarget );
  13100. }
  13101. // Ensure depth buffer writing is enabled so it can be cleared on next render
  13102. state.buffers.depth.setTest( true );
  13103. state.buffers.depth.setMask( true );
  13104. state.buffers.color.setMask( true );
  13105. state.setPolygonOffset( false );
  13106. scene.onAfterRender( _this, scene, camera );
  13107. if ( vr.enabled ) {
  13108. vr.submitFrame();
  13109. }
  13110. // _gl.finish();
  13111. currentRenderList = null;
  13112. currentRenderState = null;
  13113. };
  13114. /*
  13115. // TODO Duplicated code (Frustum)
  13116. var _sphere = new Sphere();
  13117. function isObjectViewable( object ) {
  13118. var geometry = object.geometry;
  13119. if ( geometry.boundingSphere === null )
  13120. geometry.computeBoundingSphere();
  13121. _sphere.copy( geometry.boundingSphere ).
  13122. applyMatrix4( object.matrixWorld );
  13123. return isSphereViewable( _sphere );
  13124. }
  13125. function isSpriteViewable( sprite ) {
  13126. _sphere.center.set( 0, 0, 0 );
  13127. _sphere.radius = 0.7071067811865476;
  13128. _sphere.applyMatrix4( sprite.matrixWorld );
  13129. return isSphereViewable( _sphere );
  13130. }
  13131. function isSphereViewable( sphere ) {
  13132. if ( ! _frustum.intersectsSphere( sphere ) ) return false;
  13133. var numPlanes = _clipping.numPlanes;
  13134. if ( numPlanes === 0 ) return true;
  13135. var planes = _this.clippingPlanes,
  13136. center = sphere.center,
  13137. negRad = - sphere.radius,
  13138. i = 0;
  13139. do {
  13140. // out when deeper than radius in the negative halfspace
  13141. if ( planes[ i ].distanceToPoint( center ) < negRad ) return false;
  13142. } while ( ++ i !== numPlanes );
  13143. return true;
  13144. }
  13145. */
  13146. function projectObject( object, camera, sortObjects ) {
  13147. if ( object.visible === false ) return;
  13148. var visible = object.layers.test( camera.layers );
  13149. if ( visible ) {
  13150. if ( object.isLight ) {
  13151. currentRenderState.pushLight( object );
  13152. if ( object.castShadow ) {
  13153. currentRenderState.pushShadow( object );
  13154. }
  13155. } else if ( object.isSprite ) {
  13156. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  13157. currentRenderState.pushSprite( object );
  13158. }
  13159. } else if ( object.isImmediateRenderObject ) {
  13160. if ( sortObjects ) {
  13161. _vector3.setFromMatrixPosition( object.matrixWorld )
  13162. .applyMatrix4( _projScreenMatrix );
  13163. }
  13164. currentRenderList.push( object, null, object.material, _vector3.z, null );
  13165. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  13166. if ( object.isSkinnedMesh ) {
  13167. object.skeleton.update();
  13168. }
  13169. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  13170. if ( sortObjects ) {
  13171. _vector3.setFromMatrixPosition( object.matrixWorld )
  13172. .applyMatrix4( _projScreenMatrix );
  13173. }
  13174. var geometry = objects.update( object );
  13175. var material = object.material;
  13176. if ( Array.isArray( material ) ) {
  13177. var groups = geometry.groups;
  13178. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  13179. var group = groups[ i ];
  13180. var groupMaterial = material[ group.materialIndex ];
  13181. if ( groupMaterial && groupMaterial.visible ) {
  13182. currentRenderList.push( object, geometry, groupMaterial, _vector3.z, group );
  13183. }
  13184. }
  13185. } else if ( material.visible ) {
  13186. currentRenderList.push( object, geometry, material, _vector3.z, null );
  13187. }
  13188. }
  13189. }
  13190. }
  13191. var children = object.children;
  13192. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13193. projectObject( children[ i ], camera, sortObjects );
  13194. }
  13195. }
  13196. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  13197. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  13198. var renderItem = renderList[ i ];
  13199. var object = renderItem.object;
  13200. var geometry = renderItem.geometry;
  13201. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  13202. var group = renderItem.group;
  13203. if ( camera.isArrayCamera ) {
  13204. _currentArrayCamera = camera;
  13205. var cameras = camera.cameras;
  13206. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  13207. var camera2 = cameras[ j ];
  13208. if ( object.layers.test( camera2.layers ) ) {
  13209. var bounds = camera2.bounds;
  13210. var x = bounds.x * _width;
  13211. var y = bounds.y * _height;
  13212. var width = bounds.z * _width;
  13213. var height = bounds.w * _height;
  13214. state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
  13215. renderObject( object, scene, camera2, geometry, material, group );
  13216. }
  13217. }
  13218. } else {
  13219. _currentArrayCamera = null;
  13220. renderObject( object, scene, camera, geometry, material, group );
  13221. }
  13222. }
  13223. }
  13224. function renderObject( object, scene, camera, geometry, material, group ) {
  13225. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  13226. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  13227. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  13228. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  13229. if ( object.isImmediateRenderObject ) {
  13230. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  13231. state.setMaterial( material, frontFaceCW );
  13232. var program = setProgram( camera, scene.fog, material, object );
  13233. _currentGeometryProgram = '';
  13234. renderObjectImmediate( object, program, material );
  13235. } else {
  13236. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  13237. }
  13238. object.onAfterRender( _this, scene, camera, geometry, material, group );
  13239. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  13240. }
  13241. function initMaterial( material, fog, object ) {
  13242. var materialProperties = properties.get( material );
  13243. var lights = currentRenderState.state.lights;
  13244. var shadowsArray = currentRenderState.state.shadowsArray;
  13245. var parameters = programCache.getParameters(
  13246. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  13247. var code = programCache.getProgramCode( material, parameters );
  13248. var program = materialProperties.program;
  13249. var programChange = true;
  13250. if ( program === undefined ) {
  13251. // new material
  13252. material.addEventListener( 'dispose', onMaterialDispose );
  13253. } else if ( program.code !== code ) {
  13254. // changed glsl or parameters
  13255. releaseMaterialProgramReference( material );
  13256. } else if ( materialProperties.lightsHash !== lights.state.hash ) {
  13257. properties.update( material, 'lightsHash', lights.state.hash );
  13258. programChange = false;
  13259. } else if ( parameters.shaderID !== undefined ) {
  13260. // same glsl and uniform list
  13261. return;
  13262. } else {
  13263. // only rebuild uniform list
  13264. programChange = false;
  13265. }
  13266. if ( programChange ) {
  13267. if ( parameters.shaderID ) {
  13268. var shader = ShaderLib[ parameters.shaderID ];
  13269. materialProperties.shader = {
  13270. name: material.type,
  13271. uniforms: UniformsUtils.clone( shader.uniforms ),
  13272. vertexShader: shader.vertexShader,
  13273. fragmentShader: shader.fragmentShader
  13274. };
  13275. } else {
  13276. materialProperties.shader = {
  13277. name: material.type,
  13278. uniforms: material.uniforms,
  13279. vertexShader: material.vertexShader,
  13280. fragmentShader: material.fragmentShader
  13281. };
  13282. }
  13283. material.onBeforeCompile( materialProperties.shader );
  13284. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  13285. materialProperties.program = program;
  13286. material.program = program;
  13287. }
  13288. var programAttributes = program.getAttributes();
  13289. if ( material.morphTargets ) {
  13290. material.numSupportedMorphTargets = 0;
  13291. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  13292. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  13293. material.numSupportedMorphTargets ++;
  13294. }
  13295. }
  13296. }
  13297. if ( material.morphNormals ) {
  13298. material.numSupportedMorphNormals = 0;
  13299. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  13300. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  13301. material.numSupportedMorphNormals ++;
  13302. }
  13303. }
  13304. }
  13305. var uniforms = materialProperties.shader.uniforms;
  13306. if ( ! material.isShaderMaterial &&
  13307. ! material.isRawShaderMaterial ||
  13308. material.clipping === true ) {
  13309. materialProperties.numClippingPlanes = _clipping.numPlanes;
  13310. materialProperties.numIntersection = _clipping.numIntersection;
  13311. uniforms.clippingPlanes = _clipping.uniform;
  13312. }
  13313. materialProperties.fog = fog;
  13314. // store the light setup it was created for
  13315. materialProperties.lightsHash = lights.state.hash;
  13316. if ( material.lights ) {
  13317. // wire up the material to this renderer's lighting state
  13318. uniforms.ambientLightColor.value = lights.state.ambient;
  13319. uniforms.directionalLights.value = lights.state.directional;
  13320. uniforms.spotLights.value = lights.state.spot;
  13321. uniforms.rectAreaLights.value = lights.state.rectArea;
  13322. uniforms.pointLights.value = lights.state.point;
  13323. uniforms.hemisphereLights.value = lights.state.hemi;
  13324. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  13325. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  13326. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  13327. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  13328. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  13329. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  13330. // TODO (abelnation): add area lights shadow info to uniforms
  13331. }
  13332. var progUniforms = materialProperties.program.getUniforms(),
  13333. uniformsList =
  13334. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  13335. materialProperties.uniformsList = uniformsList;
  13336. }
  13337. function setProgram( camera, fog, material, object ) {
  13338. _usedTextureUnits = 0;
  13339. var materialProperties = properties.get( material );
  13340. var lights = currentRenderState.state.lights;
  13341. if ( _clippingEnabled ) {
  13342. if ( _localClippingEnabled || camera !== _currentCamera ) {
  13343. var useCache =
  13344. camera === _currentCamera &&
  13345. material.id === _currentMaterialId;
  13346. // we might want to call this function with some ClippingGroup
  13347. // object instead of the material, once it becomes feasible
  13348. // (#8465, #8379)
  13349. _clipping.setState(
  13350. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  13351. camera, materialProperties, useCache );
  13352. }
  13353. }
  13354. if ( material.needsUpdate === false ) {
  13355. if ( materialProperties.program === undefined ) {
  13356. material.needsUpdate = true;
  13357. } else if ( material.fog && materialProperties.fog !== fog ) {
  13358. material.needsUpdate = true;
  13359. } else if ( material.lights && materialProperties.lightsHash !== lights.state.hash ) {
  13360. material.needsUpdate = true;
  13361. } else if ( materialProperties.numClippingPlanes !== undefined &&
  13362. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  13363. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  13364. material.needsUpdate = true;
  13365. }
  13366. }
  13367. if ( material.needsUpdate ) {
  13368. initMaterial( material, fog, object );
  13369. material.needsUpdate = false;
  13370. }
  13371. var refreshProgram = false;
  13372. var refreshMaterial = false;
  13373. var refreshLights = false;
  13374. var program = materialProperties.program,
  13375. p_uniforms = program.getUniforms(),
  13376. m_uniforms = materialProperties.shader.uniforms;
  13377. if ( state.useProgram( program.program ) ) {
  13378. refreshProgram = true;
  13379. refreshMaterial = true;
  13380. refreshLights = true;
  13381. }
  13382. if ( material.id !== _currentMaterialId ) {
  13383. _currentMaterialId = material.id;
  13384. refreshMaterial = true;
  13385. }
  13386. if ( refreshProgram || camera !== _currentCamera ) {
  13387. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  13388. if ( capabilities.logarithmicDepthBuffer ) {
  13389. p_uniforms.setValue( _gl, 'logDepthBufFC',
  13390. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  13391. }
  13392. // Avoid unneeded uniform updates per ArrayCamera's sub-camera
  13393. if ( _currentCamera !== ( _currentArrayCamera || camera ) ) {
  13394. _currentCamera = ( _currentArrayCamera || camera );
  13395. // lighting uniforms depend on the camera so enforce an update
  13396. // now, in case this material supports lights - or later, when
  13397. // the next material that does gets activated:
  13398. refreshMaterial = true; // set to true on material change
  13399. refreshLights = true; // remains set until update done
  13400. }
  13401. // load material specific uniforms
  13402. // (shader material also gets them for the sake of genericity)
  13403. if ( material.isShaderMaterial ||
  13404. material.isMeshPhongMaterial ||
  13405. material.isMeshStandardMaterial ||
  13406. material.envMap ) {
  13407. var uCamPos = p_uniforms.map.cameraPosition;
  13408. if ( uCamPos !== undefined ) {
  13409. uCamPos.setValue( _gl,
  13410. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  13411. }
  13412. }
  13413. if ( material.isMeshPhongMaterial ||
  13414. material.isMeshLambertMaterial ||
  13415. material.isMeshBasicMaterial ||
  13416. material.isMeshStandardMaterial ||
  13417. material.isShaderMaterial ||
  13418. material.skinning ) {
  13419. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  13420. }
  13421. }
  13422. // skinning uniforms must be set even if material didn't change
  13423. // auto-setting of texture unit for bone texture must go before other textures
  13424. // not sure why, but otherwise weird things happen
  13425. if ( material.skinning ) {
  13426. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  13427. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  13428. var skeleton = object.skeleton;
  13429. if ( skeleton ) {
  13430. var bones = skeleton.bones;
  13431. if ( capabilities.floatVertexTextures ) {
  13432. if ( skeleton.boneTexture === undefined ) {
  13433. // layout (1 matrix = 4 pixels)
  13434. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13435. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13436. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13437. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13438. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13439. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  13440. size = _Math.ceilPowerOfTwo( size );
  13441. size = Math.max( size, 4 );
  13442. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  13443. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  13444. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  13445. boneTexture.needsUpdate = true;
  13446. skeleton.boneMatrices = boneMatrices;
  13447. skeleton.boneTexture = boneTexture;
  13448. skeleton.boneTextureSize = size;
  13449. }
  13450. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture );
  13451. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  13452. } else {
  13453. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  13454. }
  13455. }
  13456. }
  13457. if ( refreshMaterial ) {
  13458. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  13459. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  13460. if ( material.lights ) {
  13461. // the current material requires lighting info
  13462. // note: all lighting uniforms are always set correctly
  13463. // they simply reference the renderer's state for their
  13464. // values
  13465. //
  13466. // use the current material's .needsUpdate flags to set
  13467. // the GL state when required
  13468. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  13469. }
  13470. // refresh uniforms common to several materials
  13471. if ( fog && material.fog ) {
  13472. refreshUniformsFog( m_uniforms, fog );
  13473. }
  13474. if ( material.isMeshBasicMaterial ) {
  13475. refreshUniformsCommon( m_uniforms, material );
  13476. } else if ( material.isMeshLambertMaterial ) {
  13477. refreshUniformsCommon( m_uniforms, material );
  13478. refreshUniformsLambert( m_uniforms, material );
  13479. } else if ( material.isMeshPhongMaterial ) {
  13480. refreshUniformsCommon( m_uniforms, material );
  13481. if ( material.isMeshToonMaterial ) {
  13482. refreshUniformsToon( m_uniforms, material );
  13483. } else {
  13484. refreshUniformsPhong( m_uniforms, material );
  13485. }
  13486. } else if ( material.isMeshStandardMaterial ) {
  13487. refreshUniformsCommon( m_uniforms, material );
  13488. if ( material.isMeshPhysicalMaterial ) {
  13489. refreshUniformsPhysical( m_uniforms, material );
  13490. } else {
  13491. refreshUniformsStandard( m_uniforms, material );
  13492. }
  13493. } else if ( material.isMeshDepthMaterial ) {
  13494. refreshUniformsCommon( m_uniforms, material );
  13495. refreshUniformsDepth( m_uniforms, material );
  13496. } else if ( material.isMeshDistanceMaterial ) {
  13497. refreshUniformsCommon( m_uniforms, material );
  13498. refreshUniformsDistance( m_uniforms, material );
  13499. } else if ( material.isMeshNormalMaterial ) {
  13500. refreshUniformsCommon( m_uniforms, material );
  13501. refreshUniformsNormal( m_uniforms, material );
  13502. } else if ( material.isLineBasicMaterial ) {
  13503. refreshUniformsLine( m_uniforms, material );
  13504. if ( material.isLineDashedMaterial ) {
  13505. refreshUniformsDash( m_uniforms, material );
  13506. }
  13507. } else if ( material.isPointsMaterial ) {
  13508. refreshUniformsPoints( m_uniforms, material );
  13509. } else if ( material.isShadowMaterial ) {
  13510. m_uniforms.color.value = material.color;
  13511. m_uniforms.opacity.value = material.opacity;
  13512. }
  13513. // RectAreaLight Texture
  13514. // TODO (mrdoob): Find a nicer implementation
  13515. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  13516. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  13517. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, _this );
  13518. }
  13519. // common matrices
  13520. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  13521. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  13522. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  13523. return program;
  13524. }
  13525. // Uniforms (refresh uniforms objects)
  13526. function refreshUniformsCommon( uniforms, material ) {
  13527. uniforms.opacity.value = material.opacity;
  13528. if ( material.color ) {
  13529. uniforms.diffuse.value = material.color;
  13530. }
  13531. if ( material.emissive ) {
  13532. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  13533. }
  13534. if ( material.map ) {
  13535. uniforms.map.value = material.map;
  13536. }
  13537. if ( material.alphaMap ) {
  13538. uniforms.alphaMap.value = material.alphaMap;
  13539. }
  13540. if ( material.specularMap ) {
  13541. uniforms.specularMap.value = material.specularMap;
  13542. }
  13543. if ( material.envMap ) {
  13544. uniforms.envMap.value = material.envMap;
  13545. // don't flip CubeTexture envMaps, flip everything else:
  13546. // WebGLRenderTargetCube will be flipped for backwards compatibility
  13547. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  13548. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  13549. uniforms.flipEnvMap.value = ( ! ( material.envMap && material.envMap.isCubeTexture ) ) ? 1 : - 1;
  13550. uniforms.reflectivity.value = material.reflectivity;
  13551. uniforms.refractionRatio.value = material.refractionRatio;
  13552. }
  13553. if ( material.lightMap ) {
  13554. uniforms.lightMap.value = material.lightMap;
  13555. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13556. }
  13557. if ( material.aoMap ) {
  13558. uniforms.aoMap.value = material.aoMap;
  13559. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13560. }
  13561. // uv repeat and offset setting priorities
  13562. // 1. color map
  13563. // 2. specular map
  13564. // 3. normal map
  13565. // 4. bump map
  13566. // 5. alpha map
  13567. // 6. emissive map
  13568. var uvScaleMap;
  13569. if ( material.map ) {
  13570. uvScaleMap = material.map;
  13571. } else if ( material.specularMap ) {
  13572. uvScaleMap = material.specularMap;
  13573. } else if ( material.displacementMap ) {
  13574. uvScaleMap = material.displacementMap;
  13575. } else if ( material.normalMap ) {
  13576. uvScaleMap = material.normalMap;
  13577. } else if ( material.bumpMap ) {
  13578. uvScaleMap = material.bumpMap;
  13579. } else if ( material.roughnessMap ) {
  13580. uvScaleMap = material.roughnessMap;
  13581. } else if ( material.metalnessMap ) {
  13582. uvScaleMap = material.metalnessMap;
  13583. } else if ( material.alphaMap ) {
  13584. uvScaleMap = material.alphaMap;
  13585. } else if ( material.emissiveMap ) {
  13586. uvScaleMap = material.emissiveMap;
  13587. }
  13588. if ( uvScaleMap !== undefined ) {
  13589. // backwards compatibility
  13590. if ( uvScaleMap.isWebGLRenderTarget ) {
  13591. uvScaleMap = uvScaleMap.texture;
  13592. }
  13593. if ( uvScaleMap.matrixAutoUpdate === true ) {
  13594. var offset = uvScaleMap.offset;
  13595. var repeat = uvScaleMap.repeat;
  13596. var rotation = uvScaleMap.rotation;
  13597. var center = uvScaleMap.center;
  13598. uvScaleMap.matrix.setUvTransform( offset.x, offset.y, repeat.x, repeat.y, rotation, center.x, center.y );
  13599. }
  13600. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  13601. }
  13602. }
  13603. function refreshUniformsLine( uniforms, material ) {
  13604. uniforms.diffuse.value = material.color;
  13605. uniforms.opacity.value = material.opacity;
  13606. }
  13607. function refreshUniformsDash( uniforms, material ) {
  13608. uniforms.dashSize.value = material.dashSize;
  13609. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13610. uniforms.scale.value = material.scale;
  13611. }
  13612. function refreshUniformsPoints( uniforms, material ) {
  13613. uniforms.diffuse.value = material.color;
  13614. uniforms.opacity.value = material.opacity;
  13615. uniforms.size.value = material.size * _pixelRatio;
  13616. uniforms.scale.value = _height * 0.5;
  13617. uniforms.map.value = material.map;
  13618. if ( material.map !== null ) {
  13619. if ( material.map.matrixAutoUpdate === true ) {
  13620. var offset = material.map.offset;
  13621. var repeat = material.map.repeat;
  13622. var rotation = material.map.rotation;
  13623. var center = material.map.center;
  13624. material.map.matrix.setUvTransform( offset.x, offset.y, repeat.x, repeat.y, rotation, center.x, center.y );
  13625. }
  13626. uniforms.uvTransform.value.copy( material.map.matrix );
  13627. }
  13628. }
  13629. function refreshUniformsFog( uniforms, fog ) {
  13630. uniforms.fogColor.value = fog.color;
  13631. if ( fog.isFog ) {
  13632. uniforms.fogNear.value = fog.near;
  13633. uniforms.fogFar.value = fog.far;
  13634. } else if ( fog.isFogExp2 ) {
  13635. uniforms.fogDensity.value = fog.density;
  13636. }
  13637. }
  13638. function refreshUniformsLambert( uniforms, material ) {
  13639. if ( material.emissiveMap ) {
  13640. uniforms.emissiveMap.value = material.emissiveMap;
  13641. }
  13642. }
  13643. function refreshUniformsPhong( uniforms, material ) {
  13644. uniforms.specular.value = material.specular;
  13645. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  13646. if ( material.emissiveMap ) {
  13647. uniforms.emissiveMap.value = material.emissiveMap;
  13648. }
  13649. if ( material.bumpMap ) {
  13650. uniforms.bumpMap.value = material.bumpMap;
  13651. uniforms.bumpScale.value = material.bumpScale;
  13652. }
  13653. if ( material.normalMap ) {
  13654. uniforms.normalMap.value = material.normalMap;
  13655. uniforms.normalScale.value.copy( material.normalScale );
  13656. }
  13657. if ( material.displacementMap ) {
  13658. uniforms.displacementMap.value = material.displacementMap;
  13659. uniforms.displacementScale.value = material.displacementScale;
  13660. uniforms.displacementBias.value = material.displacementBias;
  13661. }
  13662. }
  13663. function refreshUniformsToon( uniforms, material ) {
  13664. refreshUniformsPhong( uniforms, material );
  13665. if ( material.gradientMap ) {
  13666. uniforms.gradientMap.value = material.gradientMap;
  13667. }
  13668. }
  13669. function refreshUniformsStandard( uniforms, material ) {
  13670. uniforms.roughness.value = material.roughness;
  13671. uniforms.metalness.value = material.metalness;
  13672. if ( material.roughnessMap ) {
  13673. uniforms.roughnessMap.value = material.roughnessMap;
  13674. }
  13675. if ( material.metalnessMap ) {
  13676. uniforms.metalnessMap.value = material.metalnessMap;
  13677. }
  13678. if ( material.emissiveMap ) {
  13679. uniforms.emissiveMap.value = material.emissiveMap;
  13680. }
  13681. if ( material.bumpMap ) {
  13682. uniforms.bumpMap.value = material.bumpMap;
  13683. uniforms.bumpScale.value = material.bumpScale;
  13684. }
  13685. if ( material.normalMap ) {
  13686. uniforms.normalMap.value = material.normalMap;
  13687. uniforms.normalScale.value.copy( material.normalScale );
  13688. }
  13689. if ( material.displacementMap ) {
  13690. uniforms.displacementMap.value = material.displacementMap;
  13691. uniforms.displacementScale.value = material.displacementScale;
  13692. uniforms.displacementBias.value = material.displacementBias;
  13693. }
  13694. if ( material.envMap ) {
  13695. //uniforms.envMap.value = material.envMap; // part of uniforms common
  13696. uniforms.envMapIntensity.value = material.envMapIntensity;
  13697. }
  13698. }
  13699. function refreshUniformsPhysical( uniforms, material ) {
  13700. uniforms.clearCoat.value = material.clearCoat;
  13701. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  13702. refreshUniformsStandard( uniforms, material );
  13703. }
  13704. function refreshUniformsDepth( uniforms, material ) {
  13705. if ( material.displacementMap ) {
  13706. uniforms.displacementMap.value = material.displacementMap;
  13707. uniforms.displacementScale.value = material.displacementScale;
  13708. uniforms.displacementBias.value = material.displacementBias;
  13709. }
  13710. }
  13711. function refreshUniformsDistance( uniforms, material ) {
  13712. if ( material.displacementMap ) {
  13713. uniforms.displacementMap.value = material.displacementMap;
  13714. uniforms.displacementScale.value = material.displacementScale;
  13715. uniforms.displacementBias.value = material.displacementBias;
  13716. }
  13717. uniforms.referencePosition.value.copy( material.referencePosition );
  13718. uniforms.nearDistance.value = material.nearDistance;
  13719. uniforms.farDistance.value = material.farDistance;
  13720. }
  13721. function refreshUniformsNormal( uniforms, material ) {
  13722. if ( material.bumpMap ) {
  13723. uniforms.bumpMap.value = material.bumpMap;
  13724. uniforms.bumpScale.value = material.bumpScale;
  13725. }
  13726. if ( material.normalMap ) {
  13727. uniforms.normalMap.value = material.normalMap;
  13728. uniforms.normalScale.value.copy( material.normalScale );
  13729. }
  13730. if ( material.displacementMap ) {
  13731. uniforms.displacementMap.value = material.displacementMap;
  13732. uniforms.displacementScale.value = material.displacementScale;
  13733. uniforms.displacementBias.value = material.displacementBias;
  13734. }
  13735. }
  13736. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  13737. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  13738. uniforms.ambientLightColor.needsUpdate = value;
  13739. uniforms.directionalLights.needsUpdate = value;
  13740. uniforms.pointLights.needsUpdate = value;
  13741. uniforms.spotLights.needsUpdate = value;
  13742. uniforms.rectAreaLights.needsUpdate = value;
  13743. uniforms.hemisphereLights.needsUpdate = value;
  13744. }
  13745. // Textures
  13746. function allocTextureUnit() {
  13747. var textureUnit = _usedTextureUnits;
  13748. if ( textureUnit >= capabilities.maxTextures ) {
  13749. console.warn( 'THREE.WebGLRenderer: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  13750. }
  13751. _usedTextureUnits += 1;
  13752. return textureUnit;
  13753. }
  13754. this.allocTextureUnit = allocTextureUnit;
  13755. // this.setTexture2D = setTexture2D;
  13756. this.setTexture2D = ( function () {
  13757. var warned = false;
  13758. // backwards compatibility: peel texture.texture
  13759. return function setTexture2D( texture, slot ) {
  13760. if ( texture && texture.isWebGLRenderTarget ) {
  13761. if ( ! warned ) {
  13762. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  13763. warned = true;
  13764. }
  13765. texture = texture.texture;
  13766. }
  13767. textures.setTexture2D( texture, slot );
  13768. };
  13769. }() );
  13770. this.setTexture = ( function () {
  13771. var warned = false;
  13772. return function setTexture( texture, slot ) {
  13773. if ( ! warned ) {
  13774. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  13775. warned = true;
  13776. }
  13777. textures.setTexture2D( texture, slot );
  13778. };
  13779. }() );
  13780. this.setTextureCube = ( function () {
  13781. var warned = false;
  13782. return function setTextureCube( texture, slot ) {
  13783. // backwards compatibility: peel texture.texture
  13784. if ( texture && texture.isWebGLRenderTargetCube ) {
  13785. if ( ! warned ) {
  13786. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  13787. warned = true;
  13788. }
  13789. texture = texture.texture;
  13790. }
  13791. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  13792. // TODO: unify these code paths
  13793. if ( ( texture && texture.isCubeTexture ) ||
  13794. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13795. // CompressedTexture can have Array in image :/
  13796. // this function alone should take care of cube textures
  13797. textures.setTextureCube( texture, slot );
  13798. } else {
  13799. // assumed: texture property of THREE.WebGLRenderTargetCube
  13800. textures.setTextureCubeDynamic( texture, slot );
  13801. }
  13802. };
  13803. }() );
  13804. this.getRenderTarget = function () {
  13805. return _currentRenderTarget;
  13806. };
  13807. this.setRenderTarget = function ( renderTarget ) {
  13808. _currentRenderTarget = renderTarget;
  13809. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  13810. textures.setupRenderTarget( renderTarget );
  13811. }
  13812. var framebuffer = null;
  13813. var isCube = false;
  13814. if ( renderTarget ) {
  13815. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  13816. if ( renderTarget.isWebGLRenderTargetCube ) {
  13817. framebuffer = __webglFramebuffer[ renderTarget.activeCubeFace ];
  13818. isCube = true;
  13819. } else {
  13820. framebuffer = __webglFramebuffer;
  13821. }
  13822. _currentViewport.copy( renderTarget.viewport );
  13823. _currentScissor.copy( renderTarget.scissor );
  13824. _currentScissorTest = renderTarget.scissorTest;
  13825. } else {
  13826. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  13827. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  13828. _currentScissorTest = _scissorTest;
  13829. }
  13830. if ( _currentFramebuffer !== framebuffer ) {
  13831. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13832. _currentFramebuffer = framebuffer;
  13833. }
  13834. state.viewport( _currentViewport );
  13835. state.scissor( _currentScissor );
  13836. state.setScissorTest( _currentScissorTest );
  13837. if ( isCube ) {
  13838. var textureProperties = properties.get( renderTarget.texture );
  13839. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  13840. }
  13841. };
  13842. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  13843. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  13844. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  13845. return;
  13846. }
  13847. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  13848. if ( framebuffer ) {
  13849. var restore = false;
  13850. if ( framebuffer !== _currentFramebuffer ) {
  13851. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13852. restore = true;
  13853. }
  13854. try {
  13855. var texture = renderTarget.texture;
  13856. var textureFormat = texture.format;
  13857. var textureType = texture.type;
  13858. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  13859. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  13860. return;
  13861. }
  13862. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  13863. ! ( textureType === FloatType && ( extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  13864. ! ( textureType === HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  13865. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  13866. return;
  13867. }
  13868. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  13869. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  13870. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  13871. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  13872. }
  13873. } else {
  13874. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  13875. }
  13876. } finally {
  13877. if ( restore ) {
  13878. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  13879. }
  13880. }
  13881. }
  13882. };
  13883. this.copyFramebufferToTexture = function ( position, texture, level ) {
  13884. var width = texture.image.width;
  13885. var height = texture.image.height;
  13886. var internalFormat = utils.convert( texture.format );
  13887. this.setTexture2D( texture, 0 );
  13888. _gl.copyTexImage2D( _gl.TEXTURE_2D, level || 0, internalFormat, position.x, position.y, width, height, 0 );
  13889. };
  13890. }
  13891. /**
  13892. * @author mrdoob / http://mrdoob.com/
  13893. * @author alteredq / http://alteredqualia.com/
  13894. */
  13895. function FogExp2( color, density ) {
  13896. this.name = '';
  13897. this.color = new Color( color );
  13898. this.density = ( density !== undefined ) ? density : 0.00025;
  13899. }
  13900. FogExp2.prototype.isFogExp2 = true;
  13901. FogExp2.prototype.clone = function () {
  13902. return new FogExp2( this.color.getHex(), this.density );
  13903. };
  13904. FogExp2.prototype.toJSON = function ( /* meta */ ) {
  13905. return {
  13906. type: 'FogExp2',
  13907. color: this.color.getHex(),
  13908. density: this.density
  13909. };
  13910. };
  13911. /**
  13912. * @author mrdoob / http://mrdoob.com/
  13913. * @author alteredq / http://alteredqualia.com/
  13914. */
  13915. function Fog( color, near, far ) {
  13916. this.name = '';
  13917. this.color = new Color( color );
  13918. this.near = ( near !== undefined ) ? near : 1;
  13919. this.far = ( far !== undefined ) ? far : 1000;
  13920. }
  13921. Fog.prototype.isFog = true;
  13922. Fog.prototype.clone = function () {
  13923. return new Fog( this.color.getHex(), this.near, this.far );
  13924. };
  13925. Fog.prototype.toJSON = function ( /* meta */ ) {
  13926. return {
  13927. type: 'Fog',
  13928. color: this.color.getHex(),
  13929. near: this.near,
  13930. far: this.far
  13931. };
  13932. };
  13933. /**
  13934. * @author mrdoob / http://mrdoob.com/
  13935. */
  13936. function Scene() {
  13937. Object3D.call( this );
  13938. this.type = 'Scene';
  13939. this.background = null;
  13940. this.fog = null;
  13941. this.overrideMaterial = null;
  13942. this.autoUpdate = true; // checked by the renderer
  13943. }
  13944. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13945. constructor: Scene,
  13946. copy: function ( source, recursive ) {
  13947. Object3D.prototype.copy.call( this, source, recursive );
  13948. if ( source.background !== null ) this.background = source.background.clone();
  13949. if ( source.fog !== null ) this.fog = source.fog.clone();
  13950. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  13951. this.autoUpdate = source.autoUpdate;
  13952. this.matrixAutoUpdate = source.matrixAutoUpdate;
  13953. return this;
  13954. },
  13955. toJSON: function ( meta ) {
  13956. var data = Object3D.prototype.toJSON.call( this, meta );
  13957. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  13958. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  13959. return data;
  13960. }
  13961. } );
  13962. /**
  13963. * @author alteredq / http://alteredqualia.com/
  13964. *
  13965. * parameters = {
  13966. * color: <hex>,
  13967. * opacity: <float>,
  13968. * map: new THREE.Texture( <Image> ),
  13969. *
  13970. * uvOffset: new THREE.Vector2(),
  13971. * uvScale: new THREE.Vector2()
  13972. * }
  13973. */
  13974. function SpriteMaterial( parameters ) {
  13975. Material.call( this );
  13976. this.type = 'SpriteMaterial';
  13977. this.color = new Color( 0xffffff );
  13978. this.map = null;
  13979. this.rotation = 0;
  13980. this.fog = false;
  13981. this.lights = false;
  13982. this.setValues( parameters );
  13983. }
  13984. SpriteMaterial.prototype = Object.create( Material.prototype );
  13985. SpriteMaterial.prototype.constructor = SpriteMaterial;
  13986. SpriteMaterial.prototype.isSpriteMaterial = true;
  13987. SpriteMaterial.prototype.copy = function ( source ) {
  13988. Material.prototype.copy.call( this, source );
  13989. this.color.copy( source.color );
  13990. this.map = source.map;
  13991. this.rotation = source.rotation;
  13992. return this;
  13993. };
  13994. /**
  13995. * @author mikael emtinger / http://gomo.se/
  13996. * @author alteredq / http://alteredqualia.com/
  13997. */
  13998. function Sprite( material ) {
  13999. Object3D.call( this );
  14000. this.type = 'Sprite';
  14001. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  14002. this.center = new Vector2( 0.5, 0.5 );
  14003. }
  14004. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14005. constructor: Sprite,
  14006. isSprite: true,
  14007. raycast: ( function () {
  14008. var intersectPoint = new Vector3();
  14009. var worldPosition = new Vector3();
  14010. var worldScale = new Vector3();
  14011. return function raycast( raycaster, intersects ) {
  14012. worldPosition.setFromMatrixPosition( this.matrixWorld );
  14013. raycaster.ray.closestPointToPoint( worldPosition, intersectPoint );
  14014. worldScale.setFromMatrixScale( this.matrixWorld );
  14015. var guessSizeSq = worldScale.x * worldScale.y / 4;
  14016. if ( worldPosition.distanceToSquared( intersectPoint ) > guessSizeSq ) return;
  14017. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  14018. if ( distance < raycaster.near || distance > raycaster.far ) return;
  14019. intersects.push( {
  14020. distance: distance,
  14021. point: intersectPoint.clone(),
  14022. face: null,
  14023. object: this
  14024. } );
  14025. };
  14026. }() ),
  14027. clone: function () {
  14028. return new this.constructor( this.material ).copy( this );
  14029. },
  14030. copy: function ( source ) {
  14031. Object3D.prototype.copy.call( this, source );
  14032. if ( source.center !== undefined ) this.center.copy( source.center );
  14033. return this;
  14034. }
  14035. } );
  14036. /**
  14037. * @author mikael emtinger / http://gomo.se/
  14038. * @author alteredq / http://alteredqualia.com/
  14039. * @author mrdoob / http://mrdoob.com/
  14040. */
  14041. function LOD() {
  14042. Object3D.call( this );
  14043. this.type = 'LOD';
  14044. Object.defineProperties( this, {
  14045. levels: {
  14046. enumerable: true,
  14047. value: []
  14048. }
  14049. } );
  14050. }
  14051. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14052. constructor: LOD,
  14053. copy: function ( source ) {
  14054. Object3D.prototype.copy.call( this, source, false );
  14055. var levels = source.levels;
  14056. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  14057. var level = levels[ i ];
  14058. this.addLevel( level.object.clone(), level.distance );
  14059. }
  14060. return this;
  14061. },
  14062. addLevel: function ( object, distance ) {
  14063. if ( distance === undefined ) distance = 0;
  14064. distance = Math.abs( distance );
  14065. var levels = this.levels;
  14066. for ( var l = 0; l < levels.length; l ++ ) {
  14067. if ( distance < levels[ l ].distance ) {
  14068. break;
  14069. }
  14070. }
  14071. levels.splice( l, 0, { distance: distance, object: object } );
  14072. this.add( object );
  14073. },
  14074. getObjectForDistance: function ( distance ) {
  14075. var levels = this.levels;
  14076. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  14077. if ( distance < levels[ i ].distance ) {
  14078. break;
  14079. }
  14080. }
  14081. return levels[ i - 1 ].object;
  14082. },
  14083. raycast: ( function () {
  14084. var matrixPosition = new Vector3();
  14085. return function raycast( raycaster, intersects ) {
  14086. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  14087. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  14088. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  14089. };
  14090. }() ),
  14091. update: function () {
  14092. var v1 = new Vector3();
  14093. var v2 = new Vector3();
  14094. return function update( camera ) {
  14095. var levels = this.levels;
  14096. if ( levels.length > 1 ) {
  14097. v1.setFromMatrixPosition( camera.matrixWorld );
  14098. v2.setFromMatrixPosition( this.matrixWorld );
  14099. var distance = v1.distanceTo( v2 );
  14100. levels[ 0 ].object.visible = true;
  14101. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  14102. if ( distance >= levels[ i ].distance ) {
  14103. levels[ i - 1 ].object.visible = false;
  14104. levels[ i ].object.visible = true;
  14105. } else {
  14106. break;
  14107. }
  14108. }
  14109. for ( ; i < l; i ++ ) {
  14110. levels[ i ].object.visible = false;
  14111. }
  14112. }
  14113. };
  14114. }(),
  14115. toJSON: function ( meta ) {
  14116. var data = Object3D.prototype.toJSON.call( this, meta );
  14117. data.object.levels = [];
  14118. var levels = this.levels;
  14119. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  14120. var level = levels[ i ];
  14121. data.object.levels.push( {
  14122. object: level.object.uuid,
  14123. distance: level.distance
  14124. } );
  14125. }
  14126. return data;
  14127. }
  14128. } );
  14129. /**
  14130. * @author mikael emtinger / http://gomo.se/
  14131. * @author alteredq / http://alteredqualia.com/
  14132. * @author michael guerrero / http://realitymeltdown.com
  14133. * @author ikerr / http://verold.com
  14134. */
  14135. function Skeleton( bones, boneInverses ) {
  14136. // copy the bone array
  14137. bones = bones || [];
  14138. this.bones = bones.slice( 0 );
  14139. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  14140. // use the supplied bone inverses or calculate the inverses
  14141. if ( boneInverses === undefined ) {
  14142. this.calculateInverses();
  14143. } else {
  14144. if ( this.bones.length === boneInverses.length ) {
  14145. this.boneInverses = boneInverses.slice( 0 );
  14146. } else {
  14147. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  14148. this.boneInverses = [];
  14149. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  14150. this.boneInverses.push( new Matrix4() );
  14151. }
  14152. }
  14153. }
  14154. }
  14155. Object.assign( Skeleton.prototype, {
  14156. calculateInverses: function () {
  14157. this.boneInverses = [];
  14158. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  14159. var inverse = new Matrix4();
  14160. if ( this.bones[ i ] ) {
  14161. inverse.getInverse( this.bones[ i ].matrixWorld );
  14162. }
  14163. this.boneInverses.push( inverse );
  14164. }
  14165. },
  14166. pose: function () {
  14167. var bone, i, il;
  14168. // recover the bind-time world matrices
  14169. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  14170. bone = this.bones[ i ];
  14171. if ( bone ) {
  14172. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  14173. }
  14174. }
  14175. // compute the local matrices, positions, rotations and scales
  14176. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  14177. bone = this.bones[ i ];
  14178. if ( bone ) {
  14179. if ( bone.parent && bone.parent.isBone ) {
  14180. bone.matrix.getInverse( bone.parent.matrixWorld );
  14181. bone.matrix.multiply( bone.matrixWorld );
  14182. } else {
  14183. bone.matrix.copy( bone.matrixWorld );
  14184. }
  14185. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  14186. }
  14187. }
  14188. },
  14189. update: ( function () {
  14190. var offsetMatrix = new Matrix4();
  14191. var identityMatrix = new Matrix4();
  14192. return function update() {
  14193. var bones = this.bones;
  14194. var boneInverses = this.boneInverses;
  14195. var boneMatrices = this.boneMatrices;
  14196. var boneTexture = this.boneTexture;
  14197. // flatten bone matrices to array
  14198. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  14199. // compute the offset between the current and the original transform
  14200. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  14201. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  14202. offsetMatrix.toArray( boneMatrices, i * 16 );
  14203. }
  14204. if ( boneTexture !== undefined ) {
  14205. boneTexture.needsUpdate = true;
  14206. }
  14207. };
  14208. } )(),
  14209. clone: function () {
  14210. return new Skeleton( this.bones, this.boneInverses );
  14211. },
  14212. getBoneByName: function ( name ) {
  14213. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  14214. var bone = this.bones[ i ];
  14215. if ( bone.name === name ) {
  14216. return bone;
  14217. }
  14218. }
  14219. return undefined;
  14220. }
  14221. } );
  14222. /**
  14223. * @author mikael emtinger / http://gomo.se/
  14224. * @author alteredq / http://alteredqualia.com/
  14225. * @author ikerr / http://verold.com
  14226. */
  14227. function Bone() {
  14228. Object3D.call( this );
  14229. this.type = 'Bone';
  14230. }
  14231. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14232. constructor: Bone,
  14233. isBone: true
  14234. } );
  14235. /**
  14236. * @author mikael emtinger / http://gomo.se/
  14237. * @author alteredq / http://alteredqualia.com/
  14238. * @author ikerr / http://verold.com
  14239. */
  14240. function SkinnedMesh( geometry, material ) {
  14241. Mesh.call( this, geometry, material );
  14242. this.type = 'SkinnedMesh';
  14243. this.bindMode = 'attached';
  14244. this.bindMatrix = new Matrix4();
  14245. this.bindMatrixInverse = new Matrix4();
  14246. var bones = this.initBones();
  14247. var skeleton = new Skeleton( bones );
  14248. this.bind( skeleton, this.matrixWorld );
  14249. this.normalizeSkinWeights();
  14250. }
  14251. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  14252. constructor: SkinnedMesh,
  14253. isSkinnedMesh: true,
  14254. initBones: function () {
  14255. var bones = [], bone, gbone;
  14256. var i, il;
  14257. if ( this.geometry && this.geometry.bones !== undefined ) {
  14258. // first, create array of 'Bone' objects from geometry data
  14259. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  14260. gbone = this.geometry.bones[ i ];
  14261. // create new 'Bone' object
  14262. bone = new Bone();
  14263. bones.push( bone );
  14264. // apply values
  14265. bone.name = gbone.name;
  14266. bone.position.fromArray( gbone.pos );
  14267. bone.quaternion.fromArray( gbone.rotq );
  14268. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  14269. }
  14270. // second, create bone hierarchy
  14271. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  14272. gbone = this.geometry.bones[ i ];
  14273. if ( ( gbone.parent !== - 1 ) && ( gbone.parent !== null ) && ( bones[ gbone.parent ] !== undefined ) ) {
  14274. // subsequent bones in the hierarchy
  14275. bones[ gbone.parent ].add( bones[ i ] );
  14276. } else {
  14277. // topmost bone, immediate child of the skinned mesh
  14278. this.add( bones[ i ] );
  14279. }
  14280. }
  14281. }
  14282. // now the bones are part of the scene graph and children of the skinned mesh.
  14283. // let's update the corresponding matrices
  14284. this.updateMatrixWorld( true );
  14285. return bones;
  14286. },
  14287. bind: function ( skeleton, bindMatrix ) {
  14288. this.skeleton = skeleton;
  14289. if ( bindMatrix === undefined ) {
  14290. this.updateMatrixWorld( true );
  14291. this.skeleton.calculateInverses();
  14292. bindMatrix = this.matrixWorld;
  14293. }
  14294. this.bindMatrix.copy( bindMatrix );
  14295. this.bindMatrixInverse.getInverse( bindMatrix );
  14296. },
  14297. pose: function () {
  14298. this.skeleton.pose();
  14299. },
  14300. normalizeSkinWeights: function () {
  14301. var scale, i;
  14302. if ( this.geometry && this.geometry.isGeometry ) {
  14303. for ( i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  14304. var sw = this.geometry.skinWeights[ i ];
  14305. scale = 1.0 / sw.manhattanLength();
  14306. if ( scale !== Infinity ) {
  14307. sw.multiplyScalar( scale );
  14308. } else {
  14309. sw.set( 1, 0, 0, 0 ); // do something reasonable
  14310. }
  14311. }
  14312. } else if ( this.geometry && this.geometry.isBufferGeometry ) {
  14313. var vec = new Vector4();
  14314. var skinWeight = this.geometry.attributes.skinWeight;
  14315. for ( i = 0; i < skinWeight.count; i ++ ) {
  14316. vec.x = skinWeight.getX( i );
  14317. vec.y = skinWeight.getY( i );
  14318. vec.z = skinWeight.getZ( i );
  14319. vec.w = skinWeight.getW( i );
  14320. scale = 1.0 / vec.manhattanLength();
  14321. if ( scale !== Infinity ) {
  14322. vec.multiplyScalar( scale );
  14323. } else {
  14324. vec.set( 1, 0, 0, 0 ); // do something reasonable
  14325. }
  14326. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  14327. }
  14328. }
  14329. },
  14330. updateMatrixWorld: function ( force ) {
  14331. Mesh.prototype.updateMatrixWorld.call( this, force );
  14332. if ( this.bindMode === 'attached' ) {
  14333. this.bindMatrixInverse.getInverse( this.matrixWorld );
  14334. } else if ( this.bindMode === 'detached' ) {
  14335. this.bindMatrixInverse.getInverse( this.bindMatrix );
  14336. } else {
  14337. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  14338. }
  14339. },
  14340. clone: function () {
  14341. return new this.constructor( this.geometry, this.material ).copy( this );
  14342. }
  14343. } );
  14344. /**
  14345. * @author mrdoob / http://mrdoob.com/
  14346. * @author alteredq / http://alteredqualia.com/
  14347. *
  14348. * parameters = {
  14349. * color: <hex>,
  14350. * opacity: <float>,
  14351. *
  14352. * linewidth: <float>,
  14353. * linecap: "round",
  14354. * linejoin: "round"
  14355. * }
  14356. */
  14357. function LineBasicMaterial( parameters ) {
  14358. Material.call( this );
  14359. this.type = 'LineBasicMaterial';
  14360. this.color = new Color( 0xffffff );
  14361. this.linewidth = 1;
  14362. this.linecap = 'round';
  14363. this.linejoin = 'round';
  14364. this.lights = false;
  14365. this.setValues( parameters );
  14366. }
  14367. LineBasicMaterial.prototype = Object.create( Material.prototype );
  14368. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  14369. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  14370. LineBasicMaterial.prototype.copy = function ( source ) {
  14371. Material.prototype.copy.call( this, source );
  14372. this.color.copy( source.color );
  14373. this.linewidth = source.linewidth;
  14374. this.linecap = source.linecap;
  14375. this.linejoin = source.linejoin;
  14376. return this;
  14377. };
  14378. /**
  14379. * @author mrdoob / http://mrdoob.com/
  14380. */
  14381. function Line( geometry, material, mode ) {
  14382. if ( mode === 1 ) {
  14383. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  14384. return new LineSegments( geometry, material );
  14385. }
  14386. Object3D.call( this );
  14387. this.type = 'Line';
  14388. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  14389. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  14390. }
  14391. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14392. constructor: Line,
  14393. isLine: true,
  14394. raycast: ( function () {
  14395. var inverseMatrix = new Matrix4();
  14396. var ray = new Ray();
  14397. var sphere = new Sphere();
  14398. return function raycast( raycaster, intersects ) {
  14399. var precision = raycaster.linePrecision;
  14400. var precisionSq = precision * precision;
  14401. var geometry = this.geometry;
  14402. var matrixWorld = this.matrixWorld;
  14403. // Checking boundingSphere distance to ray
  14404. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  14405. sphere.copy( geometry.boundingSphere );
  14406. sphere.applyMatrix4( matrixWorld );
  14407. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  14408. //
  14409. inverseMatrix.getInverse( matrixWorld );
  14410. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  14411. var vStart = new Vector3();
  14412. var vEnd = new Vector3();
  14413. var interSegment = new Vector3();
  14414. var interRay = new Vector3();
  14415. var step = ( this && this.isLineSegments ) ? 2 : 1;
  14416. if ( geometry.isBufferGeometry ) {
  14417. var index = geometry.index;
  14418. var attributes = geometry.attributes;
  14419. var positions = attributes.position.array;
  14420. if ( index !== null ) {
  14421. var indices = index.array;
  14422. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  14423. var a = indices[ i ];
  14424. var b = indices[ i + 1 ];
  14425. vStart.fromArray( positions, a * 3 );
  14426. vEnd.fromArray( positions, b * 3 );
  14427. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14428. if ( distSq > precisionSq ) continue;
  14429. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14430. var distance = raycaster.ray.origin.distanceTo( interRay );
  14431. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14432. intersects.push( {
  14433. distance: distance,
  14434. // What do we want? intersection point on the ray or on the segment??
  14435. // point: raycaster.ray.at( distance ),
  14436. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14437. index: i,
  14438. face: null,
  14439. faceIndex: null,
  14440. object: this
  14441. } );
  14442. }
  14443. } else {
  14444. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  14445. vStart.fromArray( positions, 3 * i );
  14446. vEnd.fromArray( positions, 3 * i + 3 );
  14447. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14448. if ( distSq > precisionSq ) continue;
  14449. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14450. var distance = raycaster.ray.origin.distanceTo( interRay );
  14451. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14452. intersects.push( {
  14453. distance: distance,
  14454. // What do we want? intersection point on the ray or on the segment??
  14455. // point: raycaster.ray.at( distance ),
  14456. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14457. index: i,
  14458. face: null,
  14459. faceIndex: null,
  14460. object: this
  14461. } );
  14462. }
  14463. }
  14464. } else if ( geometry.isGeometry ) {
  14465. var vertices = geometry.vertices;
  14466. var nbVertices = vertices.length;
  14467. for ( var i = 0; i < nbVertices - 1; i += step ) {
  14468. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  14469. if ( distSq > precisionSq ) continue;
  14470. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14471. var distance = raycaster.ray.origin.distanceTo( interRay );
  14472. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14473. intersects.push( {
  14474. distance: distance,
  14475. // What do we want? intersection point on the ray or on the segment??
  14476. // point: raycaster.ray.at( distance ),
  14477. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14478. index: i,
  14479. face: null,
  14480. faceIndex: null,
  14481. object: this
  14482. } );
  14483. }
  14484. }
  14485. };
  14486. }() ),
  14487. clone: function () {
  14488. return new this.constructor( this.geometry, this.material ).copy( this );
  14489. }
  14490. } );
  14491. /**
  14492. * @author mrdoob / http://mrdoob.com/
  14493. */
  14494. function LineSegments( geometry, material ) {
  14495. Line.call( this, geometry, material );
  14496. this.type = 'LineSegments';
  14497. }
  14498. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  14499. constructor: LineSegments,
  14500. isLineSegments: true
  14501. } );
  14502. /**
  14503. * @author mgreter / http://github.com/mgreter
  14504. */
  14505. function LineLoop( geometry, material ) {
  14506. Line.call( this, geometry, material );
  14507. this.type = 'LineLoop';
  14508. }
  14509. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  14510. constructor: LineLoop,
  14511. isLineLoop: true,
  14512. } );
  14513. /**
  14514. * @author mrdoob / http://mrdoob.com/
  14515. * @author alteredq / http://alteredqualia.com/
  14516. *
  14517. * parameters = {
  14518. * color: <hex>,
  14519. * opacity: <float>,
  14520. * map: new THREE.Texture( <Image> ),
  14521. *
  14522. * size: <float>,
  14523. * sizeAttenuation: <bool>
  14524. * }
  14525. */
  14526. function PointsMaterial( parameters ) {
  14527. Material.call( this );
  14528. this.type = 'PointsMaterial';
  14529. this.color = new Color( 0xffffff );
  14530. this.map = null;
  14531. this.size = 1;
  14532. this.sizeAttenuation = true;
  14533. this.lights = false;
  14534. this.setValues( parameters );
  14535. }
  14536. PointsMaterial.prototype = Object.create( Material.prototype );
  14537. PointsMaterial.prototype.constructor = PointsMaterial;
  14538. PointsMaterial.prototype.isPointsMaterial = true;
  14539. PointsMaterial.prototype.copy = function ( source ) {
  14540. Material.prototype.copy.call( this, source );
  14541. this.color.copy( source.color );
  14542. this.map = source.map;
  14543. this.size = source.size;
  14544. this.sizeAttenuation = source.sizeAttenuation;
  14545. return this;
  14546. };
  14547. /**
  14548. * @author alteredq / http://alteredqualia.com/
  14549. */
  14550. function Points( geometry, material ) {
  14551. Object3D.call( this );
  14552. this.type = 'Points';
  14553. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  14554. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  14555. }
  14556. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14557. constructor: Points,
  14558. isPoints: true,
  14559. raycast: ( function () {
  14560. var inverseMatrix = new Matrix4();
  14561. var ray = new Ray();
  14562. var sphere = new Sphere();
  14563. return function raycast( raycaster, intersects ) {
  14564. var object = this;
  14565. var geometry = this.geometry;
  14566. var matrixWorld = this.matrixWorld;
  14567. var threshold = raycaster.params.Points.threshold;
  14568. // Checking boundingSphere distance to ray
  14569. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  14570. sphere.copy( geometry.boundingSphere );
  14571. sphere.applyMatrix4( matrixWorld );
  14572. sphere.radius += threshold;
  14573. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  14574. //
  14575. inverseMatrix.getInverse( matrixWorld );
  14576. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  14577. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  14578. var localThresholdSq = localThreshold * localThreshold;
  14579. var position = new Vector3();
  14580. function testPoint( point, index ) {
  14581. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  14582. if ( rayPointDistanceSq < localThresholdSq ) {
  14583. var intersectPoint = ray.closestPointToPoint( point );
  14584. intersectPoint.applyMatrix4( matrixWorld );
  14585. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  14586. if ( distance < raycaster.near || distance > raycaster.far ) return;
  14587. intersects.push( {
  14588. distance: distance,
  14589. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  14590. point: intersectPoint.clone(),
  14591. index: index,
  14592. face: null,
  14593. object: object
  14594. } );
  14595. }
  14596. }
  14597. if ( geometry.isBufferGeometry ) {
  14598. var index = geometry.index;
  14599. var attributes = geometry.attributes;
  14600. var positions = attributes.position.array;
  14601. if ( index !== null ) {
  14602. var indices = index.array;
  14603. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  14604. var a = indices[ i ];
  14605. position.fromArray( positions, a * 3 );
  14606. testPoint( position, a );
  14607. }
  14608. } else {
  14609. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  14610. position.fromArray( positions, i * 3 );
  14611. testPoint( position, i );
  14612. }
  14613. }
  14614. } else {
  14615. var vertices = geometry.vertices;
  14616. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  14617. testPoint( vertices[ i ], i );
  14618. }
  14619. }
  14620. };
  14621. }() ),
  14622. clone: function () {
  14623. return new this.constructor( this.geometry, this.material ).copy( this );
  14624. }
  14625. } );
  14626. /**
  14627. * @author mrdoob / http://mrdoob.com/
  14628. */
  14629. function Group() {
  14630. Object3D.call( this );
  14631. this.type = 'Group';
  14632. }
  14633. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14634. constructor: Group,
  14635. isGroup: true
  14636. } );
  14637. /**
  14638. * @author mrdoob / http://mrdoob.com/
  14639. */
  14640. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  14641. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  14642. this.generateMipmaps = false;
  14643. }
  14644. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  14645. constructor: VideoTexture,
  14646. isVideoTexture: true,
  14647. update: function () {
  14648. var video = this.image;
  14649. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  14650. this.needsUpdate = true;
  14651. }
  14652. }
  14653. } );
  14654. /**
  14655. * @author alteredq / http://alteredqualia.com/
  14656. */
  14657. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  14658. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  14659. this.image = { width: width, height: height };
  14660. this.mipmaps = mipmaps;
  14661. // no flipping for cube textures
  14662. // (also flipping doesn't work for compressed textures )
  14663. this.flipY = false;
  14664. // can't generate mipmaps for compressed textures
  14665. // mips must be embedded in DDS files
  14666. this.generateMipmaps = false;
  14667. }
  14668. CompressedTexture.prototype = Object.create( Texture.prototype );
  14669. CompressedTexture.prototype.constructor = CompressedTexture;
  14670. CompressedTexture.prototype.isCompressedTexture = true;
  14671. /**
  14672. * @author Matt DesLauriers / @mattdesl
  14673. * @author atix / arthursilber.de
  14674. */
  14675. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  14676. format = format !== undefined ? format : DepthFormat;
  14677. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  14678. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  14679. }
  14680. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  14681. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  14682. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  14683. this.image = { width: width, height: height };
  14684. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  14685. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  14686. this.flipY = false;
  14687. this.generateMipmaps = false;
  14688. }
  14689. DepthTexture.prototype = Object.create( Texture.prototype );
  14690. DepthTexture.prototype.constructor = DepthTexture;
  14691. DepthTexture.prototype.isDepthTexture = true;
  14692. /**
  14693. * @author mrdoob / http://mrdoob.com/
  14694. * @author Mugen87 / https://github.com/Mugen87
  14695. */
  14696. function WireframeGeometry( geometry ) {
  14697. BufferGeometry.call( this );
  14698. this.type = 'WireframeGeometry';
  14699. // buffer
  14700. var vertices = [];
  14701. // helper variables
  14702. var i, j, l, o, ol;
  14703. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  14704. var key, keys = [ 'a', 'b', 'c' ];
  14705. var vertex;
  14706. // different logic for Geometry and BufferGeometry
  14707. if ( geometry && geometry.isGeometry ) {
  14708. // create a data structure that contains all edges without duplicates
  14709. var faces = geometry.faces;
  14710. for ( i = 0, l = faces.length; i < l; i ++ ) {
  14711. var face = faces[ i ];
  14712. for ( j = 0; j < 3; j ++ ) {
  14713. edge1 = face[ keys[ j ] ];
  14714. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  14715. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  14716. edge[ 1 ] = Math.max( edge1, edge2 );
  14717. key = edge[ 0 ] + ',' + edge[ 1 ];
  14718. if ( edges[ key ] === undefined ) {
  14719. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  14720. }
  14721. }
  14722. }
  14723. // generate vertices
  14724. for ( key in edges ) {
  14725. e = edges[ key ];
  14726. vertex = geometry.vertices[ e.index1 ];
  14727. vertices.push( vertex.x, vertex.y, vertex.z );
  14728. vertex = geometry.vertices[ e.index2 ];
  14729. vertices.push( vertex.x, vertex.y, vertex.z );
  14730. }
  14731. } else if ( geometry && geometry.isBufferGeometry ) {
  14732. var position, indices, groups;
  14733. var group, start, count;
  14734. var index1, index2;
  14735. vertex = new Vector3();
  14736. if ( geometry.index !== null ) {
  14737. // indexed BufferGeometry
  14738. position = geometry.attributes.position;
  14739. indices = geometry.index;
  14740. groups = geometry.groups;
  14741. if ( groups.length === 0 ) {
  14742. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  14743. }
  14744. // create a data structure that contains all eges without duplicates
  14745. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  14746. group = groups[ o ];
  14747. start = group.start;
  14748. count = group.count;
  14749. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  14750. for ( j = 0; j < 3; j ++ ) {
  14751. edge1 = indices.getX( i + j );
  14752. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  14753. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  14754. edge[ 1 ] = Math.max( edge1, edge2 );
  14755. key = edge[ 0 ] + ',' + edge[ 1 ];
  14756. if ( edges[ key ] === undefined ) {
  14757. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  14758. }
  14759. }
  14760. }
  14761. }
  14762. // generate vertices
  14763. for ( key in edges ) {
  14764. e = edges[ key ];
  14765. vertex.fromBufferAttribute( position, e.index1 );
  14766. vertices.push( vertex.x, vertex.y, vertex.z );
  14767. vertex.fromBufferAttribute( position, e.index2 );
  14768. vertices.push( vertex.x, vertex.y, vertex.z );
  14769. }
  14770. } else {
  14771. // non-indexed BufferGeometry
  14772. position = geometry.attributes.position;
  14773. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  14774. for ( j = 0; j < 3; j ++ ) {
  14775. // three edges per triangle, an edge is represented as (index1, index2)
  14776. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  14777. index1 = 3 * i + j;
  14778. vertex.fromBufferAttribute( position, index1 );
  14779. vertices.push( vertex.x, vertex.y, vertex.z );
  14780. index2 = 3 * i + ( ( j + 1 ) % 3 );
  14781. vertex.fromBufferAttribute( position, index2 );
  14782. vertices.push( vertex.x, vertex.y, vertex.z );
  14783. }
  14784. }
  14785. }
  14786. }
  14787. // build geometry
  14788. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  14789. }
  14790. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  14791. WireframeGeometry.prototype.constructor = WireframeGeometry;
  14792. /**
  14793. * @author zz85 / https://github.com/zz85
  14794. * @author Mugen87 / https://github.com/Mugen87
  14795. *
  14796. * Parametric Surfaces Geometry
  14797. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  14798. */
  14799. // ParametricGeometry
  14800. function ParametricGeometry( func, slices, stacks ) {
  14801. Geometry.call( this );
  14802. this.type = 'ParametricGeometry';
  14803. this.parameters = {
  14804. func: func,
  14805. slices: slices,
  14806. stacks: stacks
  14807. };
  14808. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  14809. this.mergeVertices();
  14810. }
  14811. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  14812. ParametricGeometry.prototype.constructor = ParametricGeometry;
  14813. // ParametricBufferGeometry
  14814. function ParametricBufferGeometry( func, slices, stacks ) {
  14815. BufferGeometry.call( this );
  14816. this.type = 'ParametricBufferGeometry';
  14817. this.parameters = {
  14818. func: func,
  14819. slices: slices,
  14820. stacks: stacks
  14821. };
  14822. // buffers
  14823. var indices = [];
  14824. var vertices = [];
  14825. var normals = [];
  14826. var uvs = [];
  14827. var EPS = 0.00001;
  14828. var normal = new Vector3();
  14829. var p0 = new Vector3(), p1 = new Vector3();
  14830. var pu = new Vector3(), pv = new Vector3();
  14831. var i, j;
  14832. // generate vertices, normals and uvs
  14833. var sliceCount = slices + 1;
  14834. for ( i = 0; i <= stacks; i ++ ) {
  14835. var v = i / stacks;
  14836. for ( j = 0; j <= slices; j ++ ) {
  14837. var u = j / slices;
  14838. // vertex
  14839. p0 = func( u, v, p0 );
  14840. vertices.push( p0.x, p0.y, p0.z );
  14841. // normal
  14842. // approximate tangent vectors via finite differences
  14843. if ( u - EPS >= 0 ) {
  14844. p1 = func( u - EPS, v, p1 );
  14845. pu.subVectors( p0, p1 );
  14846. } else {
  14847. p1 = func( u + EPS, v, p1 );
  14848. pu.subVectors( p1, p0 );
  14849. }
  14850. if ( v - EPS >= 0 ) {
  14851. p1 = func( u, v - EPS, p1 );
  14852. pv.subVectors( p0, p1 );
  14853. } else {
  14854. p1 = func( u, v + EPS, p1 );
  14855. pv.subVectors( p1, p0 );
  14856. }
  14857. // cross product of tangent vectors returns surface normal
  14858. normal.crossVectors( pu, pv ).normalize();
  14859. normals.push( normal.x, normal.y, normal.z );
  14860. // uv
  14861. uvs.push( u, v );
  14862. }
  14863. }
  14864. // generate indices
  14865. for ( i = 0; i < stacks; i ++ ) {
  14866. for ( j = 0; j < slices; j ++ ) {
  14867. var a = i * sliceCount + j;
  14868. var b = i * sliceCount + j + 1;
  14869. var c = ( i + 1 ) * sliceCount + j + 1;
  14870. var d = ( i + 1 ) * sliceCount + j;
  14871. // faces one and two
  14872. indices.push( a, b, d );
  14873. indices.push( b, c, d );
  14874. }
  14875. }
  14876. // build geometry
  14877. this.setIndex( indices );
  14878. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  14879. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  14880. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  14881. }
  14882. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  14883. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  14884. /**
  14885. * @author clockworkgeek / https://github.com/clockworkgeek
  14886. * @author timothypratley / https://github.com/timothypratley
  14887. * @author WestLangley / http://github.com/WestLangley
  14888. * @author Mugen87 / https://github.com/Mugen87
  14889. */
  14890. // PolyhedronGeometry
  14891. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  14892. Geometry.call( this );
  14893. this.type = 'PolyhedronGeometry';
  14894. this.parameters = {
  14895. vertices: vertices,
  14896. indices: indices,
  14897. radius: radius,
  14898. detail: detail
  14899. };
  14900. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  14901. this.mergeVertices();
  14902. }
  14903. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  14904. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  14905. // PolyhedronBufferGeometry
  14906. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  14907. BufferGeometry.call( this );
  14908. this.type = 'PolyhedronBufferGeometry';
  14909. this.parameters = {
  14910. vertices: vertices,
  14911. indices: indices,
  14912. radius: radius,
  14913. detail: detail
  14914. };
  14915. radius = radius || 1;
  14916. detail = detail || 0;
  14917. // default buffer data
  14918. var vertexBuffer = [];
  14919. var uvBuffer = [];
  14920. // the subdivision creates the vertex buffer data
  14921. subdivide( detail );
  14922. // all vertices should lie on a conceptual sphere with a given radius
  14923. appplyRadius( radius );
  14924. // finally, create the uv data
  14925. generateUVs();
  14926. // build non-indexed geometry
  14927. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  14928. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  14929. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  14930. if ( detail === 0 ) {
  14931. this.computeVertexNormals(); // flat normals
  14932. } else {
  14933. this.normalizeNormals(); // smooth normals
  14934. }
  14935. // helper functions
  14936. function subdivide( detail ) {
  14937. var a = new Vector3();
  14938. var b = new Vector3();
  14939. var c = new Vector3();
  14940. // iterate over all faces and apply a subdivison with the given detail value
  14941. for ( var i = 0; i < indices.length; i += 3 ) {
  14942. // get the vertices of the face
  14943. getVertexByIndex( indices[ i + 0 ], a );
  14944. getVertexByIndex( indices[ i + 1 ], b );
  14945. getVertexByIndex( indices[ i + 2 ], c );
  14946. // perform subdivision
  14947. subdivideFace( a, b, c, detail );
  14948. }
  14949. }
  14950. function subdivideFace( a, b, c, detail ) {
  14951. var cols = Math.pow( 2, detail );
  14952. // we use this multidimensional array as a data structure for creating the subdivision
  14953. var v = [];
  14954. var i, j;
  14955. // construct all of the vertices for this subdivision
  14956. for ( i = 0; i <= cols; i ++ ) {
  14957. v[ i ] = [];
  14958. var aj = a.clone().lerp( c, i / cols );
  14959. var bj = b.clone().lerp( c, i / cols );
  14960. var rows = cols - i;
  14961. for ( j = 0; j <= rows; j ++ ) {
  14962. if ( j === 0 && i === cols ) {
  14963. v[ i ][ j ] = aj;
  14964. } else {
  14965. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  14966. }
  14967. }
  14968. }
  14969. // construct all of the faces
  14970. for ( i = 0; i < cols; i ++ ) {
  14971. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  14972. var k = Math.floor( j / 2 );
  14973. if ( j % 2 === 0 ) {
  14974. pushVertex( v[ i ][ k + 1 ] );
  14975. pushVertex( v[ i + 1 ][ k ] );
  14976. pushVertex( v[ i ][ k ] );
  14977. } else {
  14978. pushVertex( v[ i ][ k + 1 ] );
  14979. pushVertex( v[ i + 1 ][ k + 1 ] );
  14980. pushVertex( v[ i + 1 ][ k ] );
  14981. }
  14982. }
  14983. }
  14984. }
  14985. function appplyRadius( radius ) {
  14986. var vertex = new Vector3();
  14987. // iterate over the entire buffer and apply the radius to each vertex
  14988. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  14989. vertex.x = vertexBuffer[ i + 0 ];
  14990. vertex.y = vertexBuffer[ i + 1 ];
  14991. vertex.z = vertexBuffer[ i + 2 ];
  14992. vertex.normalize().multiplyScalar( radius );
  14993. vertexBuffer[ i + 0 ] = vertex.x;
  14994. vertexBuffer[ i + 1 ] = vertex.y;
  14995. vertexBuffer[ i + 2 ] = vertex.z;
  14996. }
  14997. }
  14998. function generateUVs() {
  14999. var vertex = new Vector3();
  15000. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  15001. vertex.x = vertexBuffer[ i + 0 ];
  15002. vertex.y = vertexBuffer[ i + 1 ];
  15003. vertex.z = vertexBuffer[ i + 2 ];
  15004. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  15005. var v = inclination( vertex ) / Math.PI + 0.5;
  15006. uvBuffer.push( u, 1 - v );
  15007. }
  15008. correctUVs();
  15009. correctSeam();
  15010. }
  15011. function correctSeam() {
  15012. // handle case when face straddles the seam, see #3269
  15013. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  15014. // uv data of a single face
  15015. var x0 = uvBuffer[ i + 0 ];
  15016. var x1 = uvBuffer[ i + 2 ];
  15017. var x2 = uvBuffer[ i + 4 ];
  15018. var max = Math.max( x0, x1, x2 );
  15019. var min = Math.min( x0, x1, x2 );
  15020. // 0.9 is somewhat arbitrary
  15021. if ( max > 0.9 && min < 0.1 ) {
  15022. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  15023. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  15024. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  15025. }
  15026. }
  15027. }
  15028. function pushVertex( vertex ) {
  15029. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  15030. }
  15031. function getVertexByIndex( index, vertex ) {
  15032. var stride = index * 3;
  15033. vertex.x = vertices[ stride + 0 ];
  15034. vertex.y = vertices[ stride + 1 ];
  15035. vertex.z = vertices[ stride + 2 ];
  15036. }
  15037. function correctUVs() {
  15038. var a = new Vector3();
  15039. var b = new Vector3();
  15040. var c = new Vector3();
  15041. var centroid = new Vector3();
  15042. var uvA = new Vector2();
  15043. var uvB = new Vector2();
  15044. var uvC = new Vector2();
  15045. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  15046. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  15047. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  15048. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  15049. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  15050. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  15051. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  15052. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  15053. var azi = azimuth( centroid );
  15054. correctUV( uvA, j + 0, a, azi );
  15055. correctUV( uvB, j + 2, b, azi );
  15056. correctUV( uvC, j + 4, c, azi );
  15057. }
  15058. }
  15059. function correctUV( uv, stride, vector, azimuth ) {
  15060. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  15061. uvBuffer[ stride ] = uv.x - 1;
  15062. }
  15063. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  15064. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  15065. }
  15066. }
  15067. // Angle around the Y axis, counter-clockwise when looking from above.
  15068. function azimuth( vector ) {
  15069. return Math.atan2( vector.z, - vector.x );
  15070. }
  15071. // Angle above the XZ plane.
  15072. function inclination( vector ) {
  15073. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  15074. }
  15075. }
  15076. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15077. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  15078. /**
  15079. * @author timothypratley / https://github.com/timothypratley
  15080. * @author Mugen87 / https://github.com/Mugen87
  15081. */
  15082. // TetrahedronGeometry
  15083. function TetrahedronGeometry( radius, detail ) {
  15084. Geometry.call( this );
  15085. this.type = 'TetrahedronGeometry';
  15086. this.parameters = {
  15087. radius: radius,
  15088. detail: detail
  15089. };
  15090. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  15091. this.mergeVertices();
  15092. }
  15093. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  15094. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  15095. // TetrahedronBufferGeometry
  15096. function TetrahedronBufferGeometry( radius, detail ) {
  15097. var vertices = [
  15098. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  15099. ];
  15100. var indices = [
  15101. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  15102. ];
  15103. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15104. this.type = 'TetrahedronBufferGeometry';
  15105. this.parameters = {
  15106. radius: radius,
  15107. detail: detail
  15108. };
  15109. }
  15110. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15111. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  15112. /**
  15113. * @author timothypratley / https://github.com/timothypratley
  15114. * @author Mugen87 / https://github.com/Mugen87
  15115. */
  15116. // OctahedronGeometry
  15117. function OctahedronGeometry( radius, detail ) {
  15118. Geometry.call( this );
  15119. this.type = 'OctahedronGeometry';
  15120. this.parameters = {
  15121. radius: radius,
  15122. detail: detail
  15123. };
  15124. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  15125. this.mergeVertices();
  15126. }
  15127. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  15128. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  15129. // OctahedronBufferGeometry
  15130. function OctahedronBufferGeometry( radius, detail ) {
  15131. var vertices = [
  15132. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  15133. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  15134. ];
  15135. var indices = [
  15136. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  15137. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  15138. 1, 3, 4, 1, 4, 2
  15139. ];
  15140. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15141. this.type = 'OctahedronBufferGeometry';
  15142. this.parameters = {
  15143. radius: radius,
  15144. detail: detail
  15145. };
  15146. }
  15147. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15148. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  15149. /**
  15150. * @author timothypratley / https://github.com/timothypratley
  15151. * @author Mugen87 / https://github.com/Mugen87
  15152. */
  15153. // IcosahedronGeometry
  15154. function IcosahedronGeometry( radius, detail ) {
  15155. Geometry.call( this );
  15156. this.type = 'IcosahedronGeometry';
  15157. this.parameters = {
  15158. radius: radius,
  15159. detail: detail
  15160. };
  15161. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  15162. this.mergeVertices();
  15163. }
  15164. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  15165. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  15166. // IcosahedronBufferGeometry
  15167. function IcosahedronBufferGeometry( radius, detail ) {
  15168. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  15169. var vertices = [
  15170. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  15171. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  15172. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  15173. ];
  15174. var indices = [
  15175. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  15176. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  15177. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  15178. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  15179. ];
  15180. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15181. this.type = 'IcosahedronBufferGeometry';
  15182. this.parameters = {
  15183. radius: radius,
  15184. detail: detail
  15185. };
  15186. }
  15187. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15188. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  15189. /**
  15190. * @author Abe Pazos / https://hamoid.com
  15191. * @author Mugen87 / https://github.com/Mugen87
  15192. */
  15193. // DodecahedronGeometry
  15194. function DodecahedronGeometry( radius, detail ) {
  15195. Geometry.call( this );
  15196. this.type = 'DodecahedronGeometry';
  15197. this.parameters = {
  15198. radius: radius,
  15199. detail: detail
  15200. };
  15201. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  15202. this.mergeVertices();
  15203. }
  15204. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  15205. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  15206. // DodecahedronBufferGeometry
  15207. function DodecahedronBufferGeometry( radius, detail ) {
  15208. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  15209. var r = 1 / t;
  15210. var vertices = [
  15211. // (±1, ±1, ±1)
  15212. - 1, - 1, - 1, - 1, - 1, 1,
  15213. - 1, 1, - 1, - 1, 1, 1,
  15214. 1, - 1, - 1, 1, - 1, 1,
  15215. 1, 1, - 1, 1, 1, 1,
  15216. // (0, ±1/φ, ±φ)
  15217. 0, - r, - t, 0, - r, t,
  15218. 0, r, - t, 0, r, t,
  15219. // (±1/φ, ±φ, 0)
  15220. - r, - t, 0, - r, t, 0,
  15221. r, - t, 0, r, t, 0,
  15222. // (±φ, 0, ±1/φ)
  15223. - t, 0, - r, t, 0, - r,
  15224. - t, 0, r, t, 0, r
  15225. ];
  15226. var indices = [
  15227. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  15228. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  15229. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  15230. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  15231. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  15232. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  15233. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  15234. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  15235. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  15236. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  15237. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  15238. 1, 12, 14, 1, 14, 5, 1, 5, 9
  15239. ];
  15240. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15241. this.type = 'DodecahedronBufferGeometry';
  15242. this.parameters = {
  15243. radius: radius,
  15244. detail: detail
  15245. };
  15246. }
  15247. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15248. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  15249. /**
  15250. * @author oosmoxiecode / https://github.com/oosmoxiecode
  15251. * @author WestLangley / https://github.com/WestLangley
  15252. * @author zz85 / https://github.com/zz85
  15253. * @author miningold / https://github.com/miningold
  15254. * @author jonobr1 / https://github.com/jonobr1
  15255. * @author Mugen87 / https://github.com/Mugen87
  15256. *
  15257. */
  15258. // TubeGeometry
  15259. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  15260. Geometry.call( this );
  15261. this.type = 'TubeGeometry';
  15262. this.parameters = {
  15263. path: path,
  15264. tubularSegments: tubularSegments,
  15265. radius: radius,
  15266. radialSegments: radialSegments,
  15267. closed: closed
  15268. };
  15269. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  15270. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  15271. // expose internals
  15272. this.tangents = bufferGeometry.tangents;
  15273. this.normals = bufferGeometry.normals;
  15274. this.binormals = bufferGeometry.binormals;
  15275. // create geometry
  15276. this.fromBufferGeometry( bufferGeometry );
  15277. this.mergeVertices();
  15278. }
  15279. TubeGeometry.prototype = Object.create( Geometry.prototype );
  15280. TubeGeometry.prototype.constructor = TubeGeometry;
  15281. // TubeBufferGeometry
  15282. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  15283. BufferGeometry.call( this );
  15284. this.type = 'TubeBufferGeometry';
  15285. this.parameters = {
  15286. path: path,
  15287. tubularSegments: tubularSegments,
  15288. radius: radius,
  15289. radialSegments: radialSegments,
  15290. closed: closed
  15291. };
  15292. tubularSegments = tubularSegments || 64;
  15293. radius = radius || 1;
  15294. radialSegments = radialSegments || 8;
  15295. closed = closed || false;
  15296. var frames = path.computeFrenetFrames( tubularSegments, closed );
  15297. // expose internals
  15298. this.tangents = frames.tangents;
  15299. this.normals = frames.normals;
  15300. this.binormals = frames.binormals;
  15301. // helper variables
  15302. var vertex = new Vector3();
  15303. var normal = new Vector3();
  15304. var uv = new Vector2();
  15305. var P = new Vector3();
  15306. var i, j;
  15307. // buffer
  15308. var vertices = [];
  15309. var normals = [];
  15310. var uvs = [];
  15311. var indices = [];
  15312. // create buffer data
  15313. generateBufferData();
  15314. // build geometry
  15315. this.setIndex( indices );
  15316. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15317. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15318. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15319. // functions
  15320. function generateBufferData() {
  15321. for ( i = 0; i < tubularSegments; i ++ ) {
  15322. generateSegment( i );
  15323. }
  15324. // if the geometry is not closed, generate the last row of vertices and normals
  15325. // at the regular position on the given path
  15326. //
  15327. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  15328. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  15329. // uvs are generated in a separate function.
  15330. // this makes it easy compute correct values for closed geometries
  15331. generateUVs();
  15332. // finally create faces
  15333. generateIndices();
  15334. }
  15335. function generateSegment( i ) {
  15336. // we use getPointAt to sample evenly distributed points from the given path
  15337. P = path.getPointAt( i / tubularSegments, P );
  15338. // retrieve corresponding normal and binormal
  15339. var N = frames.normals[ i ];
  15340. var B = frames.binormals[ i ];
  15341. // generate normals and vertices for the current segment
  15342. for ( j = 0; j <= radialSegments; j ++ ) {
  15343. var v = j / radialSegments * Math.PI * 2;
  15344. var sin = Math.sin( v );
  15345. var cos = - Math.cos( v );
  15346. // normal
  15347. normal.x = ( cos * N.x + sin * B.x );
  15348. normal.y = ( cos * N.y + sin * B.y );
  15349. normal.z = ( cos * N.z + sin * B.z );
  15350. normal.normalize();
  15351. normals.push( normal.x, normal.y, normal.z );
  15352. // vertex
  15353. vertex.x = P.x + radius * normal.x;
  15354. vertex.y = P.y + radius * normal.y;
  15355. vertex.z = P.z + radius * normal.z;
  15356. vertices.push( vertex.x, vertex.y, vertex.z );
  15357. }
  15358. }
  15359. function generateIndices() {
  15360. for ( j = 1; j <= tubularSegments; j ++ ) {
  15361. for ( i = 1; i <= radialSegments; i ++ ) {
  15362. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  15363. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  15364. var c = ( radialSegments + 1 ) * j + i;
  15365. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  15366. // faces
  15367. indices.push( a, b, d );
  15368. indices.push( b, c, d );
  15369. }
  15370. }
  15371. }
  15372. function generateUVs() {
  15373. for ( i = 0; i <= tubularSegments; i ++ ) {
  15374. for ( j = 0; j <= radialSegments; j ++ ) {
  15375. uv.x = i / tubularSegments;
  15376. uv.y = j / radialSegments;
  15377. uvs.push( uv.x, uv.y );
  15378. }
  15379. }
  15380. }
  15381. }
  15382. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15383. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  15384. /**
  15385. * @author oosmoxiecode
  15386. * @author Mugen87 / https://github.com/Mugen87
  15387. *
  15388. * based on http://www.blackpawn.com/texts/pqtorus/
  15389. */
  15390. // TorusKnotGeometry
  15391. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  15392. Geometry.call( this );
  15393. this.type = 'TorusKnotGeometry';
  15394. this.parameters = {
  15395. radius: radius,
  15396. tube: tube,
  15397. tubularSegments: tubularSegments,
  15398. radialSegments: radialSegments,
  15399. p: p,
  15400. q: q
  15401. };
  15402. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  15403. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  15404. this.mergeVertices();
  15405. }
  15406. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  15407. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  15408. // TorusKnotBufferGeometry
  15409. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  15410. BufferGeometry.call( this );
  15411. this.type = 'TorusKnotBufferGeometry';
  15412. this.parameters = {
  15413. radius: radius,
  15414. tube: tube,
  15415. tubularSegments: tubularSegments,
  15416. radialSegments: radialSegments,
  15417. p: p,
  15418. q: q
  15419. };
  15420. radius = radius || 1;
  15421. tube = tube || 0.4;
  15422. tubularSegments = Math.floor( tubularSegments ) || 64;
  15423. radialSegments = Math.floor( radialSegments ) || 8;
  15424. p = p || 2;
  15425. q = q || 3;
  15426. // buffers
  15427. var indices = [];
  15428. var vertices = [];
  15429. var normals = [];
  15430. var uvs = [];
  15431. // helper variables
  15432. var i, j;
  15433. var vertex = new Vector3();
  15434. var normal = new Vector3();
  15435. var P1 = new Vector3();
  15436. var P2 = new Vector3();
  15437. var B = new Vector3();
  15438. var T = new Vector3();
  15439. var N = new Vector3();
  15440. // generate vertices, normals and uvs
  15441. for ( i = 0; i <= tubularSegments; ++ i ) {
  15442. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  15443. var u = i / tubularSegments * p * Math.PI * 2;
  15444. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  15445. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  15446. calculatePositionOnCurve( u, p, q, radius, P1 );
  15447. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  15448. // calculate orthonormal basis
  15449. T.subVectors( P2, P1 );
  15450. N.addVectors( P2, P1 );
  15451. B.crossVectors( T, N );
  15452. N.crossVectors( B, T );
  15453. // normalize B, N. T can be ignored, we don't use it
  15454. B.normalize();
  15455. N.normalize();
  15456. for ( j = 0; j <= radialSegments; ++ j ) {
  15457. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  15458. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  15459. var v = j / radialSegments * Math.PI * 2;
  15460. var cx = - tube * Math.cos( v );
  15461. var cy = tube * Math.sin( v );
  15462. // now calculate the final vertex position.
  15463. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  15464. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  15465. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  15466. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  15467. vertices.push( vertex.x, vertex.y, vertex.z );
  15468. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  15469. normal.subVectors( vertex, P1 ).normalize();
  15470. normals.push( normal.x, normal.y, normal.z );
  15471. // uv
  15472. uvs.push( i / tubularSegments );
  15473. uvs.push( j / radialSegments );
  15474. }
  15475. }
  15476. // generate indices
  15477. for ( j = 1; j <= tubularSegments; j ++ ) {
  15478. for ( i = 1; i <= radialSegments; i ++ ) {
  15479. // indices
  15480. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  15481. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  15482. var c = ( radialSegments + 1 ) * j + i;
  15483. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  15484. // faces
  15485. indices.push( a, b, d );
  15486. indices.push( b, c, d );
  15487. }
  15488. }
  15489. // build geometry
  15490. this.setIndex( indices );
  15491. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15492. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15493. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15494. // this function calculates the current position on the torus curve
  15495. function calculatePositionOnCurve( u, p, q, radius, position ) {
  15496. var cu = Math.cos( u );
  15497. var su = Math.sin( u );
  15498. var quOverP = q / p * u;
  15499. var cs = Math.cos( quOverP );
  15500. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  15501. position.y = radius * ( 2 + cs ) * su * 0.5;
  15502. position.z = radius * Math.sin( quOverP ) * 0.5;
  15503. }
  15504. }
  15505. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15506. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  15507. /**
  15508. * @author oosmoxiecode
  15509. * @author mrdoob / http://mrdoob.com/
  15510. * @author Mugen87 / https://github.com/Mugen87
  15511. */
  15512. // TorusGeometry
  15513. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  15514. Geometry.call( this );
  15515. this.type = 'TorusGeometry';
  15516. this.parameters = {
  15517. radius: radius,
  15518. tube: tube,
  15519. radialSegments: radialSegments,
  15520. tubularSegments: tubularSegments,
  15521. arc: arc
  15522. };
  15523. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  15524. this.mergeVertices();
  15525. }
  15526. TorusGeometry.prototype = Object.create( Geometry.prototype );
  15527. TorusGeometry.prototype.constructor = TorusGeometry;
  15528. // TorusBufferGeometry
  15529. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  15530. BufferGeometry.call( this );
  15531. this.type = 'TorusBufferGeometry';
  15532. this.parameters = {
  15533. radius: radius,
  15534. tube: tube,
  15535. radialSegments: radialSegments,
  15536. tubularSegments: tubularSegments,
  15537. arc: arc
  15538. };
  15539. radius = radius || 1;
  15540. tube = tube || 0.4;
  15541. radialSegments = Math.floor( radialSegments ) || 8;
  15542. tubularSegments = Math.floor( tubularSegments ) || 6;
  15543. arc = arc || Math.PI * 2;
  15544. // buffers
  15545. var indices = [];
  15546. var vertices = [];
  15547. var normals = [];
  15548. var uvs = [];
  15549. // helper variables
  15550. var center = new Vector3();
  15551. var vertex = new Vector3();
  15552. var normal = new Vector3();
  15553. var j, i;
  15554. // generate vertices, normals and uvs
  15555. for ( j = 0; j <= radialSegments; j ++ ) {
  15556. for ( i = 0; i <= tubularSegments; i ++ ) {
  15557. var u = i / tubularSegments * arc;
  15558. var v = j / radialSegments * Math.PI * 2;
  15559. // vertex
  15560. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  15561. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  15562. vertex.z = tube * Math.sin( v );
  15563. vertices.push( vertex.x, vertex.y, vertex.z );
  15564. // normal
  15565. center.x = radius * Math.cos( u );
  15566. center.y = radius * Math.sin( u );
  15567. normal.subVectors( vertex, center ).normalize();
  15568. normals.push( normal.x, normal.y, normal.z );
  15569. // uv
  15570. uvs.push( i / tubularSegments );
  15571. uvs.push( j / radialSegments );
  15572. }
  15573. }
  15574. // generate indices
  15575. for ( j = 1; j <= radialSegments; j ++ ) {
  15576. for ( i = 1; i <= tubularSegments; i ++ ) {
  15577. // indices
  15578. var a = ( tubularSegments + 1 ) * j + i - 1;
  15579. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  15580. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  15581. var d = ( tubularSegments + 1 ) * j + i;
  15582. // faces
  15583. indices.push( a, b, d );
  15584. indices.push( b, c, d );
  15585. }
  15586. }
  15587. // build geometry
  15588. this.setIndex( indices );
  15589. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15590. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15591. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15592. }
  15593. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15594. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  15595. /**
  15596. * @author Mugen87 / https://github.com/Mugen87
  15597. * Port from https://github.com/mapbox/earcut (v2.1.2)
  15598. */
  15599. var Earcut = {
  15600. triangulate: function ( data, holeIndices, dim ) {
  15601. dim = dim || 2;
  15602. var hasHoles = holeIndices && holeIndices.length,
  15603. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  15604. outerNode = linkedList( data, 0, outerLen, dim, true ),
  15605. triangles = [];
  15606. if ( ! outerNode ) return triangles;
  15607. var minX, minY, maxX, maxY, x, y, invSize;
  15608. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  15609. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  15610. if ( data.length > 80 * dim ) {
  15611. minX = maxX = data[ 0 ];
  15612. minY = maxY = data[ 1 ];
  15613. for ( var i = dim; i < outerLen; i += dim ) {
  15614. x = data[ i ];
  15615. y = data[ i + 1 ];
  15616. if ( x < minX ) minX = x;
  15617. if ( y < minY ) minY = y;
  15618. if ( x > maxX ) maxX = x;
  15619. if ( y > maxY ) maxY = y;
  15620. }
  15621. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  15622. invSize = Math.max( maxX - minX, maxY - minY );
  15623. invSize = invSize !== 0 ? 1 / invSize : 0;
  15624. }
  15625. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  15626. return triangles;
  15627. }
  15628. };
  15629. // create a circular doubly linked list from polygon points in the specified winding order
  15630. function linkedList( data, start, end, dim, clockwise ) {
  15631. var i, last;
  15632. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  15633. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  15634. } else {
  15635. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  15636. }
  15637. if ( last && equals( last, last.next ) ) {
  15638. removeNode( last );
  15639. last = last.next;
  15640. }
  15641. return last;
  15642. }
  15643. // eliminate colinear or duplicate points
  15644. function filterPoints( start, end ) {
  15645. if ( ! start ) return start;
  15646. if ( ! end ) end = start;
  15647. var p = start, again;
  15648. do {
  15649. again = false;
  15650. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  15651. removeNode( p );
  15652. p = end = p.prev;
  15653. if ( p === p.next ) break;
  15654. again = true;
  15655. } else {
  15656. p = p.next;
  15657. }
  15658. } while ( again || p !== end );
  15659. return end;
  15660. }
  15661. // main ear slicing loop which triangulates a polygon (given as a linked list)
  15662. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  15663. if ( ! ear ) return;
  15664. // interlink polygon nodes in z-order
  15665. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  15666. var stop = ear, prev, next;
  15667. // iterate through ears, slicing them one by one
  15668. while ( ear.prev !== ear.next ) {
  15669. prev = ear.prev;
  15670. next = ear.next;
  15671. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  15672. // cut off the triangle
  15673. triangles.push( prev.i / dim );
  15674. triangles.push( ear.i / dim );
  15675. triangles.push( next.i / dim );
  15676. removeNode( ear );
  15677. // skipping the next vertice leads to less sliver triangles
  15678. ear = next.next;
  15679. stop = next.next;
  15680. continue;
  15681. }
  15682. ear = next;
  15683. // if we looped through the whole remaining polygon and can't find any more ears
  15684. if ( ear === stop ) {
  15685. // try filtering points and slicing again
  15686. if ( ! pass ) {
  15687. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  15688. // if this didn't work, try curing all small self-intersections locally
  15689. } else if ( pass === 1 ) {
  15690. ear = cureLocalIntersections( ear, triangles, dim );
  15691. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  15692. // as a last resort, try splitting the remaining polygon into two
  15693. } else if ( pass === 2 ) {
  15694. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  15695. }
  15696. break;
  15697. }
  15698. }
  15699. }
  15700. // check whether a polygon node forms a valid ear with adjacent nodes
  15701. function isEar( ear ) {
  15702. var a = ear.prev,
  15703. b = ear,
  15704. c = ear.next;
  15705. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  15706. // now make sure we don't have other points inside the potential ear
  15707. var p = ear.next.next;
  15708. while ( p !== ear.prev ) {
  15709. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) {
  15710. return false;
  15711. }
  15712. p = p.next;
  15713. }
  15714. return true;
  15715. }
  15716. function isEarHashed( ear, minX, minY, invSize ) {
  15717. var a = ear.prev,
  15718. b = ear,
  15719. c = ear.next;
  15720. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  15721. // triangle bbox; min & max are calculated like this for speed
  15722. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  15723. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  15724. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  15725. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  15726. // z-order range for the current triangle bbox;
  15727. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  15728. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  15729. // first look for points inside the triangle in increasing z-order
  15730. var p = ear.nextZ;
  15731. while ( p && p.z <= maxZ ) {
  15732. if ( p !== ear.prev && p !== ear.next &&
  15733. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  15734. area( p.prev, p, p.next ) >= 0 ) return false;
  15735. p = p.nextZ;
  15736. }
  15737. // then look for points in decreasing z-order
  15738. p = ear.prevZ;
  15739. while ( p && p.z >= minZ ) {
  15740. if ( p !== ear.prev && p !== ear.next &&
  15741. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  15742. area( p.prev, p, p.next ) >= 0 ) return false;
  15743. p = p.prevZ;
  15744. }
  15745. return true;
  15746. }
  15747. // go through all polygon nodes and cure small local self-intersections
  15748. function cureLocalIntersections( start, triangles, dim ) {
  15749. var p = start;
  15750. do {
  15751. var a = p.prev, b = p.next.next;
  15752. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  15753. triangles.push( a.i / dim );
  15754. triangles.push( p.i / dim );
  15755. triangles.push( b.i / dim );
  15756. // remove two nodes involved
  15757. removeNode( p );
  15758. removeNode( p.next );
  15759. p = start = b;
  15760. }
  15761. p = p.next;
  15762. } while ( p !== start );
  15763. return p;
  15764. }
  15765. // try splitting polygon into two and triangulate them independently
  15766. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  15767. // look for a valid diagonal that divides the polygon into two
  15768. var a = start;
  15769. do {
  15770. var b = a.next.next;
  15771. while ( b !== a.prev ) {
  15772. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  15773. // split the polygon in two by the diagonal
  15774. var c = splitPolygon( a, b );
  15775. // filter colinear points around the cuts
  15776. a = filterPoints( a, a.next );
  15777. c = filterPoints( c, c.next );
  15778. // run earcut on each half
  15779. earcutLinked( a, triangles, dim, minX, minY, invSize );
  15780. earcutLinked( c, triangles, dim, minX, minY, invSize );
  15781. return;
  15782. }
  15783. b = b.next;
  15784. }
  15785. a = a.next;
  15786. } while ( a !== start );
  15787. }
  15788. // link every hole into the outer loop, producing a single-ring polygon without holes
  15789. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  15790. var queue = [], i, len, start, end, list;
  15791. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  15792. start = holeIndices[ i ] * dim;
  15793. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  15794. list = linkedList( data, start, end, dim, false );
  15795. if ( list === list.next ) list.steiner = true;
  15796. queue.push( getLeftmost( list ) );
  15797. }
  15798. queue.sort( compareX );
  15799. // process holes from left to right
  15800. for ( i = 0; i < queue.length; i ++ ) {
  15801. eliminateHole( queue[ i ], outerNode );
  15802. outerNode = filterPoints( outerNode, outerNode.next );
  15803. }
  15804. return outerNode;
  15805. }
  15806. function compareX( a, b ) {
  15807. return a.x - b.x;
  15808. }
  15809. // find a bridge between vertices that connects hole with an outer ring and and link it
  15810. function eliminateHole( hole, outerNode ) {
  15811. outerNode = findHoleBridge( hole, outerNode );
  15812. if ( outerNode ) {
  15813. var b = splitPolygon( outerNode, hole );
  15814. filterPoints( b, b.next );
  15815. }
  15816. }
  15817. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  15818. function findHoleBridge( hole, outerNode ) {
  15819. var p = outerNode,
  15820. hx = hole.x,
  15821. hy = hole.y,
  15822. qx = - Infinity,
  15823. m;
  15824. // find a segment intersected by a ray from the hole's leftmost point to the left;
  15825. // segment's endpoint with lesser x will be potential connection point
  15826. do {
  15827. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  15828. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  15829. if ( x <= hx && x > qx ) {
  15830. qx = x;
  15831. if ( x === hx ) {
  15832. if ( hy === p.y ) return p;
  15833. if ( hy === p.next.y ) return p.next;
  15834. }
  15835. m = p.x < p.next.x ? p : p.next;
  15836. }
  15837. }
  15838. p = p.next;
  15839. } while ( p !== outerNode );
  15840. if ( ! m ) return null;
  15841. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  15842. // look for points inside the triangle of hole point, segment intersection and endpoint;
  15843. // if there are no points found, we have a valid connection;
  15844. // otherwise choose the point of the minimum angle with the ray as connection point
  15845. var stop = m,
  15846. mx = m.x,
  15847. my = m.y,
  15848. tanMin = Infinity,
  15849. tan;
  15850. p = m.next;
  15851. while ( p !== stop ) {
  15852. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  15853. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  15854. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  15855. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  15856. m = p;
  15857. tanMin = tan;
  15858. }
  15859. }
  15860. p = p.next;
  15861. }
  15862. return m;
  15863. }
  15864. // interlink polygon nodes in z-order
  15865. function indexCurve( start, minX, minY, invSize ) {
  15866. var p = start;
  15867. do {
  15868. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  15869. p.prevZ = p.prev;
  15870. p.nextZ = p.next;
  15871. p = p.next;
  15872. } while ( p !== start );
  15873. p.prevZ.nextZ = null;
  15874. p.prevZ = null;
  15875. sortLinked( p );
  15876. }
  15877. // Simon Tatham's linked list merge sort algorithm
  15878. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  15879. function sortLinked( list ) {
  15880. var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
  15881. do {
  15882. p = list;
  15883. list = null;
  15884. tail = null;
  15885. numMerges = 0;
  15886. while ( p ) {
  15887. numMerges ++;
  15888. q = p;
  15889. pSize = 0;
  15890. for ( i = 0; i < inSize; i ++ ) {
  15891. pSize ++;
  15892. q = q.nextZ;
  15893. if ( ! q ) break;
  15894. }
  15895. qSize = inSize;
  15896. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  15897. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  15898. e = p;
  15899. p = p.nextZ;
  15900. pSize --;
  15901. } else {
  15902. e = q;
  15903. q = q.nextZ;
  15904. qSize --;
  15905. }
  15906. if ( tail ) tail.nextZ = e;
  15907. else list = e;
  15908. e.prevZ = tail;
  15909. tail = e;
  15910. }
  15911. p = q;
  15912. }
  15913. tail.nextZ = null;
  15914. inSize *= 2;
  15915. } while ( numMerges > 1 );
  15916. return list;
  15917. }
  15918. // z-order of a point given coords and inverse of the longer side of data bbox
  15919. function zOrder( x, y, minX, minY, invSize ) {
  15920. // coords are transformed into non-negative 15-bit integer range
  15921. x = 32767 * ( x - minX ) * invSize;
  15922. y = 32767 * ( y - minY ) * invSize;
  15923. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  15924. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  15925. x = ( x | ( x << 2 ) ) & 0x33333333;
  15926. x = ( x | ( x << 1 ) ) & 0x55555555;
  15927. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  15928. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  15929. y = ( y | ( y << 2 ) ) & 0x33333333;
  15930. y = ( y | ( y << 1 ) ) & 0x55555555;
  15931. return x | ( y << 1 );
  15932. }
  15933. // find the leftmost node of a polygon ring
  15934. function getLeftmost( start ) {
  15935. var p = start, leftmost = start;
  15936. do {
  15937. if ( p.x < leftmost.x ) leftmost = p;
  15938. p = p.next;
  15939. } while ( p !== start );
  15940. return leftmost;
  15941. }
  15942. // check if a point lies within a convex triangle
  15943. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  15944. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  15945. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  15946. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  15947. }
  15948. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  15949. function isValidDiagonal( a, b ) {
  15950. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  15951. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  15952. }
  15953. // signed area of a triangle
  15954. function area( p, q, r ) {
  15955. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  15956. }
  15957. // check if two points are equal
  15958. function equals( p1, p2 ) {
  15959. return p1.x === p2.x && p1.y === p2.y;
  15960. }
  15961. // check if two segments intersect
  15962. function intersects( p1, q1, p2, q2 ) {
  15963. if ( ( equals( p1, q1 ) && equals( p2, q2 ) ) ||
  15964. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  15965. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  15966. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  15967. }
  15968. // check if a polygon diagonal intersects any polygon segments
  15969. function intersectsPolygon( a, b ) {
  15970. var p = a;
  15971. do {
  15972. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  15973. intersects( p, p.next, a, b ) ) {
  15974. return true;
  15975. }
  15976. p = p.next;
  15977. } while ( p !== a );
  15978. return false;
  15979. }
  15980. // check if a polygon diagonal is locally inside the polygon
  15981. function locallyInside( a, b ) {
  15982. return area( a.prev, a, a.next ) < 0 ?
  15983. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  15984. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  15985. }
  15986. // check if the middle point of a polygon diagonal is inside the polygon
  15987. function middleInside( a, b ) {
  15988. var p = a,
  15989. inside = false,
  15990. px = ( a.x + b.x ) / 2,
  15991. py = ( a.y + b.y ) / 2;
  15992. do {
  15993. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  15994. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) ) {
  15995. inside = ! inside;
  15996. }
  15997. p = p.next;
  15998. } while ( p !== a );
  15999. return inside;
  16000. }
  16001. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  16002. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  16003. function splitPolygon( a, b ) {
  16004. var a2 = new Node( a.i, a.x, a.y ),
  16005. b2 = new Node( b.i, b.x, b.y ),
  16006. an = a.next,
  16007. bp = b.prev;
  16008. a.next = b;
  16009. b.prev = a;
  16010. a2.next = an;
  16011. an.prev = a2;
  16012. b2.next = a2;
  16013. a2.prev = b2;
  16014. bp.next = b2;
  16015. b2.prev = bp;
  16016. return b2;
  16017. }
  16018. // create a node and optionally link it with previous one (in a circular doubly linked list)
  16019. function insertNode( i, x, y, last ) {
  16020. var p = new Node( i, x, y );
  16021. if ( ! last ) {
  16022. p.prev = p;
  16023. p.next = p;
  16024. } else {
  16025. p.next = last.next;
  16026. p.prev = last;
  16027. last.next.prev = p;
  16028. last.next = p;
  16029. }
  16030. return p;
  16031. }
  16032. function removeNode( p ) {
  16033. p.next.prev = p.prev;
  16034. p.prev.next = p.next;
  16035. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  16036. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  16037. }
  16038. function Node( i, x, y ) {
  16039. // vertice index in coordinates array
  16040. this.i = i;
  16041. // vertex coordinates
  16042. this.x = x;
  16043. this.y = y;
  16044. // previous and next vertice nodes in a polygon ring
  16045. this.prev = null;
  16046. this.next = null;
  16047. // z-order curve value
  16048. this.z = null;
  16049. // previous and next nodes in z-order
  16050. this.prevZ = null;
  16051. this.nextZ = null;
  16052. // indicates whether this is a steiner point
  16053. this.steiner = false;
  16054. }
  16055. function signedArea( data, start, end, dim ) {
  16056. var sum = 0;
  16057. for ( var i = start, j = end - dim; i < end; i += dim ) {
  16058. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  16059. j = i;
  16060. }
  16061. return sum;
  16062. }
  16063. /**
  16064. * @author zz85 / http://www.lab4games.net/zz85/blog
  16065. */
  16066. var ShapeUtils = {
  16067. // calculate area of the contour polygon
  16068. area: function ( contour ) {
  16069. var n = contour.length;
  16070. var a = 0.0;
  16071. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  16072. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  16073. }
  16074. return a * 0.5;
  16075. },
  16076. isClockWise: function ( pts ) {
  16077. return ShapeUtils.area( pts ) < 0;
  16078. },
  16079. triangulateShape: function ( contour, holes ) {
  16080. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  16081. var holeIndices = []; // array of hole indices
  16082. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  16083. removeDupEndPts( contour );
  16084. addContour( vertices, contour );
  16085. //
  16086. var holeIndex = contour.length;
  16087. holes.forEach( removeDupEndPts );
  16088. for ( var i = 0; i < holes.length; i ++ ) {
  16089. holeIndices.push( holeIndex );
  16090. holeIndex += holes[ i ].length;
  16091. addContour( vertices, holes[ i ] );
  16092. }
  16093. //
  16094. var triangles = Earcut.triangulate( vertices, holeIndices );
  16095. //
  16096. for ( var i = 0; i < triangles.length; i += 3 ) {
  16097. faces.push( triangles.slice( i, i + 3 ) );
  16098. }
  16099. return faces;
  16100. }
  16101. };
  16102. function removeDupEndPts( points ) {
  16103. var l = points.length;
  16104. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  16105. points.pop();
  16106. }
  16107. }
  16108. function addContour( vertices, contour ) {
  16109. for ( var i = 0; i < contour.length; i ++ ) {
  16110. vertices.push( contour[ i ].x );
  16111. vertices.push( contour[ i ].y );
  16112. }
  16113. }
  16114. /**
  16115. * @author zz85 / http://www.lab4games.net/zz85/blog
  16116. *
  16117. * Creates extruded geometry from a path shape.
  16118. *
  16119. * parameters = {
  16120. *
  16121. * curveSegments: <int>, // number of points on the curves
  16122. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  16123. * amount: <int>, // Depth to extrude the shape
  16124. *
  16125. * bevelEnabled: <bool>, // turn on bevel
  16126. * bevelThickness: <float>, // how deep into the original shape bevel goes
  16127. * bevelSize: <float>, // how far from shape outline is bevel
  16128. * bevelSegments: <int>, // number of bevel layers
  16129. *
  16130. * extrudePath: <THREE.Curve> // curve to extrude shape along
  16131. * frames: <Object> // containing arrays of tangents, normals, binormals
  16132. *
  16133. * UVGenerator: <Object> // object that provides UV generator functions
  16134. *
  16135. * }
  16136. */
  16137. // ExtrudeGeometry
  16138. function ExtrudeGeometry( shapes, options ) {
  16139. Geometry.call( this );
  16140. this.type = 'ExtrudeGeometry';
  16141. this.parameters = {
  16142. shapes: shapes,
  16143. options: options
  16144. };
  16145. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  16146. this.mergeVertices();
  16147. }
  16148. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  16149. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  16150. // ExtrudeBufferGeometry
  16151. function ExtrudeBufferGeometry( shapes, options ) {
  16152. if ( typeof ( shapes ) === "undefined" ) {
  16153. return;
  16154. }
  16155. BufferGeometry.call( this );
  16156. this.type = 'ExtrudeBufferGeometry';
  16157. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  16158. this.addShapeList( shapes, options );
  16159. this.computeVertexNormals();
  16160. // can't really use automatic vertex normals
  16161. // as then front and back sides get smoothed too
  16162. // should do separate smoothing just for sides
  16163. //this.computeVertexNormals();
  16164. //console.log( "took", ( Date.now() - startTime ) );
  16165. }
  16166. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16167. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  16168. ExtrudeBufferGeometry.prototype.getArrays = function () {
  16169. var positionAttribute = this.getAttribute( "position" );
  16170. var verticesArray = positionAttribute ? Array.prototype.slice.call( positionAttribute.array ) : [];
  16171. var uvAttribute = this.getAttribute( "uv" );
  16172. var uvArray = uvAttribute ? Array.prototype.slice.call( uvAttribute.array ) : [];
  16173. var IndexAttribute = this.index;
  16174. var indicesArray = IndexAttribute ? Array.prototype.slice.call( IndexAttribute.array ) : [];
  16175. return {
  16176. position: verticesArray,
  16177. uv: uvArray,
  16178. index: indicesArray
  16179. };
  16180. };
  16181. ExtrudeBufferGeometry.prototype.addShapeList = function ( shapes, options ) {
  16182. var sl = shapes.length;
  16183. options.arrays = this.getArrays();
  16184. for ( var s = 0; s < sl; s ++ ) {
  16185. var shape = shapes[ s ];
  16186. this.addShape( shape, options );
  16187. }
  16188. this.setIndex( options.arrays.index );
  16189. this.addAttribute( 'position', new Float32BufferAttribute( options.arrays.position, 3 ) );
  16190. this.addAttribute( 'uv', new Float32BufferAttribute( options.arrays.uv, 2 ) );
  16191. };
  16192. ExtrudeBufferGeometry.prototype.addShape = function ( shape, options ) {
  16193. var arrays = options.arrays ? options.arrays : this.getArrays();
  16194. var verticesArray = arrays.position;
  16195. var indicesArray = arrays.index;
  16196. var uvArray = arrays.uv;
  16197. var placeholder = [];
  16198. var amount = options.amount !== undefined ? options.amount : 100;
  16199. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  16200. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  16201. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  16202. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  16203. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  16204. var steps = options.steps !== undefined ? options.steps : 1;
  16205. var extrudePath = options.extrudePath;
  16206. var extrudePts, extrudeByPath = false;
  16207. // Use default WorldUVGenerator if no UV generators are specified.
  16208. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : ExtrudeGeometry.WorldUVGenerator;
  16209. var splineTube, binormal, normal, position2;
  16210. if ( extrudePath ) {
  16211. extrudePts = extrudePath.getSpacedPoints( steps );
  16212. extrudeByPath = true;
  16213. bevelEnabled = false; // bevels not supported for path extrusion
  16214. // SETUP TNB variables
  16215. // TODO1 - have a .isClosed in spline?
  16216. splineTube = options.frames !== undefined ? options.frames : extrudePath.computeFrenetFrames( steps, false );
  16217. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  16218. binormal = new Vector3();
  16219. normal = new Vector3();
  16220. position2 = new Vector3();
  16221. }
  16222. // Safeguards if bevels are not enabled
  16223. if ( ! bevelEnabled ) {
  16224. bevelSegments = 0;
  16225. bevelThickness = 0;
  16226. bevelSize = 0;
  16227. }
  16228. // Variables initialization
  16229. var ahole, h, hl; // looping of holes
  16230. var scope = this;
  16231. var shapePoints = shape.extractPoints( curveSegments );
  16232. var vertices = shapePoints.shape;
  16233. var holes = shapePoints.holes;
  16234. var reverse = ! ShapeUtils.isClockWise( vertices );
  16235. if ( reverse ) {
  16236. vertices = vertices.reverse();
  16237. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  16238. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16239. ahole = holes[ h ];
  16240. if ( ShapeUtils.isClockWise( ahole ) ) {
  16241. holes[ h ] = ahole.reverse();
  16242. }
  16243. }
  16244. }
  16245. var faces = ShapeUtils.triangulateShape( vertices, holes );
  16246. /* Vertices */
  16247. var contour = vertices; // vertices has all points but contour has only points of circumference
  16248. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16249. ahole = holes[ h ];
  16250. vertices = vertices.concat( ahole );
  16251. }
  16252. function scalePt2( pt, vec, size ) {
  16253. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  16254. return vec.clone().multiplyScalar( size ).add( pt );
  16255. }
  16256. var b, bs, t, z,
  16257. vert, vlen = vertices.length,
  16258. face, flen = faces.length;
  16259. // Find directions for point movement
  16260. function getBevelVec( inPt, inPrev, inNext ) {
  16261. // computes for inPt the corresponding point inPt' on a new contour
  16262. // shifted by 1 unit (length of normalized vector) to the left
  16263. // if we walk along contour clockwise, this new contour is outside the old one
  16264. //
  16265. // inPt' is the intersection of the two lines parallel to the two
  16266. // adjacent edges of inPt at a distance of 1 unit on the left side.
  16267. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  16268. // good reading for geometry algorithms (here: line-line intersection)
  16269. // http://geomalgorithms.com/a05-_intersect-1.html
  16270. var v_prev_x = inPt.x - inPrev.x,
  16271. v_prev_y = inPt.y - inPrev.y;
  16272. var v_next_x = inNext.x - inPt.x,
  16273. v_next_y = inNext.y - inPt.y;
  16274. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  16275. // check for collinear edges
  16276. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  16277. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  16278. // not collinear
  16279. // length of vectors for normalizing
  16280. var v_prev_len = Math.sqrt( v_prev_lensq );
  16281. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  16282. // shift adjacent points by unit vectors to the left
  16283. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  16284. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  16285. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  16286. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  16287. // scaling factor for v_prev to intersection point
  16288. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  16289. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  16290. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  16291. // vector from inPt to intersection point
  16292. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  16293. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  16294. // Don't normalize!, otherwise sharp corners become ugly
  16295. // but prevent crazy spikes
  16296. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  16297. if ( v_trans_lensq <= 2 ) {
  16298. return new Vector2( v_trans_x, v_trans_y );
  16299. } else {
  16300. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  16301. }
  16302. } else {
  16303. // handle special case of collinear edges
  16304. var direction_eq = false; // assumes: opposite
  16305. if ( v_prev_x > Number.EPSILON ) {
  16306. if ( v_next_x > Number.EPSILON ) {
  16307. direction_eq = true;
  16308. }
  16309. } else {
  16310. if ( v_prev_x < - Number.EPSILON ) {
  16311. if ( v_next_x < - Number.EPSILON ) {
  16312. direction_eq = true;
  16313. }
  16314. } else {
  16315. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  16316. direction_eq = true;
  16317. }
  16318. }
  16319. }
  16320. if ( direction_eq ) {
  16321. // console.log("Warning: lines are a straight sequence");
  16322. v_trans_x = - v_prev_y;
  16323. v_trans_y = v_prev_x;
  16324. shrink_by = Math.sqrt( v_prev_lensq );
  16325. } else {
  16326. // console.log("Warning: lines are a straight spike");
  16327. v_trans_x = v_prev_x;
  16328. v_trans_y = v_prev_y;
  16329. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  16330. }
  16331. }
  16332. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  16333. }
  16334. var contourMovements = [];
  16335. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  16336. if ( j === il ) j = 0;
  16337. if ( k === il ) k = 0;
  16338. // (j)---(i)---(k)
  16339. // console.log('i,j,k', i, j , k)
  16340. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  16341. }
  16342. var holesMovements = [],
  16343. oneHoleMovements, verticesMovements = contourMovements.concat();
  16344. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16345. ahole = holes[ h ];
  16346. oneHoleMovements = [];
  16347. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  16348. if ( j === il ) j = 0;
  16349. if ( k === il ) k = 0;
  16350. // (j)---(i)---(k)
  16351. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  16352. }
  16353. holesMovements.push( oneHoleMovements );
  16354. verticesMovements = verticesMovements.concat( oneHoleMovements );
  16355. }
  16356. // Loop bevelSegments, 1 for the front, 1 for the back
  16357. for ( b = 0; b < bevelSegments; b ++ ) {
  16358. //for ( b = bevelSegments; b > 0; b -- ) {
  16359. t = b / bevelSegments;
  16360. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  16361. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  16362. // contract shape
  16363. for ( i = 0, il = contour.length; i < il; i ++ ) {
  16364. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  16365. v( vert.x, vert.y, - z );
  16366. }
  16367. // expand holes
  16368. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16369. ahole = holes[ h ];
  16370. oneHoleMovements = holesMovements[ h ];
  16371. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  16372. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  16373. v( vert.x, vert.y, - z );
  16374. }
  16375. }
  16376. }
  16377. bs = bevelSize;
  16378. // Back facing vertices
  16379. for ( i = 0; i < vlen; i ++ ) {
  16380. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  16381. if ( ! extrudeByPath ) {
  16382. v( vert.x, vert.y, 0 );
  16383. } else {
  16384. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  16385. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  16386. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  16387. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  16388. v( position2.x, position2.y, position2.z );
  16389. }
  16390. }
  16391. // Add stepped vertices...
  16392. // Including front facing vertices
  16393. var s;
  16394. for ( s = 1; s <= steps; s ++ ) {
  16395. for ( i = 0; i < vlen; i ++ ) {
  16396. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  16397. if ( ! extrudeByPath ) {
  16398. v( vert.x, vert.y, amount / steps * s );
  16399. } else {
  16400. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  16401. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  16402. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  16403. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  16404. v( position2.x, position2.y, position2.z );
  16405. }
  16406. }
  16407. }
  16408. // Add bevel segments planes
  16409. //for ( b = 1; b <= bevelSegments; b ++ ) {
  16410. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  16411. t = b / bevelSegments;
  16412. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  16413. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  16414. // contract shape
  16415. for ( i = 0, il = contour.length; i < il; i ++ ) {
  16416. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  16417. v( vert.x, vert.y, amount + z );
  16418. }
  16419. // expand holes
  16420. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16421. ahole = holes[ h ];
  16422. oneHoleMovements = holesMovements[ h ];
  16423. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  16424. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  16425. if ( ! extrudeByPath ) {
  16426. v( vert.x, vert.y, amount + z );
  16427. } else {
  16428. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  16429. }
  16430. }
  16431. }
  16432. }
  16433. /* Faces */
  16434. // Top and bottom faces
  16435. buildLidFaces();
  16436. // Sides faces
  16437. buildSideFaces();
  16438. ///// Internal functions
  16439. function buildLidFaces() {
  16440. var start = verticesArray.length / 3;
  16441. if ( bevelEnabled ) {
  16442. var layer = 0; // steps + 1
  16443. var offset = vlen * layer;
  16444. // Bottom faces
  16445. for ( i = 0; i < flen; i ++ ) {
  16446. face = faces[ i ];
  16447. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  16448. }
  16449. layer = steps + bevelSegments * 2;
  16450. offset = vlen * layer;
  16451. // Top faces
  16452. for ( i = 0; i < flen; i ++ ) {
  16453. face = faces[ i ];
  16454. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  16455. }
  16456. } else {
  16457. // Bottom faces
  16458. for ( i = 0; i < flen; i ++ ) {
  16459. face = faces[ i ];
  16460. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  16461. }
  16462. // Top faces
  16463. for ( i = 0; i < flen; i ++ ) {
  16464. face = faces[ i ];
  16465. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  16466. }
  16467. }
  16468. scope.addGroup( start, verticesArray.length / 3 - start, options.material !== undefined ? options.material : 0 );
  16469. }
  16470. // Create faces for the z-sides of the shape
  16471. function buildSideFaces() {
  16472. var start = verticesArray.length / 3;
  16473. var layeroffset = 0;
  16474. sidewalls( contour, layeroffset );
  16475. layeroffset += contour.length;
  16476. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16477. ahole = holes[ h ];
  16478. sidewalls( ahole, layeroffset );
  16479. //, true
  16480. layeroffset += ahole.length;
  16481. }
  16482. scope.addGroup( start, verticesArray.length / 3 - start, options.extrudeMaterial !== undefined ? options.extrudeMaterial : 1 );
  16483. }
  16484. function sidewalls( contour, layeroffset ) {
  16485. var j, k;
  16486. i = contour.length;
  16487. while ( -- i >= 0 ) {
  16488. j = i;
  16489. k = i - 1;
  16490. if ( k < 0 ) k = contour.length - 1;
  16491. //console.log('b', i,j, i-1, k,vertices.length);
  16492. var s = 0,
  16493. sl = steps + bevelSegments * 2;
  16494. for ( s = 0; s < sl; s ++ ) {
  16495. var slen1 = vlen * s;
  16496. var slen2 = vlen * ( s + 1 );
  16497. var a = layeroffset + j + slen1,
  16498. b = layeroffset + k + slen1,
  16499. c = layeroffset + k + slen2,
  16500. d = layeroffset + j + slen2;
  16501. f4( a, b, c, d );
  16502. }
  16503. }
  16504. }
  16505. function v( x, y, z ) {
  16506. placeholder.push( x );
  16507. placeholder.push( y );
  16508. placeholder.push( z );
  16509. }
  16510. function f3( a, b, c ) {
  16511. addVertex( a );
  16512. addVertex( b );
  16513. addVertex( c );
  16514. var nextIndex = verticesArray.length / 3;
  16515. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  16516. addUV( uvs[ 0 ] );
  16517. addUV( uvs[ 1 ] );
  16518. addUV( uvs[ 2 ] );
  16519. }
  16520. function f4( a, b, c, d ) {
  16521. addVertex( a );
  16522. addVertex( b );
  16523. addVertex( d );
  16524. addVertex( b );
  16525. addVertex( c );
  16526. addVertex( d );
  16527. var nextIndex = verticesArray.length / 3;
  16528. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  16529. addUV( uvs[ 0 ] );
  16530. addUV( uvs[ 1 ] );
  16531. addUV( uvs[ 3 ] );
  16532. addUV( uvs[ 1 ] );
  16533. addUV( uvs[ 2 ] );
  16534. addUV( uvs[ 3 ] );
  16535. }
  16536. function addVertex( index ) {
  16537. indicesArray.push( verticesArray.length / 3 );
  16538. verticesArray.push( placeholder[ index * 3 + 0 ] );
  16539. verticesArray.push( placeholder[ index * 3 + 1 ] );
  16540. verticesArray.push( placeholder[ index * 3 + 2 ] );
  16541. }
  16542. function addUV( vector2 ) {
  16543. uvArray.push( vector2.x );
  16544. uvArray.push( vector2.y );
  16545. }
  16546. if ( ! options.arrays ) {
  16547. this.setIndex( indicesArray );
  16548. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  16549. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  16550. }
  16551. };
  16552. ExtrudeGeometry.WorldUVGenerator = {
  16553. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  16554. var a_x = vertices[ indexA * 3 ];
  16555. var a_y = vertices[ indexA * 3 + 1 ];
  16556. var b_x = vertices[ indexB * 3 ];
  16557. var b_y = vertices[ indexB * 3 + 1 ];
  16558. var c_x = vertices[ indexC * 3 ];
  16559. var c_y = vertices[ indexC * 3 + 1 ];
  16560. return [
  16561. new Vector2( a_x, a_y ),
  16562. new Vector2( b_x, b_y ),
  16563. new Vector2( c_x, c_y )
  16564. ];
  16565. },
  16566. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  16567. var a_x = vertices[ indexA * 3 ];
  16568. var a_y = vertices[ indexA * 3 + 1 ];
  16569. var a_z = vertices[ indexA * 3 + 2 ];
  16570. var b_x = vertices[ indexB * 3 ];
  16571. var b_y = vertices[ indexB * 3 + 1 ];
  16572. var b_z = vertices[ indexB * 3 + 2 ];
  16573. var c_x = vertices[ indexC * 3 ];
  16574. var c_y = vertices[ indexC * 3 + 1 ];
  16575. var c_z = vertices[ indexC * 3 + 2 ];
  16576. var d_x = vertices[ indexD * 3 ];
  16577. var d_y = vertices[ indexD * 3 + 1 ];
  16578. var d_z = vertices[ indexD * 3 + 2 ];
  16579. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  16580. return [
  16581. new Vector2( a_x, 1 - a_z ),
  16582. new Vector2( b_x, 1 - b_z ),
  16583. new Vector2( c_x, 1 - c_z ),
  16584. new Vector2( d_x, 1 - d_z )
  16585. ];
  16586. } else {
  16587. return [
  16588. new Vector2( a_y, 1 - a_z ),
  16589. new Vector2( b_y, 1 - b_z ),
  16590. new Vector2( c_y, 1 - c_z ),
  16591. new Vector2( d_y, 1 - d_z )
  16592. ];
  16593. }
  16594. }
  16595. };
  16596. /**
  16597. * @author zz85 / http://www.lab4games.net/zz85/blog
  16598. * @author alteredq / http://alteredqualia.com/
  16599. *
  16600. * Text = 3D Text
  16601. *
  16602. * parameters = {
  16603. * font: <THREE.Font>, // font
  16604. *
  16605. * size: <float>, // size of the text
  16606. * height: <float>, // thickness to extrude text
  16607. * curveSegments: <int>, // number of points on the curves
  16608. *
  16609. * bevelEnabled: <bool>, // turn on bevel
  16610. * bevelThickness: <float>, // how deep into text bevel goes
  16611. * bevelSize: <float> // how far from text outline is bevel
  16612. * }
  16613. */
  16614. // TextGeometry
  16615. function TextGeometry( text, parameters ) {
  16616. Geometry.call( this );
  16617. this.type = 'TextGeometry';
  16618. this.parameters = {
  16619. text: text,
  16620. parameters: parameters
  16621. };
  16622. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  16623. this.mergeVertices();
  16624. }
  16625. TextGeometry.prototype = Object.create( Geometry.prototype );
  16626. TextGeometry.prototype.constructor = TextGeometry;
  16627. // TextBufferGeometry
  16628. function TextBufferGeometry( text, parameters ) {
  16629. parameters = parameters || {};
  16630. var font = parameters.font;
  16631. if ( ! ( font && font.isFont ) ) {
  16632. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  16633. return new Geometry();
  16634. }
  16635. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  16636. // translate parameters to ExtrudeGeometry API
  16637. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  16638. // defaults
  16639. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  16640. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  16641. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  16642. ExtrudeBufferGeometry.call( this, shapes, parameters );
  16643. this.type = 'TextBufferGeometry';
  16644. }
  16645. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  16646. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  16647. /**
  16648. * @author mrdoob / http://mrdoob.com/
  16649. * @author benaadams / https://twitter.com/ben_a_adams
  16650. * @author Mugen87 / https://github.com/Mugen87
  16651. */
  16652. // SphereGeometry
  16653. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  16654. Geometry.call( this );
  16655. this.type = 'SphereGeometry';
  16656. this.parameters = {
  16657. radius: radius,
  16658. widthSegments: widthSegments,
  16659. heightSegments: heightSegments,
  16660. phiStart: phiStart,
  16661. phiLength: phiLength,
  16662. thetaStart: thetaStart,
  16663. thetaLength: thetaLength
  16664. };
  16665. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  16666. this.mergeVertices();
  16667. }
  16668. SphereGeometry.prototype = Object.create( Geometry.prototype );
  16669. SphereGeometry.prototype.constructor = SphereGeometry;
  16670. // SphereBufferGeometry
  16671. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  16672. BufferGeometry.call( this );
  16673. this.type = 'SphereBufferGeometry';
  16674. this.parameters = {
  16675. radius: radius,
  16676. widthSegments: widthSegments,
  16677. heightSegments: heightSegments,
  16678. phiStart: phiStart,
  16679. phiLength: phiLength,
  16680. thetaStart: thetaStart,
  16681. thetaLength: thetaLength
  16682. };
  16683. radius = radius || 1;
  16684. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  16685. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  16686. phiStart = phiStart !== undefined ? phiStart : 0;
  16687. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  16688. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  16689. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  16690. var thetaEnd = thetaStart + thetaLength;
  16691. var ix, iy;
  16692. var index = 0;
  16693. var grid = [];
  16694. var vertex = new Vector3();
  16695. var normal = new Vector3();
  16696. // buffers
  16697. var indices = [];
  16698. var vertices = [];
  16699. var normals = [];
  16700. var uvs = [];
  16701. // generate vertices, normals and uvs
  16702. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  16703. var verticesRow = [];
  16704. var v = iy / heightSegments;
  16705. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  16706. var u = ix / widthSegments;
  16707. // vertex
  16708. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  16709. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  16710. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  16711. vertices.push( vertex.x, vertex.y, vertex.z );
  16712. // normal
  16713. normal.set( vertex.x, vertex.y, vertex.z ).normalize();
  16714. normals.push( normal.x, normal.y, normal.z );
  16715. // uv
  16716. uvs.push( u, 1 - v );
  16717. verticesRow.push( index ++ );
  16718. }
  16719. grid.push( verticesRow );
  16720. }
  16721. // indices
  16722. for ( iy = 0; iy < heightSegments; iy ++ ) {
  16723. for ( ix = 0; ix < widthSegments; ix ++ ) {
  16724. var a = grid[ iy ][ ix + 1 ];
  16725. var b = grid[ iy ][ ix ];
  16726. var c = grid[ iy + 1 ][ ix ];
  16727. var d = grid[ iy + 1 ][ ix + 1 ];
  16728. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  16729. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  16730. }
  16731. }
  16732. // build geometry
  16733. this.setIndex( indices );
  16734. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16735. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16736. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16737. }
  16738. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16739. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  16740. /**
  16741. * @author Kaleb Murphy
  16742. * @author Mugen87 / https://github.com/Mugen87
  16743. */
  16744. // RingGeometry
  16745. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  16746. Geometry.call( this );
  16747. this.type = 'RingGeometry';
  16748. this.parameters = {
  16749. innerRadius: innerRadius,
  16750. outerRadius: outerRadius,
  16751. thetaSegments: thetaSegments,
  16752. phiSegments: phiSegments,
  16753. thetaStart: thetaStart,
  16754. thetaLength: thetaLength
  16755. };
  16756. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  16757. this.mergeVertices();
  16758. }
  16759. RingGeometry.prototype = Object.create( Geometry.prototype );
  16760. RingGeometry.prototype.constructor = RingGeometry;
  16761. // RingBufferGeometry
  16762. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  16763. BufferGeometry.call( this );
  16764. this.type = 'RingBufferGeometry';
  16765. this.parameters = {
  16766. innerRadius: innerRadius,
  16767. outerRadius: outerRadius,
  16768. thetaSegments: thetaSegments,
  16769. phiSegments: phiSegments,
  16770. thetaStart: thetaStart,
  16771. thetaLength: thetaLength
  16772. };
  16773. innerRadius = innerRadius || 0.5;
  16774. outerRadius = outerRadius || 1;
  16775. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  16776. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  16777. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  16778. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  16779. // buffers
  16780. var indices = [];
  16781. var vertices = [];
  16782. var normals = [];
  16783. var uvs = [];
  16784. // some helper variables
  16785. var segment;
  16786. var radius = innerRadius;
  16787. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  16788. var vertex = new Vector3();
  16789. var uv = new Vector2();
  16790. var j, i;
  16791. // generate vertices, normals and uvs
  16792. for ( j = 0; j <= phiSegments; j ++ ) {
  16793. for ( i = 0; i <= thetaSegments; i ++ ) {
  16794. // values are generate from the inside of the ring to the outside
  16795. segment = thetaStart + i / thetaSegments * thetaLength;
  16796. // vertex
  16797. vertex.x = radius * Math.cos( segment );
  16798. vertex.y = radius * Math.sin( segment );
  16799. vertices.push( vertex.x, vertex.y, vertex.z );
  16800. // normal
  16801. normals.push( 0, 0, 1 );
  16802. // uv
  16803. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  16804. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  16805. uvs.push( uv.x, uv.y );
  16806. }
  16807. // increase the radius for next row of vertices
  16808. radius += radiusStep;
  16809. }
  16810. // indices
  16811. for ( j = 0; j < phiSegments; j ++ ) {
  16812. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  16813. for ( i = 0; i < thetaSegments; i ++ ) {
  16814. segment = i + thetaSegmentLevel;
  16815. var a = segment;
  16816. var b = segment + thetaSegments + 1;
  16817. var c = segment + thetaSegments + 2;
  16818. var d = segment + 1;
  16819. // faces
  16820. indices.push( a, b, d );
  16821. indices.push( b, c, d );
  16822. }
  16823. }
  16824. // build geometry
  16825. this.setIndex( indices );
  16826. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16827. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16828. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16829. }
  16830. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16831. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  16832. /**
  16833. * @author astrodud / http://astrodud.isgreat.org/
  16834. * @author zz85 / https://github.com/zz85
  16835. * @author bhouston / http://clara.io
  16836. * @author Mugen87 / https://github.com/Mugen87
  16837. */
  16838. // LatheGeometry
  16839. function LatheGeometry( points, segments, phiStart, phiLength ) {
  16840. Geometry.call( this );
  16841. this.type = 'LatheGeometry';
  16842. this.parameters = {
  16843. points: points,
  16844. segments: segments,
  16845. phiStart: phiStart,
  16846. phiLength: phiLength
  16847. };
  16848. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  16849. this.mergeVertices();
  16850. }
  16851. LatheGeometry.prototype = Object.create( Geometry.prototype );
  16852. LatheGeometry.prototype.constructor = LatheGeometry;
  16853. // LatheBufferGeometry
  16854. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  16855. BufferGeometry.call( this );
  16856. this.type = 'LatheBufferGeometry';
  16857. this.parameters = {
  16858. points: points,
  16859. segments: segments,
  16860. phiStart: phiStart,
  16861. phiLength: phiLength
  16862. };
  16863. segments = Math.floor( segments ) || 12;
  16864. phiStart = phiStart || 0;
  16865. phiLength = phiLength || Math.PI * 2;
  16866. // clamp phiLength so it's in range of [ 0, 2PI ]
  16867. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  16868. // buffers
  16869. var indices = [];
  16870. var vertices = [];
  16871. var uvs = [];
  16872. // helper variables
  16873. var base;
  16874. var inverseSegments = 1.0 / segments;
  16875. var vertex = new Vector3();
  16876. var uv = new Vector2();
  16877. var i, j;
  16878. // generate vertices and uvs
  16879. for ( i = 0; i <= segments; i ++ ) {
  16880. var phi = phiStart + i * inverseSegments * phiLength;
  16881. var sin = Math.sin( phi );
  16882. var cos = Math.cos( phi );
  16883. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  16884. // vertex
  16885. vertex.x = points[ j ].x * sin;
  16886. vertex.y = points[ j ].y;
  16887. vertex.z = points[ j ].x * cos;
  16888. vertices.push( vertex.x, vertex.y, vertex.z );
  16889. // uv
  16890. uv.x = i / segments;
  16891. uv.y = j / ( points.length - 1 );
  16892. uvs.push( uv.x, uv.y );
  16893. }
  16894. }
  16895. // indices
  16896. for ( i = 0; i < segments; i ++ ) {
  16897. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  16898. base = j + i * points.length;
  16899. var a = base;
  16900. var b = base + points.length;
  16901. var c = base + points.length + 1;
  16902. var d = base + 1;
  16903. // faces
  16904. indices.push( a, b, d );
  16905. indices.push( b, c, d );
  16906. }
  16907. }
  16908. // build geometry
  16909. this.setIndex( indices );
  16910. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16911. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16912. // generate normals
  16913. this.computeVertexNormals();
  16914. // if the geometry is closed, we need to average the normals along the seam.
  16915. // because the corresponding vertices are identical (but still have different UVs).
  16916. if ( phiLength === Math.PI * 2 ) {
  16917. var normals = this.attributes.normal.array;
  16918. var n1 = new Vector3();
  16919. var n2 = new Vector3();
  16920. var n = new Vector3();
  16921. // this is the buffer offset for the last line of vertices
  16922. base = segments * points.length * 3;
  16923. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  16924. // select the normal of the vertex in the first line
  16925. n1.x = normals[ j + 0 ];
  16926. n1.y = normals[ j + 1 ];
  16927. n1.z = normals[ j + 2 ];
  16928. // select the normal of the vertex in the last line
  16929. n2.x = normals[ base + j + 0 ];
  16930. n2.y = normals[ base + j + 1 ];
  16931. n2.z = normals[ base + j + 2 ];
  16932. // average normals
  16933. n.addVectors( n1, n2 ).normalize();
  16934. // assign the new values to both normals
  16935. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  16936. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  16937. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  16938. }
  16939. }
  16940. }
  16941. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16942. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  16943. /**
  16944. * @author jonobr1 / http://jonobr1.com
  16945. * @author Mugen87 / https://github.com/Mugen87
  16946. */
  16947. // ShapeGeometry
  16948. function ShapeGeometry( shapes, curveSegments ) {
  16949. Geometry.call( this );
  16950. this.type = 'ShapeGeometry';
  16951. if ( typeof curveSegments === 'object' ) {
  16952. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  16953. curveSegments = curveSegments.curveSegments;
  16954. }
  16955. this.parameters = {
  16956. shapes: shapes,
  16957. curveSegments: curveSegments
  16958. };
  16959. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  16960. this.mergeVertices();
  16961. }
  16962. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  16963. ShapeGeometry.prototype.constructor = ShapeGeometry;
  16964. ShapeGeometry.prototype.toJSON = function () {
  16965. var data = Geometry.prototype.toJSON.call( this );
  16966. var shapes = this.parameters.shapes;
  16967. return toJSON( shapes, data );
  16968. };
  16969. // ShapeBufferGeometry
  16970. function ShapeBufferGeometry( shapes, curveSegments ) {
  16971. BufferGeometry.call( this );
  16972. this.type = 'ShapeBufferGeometry';
  16973. this.parameters = {
  16974. shapes: shapes,
  16975. curveSegments: curveSegments
  16976. };
  16977. curveSegments = curveSegments || 12;
  16978. // buffers
  16979. var indices = [];
  16980. var vertices = [];
  16981. var normals = [];
  16982. var uvs = [];
  16983. // helper variables
  16984. var groupStart = 0;
  16985. var groupCount = 0;
  16986. // allow single and array values for "shapes" parameter
  16987. if ( Array.isArray( shapes ) === false ) {
  16988. addShape( shapes );
  16989. } else {
  16990. for ( var i = 0; i < shapes.length; i ++ ) {
  16991. addShape( shapes[ i ] );
  16992. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  16993. groupStart += groupCount;
  16994. groupCount = 0;
  16995. }
  16996. }
  16997. // build geometry
  16998. this.setIndex( indices );
  16999. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17000. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17001. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17002. // helper functions
  17003. function addShape( shape ) {
  17004. var i, l, shapeHole;
  17005. var indexOffset = vertices.length / 3;
  17006. var points = shape.extractPoints( curveSegments );
  17007. var shapeVertices = points.shape;
  17008. var shapeHoles = points.holes;
  17009. // check direction of vertices
  17010. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  17011. shapeVertices = shapeVertices.reverse();
  17012. // also check if holes are in the opposite direction
  17013. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  17014. shapeHole = shapeHoles[ i ];
  17015. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  17016. shapeHoles[ i ] = shapeHole.reverse();
  17017. }
  17018. }
  17019. }
  17020. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  17021. // join vertices of inner and outer paths to a single array
  17022. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  17023. shapeHole = shapeHoles[ i ];
  17024. shapeVertices = shapeVertices.concat( shapeHole );
  17025. }
  17026. // vertices, normals, uvs
  17027. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  17028. var vertex = shapeVertices[ i ];
  17029. vertices.push( vertex.x, vertex.y, 0 );
  17030. normals.push( 0, 0, 1 );
  17031. uvs.push( vertex.x, vertex.y ); // world uvs
  17032. }
  17033. // incides
  17034. for ( i = 0, l = faces.length; i < l; i ++ ) {
  17035. var face = faces[ i ];
  17036. var a = face[ 0 ] + indexOffset;
  17037. var b = face[ 1 ] + indexOffset;
  17038. var c = face[ 2 ] + indexOffset;
  17039. indices.push( a, b, c );
  17040. groupCount += 3;
  17041. }
  17042. }
  17043. }
  17044. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17045. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  17046. ShapeBufferGeometry.prototype.toJSON = function () {
  17047. var data = BufferGeometry.prototype.toJSON.call( this );
  17048. var shapes = this.parameters.shapes;
  17049. return toJSON( shapes, data );
  17050. };
  17051. //
  17052. function toJSON( shapes, data ) {
  17053. data.shapes = [];
  17054. if ( Array.isArray( shapes ) ) {
  17055. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17056. var shape = shapes[ i ];
  17057. data.shapes.push( shape.uuid );
  17058. }
  17059. } else {
  17060. data.shapes.push( shapes.uuid );
  17061. }
  17062. return data;
  17063. }
  17064. /**
  17065. * @author WestLangley / http://github.com/WestLangley
  17066. * @author Mugen87 / https://github.com/Mugen87
  17067. */
  17068. function EdgesGeometry( geometry, thresholdAngle ) {
  17069. BufferGeometry.call( this );
  17070. this.type = 'EdgesGeometry';
  17071. this.parameters = {
  17072. thresholdAngle: thresholdAngle
  17073. };
  17074. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  17075. // buffer
  17076. var vertices = [];
  17077. // helper variables
  17078. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  17079. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  17080. var key, keys = [ 'a', 'b', 'c' ];
  17081. // prepare source geometry
  17082. var geometry2;
  17083. if ( geometry.isBufferGeometry ) {
  17084. geometry2 = new Geometry();
  17085. geometry2.fromBufferGeometry( geometry );
  17086. } else {
  17087. geometry2 = geometry.clone();
  17088. }
  17089. geometry2.mergeVertices();
  17090. geometry2.computeFaceNormals();
  17091. var sourceVertices = geometry2.vertices;
  17092. var faces = geometry2.faces;
  17093. // now create a data structure where each entry represents an edge with its adjoining faces
  17094. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  17095. var face = faces[ i ];
  17096. for ( var j = 0; j < 3; j ++ ) {
  17097. edge1 = face[ keys[ j ] ];
  17098. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  17099. edge[ 0 ] = Math.min( edge1, edge2 );
  17100. edge[ 1 ] = Math.max( edge1, edge2 );
  17101. key = edge[ 0 ] + ',' + edge[ 1 ];
  17102. if ( edges[ key ] === undefined ) {
  17103. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  17104. } else {
  17105. edges[ key ].face2 = i;
  17106. }
  17107. }
  17108. }
  17109. // generate vertices
  17110. for ( key in edges ) {
  17111. var e = edges[ key ];
  17112. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  17113. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  17114. var vertex = sourceVertices[ e.index1 ];
  17115. vertices.push( vertex.x, vertex.y, vertex.z );
  17116. vertex = sourceVertices[ e.index2 ];
  17117. vertices.push( vertex.x, vertex.y, vertex.z );
  17118. }
  17119. }
  17120. // build geometry
  17121. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17122. }
  17123. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  17124. EdgesGeometry.prototype.constructor = EdgesGeometry;
  17125. /**
  17126. * @author mrdoob / http://mrdoob.com/
  17127. * @author Mugen87 / https://github.com/Mugen87
  17128. */
  17129. // CylinderGeometry
  17130. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17131. Geometry.call( this );
  17132. this.type = 'CylinderGeometry';
  17133. this.parameters = {
  17134. radiusTop: radiusTop,
  17135. radiusBottom: radiusBottom,
  17136. height: height,
  17137. radialSegments: radialSegments,
  17138. heightSegments: heightSegments,
  17139. openEnded: openEnded,
  17140. thetaStart: thetaStart,
  17141. thetaLength: thetaLength
  17142. };
  17143. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  17144. this.mergeVertices();
  17145. }
  17146. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  17147. CylinderGeometry.prototype.constructor = CylinderGeometry;
  17148. // CylinderBufferGeometry
  17149. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17150. BufferGeometry.call( this );
  17151. this.type = 'CylinderBufferGeometry';
  17152. this.parameters = {
  17153. radiusTop: radiusTop,
  17154. radiusBottom: radiusBottom,
  17155. height: height,
  17156. radialSegments: radialSegments,
  17157. heightSegments: heightSegments,
  17158. openEnded: openEnded,
  17159. thetaStart: thetaStart,
  17160. thetaLength: thetaLength
  17161. };
  17162. var scope = this;
  17163. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  17164. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  17165. height = height || 1;
  17166. radialSegments = Math.floor( radialSegments ) || 8;
  17167. heightSegments = Math.floor( heightSegments ) || 1;
  17168. openEnded = openEnded !== undefined ? openEnded : false;
  17169. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  17170. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  17171. // buffers
  17172. var indices = [];
  17173. var vertices = [];
  17174. var normals = [];
  17175. var uvs = [];
  17176. // helper variables
  17177. var index = 0;
  17178. var indexArray = [];
  17179. var halfHeight = height / 2;
  17180. var groupStart = 0;
  17181. // generate geometry
  17182. generateTorso();
  17183. if ( openEnded === false ) {
  17184. if ( radiusTop > 0 ) generateCap( true );
  17185. if ( radiusBottom > 0 ) generateCap( false );
  17186. }
  17187. // build geometry
  17188. this.setIndex( indices );
  17189. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17190. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17191. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17192. function generateTorso() {
  17193. var x, y;
  17194. var normal = new Vector3();
  17195. var vertex = new Vector3();
  17196. var groupCount = 0;
  17197. // this will be used to calculate the normal
  17198. var slope = ( radiusBottom - radiusTop ) / height;
  17199. // generate vertices, normals and uvs
  17200. for ( y = 0; y <= heightSegments; y ++ ) {
  17201. var indexRow = [];
  17202. var v = y / heightSegments;
  17203. // calculate the radius of the current row
  17204. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  17205. for ( x = 0; x <= radialSegments; x ++ ) {
  17206. var u = x / radialSegments;
  17207. var theta = u * thetaLength + thetaStart;
  17208. var sinTheta = Math.sin( theta );
  17209. var cosTheta = Math.cos( theta );
  17210. // vertex
  17211. vertex.x = radius * sinTheta;
  17212. vertex.y = - v * height + halfHeight;
  17213. vertex.z = radius * cosTheta;
  17214. vertices.push( vertex.x, vertex.y, vertex.z );
  17215. // normal
  17216. normal.set( sinTheta, slope, cosTheta ).normalize();
  17217. normals.push( normal.x, normal.y, normal.z );
  17218. // uv
  17219. uvs.push( u, 1 - v );
  17220. // save index of vertex in respective row
  17221. indexRow.push( index ++ );
  17222. }
  17223. // now save vertices of the row in our index array
  17224. indexArray.push( indexRow );
  17225. }
  17226. // generate indices
  17227. for ( x = 0; x < radialSegments; x ++ ) {
  17228. for ( y = 0; y < heightSegments; y ++ ) {
  17229. // we use the index array to access the correct indices
  17230. var a = indexArray[ y ][ x ];
  17231. var b = indexArray[ y + 1 ][ x ];
  17232. var c = indexArray[ y + 1 ][ x + 1 ];
  17233. var d = indexArray[ y ][ x + 1 ];
  17234. // faces
  17235. indices.push( a, b, d );
  17236. indices.push( b, c, d );
  17237. // update group counter
  17238. groupCount += 6;
  17239. }
  17240. }
  17241. // add a group to the geometry. this will ensure multi material support
  17242. scope.addGroup( groupStart, groupCount, 0 );
  17243. // calculate new start value for groups
  17244. groupStart += groupCount;
  17245. }
  17246. function generateCap( top ) {
  17247. var x, centerIndexStart, centerIndexEnd;
  17248. var uv = new Vector2();
  17249. var vertex = new Vector3();
  17250. var groupCount = 0;
  17251. var radius = ( top === true ) ? radiusTop : radiusBottom;
  17252. var sign = ( top === true ) ? 1 : - 1;
  17253. // save the index of the first center vertex
  17254. centerIndexStart = index;
  17255. // first we generate the center vertex data of the cap.
  17256. // because the geometry needs one set of uvs per face,
  17257. // we must generate a center vertex per face/segment
  17258. for ( x = 1; x <= radialSegments; x ++ ) {
  17259. // vertex
  17260. vertices.push( 0, halfHeight * sign, 0 );
  17261. // normal
  17262. normals.push( 0, sign, 0 );
  17263. // uv
  17264. uvs.push( 0.5, 0.5 );
  17265. // increase index
  17266. index ++;
  17267. }
  17268. // save the index of the last center vertex
  17269. centerIndexEnd = index;
  17270. // now we generate the surrounding vertices, normals and uvs
  17271. for ( x = 0; x <= radialSegments; x ++ ) {
  17272. var u = x / radialSegments;
  17273. var theta = u * thetaLength + thetaStart;
  17274. var cosTheta = Math.cos( theta );
  17275. var sinTheta = Math.sin( theta );
  17276. // vertex
  17277. vertex.x = radius * sinTheta;
  17278. vertex.y = halfHeight * sign;
  17279. vertex.z = radius * cosTheta;
  17280. vertices.push( vertex.x, vertex.y, vertex.z );
  17281. // normal
  17282. normals.push( 0, sign, 0 );
  17283. // uv
  17284. uv.x = ( cosTheta * 0.5 ) + 0.5;
  17285. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  17286. uvs.push( uv.x, uv.y );
  17287. // increase index
  17288. index ++;
  17289. }
  17290. // generate indices
  17291. for ( x = 0; x < radialSegments; x ++ ) {
  17292. var c = centerIndexStart + x;
  17293. var i = centerIndexEnd + x;
  17294. if ( top === true ) {
  17295. // face top
  17296. indices.push( i, i + 1, c );
  17297. } else {
  17298. // face bottom
  17299. indices.push( i + 1, i, c );
  17300. }
  17301. groupCount += 3;
  17302. }
  17303. // add a group to the geometry. this will ensure multi material support
  17304. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  17305. // calculate new start value for groups
  17306. groupStart += groupCount;
  17307. }
  17308. }
  17309. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17310. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  17311. /**
  17312. * @author abelnation / http://github.com/abelnation
  17313. */
  17314. // ConeGeometry
  17315. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17316. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  17317. this.type = 'ConeGeometry';
  17318. this.parameters = {
  17319. radius: radius,
  17320. height: height,
  17321. radialSegments: radialSegments,
  17322. heightSegments: heightSegments,
  17323. openEnded: openEnded,
  17324. thetaStart: thetaStart,
  17325. thetaLength: thetaLength
  17326. };
  17327. }
  17328. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  17329. ConeGeometry.prototype.constructor = ConeGeometry;
  17330. // ConeBufferGeometry
  17331. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17332. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  17333. this.type = 'ConeBufferGeometry';
  17334. this.parameters = {
  17335. radius: radius,
  17336. height: height,
  17337. radialSegments: radialSegments,
  17338. heightSegments: heightSegments,
  17339. openEnded: openEnded,
  17340. thetaStart: thetaStart,
  17341. thetaLength: thetaLength
  17342. };
  17343. }
  17344. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  17345. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  17346. /**
  17347. * @author benaadams / https://twitter.com/ben_a_adams
  17348. * @author Mugen87 / https://github.com/Mugen87
  17349. * @author hughes
  17350. */
  17351. // CircleGeometry
  17352. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  17353. Geometry.call( this );
  17354. this.type = 'CircleGeometry';
  17355. this.parameters = {
  17356. radius: radius,
  17357. segments: segments,
  17358. thetaStart: thetaStart,
  17359. thetaLength: thetaLength
  17360. };
  17361. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  17362. this.mergeVertices();
  17363. }
  17364. CircleGeometry.prototype = Object.create( Geometry.prototype );
  17365. CircleGeometry.prototype.constructor = CircleGeometry;
  17366. // CircleBufferGeometry
  17367. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  17368. BufferGeometry.call( this );
  17369. this.type = 'CircleBufferGeometry';
  17370. this.parameters = {
  17371. radius: radius,
  17372. segments: segments,
  17373. thetaStart: thetaStart,
  17374. thetaLength: thetaLength
  17375. };
  17376. radius = radius || 1;
  17377. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  17378. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17379. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  17380. // buffers
  17381. var indices = [];
  17382. var vertices = [];
  17383. var normals = [];
  17384. var uvs = [];
  17385. // helper variables
  17386. var i, s;
  17387. var vertex = new Vector3();
  17388. var uv = new Vector2();
  17389. // center point
  17390. vertices.push( 0, 0, 0 );
  17391. normals.push( 0, 0, 1 );
  17392. uvs.push( 0.5, 0.5 );
  17393. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  17394. var segment = thetaStart + s / segments * thetaLength;
  17395. // vertex
  17396. vertex.x = radius * Math.cos( segment );
  17397. vertex.y = radius * Math.sin( segment );
  17398. vertices.push( vertex.x, vertex.y, vertex.z );
  17399. // normal
  17400. normals.push( 0, 0, 1 );
  17401. // uvs
  17402. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  17403. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  17404. uvs.push( uv.x, uv.y );
  17405. }
  17406. // indices
  17407. for ( i = 1; i <= segments; i ++ ) {
  17408. indices.push( i, i + 1, 0 );
  17409. }
  17410. // build geometry
  17411. this.setIndex( indices );
  17412. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17413. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17414. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17415. }
  17416. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17417. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  17418. var Geometries = Object.freeze({
  17419. WireframeGeometry: WireframeGeometry,
  17420. ParametricGeometry: ParametricGeometry,
  17421. ParametricBufferGeometry: ParametricBufferGeometry,
  17422. TetrahedronGeometry: TetrahedronGeometry,
  17423. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  17424. OctahedronGeometry: OctahedronGeometry,
  17425. OctahedronBufferGeometry: OctahedronBufferGeometry,
  17426. IcosahedronGeometry: IcosahedronGeometry,
  17427. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  17428. DodecahedronGeometry: DodecahedronGeometry,
  17429. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  17430. PolyhedronGeometry: PolyhedronGeometry,
  17431. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  17432. TubeGeometry: TubeGeometry,
  17433. TubeBufferGeometry: TubeBufferGeometry,
  17434. TorusKnotGeometry: TorusKnotGeometry,
  17435. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  17436. TorusGeometry: TorusGeometry,
  17437. TorusBufferGeometry: TorusBufferGeometry,
  17438. TextGeometry: TextGeometry,
  17439. TextBufferGeometry: TextBufferGeometry,
  17440. SphereGeometry: SphereGeometry,
  17441. SphereBufferGeometry: SphereBufferGeometry,
  17442. RingGeometry: RingGeometry,
  17443. RingBufferGeometry: RingBufferGeometry,
  17444. PlaneGeometry: PlaneGeometry,
  17445. PlaneBufferGeometry: PlaneBufferGeometry,
  17446. LatheGeometry: LatheGeometry,
  17447. LatheBufferGeometry: LatheBufferGeometry,
  17448. ShapeGeometry: ShapeGeometry,
  17449. ShapeBufferGeometry: ShapeBufferGeometry,
  17450. ExtrudeGeometry: ExtrudeGeometry,
  17451. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  17452. EdgesGeometry: EdgesGeometry,
  17453. ConeGeometry: ConeGeometry,
  17454. ConeBufferGeometry: ConeBufferGeometry,
  17455. CylinderGeometry: CylinderGeometry,
  17456. CylinderBufferGeometry: CylinderBufferGeometry,
  17457. CircleGeometry: CircleGeometry,
  17458. CircleBufferGeometry: CircleBufferGeometry,
  17459. BoxGeometry: BoxGeometry,
  17460. BoxBufferGeometry: BoxBufferGeometry
  17461. });
  17462. /**
  17463. * @author mrdoob / http://mrdoob.com/
  17464. *
  17465. * parameters = {
  17466. * color: <THREE.Color>,
  17467. * opacity: <float>
  17468. * }
  17469. */
  17470. function ShadowMaterial( parameters ) {
  17471. Material.call( this );
  17472. this.type = 'ShadowMaterial';
  17473. this.color = new Color( 0x000000 );
  17474. this.opacity = 1.0;
  17475. this.lights = true;
  17476. this.transparent = true;
  17477. this.setValues( parameters );
  17478. }
  17479. ShadowMaterial.prototype = Object.create( Material.prototype );
  17480. ShadowMaterial.prototype.constructor = ShadowMaterial;
  17481. ShadowMaterial.prototype.isShadowMaterial = true;
  17482. /**
  17483. * @author mrdoob / http://mrdoob.com/
  17484. */
  17485. function RawShaderMaterial( parameters ) {
  17486. ShaderMaterial.call( this, parameters );
  17487. this.type = 'RawShaderMaterial';
  17488. }
  17489. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  17490. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  17491. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  17492. /**
  17493. * @author WestLangley / http://github.com/WestLangley
  17494. *
  17495. * parameters = {
  17496. * color: <hex>,
  17497. * roughness: <float>,
  17498. * metalness: <float>,
  17499. * opacity: <float>,
  17500. *
  17501. * map: new THREE.Texture( <Image> ),
  17502. *
  17503. * lightMap: new THREE.Texture( <Image> ),
  17504. * lightMapIntensity: <float>
  17505. *
  17506. * aoMap: new THREE.Texture( <Image> ),
  17507. * aoMapIntensity: <float>
  17508. *
  17509. * emissive: <hex>,
  17510. * emissiveIntensity: <float>
  17511. * emissiveMap: new THREE.Texture( <Image> ),
  17512. *
  17513. * bumpMap: new THREE.Texture( <Image> ),
  17514. * bumpScale: <float>,
  17515. *
  17516. * normalMap: new THREE.Texture( <Image> ),
  17517. * normalScale: <Vector2>,
  17518. *
  17519. * displacementMap: new THREE.Texture( <Image> ),
  17520. * displacementScale: <float>,
  17521. * displacementBias: <float>,
  17522. *
  17523. * roughnessMap: new THREE.Texture( <Image> ),
  17524. *
  17525. * metalnessMap: new THREE.Texture( <Image> ),
  17526. *
  17527. * alphaMap: new THREE.Texture( <Image> ),
  17528. *
  17529. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  17530. * envMapIntensity: <float>
  17531. *
  17532. * refractionRatio: <float>,
  17533. *
  17534. * wireframe: <boolean>,
  17535. * wireframeLinewidth: <float>,
  17536. *
  17537. * skinning: <bool>,
  17538. * morphTargets: <bool>,
  17539. * morphNormals: <bool>
  17540. * }
  17541. */
  17542. function MeshStandardMaterial( parameters ) {
  17543. Material.call( this );
  17544. this.defines = { 'STANDARD': '' };
  17545. this.type = 'MeshStandardMaterial';
  17546. this.color = new Color( 0xffffff ); // diffuse
  17547. this.roughness = 0.5;
  17548. this.metalness = 0.5;
  17549. this.map = null;
  17550. this.lightMap = null;
  17551. this.lightMapIntensity = 1.0;
  17552. this.aoMap = null;
  17553. this.aoMapIntensity = 1.0;
  17554. this.emissive = new Color( 0x000000 );
  17555. this.emissiveIntensity = 1.0;
  17556. this.emissiveMap = null;
  17557. this.bumpMap = null;
  17558. this.bumpScale = 1;
  17559. this.normalMap = null;
  17560. this.normalScale = new Vector2( 1, 1 );
  17561. this.displacementMap = null;
  17562. this.displacementScale = 1;
  17563. this.displacementBias = 0;
  17564. this.roughnessMap = null;
  17565. this.metalnessMap = null;
  17566. this.alphaMap = null;
  17567. this.envMap = null;
  17568. this.envMapIntensity = 1.0;
  17569. this.refractionRatio = 0.98;
  17570. this.wireframe = false;
  17571. this.wireframeLinewidth = 1;
  17572. this.wireframeLinecap = 'round';
  17573. this.wireframeLinejoin = 'round';
  17574. this.skinning = false;
  17575. this.morphTargets = false;
  17576. this.morphNormals = false;
  17577. this.setValues( parameters );
  17578. }
  17579. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  17580. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  17581. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  17582. MeshStandardMaterial.prototype.copy = function ( source ) {
  17583. Material.prototype.copy.call( this, source );
  17584. this.defines = { 'STANDARD': '' };
  17585. this.color.copy( source.color );
  17586. this.roughness = source.roughness;
  17587. this.metalness = source.metalness;
  17588. this.map = source.map;
  17589. this.lightMap = source.lightMap;
  17590. this.lightMapIntensity = source.lightMapIntensity;
  17591. this.aoMap = source.aoMap;
  17592. this.aoMapIntensity = source.aoMapIntensity;
  17593. this.emissive.copy( source.emissive );
  17594. this.emissiveMap = source.emissiveMap;
  17595. this.emissiveIntensity = source.emissiveIntensity;
  17596. this.bumpMap = source.bumpMap;
  17597. this.bumpScale = source.bumpScale;
  17598. this.normalMap = source.normalMap;
  17599. this.normalScale.copy( source.normalScale );
  17600. this.displacementMap = source.displacementMap;
  17601. this.displacementScale = source.displacementScale;
  17602. this.displacementBias = source.displacementBias;
  17603. this.roughnessMap = source.roughnessMap;
  17604. this.metalnessMap = source.metalnessMap;
  17605. this.alphaMap = source.alphaMap;
  17606. this.envMap = source.envMap;
  17607. this.envMapIntensity = source.envMapIntensity;
  17608. this.refractionRatio = source.refractionRatio;
  17609. this.wireframe = source.wireframe;
  17610. this.wireframeLinewidth = source.wireframeLinewidth;
  17611. this.wireframeLinecap = source.wireframeLinecap;
  17612. this.wireframeLinejoin = source.wireframeLinejoin;
  17613. this.skinning = source.skinning;
  17614. this.morphTargets = source.morphTargets;
  17615. this.morphNormals = source.morphNormals;
  17616. return this;
  17617. };
  17618. /**
  17619. * @author WestLangley / http://github.com/WestLangley
  17620. *
  17621. * parameters = {
  17622. * reflectivity: <float>
  17623. * }
  17624. */
  17625. function MeshPhysicalMaterial( parameters ) {
  17626. MeshStandardMaterial.call( this );
  17627. this.defines = { 'PHYSICAL': '' };
  17628. this.type = 'MeshPhysicalMaterial';
  17629. this.reflectivity = 0.5; // maps to F0 = 0.04
  17630. this.clearCoat = 0.0;
  17631. this.clearCoatRoughness = 0.0;
  17632. this.setValues( parameters );
  17633. }
  17634. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  17635. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  17636. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  17637. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  17638. MeshStandardMaterial.prototype.copy.call( this, source );
  17639. this.defines = { 'PHYSICAL': '' };
  17640. this.reflectivity = source.reflectivity;
  17641. this.clearCoat = source.clearCoat;
  17642. this.clearCoatRoughness = source.clearCoatRoughness;
  17643. return this;
  17644. };
  17645. /**
  17646. * @author mrdoob / http://mrdoob.com/
  17647. * @author alteredq / http://alteredqualia.com/
  17648. *
  17649. * parameters = {
  17650. * color: <hex>,
  17651. * specular: <hex>,
  17652. * shininess: <float>,
  17653. * opacity: <float>,
  17654. *
  17655. * map: new THREE.Texture( <Image> ),
  17656. *
  17657. * lightMap: new THREE.Texture( <Image> ),
  17658. * lightMapIntensity: <float>
  17659. *
  17660. * aoMap: new THREE.Texture( <Image> ),
  17661. * aoMapIntensity: <float>
  17662. *
  17663. * emissive: <hex>,
  17664. * emissiveIntensity: <float>
  17665. * emissiveMap: new THREE.Texture( <Image> ),
  17666. *
  17667. * bumpMap: new THREE.Texture( <Image> ),
  17668. * bumpScale: <float>,
  17669. *
  17670. * normalMap: new THREE.Texture( <Image> ),
  17671. * normalScale: <Vector2>,
  17672. *
  17673. * displacementMap: new THREE.Texture( <Image> ),
  17674. * displacementScale: <float>,
  17675. * displacementBias: <float>,
  17676. *
  17677. * specularMap: new THREE.Texture( <Image> ),
  17678. *
  17679. * alphaMap: new THREE.Texture( <Image> ),
  17680. *
  17681. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  17682. * combine: THREE.Multiply,
  17683. * reflectivity: <float>,
  17684. * refractionRatio: <float>,
  17685. *
  17686. * wireframe: <boolean>,
  17687. * wireframeLinewidth: <float>,
  17688. *
  17689. * skinning: <bool>,
  17690. * morphTargets: <bool>,
  17691. * morphNormals: <bool>
  17692. * }
  17693. */
  17694. function MeshPhongMaterial( parameters ) {
  17695. Material.call( this );
  17696. this.type = 'MeshPhongMaterial';
  17697. this.color = new Color( 0xffffff ); // diffuse
  17698. this.specular = new Color( 0x111111 );
  17699. this.shininess = 30;
  17700. this.map = null;
  17701. this.lightMap = null;
  17702. this.lightMapIntensity = 1.0;
  17703. this.aoMap = null;
  17704. this.aoMapIntensity = 1.0;
  17705. this.emissive = new Color( 0x000000 );
  17706. this.emissiveIntensity = 1.0;
  17707. this.emissiveMap = null;
  17708. this.bumpMap = null;
  17709. this.bumpScale = 1;
  17710. this.normalMap = null;
  17711. this.normalScale = new Vector2( 1, 1 );
  17712. this.displacementMap = null;
  17713. this.displacementScale = 1;
  17714. this.displacementBias = 0;
  17715. this.specularMap = null;
  17716. this.alphaMap = null;
  17717. this.envMap = null;
  17718. this.combine = MultiplyOperation;
  17719. this.reflectivity = 1;
  17720. this.refractionRatio = 0.98;
  17721. this.wireframe = false;
  17722. this.wireframeLinewidth = 1;
  17723. this.wireframeLinecap = 'round';
  17724. this.wireframeLinejoin = 'round';
  17725. this.skinning = false;
  17726. this.morphTargets = false;
  17727. this.morphNormals = false;
  17728. this.setValues( parameters );
  17729. }
  17730. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  17731. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  17732. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  17733. MeshPhongMaterial.prototype.copy = function ( source ) {
  17734. Material.prototype.copy.call( this, source );
  17735. this.color.copy( source.color );
  17736. this.specular.copy( source.specular );
  17737. this.shininess = source.shininess;
  17738. this.map = source.map;
  17739. this.lightMap = source.lightMap;
  17740. this.lightMapIntensity = source.lightMapIntensity;
  17741. this.aoMap = source.aoMap;
  17742. this.aoMapIntensity = source.aoMapIntensity;
  17743. this.emissive.copy( source.emissive );
  17744. this.emissiveMap = source.emissiveMap;
  17745. this.emissiveIntensity = source.emissiveIntensity;
  17746. this.bumpMap = source.bumpMap;
  17747. this.bumpScale = source.bumpScale;
  17748. this.normalMap = source.normalMap;
  17749. this.normalScale.copy( source.normalScale );
  17750. this.displacementMap = source.displacementMap;
  17751. this.displacementScale = source.displacementScale;
  17752. this.displacementBias = source.displacementBias;
  17753. this.specularMap = source.specularMap;
  17754. this.alphaMap = source.alphaMap;
  17755. this.envMap = source.envMap;
  17756. this.combine = source.combine;
  17757. this.reflectivity = source.reflectivity;
  17758. this.refractionRatio = source.refractionRatio;
  17759. this.wireframe = source.wireframe;
  17760. this.wireframeLinewidth = source.wireframeLinewidth;
  17761. this.wireframeLinecap = source.wireframeLinecap;
  17762. this.wireframeLinejoin = source.wireframeLinejoin;
  17763. this.skinning = source.skinning;
  17764. this.morphTargets = source.morphTargets;
  17765. this.morphNormals = source.morphNormals;
  17766. return this;
  17767. };
  17768. /**
  17769. * @author takahirox / http://github.com/takahirox
  17770. *
  17771. * parameters = {
  17772. * gradientMap: new THREE.Texture( <Image> )
  17773. * }
  17774. */
  17775. function MeshToonMaterial( parameters ) {
  17776. MeshPhongMaterial.call( this );
  17777. this.defines = { 'TOON': '' };
  17778. this.type = 'MeshToonMaterial';
  17779. this.gradientMap = null;
  17780. this.setValues( parameters );
  17781. }
  17782. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  17783. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  17784. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  17785. MeshToonMaterial.prototype.copy = function ( source ) {
  17786. MeshPhongMaterial.prototype.copy.call( this, source );
  17787. this.gradientMap = source.gradientMap;
  17788. return this;
  17789. };
  17790. /**
  17791. * @author mrdoob / http://mrdoob.com/
  17792. * @author WestLangley / http://github.com/WestLangley
  17793. *
  17794. * parameters = {
  17795. * opacity: <float>,
  17796. *
  17797. * bumpMap: new THREE.Texture( <Image> ),
  17798. * bumpScale: <float>,
  17799. *
  17800. * normalMap: new THREE.Texture( <Image> ),
  17801. * normalScale: <Vector2>,
  17802. *
  17803. * displacementMap: new THREE.Texture( <Image> ),
  17804. * displacementScale: <float>,
  17805. * displacementBias: <float>,
  17806. *
  17807. * wireframe: <boolean>,
  17808. * wireframeLinewidth: <float>
  17809. *
  17810. * skinning: <bool>,
  17811. * morphTargets: <bool>,
  17812. * morphNormals: <bool>
  17813. * }
  17814. */
  17815. function MeshNormalMaterial( parameters ) {
  17816. Material.call( this );
  17817. this.type = 'MeshNormalMaterial';
  17818. this.bumpMap = null;
  17819. this.bumpScale = 1;
  17820. this.normalMap = null;
  17821. this.normalScale = new Vector2( 1, 1 );
  17822. this.displacementMap = null;
  17823. this.displacementScale = 1;
  17824. this.displacementBias = 0;
  17825. this.wireframe = false;
  17826. this.wireframeLinewidth = 1;
  17827. this.fog = false;
  17828. this.lights = false;
  17829. this.skinning = false;
  17830. this.morphTargets = false;
  17831. this.morphNormals = false;
  17832. this.setValues( parameters );
  17833. }
  17834. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  17835. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  17836. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  17837. MeshNormalMaterial.prototype.copy = function ( source ) {
  17838. Material.prototype.copy.call( this, source );
  17839. this.bumpMap = source.bumpMap;
  17840. this.bumpScale = source.bumpScale;
  17841. this.normalMap = source.normalMap;
  17842. this.normalScale.copy( source.normalScale );
  17843. this.displacementMap = source.displacementMap;
  17844. this.displacementScale = source.displacementScale;
  17845. this.displacementBias = source.displacementBias;
  17846. this.wireframe = source.wireframe;
  17847. this.wireframeLinewidth = source.wireframeLinewidth;
  17848. this.skinning = source.skinning;
  17849. this.morphTargets = source.morphTargets;
  17850. this.morphNormals = source.morphNormals;
  17851. return this;
  17852. };
  17853. /**
  17854. * @author mrdoob / http://mrdoob.com/
  17855. * @author alteredq / http://alteredqualia.com/
  17856. *
  17857. * parameters = {
  17858. * color: <hex>,
  17859. * opacity: <float>,
  17860. *
  17861. * map: new THREE.Texture( <Image> ),
  17862. *
  17863. * lightMap: new THREE.Texture( <Image> ),
  17864. * lightMapIntensity: <float>
  17865. *
  17866. * aoMap: new THREE.Texture( <Image> ),
  17867. * aoMapIntensity: <float>
  17868. *
  17869. * emissive: <hex>,
  17870. * emissiveIntensity: <float>
  17871. * emissiveMap: new THREE.Texture( <Image> ),
  17872. *
  17873. * specularMap: new THREE.Texture( <Image> ),
  17874. *
  17875. * alphaMap: new THREE.Texture( <Image> ),
  17876. *
  17877. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  17878. * combine: THREE.Multiply,
  17879. * reflectivity: <float>,
  17880. * refractionRatio: <float>,
  17881. *
  17882. * wireframe: <boolean>,
  17883. * wireframeLinewidth: <float>,
  17884. *
  17885. * skinning: <bool>,
  17886. * morphTargets: <bool>,
  17887. * morphNormals: <bool>
  17888. * }
  17889. */
  17890. function MeshLambertMaterial( parameters ) {
  17891. Material.call( this );
  17892. this.type = 'MeshLambertMaterial';
  17893. this.color = new Color( 0xffffff ); // diffuse
  17894. this.map = null;
  17895. this.lightMap = null;
  17896. this.lightMapIntensity = 1.0;
  17897. this.aoMap = null;
  17898. this.aoMapIntensity = 1.0;
  17899. this.emissive = new Color( 0x000000 );
  17900. this.emissiveIntensity = 1.0;
  17901. this.emissiveMap = null;
  17902. this.specularMap = null;
  17903. this.alphaMap = null;
  17904. this.envMap = null;
  17905. this.combine = MultiplyOperation;
  17906. this.reflectivity = 1;
  17907. this.refractionRatio = 0.98;
  17908. this.wireframe = false;
  17909. this.wireframeLinewidth = 1;
  17910. this.wireframeLinecap = 'round';
  17911. this.wireframeLinejoin = 'round';
  17912. this.skinning = false;
  17913. this.morphTargets = false;
  17914. this.morphNormals = false;
  17915. this.setValues( parameters );
  17916. }
  17917. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  17918. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  17919. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  17920. MeshLambertMaterial.prototype.copy = function ( source ) {
  17921. Material.prototype.copy.call( this, source );
  17922. this.color.copy( source.color );
  17923. this.map = source.map;
  17924. this.lightMap = source.lightMap;
  17925. this.lightMapIntensity = source.lightMapIntensity;
  17926. this.aoMap = source.aoMap;
  17927. this.aoMapIntensity = source.aoMapIntensity;
  17928. this.emissive.copy( source.emissive );
  17929. this.emissiveMap = source.emissiveMap;
  17930. this.emissiveIntensity = source.emissiveIntensity;
  17931. this.specularMap = source.specularMap;
  17932. this.alphaMap = source.alphaMap;
  17933. this.envMap = source.envMap;
  17934. this.combine = source.combine;
  17935. this.reflectivity = source.reflectivity;
  17936. this.refractionRatio = source.refractionRatio;
  17937. this.wireframe = source.wireframe;
  17938. this.wireframeLinewidth = source.wireframeLinewidth;
  17939. this.wireframeLinecap = source.wireframeLinecap;
  17940. this.wireframeLinejoin = source.wireframeLinejoin;
  17941. this.skinning = source.skinning;
  17942. this.morphTargets = source.morphTargets;
  17943. this.morphNormals = source.morphNormals;
  17944. return this;
  17945. };
  17946. /**
  17947. * @author alteredq / http://alteredqualia.com/
  17948. *
  17949. * parameters = {
  17950. * color: <hex>,
  17951. * opacity: <float>,
  17952. *
  17953. * linewidth: <float>,
  17954. *
  17955. * scale: <float>,
  17956. * dashSize: <float>,
  17957. * gapSize: <float>
  17958. * }
  17959. */
  17960. function LineDashedMaterial( parameters ) {
  17961. LineBasicMaterial.call( this );
  17962. this.type = 'LineDashedMaterial';
  17963. this.scale = 1;
  17964. this.dashSize = 3;
  17965. this.gapSize = 1;
  17966. this.setValues( parameters );
  17967. }
  17968. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  17969. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  17970. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  17971. LineDashedMaterial.prototype.copy = function ( source ) {
  17972. LineBasicMaterial.prototype.copy.call( this, source );
  17973. this.scale = source.scale;
  17974. this.dashSize = source.dashSize;
  17975. this.gapSize = source.gapSize;
  17976. return this;
  17977. };
  17978. var Materials = Object.freeze({
  17979. ShadowMaterial: ShadowMaterial,
  17980. SpriteMaterial: SpriteMaterial,
  17981. RawShaderMaterial: RawShaderMaterial,
  17982. ShaderMaterial: ShaderMaterial,
  17983. PointsMaterial: PointsMaterial,
  17984. MeshPhysicalMaterial: MeshPhysicalMaterial,
  17985. MeshStandardMaterial: MeshStandardMaterial,
  17986. MeshPhongMaterial: MeshPhongMaterial,
  17987. MeshToonMaterial: MeshToonMaterial,
  17988. MeshNormalMaterial: MeshNormalMaterial,
  17989. MeshLambertMaterial: MeshLambertMaterial,
  17990. MeshDepthMaterial: MeshDepthMaterial,
  17991. MeshDistanceMaterial: MeshDistanceMaterial,
  17992. MeshBasicMaterial: MeshBasicMaterial,
  17993. LineDashedMaterial: LineDashedMaterial,
  17994. LineBasicMaterial: LineBasicMaterial,
  17995. Material: Material
  17996. });
  17997. /**
  17998. * @author mrdoob / http://mrdoob.com/
  17999. */
  18000. var Cache = {
  18001. enabled: false,
  18002. files: {},
  18003. add: function ( key, file ) {
  18004. if ( this.enabled === false ) return;
  18005. // console.log( 'THREE.Cache', 'Adding key:', key );
  18006. this.files[ key ] = file;
  18007. },
  18008. get: function ( key ) {
  18009. if ( this.enabled === false ) return;
  18010. // console.log( 'THREE.Cache', 'Checking key:', key );
  18011. return this.files[ key ];
  18012. },
  18013. remove: function ( key ) {
  18014. delete this.files[ key ];
  18015. },
  18016. clear: function () {
  18017. this.files = {};
  18018. }
  18019. };
  18020. /**
  18021. * @author mrdoob / http://mrdoob.com/
  18022. */
  18023. function LoadingManager( onLoad, onProgress, onError ) {
  18024. var scope = this;
  18025. var isLoading = false;
  18026. var itemsLoaded = 0;
  18027. var itemsTotal = 0;
  18028. var urlModifier = undefined;
  18029. this.onStart = undefined;
  18030. this.onLoad = onLoad;
  18031. this.onProgress = onProgress;
  18032. this.onError = onError;
  18033. this.itemStart = function ( url ) {
  18034. itemsTotal ++;
  18035. if ( isLoading === false ) {
  18036. if ( scope.onStart !== undefined ) {
  18037. scope.onStart( url, itemsLoaded, itemsTotal );
  18038. }
  18039. }
  18040. isLoading = true;
  18041. };
  18042. this.itemEnd = function ( url ) {
  18043. itemsLoaded ++;
  18044. if ( scope.onProgress !== undefined ) {
  18045. scope.onProgress( url, itemsLoaded, itemsTotal );
  18046. }
  18047. if ( itemsLoaded === itemsTotal ) {
  18048. isLoading = false;
  18049. if ( scope.onLoad !== undefined ) {
  18050. scope.onLoad();
  18051. }
  18052. }
  18053. };
  18054. this.itemError = function ( url ) {
  18055. if ( scope.onError !== undefined ) {
  18056. scope.onError( url );
  18057. }
  18058. };
  18059. this.resolveURL = function ( url ) {
  18060. if ( urlModifier ) {
  18061. return urlModifier( url );
  18062. }
  18063. return url;
  18064. };
  18065. this.setURLModifier = function ( transform ) {
  18066. urlModifier = transform;
  18067. return this;
  18068. };
  18069. }
  18070. var DefaultLoadingManager = new LoadingManager();
  18071. /**
  18072. * @author mrdoob / http://mrdoob.com/
  18073. */
  18074. var loading = {};
  18075. function FileLoader( manager ) {
  18076. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18077. }
  18078. Object.assign( FileLoader.prototype, {
  18079. load: function ( url, onLoad, onProgress, onError ) {
  18080. if ( url === undefined ) url = '';
  18081. if ( this.path !== undefined ) url = this.path + url;
  18082. url = this.manager.resolveURL( url );
  18083. var scope = this;
  18084. var cached = Cache.get( url );
  18085. if ( cached !== undefined ) {
  18086. scope.manager.itemStart( url );
  18087. setTimeout( function () {
  18088. if ( onLoad ) onLoad( cached );
  18089. scope.manager.itemEnd( url );
  18090. }, 0 );
  18091. return cached;
  18092. }
  18093. // Check if request is duplicate
  18094. if ( loading[ url ] !== undefined ) {
  18095. loading[ url ].push( {
  18096. onLoad: onLoad,
  18097. onProgress: onProgress,
  18098. onError: onError
  18099. } );
  18100. return;
  18101. }
  18102. // Check for data: URI
  18103. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  18104. var dataUriRegexResult = url.match( dataUriRegex );
  18105. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  18106. if ( dataUriRegexResult ) {
  18107. var mimeType = dataUriRegexResult[ 1 ];
  18108. var isBase64 = !! dataUriRegexResult[ 2 ];
  18109. var data = dataUriRegexResult[ 3 ];
  18110. data = window.decodeURIComponent( data );
  18111. if ( isBase64 ) data = window.atob( data );
  18112. try {
  18113. var response;
  18114. var responseType = ( this.responseType || '' ).toLowerCase();
  18115. switch ( responseType ) {
  18116. case 'arraybuffer':
  18117. case 'blob':
  18118. var view = new Uint8Array( data.length );
  18119. for ( var i = 0; i < data.length; i ++ ) {
  18120. view[ i ] = data.charCodeAt( i );
  18121. }
  18122. if ( responseType === 'blob' ) {
  18123. response = new Blob( [ view.buffer ], { type: mimeType } );
  18124. } else {
  18125. response = view.buffer;
  18126. }
  18127. break;
  18128. case 'document':
  18129. var parser = new DOMParser();
  18130. response = parser.parseFromString( data, mimeType );
  18131. break;
  18132. case 'json':
  18133. response = JSON.parse( data );
  18134. break;
  18135. default: // 'text' or other
  18136. response = data;
  18137. break;
  18138. }
  18139. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  18140. window.setTimeout( function () {
  18141. if ( onLoad ) onLoad( response );
  18142. scope.manager.itemEnd( url );
  18143. }, 0 );
  18144. } catch ( error ) {
  18145. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  18146. window.setTimeout( function () {
  18147. if ( onError ) onError( error );
  18148. scope.manager.itemEnd( url );
  18149. scope.manager.itemError( url );
  18150. }, 0 );
  18151. }
  18152. } else {
  18153. // Initialise array for duplicate requests
  18154. loading[ url ] = [];
  18155. loading[ url ].push( {
  18156. onLoad: onLoad,
  18157. onProgress: onProgress,
  18158. onError: onError
  18159. } );
  18160. var request = new XMLHttpRequest();
  18161. request.open( 'GET', url, true );
  18162. request.addEventListener( 'load', function ( event ) {
  18163. var response = this.response;
  18164. Cache.add( url, response );
  18165. var callbacks = loading[ url ];
  18166. delete loading[ url ];
  18167. if ( this.status === 200 ) {
  18168. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18169. var callback = callbacks[ i ];
  18170. if ( callback.onLoad ) callback.onLoad( response );
  18171. }
  18172. scope.manager.itemEnd( url );
  18173. } else if ( this.status === 0 ) {
  18174. // Some browsers return HTTP Status 0 when using non-http protocol
  18175. // e.g. 'file://' or 'data://'. Handle as success.
  18176. console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  18177. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18178. var callback = callbacks[ i ];
  18179. if ( callback.onLoad ) callback.onLoad( response );
  18180. }
  18181. scope.manager.itemEnd( url );
  18182. } else {
  18183. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18184. var callback = callbacks[ i ];
  18185. if ( callback.onError ) callback.onError( event );
  18186. }
  18187. scope.manager.itemEnd( url );
  18188. scope.manager.itemError( url );
  18189. }
  18190. }, false );
  18191. request.addEventListener( 'progress', function ( event ) {
  18192. var callbacks = loading[ url ];
  18193. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18194. var callback = callbacks[ i ];
  18195. if ( callback.onProgress ) callback.onProgress( event );
  18196. }
  18197. }, false );
  18198. request.addEventListener( 'error', function ( event ) {
  18199. var callbacks = loading[ url ];
  18200. delete loading[ url ];
  18201. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18202. var callback = callbacks[ i ];
  18203. if ( callback.onError ) callback.onError( event );
  18204. }
  18205. scope.manager.itemEnd( url );
  18206. scope.manager.itemError( url );
  18207. }, false );
  18208. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  18209. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  18210. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  18211. for ( var header in this.requestHeader ) {
  18212. request.setRequestHeader( header, this.requestHeader[ header ] );
  18213. }
  18214. request.send( null );
  18215. }
  18216. scope.manager.itemStart( url );
  18217. return request;
  18218. },
  18219. setPath: function ( value ) {
  18220. this.path = value;
  18221. return this;
  18222. },
  18223. setResponseType: function ( value ) {
  18224. this.responseType = value;
  18225. return this;
  18226. },
  18227. setWithCredentials: function ( value ) {
  18228. this.withCredentials = value;
  18229. return this;
  18230. },
  18231. setMimeType: function ( value ) {
  18232. this.mimeType = value;
  18233. return this;
  18234. },
  18235. setRequestHeader: function ( value ) {
  18236. this.requestHeader = value;
  18237. return this;
  18238. }
  18239. } );
  18240. /**
  18241. * @author mrdoob / http://mrdoob.com/
  18242. *
  18243. * Abstract Base class to block based textures loader (dds, pvr, ...)
  18244. */
  18245. function CompressedTextureLoader( manager ) {
  18246. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18247. // override in sub classes
  18248. this._parser = null;
  18249. }
  18250. Object.assign( CompressedTextureLoader.prototype, {
  18251. load: function ( url, onLoad, onProgress, onError ) {
  18252. var scope = this;
  18253. var images = [];
  18254. var texture = new CompressedTexture();
  18255. texture.image = images;
  18256. var loader = new FileLoader( this.manager );
  18257. loader.setPath( this.path );
  18258. loader.setResponseType( 'arraybuffer' );
  18259. function loadTexture( i ) {
  18260. loader.load( url[ i ], function ( buffer ) {
  18261. var texDatas = scope._parser( buffer, true );
  18262. images[ i ] = {
  18263. width: texDatas.width,
  18264. height: texDatas.height,
  18265. format: texDatas.format,
  18266. mipmaps: texDatas.mipmaps
  18267. };
  18268. loaded += 1;
  18269. if ( loaded === 6 ) {
  18270. if ( texDatas.mipmapCount === 1 )
  18271. texture.minFilter = LinearFilter;
  18272. texture.format = texDatas.format;
  18273. texture.needsUpdate = true;
  18274. if ( onLoad ) onLoad( texture );
  18275. }
  18276. }, onProgress, onError );
  18277. }
  18278. if ( Array.isArray( url ) ) {
  18279. var loaded = 0;
  18280. for ( var i = 0, il = url.length; i < il; ++ i ) {
  18281. loadTexture( i );
  18282. }
  18283. } else {
  18284. // compressed cubemap texture stored in a single DDS file
  18285. loader.load( url, function ( buffer ) {
  18286. var texDatas = scope._parser( buffer, true );
  18287. if ( texDatas.isCubemap ) {
  18288. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  18289. for ( var f = 0; f < faces; f ++ ) {
  18290. images[ f ] = { mipmaps: [] };
  18291. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  18292. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  18293. images[ f ].format = texDatas.format;
  18294. images[ f ].width = texDatas.width;
  18295. images[ f ].height = texDatas.height;
  18296. }
  18297. }
  18298. } else {
  18299. texture.image.width = texDatas.width;
  18300. texture.image.height = texDatas.height;
  18301. texture.mipmaps = texDatas.mipmaps;
  18302. }
  18303. if ( texDatas.mipmapCount === 1 ) {
  18304. texture.minFilter = LinearFilter;
  18305. }
  18306. texture.format = texDatas.format;
  18307. texture.needsUpdate = true;
  18308. if ( onLoad ) onLoad( texture );
  18309. }, onProgress, onError );
  18310. }
  18311. return texture;
  18312. },
  18313. setPath: function ( value ) {
  18314. this.path = value;
  18315. return this;
  18316. }
  18317. } );
  18318. /**
  18319. * @author Nikos M. / https://github.com/foo123/
  18320. *
  18321. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  18322. */
  18323. function DataTextureLoader( manager ) {
  18324. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18325. // override in sub classes
  18326. this._parser = null;
  18327. }
  18328. Object.assign( DataTextureLoader.prototype, {
  18329. load: function ( url, onLoad, onProgress, onError ) {
  18330. var scope = this;
  18331. var texture = new DataTexture();
  18332. var loader = new FileLoader( this.manager );
  18333. loader.setResponseType( 'arraybuffer' );
  18334. loader.load( url, function ( buffer ) {
  18335. var texData = scope._parser( buffer );
  18336. if ( ! texData ) return;
  18337. if ( undefined !== texData.image ) {
  18338. texture.image = texData.image;
  18339. } else if ( undefined !== texData.data ) {
  18340. texture.image.width = texData.width;
  18341. texture.image.height = texData.height;
  18342. texture.image.data = texData.data;
  18343. }
  18344. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : ClampToEdgeWrapping;
  18345. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : ClampToEdgeWrapping;
  18346. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : LinearFilter;
  18347. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : LinearMipMapLinearFilter;
  18348. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  18349. if ( undefined !== texData.format ) {
  18350. texture.format = texData.format;
  18351. }
  18352. if ( undefined !== texData.type ) {
  18353. texture.type = texData.type;
  18354. }
  18355. if ( undefined !== texData.mipmaps ) {
  18356. texture.mipmaps = texData.mipmaps;
  18357. }
  18358. if ( 1 === texData.mipmapCount ) {
  18359. texture.minFilter = LinearFilter;
  18360. }
  18361. texture.needsUpdate = true;
  18362. if ( onLoad ) onLoad( texture, texData );
  18363. }, onProgress, onError );
  18364. return texture;
  18365. }
  18366. } );
  18367. /**
  18368. * @author mrdoob / http://mrdoob.com/
  18369. */
  18370. function ImageLoader( manager ) {
  18371. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18372. }
  18373. Object.assign( ImageLoader.prototype, {
  18374. crossOrigin: 'Anonymous',
  18375. load: function ( url, onLoad, onProgress, onError ) {
  18376. if ( url === undefined ) url = '';
  18377. if ( this.path !== undefined ) url = this.path + url;
  18378. url = this.manager.resolveURL( url );
  18379. var scope = this;
  18380. var cached = Cache.get( url );
  18381. if ( cached !== undefined ) {
  18382. scope.manager.itemStart( url );
  18383. setTimeout( function () {
  18384. if ( onLoad ) onLoad( cached );
  18385. scope.manager.itemEnd( url );
  18386. }, 0 );
  18387. return cached;
  18388. }
  18389. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  18390. image.addEventListener( 'load', function () {
  18391. Cache.add( url, this );
  18392. if ( onLoad ) onLoad( this );
  18393. scope.manager.itemEnd( url );
  18394. }, false );
  18395. /*
  18396. image.addEventListener( 'progress', function ( event ) {
  18397. if ( onProgress ) onProgress( event );
  18398. }, false );
  18399. */
  18400. image.addEventListener( 'error', function ( event ) {
  18401. if ( onError ) onError( event );
  18402. scope.manager.itemEnd( url );
  18403. scope.manager.itemError( url );
  18404. }, false );
  18405. if ( url.substr( 0, 5 ) !== 'data:' ) {
  18406. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  18407. }
  18408. scope.manager.itemStart( url );
  18409. image.src = url;
  18410. return image;
  18411. },
  18412. setCrossOrigin: function ( value ) {
  18413. this.crossOrigin = value;
  18414. return this;
  18415. },
  18416. setPath: function ( value ) {
  18417. this.path = value;
  18418. return this;
  18419. }
  18420. } );
  18421. /**
  18422. * @author mrdoob / http://mrdoob.com/
  18423. */
  18424. function CubeTextureLoader( manager ) {
  18425. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18426. }
  18427. Object.assign( CubeTextureLoader.prototype, {
  18428. crossOrigin: 'Anonymous',
  18429. load: function ( urls, onLoad, onProgress, onError ) {
  18430. var texture = new CubeTexture();
  18431. var loader = new ImageLoader( this.manager );
  18432. loader.setCrossOrigin( this.crossOrigin );
  18433. loader.setPath( this.path );
  18434. var loaded = 0;
  18435. function loadTexture( i ) {
  18436. loader.load( urls[ i ], function ( image ) {
  18437. texture.images[ i ] = image;
  18438. loaded ++;
  18439. if ( loaded === 6 ) {
  18440. texture.needsUpdate = true;
  18441. if ( onLoad ) onLoad( texture );
  18442. }
  18443. }, undefined, onError );
  18444. }
  18445. for ( var i = 0; i < urls.length; ++ i ) {
  18446. loadTexture( i );
  18447. }
  18448. return texture;
  18449. },
  18450. setCrossOrigin: function ( value ) {
  18451. this.crossOrigin = value;
  18452. return this;
  18453. },
  18454. setPath: function ( value ) {
  18455. this.path = value;
  18456. return this;
  18457. }
  18458. } );
  18459. /**
  18460. * @author mrdoob / http://mrdoob.com/
  18461. */
  18462. function TextureLoader( manager ) {
  18463. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18464. }
  18465. Object.assign( TextureLoader.prototype, {
  18466. crossOrigin: 'Anonymous',
  18467. load: function ( url, onLoad, onProgress, onError ) {
  18468. var texture = new Texture();
  18469. var loader = new ImageLoader( this.manager );
  18470. loader.setCrossOrigin( this.crossOrigin );
  18471. loader.setPath( this.path );
  18472. loader.load( url, function ( image ) {
  18473. texture.image = image;
  18474. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  18475. var isJPEG = url.search( /\.(jpg|jpeg)$/ ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  18476. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  18477. texture.needsUpdate = true;
  18478. if ( onLoad !== undefined ) {
  18479. onLoad( texture );
  18480. }
  18481. }, onProgress, onError );
  18482. return texture;
  18483. },
  18484. setCrossOrigin: function ( value ) {
  18485. this.crossOrigin = value;
  18486. return this;
  18487. },
  18488. setPath: function ( value ) {
  18489. this.path = value;
  18490. return this;
  18491. }
  18492. } );
  18493. /**
  18494. * @author zz85 / http://www.lab4games.net/zz85/blog
  18495. * Extensible curve object
  18496. *
  18497. * Some common of curve methods:
  18498. * .getPoint( t, optionalTarget ), .getTangent( t )
  18499. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  18500. * .getPoints(), .getSpacedPoints()
  18501. * .getLength()
  18502. * .updateArcLengths()
  18503. *
  18504. * This following curves inherit from THREE.Curve:
  18505. *
  18506. * -- 2D curves --
  18507. * THREE.ArcCurve
  18508. * THREE.CubicBezierCurve
  18509. * THREE.EllipseCurve
  18510. * THREE.LineCurve
  18511. * THREE.QuadraticBezierCurve
  18512. * THREE.SplineCurve
  18513. *
  18514. * -- 3D curves --
  18515. * THREE.CatmullRomCurve3
  18516. * THREE.CubicBezierCurve3
  18517. * THREE.LineCurve3
  18518. * THREE.QuadraticBezierCurve3
  18519. *
  18520. * A series of curves can be represented as a THREE.CurvePath.
  18521. *
  18522. **/
  18523. /**************************************************************
  18524. * Abstract Curve base class
  18525. **************************************************************/
  18526. function Curve() {
  18527. this.type = 'Curve';
  18528. this.arcLengthDivisions = 200;
  18529. }
  18530. Object.assign( Curve.prototype, {
  18531. // Virtual base class method to overwrite and implement in subclasses
  18532. // - t [0 .. 1]
  18533. getPoint: function ( /* t, optionalTarget */ ) {
  18534. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  18535. return null;
  18536. },
  18537. // Get point at relative position in curve according to arc length
  18538. // - u [0 .. 1]
  18539. getPointAt: function ( u, optionalTarget ) {
  18540. var t = this.getUtoTmapping( u );
  18541. return this.getPoint( t, optionalTarget );
  18542. },
  18543. // Get sequence of points using getPoint( t )
  18544. getPoints: function ( divisions ) {
  18545. if ( divisions === undefined ) divisions = 5;
  18546. var points = [];
  18547. for ( var d = 0; d <= divisions; d ++ ) {
  18548. points.push( this.getPoint( d / divisions ) );
  18549. }
  18550. return points;
  18551. },
  18552. // Get sequence of points using getPointAt( u )
  18553. getSpacedPoints: function ( divisions ) {
  18554. if ( divisions === undefined ) divisions = 5;
  18555. var points = [];
  18556. for ( var d = 0; d <= divisions; d ++ ) {
  18557. points.push( this.getPointAt( d / divisions ) );
  18558. }
  18559. return points;
  18560. },
  18561. // Get total curve arc length
  18562. getLength: function () {
  18563. var lengths = this.getLengths();
  18564. return lengths[ lengths.length - 1 ];
  18565. },
  18566. // Get list of cumulative segment lengths
  18567. getLengths: function ( divisions ) {
  18568. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  18569. if ( this.cacheArcLengths &&
  18570. ( this.cacheArcLengths.length === divisions + 1 ) &&
  18571. ! this.needsUpdate ) {
  18572. return this.cacheArcLengths;
  18573. }
  18574. this.needsUpdate = false;
  18575. var cache = [];
  18576. var current, last = this.getPoint( 0 );
  18577. var p, sum = 0;
  18578. cache.push( 0 );
  18579. for ( p = 1; p <= divisions; p ++ ) {
  18580. current = this.getPoint( p / divisions );
  18581. sum += current.distanceTo( last );
  18582. cache.push( sum );
  18583. last = current;
  18584. }
  18585. this.cacheArcLengths = cache;
  18586. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  18587. },
  18588. updateArcLengths: function () {
  18589. this.needsUpdate = true;
  18590. this.getLengths();
  18591. },
  18592. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  18593. getUtoTmapping: function ( u, distance ) {
  18594. var arcLengths = this.getLengths();
  18595. var i = 0, il = arcLengths.length;
  18596. var targetArcLength; // The targeted u distance value to get
  18597. if ( distance ) {
  18598. targetArcLength = distance;
  18599. } else {
  18600. targetArcLength = u * arcLengths[ il - 1 ];
  18601. }
  18602. // binary search for the index with largest value smaller than target u distance
  18603. var low = 0, high = il - 1, comparison;
  18604. while ( low <= high ) {
  18605. i = Math.floor( low + ( high - low ) / 2 ); // less likely to overflow, though probably not issue here, JS doesn't really have integers, all numbers are floats
  18606. comparison = arcLengths[ i ] - targetArcLength;
  18607. if ( comparison < 0 ) {
  18608. low = i + 1;
  18609. } else if ( comparison > 0 ) {
  18610. high = i - 1;
  18611. } else {
  18612. high = i;
  18613. break;
  18614. // DONE
  18615. }
  18616. }
  18617. i = high;
  18618. if ( arcLengths[ i ] === targetArcLength ) {
  18619. return i / ( il - 1 );
  18620. }
  18621. // we could get finer grain at lengths, or use simple interpolation between two points
  18622. var lengthBefore = arcLengths[ i ];
  18623. var lengthAfter = arcLengths[ i + 1 ];
  18624. var segmentLength = lengthAfter - lengthBefore;
  18625. // determine where we are between the 'before' and 'after' points
  18626. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  18627. // add that fractional amount to t
  18628. var t = ( i + segmentFraction ) / ( il - 1 );
  18629. return t;
  18630. },
  18631. // Returns a unit vector tangent at t
  18632. // In case any sub curve does not implement its tangent derivation,
  18633. // 2 points a small delta apart will be used to find its gradient
  18634. // which seems to give a reasonable approximation
  18635. getTangent: function ( t ) {
  18636. var delta = 0.0001;
  18637. var t1 = t - delta;
  18638. var t2 = t + delta;
  18639. // Capping in case of danger
  18640. if ( t1 < 0 ) t1 = 0;
  18641. if ( t2 > 1 ) t2 = 1;
  18642. var pt1 = this.getPoint( t1 );
  18643. var pt2 = this.getPoint( t2 );
  18644. var vec = pt2.clone().sub( pt1 );
  18645. return vec.normalize();
  18646. },
  18647. getTangentAt: function ( u ) {
  18648. var t = this.getUtoTmapping( u );
  18649. return this.getTangent( t );
  18650. },
  18651. computeFrenetFrames: function ( segments, closed ) {
  18652. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  18653. var normal = new Vector3();
  18654. var tangents = [];
  18655. var normals = [];
  18656. var binormals = [];
  18657. var vec = new Vector3();
  18658. var mat = new Matrix4();
  18659. var i, u, theta;
  18660. // compute the tangent vectors for each segment on the curve
  18661. for ( i = 0; i <= segments; i ++ ) {
  18662. u = i / segments;
  18663. tangents[ i ] = this.getTangentAt( u );
  18664. tangents[ i ].normalize();
  18665. }
  18666. // select an initial normal vector perpendicular to the first tangent vector,
  18667. // and in the direction of the minimum tangent xyz component
  18668. normals[ 0 ] = new Vector3();
  18669. binormals[ 0 ] = new Vector3();
  18670. var min = Number.MAX_VALUE;
  18671. var tx = Math.abs( tangents[ 0 ].x );
  18672. var ty = Math.abs( tangents[ 0 ].y );
  18673. var tz = Math.abs( tangents[ 0 ].z );
  18674. if ( tx <= min ) {
  18675. min = tx;
  18676. normal.set( 1, 0, 0 );
  18677. }
  18678. if ( ty <= min ) {
  18679. min = ty;
  18680. normal.set( 0, 1, 0 );
  18681. }
  18682. if ( tz <= min ) {
  18683. normal.set( 0, 0, 1 );
  18684. }
  18685. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  18686. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  18687. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  18688. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  18689. for ( i = 1; i <= segments; i ++ ) {
  18690. normals[ i ] = normals[ i - 1 ].clone();
  18691. binormals[ i ] = binormals[ i - 1 ].clone();
  18692. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  18693. if ( vec.length() > Number.EPSILON ) {
  18694. vec.normalize();
  18695. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  18696. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  18697. }
  18698. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  18699. }
  18700. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  18701. if ( closed === true ) {
  18702. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  18703. theta /= segments;
  18704. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  18705. theta = - theta;
  18706. }
  18707. for ( i = 1; i <= segments; i ++ ) {
  18708. // twist a little...
  18709. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  18710. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  18711. }
  18712. }
  18713. return {
  18714. tangents: tangents,
  18715. normals: normals,
  18716. binormals: binormals
  18717. };
  18718. },
  18719. clone: function () {
  18720. return new this.constructor().copy( this );
  18721. },
  18722. copy: function ( source ) {
  18723. this.arcLengthDivisions = source.arcLengthDivisions;
  18724. return this;
  18725. },
  18726. toJSON: function () {
  18727. var data = {
  18728. metadata: {
  18729. version: 4.5,
  18730. type: 'Curve',
  18731. generator: 'Curve.toJSON'
  18732. }
  18733. };
  18734. data.arcLengthDivisions = this.arcLengthDivisions;
  18735. data.type = this.type;
  18736. return data;
  18737. },
  18738. fromJSON: function ( json ) {
  18739. this.arcLengthDivisions = json.arcLengthDivisions;
  18740. return this;
  18741. }
  18742. } );
  18743. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  18744. Curve.call( this );
  18745. this.type = 'EllipseCurve';
  18746. this.aX = aX || 0;
  18747. this.aY = aY || 0;
  18748. this.xRadius = xRadius || 1;
  18749. this.yRadius = yRadius || 1;
  18750. this.aStartAngle = aStartAngle || 0;
  18751. this.aEndAngle = aEndAngle || 2 * Math.PI;
  18752. this.aClockwise = aClockwise || false;
  18753. this.aRotation = aRotation || 0;
  18754. }
  18755. EllipseCurve.prototype = Object.create( Curve.prototype );
  18756. EllipseCurve.prototype.constructor = EllipseCurve;
  18757. EllipseCurve.prototype.isEllipseCurve = true;
  18758. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  18759. var point = optionalTarget || new Vector2();
  18760. var twoPi = Math.PI * 2;
  18761. var deltaAngle = this.aEndAngle - this.aStartAngle;
  18762. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  18763. // ensures that deltaAngle is 0 .. 2 PI
  18764. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  18765. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  18766. if ( deltaAngle < Number.EPSILON ) {
  18767. if ( samePoints ) {
  18768. deltaAngle = 0;
  18769. } else {
  18770. deltaAngle = twoPi;
  18771. }
  18772. }
  18773. if ( this.aClockwise === true && ! samePoints ) {
  18774. if ( deltaAngle === twoPi ) {
  18775. deltaAngle = - twoPi;
  18776. } else {
  18777. deltaAngle = deltaAngle - twoPi;
  18778. }
  18779. }
  18780. var angle = this.aStartAngle + t * deltaAngle;
  18781. var x = this.aX + this.xRadius * Math.cos( angle );
  18782. var y = this.aY + this.yRadius * Math.sin( angle );
  18783. if ( this.aRotation !== 0 ) {
  18784. var cos = Math.cos( this.aRotation );
  18785. var sin = Math.sin( this.aRotation );
  18786. var tx = x - this.aX;
  18787. var ty = y - this.aY;
  18788. // Rotate the point about the center of the ellipse.
  18789. x = tx * cos - ty * sin + this.aX;
  18790. y = tx * sin + ty * cos + this.aY;
  18791. }
  18792. return point.set( x, y );
  18793. };
  18794. EllipseCurve.prototype.copy = function ( source ) {
  18795. Curve.prototype.copy.call( this, source );
  18796. this.aX = source.aX;
  18797. this.aY = source.aY;
  18798. this.xRadius = source.xRadius;
  18799. this.yRadius = source.yRadius;
  18800. this.aStartAngle = source.aStartAngle;
  18801. this.aEndAngle = source.aEndAngle;
  18802. this.aClockwise = source.aClockwise;
  18803. this.aRotation = source.aRotation;
  18804. return this;
  18805. };
  18806. EllipseCurve.prototype.toJSON = function () {
  18807. var data = Curve.prototype.toJSON.call( this );
  18808. data.aX = this.aX;
  18809. data.aY = this.aY;
  18810. data.xRadius = this.xRadius;
  18811. data.yRadius = this.yRadius;
  18812. data.aStartAngle = this.aStartAngle;
  18813. data.aEndAngle = this.aEndAngle;
  18814. data.aClockwise = this.aClockwise;
  18815. data.aRotation = this.aRotation;
  18816. return data;
  18817. };
  18818. EllipseCurve.prototype.fromJSON = function ( json ) {
  18819. Curve.prototype.fromJSON.call( this, json );
  18820. this.aX = json.aX;
  18821. this.aY = json.aY;
  18822. this.xRadius = json.xRadius;
  18823. this.yRadius = json.yRadius;
  18824. this.aStartAngle = json.aStartAngle;
  18825. this.aEndAngle = json.aEndAngle;
  18826. this.aClockwise = json.aClockwise;
  18827. this.aRotation = json.aRotation;
  18828. return this;
  18829. };
  18830. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  18831. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  18832. this.type = 'ArcCurve';
  18833. }
  18834. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  18835. ArcCurve.prototype.constructor = ArcCurve;
  18836. ArcCurve.prototype.isArcCurve = true;
  18837. /**
  18838. * @author zz85 https://github.com/zz85
  18839. *
  18840. * Centripetal CatmullRom Curve - which is useful for avoiding
  18841. * cusps and self-intersections in non-uniform catmull rom curves.
  18842. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  18843. *
  18844. * curve.type accepts centripetal(default), chordal and catmullrom
  18845. * curve.tension is used for catmullrom which defaults to 0.5
  18846. */
  18847. /*
  18848. Based on an optimized c++ solution in
  18849. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  18850. - http://ideone.com/NoEbVM
  18851. This CubicPoly class could be used for reusing some variables and calculations,
  18852. but for three.js curve use, it could be possible inlined and flatten into a single function call
  18853. which can be placed in CurveUtils.
  18854. */
  18855. function CubicPoly() {
  18856. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  18857. /*
  18858. * Compute coefficients for a cubic polynomial
  18859. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  18860. * such that
  18861. * p(0) = x0, p(1) = x1
  18862. * and
  18863. * p'(0) = t0, p'(1) = t1.
  18864. */
  18865. function init( x0, x1, t0, t1 ) {
  18866. c0 = x0;
  18867. c1 = t0;
  18868. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  18869. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  18870. }
  18871. return {
  18872. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  18873. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  18874. },
  18875. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  18876. // compute tangents when parameterized in [t1,t2]
  18877. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  18878. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  18879. // rescale tangents for parametrization in [0,1]
  18880. t1 *= dt1;
  18881. t2 *= dt1;
  18882. init( x1, x2, t1, t2 );
  18883. },
  18884. calc: function ( t ) {
  18885. var t2 = t * t;
  18886. var t3 = t2 * t;
  18887. return c0 + c1 * t + c2 * t2 + c3 * t3;
  18888. }
  18889. };
  18890. }
  18891. //
  18892. var tmp = new Vector3();
  18893. var px = new CubicPoly();
  18894. var py = new CubicPoly();
  18895. var pz = new CubicPoly();
  18896. function CatmullRomCurve3( points, closed, curveType, tension ) {
  18897. Curve.call( this );
  18898. this.type = 'CatmullRomCurve3';
  18899. this.points = points || [];
  18900. this.closed = closed || false;
  18901. this.curveType = curveType || 'centripetal';
  18902. this.tension = tension || 0.5;
  18903. }
  18904. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  18905. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  18906. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  18907. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  18908. var point = optionalTarget || new Vector3();
  18909. var points = this.points;
  18910. var l = points.length;
  18911. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  18912. var intPoint = Math.floor( p );
  18913. var weight = p - intPoint;
  18914. if ( this.closed ) {
  18915. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  18916. } else if ( weight === 0 && intPoint === l - 1 ) {
  18917. intPoint = l - 2;
  18918. weight = 1;
  18919. }
  18920. var p0, p1, p2, p3; // 4 points
  18921. if ( this.closed || intPoint > 0 ) {
  18922. p0 = points[ ( intPoint - 1 ) % l ];
  18923. } else {
  18924. // extrapolate first point
  18925. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  18926. p0 = tmp;
  18927. }
  18928. p1 = points[ intPoint % l ];
  18929. p2 = points[ ( intPoint + 1 ) % l ];
  18930. if ( this.closed || intPoint + 2 < l ) {
  18931. p3 = points[ ( intPoint + 2 ) % l ];
  18932. } else {
  18933. // extrapolate last point
  18934. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  18935. p3 = tmp;
  18936. }
  18937. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  18938. // init Centripetal / Chordal Catmull-Rom
  18939. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  18940. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  18941. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  18942. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  18943. // safety check for repeated points
  18944. if ( dt1 < 1e-4 ) dt1 = 1.0;
  18945. if ( dt0 < 1e-4 ) dt0 = dt1;
  18946. if ( dt2 < 1e-4 ) dt2 = dt1;
  18947. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  18948. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  18949. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  18950. } else if ( this.curveType === 'catmullrom' ) {
  18951. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  18952. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  18953. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  18954. }
  18955. point.set(
  18956. px.calc( weight ),
  18957. py.calc( weight ),
  18958. pz.calc( weight )
  18959. );
  18960. return point;
  18961. };
  18962. CatmullRomCurve3.prototype.copy = function ( source ) {
  18963. Curve.prototype.copy.call( this, source );
  18964. this.points = [];
  18965. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  18966. var point = source.points[ i ];
  18967. this.points.push( point.clone() );
  18968. }
  18969. this.closed = source.closed;
  18970. this.curveType = source.curveType;
  18971. this.tension = source.tension;
  18972. return this;
  18973. };
  18974. CatmullRomCurve3.prototype.toJSON = function () {
  18975. var data = Curve.prototype.toJSON.call( this );
  18976. data.points = [];
  18977. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  18978. var point = this.points[ i ];
  18979. data.points.push( point.toArray() );
  18980. }
  18981. data.closed = this.closed;
  18982. data.curveType = this.curveType;
  18983. data.tension = this.tension;
  18984. return data;
  18985. };
  18986. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  18987. Curve.prototype.fromJSON.call( this, json );
  18988. this.points = [];
  18989. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  18990. var point = json.points[ i ];
  18991. this.points.push( new Vector3().fromArray( point ) );
  18992. }
  18993. this.closed = json.closed;
  18994. this.curveType = json.curveType;
  18995. this.tension = json.tension;
  18996. return this;
  18997. };
  18998. /**
  18999. * @author zz85 / http://www.lab4games.net/zz85/blog
  19000. *
  19001. * Bezier Curves formulas obtained from
  19002. * http://en.wikipedia.org/wiki/Bézier_curve
  19003. */
  19004. function CatmullRom( t, p0, p1, p2, p3 ) {
  19005. var v0 = ( p2 - p0 ) * 0.5;
  19006. var v1 = ( p3 - p1 ) * 0.5;
  19007. var t2 = t * t;
  19008. var t3 = t * t2;
  19009. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  19010. }
  19011. //
  19012. function QuadraticBezierP0( t, p ) {
  19013. var k = 1 - t;
  19014. return k * k * p;
  19015. }
  19016. function QuadraticBezierP1( t, p ) {
  19017. return 2 * ( 1 - t ) * t * p;
  19018. }
  19019. function QuadraticBezierP2( t, p ) {
  19020. return t * t * p;
  19021. }
  19022. function QuadraticBezier( t, p0, p1, p2 ) {
  19023. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  19024. QuadraticBezierP2( t, p2 );
  19025. }
  19026. //
  19027. function CubicBezierP0( t, p ) {
  19028. var k = 1 - t;
  19029. return k * k * k * p;
  19030. }
  19031. function CubicBezierP1( t, p ) {
  19032. var k = 1 - t;
  19033. return 3 * k * k * t * p;
  19034. }
  19035. function CubicBezierP2( t, p ) {
  19036. return 3 * ( 1 - t ) * t * t * p;
  19037. }
  19038. function CubicBezierP3( t, p ) {
  19039. return t * t * t * p;
  19040. }
  19041. function CubicBezier( t, p0, p1, p2, p3 ) {
  19042. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  19043. CubicBezierP3( t, p3 );
  19044. }
  19045. function CubicBezierCurve( v0, v1, v2, v3 ) {
  19046. Curve.call( this );
  19047. this.type = 'CubicBezierCurve';
  19048. this.v0 = v0 || new Vector2();
  19049. this.v1 = v1 || new Vector2();
  19050. this.v2 = v2 || new Vector2();
  19051. this.v3 = v3 || new Vector2();
  19052. }
  19053. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  19054. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  19055. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  19056. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19057. var point = optionalTarget || new Vector2();
  19058. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  19059. point.set(
  19060. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  19061. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  19062. );
  19063. return point;
  19064. };
  19065. CubicBezierCurve.prototype.copy = function ( source ) {
  19066. Curve.prototype.copy.call( this, source );
  19067. this.v0.copy( source.v0 );
  19068. this.v1.copy( source.v1 );
  19069. this.v2.copy( source.v2 );
  19070. this.v3.copy( source.v3 );
  19071. return this;
  19072. };
  19073. CubicBezierCurve.prototype.toJSON = function () {
  19074. var data = Curve.prototype.toJSON.call( this );
  19075. data.v0 = this.v0.toArray();
  19076. data.v1 = this.v1.toArray();
  19077. data.v2 = this.v2.toArray();
  19078. data.v3 = this.v3.toArray();
  19079. return data;
  19080. };
  19081. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  19082. Curve.prototype.fromJSON.call( this, json );
  19083. this.v0.fromArray( json.v0 );
  19084. this.v1.fromArray( json.v1 );
  19085. this.v2.fromArray( json.v2 );
  19086. this.v3.fromArray( json.v3 );
  19087. return this;
  19088. };
  19089. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  19090. Curve.call( this );
  19091. this.type = 'CubicBezierCurve3';
  19092. this.v0 = v0 || new Vector3();
  19093. this.v1 = v1 || new Vector3();
  19094. this.v2 = v2 || new Vector3();
  19095. this.v3 = v3 || new Vector3();
  19096. }
  19097. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  19098. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  19099. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  19100. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19101. var point = optionalTarget || new Vector3();
  19102. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  19103. point.set(
  19104. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  19105. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  19106. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  19107. );
  19108. return point;
  19109. };
  19110. CubicBezierCurve3.prototype.copy = function ( source ) {
  19111. Curve.prototype.copy.call( this, source );
  19112. this.v0.copy( source.v0 );
  19113. this.v1.copy( source.v1 );
  19114. this.v2.copy( source.v2 );
  19115. this.v3.copy( source.v3 );
  19116. return this;
  19117. };
  19118. CubicBezierCurve3.prototype.toJSON = function () {
  19119. var data = Curve.prototype.toJSON.call( this );
  19120. data.v0 = this.v0.toArray();
  19121. data.v1 = this.v1.toArray();
  19122. data.v2 = this.v2.toArray();
  19123. data.v3 = this.v3.toArray();
  19124. return data;
  19125. };
  19126. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  19127. Curve.prototype.fromJSON.call( this, json );
  19128. this.v0.fromArray( json.v0 );
  19129. this.v1.fromArray( json.v1 );
  19130. this.v2.fromArray( json.v2 );
  19131. this.v3.fromArray( json.v3 );
  19132. return this;
  19133. };
  19134. function LineCurve( v1, v2 ) {
  19135. Curve.call( this );
  19136. this.type = 'LineCurve';
  19137. this.v1 = v1 || new Vector2();
  19138. this.v2 = v2 || new Vector2();
  19139. }
  19140. LineCurve.prototype = Object.create( Curve.prototype );
  19141. LineCurve.prototype.constructor = LineCurve;
  19142. LineCurve.prototype.isLineCurve = true;
  19143. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19144. var point = optionalTarget || new Vector2();
  19145. if ( t === 1 ) {
  19146. point.copy( this.v2 );
  19147. } else {
  19148. point.copy( this.v2 ).sub( this.v1 );
  19149. point.multiplyScalar( t ).add( this.v1 );
  19150. }
  19151. return point;
  19152. };
  19153. // Line curve is linear, so we can overwrite default getPointAt
  19154. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  19155. return this.getPoint( u, optionalTarget );
  19156. };
  19157. LineCurve.prototype.getTangent = function ( /* t */ ) {
  19158. var tangent = this.v2.clone().sub( this.v1 );
  19159. return tangent.normalize();
  19160. };
  19161. LineCurve.prototype.copy = function ( source ) {
  19162. Curve.prototype.copy.call( this, source );
  19163. this.v1.copy( source.v1 );
  19164. this.v2.copy( source.v2 );
  19165. return this;
  19166. };
  19167. LineCurve.prototype.toJSON = function () {
  19168. var data = Curve.prototype.toJSON.call( this );
  19169. data.v1 = this.v1.toArray();
  19170. data.v2 = this.v2.toArray();
  19171. return data;
  19172. };
  19173. LineCurve.prototype.fromJSON = function ( json ) {
  19174. Curve.prototype.fromJSON.call( this, json );
  19175. this.v1.fromArray( json.v1 );
  19176. this.v2.fromArray( json.v2 );
  19177. return this;
  19178. };
  19179. function LineCurve3( v1, v2 ) {
  19180. Curve.call( this );
  19181. this.type = 'LineCurve3';
  19182. this.v1 = v1 || new Vector3();
  19183. this.v2 = v2 || new Vector3();
  19184. }
  19185. LineCurve3.prototype = Object.create( Curve.prototype );
  19186. LineCurve3.prototype.constructor = LineCurve3;
  19187. LineCurve3.prototype.isLineCurve3 = true;
  19188. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19189. var point = optionalTarget || new Vector3();
  19190. if ( t === 1 ) {
  19191. point.copy( this.v2 );
  19192. } else {
  19193. point.copy( this.v2 ).sub( this.v1 );
  19194. point.multiplyScalar( t ).add( this.v1 );
  19195. }
  19196. return point;
  19197. };
  19198. // Line curve is linear, so we can overwrite default getPointAt
  19199. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  19200. return this.getPoint( u, optionalTarget );
  19201. };
  19202. LineCurve3.prototype.copy = function ( source ) {
  19203. Curve.prototype.copy.call( this, source );
  19204. this.v1.copy( source.v1 );
  19205. this.v2.copy( source.v2 );
  19206. return this;
  19207. };
  19208. LineCurve3.prototype.toJSON = function () {
  19209. var data = Curve.prototype.toJSON.call( this );
  19210. data.v1 = this.v1.toArray();
  19211. data.v2 = this.v2.toArray();
  19212. return data;
  19213. };
  19214. LineCurve3.prototype.fromJSON = function ( json ) {
  19215. Curve.prototype.fromJSON.call( this, json );
  19216. this.v1.fromArray( json.v1 );
  19217. this.v2.fromArray( json.v2 );
  19218. return this;
  19219. };
  19220. function QuadraticBezierCurve( v0, v1, v2 ) {
  19221. Curve.call( this );
  19222. this.type = 'QuadraticBezierCurve';
  19223. this.v0 = v0 || new Vector2();
  19224. this.v1 = v1 || new Vector2();
  19225. this.v2 = v2 || new Vector2();
  19226. }
  19227. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  19228. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  19229. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  19230. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19231. var point = optionalTarget || new Vector2();
  19232. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  19233. point.set(
  19234. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  19235. QuadraticBezier( t, v0.y, v1.y, v2.y )
  19236. );
  19237. return point;
  19238. };
  19239. QuadraticBezierCurve.prototype.copy = function ( source ) {
  19240. Curve.prototype.copy.call( this, source );
  19241. this.v0.copy( source.v0 );
  19242. this.v1.copy( source.v1 );
  19243. this.v2.copy( source.v2 );
  19244. return this;
  19245. };
  19246. QuadraticBezierCurve.prototype.toJSON = function () {
  19247. var data = Curve.prototype.toJSON.call( this );
  19248. data.v0 = this.v0.toArray();
  19249. data.v1 = this.v1.toArray();
  19250. data.v2 = this.v2.toArray();
  19251. return data;
  19252. };
  19253. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  19254. Curve.prototype.fromJSON.call( this, json );
  19255. this.v0.fromArray( json.v0 );
  19256. this.v1.fromArray( json.v1 );
  19257. this.v2.fromArray( json.v2 );
  19258. return this;
  19259. };
  19260. function QuadraticBezierCurve3( v0, v1, v2 ) {
  19261. Curve.call( this );
  19262. this.type = 'QuadraticBezierCurve3';
  19263. this.v0 = v0 || new Vector3();
  19264. this.v1 = v1 || new Vector3();
  19265. this.v2 = v2 || new Vector3();
  19266. }
  19267. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  19268. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  19269. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  19270. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19271. var point = optionalTarget || new Vector3();
  19272. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  19273. point.set(
  19274. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  19275. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  19276. QuadraticBezier( t, v0.z, v1.z, v2.z )
  19277. );
  19278. return point;
  19279. };
  19280. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  19281. Curve.prototype.copy.call( this, source );
  19282. this.v0.copy( source.v0 );
  19283. this.v1.copy( source.v1 );
  19284. this.v2.copy( source.v2 );
  19285. return this;
  19286. };
  19287. QuadraticBezierCurve3.prototype.toJSON = function () {
  19288. var data = Curve.prototype.toJSON.call( this );
  19289. data.v0 = this.v0.toArray();
  19290. data.v1 = this.v1.toArray();
  19291. data.v2 = this.v2.toArray();
  19292. return data;
  19293. };
  19294. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  19295. Curve.prototype.fromJSON.call( this, json );
  19296. this.v0.fromArray( json.v0 );
  19297. this.v1.fromArray( json.v1 );
  19298. this.v2.fromArray( json.v2 );
  19299. return this;
  19300. };
  19301. function SplineCurve( points /* array of Vector2 */ ) {
  19302. Curve.call( this );
  19303. this.type = 'SplineCurve';
  19304. this.points = points || [];
  19305. }
  19306. SplineCurve.prototype = Object.create( Curve.prototype );
  19307. SplineCurve.prototype.constructor = SplineCurve;
  19308. SplineCurve.prototype.isSplineCurve = true;
  19309. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19310. var point = optionalTarget || new Vector2();
  19311. var points = this.points;
  19312. var p = ( points.length - 1 ) * t;
  19313. var intPoint = Math.floor( p );
  19314. var weight = p - intPoint;
  19315. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  19316. var p1 = points[ intPoint ];
  19317. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  19318. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  19319. point.set(
  19320. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  19321. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  19322. );
  19323. return point;
  19324. };
  19325. SplineCurve.prototype.copy = function ( source ) {
  19326. Curve.prototype.copy.call( this, source );
  19327. this.points = [];
  19328. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  19329. var point = source.points[ i ];
  19330. this.points.push( point.clone() );
  19331. }
  19332. return this;
  19333. };
  19334. SplineCurve.prototype.toJSON = function () {
  19335. var data = Curve.prototype.toJSON.call( this );
  19336. data.points = [];
  19337. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  19338. var point = this.points[ i ];
  19339. data.points.push( point.toArray() );
  19340. }
  19341. return data;
  19342. };
  19343. SplineCurve.prototype.fromJSON = function ( json ) {
  19344. Curve.prototype.fromJSON.call( this, json );
  19345. this.points = [];
  19346. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  19347. var point = json.points[ i ];
  19348. this.points.push( new Vector2().fromArray( point ) );
  19349. }
  19350. return this;
  19351. };
  19352. var Curves = Object.freeze({
  19353. ArcCurve: ArcCurve,
  19354. CatmullRomCurve3: CatmullRomCurve3,
  19355. CubicBezierCurve: CubicBezierCurve,
  19356. CubicBezierCurve3: CubicBezierCurve3,
  19357. EllipseCurve: EllipseCurve,
  19358. LineCurve: LineCurve,
  19359. LineCurve3: LineCurve3,
  19360. QuadraticBezierCurve: QuadraticBezierCurve,
  19361. QuadraticBezierCurve3: QuadraticBezierCurve3,
  19362. SplineCurve: SplineCurve
  19363. });
  19364. /**
  19365. * @author zz85 / http://www.lab4games.net/zz85/blog
  19366. *
  19367. **/
  19368. /**************************************************************
  19369. * Curved Path - a curve path is simply a array of connected
  19370. * curves, but retains the api of a curve
  19371. **************************************************************/
  19372. function CurvePath() {
  19373. Curve.call( this );
  19374. this.type = 'CurvePath';
  19375. this.curves = [];
  19376. this.autoClose = false; // Automatically closes the path
  19377. }
  19378. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  19379. constructor: CurvePath,
  19380. add: function ( curve ) {
  19381. this.curves.push( curve );
  19382. },
  19383. closePath: function () {
  19384. // Add a line curve if start and end of lines are not connected
  19385. var startPoint = this.curves[ 0 ].getPoint( 0 );
  19386. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  19387. if ( ! startPoint.equals( endPoint ) ) {
  19388. this.curves.push( new LineCurve( endPoint, startPoint ) );
  19389. }
  19390. },
  19391. // To get accurate point with reference to
  19392. // entire path distance at time t,
  19393. // following has to be done:
  19394. // 1. Length of each sub path have to be known
  19395. // 2. Locate and identify type of curve
  19396. // 3. Get t for the curve
  19397. // 4. Return curve.getPointAt(t')
  19398. getPoint: function ( t ) {
  19399. var d = t * this.getLength();
  19400. var curveLengths = this.getCurveLengths();
  19401. var i = 0;
  19402. // To think about boundaries points.
  19403. while ( i < curveLengths.length ) {
  19404. if ( curveLengths[ i ] >= d ) {
  19405. var diff = curveLengths[ i ] - d;
  19406. var curve = this.curves[ i ];
  19407. var segmentLength = curve.getLength();
  19408. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  19409. return curve.getPointAt( u );
  19410. }
  19411. i ++;
  19412. }
  19413. return null;
  19414. // loop where sum != 0, sum > d , sum+1 <d
  19415. },
  19416. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  19417. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  19418. // getPoint() depends on getLength
  19419. getLength: function () {
  19420. var lens = this.getCurveLengths();
  19421. return lens[ lens.length - 1 ];
  19422. },
  19423. // cacheLengths must be recalculated.
  19424. updateArcLengths: function () {
  19425. this.needsUpdate = true;
  19426. this.cacheLengths = null;
  19427. this.getCurveLengths();
  19428. },
  19429. // Compute lengths and cache them
  19430. // We cannot overwrite getLengths() because UtoT mapping uses it.
  19431. getCurveLengths: function () {
  19432. // We use cache values if curves and cache array are same length
  19433. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  19434. return this.cacheLengths;
  19435. }
  19436. // Get length of sub-curve
  19437. // Push sums into cached array
  19438. var lengths = [], sums = 0;
  19439. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  19440. sums += this.curves[ i ].getLength();
  19441. lengths.push( sums );
  19442. }
  19443. this.cacheLengths = lengths;
  19444. return lengths;
  19445. },
  19446. getSpacedPoints: function ( divisions ) {
  19447. if ( divisions === undefined ) divisions = 40;
  19448. var points = [];
  19449. for ( var i = 0; i <= divisions; i ++ ) {
  19450. points.push( this.getPoint( i / divisions ) );
  19451. }
  19452. if ( this.autoClose ) {
  19453. points.push( points[ 0 ] );
  19454. }
  19455. return points;
  19456. },
  19457. getPoints: function ( divisions ) {
  19458. divisions = divisions || 12;
  19459. var points = [], last;
  19460. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  19461. var curve = curves[ i ];
  19462. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  19463. : ( curve && curve.isLineCurve ) ? 1
  19464. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  19465. : divisions;
  19466. var pts = curve.getPoints( resolution );
  19467. for ( var j = 0; j < pts.length; j ++ ) {
  19468. var point = pts[ j ];
  19469. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  19470. points.push( point );
  19471. last = point;
  19472. }
  19473. }
  19474. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  19475. points.push( points[ 0 ] );
  19476. }
  19477. return points;
  19478. },
  19479. copy: function ( source ) {
  19480. Curve.prototype.copy.call( this, source );
  19481. this.curves = [];
  19482. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  19483. var curve = source.curves[ i ];
  19484. this.curves.push( curve.clone() );
  19485. }
  19486. this.autoClose = source.autoClose;
  19487. return this;
  19488. },
  19489. toJSON: function () {
  19490. var data = Curve.prototype.toJSON.call( this );
  19491. data.autoClose = this.autoClose;
  19492. data.curves = [];
  19493. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  19494. var curve = this.curves[ i ];
  19495. data.curves.push( curve.toJSON() );
  19496. }
  19497. return data;
  19498. },
  19499. fromJSON: function ( json ) {
  19500. Curve.prototype.fromJSON.call( this, json );
  19501. this.autoClose = json.autoClose;
  19502. this.curves = [];
  19503. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  19504. var curve = json.curves[ i ];
  19505. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  19506. }
  19507. return this;
  19508. }
  19509. } );
  19510. /**
  19511. * @author zz85 / http://www.lab4games.net/zz85/blog
  19512. * Creates free form 2d path using series of points, lines or curves.
  19513. **/
  19514. function Path( points ) {
  19515. CurvePath.call( this );
  19516. this.type = 'Path';
  19517. this.currentPoint = new Vector2();
  19518. if ( points ) {
  19519. this.setFromPoints( points );
  19520. }
  19521. }
  19522. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  19523. constructor: Path,
  19524. setFromPoints: function ( points ) {
  19525. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  19526. for ( var i = 1, l = points.length; i < l; i ++ ) {
  19527. this.lineTo( points[ i ].x, points[ i ].y );
  19528. }
  19529. },
  19530. moveTo: function ( x, y ) {
  19531. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  19532. },
  19533. lineTo: function ( x, y ) {
  19534. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  19535. this.curves.push( curve );
  19536. this.currentPoint.set( x, y );
  19537. },
  19538. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  19539. var curve = new QuadraticBezierCurve(
  19540. this.currentPoint.clone(),
  19541. new Vector2( aCPx, aCPy ),
  19542. new Vector2( aX, aY )
  19543. );
  19544. this.curves.push( curve );
  19545. this.currentPoint.set( aX, aY );
  19546. },
  19547. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  19548. var curve = new CubicBezierCurve(
  19549. this.currentPoint.clone(),
  19550. new Vector2( aCP1x, aCP1y ),
  19551. new Vector2( aCP2x, aCP2y ),
  19552. new Vector2( aX, aY )
  19553. );
  19554. this.curves.push( curve );
  19555. this.currentPoint.set( aX, aY );
  19556. },
  19557. splineThru: function ( pts /*Array of Vector*/ ) {
  19558. var npts = [ this.currentPoint.clone() ].concat( pts );
  19559. var curve = new SplineCurve( npts );
  19560. this.curves.push( curve );
  19561. this.currentPoint.copy( pts[ pts.length - 1 ] );
  19562. },
  19563. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  19564. var x0 = this.currentPoint.x;
  19565. var y0 = this.currentPoint.y;
  19566. this.absarc( aX + x0, aY + y0, aRadius,
  19567. aStartAngle, aEndAngle, aClockwise );
  19568. },
  19569. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  19570. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  19571. },
  19572. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  19573. var x0 = this.currentPoint.x;
  19574. var y0 = this.currentPoint.y;
  19575. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  19576. },
  19577. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  19578. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  19579. if ( this.curves.length > 0 ) {
  19580. // if a previous curve is present, attempt to join
  19581. var firstPoint = curve.getPoint( 0 );
  19582. if ( ! firstPoint.equals( this.currentPoint ) ) {
  19583. this.lineTo( firstPoint.x, firstPoint.y );
  19584. }
  19585. }
  19586. this.curves.push( curve );
  19587. var lastPoint = curve.getPoint( 1 );
  19588. this.currentPoint.copy( lastPoint );
  19589. },
  19590. copy: function ( source ) {
  19591. CurvePath.prototype.copy.call( this, source );
  19592. this.currentPoint.copy( source.currentPoint );
  19593. return this;
  19594. },
  19595. toJSON: function () {
  19596. var data = CurvePath.prototype.toJSON.call( this );
  19597. data.currentPoint = this.currentPoint.toArray();
  19598. return data;
  19599. },
  19600. fromJSON: function ( json ) {
  19601. CurvePath.prototype.fromJSON.call( this, json );
  19602. this.currentPoint.fromArray( json.currentPoint );
  19603. return this;
  19604. }
  19605. } );
  19606. /**
  19607. * @author zz85 / http://www.lab4games.net/zz85/blog
  19608. * Defines a 2d shape plane using paths.
  19609. **/
  19610. // STEP 1 Create a path.
  19611. // STEP 2 Turn path into shape.
  19612. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  19613. // STEP 3a - Extract points from each shape, turn to vertices
  19614. // STEP 3b - Triangulate each shape, add faces.
  19615. function Shape( points ) {
  19616. Path.call( this, points );
  19617. this.uuid = _Math.generateUUID();
  19618. this.type = 'Shape';
  19619. this.holes = [];
  19620. }
  19621. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  19622. constructor: Shape,
  19623. getPointsHoles: function ( divisions ) {
  19624. var holesPts = [];
  19625. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  19626. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  19627. }
  19628. return holesPts;
  19629. },
  19630. // get points of shape and holes (keypoints based on segments parameter)
  19631. extractPoints: function ( divisions ) {
  19632. return {
  19633. shape: this.getPoints( divisions ),
  19634. holes: this.getPointsHoles( divisions )
  19635. };
  19636. },
  19637. copy: function ( source ) {
  19638. Path.prototype.copy.call( this, source );
  19639. this.holes = [];
  19640. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  19641. var hole = source.holes[ i ];
  19642. this.holes.push( hole.clone() );
  19643. }
  19644. return this;
  19645. },
  19646. toJSON: function () {
  19647. var data = Path.prototype.toJSON.call( this );
  19648. data.uuid = this.uuid;
  19649. data.holes = [];
  19650. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  19651. var hole = this.holes[ i ];
  19652. data.holes.push( hole.toJSON() );
  19653. }
  19654. return data;
  19655. },
  19656. fromJSON: function ( json ) {
  19657. Path.prototype.fromJSON.call( this, json );
  19658. this.uuid = json.uuid;
  19659. this.holes = [];
  19660. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  19661. var hole = json.holes[ i ];
  19662. this.holes.push( new Path().fromJSON( hole ) );
  19663. }
  19664. return this;
  19665. }
  19666. } );
  19667. /**
  19668. * @author mrdoob / http://mrdoob.com/
  19669. * @author alteredq / http://alteredqualia.com/
  19670. */
  19671. function Light( color, intensity ) {
  19672. Object3D.call( this );
  19673. this.type = 'Light';
  19674. this.color = new Color( color );
  19675. this.intensity = intensity !== undefined ? intensity : 1;
  19676. this.receiveShadow = undefined;
  19677. }
  19678. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  19679. constructor: Light,
  19680. isLight: true,
  19681. copy: function ( source ) {
  19682. Object3D.prototype.copy.call( this, source );
  19683. this.color.copy( source.color );
  19684. this.intensity = source.intensity;
  19685. return this;
  19686. },
  19687. toJSON: function ( meta ) {
  19688. var data = Object3D.prototype.toJSON.call( this, meta );
  19689. data.object.color = this.color.getHex();
  19690. data.object.intensity = this.intensity;
  19691. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  19692. if ( this.distance !== undefined ) data.object.distance = this.distance;
  19693. if ( this.angle !== undefined ) data.object.angle = this.angle;
  19694. if ( this.decay !== undefined ) data.object.decay = this.decay;
  19695. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  19696. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  19697. return data;
  19698. }
  19699. } );
  19700. /**
  19701. * @author alteredq / http://alteredqualia.com/
  19702. */
  19703. function HemisphereLight( skyColor, groundColor, intensity ) {
  19704. Light.call( this, skyColor, intensity );
  19705. this.type = 'HemisphereLight';
  19706. this.castShadow = undefined;
  19707. this.position.copy( Object3D.DefaultUp );
  19708. this.updateMatrix();
  19709. this.groundColor = new Color( groundColor );
  19710. }
  19711. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  19712. constructor: HemisphereLight,
  19713. isHemisphereLight: true,
  19714. copy: function ( source ) {
  19715. Light.prototype.copy.call( this, source );
  19716. this.groundColor.copy( source.groundColor );
  19717. return this;
  19718. }
  19719. } );
  19720. /**
  19721. * @author mrdoob / http://mrdoob.com/
  19722. */
  19723. function LightShadow( camera ) {
  19724. this.camera = camera;
  19725. this.bias = 0;
  19726. this.radius = 1;
  19727. this.mapSize = new Vector2( 512, 512 );
  19728. this.map = null;
  19729. this.matrix = new Matrix4();
  19730. }
  19731. Object.assign( LightShadow.prototype, {
  19732. copy: function ( source ) {
  19733. this.camera = source.camera.clone();
  19734. this.bias = source.bias;
  19735. this.radius = source.radius;
  19736. this.mapSize.copy( source.mapSize );
  19737. return this;
  19738. },
  19739. clone: function () {
  19740. return new this.constructor().copy( this );
  19741. },
  19742. toJSON: function () {
  19743. var object = {};
  19744. if ( this.bias !== 0 ) object.bias = this.bias;
  19745. if ( this.radius !== 1 ) object.radius = this.radius;
  19746. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  19747. object.camera = this.camera.toJSON( false ).object;
  19748. delete object.camera.matrix;
  19749. return object;
  19750. }
  19751. } );
  19752. /**
  19753. * @author mrdoob / http://mrdoob.com/
  19754. */
  19755. function SpotLightShadow() {
  19756. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  19757. }
  19758. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  19759. constructor: SpotLightShadow,
  19760. isSpotLightShadow: true,
  19761. update: function ( light ) {
  19762. var camera = this.camera;
  19763. var fov = _Math.RAD2DEG * 2 * light.angle;
  19764. var aspect = this.mapSize.width / this.mapSize.height;
  19765. var far = light.distance || camera.far;
  19766. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  19767. camera.fov = fov;
  19768. camera.aspect = aspect;
  19769. camera.far = far;
  19770. camera.updateProjectionMatrix();
  19771. }
  19772. }
  19773. } );
  19774. /**
  19775. * @author alteredq / http://alteredqualia.com/
  19776. */
  19777. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  19778. Light.call( this, color, intensity );
  19779. this.type = 'SpotLight';
  19780. this.position.copy( Object3D.DefaultUp );
  19781. this.updateMatrix();
  19782. this.target = new Object3D();
  19783. Object.defineProperty( this, 'power', {
  19784. get: function () {
  19785. // intensity = power per solid angle.
  19786. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  19787. return this.intensity * Math.PI;
  19788. },
  19789. set: function ( power ) {
  19790. // intensity = power per solid angle.
  19791. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  19792. this.intensity = power / Math.PI;
  19793. }
  19794. } );
  19795. this.distance = ( distance !== undefined ) ? distance : 0;
  19796. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  19797. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  19798. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  19799. this.shadow = new SpotLightShadow();
  19800. }
  19801. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  19802. constructor: SpotLight,
  19803. isSpotLight: true,
  19804. copy: function ( source ) {
  19805. Light.prototype.copy.call( this, source );
  19806. this.distance = source.distance;
  19807. this.angle = source.angle;
  19808. this.penumbra = source.penumbra;
  19809. this.decay = source.decay;
  19810. this.target = source.target.clone();
  19811. this.shadow = source.shadow.clone();
  19812. return this;
  19813. }
  19814. } );
  19815. /**
  19816. * @author mrdoob / http://mrdoob.com/
  19817. */
  19818. function PointLight( color, intensity, distance, decay ) {
  19819. Light.call( this, color, intensity );
  19820. this.type = 'PointLight';
  19821. Object.defineProperty( this, 'power', {
  19822. get: function () {
  19823. // intensity = power per solid angle.
  19824. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  19825. return this.intensity * 4 * Math.PI;
  19826. },
  19827. set: function ( power ) {
  19828. // intensity = power per solid angle.
  19829. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  19830. this.intensity = power / ( 4 * Math.PI );
  19831. }
  19832. } );
  19833. this.distance = ( distance !== undefined ) ? distance : 0;
  19834. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  19835. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  19836. }
  19837. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  19838. constructor: PointLight,
  19839. isPointLight: true,
  19840. copy: function ( source ) {
  19841. Light.prototype.copy.call( this, source );
  19842. this.distance = source.distance;
  19843. this.decay = source.decay;
  19844. this.shadow = source.shadow.clone();
  19845. return this;
  19846. }
  19847. } );
  19848. /**
  19849. * @author mrdoob / http://mrdoob.com/
  19850. */
  19851. function DirectionalLightShadow( ) {
  19852. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  19853. }
  19854. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  19855. constructor: DirectionalLightShadow
  19856. } );
  19857. /**
  19858. * @author mrdoob / http://mrdoob.com/
  19859. * @author alteredq / http://alteredqualia.com/
  19860. */
  19861. function DirectionalLight( color, intensity ) {
  19862. Light.call( this, color, intensity );
  19863. this.type = 'DirectionalLight';
  19864. this.position.copy( Object3D.DefaultUp );
  19865. this.updateMatrix();
  19866. this.target = new Object3D();
  19867. this.shadow = new DirectionalLightShadow();
  19868. }
  19869. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  19870. constructor: DirectionalLight,
  19871. isDirectionalLight: true,
  19872. copy: function ( source ) {
  19873. Light.prototype.copy.call( this, source );
  19874. this.target = source.target.clone();
  19875. this.shadow = source.shadow.clone();
  19876. return this;
  19877. }
  19878. } );
  19879. /**
  19880. * @author mrdoob / http://mrdoob.com/
  19881. */
  19882. function AmbientLight( color, intensity ) {
  19883. Light.call( this, color, intensity );
  19884. this.type = 'AmbientLight';
  19885. this.castShadow = undefined;
  19886. }
  19887. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  19888. constructor: AmbientLight,
  19889. isAmbientLight: true
  19890. } );
  19891. /**
  19892. * @author abelnation / http://github.com/abelnation
  19893. */
  19894. function RectAreaLight( color, intensity, width, height ) {
  19895. Light.call( this, color, intensity );
  19896. this.type = 'RectAreaLight';
  19897. this.width = ( width !== undefined ) ? width : 10;
  19898. this.height = ( height !== undefined ) ? height : 10;
  19899. }
  19900. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  19901. constructor: RectAreaLight,
  19902. isRectAreaLight: true,
  19903. copy: function ( source ) {
  19904. Light.prototype.copy.call( this, source );
  19905. this.width = source.width;
  19906. this.height = source.height;
  19907. return this;
  19908. },
  19909. toJSON: function ( meta ) {
  19910. var data = Light.prototype.toJSON.call( this, meta );
  19911. data.object.width = this.width;
  19912. data.object.height = this.height;
  19913. return data;
  19914. }
  19915. } );
  19916. /**
  19917. *
  19918. * A Track that interpolates Strings
  19919. *
  19920. *
  19921. * @author Ben Houston / http://clara.io/
  19922. * @author David Sarno / http://lighthaus.us/
  19923. * @author tschw
  19924. */
  19925. function StringKeyframeTrack( name, times, values, interpolation ) {
  19926. KeyframeTrack.call( this, name, times, values, interpolation );
  19927. }
  19928. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  19929. constructor: StringKeyframeTrack,
  19930. ValueTypeName: 'string',
  19931. ValueBufferType: Array,
  19932. DefaultInterpolation: InterpolateDiscrete,
  19933. InterpolantFactoryMethodLinear: undefined,
  19934. InterpolantFactoryMethodSmooth: undefined
  19935. } );
  19936. /**
  19937. *
  19938. * A Track of Boolean keyframe values.
  19939. *
  19940. *
  19941. * @author Ben Houston / http://clara.io/
  19942. * @author David Sarno / http://lighthaus.us/
  19943. * @author tschw
  19944. */
  19945. function BooleanKeyframeTrack( name, times, values ) {
  19946. KeyframeTrack.call( this, name, times, values );
  19947. }
  19948. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  19949. constructor: BooleanKeyframeTrack,
  19950. ValueTypeName: 'bool',
  19951. ValueBufferType: Array,
  19952. DefaultInterpolation: InterpolateDiscrete,
  19953. InterpolantFactoryMethodLinear: undefined,
  19954. InterpolantFactoryMethodSmooth: undefined
  19955. // Note: Actually this track could have a optimized / compressed
  19956. // representation of a single value and a custom interpolant that
  19957. // computes "firstValue ^ isOdd( index )".
  19958. } );
  19959. /**
  19960. * Abstract base class of interpolants over parametric samples.
  19961. *
  19962. * The parameter domain is one dimensional, typically the time or a path
  19963. * along a curve defined by the data.
  19964. *
  19965. * The sample values can have any dimensionality and derived classes may
  19966. * apply special interpretations to the data.
  19967. *
  19968. * This class provides the interval seek in a Template Method, deferring
  19969. * the actual interpolation to derived classes.
  19970. *
  19971. * Time complexity is O(1) for linear access crossing at most two points
  19972. * and O(log N) for random access, where N is the number of positions.
  19973. *
  19974. * References:
  19975. *
  19976. * http://www.oodesign.com/template-method-pattern.html
  19977. *
  19978. * @author tschw
  19979. */
  19980. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19981. this.parameterPositions = parameterPositions;
  19982. this._cachedIndex = 0;
  19983. this.resultBuffer = resultBuffer !== undefined ?
  19984. resultBuffer : new sampleValues.constructor( sampleSize );
  19985. this.sampleValues = sampleValues;
  19986. this.valueSize = sampleSize;
  19987. }
  19988. Object.assign( Interpolant.prototype, {
  19989. evaluate: function ( t ) {
  19990. var pp = this.parameterPositions,
  19991. i1 = this._cachedIndex,
  19992. t1 = pp[ i1 ],
  19993. t0 = pp[ i1 - 1 ];
  19994. validate_interval: {
  19995. seek: {
  19996. var right;
  19997. linear_scan: {
  19998. //- See http://jsperf.com/comparison-to-undefined/3
  19999. //- slower code:
  20000. //-
  20001. //- if ( t >= t1 || t1 === undefined ) {
  20002. forward_scan: if ( ! ( t < t1 ) ) {
  20003. for ( var giveUpAt = i1 + 2; ; ) {
  20004. if ( t1 === undefined ) {
  20005. if ( t < t0 ) break forward_scan;
  20006. // after end
  20007. i1 = pp.length;
  20008. this._cachedIndex = i1;
  20009. return this.afterEnd_( i1 - 1, t, t0 );
  20010. }
  20011. if ( i1 === giveUpAt ) break; // this loop
  20012. t0 = t1;
  20013. t1 = pp[ ++ i1 ];
  20014. if ( t < t1 ) {
  20015. // we have arrived at the sought interval
  20016. break seek;
  20017. }
  20018. }
  20019. // prepare binary search on the right side of the index
  20020. right = pp.length;
  20021. break linear_scan;
  20022. }
  20023. //- slower code:
  20024. //- if ( t < t0 || t0 === undefined ) {
  20025. if ( ! ( t >= t0 ) ) {
  20026. // looping?
  20027. var t1global = pp[ 1 ];
  20028. if ( t < t1global ) {
  20029. i1 = 2; // + 1, using the scan for the details
  20030. t0 = t1global;
  20031. }
  20032. // linear reverse scan
  20033. for ( var giveUpAt = i1 - 2; ; ) {
  20034. if ( t0 === undefined ) {
  20035. // before start
  20036. this._cachedIndex = 0;
  20037. return this.beforeStart_( 0, t, t1 );
  20038. }
  20039. if ( i1 === giveUpAt ) break; // this loop
  20040. t1 = t0;
  20041. t0 = pp[ -- i1 - 1 ];
  20042. if ( t >= t0 ) {
  20043. // we have arrived at the sought interval
  20044. break seek;
  20045. }
  20046. }
  20047. // prepare binary search on the left side of the index
  20048. right = i1;
  20049. i1 = 0;
  20050. break linear_scan;
  20051. }
  20052. // the interval is valid
  20053. break validate_interval;
  20054. } // linear scan
  20055. // binary search
  20056. while ( i1 < right ) {
  20057. var mid = ( i1 + right ) >>> 1;
  20058. if ( t < pp[ mid ] ) {
  20059. right = mid;
  20060. } else {
  20061. i1 = mid + 1;
  20062. }
  20063. }
  20064. t1 = pp[ i1 ];
  20065. t0 = pp[ i1 - 1 ];
  20066. // check boundary cases, again
  20067. if ( t0 === undefined ) {
  20068. this._cachedIndex = 0;
  20069. return this.beforeStart_( 0, t, t1 );
  20070. }
  20071. if ( t1 === undefined ) {
  20072. i1 = pp.length;
  20073. this._cachedIndex = i1;
  20074. return this.afterEnd_( i1 - 1, t0, t );
  20075. }
  20076. } // seek
  20077. this._cachedIndex = i1;
  20078. this.intervalChanged_( i1, t0, t1 );
  20079. } // validate_interval
  20080. return this.interpolate_( i1, t0, t, t1 );
  20081. },
  20082. settings: null, // optional, subclass-specific settings structure
  20083. // Note: The indirection allows central control of many interpolants.
  20084. // --- Protected interface
  20085. DefaultSettings_: {},
  20086. getSettings_: function () {
  20087. return this.settings || this.DefaultSettings_;
  20088. },
  20089. copySampleValue_: function ( index ) {
  20090. // copies a sample value to the result buffer
  20091. var result = this.resultBuffer,
  20092. values = this.sampleValues,
  20093. stride = this.valueSize,
  20094. offset = index * stride;
  20095. for ( var i = 0; i !== stride; ++ i ) {
  20096. result[ i ] = values[ offset + i ];
  20097. }
  20098. return result;
  20099. },
  20100. // Template methods for derived classes:
  20101. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  20102. throw new Error( 'call to abstract method' );
  20103. // implementations shall return this.resultBuffer
  20104. },
  20105. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  20106. // empty
  20107. }
  20108. } );
  20109. //!\ DECLARE ALIAS AFTER assign prototype !
  20110. Object.assign( Interpolant.prototype, {
  20111. //( 0, t, t0 ), returns this.resultBuffer
  20112. beforeStart_: Interpolant.prototype.copySampleValue_,
  20113. //( N-1, tN-1, t ), returns this.resultBuffer
  20114. afterEnd_: Interpolant.prototype.copySampleValue_,
  20115. } );
  20116. /**
  20117. * Spherical linear unit quaternion interpolant.
  20118. *
  20119. * @author tschw
  20120. */
  20121. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20122. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20123. }
  20124. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20125. constructor: QuaternionLinearInterpolant,
  20126. interpolate_: function ( i1, t0, t, t1 ) {
  20127. var result = this.resultBuffer,
  20128. values = this.sampleValues,
  20129. stride = this.valueSize,
  20130. offset = i1 * stride,
  20131. alpha = ( t - t0 ) / ( t1 - t0 );
  20132. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  20133. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20134. }
  20135. return result;
  20136. }
  20137. } );
  20138. /**
  20139. *
  20140. * A Track of quaternion keyframe values.
  20141. *
  20142. * @author Ben Houston / http://clara.io/
  20143. * @author David Sarno / http://lighthaus.us/
  20144. * @author tschw
  20145. */
  20146. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20147. KeyframeTrack.call( this, name, times, values, interpolation );
  20148. }
  20149. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20150. constructor: QuaternionKeyframeTrack,
  20151. ValueTypeName: 'quaternion',
  20152. // ValueBufferType is inherited
  20153. DefaultInterpolation: InterpolateLinear,
  20154. InterpolantFactoryMethodLinear: function ( result ) {
  20155. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20156. },
  20157. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20158. } );
  20159. /**
  20160. *
  20161. * A Track of keyframe values that represent color.
  20162. *
  20163. *
  20164. * @author Ben Houston / http://clara.io/
  20165. * @author David Sarno / http://lighthaus.us/
  20166. * @author tschw
  20167. */
  20168. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20169. KeyframeTrack.call( this, name, times, values, interpolation );
  20170. }
  20171. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20172. constructor: ColorKeyframeTrack,
  20173. ValueTypeName: 'color'
  20174. // ValueBufferType is inherited
  20175. // DefaultInterpolation is inherited
  20176. // Note: Very basic implementation and nothing special yet.
  20177. // However, this is the place for color space parameterization.
  20178. } );
  20179. /**
  20180. *
  20181. * A Track of numeric keyframe values.
  20182. *
  20183. * @author Ben Houston / http://clara.io/
  20184. * @author David Sarno / http://lighthaus.us/
  20185. * @author tschw
  20186. */
  20187. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20188. KeyframeTrack.call( this, name, times, values, interpolation );
  20189. }
  20190. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20191. constructor: NumberKeyframeTrack,
  20192. ValueTypeName: 'number'
  20193. // ValueBufferType is inherited
  20194. // DefaultInterpolation is inherited
  20195. } );
  20196. /**
  20197. * Fast and simple cubic spline interpolant.
  20198. *
  20199. * It was derived from a Hermitian construction setting the first derivative
  20200. * at each sample position to the linear slope between neighboring positions
  20201. * over their parameter interval.
  20202. *
  20203. * @author tschw
  20204. */
  20205. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20206. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20207. this._weightPrev = - 0;
  20208. this._offsetPrev = - 0;
  20209. this._weightNext = - 0;
  20210. this._offsetNext = - 0;
  20211. }
  20212. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20213. constructor: CubicInterpolant,
  20214. DefaultSettings_: {
  20215. endingStart: ZeroCurvatureEnding,
  20216. endingEnd: ZeroCurvatureEnding
  20217. },
  20218. intervalChanged_: function ( i1, t0, t1 ) {
  20219. var pp = this.parameterPositions,
  20220. iPrev = i1 - 2,
  20221. iNext = i1 + 1,
  20222. tPrev = pp[ iPrev ],
  20223. tNext = pp[ iNext ];
  20224. if ( tPrev === undefined ) {
  20225. switch ( this.getSettings_().endingStart ) {
  20226. case ZeroSlopeEnding:
  20227. // f'(t0) = 0
  20228. iPrev = i1;
  20229. tPrev = 2 * t0 - t1;
  20230. break;
  20231. case WrapAroundEnding:
  20232. // use the other end of the curve
  20233. iPrev = pp.length - 2;
  20234. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  20235. break;
  20236. default: // ZeroCurvatureEnding
  20237. // f''(t0) = 0 a.k.a. Natural Spline
  20238. iPrev = i1;
  20239. tPrev = t1;
  20240. }
  20241. }
  20242. if ( tNext === undefined ) {
  20243. switch ( this.getSettings_().endingEnd ) {
  20244. case ZeroSlopeEnding:
  20245. // f'(tN) = 0
  20246. iNext = i1;
  20247. tNext = 2 * t1 - t0;
  20248. break;
  20249. case WrapAroundEnding:
  20250. // use the other end of the curve
  20251. iNext = 1;
  20252. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  20253. break;
  20254. default: // ZeroCurvatureEnding
  20255. // f''(tN) = 0, a.k.a. Natural Spline
  20256. iNext = i1 - 1;
  20257. tNext = t0;
  20258. }
  20259. }
  20260. var halfDt = ( t1 - t0 ) * 0.5,
  20261. stride = this.valueSize;
  20262. this._weightPrev = halfDt / ( t0 - tPrev );
  20263. this._weightNext = halfDt / ( tNext - t1 );
  20264. this._offsetPrev = iPrev * stride;
  20265. this._offsetNext = iNext * stride;
  20266. },
  20267. interpolate_: function ( i1, t0, t, t1 ) {
  20268. var result = this.resultBuffer,
  20269. values = this.sampleValues,
  20270. stride = this.valueSize,
  20271. o1 = i1 * stride, o0 = o1 - stride,
  20272. oP = this._offsetPrev, oN = this._offsetNext,
  20273. wP = this._weightPrev, wN = this._weightNext,
  20274. p = ( t - t0 ) / ( t1 - t0 ),
  20275. pp = p * p,
  20276. ppp = pp * p;
  20277. // evaluate polynomials
  20278. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  20279. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  20280. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  20281. var sN = wN * ppp - wN * pp;
  20282. // combine data linearly
  20283. for ( var i = 0; i !== stride; ++ i ) {
  20284. result[ i ] =
  20285. sP * values[ oP + i ] +
  20286. s0 * values[ o0 + i ] +
  20287. s1 * values[ o1 + i ] +
  20288. sN * values[ oN + i ];
  20289. }
  20290. return result;
  20291. }
  20292. } );
  20293. /**
  20294. * @author tschw
  20295. */
  20296. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20297. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20298. }
  20299. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20300. constructor: LinearInterpolant,
  20301. interpolate_: function ( i1, t0, t, t1 ) {
  20302. var result = this.resultBuffer,
  20303. values = this.sampleValues,
  20304. stride = this.valueSize,
  20305. offset1 = i1 * stride,
  20306. offset0 = offset1 - stride,
  20307. weight1 = ( t - t0 ) / ( t1 - t0 ),
  20308. weight0 = 1 - weight1;
  20309. for ( var i = 0; i !== stride; ++ i ) {
  20310. result[ i ] =
  20311. values[ offset0 + i ] * weight0 +
  20312. values[ offset1 + i ] * weight1;
  20313. }
  20314. return result;
  20315. }
  20316. } );
  20317. /**
  20318. *
  20319. * Interpolant that evaluates to the sample value at the position preceeding
  20320. * the parameter.
  20321. *
  20322. * @author tschw
  20323. */
  20324. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20325. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20326. }
  20327. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20328. constructor: DiscreteInterpolant,
  20329. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  20330. return this.copySampleValue_( i1 - 1 );
  20331. }
  20332. } );
  20333. /**
  20334. * @author tschw
  20335. * @author Ben Houston / http://clara.io/
  20336. * @author David Sarno / http://lighthaus.us/
  20337. */
  20338. var AnimationUtils = {
  20339. // same as Array.prototype.slice, but also works on typed arrays
  20340. arraySlice: function ( array, from, to ) {
  20341. if ( AnimationUtils.isTypedArray( array ) ) {
  20342. // in ios9 array.subarray(from, undefined) will return empty array
  20343. // but array.subarray(from) or array.subarray(from, len) is correct
  20344. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  20345. }
  20346. return array.slice( from, to );
  20347. },
  20348. // converts an array to a specific type
  20349. convertArray: function ( array, type, forceClone ) {
  20350. if ( ! array || // let 'undefined' and 'null' pass
  20351. ! forceClone && array.constructor === type ) return array;
  20352. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  20353. return new type( array ); // create typed array
  20354. }
  20355. return Array.prototype.slice.call( array ); // create Array
  20356. },
  20357. isTypedArray: function ( object ) {
  20358. return ArrayBuffer.isView( object ) &&
  20359. ! ( object instanceof DataView );
  20360. },
  20361. // returns an array by which times and values can be sorted
  20362. getKeyframeOrder: function ( times ) {
  20363. function compareTime( i, j ) {
  20364. return times[ i ] - times[ j ];
  20365. }
  20366. var n = times.length;
  20367. var result = new Array( n );
  20368. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  20369. result.sort( compareTime );
  20370. return result;
  20371. },
  20372. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20373. sortedArray: function ( values, stride, order ) {
  20374. var nValues = values.length;
  20375. var result = new values.constructor( nValues );
  20376. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  20377. var srcOffset = order[ i ] * stride;
  20378. for ( var j = 0; j !== stride; ++ j ) {
  20379. result[ dstOffset ++ ] = values[ srcOffset + j ];
  20380. }
  20381. }
  20382. return result;
  20383. },
  20384. // function for parsing AOS keyframe formats
  20385. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  20386. var i = 1, key = jsonKeys[ 0 ];
  20387. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  20388. key = jsonKeys[ i ++ ];
  20389. }
  20390. if ( key === undefined ) return; // no data
  20391. var value = key[ valuePropertyName ];
  20392. if ( value === undefined ) return; // no data
  20393. if ( Array.isArray( value ) ) {
  20394. do {
  20395. value = key[ valuePropertyName ];
  20396. if ( value !== undefined ) {
  20397. times.push( key.time );
  20398. values.push.apply( values, value ); // push all elements
  20399. }
  20400. key = jsonKeys[ i ++ ];
  20401. } while ( key !== undefined );
  20402. } else if ( value.toArray !== undefined ) {
  20403. // ...assume THREE.Math-ish
  20404. do {
  20405. value = key[ valuePropertyName ];
  20406. if ( value !== undefined ) {
  20407. times.push( key.time );
  20408. value.toArray( values, values.length );
  20409. }
  20410. key = jsonKeys[ i ++ ];
  20411. } while ( key !== undefined );
  20412. } else {
  20413. // otherwise push as-is
  20414. do {
  20415. value = key[ valuePropertyName ];
  20416. if ( value !== undefined ) {
  20417. times.push( key.time );
  20418. values.push( value );
  20419. }
  20420. key = jsonKeys[ i ++ ];
  20421. } while ( key !== undefined );
  20422. }
  20423. }
  20424. };
  20425. /**
  20426. *
  20427. * A timed sequence of keyframes for a specific property.
  20428. *
  20429. *
  20430. * @author Ben Houston / http://clara.io/
  20431. * @author David Sarno / http://lighthaus.us/
  20432. * @author tschw
  20433. */
  20434. function KeyframeTrack( name, times, values, interpolation ) {
  20435. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  20436. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  20437. this.name = name;
  20438. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  20439. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  20440. this.setInterpolation( interpolation || this.DefaultInterpolation );
  20441. this.validate();
  20442. this.optimize();
  20443. }
  20444. // Static methods:
  20445. Object.assign( KeyframeTrack, {
  20446. // Serialization (in static context, because of constructor invocation
  20447. // and automatic invocation of .toJSON):
  20448. parse: function ( json ) {
  20449. if ( json.type === undefined ) {
  20450. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20451. }
  20452. var trackType = KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  20453. if ( json.times === undefined ) {
  20454. var times = [], values = [];
  20455. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20456. json.times = times;
  20457. json.values = values;
  20458. }
  20459. // derived classes can define a static parse method
  20460. if ( trackType.parse !== undefined ) {
  20461. return trackType.parse( json );
  20462. } else {
  20463. // by default, we assume a constructor compatible with the base
  20464. return new trackType( json.name, json.times, json.values, json.interpolation );
  20465. }
  20466. },
  20467. toJSON: function ( track ) {
  20468. var trackType = track.constructor;
  20469. var json;
  20470. // derived classes can define a static toJSON method
  20471. if ( trackType.toJSON !== undefined ) {
  20472. json = trackType.toJSON( track );
  20473. } else {
  20474. // by default, we assume the data can be serialized as-is
  20475. json = {
  20476. 'name': track.name,
  20477. 'times': AnimationUtils.convertArray( track.times, Array ),
  20478. 'values': AnimationUtils.convertArray( track.values, Array )
  20479. };
  20480. var interpolation = track.getInterpolation();
  20481. if ( interpolation !== track.DefaultInterpolation ) {
  20482. json.interpolation = interpolation;
  20483. }
  20484. }
  20485. json.type = track.ValueTypeName; // mandatory
  20486. return json;
  20487. },
  20488. _getTrackTypeForValueTypeName: function ( typeName ) {
  20489. switch ( typeName.toLowerCase() ) {
  20490. case 'scalar':
  20491. case 'double':
  20492. case 'float':
  20493. case 'number':
  20494. case 'integer':
  20495. return NumberKeyframeTrack;
  20496. case 'vector':
  20497. case 'vector2':
  20498. case 'vector3':
  20499. case 'vector4':
  20500. return VectorKeyframeTrack;
  20501. case 'color':
  20502. return ColorKeyframeTrack;
  20503. case 'quaternion':
  20504. return QuaternionKeyframeTrack;
  20505. case 'bool':
  20506. case 'boolean':
  20507. return BooleanKeyframeTrack;
  20508. case 'string':
  20509. return StringKeyframeTrack;
  20510. }
  20511. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20512. }
  20513. } );
  20514. Object.assign( KeyframeTrack.prototype, {
  20515. constructor: KeyframeTrack,
  20516. TimeBufferType: Float32Array,
  20517. ValueBufferType: Float32Array,
  20518. DefaultInterpolation: InterpolateLinear,
  20519. InterpolantFactoryMethodDiscrete: function ( result ) {
  20520. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  20521. },
  20522. InterpolantFactoryMethodLinear: function ( result ) {
  20523. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20524. },
  20525. InterpolantFactoryMethodSmooth: function ( result ) {
  20526. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  20527. },
  20528. setInterpolation: function ( interpolation ) {
  20529. var factoryMethod;
  20530. switch ( interpolation ) {
  20531. case InterpolateDiscrete:
  20532. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20533. break;
  20534. case InterpolateLinear:
  20535. factoryMethod = this.InterpolantFactoryMethodLinear;
  20536. break;
  20537. case InterpolateSmooth:
  20538. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20539. break;
  20540. }
  20541. if ( factoryMethod === undefined ) {
  20542. var message = "unsupported interpolation for " +
  20543. this.ValueTypeName + " keyframe track named " + this.name;
  20544. if ( this.createInterpolant === undefined ) {
  20545. // fall back to default, unless the default itself is messed up
  20546. if ( interpolation !== this.DefaultInterpolation ) {
  20547. this.setInterpolation( this.DefaultInterpolation );
  20548. } else {
  20549. throw new Error( message ); // fatal, in this case
  20550. }
  20551. }
  20552. console.warn( 'THREE.KeyframeTrack:', message );
  20553. return;
  20554. }
  20555. this.createInterpolant = factoryMethod;
  20556. },
  20557. getInterpolation: function () {
  20558. switch ( this.createInterpolant ) {
  20559. case this.InterpolantFactoryMethodDiscrete:
  20560. return InterpolateDiscrete;
  20561. case this.InterpolantFactoryMethodLinear:
  20562. return InterpolateLinear;
  20563. case this.InterpolantFactoryMethodSmooth:
  20564. return InterpolateSmooth;
  20565. }
  20566. },
  20567. getValueSize: function () {
  20568. return this.values.length / this.times.length;
  20569. },
  20570. // move all keyframes either forwards or backwards in time
  20571. shift: function ( timeOffset ) {
  20572. if ( timeOffset !== 0.0 ) {
  20573. var times = this.times;
  20574. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  20575. times[ i ] += timeOffset;
  20576. }
  20577. }
  20578. return this;
  20579. },
  20580. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  20581. scale: function ( timeScale ) {
  20582. if ( timeScale !== 1.0 ) {
  20583. var times = this.times;
  20584. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  20585. times[ i ] *= timeScale;
  20586. }
  20587. }
  20588. return this;
  20589. },
  20590. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  20591. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  20592. trim: function ( startTime, endTime ) {
  20593. var times = this.times,
  20594. nKeys = times.length,
  20595. from = 0,
  20596. to = nKeys - 1;
  20597. while ( from !== nKeys && times[ from ] < startTime ) {
  20598. ++ from;
  20599. }
  20600. while ( to !== - 1 && times[ to ] > endTime ) {
  20601. -- to;
  20602. }
  20603. ++ to; // inclusive -> exclusive bound
  20604. if ( from !== 0 || to !== nKeys ) {
  20605. // empty tracks are forbidden, so keep at least one keyframe
  20606. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  20607. var stride = this.getValueSize();
  20608. this.times = AnimationUtils.arraySlice( times, from, to );
  20609. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  20610. }
  20611. return this;
  20612. },
  20613. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  20614. validate: function () {
  20615. var valid = true;
  20616. var valueSize = this.getValueSize();
  20617. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  20618. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  20619. valid = false;
  20620. }
  20621. var times = this.times,
  20622. values = this.values,
  20623. nKeys = times.length;
  20624. if ( nKeys === 0 ) {
  20625. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  20626. valid = false;
  20627. }
  20628. var prevTime = null;
  20629. for ( var i = 0; i !== nKeys; i ++ ) {
  20630. var currTime = times[ i ];
  20631. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  20632. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  20633. valid = false;
  20634. break;
  20635. }
  20636. if ( prevTime !== null && prevTime > currTime ) {
  20637. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  20638. valid = false;
  20639. break;
  20640. }
  20641. prevTime = currTime;
  20642. }
  20643. if ( values !== undefined ) {
  20644. if ( AnimationUtils.isTypedArray( values ) ) {
  20645. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  20646. var value = values[ i ];
  20647. if ( isNaN( value ) ) {
  20648. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  20649. valid = false;
  20650. break;
  20651. }
  20652. }
  20653. }
  20654. }
  20655. return valid;
  20656. },
  20657. // removes equivalent sequential keys as common in morph target sequences
  20658. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20659. optimize: function () {
  20660. var times = this.times,
  20661. values = this.values,
  20662. stride = this.getValueSize(),
  20663. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20664. writeIndex = 1,
  20665. lastIndex = times.length - 1;
  20666. for ( var i = 1; i < lastIndex; ++ i ) {
  20667. var keep = false;
  20668. var time = times[ i ];
  20669. var timeNext = times[ i + 1 ];
  20670. // remove adjacent keyframes scheduled at the same time
  20671. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  20672. if ( ! smoothInterpolation ) {
  20673. // remove unnecessary keyframes same as their neighbors
  20674. var offset = i * stride,
  20675. offsetP = offset - stride,
  20676. offsetN = offset + stride;
  20677. for ( var j = 0; j !== stride; ++ j ) {
  20678. var value = values[ offset + j ];
  20679. if ( value !== values[ offsetP + j ] ||
  20680. value !== values[ offsetN + j ] ) {
  20681. keep = true;
  20682. break;
  20683. }
  20684. }
  20685. } else {
  20686. keep = true;
  20687. }
  20688. }
  20689. // in-place compaction
  20690. if ( keep ) {
  20691. if ( i !== writeIndex ) {
  20692. times[ writeIndex ] = times[ i ];
  20693. var readOffset = i * stride,
  20694. writeOffset = writeIndex * stride;
  20695. for ( var j = 0; j !== stride; ++ j ) {
  20696. values[ writeOffset + j ] = values[ readOffset + j ];
  20697. }
  20698. }
  20699. ++ writeIndex;
  20700. }
  20701. }
  20702. // flush last keyframe (compaction looks ahead)
  20703. if ( lastIndex > 0 ) {
  20704. times[ writeIndex ] = times[ lastIndex ];
  20705. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  20706. values[ writeOffset + j ] = values[ readOffset + j ];
  20707. }
  20708. ++ writeIndex;
  20709. }
  20710. if ( writeIndex !== times.length ) {
  20711. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  20712. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  20713. }
  20714. return this;
  20715. }
  20716. } );
  20717. /**
  20718. *
  20719. * A Track of vectored keyframe values.
  20720. *
  20721. *
  20722. * @author Ben Houston / http://clara.io/
  20723. * @author David Sarno / http://lighthaus.us/
  20724. * @author tschw
  20725. */
  20726. function VectorKeyframeTrack( name, times, values, interpolation ) {
  20727. KeyframeTrack.call( this, name, times, values, interpolation );
  20728. }
  20729. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20730. constructor: VectorKeyframeTrack,
  20731. ValueTypeName: 'vector'
  20732. // ValueBufferType is inherited
  20733. // DefaultInterpolation is inherited
  20734. } );
  20735. /**
  20736. *
  20737. * Reusable set of Tracks that represent an animation.
  20738. *
  20739. * @author Ben Houston / http://clara.io/
  20740. * @author David Sarno / http://lighthaus.us/
  20741. */
  20742. function AnimationClip( name, duration, tracks ) {
  20743. this.name = name;
  20744. this.tracks = tracks;
  20745. this.duration = ( duration !== undefined ) ? duration : - 1;
  20746. this.uuid = _Math.generateUUID();
  20747. // this means it should figure out its duration by scanning the tracks
  20748. if ( this.duration < 0 ) {
  20749. this.resetDuration();
  20750. }
  20751. this.optimize();
  20752. }
  20753. Object.assign( AnimationClip, {
  20754. parse: function ( json ) {
  20755. var tracks = [],
  20756. jsonTracks = json.tracks,
  20757. frameTime = 1.0 / ( json.fps || 1.0 );
  20758. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  20759. tracks.push( KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  20760. }
  20761. return new AnimationClip( json.name, json.duration, tracks );
  20762. },
  20763. toJSON: function ( clip ) {
  20764. var tracks = [],
  20765. clipTracks = clip.tracks;
  20766. var json = {
  20767. 'name': clip.name,
  20768. 'duration': clip.duration,
  20769. 'tracks': tracks
  20770. };
  20771. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  20772. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  20773. }
  20774. return json;
  20775. },
  20776. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  20777. var numMorphTargets = morphTargetSequence.length;
  20778. var tracks = [];
  20779. for ( var i = 0; i < numMorphTargets; i ++ ) {
  20780. var times = [];
  20781. var values = [];
  20782. times.push(
  20783. ( i + numMorphTargets - 1 ) % numMorphTargets,
  20784. i,
  20785. ( i + 1 ) % numMorphTargets );
  20786. values.push( 0, 1, 0 );
  20787. var order = AnimationUtils.getKeyframeOrder( times );
  20788. times = AnimationUtils.sortedArray( times, 1, order );
  20789. values = AnimationUtils.sortedArray( values, 1, order );
  20790. // if there is a key at the first frame, duplicate it as the
  20791. // last frame as well for perfect loop.
  20792. if ( ! noLoop && times[ 0 ] === 0 ) {
  20793. times.push( numMorphTargets );
  20794. values.push( values[ 0 ] );
  20795. }
  20796. tracks.push(
  20797. new NumberKeyframeTrack(
  20798. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  20799. times, values
  20800. ).scale( 1.0 / fps ) );
  20801. }
  20802. return new AnimationClip( name, - 1, tracks );
  20803. },
  20804. findByName: function ( objectOrClipArray, name ) {
  20805. var clipArray = objectOrClipArray;
  20806. if ( ! Array.isArray( objectOrClipArray ) ) {
  20807. var o = objectOrClipArray;
  20808. clipArray = o.geometry && o.geometry.animations || o.animations;
  20809. }
  20810. for ( var i = 0; i < clipArray.length; i ++ ) {
  20811. if ( clipArray[ i ].name === name ) {
  20812. return clipArray[ i ];
  20813. }
  20814. }
  20815. return null;
  20816. },
  20817. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  20818. var animationToMorphTargets = {};
  20819. // tested with https://regex101.com/ on trick sequences
  20820. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  20821. var pattern = /^([\w-]*?)([\d]+)$/;
  20822. // sort morph target names into animation groups based
  20823. // patterns like Walk_001, Walk_002, Run_001, Run_002
  20824. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  20825. var morphTarget = morphTargets[ i ];
  20826. var parts = morphTarget.name.match( pattern );
  20827. if ( parts && parts.length > 1 ) {
  20828. var name = parts[ 1 ];
  20829. var animationMorphTargets = animationToMorphTargets[ name ];
  20830. if ( ! animationMorphTargets ) {
  20831. animationToMorphTargets[ name ] = animationMorphTargets = [];
  20832. }
  20833. animationMorphTargets.push( morphTarget );
  20834. }
  20835. }
  20836. var clips = [];
  20837. for ( var name in animationToMorphTargets ) {
  20838. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  20839. }
  20840. return clips;
  20841. },
  20842. // parse the animation.hierarchy format
  20843. parseAnimation: function ( animation, bones ) {
  20844. if ( ! animation ) {
  20845. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  20846. return null;
  20847. }
  20848. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  20849. // only return track if there are actually keys.
  20850. if ( animationKeys.length !== 0 ) {
  20851. var times = [];
  20852. var values = [];
  20853. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  20854. // empty keys are filtered out, so check again
  20855. if ( times.length !== 0 ) {
  20856. destTracks.push( new trackType( trackName, times, values ) );
  20857. }
  20858. }
  20859. };
  20860. var tracks = [];
  20861. var clipName = animation.name || 'default';
  20862. // automatic length determination in AnimationClip.
  20863. var duration = animation.length || - 1;
  20864. var fps = animation.fps || 30;
  20865. var hierarchyTracks = animation.hierarchy || [];
  20866. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  20867. var animationKeys = hierarchyTracks[ h ].keys;
  20868. // skip empty tracks
  20869. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  20870. // process morph targets
  20871. if ( animationKeys[ 0 ].morphTargets ) {
  20872. // figure out all morph targets used in this track
  20873. var morphTargetNames = {};
  20874. for ( var k = 0; k < animationKeys.length; k ++ ) {
  20875. if ( animationKeys[ k ].morphTargets ) {
  20876. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  20877. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  20878. }
  20879. }
  20880. }
  20881. // create a track for each morph target with all zero
  20882. // morphTargetInfluences except for the keys in which
  20883. // the morphTarget is named.
  20884. for ( var morphTargetName in morphTargetNames ) {
  20885. var times = [];
  20886. var values = [];
  20887. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  20888. var animationKey = animationKeys[ k ];
  20889. times.push( animationKey.time );
  20890. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  20891. }
  20892. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  20893. }
  20894. duration = morphTargetNames.length * ( fps || 1.0 );
  20895. } else {
  20896. // ...assume skeletal animation
  20897. var boneName = '.bones[' + bones[ h ].name + ']';
  20898. addNonemptyTrack(
  20899. VectorKeyframeTrack, boneName + '.position',
  20900. animationKeys, 'pos', tracks );
  20901. addNonemptyTrack(
  20902. QuaternionKeyframeTrack, boneName + '.quaternion',
  20903. animationKeys, 'rot', tracks );
  20904. addNonemptyTrack(
  20905. VectorKeyframeTrack, boneName + '.scale',
  20906. animationKeys, 'scl', tracks );
  20907. }
  20908. }
  20909. if ( tracks.length === 0 ) {
  20910. return null;
  20911. }
  20912. var clip = new AnimationClip( clipName, duration, tracks );
  20913. return clip;
  20914. }
  20915. } );
  20916. Object.assign( AnimationClip.prototype, {
  20917. resetDuration: function () {
  20918. var tracks = this.tracks, duration = 0;
  20919. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  20920. var track = this.tracks[ i ];
  20921. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  20922. }
  20923. this.duration = duration;
  20924. },
  20925. trim: function () {
  20926. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20927. this.tracks[ i ].trim( 0, this.duration );
  20928. }
  20929. return this;
  20930. },
  20931. optimize: function () {
  20932. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20933. this.tracks[ i ].optimize();
  20934. }
  20935. return this;
  20936. }
  20937. } );
  20938. /**
  20939. * @author mrdoob / http://mrdoob.com/
  20940. */
  20941. function MaterialLoader( manager ) {
  20942. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20943. this.textures = {};
  20944. }
  20945. Object.assign( MaterialLoader.prototype, {
  20946. load: function ( url, onLoad, onProgress, onError ) {
  20947. var scope = this;
  20948. var loader = new FileLoader( scope.manager );
  20949. loader.load( url, function ( text ) {
  20950. onLoad( scope.parse( JSON.parse( text ) ) );
  20951. }, onProgress, onError );
  20952. },
  20953. setTextures: function ( value ) {
  20954. this.textures = value;
  20955. },
  20956. parse: function ( json ) {
  20957. var textures = this.textures;
  20958. function getTexture( name ) {
  20959. if ( textures[ name ] === undefined ) {
  20960. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  20961. }
  20962. return textures[ name ];
  20963. }
  20964. var material = new Materials[ json.type ]();
  20965. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  20966. if ( json.name !== undefined ) material.name = json.name;
  20967. if ( json.color !== undefined ) material.color.setHex( json.color );
  20968. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  20969. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  20970. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  20971. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  20972. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  20973. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  20974. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  20975. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  20976. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  20977. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  20978. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  20979. if ( json.fog !== undefined ) material.fog = json.fog;
  20980. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  20981. if ( json.blending !== undefined ) material.blending = json.blending;
  20982. if ( json.side !== undefined ) material.side = json.side;
  20983. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  20984. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  20985. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  20986. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  20987. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  20988. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  20989. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  20990. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  20991. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  20992. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  20993. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  20994. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  20995. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  20996. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  20997. if ( json.scale !== undefined ) material.scale = json.scale;
  20998. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  20999. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  21000. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  21001. if ( json.visible !== undefined ) material.visible = json.visible;
  21002. if ( json.userData !== undefined ) material.userData = json.userData;
  21003. // Deprecated
  21004. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  21005. // for PointsMaterial
  21006. if ( json.size !== undefined ) material.size = json.size;
  21007. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  21008. // maps
  21009. if ( json.map !== undefined ) material.map = getTexture( json.map );
  21010. if ( json.alphaMap !== undefined ) {
  21011. material.alphaMap = getTexture( json.alphaMap );
  21012. material.transparent = true;
  21013. }
  21014. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  21015. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  21016. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  21017. if ( json.normalScale !== undefined ) {
  21018. var normalScale = json.normalScale;
  21019. if ( Array.isArray( normalScale ) === false ) {
  21020. // Blender exporter used to export a scalar. See #7459
  21021. normalScale = [ normalScale, normalScale ];
  21022. }
  21023. material.normalScale = new Vector2().fromArray( normalScale );
  21024. }
  21025. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  21026. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  21027. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  21028. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  21029. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  21030. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  21031. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  21032. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  21033. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  21034. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  21035. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  21036. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  21037. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  21038. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  21039. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  21040. return material;
  21041. }
  21042. } );
  21043. /**
  21044. * @author mrdoob / http://mrdoob.com/
  21045. */
  21046. function BufferGeometryLoader( manager ) {
  21047. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21048. }
  21049. Object.assign( BufferGeometryLoader.prototype, {
  21050. load: function ( url, onLoad, onProgress, onError ) {
  21051. var scope = this;
  21052. var loader = new FileLoader( scope.manager );
  21053. loader.load( url, function ( text ) {
  21054. onLoad( scope.parse( JSON.parse( text ) ) );
  21055. }, onProgress, onError );
  21056. },
  21057. parse: function ( json ) {
  21058. var geometry = new BufferGeometry();
  21059. var index = json.data.index;
  21060. if ( index !== undefined ) {
  21061. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  21062. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  21063. }
  21064. var attributes = json.data.attributes;
  21065. for ( var key in attributes ) {
  21066. var attribute = attributes[ key ];
  21067. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  21068. geometry.addAttribute( key, new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
  21069. }
  21070. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  21071. if ( groups !== undefined ) {
  21072. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  21073. var group = groups[ i ];
  21074. geometry.addGroup( group.start, group.count, group.materialIndex );
  21075. }
  21076. }
  21077. var boundingSphere = json.data.boundingSphere;
  21078. if ( boundingSphere !== undefined ) {
  21079. var center = new Vector3();
  21080. if ( boundingSphere.center !== undefined ) {
  21081. center.fromArray( boundingSphere.center );
  21082. }
  21083. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  21084. }
  21085. return geometry;
  21086. }
  21087. } );
  21088. var TYPED_ARRAYS = {
  21089. Int8Array: Int8Array,
  21090. Uint8Array: Uint8Array,
  21091. // Workaround for IE11 pre KB2929437. See #11440
  21092. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  21093. Int16Array: Int16Array,
  21094. Uint16Array: Uint16Array,
  21095. Int32Array: Int32Array,
  21096. Uint32Array: Uint32Array,
  21097. Float32Array: Float32Array,
  21098. Float64Array: Float64Array
  21099. };
  21100. /**
  21101. * @author alteredq / http://alteredqualia.com/
  21102. */
  21103. function Loader() {
  21104. this.onLoadStart = function () {};
  21105. this.onLoadProgress = function () {};
  21106. this.onLoadComplete = function () {};
  21107. }
  21108. Loader.Handlers = {
  21109. handlers: [],
  21110. add: function ( regex, loader ) {
  21111. this.handlers.push( regex, loader );
  21112. },
  21113. get: function ( file ) {
  21114. var handlers = this.handlers;
  21115. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  21116. var regex = handlers[ i ];
  21117. var loader = handlers[ i + 1 ];
  21118. if ( regex.test( file ) ) {
  21119. return loader;
  21120. }
  21121. }
  21122. return null;
  21123. }
  21124. };
  21125. Object.assign( Loader.prototype, {
  21126. crossOrigin: undefined,
  21127. initMaterials: function ( materials, texturePath, crossOrigin ) {
  21128. var array = [];
  21129. for ( var i = 0; i < materials.length; ++ i ) {
  21130. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  21131. }
  21132. return array;
  21133. },
  21134. createMaterial: ( function () {
  21135. var BlendingMode = {
  21136. NoBlending: NoBlending,
  21137. NormalBlending: NormalBlending,
  21138. AdditiveBlending: AdditiveBlending,
  21139. SubtractiveBlending: SubtractiveBlending,
  21140. MultiplyBlending: MultiplyBlending,
  21141. CustomBlending: CustomBlending
  21142. };
  21143. var color = new Color();
  21144. var textureLoader = new TextureLoader();
  21145. var materialLoader = new MaterialLoader();
  21146. return function createMaterial( m, texturePath, crossOrigin ) {
  21147. // convert from old material format
  21148. var textures = {};
  21149. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  21150. var fullPath = texturePath + path;
  21151. var loader = Loader.Handlers.get( fullPath );
  21152. var texture;
  21153. if ( loader !== null ) {
  21154. texture = loader.load( fullPath );
  21155. } else {
  21156. textureLoader.setCrossOrigin( crossOrigin );
  21157. texture = textureLoader.load( fullPath );
  21158. }
  21159. if ( repeat !== undefined ) {
  21160. texture.repeat.fromArray( repeat );
  21161. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  21162. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  21163. }
  21164. if ( offset !== undefined ) {
  21165. texture.offset.fromArray( offset );
  21166. }
  21167. if ( wrap !== undefined ) {
  21168. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  21169. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  21170. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  21171. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  21172. }
  21173. if ( anisotropy !== undefined ) {
  21174. texture.anisotropy = anisotropy;
  21175. }
  21176. var uuid = _Math.generateUUID();
  21177. textures[ uuid ] = texture;
  21178. return uuid;
  21179. }
  21180. //
  21181. var json = {
  21182. uuid: _Math.generateUUID(),
  21183. type: 'MeshLambertMaterial'
  21184. };
  21185. for ( var name in m ) {
  21186. var value = m[ name ];
  21187. switch ( name ) {
  21188. case 'DbgColor':
  21189. case 'DbgIndex':
  21190. case 'opticalDensity':
  21191. case 'illumination':
  21192. break;
  21193. case 'DbgName':
  21194. json.name = value;
  21195. break;
  21196. case 'blending':
  21197. json.blending = BlendingMode[ value ];
  21198. break;
  21199. case 'colorAmbient':
  21200. case 'mapAmbient':
  21201. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  21202. break;
  21203. case 'colorDiffuse':
  21204. json.color = color.fromArray( value ).getHex();
  21205. break;
  21206. case 'colorSpecular':
  21207. json.specular = color.fromArray( value ).getHex();
  21208. break;
  21209. case 'colorEmissive':
  21210. json.emissive = color.fromArray( value ).getHex();
  21211. break;
  21212. case 'specularCoef':
  21213. json.shininess = value;
  21214. break;
  21215. case 'shading':
  21216. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  21217. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  21218. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  21219. break;
  21220. case 'mapDiffuse':
  21221. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  21222. break;
  21223. case 'mapDiffuseRepeat':
  21224. case 'mapDiffuseOffset':
  21225. case 'mapDiffuseWrap':
  21226. case 'mapDiffuseAnisotropy':
  21227. break;
  21228. case 'mapEmissive':
  21229. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  21230. break;
  21231. case 'mapEmissiveRepeat':
  21232. case 'mapEmissiveOffset':
  21233. case 'mapEmissiveWrap':
  21234. case 'mapEmissiveAnisotropy':
  21235. break;
  21236. case 'mapLight':
  21237. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  21238. break;
  21239. case 'mapLightRepeat':
  21240. case 'mapLightOffset':
  21241. case 'mapLightWrap':
  21242. case 'mapLightAnisotropy':
  21243. break;
  21244. case 'mapAO':
  21245. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  21246. break;
  21247. case 'mapAORepeat':
  21248. case 'mapAOOffset':
  21249. case 'mapAOWrap':
  21250. case 'mapAOAnisotropy':
  21251. break;
  21252. case 'mapBump':
  21253. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  21254. break;
  21255. case 'mapBumpScale':
  21256. json.bumpScale = value;
  21257. break;
  21258. case 'mapBumpRepeat':
  21259. case 'mapBumpOffset':
  21260. case 'mapBumpWrap':
  21261. case 'mapBumpAnisotropy':
  21262. break;
  21263. case 'mapNormal':
  21264. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  21265. break;
  21266. case 'mapNormalFactor':
  21267. json.normalScale = [ value, value ];
  21268. break;
  21269. case 'mapNormalRepeat':
  21270. case 'mapNormalOffset':
  21271. case 'mapNormalWrap':
  21272. case 'mapNormalAnisotropy':
  21273. break;
  21274. case 'mapSpecular':
  21275. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  21276. break;
  21277. case 'mapSpecularRepeat':
  21278. case 'mapSpecularOffset':
  21279. case 'mapSpecularWrap':
  21280. case 'mapSpecularAnisotropy':
  21281. break;
  21282. case 'mapMetalness':
  21283. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  21284. break;
  21285. case 'mapMetalnessRepeat':
  21286. case 'mapMetalnessOffset':
  21287. case 'mapMetalnessWrap':
  21288. case 'mapMetalnessAnisotropy':
  21289. break;
  21290. case 'mapRoughness':
  21291. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  21292. break;
  21293. case 'mapRoughnessRepeat':
  21294. case 'mapRoughnessOffset':
  21295. case 'mapRoughnessWrap':
  21296. case 'mapRoughnessAnisotropy':
  21297. break;
  21298. case 'mapAlpha':
  21299. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  21300. break;
  21301. case 'mapAlphaRepeat':
  21302. case 'mapAlphaOffset':
  21303. case 'mapAlphaWrap':
  21304. case 'mapAlphaAnisotropy':
  21305. break;
  21306. case 'flipSided':
  21307. json.side = BackSide;
  21308. break;
  21309. case 'doubleSided':
  21310. json.side = DoubleSide;
  21311. break;
  21312. case 'transparency':
  21313. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  21314. json.opacity = value;
  21315. break;
  21316. case 'depthTest':
  21317. case 'depthWrite':
  21318. case 'colorWrite':
  21319. case 'opacity':
  21320. case 'reflectivity':
  21321. case 'transparent':
  21322. case 'visible':
  21323. case 'wireframe':
  21324. json[ name ] = value;
  21325. break;
  21326. case 'vertexColors':
  21327. if ( value === true ) json.vertexColors = VertexColors;
  21328. if ( value === 'face' ) json.vertexColors = FaceColors;
  21329. break;
  21330. default:
  21331. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  21332. break;
  21333. }
  21334. }
  21335. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  21336. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  21337. if ( json.opacity < 1 ) json.transparent = true;
  21338. materialLoader.setTextures( textures );
  21339. return materialLoader.parse( json );
  21340. };
  21341. } )()
  21342. } );
  21343. /**
  21344. * @author Don McCurdy / https://www.donmccurdy.com
  21345. */
  21346. var LoaderUtils = {
  21347. decodeText: function ( array ) {
  21348. if ( typeof TextDecoder !== 'undefined' ) {
  21349. return new TextDecoder().decode( array );
  21350. }
  21351. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  21352. // throws a "maximum call stack size exceeded" error for large arrays.
  21353. var s = '';
  21354. for ( var i = 0, il = array.length; i < il; i ++ ) {
  21355. // Implicitly assumes little-endian.
  21356. s += String.fromCharCode( array[ i ] );
  21357. }
  21358. // Merges multi-byte utf-8 characters.
  21359. return decodeURIComponent( escape( s ) );
  21360. },
  21361. extractUrlBase: function ( url ) {
  21362. var parts = url.split( '/' );
  21363. if ( parts.length === 1 ) return './';
  21364. parts.pop();
  21365. return parts.join( '/' ) + '/';
  21366. }
  21367. };
  21368. /**
  21369. * @author mrdoob / http://mrdoob.com/
  21370. * @author alteredq / http://alteredqualia.com/
  21371. */
  21372. function JSONLoader( manager ) {
  21373. if ( typeof manager === 'boolean' ) {
  21374. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  21375. manager = undefined;
  21376. }
  21377. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21378. this.withCredentials = false;
  21379. }
  21380. Object.assign( JSONLoader.prototype, {
  21381. load: function ( url, onLoad, onProgress, onError ) {
  21382. var scope = this;
  21383. var texturePath = this.texturePath && ( typeof this.texturePath === 'string' ) ? this.texturePath : LoaderUtils.extractUrlBase( url );
  21384. var loader = new FileLoader( this.manager );
  21385. loader.setWithCredentials( this.withCredentials );
  21386. loader.load( url, function ( text ) {
  21387. var json = JSON.parse( text );
  21388. var metadata = json.metadata;
  21389. if ( metadata !== undefined ) {
  21390. var type = metadata.type;
  21391. if ( type !== undefined ) {
  21392. if ( type.toLowerCase() === 'object' ) {
  21393. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  21394. return;
  21395. }
  21396. if ( type.toLowerCase() === 'scene' ) {
  21397. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  21398. return;
  21399. }
  21400. }
  21401. }
  21402. var object = scope.parse( json, texturePath );
  21403. onLoad( object.geometry, object.materials );
  21404. }, onProgress, onError );
  21405. },
  21406. setTexturePath: function ( value ) {
  21407. this.texturePath = value;
  21408. },
  21409. parse: ( function () {
  21410. function parseModel( json, geometry ) {
  21411. function isBitSet( value, position ) {
  21412. return value & ( 1 << position );
  21413. }
  21414. var i, j, fi,
  21415. offset, zLength,
  21416. colorIndex, normalIndex, uvIndex, materialIndex,
  21417. type,
  21418. isQuad,
  21419. hasMaterial,
  21420. hasFaceVertexUv,
  21421. hasFaceNormal, hasFaceVertexNormal,
  21422. hasFaceColor, hasFaceVertexColor,
  21423. vertex, face, faceA, faceB, hex, normal,
  21424. uvLayer, uv, u, v,
  21425. faces = json.faces,
  21426. vertices = json.vertices,
  21427. normals = json.normals,
  21428. colors = json.colors,
  21429. scale = json.scale,
  21430. nUvLayers = 0;
  21431. if ( json.uvs !== undefined ) {
  21432. // disregard empty arrays
  21433. for ( i = 0; i < json.uvs.length; i ++ ) {
  21434. if ( json.uvs[ i ].length ) nUvLayers ++;
  21435. }
  21436. for ( i = 0; i < nUvLayers; i ++ ) {
  21437. geometry.faceVertexUvs[ i ] = [];
  21438. }
  21439. }
  21440. offset = 0;
  21441. zLength = vertices.length;
  21442. while ( offset < zLength ) {
  21443. vertex = new Vector3();
  21444. vertex.x = vertices[ offset ++ ] * scale;
  21445. vertex.y = vertices[ offset ++ ] * scale;
  21446. vertex.z = vertices[ offset ++ ] * scale;
  21447. geometry.vertices.push( vertex );
  21448. }
  21449. offset = 0;
  21450. zLength = faces.length;
  21451. while ( offset < zLength ) {
  21452. type = faces[ offset ++ ];
  21453. isQuad = isBitSet( type, 0 );
  21454. hasMaterial = isBitSet( type, 1 );
  21455. hasFaceVertexUv = isBitSet( type, 3 );
  21456. hasFaceNormal = isBitSet( type, 4 );
  21457. hasFaceVertexNormal = isBitSet( type, 5 );
  21458. hasFaceColor = isBitSet( type, 6 );
  21459. hasFaceVertexColor = isBitSet( type, 7 );
  21460. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  21461. if ( isQuad ) {
  21462. faceA = new Face3();
  21463. faceA.a = faces[ offset ];
  21464. faceA.b = faces[ offset + 1 ];
  21465. faceA.c = faces[ offset + 3 ];
  21466. faceB = new Face3();
  21467. faceB.a = faces[ offset + 1 ];
  21468. faceB.b = faces[ offset + 2 ];
  21469. faceB.c = faces[ offset + 3 ];
  21470. offset += 4;
  21471. if ( hasMaterial ) {
  21472. materialIndex = faces[ offset ++ ];
  21473. faceA.materialIndex = materialIndex;
  21474. faceB.materialIndex = materialIndex;
  21475. }
  21476. // to get face <=> uv index correspondence
  21477. fi = geometry.faces.length;
  21478. if ( hasFaceVertexUv ) {
  21479. for ( i = 0; i < nUvLayers; i ++ ) {
  21480. uvLayer = json.uvs[ i ];
  21481. geometry.faceVertexUvs[ i ][ fi ] = [];
  21482. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  21483. for ( j = 0; j < 4; j ++ ) {
  21484. uvIndex = faces[ offset ++ ];
  21485. u = uvLayer[ uvIndex * 2 ];
  21486. v = uvLayer[ uvIndex * 2 + 1 ];
  21487. uv = new Vector2( u, v );
  21488. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  21489. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  21490. }
  21491. }
  21492. }
  21493. if ( hasFaceNormal ) {
  21494. normalIndex = faces[ offset ++ ] * 3;
  21495. faceA.normal.set(
  21496. normals[ normalIndex ++ ],
  21497. normals[ normalIndex ++ ],
  21498. normals[ normalIndex ]
  21499. );
  21500. faceB.normal.copy( faceA.normal );
  21501. }
  21502. if ( hasFaceVertexNormal ) {
  21503. for ( i = 0; i < 4; i ++ ) {
  21504. normalIndex = faces[ offset ++ ] * 3;
  21505. normal = new Vector3(
  21506. normals[ normalIndex ++ ],
  21507. normals[ normalIndex ++ ],
  21508. normals[ normalIndex ]
  21509. );
  21510. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  21511. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  21512. }
  21513. }
  21514. if ( hasFaceColor ) {
  21515. colorIndex = faces[ offset ++ ];
  21516. hex = colors[ colorIndex ];
  21517. faceA.color.setHex( hex );
  21518. faceB.color.setHex( hex );
  21519. }
  21520. if ( hasFaceVertexColor ) {
  21521. for ( i = 0; i < 4; i ++ ) {
  21522. colorIndex = faces[ offset ++ ];
  21523. hex = colors[ colorIndex ];
  21524. if ( i !== 2 ) faceA.vertexColors.push( new Color( hex ) );
  21525. if ( i !== 0 ) faceB.vertexColors.push( new Color( hex ) );
  21526. }
  21527. }
  21528. geometry.faces.push( faceA );
  21529. geometry.faces.push( faceB );
  21530. } else {
  21531. face = new Face3();
  21532. face.a = faces[ offset ++ ];
  21533. face.b = faces[ offset ++ ];
  21534. face.c = faces[ offset ++ ];
  21535. if ( hasMaterial ) {
  21536. materialIndex = faces[ offset ++ ];
  21537. face.materialIndex = materialIndex;
  21538. }
  21539. // to get face <=> uv index correspondence
  21540. fi = geometry.faces.length;
  21541. if ( hasFaceVertexUv ) {
  21542. for ( i = 0; i < nUvLayers; i ++ ) {
  21543. uvLayer = json.uvs[ i ];
  21544. geometry.faceVertexUvs[ i ][ fi ] = [];
  21545. for ( j = 0; j < 3; j ++ ) {
  21546. uvIndex = faces[ offset ++ ];
  21547. u = uvLayer[ uvIndex * 2 ];
  21548. v = uvLayer[ uvIndex * 2 + 1 ];
  21549. uv = new Vector2( u, v );
  21550. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  21551. }
  21552. }
  21553. }
  21554. if ( hasFaceNormal ) {
  21555. normalIndex = faces[ offset ++ ] * 3;
  21556. face.normal.set(
  21557. normals[ normalIndex ++ ],
  21558. normals[ normalIndex ++ ],
  21559. normals[ normalIndex ]
  21560. );
  21561. }
  21562. if ( hasFaceVertexNormal ) {
  21563. for ( i = 0; i < 3; i ++ ) {
  21564. normalIndex = faces[ offset ++ ] * 3;
  21565. normal = new Vector3(
  21566. normals[ normalIndex ++ ],
  21567. normals[ normalIndex ++ ],
  21568. normals[ normalIndex ]
  21569. );
  21570. face.vertexNormals.push( normal );
  21571. }
  21572. }
  21573. if ( hasFaceColor ) {
  21574. colorIndex = faces[ offset ++ ];
  21575. face.color.setHex( colors[ colorIndex ] );
  21576. }
  21577. if ( hasFaceVertexColor ) {
  21578. for ( i = 0; i < 3; i ++ ) {
  21579. colorIndex = faces[ offset ++ ];
  21580. face.vertexColors.push( new Color( colors[ colorIndex ] ) );
  21581. }
  21582. }
  21583. geometry.faces.push( face );
  21584. }
  21585. }
  21586. }
  21587. function parseSkin( json, geometry ) {
  21588. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  21589. if ( json.skinWeights ) {
  21590. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  21591. var x = json.skinWeights[ i ];
  21592. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  21593. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  21594. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  21595. geometry.skinWeights.push( new Vector4( x, y, z, w ) );
  21596. }
  21597. }
  21598. if ( json.skinIndices ) {
  21599. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  21600. var a = json.skinIndices[ i ];
  21601. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  21602. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  21603. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  21604. geometry.skinIndices.push( new Vector4( a, b, c, d ) );
  21605. }
  21606. }
  21607. geometry.bones = json.bones;
  21608. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  21609. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  21610. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  21611. }
  21612. }
  21613. function parseMorphing( json, geometry ) {
  21614. var scale = json.scale;
  21615. if ( json.morphTargets !== undefined ) {
  21616. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  21617. geometry.morphTargets[ i ] = {};
  21618. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  21619. geometry.morphTargets[ i ].vertices = [];
  21620. var dstVertices = geometry.morphTargets[ i ].vertices;
  21621. var srcVertices = json.morphTargets[ i ].vertices;
  21622. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  21623. var vertex = new Vector3();
  21624. vertex.x = srcVertices[ v ] * scale;
  21625. vertex.y = srcVertices[ v + 1 ] * scale;
  21626. vertex.z = srcVertices[ v + 2 ] * scale;
  21627. dstVertices.push( vertex );
  21628. }
  21629. }
  21630. }
  21631. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  21632. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  21633. var faces = geometry.faces;
  21634. var morphColors = json.morphColors[ 0 ].colors;
  21635. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21636. faces[ i ].color.fromArray( morphColors, i * 3 );
  21637. }
  21638. }
  21639. }
  21640. function parseAnimations( json, geometry ) {
  21641. var outputAnimations = [];
  21642. // parse old style Bone/Hierarchy animations
  21643. var animations = [];
  21644. if ( json.animation !== undefined ) {
  21645. animations.push( json.animation );
  21646. }
  21647. if ( json.animations !== undefined ) {
  21648. if ( json.animations.length ) {
  21649. animations = animations.concat( json.animations );
  21650. } else {
  21651. animations.push( json.animations );
  21652. }
  21653. }
  21654. for ( var i = 0; i < animations.length; i ++ ) {
  21655. var clip = AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  21656. if ( clip ) outputAnimations.push( clip );
  21657. }
  21658. // parse implicit morph animations
  21659. if ( geometry.morphTargets ) {
  21660. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  21661. var morphAnimationClips = AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  21662. outputAnimations = outputAnimations.concat( morphAnimationClips );
  21663. }
  21664. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  21665. }
  21666. return function parse( json, texturePath ) {
  21667. if ( json.data !== undefined ) {
  21668. // Geometry 4.0 spec
  21669. json = json.data;
  21670. }
  21671. if ( json.scale !== undefined ) {
  21672. json.scale = 1.0 / json.scale;
  21673. } else {
  21674. json.scale = 1.0;
  21675. }
  21676. var geometry = new Geometry();
  21677. parseModel( json, geometry );
  21678. parseSkin( json, geometry );
  21679. parseMorphing( json, geometry );
  21680. parseAnimations( json, geometry );
  21681. geometry.computeFaceNormals();
  21682. geometry.computeBoundingSphere();
  21683. if ( json.materials === undefined || json.materials.length === 0 ) {
  21684. return { geometry: geometry };
  21685. } else {
  21686. var materials = Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  21687. return { geometry: geometry, materials: materials };
  21688. }
  21689. };
  21690. } )()
  21691. } );
  21692. /**
  21693. * @author mrdoob / http://mrdoob.com/
  21694. */
  21695. function ObjectLoader( manager ) {
  21696. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21697. this.texturePath = '';
  21698. }
  21699. Object.assign( ObjectLoader.prototype, {
  21700. load: function ( url, onLoad, onProgress, onError ) {
  21701. if ( this.texturePath === '' ) {
  21702. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  21703. }
  21704. var scope = this;
  21705. var loader = new FileLoader( scope.manager );
  21706. loader.load( url, function ( text ) {
  21707. var json = null;
  21708. try {
  21709. json = JSON.parse( text );
  21710. } catch ( error ) {
  21711. if ( onError !== undefined ) onError( error );
  21712. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  21713. return;
  21714. }
  21715. var metadata = json.metadata;
  21716. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  21717. console.error( 'THREE.ObjectLoader: Can\'t load ' + url + '. Use THREE.JSONLoader instead.' );
  21718. return;
  21719. }
  21720. scope.parse( json, onLoad );
  21721. }, onProgress, onError );
  21722. },
  21723. setTexturePath: function ( value ) {
  21724. this.texturePath = value;
  21725. },
  21726. setCrossOrigin: function ( value ) {
  21727. this.crossOrigin = value;
  21728. },
  21729. parse: function ( json, onLoad ) {
  21730. var shapes = this.parseShape( json.shapes );
  21731. var geometries = this.parseGeometries( json.geometries, shapes );
  21732. var images = this.parseImages( json.images, function () {
  21733. if ( onLoad !== undefined ) onLoad( object );
  21734. } );
  21735. var textures = this.parseTextures( json.textures, images );
  21736. var materials = this.parseMaterials( json.materials, textures );
  21737. var object = this.parseObject( json.object, geometries, materials );
  21738. if ( json.animations ) {
  21739. object.animations = this.parseAnimations( json.animations );
  21740. }
  21741. if ( json.images === undefined || json.images.length === 0 ) {
  21742. if ( onLoad !== undefined ) onLoad( object );
  21743. }
  21744. return object;
  21745. },
  21746. parseShape: function ( json ) {
  21747. var shapes = {};
  21748. if ( json !== undefined ) {
  21749. for ( var i = 0, l = json.length; i < l; i ++ ) {
  21750. var shape = new Shape().fromJSON( json[ i ] );
  21751. shapes[ shape.uuid ] = shape;
  21752. }
  21753. }
  21754. return shapes;
  21755. },
  21756. parseGeometries: function ( json, shapes ) {
  21757. var geometries = {};
  21758. if ( json !== undefined ) {
  21759. var geometryLoader = new JSONLoader();
  21760. var bufferGeometryLoader = new BufferGeometryLoader();
  21761. for ( var i = 0, l = json.length; i < l; i ++ ) {
  21762. var geometry;
  21763. var data = json[ i ];
  21764. switch ( data.type ) {
  21765. case 'PlaneGeometry':
  21766. case 'PlaneBufferGeometry':
  21767. geometry = new Geometries[ data.type ](
  21768. data.width,
  21769. data.height,
  21770. data.widthSegments,
  21771. data.heightSegments
  21772. );
  21773. break;
  21774. case 'BoxGeometry':
  21775. case 'BoxBufferGeometry':
  21776. case 'CubeGeometry': // backwards compatible
  21777. geometry = new Geometries[ data.type ](
  21778. data.width,
  21779. data.height,
  21780. data.depth,
  21781. data.widthSegments,
  21782. data.heightSegments,
  21783. data.depthSegments
  21784. );
  21785. break;
  21786. case 'CircleGeometry':
  21787. case 'CircleBufferGeometry':
  21788. geometry = new Geometries[ data.type ](
  21789. data.radius,
  21790. data.segments,
  21791. data.thetaStart,
  21792. data.thetaLength
  21793. );
  21794. break;
  21795. case 'CylinderGeometry':
  21796. case 'CylinderBufferGeometry':
  21797. geometry = new Geometries[ data.type ](
  21798. data.radiusTop,
  21799. data.radiusBottom,
  21800. data.height,
  21801. data.radialSegments,
  21802. data.heightSegments,
  21803. data.openEnded,
  21804. data.thetaStart,
  21805. data.thetaLength
  21806. );
  21807. break;
  21808. case 'ConeGeometry':
  21809. case 'ConeBufferGeometry':
  21810. geometry = new Geometries[ data.type ](
  21811. data.radius,
  21812. data.height,
  21813. data.radialSegments,
  21814. data.heightSegments,
  21815. data.openEnded,
  21816. data.thetaStart,
  21817. data.thetaLength
  21818. );
  21819. break;
  21820. case 'SphereGeometry':
  21821. case 'SphereBufferGeometry':
  21822. geometry = new Geometries[ data.type ](
  21823. data.radius,
  21824. data.widthSegments,
  21825. data.heightSegments,
  21826. data.phiStart,
  21827. data.phiLength,
  21828. data.thetaStart,
  21829. data.thetaLength
  21830. );
  21831. break;
  21832. case 'DodecahedronGeometry':
  21833. case 'DodecahedronBufferGeometry':
  21834. case 'IcosahedronGeometry':
  21835. case 'IcosahedronBufferGeometry':
  21836. case 'OctahedronGeometry':
  21837. case 'OctahedronBufferGeometry':
  21838. case 'TetrahedronGeometry':
  21839. case 'TetrahedronBufferGeometry':
  21840. geometry = new Geometries[ data.type ](
  21841. data.radius,
  21842. data.detail
  21843. );
  21844. break;
  21845. case 'RingGeometry':
  21846. case 'RingBufferGeometry':
  21847. geometry = new Geometries[ data.type ](
  21848. data.innerRadius,
  21849. data.outerRadius,
  21850. data.thetaSegments,
  21851. data.phiSegments,
  21852. data.thetaStart,
  21853. data.thetaLength
  21854. );
  21855. break;
  21856. case 'TorusGeometry':
  21857. case 'TorusBufferGeometry':
  21858. geometry = new Geometries[ data.type ](
  21859. data.radius,
  21860. data.tube,
  21861. data.radialSegments,
  21862. data.tubularSegments,
  21863. data.arc
  21864. );
  21865. break;
  21866. case 'TorusKnotGeometry':
  21867. case 'TorusKnotBufferGeometry':
  21868. geometry = new Geometries[ data.type ](
  21869. data.radius,
  21870. data.tube,
  21871. data.tubularSegments,
  21872. data.radialSegments,
  21873. data.p,
  21874. data.q
  21875. );
  21876. break;
  21877. case 'LatheGeometry':
  21878. case 'LatheBufferGeometry':
  21879. geometry = new Geometries[ data.type ](
  21880. data.points,
  21881. data.segments,
  21882. data.phiStart,
  21883. data.phiLength
  21884. );
  21885. break;
  21886. case 'PolyhedronGeometry':
  21887. case 'PolyhedronBufferGeometry':
  21888. geometry = new Geometries[ data.type ](
  21889. data.vertices,
  21890. data.indices,
  21891. data.radius,
  21892. data.details
  21893. );
  21894. break;
  21895. case 'ShapeGeometry':
  21896. case 'ShapeBufferGeometry':
  21897. var geometryShapes = [];
  21898. for ( var i = 0, l = data.shapes.length; i < l; i ++ ) {
  21899. var shape = shapes[ data.shapes[ i ] ];
  21900. geometryShapes.push( shape );
  21901. }
  21902. geometry = new Geometries[ data.type ](
  21903. geometryShapes,
  21904. data.curveSegments
  21905. );
  21906. break;
  21907. case 'BufferGeometry':
  21908. geometry = bufferGeometryLoader.parse( data );
  21909. break;
  21910. case 'Geometry':
  21911. geometry = geometryLoader.parse( data, this.texturePath ).geometry;
  21912. break;
  21913. default:
  21914. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  21915. continue;
  21916. }
  21917. geometry.uuid = data.uuid;
  21918. if ( data.name !== undefined ) geometry.name = data.name;
  21919. geometries[ data.uuid ] = geometry;
  21920. }
  21921. }
  21922. return geometries;
  21923. },
  21924. parseMaterials: function ( json, textures ) {
  21925. var materials = {};
  21926. if ( json !== undefined ) {
  21927. var loader = new MaterialLoader();
  21928. loader.setTextures( textures );
  21929. for ( var i = 0, l = json.length; i < l; i ++ ) {
  21930. var data = json[ i ];
  21931. if ( data.type === 'MultiMaterial' ) {
  21932. // Deprecated
  21933. var array = [];
  21934. for ( var j = 0; j < data.materials.length; j ++ ) {
  21935. array.push( loader.parse( data.materials[ j ] ) );
  21936. }
  21937. materials[ data.uuid ] = array;
  21938. } else {
  21939. materials[ data.uuid ] = loader.parse( data );
  21940. }
  21941. }
  21942. }
  21943. return materials;
  21944. },
  21945. parseAnimations: function ( json ) {
  21946. var animations = [];
  21947. for ( var i = 0; i < json.length; i ++ ) {
  21948. var clip = AnimationClip.parse( json[ i ] );
  21949. animations.push( clip );
  21950. }
  21951. return animations;
  21952. },
  21953. parseImages: function ( json, onLoad ) {
  21954. var scope = this;
  21955. var images = {};
  21956. function loadImage( url ) {
  21957. scope.manager.itemStart( url );
  21958. return loader.load( url, function () {
  21959. scope.manager.itemEnd( url );
  21960. }, undefined, function () {
  21961. scope.manager.itemEnd( url );
  21962. scope.manager.itemError( url );
  21963. } );
  21964. }
  21965. if ( json !== undefined && json.length > 0 ) {
  21966. var manager = new LoadingManager( onLoad );
  21967. var loader = new ImageLoader( manager );
  21968. loader.setCrossOrigin( this.crossOrigin );
  21969. for ( var i = 0, l = json.length; i < l; i ++ ) {
  21970. var image = json[ i ];
  21971. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  21972. images[ image.uuid ] = loadImage( path );
  21973. }
  21974. }
  21975. return images;
  21976. },
  21977. parseTextures: function ( json, images ) {
  21978. function parseConstant( value, type ) {
  21979. if ( typeof value === 'number' ) return value;
  21980. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  21981. return type[ value ];
  21982. }
  21983. var textures = {};
  21984. if ( json !== undefined ) {
  21985. for ( var i = 0, l = json.length; i < l; i ++ ) {
  21986. var data = json[ i ];
  21987. if ( data.image === undefined ) {
  21988. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  21989. }
  21990. if ( images[ data.image ] === undefined ) {
  21991. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  21992. }
  21993. var texture = new Texture( images[ data.image ] );
  21994. texture.needsUpdate = true;
  21995. texture.uuid = data.uuid;
  21996. if ( data.name !== undefined ) texture.name = data.name;
  21997. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  21998. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  21999. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  22000. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  22001. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  22002. if ( data.wrap !== undefined ) {
  22003. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  22004. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  22005. }
  22006. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  22007. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  22008. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  22009. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  22010. textures[ data.uuid ] = texture;
  22011. }
  22012. }
  22013. return textures;
  22014. },
  22015. parseObject: function ( data, geometries, materials ) {
  22016. var object;
  22017. function getGeometry( name ) {
  22018. if ( geometries[ name ] === undefined ) {
  22019. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  22020. }
  22021. return geometries[ name ];
  22022. }
  22023. function getMaterial( name ) {
  22024. if ( name === undefined ) return undefined;
  22025. if ( Array.isArray( name ) ) {
  22026. var array = [];
  22027. for ( var i = 0, l = name.length; i < l; i ++ ) {
  22028. var uuid = name[ i ];
  22029. if ( materials[ uuid ] === undefined ) {
  22030. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  22031. }
  22032. array.push( materials[ uuid ] );
  22033. }
  22034. return array;
  22035. }
  22036. if ( materials[ name ] === undefined ) {
  22037. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  22038. }
  22039. return materials[ name ];
  22040. }
  22041. switch ( data.type ) {
  22042. case 'Scene':
  22043. object = new Scene();
  22044. if ( data.background !== undefined ) {
  22045. if ( Number.isInteger( data.background ) ) {
  22046. object.background = new Color( data.background );
  22047. }
  22048. }
  22049. if ( data.fog !== undefined ) {
  22050. if ( data.fog.type === 'Fog' ) {
  22051. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  22052. } else if ( data.fog.type === 'FogExp2' ) {
  22053. object.fog = new FogExp2( data.fog.color, data.fog.density );
  22054. }
  22055. }
  22056. break;
  22057. case 'PerspectiveCamera':
  22058. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  22059. if ( data.focus !== undefined ) object.focus = data.focus;
  22060. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  22061. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  22062. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  22063. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  22064. break;
  22065. case 'OrthographicCamera':
  22066. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  22067. break;
  22068. case 'AmbientLight':
  22069. object = new AmbientLight( data.color, data.intensity );
  22070. break;
  22071. case 'DirectionalLight':
  22072. object = new DirectionalLight( data.color, data.intensity );
  22073. break;
  22074. case 'PointLight':
  22075. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  22076. break;
  22077. case 'RectAreaLight':
  22078. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  22079. break;
  22080. case 'SpotLight':
  22081. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  22082. break;
  22083. case 'HemisphereLight':
  22084. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  22085. break;
  22086. case 'SkinnedMesh':
  22087. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  22088. case 'Mesh':
  22089. var geometry = getGeometry( data.geometry );
  22090. var material = getMaterial( data.material );
  22091. if ( geometry.bones && geometry.bones.length > 0 ) {
  22092. object = new SkinnedMesh( geometry, material );
  22093. } else {
  22094. object = new Mesh( geometry, material );
  22095. }
  22096. break;
  22097. case 'LOD':
  22098. object = new LOD();
  22099. break;
  22100. case 'Line':
  22101. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  22102. break;
  22103. case 'LineLoop':
  22104. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  22105. break;
  22106. case 'LineSegments':
  22107. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  22108. break;
  22109. case 'PointCloud':
  22110. case 'Points':
  22111. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  22112. break;
  22113. case 'Sprite':
  22114. object = new Sprite( getMaterial( data.material ) );
  22115. break;
  22116. case 'Group':
  22117. object = new Group();
  22118. break;
  22119. default:
  22120. object = new Object3D();
  22121. }
  22122. object.uuid = data.uuid;
  22123. if ( data.name !== undefined ) object.name = data.name;
  22124. if ( data.matrix !== undefined ) {
  22125. object.matrix.fromArray( data.matrix );
  22126. object.matrix.decompose( object.position, object.quaternion, object.scale );
  22127. } else {
  22128. if ( data.position !== undefined ) object.position.fromArray( data.position );
  22129. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  22130. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  22131. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  22132. }
  22133. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  22134. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  22135. if ( data.shadow ) {
  22136. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  22137. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  22138. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  22139. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  22140. }
  22141. if ( data.visible !== undefined ) object.visible = data.visible;
  22142. if ( data.userData !== undefined ) object.userData = data.userData;
  22143. if ( data.children !== undefined ) {
  22144. var children = data.children;
  22145. for ( var i = 0; i < children.length; i ++ ) {
  22146. object.add( this.parseObject( children[ i ], geometries, materials ) );
  22147. }
  22148. }
  22149. if ( data.type === 'LOD' ) {
  22150. var levels = data.levels;
  22151. for ( var l = 0; l < levels.length; l ++ ) {
  22152. var level = levels[ l ];
  22153. var child = object.getObjectByProperty( 'uuid', level.object );
  22154. if ( child !== undefined ) {
  22155. object.addLevel( child, level.distance );
  22156. }
  22157. }
  22158. }
  22159. return object;
  22160. }
  22161. } );
  22162. var TEXTURE_MAPPING = {
  22163. UVMapping: UVMapping,
  22164. CubeReflectionMapping: CubeReflectionMapping,
  22165. CubeRefractionMapping: CubeRefractionMapping,
  22166. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  22167. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  22168. SphericalReflectionMapping: SphericalReflectionMapping,
  22169. CubeUVReflectionMapping: CubeUVReflectionMapping,
  22170. CubeUVRefractionMapping: CubeUVRefractionMapping
  22171. };
  22172. var TEXTURE_WRAPPING = {
  22173. RepeatWrapping: RepeatWrapping,
  22174. ClampToEdgeWrapping: ClampToEdgeWrapping,
  22175. MirroredRepeatWrapping: MirroredRepeatWrapping
  22176. };
  22177. var TEXTURE_FILTER = {
  22178. NearestFilter: NearestFilter,
  22179. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  22180. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  22181. LinearFilter: LinearFilter,
  22182. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  22183. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  22184. };
  22185. /**
  22186. * @author thespite / http://clicktorelease.com/
  22187. */
  22188. function ImageBitmapLoader( manager ) {
  22189. if ( typeof createImageBitmap === 'undefined' ) {
  22190. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  22191. }
  22192. if ( typeof fetch === 'undefined' ) {
  22193. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  22194. }
  22195. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  22196. this.options = undefined;
  22197. }
  22198. ImageBitmapLoader.prototype = {
  22199. constructor: ImageBitmapLoader,
  22200. setOptions: function setOptions( options ) {
  22201. this.options = options;
  22202. return this;
  22203. },
  22204. load: function load( url, onLoad, onProgress, onError ) {
  22205. if ( url === undefined ) url = '';
  22206. if ( this.path !== undefined ) url = this.path + url;
  22207. var scope = this;
  22208. var cached = Cache.get( url );
  22209. if ( cached !== undefined ) {
  22210. scope.manager.itemStart( url );
  22211. setTimeout( function () {
  22212. if ( onLoad ) onLoad( cached );
  22213. scope.manager.itemEnd( url );
  22214. }, 0 );
  22215. return cached;
  22216. }
  22217. fetch( url ).then( function ( res ) {
  22218. return res.blob();
  22219. } ).then( function ( blob ) {
  22220. return createImageBitmap( blob, scope.options );
  22221. } ).then( function ( imageBitmap ) {
  22222. Cache.add( url, imageBitmap );
  22223. if ( onLoad ) onLoad( imageBitmap );
  22224. scope.manager.itemEnd( url );
  22225. } ).catch( function ( e ) {
  22226. if ( onError ) onError( e );
  22227. scope.manager.itemEnd( url );
  22228. scope.manager.itemError( url );
  22229. } );
  22230. },
  22231. setCrossOrigin: function ( /* value */ ) {
  22232. return this;
  22233. },
  22234. setPath: function ( value ) {
  22235. this.path = value;
  22236. return this;
  22237. }
  22238. };
  22239. /**
  22240. * @author zz85 / http://www.lab4games.net/zz85/blog
  22241. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  22242. **/
  22243. function ShapePath() {
  22244. this.type = 'ShapePath';
  22245. this.subPaths = [];
  22246. this.currentPath = null;
  22247. }
  22248. Object.assign( ShapePath.prototype, {
  22249. moveTo: function ( x, y ) {
  22250. this.currentPath = new Path();
  22251. this.subPaths.push( this.currentPath );
  22252. this.currentPath.moveTo( x, y );
  22253. },
  22254. lineTo: function ( x, y ) {
  22255. this.currentPath.lineTo( x, y );
  22256. },
  22257. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  22258. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  22259. },
  22260. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  22261. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  22262. },
  22263. splineThru: function ( pts ) {
  22264. this.currentPath.splineThru( pts );
  22265. },
  22266. toShapes: function ( isCCW, noHoles ) {
  22267. function toShapesNoHoles( inSubpaths ) {
  22268. var shapes = [];
  22269. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  22270. var tmpPath = inSubpaths[ i ];
  22271. var tmpShape = new Shape();
  22272. tmpShape.curves = tmpPath.curves;
  22273. shapes.push( tmpShape );
  22274. }
  22275. return shapes;
  22276. }
  22277. function isPointInsidePolygon( inPt, inPolygon ) {
  22278. var polyLen = inPolygon.length;
  22279. // inPt on polygon contour => immediate success or
  22280. // toggling of inside/outside at every single! intersection point of an edge
  22281. // with the horizontal line through inPt, left of inPt
  22282. // not counting lowerY endpoints of edges and whole edges on that line
  22283. var inside = false;
  22284. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  22285. var edgeLowPt = inPolygon[ p ];
  22286. var edgeHighPt = inPolygon[ q ];
  22287. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  22288. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  22289. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  22290. // not parallel
  22291. if ( edgeDy < 0 ) {
  22292. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  22293. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  22294. }
  22295. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  22296. if ( inPt.y === edgeLowPt.y ) {
  22297. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  22298. // continue; // no intersection or edgeLowPt => doesn't count !!!
  22299. } else {
  22300. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  22301. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  22302. if ( perpEdge < 0 ) continue;
  22303. inside = ! inside; // true intersection left of inPt
  22304. }
  22305. } else {
  22306. // parallel or collinear
  22307. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  22308. // edge lies on the same horizontal line as inPt
  22309. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  22310. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  22311. // continue;
  22312. }
  22313. }
  22314. return inside;
  22315. }
  22316. var isClockWise = ShapeUtils.isClockWise;
  22317. var subPaths = this.subPaths;
  22318. if ( subPaths.length === 0 ) return [];
  22319. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  22320. var solid, tmpPath, tmpShape, shapes = [];
  22321. if ( subPaths.length === 1 ) {
  22322. tmpPath = subPaths[ 0 ];
  22323. tmpShape = new Shape();
  22324. tmpShape.curves = tmpPath.curves;
  22325. shapes.push( tmpShape );
  22326. return shapes;
  22327. }
  22328. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  22329. holesFirst = isCCW ? ! holesFirst : holesFirst;
  22330. // console.log("Holes first", holesFirst);
  22331. var betterShapeHoles = [];
  22332. var newShapes = [];
  22333. var newShapeHoles = [];
  22334. var mainIdx = 0;
  22335. var tmpPoints;
  22336. newShapes[ mainIdx ] = undefined;
  22337. newShapeHoles[ mainIdx ] = [];
  22338. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  22339. tmpPath = subPaths[ i ];
  22340. tmpPoints = tmpPath.getPoints();
  22341. solid = isClockWise( tmpPoints );
  22342. solid = isCCW ? ! solid : solid;
  22343. if ( solid ) {
  22344. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  22345. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  22346. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  22347. if ( holesFirst ) mainIdx ++;
  22348. newShapeHoles[ mainIdx ] = [];
  22349. //console.log('cw', i);
  22350. } else {
  22351. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  22352. //console.log('ccw', i);
  22353. }
  22354. }
  22355. // only Holes? -> probably all Shapes with wrong orientation
  22356. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  22357. if ( newShapes.length > 1 ) {
  22358. var ambiguous = false;
  22359. var toChange = [];
  22360. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  22361. betterShapeHoles[ sIdx ] = [];
  22362. }
  22363. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  22364. var sho = newShapeHoles[ sIdx ];
  22365. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  22366. var ho = sho[ hIdx ];
  22367. var hole_unassigned = true;
  22368. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  22369. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  22370. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  22371. if ( hole_unassigned ) {
  22372. hole_unassigned = false;
  22373. betterShapeHoles[ s2Idx ].push( ho );
  22374. } else {
  22375. ambiguous = true;
  22376. }
  22377. }
  22378. }
  22379. if ( hole_unassigned ) {
  22380. betterShapeHoles[ sIdx ].push( ho );
  22381. }
  22382. }
  22383. }
  22384. // console.log("ambiguous: ", ambiguous);
  22385. if ( toChange.length > 0 ) {
  22386. // console.log("to change: ", toChange);
  22387. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  22388. }
  22389. }
  22390. var tmpHoles;
  22391. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  22392. tmpShape = newShapes[ i ].s;
  22393. shapes.push( tmpShape );
  22394. tmpHoles = newShapeHoles[ i ];
  22395. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  22396. tmpShape.holes.push( tmpHoles[ j ].h );
  22397. }
  22398. }
  22399. //console.log("shape", shapes);
  22400. return shapes;
  22401. }
  22402. } );
  22403. /**
  22404. * @author zz85 / http://www.lab4games.net/zz85/blog
  22405. * @author mrdoob / http://mrdoob.com/
  22406. */
  22407. function Font( data ) {
  22408. this.type = 'Font';
  22409. this.data = data;
  22410. }
  22411. Object.assign( Font.prototype, {
  22412. isFont: true,
  22413. generateShapes: function ( text, size, divisions ) {
  22414. if ( size === undefined ) size = 100;
  22415. if ( divisions === undefined ) divisions = 4;
  22416. var shapes = [];
  22417. var paths = createPaths( text, size, divisions, this.data );
  22418. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  22419. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  22420. }
  22421. return shapes;
  22422. }
  22423. } );
  22424. function createPaths( text, size, divisions, data ) {
  22425. var chars = String( text ).split( '' );
  22426. var scale = size / data.resolution;
  22427. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  22428. var paths = [];
  22429. var offsetX = 0, offsetY = 0;
  22430. for ( var i = 0; i < chars.length; i ++ ) {
  22431. var char = chars[ i ];
  22432. if ( char === '\n' ) {
  22433. offsetX = 0;
  22434. offsetY -= line_height;
  22435. } else {
  22436. var ret = createPath( char, divisions, scale, offsetX, offsetY, data );
  22437. offsetX += ret.offsetX;
  22438. paths.push( ret.path );
  22439. }
  22440. }
  22441. return paths;
  22442. }
  22443. function createPath( char, divisions, scale, offsetX, offsetY, data ) {
  22444. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  22445. if ( ! glyph ) return;
  22446. var path = new ShapePath();
  22447. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  22448. if ( glyph.o ) {
  22449. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  22450. for ( var i = 0, l = outline.length; i < l; ) {
  22451. var action = outline[ i ++ ];
  22452. switch ( action ) {
  22453. case 'm': // moveTo
  22454. x = outline[ i ++ ] * scale + offsetX;
  22455. y = outline[ i ++ ] * scale + offsetY;
  22456. path.moveTo( x, y );
  22457. break;
  22458. case 'l': // lineTo
  22459. x = outline[ i ++ ] * scale + offsetX;
  22460. y = outline[ i ++ ] * scale + offsetY;
  22461. path.lineTo( x, y );
  22462. break;
  22463. case 'q': // quadraticCurveTo
  22464. cpx = outline[ i ++ ] * scale + offsetX;
  22465. cpy = outline[ i ++ ] * scale + offsetY;
  22466. cpx1 = outline[ i ++ ] * scale + offsetX;
  22467. cpy1 = outline[ i ++ ] * scale + offsetY;
  22468. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  22469. break;
  22470. case 'b': // bezierCurveTo
  22471. cpx = outline[ i ++ ] * scale + offsetX;
  22472. cpy = outline[ i ++ ] * scale + offsetY;
  22473. cpx1 = outline[ i ++ ] * scale + offsetX;
  22474. cpy1 = outline[ i ++ ] * scale + offsetY;
  22475. cpx2 = outline[ i ++ ] * scale + offsetX;
  22476. cpy2 = outline[ i ++ ] * scale + offsetY;
  22477. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  22478. break;
  22479. }
  22480. }
  22481. }
  22482. return { offsetX: glyph.ha * scale, path: path };
  22483. }
  22484. /**
  22485. * @author mrdoob / http://mrdoob.com/
  22486. */
  22487. function FontLoader( manager ) {
  22488. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22489. }
  22490. Object.assign( FontLoader.prototype, {
  22491. load: function ( url, onLoad, onProgress, onError ) {
  22492. var scope = this;
  22493. var loader = new FileLoader( this.manager );
  22494. loader.setPath( this.path );
  22495. loader.load( url, function ( text ) {
  22496. var json;
  22497. try {
  22498. json = JSON.parse( text );
  22499. } catch ( e ) {
  22500. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  22501. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  22502. }
  22503. var font = scope.parse( json );
  22504. if ( onLoad ) onLoad( font );
  22505. }, onProgress, onError );
  22506. },
  22507. parse: function ( json ) {
  22508. return new Font( json );
  22509. },
  22510. setPath: function ( value ) {
  22511. this.path = value;
  22512. return this;
  22513. }
  22514. } );
  22515. /**
  22516. * @author mrdoob / http://mrdoob.com/
  22517. */
  22518. var context;
  22519. var AudioContext = {
  22520. getContext: function () {
  22521. if ( context === undefined ) {
  22522. context = new ( window.AudioContext || window.webkitAudioContext )();
  22523. }
  22524. return context;
  22525. },
  22526. setContext: function ( value ) {
  22527. context = value;
  22528. }
  22529. };
  22530. /**
  22531. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  22532. */
  22533. function AudioLoader( manager ) {
  22534. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22535. }
  22536. Object.assign( AudioLoader.prototype, {
  22537. load: function ( url, onLoad, onProgress, onError ) {
  22538. var loader = new FileLoader( this.manager );
  22539. loader.setResponseType( 'arraybuffer' );
  22540. loader.load( url, function ( buffer ) {
  22541. var context = AudioContext.getContext();
  22542. context.decodeAudioData( buffer, function ( audioBuffer ) {
  22543. onLoad( audioBuffer );
  22544. } );
  22545. }, onProgress, onError );
  22546. }
  22547. } );
  22548. /**
  22549. * @author mrdoob / http://mrdoob.com/
  22550. */
  22551. function StereoCamera() {
  22552. this.type = 'StereoCamera';
  22553. this.aspect = 1;
  22554. this.eyeSep = 0.064;
  22555. this.cameraL = new PerspectiveCamera();
  22556. this.cameraL.layers.enable( 1 );
  22557. this.cameraL.matrixAutoUpdate = false;
  22558. this.cameraR = new PerspectiveCamera();
  22559. this.cameraR.layers.enable( 2 );
  22560. this.cameraR.matrixAutoUpdate = false;
  22561. }
  22562. Object.assign( StereoCamera.prototype, {
  22563. update: ( function () {
  22564. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  22565. var eyeRight = new Matrix4();
  22566. var eyeLeft = new Matrix4();
  22567. return function update( camera ) {
  22568. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  22569. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  22570. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  22571. if ( needsUpdate ) {
  22572. instance = this;
  22573. focus = camera.focus;
  22574. fov = camera.fov;
  22575. aspect = camera.aspect * this.aspect;
  22576. near = camera.near;
  22577. far = camera.far;
  22578. zoom = camera.zoom;
  22579. // Off-axis stereoscopic effect based on
  22580. // http://paulbourke.net/stereographics/stereorender/
  22581. var projectionMatrix = camera.projectionMatrix.clone();
  22582. eyeSep = this.eyeSep / 2;
  22583. var eyeSepOnProjection = eyeSep * near / focus;
  22584. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  22585. var xmin, xmax;
  22586. // translate xOffset
  22587. eyeLeft.elements[ 12 ] = - eyeSep;
  22588. eyeRight.elements[ 12 ] = eyeSep;
  22589. // for left eye
  22590. xmin = - ymax * aspect + eyeSepOnProjection;
  22591. xmax = ymax * aspect + eyeSepOnProjection;
  22592. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  22593. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  22594. this.cameraL.projectionMatrix.copy( projectionMatrix );
  22595. // for right eye
  22596. xmin = - ymax * aspect - eyeSepOnProjection;
  22597. xmax = ymax * aspect - eyeSepOnProjection;
  22598. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  22599. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  22600. this.cameraR.projectionMatrix.copy( projectionMatrix );
  22601. }
  22602. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  22603. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  22604. };
  22605. } )()
  22606. } );
  22607. /**
  22608. * Camera for rendering cube maps
  22609. * - renders scene into axis-aligned cube
  22610. *
  22611. * @author alteredq / http://alteredqualia.com/
  22612. */
  22613. function CubeCamera( near, far, cubeResolution ) {
  22614. Object3D.call( this );
  22615. this.type = 'CubeCamera';
  22616. var fov = 90, aspect = 1;
  22617. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  22618. cameraPX.up.set( 0, - 1, 0 );
  22619. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  22620. this.add( cameraPX );
  22621. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  22622. cameraNX.up.set( 0, - 1, 0 );
  22623. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  22624. this.add( cameraNX );
  22625. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  22626. cameraPY.up.set( 0, 0, 1 );
  22627. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  22628. this.add( cameraPY );
  22629. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  22630. cameraNY.up.set( 0, 0, - 1 );
  22631. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  22632. this.add( cameraNY );
  22633. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  22634. cameraPZ.up.set( 0, - 1, 0 );
  22635. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  22636. this.add( cameraPZ );
  22637. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  22638. cameraNZ.up.set( 0, - 1, 0 );
  22639. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  22640. this.add( cameraNZ );
  22641. var options = { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  22642. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  22643. this.renderTarget.texture.name = "CubeCamera";
  22644. this.update = function ( renderer, scene ) {
  22645. if ( this.parent === null ) this.updateMatrixWorld();
  22646. var renderTarget = this.renderTarget;
  22647. var generateMipmaps = renderTarget.texture.generateMipmaps;
  22648. renderTarget.texture.generateMipmaps = false;
  22649. renderTarget.activeCubeFace = 0;
  22650. renderer.render( scene, cameraPX, renderTarget );
  22651. renderTarget.activeCubeFace = 1;
  22652. renderer.render( scene, cameraNX, renderTarget );
  22653. renderTarget.activeCubeFace = 2;
  22654. renderer.render( scene, cameraPY, renderTarget );
  22655. renderTarget.activeCubeFace = 3;
  22656. renderer.render( scene, cameraNY, renderTarget );
  22657. renderTarget.activeCubeFace = 4;
  22658. renderer.render( scene, cameraPZ, renderTarget );
  22659. renderTarget.texture.generateMipmaps = generateMipmaps;
  22660. renderTarget.activeCubeFace = 5;
  22661. renderer.render( scene, cameraNZ, renderTarget );
  22662. renderer.setRenderTarget( null );
  22663. };
  22664. this.clear = function ( renderer, color, depth, stencil ) {
  22665. var renderTarget = this.renderTarget;
  22666. for ( var i = 0; i < 6; i ++ ) {
  22667. renderTarget.activeCubeFace = i;
  22668. renderer.setRenderTarget( renderTarget );
  22669. renderer.clear( color, depth, stencil );
  22670. }
  22671. renderer.setRenderTarget( null );
  22672. };
  22673. }
  22674. CubeCamera.prototype = Object.create( Object3D.prototype );
  22675. CubeCamera.prototype.constructor = CubeCamera;
  22676. /**
  22677. * @author mrdoob / http://mrdoob.com/
  22678. */
  22679. function AudioListener() {
  22680. Object3D.call( this );
  22681. this.type = 'AudioListener';
  22682. this.context = AudioContext.getContext();
  22683. this.gain = this.context.createGain();
  22684. this.gain.connect( this.context.destination );
  22685. this.filter = null;
  22686. }
  22687. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22688. constructor: AudioListener,
  22689. getInput: function () {
  22690. return this.gain;
  22691. },
  22692. removeFilter: function ( ) {
  22693. if ( this.filter !== null ) {
  22694. this.gain.disconnect( this.filter );
  22695. this.filter.disconnect( this.context.destination );
  22696. this.gain.connect( this.context.destination );
  22697. this.filter = null;
  22698. }
  22699. },
  22700. getFilter: function () {
  22701. return this.filter;
  22702. },
  22703. setFilter: function ( value ) {
  22704. if ( this.filter !== null ) {
  22705. this.gain.disconnect( this.filter );
  22706. this.filter.disconnect( this.context.destination );
  22707. } else {
  22708. this.gain.disconnect( this.context.destination );
  22709. }
  22710. this.filter = value;
  22711. this.gain.connect( this.filter );
  22712. this.filter.connect( this.context.destination );
  22713. },
  22714. getMasterVolume: function () {
  22715. return this.gain.gain.value;
  22716. },
  22717. setMasterVolume: function ( value ) {
  22718. this.gain.gain.value = value;
  22719. },
  22720. updateMatrixWorld: ( function () {
  22721. var position = new Vector3();
  22722. var quaternion = new Quaternion();
  22723. var scale = new Vector3();
  22724. var orientation = new Vector3();
  22725. return function updateMatrixWorld( force ) {
  22726. Object3D.prototype.updateMatrixWorld.call( this, force );
  22727. var listener = this.context.listener;
  22728. var up = this.up;
  22729. this.matrixWorld.decompose( position, quaternion, scale );
  22730. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  22731. if ( listener.positionX ) {
  22732. listener.positionX.setValueAtTime( position.x, this.context.currentTime );
  22733. listener.positionY.setValueAtTime( position.y, this.context.currentTime );
  22734. listener.positionZ.setValueAtTime( position.z, this.context.currentTime );
  22735. listener.forwardX.setValueAtTime( orientation.x, this.context.currentTime );
  22736. listener.forwardY.setValueAtTime( orientation.y, this.context.currentTime );
  22737. listener.forwardZ.setValueAtTime( orientation.z, this.context.currentTime );
  22738. listener.upX.setValueAtTime( up.x, this.context.currentTime );
  22739. listener.upY.setValueAtTime( up.y, this.context.currentTime );
  22740. listener.upZ.setValueAtTime( up.z, this.context.currentTime );
  22741. } else {
  22742. listener.setPosition( position.x, position.y, position.z );
  22743. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  22744. }
  22745. };
  22746. } )()
  22747. } );
  22748. /**
  22749. * @author mrdoob / http://mrdoob.com/
  22750. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  22751. */
  22752. function Audio( listener ) {
  22753. Object3D.call( this );
  22754. this.type = 'Audio';
  22755. this.context = listener.context;
  22756. this.gain = this.context.createGain();
  22757. this.gain.connect( listener.getInput() );
  22758. this.autoplay = false;
  22759. this.buffer = null;
  22760. this.loop = false;
  22761. this.startTime = 0;
  22762. this.offset = 0;
  22763. this.playbackRate = 1;
  22764. this.isPlaying = false;
  22765. this.hasPlaybackControl = true;
  22766. this.sourceType = 'empty';
  22767. this.filters = [];
  22768. }
  22769. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22770. constructor: Audio,
  22771. getOutput: function () {
  22772. return this.gain;
  22773. },
  22774. setNodeSource: function ( audioNode ) {
  22775. this.hasPlaybackControl = false;
  22776. this.sourceType = 'audioNode';
  22777. this.source = audioNode;
  22778. this.connect();
  22779. return this;
  22780. },
  22781. setBuffer: function ( audioBuffer ) {
  22782. this.buffer = audioBuffer;
  22783. this.sourceType = 'buffer';
  22784. if ( this.autoplay ) this.play();
  22785. return this;
  22786. },
  22787. play: function () {
  22788. if ( this.isPlaying === true ) {
  22789. console.warn( 'THREE.Audio: Audio is already playing.' );
  22790. return;
  22791. }
  22792. if ( this.hasPlaybackControl === false ) {
  22793. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  22794. return;
  22795. }
  22796. var source = this.context.createBufferSource();
  22797. source.buffer = this.buffer;
  22798. source.loop = this.loop;
  22799. source.onended = this.onEnded.bind( this );
  22800. source.playbackRate.setValueAtTime( this.playbackRate, this.startTime );
  22801. this.startTime = this.context.currentTime;
  22802. source.start( this.startTime, this.offset );
  22803. this.isPlaying = true;
  22804. this.source = source;
  22805. return this.connect();
  22806. },
  22807. pause: function () {
  22808. if ( this.hasPlaybackControl === false ) {
  22809. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  22810. return;
  22811. }
  22812. if ( this.isPlaying === true ) {
  22813. this.source.stop();
  22814. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  22815. this.isPlaying = false;
  22816. }
  22817. return this;
  22818. },
  22819. stop: function () {
  22820. if ( this.hasPlaybackControl === false ) {
  22821. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  22822. return;
  22823. }
  22824. this.source.stop();
  22825. this.offset = 0;
  22826. this.isPlaying = false;
  22827. return this;
  22828. },
  22829. connect: function () {
  22830. if ( this.filters.length > 0 ) {
  22831. this.source.connect( this.filters[ 0 ] );
  22832. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  22833. this.filters[ i - 1 ].connect( this.filters[ i ] );
  22834. }
  22835. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  22836. } else {
  22837. this.source.connect( this.getOutput() );
  22838. }
  22839. return this;
  22840. },
  22841. disconnect: function () {
  22842. if ( this.filters.length > 0 ) {
  22843. this.source.disconnect( this.filters[ 0 ] );
  22844. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  22845. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  22846. }
  22847. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  22848. } else {
  22849. this.source.disconnect( this.getOutput() );
  22850. }
  22851. return this;
  22852. },
  22853. getFilters: function () {
  22854. return this.filters;
  22855. },
  22856. setFilters: function ( value ) {
  22857. if ( ! value ) value = [];
  22858. if ( this.isPlaying === true ) {
  22859. this.disconnect();
  22860. this.filters = value;
  22861. this.connect();
  22862. } else {
  22863. this.filters = value;
  22864. }
  22865. return this;
  22866. },
  22867. getFilter: function () {
  22868. return this.getFilters()[ 0 ];
  22869. },
  22870. setFilter: function ( filter ) {
  22871. return this.setFilters( filter ? [ filter ] : [] );
  22872. },
  22873. setPlaybackRate: function ( value ) {
  22874. if ( this.hasPlaybackControl === false ) {
  22875. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  22876. return;
  22877. }
  22878. this.playbackRate = value;
  22879. if ( this.isPlaying === true ) {
  22880. this.source.playbackRate.setValueAtTime( this.playbackRate, this.context.currentTime );
  22881. }
  22882. return this;
  22883. },
  22884. getPlaybackRate: function () {
  22885. return this.playbackRate;
  22886. },
  22887. onEnded: function () {
  22888. this.isPlaying = false;
  22889. },
  22890. getLoop: function () {
  22891. if ( this.hasPlaybackControl === false ) {
  22892. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  22893. return false;
  22894. }
  22895. return this.loop;
  22896. },
  22897. setLoop: function ( value ) {
  22898. if ( this.hasPlaybackControl === false ) {
  22899. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  22900. return;
  22901. }
  22902. this.loop = value;
  22903. if ( this.isPlaying === true ) {
  22904. this.source.loop = this.loop;
  22905. }
  22906. return this;
  22907. },
  22908. getVolume: function () {
  22909. return this.gain.gain.value;
  22910. },
  22911. setVolume: function ( value ) {
  22912. this.gain.gain.value = value;
  22913. return this;
  22914. }
  22915. } );
  22916. /**
  22917. * @author mrdoob / http://mrdoob.com/
  22918. */
  22919. function PositionalAudio( listener ) {
  22920. Audio.call( this, listener );
  22921. this.panner = this.context.createPanner();
  22922. this.panner.connect( this.gain );
  22923. }
  22924. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  22925. constructor: PositionalAudio,
  22926. getOutput: function () {
  22927. return this.panner;
  22928. },
  22929. getRefDistance: function () {
  22930. return this.panner.refDistance;
  22931. },
  22932. setRefDistance: function ( value ) {
  22933. this.panner.refDistance = value;
  22934. },
  22935. getRolloffFactor: function () {
  22936. return this.panner.rolloffFactor;
  22937. },
  22938. setRolloffFactor: function ( value ) {
  22939. this.panner.rolloffFactor = value;
  22940. },
  22941. getDistanceModel: function () {
  22942. return this.panner.distanceModel;
  22943. },
  22944. setDistanceModel: function ( value ) {
  22945. this.panner.distanceModel = value;
  22946. },
  22947. getMaxDistance: function () {
  22948. return this.panner.maxDistance;
  22949. },
  22950. setMaxDistance: function ( value ) {
  22951. this.panner.maxDistance = value;
  22952. },
  22953. updateMatrixWorld: ( function () {
  22954. var position = new Vector3();
  22955. return function updateMatrixWorld( force ) {
  22956. Object3D.prototype.updateMatrixWorld.call( this, force );
  22957. position.setFromMatrixPosition( this.matrixWorld );
  22958. this.panner.setPosition( position.x, position.y, position.z );
  22959. };
  22960. } )()
  22961. } );
  22962. /**
  22963. * @author mrdoob / http://mrdoob.com/
  22964. */
  22965. function AudioAnalyser( audio, fftSize ) {
  22966. this.analyser = audio.context.createAnalyser();
  22967. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  22968. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  22969. audio.getOutput().connect( this.analyser );
  22970. }
  22971. Object.assign( AudioAnalyser.prototype, {
  22972. getFrequencyData: function () {
  22973. this.analyser.getByteFrequencyData( this.data );
  22974. return this.data;
  22975. },
  22976. getAverageFrequency: function () {
  22977. var value = 0, data = this.getFrequencyData();
  22978. for ( var i = 0; i < data.length; i ++ ) {
  22979. value += data[ i ];
  22980. }
  22981. return value / data.length;
  22982. }
  22983. } );
  22984. /**
  22985. *
  22986. * Buffered scene graph property that allows weighted accumulation.
  22987. *
  22988. *
  22989. * @author Ben Houston / http://clara.io/
  22990. * @author David Sarno / http://lighthaus.us/
  22991. * @author tschw
  22992. */
  22993. function PropertyMixer( binding, typeName, valueSize ) {
  22994. this.binding = binding;
  22995. this.valueSize = valueSize;
  22996. var bufferType = Float64Array,
  22997. mixFunction;
  22998. switch ( typeName ) {
  22999. case 'quaternion':
  23000. mixFunction = this._slerp;
  23001. break;
  23002. case 'string':
  23003. case 'bool':
  23004. bufferType = Array;
  23005. mixFunction = this._select;
  23006. break;
  23007. default:
  23008. mixFunction = this._lerp;
  23009. }
  23010. this.buffer = new bufferType( valueSize * 4 );
  23011. // layout: [ incoming | accu0 | accu1 | orig ]
  23012. //
  23013. // interpolators can use .buffer as their .result
  23014. // the data then goes to 'incoming'
  23015. //
  23016. // 'accu0' and 'accu1' are used frame-interleaved for
  23017. // the cumulative result and are compared to detect
  23018. // changes
  23019. //
  23020. // 'orig' stores the original state of the property
  23021. this._mixBufferRegion = mixFunction;
  23022. this.cumulativeWeight = 0;
  23023. this.useCount = 0;
  23024. this.referenceCount = 0;
  23025. }
  23026. Object.assign( PropertyMixer.prototype, {
  23027. // accumulate data in the 'incoming' region into 'accu<i>'
  23028. accumulate: function ( accuIndex, weight ) {
  23029. // note: happily accumulating nothing when weight = 0, the caller knows
  23030. // the weight and shouldn't have made the call in the first place
  23031. var buffer = this.buffer,
  23032. stride = this.valueSize,
  23033. offset = accuIndex * stride + stride,
  23034. currentWeight = this.cumulativeWeight;
  23035. if ( currentWeight === 0 ) {
  23036. // accuN := incoming * weight
  23037. for ( var i = 0; i !== stride; ++ i ) {
  23038. buffer[ offset + i ] = buffer[ i ];
  23039. }
  23040. currentWeight = weight;
  23041. } else {
  23042. // accuN := accuN + incoming * weight
  23043. currentWeight += weight;
  23044. var mix = weight / currentWeight;
  23045. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  23046. }
  23047. this.cumulativeWeight = currentWeight;
  23048. },
  23049. // apply the state of 'accu<i>' to the binding when accus differ
  23050. apply: function ( accuIndex ) {
  23051. var stride = this.valueSize,
  23052. buffer = this.buffer,
  23053. offset = accuIndex * stride + stride,
  23054. weight = this.cumulativeWeight,
  23055. binding = this.binding;
  23056. this.cumulativeWeight = 0;
  23057. if ( weight < 1 ) {
  23058. // accuN := accuN + original * ( 1 - cumulativeWeight )
  23059. var originalValueOffset = stride * 3;
  23060. this._mixBufferRegion(
  23061. buffer, offset, originalValueOffset, 1 - weight, stride );
  23062. }
  23063. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  23064. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  23065. // value has changed -> update scene graph
  23066. binding.setValue( buffer, offset );
  23067. break;
  23068. }
  23069. }
  23070. },
  23071. // remember the state of the bound property and copy it to both accus
  23072. saveOriginalState: function () {
  23073. var binding = this.binding;
  23074. var buffer = this.buffer,
  23075. stride = this.valueSize,
  23076. originalValueOffset = stride * 3;
  23077. binding.getValue( buffer, originalValueOffset );
  23078. // accu[0..1] := orig -- initially detect changes against the original
  23079. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  23080. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  23081. }
  23082. this.cumulativeWeight = 0;
  23083. },
  23084. // apply the state previously taken via 'saveOriginalState' to the binding
  23085. restoreOriginalState: function () {
  23086. var originalValueOffset = this.valueSize * 3;
  23087. this.binding.setValue( this.buffer, originalValueOffset );
  23088. },
  23089. // mix functions
  23090. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  23091. if ( t >= 0.5 ) {
  23092. for ( var i = 0; i !== stride; ++ i ) {
  23093. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  23094. }
  23095. }
  23096. },
  23097. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  23098. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  23099. },
  23100. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  23101. var s = 1 - t;
  23102. for ( var i = 0; i !== stride; ++ i ) {
  23103. var j = dstOffset + i;
  23104. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  23105. }
  23106. }
  23107. } );
  23108. /**
  23109. *
  23110. * A reference to a real property in the scene graph.
  23111. *
  23112. *
  23113. * @author Ben Houston / http://clara.io/
  23114. * @author David Sarno / http://lighthaus.us/
  23115. * @author tschw
  23116. */
  23117. // Characters [].:/ are reserved for track binding syntax.
  23118. var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  23119. function Composite( targetGroup, path, optionalParsedPath ) {
  23120. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  23121. this._targetGroup = targetGroup;
  23122. this._bindings = targetGroup.subscribe_( path, parsedPath );
  23123. }
  23124. Object.assign( Composite.prototype, {
  23125. getValue: function ( array, offset ) {
  23126. this.bind(); // bind all binding
  23127. var firstValidIndex = this._targetGroup.nCachedObjects_,
  23128. binding = this._bindings[ firstValidIndex ];
  23129. // and only call .getValue on the first
  23130. if ( binding !== undefined ) binding.getValue( array, offset );
  23131. },
  23132. setValue: function ( array, offset ) {
  23133. var bindings = this._bindings;
  23134. for ( var i = this._targetGroup.nCachedObjects_,
  23135. n = bindings.length; i !== n; ++ i ) {
  23136. bindings[ i ].setValue( array, offset );
  23137. }
  23138. },
  23139. bind: function () {
  23140. var bindings = this._bindings;
  23141. for ( var i = this._targetGroup.nCachedObjects_,
  23142. n = bindings.length; i !== n; ++ i ) {
  23143. bindings[ i ].bind();
  23144. }
  23145. },
  23146. unbind: function () {
  23147. var bindings = this._bindings;
  23148. for ( var i = this._targetGroup.nCachedObjects_,
  23149. n = bindings.length; i !== n; ++ i ) {
  23150. bindings[ i ].unbind();
  23151. }
  23152. }
  23153. } );
  23154. function PropertyBinding( rootNode, path, parsedPath ) {
  23155. this.path = path;
  23156. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  23157. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  23158. this.rootNode = rootNode;
  23159. }
  23160. Object.assign( PropertyBinding, {
  23161. Composite: Composite,
  23162. create: function ( root, path, parsedPath ) {
  23163. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  23164. return new PropertyBinding( root, path, parsedPath );
  23165. } else {
  23166. return new PropertyBinding.Composite( root, path, parsedPath );
  23167. }
  23168. },
  23169. /**
  23170. * Replaces spaces with underscores and removes unsupported characters from
  23171. * node names, to ensure compatibility with parseTrackName().
  23172. *
  23173. * @param {string} name Node name to be sanitized.
  23174. * @return {string}
  23175. */
  23176. sanitizeNodeName: ( function () {
  23177. var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
  23178. return function sanitizeNodeName( name ) {
  23179. return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
  23180. };
  23181. }() ),
  23182. parseTrackName: function () {
  23183. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  23184. // only latin characters, and the unicode \p{L} is not yet supported. So
  23185. // instead, we exclude reserved characters and match everything else.
  23186. var wordChar = '[^' + RESERVED_CHARS_RE + ']';
  23187. var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  23188. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  23189. // be matched to parse the rest of the track name.
  23190. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  23191. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  23192. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  23193. // Object on target node, and accessor. May not contain reserved
  23194. // characters. Accessor may contain any character except closing bracket.
  23195. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  23196. // Property and accessor. May not contain reserved characters. Accessor may
  23197. // contain any non-bracket characters.
  23198. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  23199. var trackRe = new RegExp( ''
  23200. + '^'
  23201. + directoryRe
  23202. + nodeRe
  23203. + objectRe
  23204. + propertyRe
  23205. + '$'
  23206. );
  23207. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  23208. return function parseTrackName( trackName ) {
  23209. var matches = trackRe.exec( trackName );
  23210. if ( ! matches ) {
  23211. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  23212. }
  23213. var results = {
  23214. // directoryName: matches[ 1 ], // (tschw) currently unused
  23215. nodeName: matches[ 2 ],
  23216. objectName: matches[ 3 ],
  23217. objectIndex: matches[ 4 ],
  23218. propertyName: matches[ 5 ], // required
  23219. propertyIndex: matches[ 6 ]
  23220. };
  23221. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  23222. if ( lastDot !== undefined && lastDot !== - 1 ) {
  23223. var objectName = results.nodeName.substring( lastDot + 1 );
  23224. // Object names must be checked against a whitelist. Otherwise, there
  23225. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  23226. // 'bar' could be the objectName, or part of a nodeName (which can
  23227. // include '.' characters).
  23228. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  23229. results.nodeName = results.nodeName.substring( 0, lastDot );
  23230. results.objectName = objectName;
  23231. }
  23232. }
  23233. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  23234. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  23235. }
  23236. return results;
  23237. };
  23238. }(),
  23239. findNode: function ( root, nodeName ) {
  23240. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  23241. return root;
  23242. }
  23243. // search into skeleton bones.
  23244. if ( root.skeleton ) {
  23245. var bone = root.skeleton.getBoneByName( nodeName );
  23246. if ( bone !== undefined ) {
  23247. return bone;
  23248. }
  23249. }
  23250. // search into node subtree.
  23251. if ( root.children ) {
  23252. var searchNodeSubtree = function ( children ) {
  23253. for ( var i = 0; i < children.length; i ++ ) {
  23254. var childNode = children[ i ];
  23255. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  23256. return childNode;
  23257. }
  23258. var result = searchNodeSubtree( childNode.children );
  23259. if ( result ) return result;
  23260. }
  23261. return null;
  23262. };
  23263. var subTreeNode = searchNodeSubtree( root.children );
  23264. if ( subTreeNode ) {
  23265. return subTreeNode;
  23266. }
  23267. }
  23268. return null;
  23269. }
  23270. } );
  23271. Object.assign( PropertyBinding.prototype, { // prototype, continued
  23272. // these are used to "bind" a nonexistent property
  23273. _getValue_unavailable: function () {},
  23274. _setValue_unavailable: function () {},
  23275. BindingType: {
  23276. Direct: 0,
  23277. EntireArray: 1,
  23278. ArrayElement: 2,
  23279. HasFromToArray: 3
  23280. },
  23281. Versioning: {
  23282. None: 0,
  23283. NeedsUpdate: 1,
  23284. MatrixWorldNeedsUpdate: 2
  23285. },
  23286. GetterByBindingType: [
  23287. function getValue_direct( buffer, offset ) {
  23288. buffer[ offset ] = this.node[ this.propertyName ];
  23289. },
  23290. function getValue_array( buffer, offset ) {
  23291. var source = this.resolvedProperty;
  23292. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  23293. buffer[ offset ++ ] = source[ i ];
  23294. }
  23295. },
  23296. function getValue_arrayElement( buffer, offset ) {
  23297. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  23298. },
  23299. function getValue_toArray( buffer, offset ) {
  23300. this.resolvedProperty.toArray( buffer, offset );
  23301. }
  23302. ],
  23303. SetterByBindingTypeAndVersioning: [
  23304. [
  23305. // Direct
  23306. function setValue_direct( buffer, offset ) {
  23307. this.targetObject[ this.propertyName ] = buffer[ offset ];
  23308. },
  23309. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  23310. this.targetObject[ this.propertyName ] = buffer[ offset ];
  23311. this.targetObject.needsUpdate = true;
  23312. },
  23313. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23314. this.targetObject[ this.propertyName ] = buffer[ offset ];
  23315. this.targetObject.matrixWorldNeedsUpdate = true;
  23316. }
  23317. ], [
  23318. // EntireArray
  23319. function setValue_array( buffer, offset ) {
  23320. var dest = this.resolvedProperty;
  23321. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  23322. dest[ i ] = buffer[ offset ++ ];
  23323. }
  23324. },
  23325. function setValue_array_setNeedsUpdate( buffer, offset ) {
  23326. var dest = this.resolvedProperty;
  23327. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  23328. dest[ i ] = buffer[ offset ++ ];
  23329. }
  23330. this.targetObject.needsUpdate = true;
  23331. },
  23332. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23333. var dest = this.resolvedProperty;
  23334. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  23335. dest[ i ] = buffer[ offset ++ ];
  23336. }
  23337. this.targetObject.matrixWorldNeedsUpdate = true;
  23338. }
  23339. ], [
  23340. // ArrayElement
  23341. function setValue_arrayElement( buffer, offset ) {
  23342. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  23343. },
  23344. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  23345. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  23346. this.targetObject.needsUpdate = true;
  23347. },
  23348. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23349. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  23350. this.targetObject.matrixWorldNeedsUpdate = true;
  23351. }
  23352. ], [
  23353. // HasToFromArray
  23354. function setValue_fromArray( buffer, offset ) {
  23355. this.resolvedProperty.fromArray( buffer, offset );
  23356. },
  23357. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  23358. this.resolvedProperty.fromArray( buffer, offset );
  23359. this.targetObject.needsUpdate = true;
  23360. },
  23361. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23362. this.resolvedProperty.fromArray( buffer, offset );
  23363. this.targetObject.matrixWorldNeedsUpdate = true;
  23364. }
  23365. ]
  23366. ],
  23367. getValue: function getValue_unbound( targetArray, offset ) {
  23368. this.bind();
  23369. this.getValue( targetArray, offset );
  23370. // Note: This class uses a State pattern on a per-method basis:
  23371. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  23372. // prototype version of these methods with one that represents
  23373. // the bound state. When the property is not found, the methods
  23374. // become no-ops.
  23375. },
  23376. setValue: function getValue_unbound( sourceArray, offset ) {
  23377. this.bind();
  23378. this.setValue( sourceArray, offset );
  23379. },
  23380. // create getter / setter pair for a property in the scene graph
  23381. bind: function () {
  23382. var targetObject = this.node,
  23383. parsedPath = this.parsedPath,
  23384. objectName = parsedPath.objectName,
  23385. propertyName = parsedPath.propertyName,
  23386. propertyIndex = parsedPath.propertyIndex;
  23387. if ( ! targetObject ) {
  23388. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  23389. this.node = targetObject;
  23390. }
  23391. // set fail state so we can just 'return' on error
  23392. this.getValue = this._getValue_unavailable;
  23393. this.setValue = this._setValue_unavailable;
  23394. // ensure there is a value node
  23395. if ( ! targetObject ) {
  23396. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  23397. return;
  23398. }
  23399. if ( objectName ) {
  23400. var objectIndex = parsedPath.objectIndex;
  23401. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  23402. switch ( objectName ) {
  23403. case 'materials':
  23404. if ( ! targetObject.material ) {
  23405. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  23406. return;
  23407. }
  23408. if ( ! targetObject.material.materials ) {
  23409. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  23410. return;
  23411. }
  23412. targetObject = targetObject.material.materials;
  23413. break;
  23414. case 'bones':
  23415. if ( ! targetObject.skeleton ) {
  23416. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  23417. return;
  23418. }
  23419. // potential future optimization: skip this if propertyIndex is already an integer
  23420. // and convert the integer string to a true integer.
  23421. targetObject = targetObject.skeleton.bones;
  23422. // support resolving morphTarget names into indices.
  23423. for ( var i = 0; i < targetObject.length; i ++ ) {
  23424. if ( targetObject[ i ].name === objectIndex ) {
  23425. objectIndex = i;
  23426. break;
  23427. }
  23428. }
  23429. break;
  23430. default:
  23431. if ( targetObject[ objectName ] === undefined ) {
  23432. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  23433. return;
  23434. }
  23435. targetObject = targetObject[ objectName ];
  23436. }
  23437. if ( objectIndex !== undefined ) {
  23438. if ( targetObject[ objectIndex ] === undefined ) {
  23439. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  23440. return;
  23441. }
  23442. targetObject = targetObject[ objectIndex ];
  23443. }
  23444. }
  23445. // resolve property
  23446. var nodeProperty = targetObject[ propertyName ];
  23447. if ( nodeProperty === undefined ) {
  23448. var nodeName = parsedPath.nodeName;
  23449. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  23450. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  23451. return;
  23452. }
  23453. // determine versioning scheme
  23454. var versioning = this.Versioning.None;
  23455. if ( targetObject.needsUpdate !== undefined ) { // material
  23456. versioning = this.Versioning.NeedsUpdate;
  23457. this.targetObject = targetObject;
  23458. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  23459. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  23460. this.targetObject = targetObject;
  23461. }
  23462. // determine how the property gets bound
  23463. var bindingType = this.BindingType.Direct;
  23464. if ( propertyIndex !== undefined ) {
  23465. // access a sub element of the property array (only primitives are supported right now)
  23466. if ( propertyName === "morphTargetInfluences" ) {
  23467. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  23468. // support resolving morphTarget names into indices.
  23469. if ( ! targetObject.geometry ) {
  23470. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  23471. return;
  23472. }
  23473. if ( targetObject.geometry.isBufferGeometry ) {
  23474. if ( ! targetObject.geometry.morphAttributes ) {
  23475. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  23476. return;
  23477. }
  23478. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  23479. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  23480. propertyIndex = i;
  23481. break;
  23482. }
  23483. }
  23484. } else {
  23485. if ( ! targetObject.geometry.morphTargets ) {
  23486. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  23487. return;
  23488. }
  23489. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  23490. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  23491. propertyIndex = i;
  23492. break;
  23493. }
  23494. }
  23495. }
  23496. }
  23497. bindingType = this.BindingType.ArrayElement;
  23498. this.resolvedProperty = nodeProperty;
  23499. this.propertyIndex = propertyIndex;
  23500. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  23501. // must use copy for Object3D.Euler/Quaternion
  23502. bindingType = this.BindingType.HasFromToArray;
  23503. this.resolvedProperty = nodeProperty;
  23504. } else if ( Array.isArray( nodeProperty ) ) {
  23505. bindingType = this.BindingType.EntireArray;
  23506. this.resolvedProperty = nodeProperty;
  23507. } else {
  23508. this.propertyName = propertyName;
  23509. }
  23510. // select getter / setter
  23511. this.getValue = this.GetterByBindingType[ bindingType ];
  23512. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  23513. },
  23514. unbind: function () {
  23515. this.node = null;
  23516. // back to the prototype version of getValue / setValue
  23517. // note: avoiding to mutate the shape of 'this' via 'delete'
  23518. this.getValue = this._getValue_unbound;
  23519. this.setValue = this._setValue_unbound;
  23520. }
  23521. } );
  23522. //!\ DECLARE ALIAS AFTER assign prototype !
  23523. Object.assign( PropertyBinding.prototype, {
  23524. // initial state of these methods that calls 'bind'
  23525. _getValue_unbound: PropertyBinding.prototype.getValue,
  23526. _setValue_unbound: PropertyBinding.prototype.setValue,
  23527. } );
  23528. /**
  23529. *
  23530. * A group of objects that receives a shared animation state.
  23531. *
  23532. * Usage:
  23533. *
  23534. * - Add objects you would otherwise pass as 'root' to the
  23535. * constructor or the .clipAction method of AnimationMixer.
  23536. *
  23537. * - Instead pass this object as 'root'.
  23538. *
  23539. * - You can also add and remove objects later when the mixer
  23540. * is running.
  23541. *
  23542. * Note:
  23543. *
  23544. * Objects of this class appear as one object to the mixer,
  23545. * so cache control of the individual objects must be done
  23546. * on the group.
  23547. *
  23548. * Limitation:
  23549. *
  23550. * - The animated properties must be compatible among the
  23551. * all objects in the group.
  23552. *
  23553. * - A single property can either be controlled through a
  23554. * target group or directly, but not both.
  23555. *
  23556. * @author tschw
  23557. */
  23558. function AnimationObjectGroup() {
  23559. this.uuid = _Math.generateUUID();
  23560. // cached objects followed by the active ones
  23561. this._objects = Array.prototype.slice.call( arguments );
  23562. this.nCachedObjects_ = 0; // threshold
  23563. // note: read by PropertyBinding.Composite
  23564. var indices = {};
  23565. this._indicesByUUID = indices; // for bookkeeping
  23566. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  23567. indices[ arguments[ i ].uuid ] = i;
  23568. }
  23569. this._paths = []; // inside: string
  23570. this._parsedPaths = []; // inside: { we don't care, here }
  23571. this._bindings = []; // inside: Array< PropertyBinding >
  23572. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  23573. var scope = this;
  23574. this.stats = {
  23575. objects: {
  23576. get total() {
  23577. return scope._objects.length;
  23578. },
  23579. get inUse() {
  23580. return this.total - scope.nCachedObjects_;
  23581. }
  23582. },
  23583. get bindingsPerObject() {
  23584. return scope._bindings.length;
  23585. }
  23586. };
  23587. }
  23588. Object.assign( AnimationObjectGroup.prototype, {
  23589. isAnimationObjectGroup: true,
  23590. add: function () {
  23591. var objects = this._objects,
  23592. nObjects = objects.length,
  23593. nCachedObjects = this.nCachedObjects_,
  23594. indicesByUUID = this._indicesByUUID,
  23595. paths = this._paths,
  23596. parsedPaths = this._parsedPaths,
  23597. bindings = this._bindings,
  23598. nBindings = bindings.length,
  23599. knownObject = undefined;
  23600. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  23601. var object = arguments[ i ],
  23602. uuid = object.uuid,
  23603. index = indicesByUUID[ uuid ];
  23604. if ( index === undefined ) {
  23605. // unknown object -> add it to the ACTIVE region
  23606. index = nObjects ++;
  23607. indicesByUUID[ uuid ] = index;
  23608. objects.push( object );
  23609. // accounting is done, now do the same for all bindings
  23610. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  23611. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  23612. }
  23613. } else if ( index < nCachedObjects ) {
  23614. knownObject = objects[ index ];
  23615. // move existing object to the ACTIVE region
  23616. var firstActiveIndex = -- nCachedObjects,
  23617. lastCachedObject = objects[ firstActiveIndex ];
  23618. indicesByUUID[ lastCachedObject.uuid ] = index;
  23619. objects[ index ] = lastCachedObject;
  23620. indicesByUUID[ uuid ] = firstActiveIndex;
  23621. objects[ firstActiveIndex ] = object;
  23622. // accounting is done, now do the same for all bindings
  23623. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  23624. var bindingsForPath = bindings[ j ],
  23625. lastCached = bindingsForPath[ firstActiveIndex ],
  23626. binding = bindingsForPath[ index ];
  23627. bindingsForPath[ index ] = lastCached;
  23628. if ( binding === undefined ) {
  23629. // since we do not bother to create new bindings
  23630. // for objects that are cached, the binding may
  23631. // or may not exist
  23632. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  23633. }
  23634. bindingsForPath[ firstActiveIndex ] = binding;
  23635. }
  23636. } else if ( objects[ index ] !== knownObject ) {
  23637. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  23638. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  23639. } // else the object is already where we want it to be
  23640. } // for arguments
  23641. this.nCachedObjects_ = nCachedObjects;
  23642. },
  23643. remove: function () {
  23644. var objects = this._objects,
  23645. nCachedObjects = this.nCachedObjects_,
  23646. indicesByUUID = this._indicesByUUID,
  23647. bindings = this._bindings,
  23648. nBindings = bindings.length;
  23649. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  23650. var object = arguments[ i ],
  23651. uuid = object.uuid,
  23652. index = indicesByUUID[ uuid ];
  23653. if ( index !== undefined && index >= nCachedObjects ) {
  23654. // move existing object into the CACHED region
  23655. var lastCachedIndex = nCachedObjects ++,
  23656. firstActiveObject = objects[ lastCachedIndex ];
  23657. indicesByUUID[ firstActiveObject.uuid ] = index;
  23658. objects[ index ] = firstActiveObject;
  23659. indicesByUUID[ uuid ] = lastCachedIndex;
  23660. objects[ lastCachedIndex ] = object;
  23661. // accounting is done, now do the same for all bindings
  23662. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  23663. var bindingsForPath = bindings[ j ],
  23664. firstActive = bindingsForPath[ lastCachedIndex ],
  23665. binding = bindingsForPath[ index ];
  23666. bindingsForPath[ index ] = firstActive;
  23667. bindingsForPath[ lastCachedIndex ] = binding;
  23668. }
  23669. }
  23670. } // for arguments
  23671. this.nCachedObjects_ = nCachedObjects;
  23672. },
  23673. // remove & forget
  23674. uncache: function () {
  23675. var objects = this._objects,
  23676. nObjects = objects.length,
  23677. nCachedObjects = this.nCachedObjects_,
  23678. indicesByUUID = this._indicesByUUID,
  23679. bindings = this._bindings,
  23680. nBindings = bindings.length;
  23681. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  23682. var object = arguments[ i ],
  23683. uuid = object.uuid,
  23684. index = indicesByUUID[ uuid ];
  23685. if ( index !== undefined ) {
  23686. delete indicesByUUID[ uuid ];
  23687. if ( index < nCachedObjects ) {
  23688. // object is cached, shrink the CACHED region
  23689. var firstActiveIndex = -- nCachedObjects,
  23690. lastCachedObject = objects[ firstActiveIndex ],
  23691. lastIndex = -- nObjects,
  23692. lastObject = objects[ lastIndex ];
  23693. // last cached object takes this object's place
  23694. indicesByUUID[ lastCachedObject.uuid ] = index;
  23695. objects[ index ] = lastCachedObject;
  23696. // last object goes to the activated slot and pop
  23697. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  23698. objects[ firstActiveIndex ] = lastObject;
  23699. objects.pop();
  23700. // accounting is done, now do the same for all bindings
  23701. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  23702. var bindingsForPath = bindings[ j ],
  23703. lastCached = bindingsForPath[ firstActiveIndex ],
  23704. last = bindingsForPath[ lastIndex ];
  23705. bindingsForPath[ index ] = lastCached;
  23706. bindingsForPath[ firstActiveIndex ] = last;
  23707. bindingsForPath.pop();
  23708. }
  23709. } else {
  23710. // object is active, just swap with the last and pop
  23711. var lastIndex = -- nObjects,
  23712. lastObject = objects[ lastIndex ];
  23713. indicesByUUID[ lastObject.uuid ] = index;
  23714. objects[ index ] = lastObject;
  23715. objects.pop();
  23716. // accounting is done, now do the same for all bindings
  23717. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  23718. var bindingsForPath = bindings[ j ];
  23719. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  23720. bindingsForPath.pop();
  23721. }
  23722. } // cached or active
  23723. } // if object is known
  23724. } // for arguments
  23725. this.nCachedObjects_ = nCachedObjects;
  23726. },
  23727. // Internal interface used by befriended PropertyBinding.Composite:
  23728. subscribe_: function ( path, parsedPath ) {
  23729. // returns an array of bindings for the given path that is changed
  23730. // according to the contained objects in the group
  23731. var indicesByPath = this._bindingsIndicesByPath,
  23732. index = indicesByPath[ path ],
  23733. bindings = this._bindings;
  23734. if ( index !== undefined ) return bindings[ index ];
  23735. var paths = this._paths,
  23736. parsedPaths = this._parsedPaths,
  23737. objects = this._objects,
  23738. nObjects = objects.length,
  23739. nCachedObjects = this.nCachedObjects_,
  23740. bindingsForPath = new Array( nObjects );
  23741. index = bindings.length;
  23742. indicesByPath[ path ] = index;
  23743. paths.push( path );
  23744. parsedPaths.push( parsedPath );
  23745. bindings.push( bindingsForPath );
  23746. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  23747. var object = objects[ i ];
  23748. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  23749. }
  23750. return bindingsForPath;
  23751. },
  23752. unsubscribe_: function ( path ) {
  23753. // tells the group to forget about a property path and no longer
  23754. // update the array previously obtained with 'subscribe_'
  23755. var indicesByPath = this._bindingsIndicesByPath,
  23756. index = indicesByPath[ path ];
  23757. if ( index !== undefined ) {
  23758. var paths = this._paths,
  23759. parsedPaths = this._parsedPaths,
  23760. bindings = this._bindings,
  23761. lastBindingsIndex = bindings.length - 1,
  23762. lastBindings = bindings[ lastBindingsIndex ],
  23763. lastBindingsPath = path[ lastBindingsIndex ];
  23764. indicesByPath[ lastBindingsPath ] = index;
  23765. bindings[ index ] = lastBindings;
  23766. bindings.pop();
  23767. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  23768. parsedPaths.pop();
  23769. paths[ index ] = paths[ lastBindingsIndex ];
  23770. paths.pop();
  23771. }
  23772. }
  23773. } );
  23774. /**
  23775. *
  23776. * Action provided by AnimationMixer for scheduling clip playback on specific
  23777. * objects.
  23778. *
  23779. * @author Ben Houston / http://clara.io/
  23780. * @author David Sarno / http://lighthaus.us/
  23781. * @author tschw
  23782. *
  23783. */
  23784. function AnimationAction( mixer, clip, localRoot ) {
  23785. this._mixer = mixer;
  23786. this._clip = clip;
  23787. this._localRoot = localRoot || null;
  23788. var tracks = clip.tracks,
  23789. nTracks = tracks.length,
  23790. interpolants = new Array( nTracks );
  23791. var interpolantSettings = {
  23792. endingStart: ZeroCurvatureEnding,
  23793. endingEnd: ZeroCurvatureEnding
  23794. };
  23795. for ( var i = 0; i !== nTracks; ++ i ) {
  23796. var interpolant = tracks[ i ].createInterpolant( null );
  23797. interpolants[ i ] = interpolant;
  23798. interpolant.settings = interpolantSettings;
  23799. }
  23800. this._interpolantSettings = interpolantSettings;
  23801. this._interpolants = interpolants; // bound by the mixer
  23802. // inside: PropertyMixer (managed by the mixer)
  23803. this._propertyBindings = new Array( nTracks );
  23804. this._cacheIndex = null; // for the memory manager
  23805. this._byClipCacheIndex = null; // for the memory manager
  23806. this._timeScaleInterpolant = null;
  23807. this._weightInterpolant = null;
  23808. this.loop = LoopRepeat;
  23809. this._loopCount = - 1;
  23810. // global mixer time when the action is to be started
  23811. // it's set back to 'null' upon start of the action
  23812. this._startTime = null;
  23813. // scaled local time of the action
  23814. // gets clamped or wrapped to 0..clip.duration according to loop
  23815. this.time = 0;
  23816. this.timeScale = 1;
  23817. this._effectiveTimeScale = 1;
  23818. this.weight = 1;
  23819. this._effectiveWeight = 1;
  23820. this.repetitions = Infinity; // no. of repetitions when looping
  23821. this.paused = false; // true -> zero effective time scale
  23822. this.enabled = true; // false -> zero effective weight
  23823. this.clampWhenFinished = false; // keep feeding the last frame?
  23824. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  23825. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  23826. }
  23827. Object.assign( AnimationAction.prototype, {
  23828. // State & Scheduling
  23829. play: function () {
  23830. this._mixer._activateAction( this );
  23831. return this;
  23832. },
  23833. stop: function () {
  23834. this._mixer._deactivateAction( this );
  23835. return this.reset();
  23836. },
  23837. reset: function () {
  23838. this.paused = false;
  23839. this.enabled = true;
  23840. this.time = 0; // restart clip
  23841. this._loopCount = - 1; // forget previous loops
  23842. this._startTime = null; // forget scheduling
  23843. return this.stopFading().stopWarping();
  23844. },
  23845. isRunning: function () {
  23846. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  23847. this._startTime === null && this._mixer._isActiveAction( this );
  23848. },
  23849. // return true when play has been called
  23850. isScheduled: function () {
  23851. return this._mixer._isActiveAction( this );
  23852. },
  23853. startAt: function ( time ) {
  23854. this._startTime = time;
  23855. return this;
  23856. },
  23857. setLoop: function ( mode, repetitions ) {
  23858. this.loop = mode;
  23859. this.repetitions = repetitions;
  23860. return this;
  23861. },
  23862. // Weight
  23863. // set the weight stopping any scheduled fading
  23864. // although .enabled = false yields an effective weight of zero, this
  23865. // method does *not* change .enabled, because it would be confusing
  23866. setEffectiveWeight: function ( weight ) {
  23867. this.weight = weight;
  23868. // note: same logic as when updated at runtime
  23869. this._effectiveWeight = this.enabled ? weight : 0;
  23870. return this.stopFading();
  23871. },
  23872. // return the weight considering fading and .enabled
  23873. getEffectiveWeight: function () {
  23874. return this._effectiveWeight;
  23875. },
  23876. fadeIn: function ( duration ) {
  23877. return this._scheduleFading( duration, 0, 1 );
  23878. },
  23879. fadeOut: function ( duration ) {
  23880. return this._scheduleFading( duration, 1, 0 );
  23881. },
  23882. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  23883. fadeOutAction.fadeOut( duration );
  23884. this.fadeIn( duration );
  23885. if ( warp ) {
  23886. var fadeInDuration = this._clip.duration,
  23887. fadeOutDuration = fadeOutAction._clip.duration,
  23888. startEndRatio = fadeOutDuration / fadeInDuration,
  23889. endStartRatio = fadeInDuration / fadeOutDuration;
  23890. fadeOutAction.warp( 1.0, startEndRatio, duration );
  23891. this.warp( endStartRatio, 1.0, duration );
  23892. }
  23893. return this;
  23894. },
  23895. crossFadeTo: function ( fadeInAction, duration, warp ) {
  23896. return fadeInAction.crossFadeFrom( this, duration, warp );
  23897. },
  23898. stopFading: function () {
  23899. var weightInterpolant = this._weightInterpolant;
  23900. if ( weightInterpolant !== null ) {
  23901. this._weightInterpolant = null;
  23902. this._mixer._takeBackControlInterpolant( weightInterpolant );
  23903. }
  23904. return this;
  23905. },
  23906. // Time Scale Control
  23907. // set the time scale stopping any scheduled warping
  23908. // although .paused = true yields an effective time scale of zero, this
  23909. // method does *not* change .paused, because it would be confusing
  23910. setEffectiveTimeScale: function ( timeScale ) {
  23911. this.timeScale = timeScale;
  23912. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  23913. return this.stopWarping();
  23914. },
  23915. // return the time scale considering warping and .paused
  23916. getEffectiveTimeScale: function () {
  23917. return this._effectiveTimeScale;
  23918. },
  23919. setDuration: function ( duration ) {
  23920. this.timeScale = this._clip.duration / duration;
  23921. return this.stopWarping();
  23922. },
  23923. syncWith: function ( action ) {
  23924. this.time = action.time;
  23925. this.timeScale = action.timeScale;
  23926. return this.stopWarping();
  23927. },
  23928. halt: function ( duration ) {
  23929. return this.warp( this._effectiveTimeScale, 0, duration );
  23930. },
  23931. warp: function ( startTimeScale, endTimeScale, duration ) {
  23932. var mixer = this._mixer, now = mixer.time,
  23933. interpolant = this._timeScaleInterpolant,
  23934. timeScale = this.timeScale;
  23935. if ( interpolant === null ) {
  23936. interpolant = mixer._lendControlInterpolant();
  23937. this._timeScaleInterpolant = interpolant;
  23938. }
  23939. var times = interpolant.parameterPositions,
  23940. values = interpolant.sampleValues;
  23941. times[ 0 ] = now;
  23942. times[ 1 ] = now + duration;
  23943. values[ 0 ] = startTimeScale / timeScale;
  23944. values[ 1 ] = endTimeScale / timeScale;
  23945. return this;
  23946. },
  23947. stopWarping: function () {
  23948. var timeScaleInterpolant = this._timeScaleInterpolant;
  23949. if ( timeScaleInterpolant !== null ) {
  23950. this._timeScaleInterpolant = null;
  23951. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  23952. }
  23953. return this;
  23954. },
  23955. // Object Accessors
  23956. getMixer: function () {
  23957. return this._mixer;
  23958. },
  23959. getClip: function () {
  23960. return this._clip;
  23961. },
  23962. getRoot: function () {
  23963. return this._localRoot || this._mixer._root;
  23964. },
  23965. // Interna
  23966. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  23967. // called by the mixer
  23968. if ( ! this.enabled ) {
  23969. // call ._updateWeight() to update ._effectiveWeight
  23970. this._updateWeight( time );
  23971. return;
  23972. }
  23973. var startTime = this._startTime;
  23974. if ( startTime !== null ) {
  23975. // check for scheduled start of action
  23976. var timeRunning = ( time - startTime ) * timeDirection;
  23977. if ( timeRunning < 0 || timeDirection === 0 ) {
  23978. return; // yet to come / don't decide when delta = 0
  23979. }
  23980. // start
  23981. this._startTime = null; // unschedule
  23982. deltaTime = timeDirection * timeRunning;
  23983. }
  23984. // apply time scale and advance time
  23985. deltaTime *= this._updateTimeScale( time );
  23986. var clipTime = this._updateTime( deltaTime );
  23987. // note: _updateTime may disable the action resulting in
  23988. // an effective weight of 0
  23989. var weight = this._updateWeight( time );
  23990. if ( weight > 0 ) {
  23991. var interpolants = this._interpolants;
  23992. var propertyMixers = this._propertyBindings;
  23993. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  23994. interpolants[ j ].evaluate( clipTime );
  23995. propertyMixers[ j ].accumulate( accuIndex, weight );
  23996. }
  23997. }
  23998. },
  23999. _updateWeight: function ( time ) {
  24000. var weight = 0;
  24001. if ( this.enabled ) {
  24002. weight = this.weight;
  24003. var interpolant = this._weightInterpolant;
  24004. if ( interpolant !== null ) {
  24005. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  24006. weight *= interpolantValue;
  24007. if ( time > interpolant.parameterPositions[ 1 ] ) {
  24008. this.stopFading();
  24009. if ( interpolantValue === 0 ) {
  24010. // faded out, disable
  24011. this.enabled = false;
  24012. }
  24013. }
  24014. }
  24015. }
  24016. this._effectiveWeight = weight;
  24017. return weight;
  24018. },
  24019. _updateTimeScale: function ( time ) {
  24020. var timeScale = 0;
  24021. if ( ! this.paused ) {
  24022. timeScale = this.timeScale;
  24023. var interpolant = this._timeScaleInterpolant;
  24024. if ( interpolant !== null ) {
  24025. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  24026. timeScale *= interpolantValue;
  24027. if ( time > interpolant.parameterPositions[ 1 ] ) {
  24028. this.stopWarping();
  24029. if ( timeScale === 0 ) {
  24030. // motion has halted, pause
  24031. this.paused = true;
  24032. } else {
  24033. // warp done - apply final time scale
  24034. this.timeScale = timeScale;
  24035. }
  24036. }
  24037. }
  24038. }
  24039. this._effectiveTimeScale = timeScale;
  24040. return timeScale;
  24041. },
  24042. _updateTime: function ( deltaTime ) {
  24043. var time = this.time + deltaTime;
  24044. if ( deltaTime === 0 ) return time;
  24045. var duration = this._clip.duration,
  24046. loop = this.loop,
  24047. loopCount = this._loopCount;
  24048. if ( loop === LoopOnce ) {
  24049. if ( loopCount === - 1 ) {
  24050. // just started
  24051. this._loopCount = 0;
  24052. this._setEndings( true, true, false );
  24053. }
  24054. handle_stop: {
  24055. if ( time >= duration ) {
  24056. time = duration;
  24057. } else if ( time < 0 ) {
  24058. time = 0;
  24059. } else break handle_stop;
  24060. if ( this.clampWhenFinished ) this.paused = true;
  24061. else this.enabled = false;
  24062. this._mixer.dispatchEvent( {
  24063. type: 'finished', action: this,
  24064. direction: deltaTime < 0 ? - 1 : 1
  24065. } );
  24066. }
  24067. } else { // repetitive Repeat or PingPong
  24068. var pingPong = ( loop === LoopPingPong );
  24069. if ( loopCount === - 1 ) {
  24070. // just started
  24071. if ( deltaTime >= 0 ) {
  24072. loopCount = 0;
  24073. this._setEndings( true, this.repetitions === 0, pingPong );
  24074. } else {
  24075. // when looping in reverse direction, the initial
  24076. // transition through zero counts as a repetition,
  24077. // so leave loopCount at -1
  24078. this._setEndings( this.repetitions === 0, true, pingPong );
  24079. }
  24080. }
  24081. if ( time >= duration || time < 0 ) {
  24082. // wrap around
  24083. var loopDelta = Math.floor( time / duration ); // signed
  24084. time -= duration * loopDelta;
  24085. loopCount += Math.abs( loopDelta );
  24086. var pending = this.repetitions - loopCount;
  24087. if ( pending < 0 ) {
  24088. // have to stop (switch state, clamp time, fire event)
  24089. if ( this.clampWhenFinished ) this.paused = true;
  24090. else this.enabled = false;
  24091. time = deltaTime > 0 ? duration : 0;
  24092. this._mixer.dispatchEvent( {
  24093. type: 'finished', action: this,
  24094. direction: deltaTime > 0 ? 1 : - 1
  24095. } );
  24096. } else {
  24097. // keep running
  24098. if ( pending === 0 ) {
  24099. // entering the last round
  24100. var atStart = deltaTime < 0;
  24101. this._setEndings( atStart, ! atStart, pingPong );
  24102. } else {
  24103. this._setEndings( false, false, pingPong );
  24104. }
  24105. this._loopCount = loopCount;
  24106. this._mixer.dispatchEvent( {
  24107. type: 'loop', action: this, loopDelta: loopDelta
  24108. } );
  24109. }
  24110. }
  24111. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  24112. // invert time for the "pong round"
  24113. this.time = time;
  24114. return duration - time;
  24115. }
  24116. }
  24117. this.time = time;
  24118. return time;
  24119. },
  24120. _setEndings: function ( atStart, atEnd, pingPong ) {
  24121. var settings = this._interpolantSettings;
  24122. if ( pingPong ) {
  24123. settings.endingStart = ZeroSlopeEnding;
  24124. settings.endingEnd = ZeroSlopeEnding;
  24125. } else {
  24126. // assuming for LoopOnce atStart == atEnd == true
  24127. if ( atStart ) {
  24128. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  24129. } else {
  24130. settings.endingStart = WrapAroundEnding;
  24131. }
  24132. if ( atEnd ) {
  24133. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  24134. } else {
  24135. settings.endingEnd = WrapAroundEnding;
  24136. }
  24137. }
  24138. },
  24139. _scheduleFading: function ( duration, weightNow, weightThen ) {
  24140. var mixer = this._mixer, now = mixer.time,
  24141. interpolant = this._weightInterpolant;
  24142. if ( interpolant === null ) {
  24143. interpolant = mixer._lendControlInterpolant();
  24144. this._weightInterpolant = interpolant;
  24145. }
  24146. var times = interpolant.parameterPositions,
  24147. values = interpolant.sampleValues;
  24148. times[ 0 ] = now; values[ 0 ] = weightNow;
  24149. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  24150. return this;
  24151. }
  24152. } );
  24153. /**
  24154. *
  24155. * Player for AnimationClips.
  24156. *
  24157. *
  24158. * @author Ben Houston / http://clara.io/
  24159. * @author David Sarno / http://lighthaus.us/
  24160. * @author tschw
  24161. */
  24162. function AnimationMixer( root ) {
  24163. this._root = root;
  24164. this._initMemoryManager();
  24165. this._accuIndex = 0;
  24166. this.time = 0;
  24167. this.timeScale = 1.0;
  24168. }
  24169. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  24170. constructor: AnimationMixer,
  24171. _bindAction: function ( action, prototypeAction ) {
  24172. var root = action._localRoot || this._root,
  24173. tracks = action._clip.tracks,
  24174. nTracks = tracks.length,
  24175. bindings = action._propertyBindings,
  24176. interpolants = action._interpolants,
  24177. rootUuid = root.uuid,
  24178. bindingsByRoot = this._bindingsByRootAndName,
  24179. bindingsByName = bindingsByRoot[ rootUuid ];
  24180. if ( bindingsByName === undefined ) {
  24181. bindingsByName = {};
  24182. bindingsByRoot[ rootUuid ] = bindingsByName;
  24183. }
  24184. for ( var i = 0; i !== nTracks; ++ i ) {
  24185. var track = tracks[ i ],
  24186. trackName = track.name,
  24187. binding = bindingsByName[ trackName ];
  24188. if ( binding !== undefined ) {
  24189. bindings[ i ] = binding;
  24190. } else {
  24191. binding = bindings[ i ];
  24192. if ( binding !== undefined ) {
  24193. // existing binding, make sure the cache knows
  24194. if ( binding._cacheIndex === null ) {
  24195. ++ binding.referenceCount;
  24196. this._addInactiveBinding( binding, rootUuid, trackName );
  24197. }
  24198. continue;
  24199. }
  24200. var path = prototypeAction && prototypeAction.
  24201. _propertyBindings[ i ].binding.parsedPath;
  24202. binding = new PropertyMixer(
  24203. PropertyBinding.create( root, trackName, path ),
  24204. track.ValueTypeName, track.getValueSize() );
  24205. ++ binding.referenceCount;
  24206. this._addInactiveBinding( binding, rootUuid, trackName );
  24207. bindings[ i ] = binding;
  24208. }
  24209. interpolants[ i ].resultBuffer = binding.buffer;
  24210. }
  24211. },
  24212. _activateAction: function ( action ) {
  24213. if ( ! this._isActiveAction( action ) ) {
  24214. if ( action._cacheIndex === null ) {
  24215. // this action has been forgotten by the cache, but the user
  24216. // appears to be still using it -> rebind
  24217. var rootUuid = ( action._localRoot || this._root ).uuid,
  24218. clipUuid = action._clip.uuid,
  24219. actionsForClip = this._actionsByClip[ clipUuid ];
  24220. this._bindAction( action,
  24221. actionsForClip && actionsForClip.knownActions[ 0 ] );
  24222. this._addInactiveAction( action, clipUuid, rootUuid );
  24223. }
  24224. var bindings = action._propertyBindings;
  24225. // increment reference counts / sort out state
  24226. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  24227. var binding = bindings[ i ];
  24228. if ( binding.useCount ++ === 0 ) {
  24229. this._lendBinding( binding );
  24230. binding.saveOriginalState();
  24231. }
  24232. }
  24233. this._lendAction( action );
  24234. }
  24235. },
  24236. _deactivateAction: function ( action ) {
  24237. if ( this._isActiveAction( action ) ) {
  24238. var bindings = action._propertyBindings;
  24239. // decrement reference counts / sort out state
  24240. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  24241. var binding = bindings[ i ];
  24242. if ( -- binding.useCount === 0 ) {
  24243. binding.restoreOriginalState();
  24244. this._takeBackBinding( binding );
  24245. }
  24246. }
  24247. this._takeBackAction( action );
  24248. }
  24249. },
  24250. // Memory manager
  24251. _initMemoryManager: function () {
  24252. this._actions = []; // 'nActiveActions' followed by inactive ones
  24253. this._nActiveActions = 0;
  24254. this._actionsByClip = {};
  24255. // inside:
  24256. // {
  24257. // knownActions: Array< AnimationAction > - used as prototypes
  24258. // actionByRoot: AnimationAction - lookup
  24259. // }
  24260. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  24261. this._nActiveBindings = 0;
  24262. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  24263. this._controlInterpolants = []; // same game as above
  24264. this._nActiveControlInterpolants = 0;
  24265. var scope = this;
  24266. this.stats = {
  24267. actions: {
  24268. get total() {
  24269. return scope._actions.length;
  24270. },
  24271. get inUse() {
  24272. return scope._nActiveActions;
  24273. }
  24274. },
  24275. bindings: {
  24276. get total() {
  24277. return scope._bindings.length;
  24278. },
  24279. get inUse() {
  24280. return scope._nActiveBindings;
  24281. }
  24282. },
  24283. controlInterpolants: {
  24284. get total() {
  24285. return scope._controlInterpolants.length;
  24286. },
  24287. get inUse() {
  24288. return scope._nActiveControlInterpolants;
  24289. }
  24290. }
  24291. };
  24292. },
  24293. // Memory management for AnimationAction objects
  24294. _isActiveAction: function ( action ) {
  24295. var index = action._cacheIndex;
  24296. return index !== null && index < this._nActiveActions;
  24297. },
  24298. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  24299. var actions = this._actions,
  24300. actionsByClip = this._actionsByClip,
  24301. actionsForClip = actionsByClip[ clipUuid ];
  24302. if ( actionsForClip === undefined ) {
  24303. actionsForClip = {
  24304. knownActions: [ action ],
  24305. actionByRoot: {}
  24306. };
  24307. action._byClipCacheIndex = 0;
  24308. actionsByClip[ clipUuid ] = actionsForClip;
  24309. } else {
  24310. var knownActions = actionsForClip.knownActions;
  24311. action._byClipCacheIndex = knownActions.length;
  24312. knownActions.push( action );
  24313. }
  24314. action._cacheIndex = actions.length;
  24315. actions.push( action );
  24316. actionsForClip.actionByRoot[ rootUuid ] = action;
  24317. },
  24318. _removeInactiveAction: function ( action ) {
  24319. var actions = this._actions,
  24320. lastInactiveAction = actions[ actions.length - 1 ],
  24321. cacheIndex = action._cacheIndex;
  24322. lastInactiveAction._cacheIndex = cacheIndex;
  24323. actions[ cacheIndex ] = lastInactiveAction;
  24324. actions.pop();
  24325. action._cacheIndex = null;
  24326. var clipUuid = action._clip.uuid,
  24327. actionsByClip = this._actionsByClip,
  24328. actionsForClip = actionsByClip[ clipUuid ],
  24329. knownActionsForClip = actionsForClip.knownActions,
  24330. lastKnownAction =
  24331. knownActionsForClip[ knownActionsForClip.length - 1 ],
  24332. byClipCacheIndex = action._byClipCacheIndex;
  24333. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  24334. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  24335. knownActionsForClip.pop();
  24336. action._byClipCacheIndex = null;
  24337. var actionByRoot = actionsForClip.actionByRoot,
  24338. rootUuid = ( action._localRoot || this._root ).uuid;
  24339. delete actionByRoot[ rootUuid ];
  24340. if ( knownActionsForClip.length === 0 ) {
  24341. delete actionsByClip[ clipUuid ];
  24342. }
  24343. this._removeInactiveBindingsForAction( action );
  24344. },
  24345. _removeInactiveBindingsForAction: function ( action ) {
  24346. var bindings = action._propertyBindings;
  24347. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  24348. var binding = bindings[ i ];
  24349. if ( -- binding.referenceCount === 0 ) {
  24350. this._removeInactiveBinding( binding );
  24351. }
  24352. }
  24353. },
  24354. _lendAction: function ( action ) {
  24355. // [ active actions | inactive actions ]
  24356. // [ active actions >| inactive actions ]
  24357. // s a
  24358. // <-swap->
  24359. // a s
  24360. var actions = this._actions,
  24361. prevIndex = action._cacheIndex,
  24362. lastActiveIndex = this._nActiveActions ++,
  24363. firstInactiveAction = actions[ lastActiveIndex ];
  24364. action._cacheIndex = lastActiveIndex;
  24365. actions[ lastActiveIndex ] = action;
  24366. firstInactiveAction._cacheIndex = prevIndex;
  24367. actions[ prevIndex ] = firstInactiveAction;
  24368. },
  24369. _takeBackAction: function ( action ) {
  24370. // [ active actions | inactive actions ]
  24371. // [ active actions |< inactive actions ]
  24372. // a s
  24373. // <-swap->
  24374. // s a
  24375. var actions = this._actions,
  24376. prevIndex = action._cacheIndex,
  24377. firstInactiveIndex = -- this._nActiveActions,
  24378. lastActiveAction = actions[ firstInactiveIndex ];
  24379. action._cacheIndex = firstInactiveIndex;
  24380. actions[ firstInactiveIndex ] = action;
  24381. lastActiveAction._cacheIndex = prevIndex;
  24382. actions[ prevIndex ] = lastActiveAction;
  24383. },
  24384. // Memory management for PropertyMixer objects
  24385. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  24386. var bindingsByRoot = this._bindingsByRootAndName,
  24387. bindingByName = bindingsByRoot[ rootUuid ],
  24388. bindings = this._bindings;
  24389. if ( bindingByName === undefined ) {
  24390. bindingByName = {};
  24391. bindingsByRoot[ rootUuid ] = bindingByName;
  24392. }
  24393. bindingByName[ trackName ] = binding;
  24394. binding._cacheIndex = bindings.length;
  24395. bindings.push( binding );
  24396. },
  24397. _removeInactiveBinding: function ( binding ) {
  24398. var bindings = this._bindings,
  24399. propBinding = binding.binding,
  24400. rootUuid = propBinding.rootNode.uuid,
  24401. trackName = propBinding.path,
  24402. bindingsByRoot = this._bindingsByRootAndName,
  24403. bindingByName = bindingsByRoot[ rootUuid ],
  24404. lastInactiveBinding = bindings[ bindings.length - 1 ],
  24405. cacheIndex = binding._cacheIndex;
  24406. lastInactiveBinding._cacheIndex = cacheIndex;
  24407. bindings[ cacheIndex ] = lastInactiveBinding;
  24408. bindings.pop();
  24409. delete bindingByName[ trackName ];
  24410. remove_empty_map: {
  24411. for ( var _ in bindingByName ) break remove_empty_map; // eslint-disable-line no-unused-vars
  24412. delete bindingsByRoot[ rootUuid ];
  24413. }
  24414. },
  24415. _lendBinding: function ( binding ) {
  24416. var bindings = this._bindings,
  24417. prevIndex = binding._cacheIndex,
  24418. lastActiveIndex = this._nActiveBindings ++,
  24419. firstInactiveBinding = bindings[ lastActiveIndex ];
  24420. binding._cacheIndex = lastActiveIndex;
  24421. bindings[ lastActiveIndex ] = binding;
  24422. firstInactiveBinding._cacheIndex = prevIndex;
  24423. bindings[ prevIndex ] = firstInactiveBinding;
  24424. },
  24425. _takeBackBinding: function ( binding ) {
  24426. var bindings = this._bindings,
  24427. prevIndex = binding._cacheIndex,
  24428. firstInactiveIndex = -- this._nActiveBindings,
  24429. lastActiveBinding = bindings[ firstInactiveIndex ];
  24430. binding._cacheIndex = firstInactiveIndex;
  24431. bindings[ firstInactiveIndex ] = binding;
  24432. lastActiveBinding._cacheIndex = prevIndex;
  24433. bindings[ prevIndex ] = lastActiveBinding;
  24434. },
  24435. // Memory management of Interpolants for weight and time scale
  24436. _lendControlInterpolant: function () {
  24437. var interpolants = this._controlInterpolants,
  24438. lastActiveIndex = this._nActiveControlInterpolants ++,
  24439. interpolant = interpolants[ lastActiveIndex ];
  24440. if ( interpolant === undefined ) {
  24441. interpolant = new LinearInterpolant(
  24442. new Float32Array( 2 ), new Float32Array( 2 ),
  24443. 1, this._controlInterpolantsResultBuffer );
  24444. interpolant.__cacheIndex = lastActiveIndex;
  24445. interpolants[ lastActiveIndex ] = interpolant;
  24446. }
  24447. return interpolant;
  24448. },
  24449. _takeBackControlInterpolant: function ( interpolant ) {
  24450. var interpolants = this._controlInterpolants,
  24451. prevIndex = interpolant.__cacheIndex,
  24452. firstInactiveIndex = -- this._nActiveControlInterpolants,
  24453. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  24454. interpolant.__cacheIndex = firstInactiveIndex;
  24455. interpolants[ firstInactiveIndex ] = interpolant;
  24456. lastActiveInterpolant.__cacheIndex = prevIndex;
  24457. interpolants[ prevIndex ] = lastActiveInterpolant;
  24458. },
  24459. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  24460. // return an action for a clip optionally using a custom root target
  24461. // object (this method allocates a lot of dynamic memory in case a
  24462. // previously unknown clip/root combination is specified)
  24463. clipAction: function ( clip, optionalRoot ) {
  24464. var root = optionalRoot || this._root,
  24465. rootUuid = root.uuid,
  24466. clipObject = typeof clip === 'string' ?
  24467. AnimationClip.findByName( root, clip ) : clip,
  24468. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  24469. actionsForClip = this._actionsByClip[ clipUuid ],
  24470. prototypeAction = null;
  24471. if ( actionsForClip !== undefined ) {
  24472. var existingAction =
  24473. actionsForClip.actionByRoot[ rootUuid ];
  24474. if ( existingAction !== undefined ) {
  24475. return existingAction;
  24476. }
  24477. // we know the clip, so we don't have to parse all
  24478. // the bindings again but can just copy
  24479. prototypeAction = actionsForClip.knownActions[ 0 ];
  24480. // also, take the clip from the prototype action
  24481. if ( clipObject === null )
  24482. clipObject = prototypeAction._clip;
  24483. }
  24484. // clip must be known when specified via string
  24485. if ( clipObject === null ) return null;
  24486. // allocate all resources required to run it
  24487. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  24488. this._bindAction( newAction, prototypeAction );
  24489. // and make the action known to the memory manager
  24490. this._addInactiveAction( newAction, clipUuid, rootUuid );
  24491. return newAction;
  24492. },
  24493. // get an existing action
  24494. existingAction: function ( clip, optionalRoot ) {
  24495. var root = optionalRoot || this._root,
  24496. rootUuid = root.uuid,
  24497. clipObject = typeof clip === 'string' ?
  24498. AnimationClip.findByName( root, clip ) : clip,
  24499. clipUuid = clipObject ? clipObject.uuid : clip,
  24500. actionsForClip = this._actionsByClip[ clipUuid ];
  24501. if ( actionsForClip !== undefined ) {
  24502. return actionsForClip.actionByRoot[ rootUuid ] || null;
  24503. }
  24504. return null;
  24505. },
  24506. // deactivates all previously scheduled actions
  24507. stopAllAction: function () {
  24508. var actions = this._actions,
  24509. nActions = this._nActiveActions,
  24510. bindings = this._bindings,
  24511. nBindings = this._nActiveBindings;
  24512. this._nActiveActions = 0;
  24513. this._nActiveBindings = 0;
  24514. for ( var i = 0; i !== nActions; ++ i ) {
  24515. actions[ i ].reset();
  24516. }
  24517. for ( var i = 0; i !== nBindings; ++ i ) {
  24518. bindings[ i ].useCount = 0;
  24519. }
  24520. return this;
  24521. },
  24522. // advance the time and update apply the animation
  24523. update: function ( deltaTime ) {
  24524. deltaTime *= this.timeScale;
  24525. var actions = this._actions,
  24526. nActions = this._nActiveActions,
  24527. time = this.time += deltaTime,
  24528. timeDirection = Math.sign( deltaTime ),
  24529. accuIndex = this._accuIndex ^= 1;
  24530. // run active actions
  24531. for ( var i = 0; i !== nActions; ++ i ) {
  24532. var action = actions[ i ];
  24533. action._update( time, deltaTime, timeDirection, accuIndex );
  24534. }
  24535. // update scene graph
  24536. var bindings = this._bindings,
  24537. nBindings = this._nActiveBindings;
  24538. for ( var i = 0; i !== nBindings; ++ i ) {
  24539. bindings[ i ].apply( accuIndex );
  24540. }
  24541. return this;
  24542. },
  24543. // return this mixer's root target object
  24544. getRoot: function () {
  24545. return this._root;
  24546. },
  24547. // free all resources specific to a particular clip
  24548. uncacheClip: function ( clip ) {
  24549. var actions = this._actions,
  24550. clipUuid = clip.uuid,
  24551. actionsByClip = this._actionsByClip,
  24552. actionsForClip = actionsByClip[ clipUuid ];
  24553. if ( actionsForClip !== undefined ) {
  24554. // note: just calling _removeInactiveAction would mess up the
  24555. // iteration state and also require updating the state we can
  24556. // just throw away
  24557. var actionsToRemove = actionsForClip.knownActions;
  24558. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  24559. var action = actionsToRemove[ i ];
  24560. this._deactivateAction( action );
  24561. var cacheIndex = action._cacheIndex,
  24562. lastInactiveAction = actions[ actions.length - 1 ];
  24563. action._cacheIndex = null;
  24564. action._byClipCacheIndex = null;
  24565. lastInactiveAction._cacheIndex = cacheIndex;
  24566. actions[ cacheIndex ] = lastInactiveAction;
  24567. actions.pop();
  24568. this._removeInactiveBindingsForAction( action );
  24569. }
  24570. delete actionsByClip[ clipUuid ];
  24571. }
  24572. },
  24573. // free all resources specific to a particular root target object
  24574. uncacheRoot: function ( root ) {
  24575. var rootUuid = root.uuid,
  24576. actionsByClip = this._actionsByClip;
  24577. for ( var clipUuid in actionsByClip ) {
  24578. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  24579. action = actionByRoot[ rootUuid ];
  24580. if ( action !== undefined ) {
  24581. this._deactivateAction( action );
  24582. this._removeInactiveAction( action );
  24583. }
  24584. }
  24585. var bindingsByRoot = this._bindingsByRootAndName,
  24586. bindingByName = bindingsByRoot[ rootUuid ];
  24587. if ( bindingByName !== undefined ) {
  24588. for ( var trackName in bindingByName ) {
  24589. var binding = bindingByName[ trackName ];
  24590. binding.restoreOriginalState();
  24591. this._removeInactiveBinding( binding );
  24592. }
  24593. }
  24594. },
  24595. // remove a targeted clip from the cache
  24596. uncacheAction: function ( clip, optionalRoot ) {
  24597. var action = this.existingAction( clip, optionalRoot );
  24598. if ( action !== null ) {
  24599. this._deactivateAction( action );
  24600. this._removeInactiveAction( action );
  24601. }
  24602. }
  24603. } );
  24604. /**
  24605. * @author mrdoob / http://mrdoob.com/
  24606. */
  24607. function Uniform( value ) {
  24608. if ( typeof value === 'string' ) {
  24609. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  24610. value = arguments[ 1 ];
  24611. }
  24612. this.value = value;
  24613. }
  24614. Uniform.prototype.clone = function () {
  24615. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  24616. };
  24617. /**
  24618. * @author benaadams / https://twitter.com/ben_a_adams
  24619. */
  24620. function InstancedBufferGeometry() {
  24621. BufferGeometry.call( this );
  24622. this.type = 'InstancedBufferGeometry';
  24623. this.maxInstancedCount = undefined;
  24624. }
  24625. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  24626. constructor: InstancedBufferGeometry,
  24627. isInstancedBufferGeometry: true,
  24628. copy: function ( source ) {
  24629. BufferGeometry.prototype.copy.call( this, source );
  24630. this.maxInstancedCount = source.maxInstancedCount;
  24631. return this;
  24632. },
  24633. clone: function () {
  24634. return new this.constructor().copy( this );
  24635. }
  24636. } );
  24637. /**
  24638. * @author benaadams / https://twitter.com/ben_a_adams
  24639. */
  24640. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  24641. this.uuid = _Math.generateUUID();
  24642. this.data = interleavedBuffer;
  24643. this.itemSize = itemSize;
  24644. this.offset = offset;
  24645. this.normalized = normalized === true;
  24646. }
  24647. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  24648. count: {
  24649. get: function () {
  24650. return this.data.count;
  24651. }
  24652. },
  24653. array: {
  24654. get: function () {
  24655. return this.data.array;
  24656. }
  24657. }
  24658. } );
  24659. Object.assign( InterleavedBufferAttribute.prototype, {
  24660. isInterleavedBufferAttribute: true,
  24661. setX: function ( index, x ) {
  24662. this.data.array[ index * this.data.stride + this.offset ] = x;
  24663. return this;
  24664. },
  24665. setY: function ( index, y ) {
  24666. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  24667. return this;
  24668. },
  24669. setZ: function ( index, z ) {
  24670. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  24671. return this;
  24672. },
  24673. setW: function ( index, w ) {
  24674. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  24675. return this;
  24676. },
  24677. getX: function ( index ) {
  24678. return this.data.array[ index * this.data.stride + this.offset ];
  24679. },
  24680. getY: function ( index ) {
  24681. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  24682. },
  24683. getZ: function ( index ) {
  24684. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  24685. },
  24686. getW: function ( index ) {
  24687. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  24688. },
  24689. setXY: function ( index, x, y ) {
  24690. index = index * this.data.stride + this.offset;
  24691. this.data.array[ index + 0 ] = x;
  24692. this.data.array[ index + 1 ] = y;
  24693. return this;
  24694. },
  24695. setXYZ: function ( index, x, y, z ) {
  24696. index = index * this.data.stride + this.offset;
  24697. this.data.array[ index + 0 ] = x;
  24698. this.data.array[ index + 1 ] = y;
  24699. this.data.array[ index + 2 ] = z;
  24700. return this;
  24701. },
  24702. setXYZW: function ( index, x, y, z, w ) {
  24703. index = index * this.data.stride + this.offset;
  24704. this.data.array[ index + 0 ] = x;
  24705. this.data.array[ index + 1 ] = y;
  24706. this.data.array[ index + 2 ] = z;
  24707. this.data.array[ index + 3 ] = w;
  24708. return this;
  24709. }
  24710. } );
  24711. /**
  24712. * @author benaadams / https://twitter.com/ben_a_adams
  24713. */
  24714. function InterleavedBuffer( array, stride ) {
  24715. this.uuid = _Math.generateUUID();
  24716. this.array = array;
  24717. this.stride = stride;
  24718. this.count = array !== undefined ? array.length / stride : 0;
  24719. this.dynamic = false;
  24720. this.updateRange = { offset: 0, count: - 1 };
  24721. this.onUploadCallback = function () {};
  24722. this.version = 0;
  24723. }
  24724. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  24725. set: function ( value ) {
  24726. if ( value === true ) this.version ++;
  24727. }
  24728. } );
  24729. Object.assign( InterleavedBuffer.prototype, {
  24730. isInterleavedBuffer: true,
  24731. setArray: function ( array ) {
  24732. if ( Array.isArray( array ) ) {
  24733. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  24734. }
  24735. this.count = array !== undefined ? array.length / this.stride : 0;
  24736. this.array = array;
  24737. },
  24738. setDynamic: function ( value ) {
  24739. this.dynamic = value;
  24740. return this;
  24741. },
  24742. copy: function ( source ) {
  24743. this.array = new source.array.constructor( source.array );
  24744. this.count = source.count;
  24745. this.stride = source.stride;
  24746. this.dynamic = source.dynamic;
  24747. return this;
  24748. },
  24749. copyAt: function ( index1, attribute, index2 ) {
  24750. index1 *= this.stride;
  24751. index2 *= attribute.stride;
  24752. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  24753. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  24754. }
  24755. return this;
  24756. },
  24757. set: function ( value, offset ) {
  24758. if ( offset === undefined ) offset = 0;
  24759. this.array.set( value, offset );
  24760. return this;
  24761. },
  24762. clone: function () {
  24763. return new this.constructor().copy( this );
  24764. },
  24765. onUpload: function ( callback ) {
  24766. this.onUploadCallback = callback;
  24767. return this;
  24768. }
  24769. } );
  24770. /**
  24771. * @author benaadams / https://twitter.com/ben_a_adams
  24772. */
  24773. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  24774. InterleavedBuffer.call( this, array, stride );
  24775. this.meshPerAttribute = meshPerAttribute || 1;
  24776. }
  24777. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  24778. constructor: InstancedInterleavedBuffer,
  24779. isInstancedInterleavedBuffer: true,
  24780. copy: function ( source ) {
  24781. InterleavedBuffer.prototype.copy.call( this, source );
  24782. this.meshPerAttribute = source.meshPerAttribute;
  24783. return this;
  24784. }
  24785. } );
  24786. /**
  24787. * @author benaadams / https://twitter.com/ben_a_adams
  24788. */
  24789. function InstancedBufferAttribute( array, itemSize, meshPerAttribute ) {
  24790. BufferAttribute.call( this, array, itemSize );
  24791. this.meshPerAttribute = meshPerAttribute || 1;
  24792. }
  24793. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  24794. constructor: InstancedBufferAttribute,
  24795. isInstancedBufferAttribute: true,
  24796. copy: function ( source ) {
  24797. BufferAttribute.prototype.copy.call( this, source );
  24798. this.meshPerAttribute = source.meshPerAttribute;
  24799. return this;
  24800. }
  24801. } );
  24802. /**
  24803. * @author mrdoob / http://mrdoob.com/
  24804. * @author bhouston / http://clara.io/
  24805. * @author stephomi / http://stephaneginier.com/
  24806. */
  24807. function Raycaster( origin, direction, near, far ) {
  24808. this.ray = new Ray( origin, direction );
  24809. // direction is assumed to be normalized (for accurate distance calculations)
  24810. this.near = near || 0;
  24811. this.far = far || Infinity;
  24812. this.params = {
  24813. Mesh: {},
  24814. Line: {},
  24815. LOD: {},
  24816. Points: { threshold: 1 },
  24817. Sprite: {}
  24818. };
  24819. Object.defineProperties( this.params, {
  24820. PointCloud: {
  24821. get: function () {
  24822. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  24823. return this.Points;
  24824. }
  24825. }
  24826. } );
  24827. }
  24828. function ascSort( a, b ) {
  24829. return a.distance - b.distance;
  24830. }
  24831. function intersectObject( object, raycaster, intersects, recursive ) {
  24832. if ( object.visible === false ) return;
  24833. object.raycast( raycaster, intersects );
  24834. if ( recursive === true ) {
  24835. var children = object.children;
  24836. for ( var i = 0, l = children.length; i < l; i ++ ) {
  24837. intersectObject( children[ i ], raycaster, intersects, true );
  24838. }
  24839. }
  24840. }
  24841. Object.assign( Raycaster.prototype, {
  24842. linePrecision: 1,
  24843. set: function ( origin, direction ) {
  24844. // direction is assumed to be normalized (for accurate distance calculations)
  24845. this.ray.set( origin, direction );
  24846. },
  24847. setFromCamera: function ( coords, camera ) {
  24848. if ( ( camera && camera.isPerspectiveCamera ) ) {
  24849. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  24850. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  24851. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  24852. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  24853. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  24854. } else {
  24855. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  24856. }
  24857. },
  24858. intersectObject: function ( object, recursive ) {
  24859. var intersects = [];
  24860. intersectObject( object, this, intersects, recursive );
  24861. intersects.sort( ascSort );
  24862. return intersects;
  24863. },
  24864. intersectObjects: function ( objects, recursive ) {
  24865. var intersects = [];
  24866. if ( Array.isArray( objects ) === false ) {
  24867. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  24868. return intersects;
  24869. }
  24870. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  24871. intersectObject( objects[ i ], this, intersects, recursive );
  24872. }
  24873. intersects.sort( ascSort );
  24874. return intersects;
  24875. }
  24876. } );
  24877. /**
  24878. * @author alteredq / http://alteredqualia.com/
  24879. */
  24880. function Clock( autoStart ) {
  24881. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  24882. this.startTime = 0;
  24883. this.oldTime = 0;
  24884. this.elapsedTime = 0;
  24885. this.running = false;
  24886. }
  24887. Object.assign( Clock.prototype, {
  24888. start: function () {
  24889. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  24890. this.oldTime = this.startTime;
  24891. this.elapsedTime = 0;
  24892. this.running = true;
  24893. },
  24894. stop: function () {
  24895. this.getElapsedTime();
  24896. this.running = false;
  24897. this.autoStart = false;
  24898. },
  24899. getElapsedTime: function () {
  24900. this.getDelta();
  24901. return this.elapsedTime;
  24902. },
  24903. getDelta: function () {
  24904. var diff = 0;
  24905. if ( this.autoStart && ! this.running ) {
  24906. this.start();
  24907. return 0;
  24908. }
  24909. if ( this.running ) {
  24910. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  24911. diff = ( newTime - this.oldTime ) / 1000;
  24912. this.oldTime = newTime;
  24913. this.elapsedTime += diff;
  24914. }
  24915. return diff;
  24916. }
  24917. } );
  24918. /**
  24919. * @author bhouston / http://clara.io
  24920. * @author WestLangley / http://github.com/WestLangley
  24921. *
  24922. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  24923. *
  24924. * The poles (phi) are at the positive and negative y axis.
  24925. * The equator starts at positive z.
  24926. */
  24927. function Spherical( radius, phi, theta ) {
  24928. this.radius = ( radius !== undefined ) ? radius : 1.0;
  24929. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  24930. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  24931. return this;
  24932. }
  24933. Object.assign( Spherical.prototype, {
  24934. set: function ( radius, phi, theta ) {
  24935. this.radius = radius;
  24936. this.phi = phi;
  24937. this.theta = theta;
  24938. return this;
  24939. },
  24940. clone: function () {
  24941. return new this.constructor().copy( this );
  24942. },
  24943. copy: function ( other ) {
  24944. this.radius = other.radius;
  24945. this.phi = other.phi;
  24946. this.theta = other.theta;
  24947. return this;
  24948. },
  24949. // restrict phi to be betwee EPS and PI-EPS
  24950. makeSafe: function () {
  24951. var EPS = 0.000001;
  24952. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  24953. return this;
  24954. },
  24955. setFromVector3: function ( vec3 ) {
  24956. this.radius = vec3.length();
  24957. if ( this.radius === 0 ) {
  24958. this.theta = 0;
  24959. this.phi = 0;
  24960. } else {
  24961. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  24962. this.phi = Math.acos( _Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  24963. }
  24964. return this;
  24965. }
  24966. } );
  24967. /**
  24968. * @author Mugen87 / https://github.com/Mugen87
  24969. *
  24970. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  24971. *
  24972. */
  24973. function Cylindrical( radius, theta, y ) {
  24974. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  24975. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  24976. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  24977. return this;
  24978. }
  24979. Object.assign( Cylindrical.prototype, {
  24980. set: function ( radius, theta, y ) {
  24981. this.radius = radius;
  24982. this.theta = theta;
  24983. this.y = y;
  24984. return this;
  24985. },
  24986. clone: function () {
  24987. return new this.constructor().copy( this );
  24988. },
  24989. copy: function ( other ) {
  24990. this.radius = other.radius;
  24991. this.theta = other.theta;
  24992. this.y = other.y;
  24993. return this;
  24994. },
  24995. setFromVector3: function ( vec3 ) {
  24996. this.radius = Math.sqrt( vec3.x * vec3.x + vec3.z * vec3.z );
  24997. this.theta = Math.atan2( vec3.x, vec3.z );
  24998. this.y = vec3.y;
  24999. return this;
  25000. }
  25001. } );
  25002. /**
  25003. * @author bhouston / http://clara.io
  25004. */
  25005. function Box2( min, max ) {
  25006. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  25007. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  25008. }
  25009. Object.assign( Box2.prototype, {
  25010. set: function ( min, max ) {
  25011. this.min.copy( min );
  25012. this.max.copy( max );
  25013. return this;
  25014. },
  25015. setFromPoints: function ( points ) {
  25016. this.makeEmpty();
  25017. for ( var i = 0, il = points.length; i < il; i ++ ) {
  25018. this.expandByPoint( points[ i ] );
  25019. }
  25020. return this;
  25021. },
  25022. setFromCenterAndSize: function () {
  25023. var v1 = new Vector2();
  25024. return function setFromCenterAndSize( center, size ) {
  25025. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  25026. this.min.copy( center ).sub( halfSize );
  25027. this.max.copy( center ).add( halfSize );
  25028. return this;
  25029. };
  25030. }(),
  25031. clone: function () {
  25032. return new this.constructor().copy( this );
  25033. },
  25034. copy: function ( box ) {
  25035. this.min.copy( box.min );
  25036. this.max.copy( box.max );
  25037. return this;
  25038. },
  25039. makeEmpty: function () {
  25040. this.min.x = this.min.y = + Infinity;
  25041. this.max.x = this.max.y = - Infinity;
  25042. return this;
  25043. },
  25044. isEmpty: function () {
  25045. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  25046. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  25047. },
  25048. getCenter: function ( optionalTarget ) {
  25049. var result = optionalTarget || new Vector2();
  25050. return this.isEmpty() ? result.set( 0, 0 ) : result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  25051. },
  25052. getSize: function ( optionalTarget ) {
  25053. var result = optionalTarget || new Vector2();
  25054. return this.isEmpty() ? result.set( 0, 0 ) : result.subVectors( this.max, this.min );
  25055. },
  25056. expandByPoint: function ( point ) {
  25057. this.min.min( point );
  25058. this.max.max( point );
  25059. return this;
  25060. },
  25061. expandByVector: function ( vector ) {
  25062. this.min.sub( vector );
  25063. this.max.add( vector );
  25064. return this;
  25065. },
  25066. expandByScalar: function ( scalar ) {
  25067. this.min.addScalar( - scalar );
  25068. this.max.addScalar( scalar );
  25069. return this;
  25070. },
  25071. containsPoint: function ( point ) {
  25072. return point.x < this.min.x || point.x > this.max.x ||
  25073. point.y < this.min.y || point.y > this.max.y ? false : true;
  25074. },
  25075. containsBox: function ( box ) {
  25076. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  25077. this.min.y <= box.min.y && box.max.y <= this.max.y;
  25078. },
  25079. getParameter: function ( point, optionalTarget ) {
  25080. // This can potentially have a divide by zero if the box
  25081. // has a size dimension of 0.
  25082. var result = optionalTarget || new Vector2();
  25083. return result.set(
  25084. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  25085. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  25086. );
  25087. },
  25088. intersectsBox: function ( box ) {
  25089. // using 4 splitting planes to rule out intersections
  25090. return box.max.x < this.min.x || box.min.x > this.max.x ||
  25091. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  25092. },
  25093. clampPoint: function ( point, optionalTarget ) {
  25094. var result = optionalTarget || new Vector2();
  25095. return result.copy( point ).clamp( this.min, this.max );
  25096. },
  25097. distanceToPoint: function () {
  25098. var v1 = new Vector2();
  25099. return function distanceToPoint( point ) {
  25100. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  25101. return clampedPoint.sub( point ).length();
  25102. };
  25103. }(),
  25104. intersect: function ( box ) {
  25105. this.min.max( box.min );
  25106. this.max.min( box.max );
  25107. return this;
  25108. },
  25109. union: function ( box ) {
  25110. this.min.min( box.min );
  25111. this.max.max( box.max );
  25112. return this;
  25113. },
  25114. translate: function ( offset ) {
  25115. this.min.add( offset );
  25116. this.max.add( offset );
  25117. return this;
  25118. },
  25119. equals: function ( box ) {
  25120. return box.min.equals( this.min ) && box.max.equals( this.max );
  25121. }
  25122. } );
  25123. /**
  25124. * @author alteredq / http://alteredqualia.com/
  25125. */
  25126. function ImmediateRenderObject( material ) {
  25127. Object3D.call( this );
  25128. this.material = material;
  25129. this.render = function ( /* renderCallback */ ) {};
  25130. }
  25131. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  25132. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  25133. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  25134. /**
  25135. * @author mrdoob / http://mrdoob.com/
  25136. * @author WestLangley / http://github.com/WestLangley
  25137. */
  25138. function VertexNormalsHelper( object, size, hex, linewidth ) {
  25139. this.object = object;
  25140. this.size = ( size !== undefined ) ? size : 1;
  25141. var color = ( hex !== undefined ) ? hex : 0xff0000;
  25142. var width = ( linewidth !== undefined ) ? linewidth : 1;
  25143. //
  25144. var nNormals = 0;
  25145. var objGeometry = this.object.geometry;
  25146. if ( objGeometry && objGeometry.isGeometry ) {
  25147. nNormals = objGeometry.faces.length * 3;
  25148. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  25149. nNormals = objGeometry.attributes.normal.count;
  25150. }
  25151. //
  25152. var geometry = new BufferGeometry();
  25153. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  25154. geometry.addAttribute( 'position', positions );
  25155. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  25156. //
  25157. this.matrixAutoUpdate = false;
  25158. this.update();
  25159. }
  25160. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  25161. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  25162. VertexNormalsHelper.prototype.update = ( function () {
  25163. var v1 = new Vector3();
  25164. var v2 = new Vector3();
  25165. var normalMatrix = new Matrix3();
  25166. return function update() {
  25167. var keys = [ 'a', 'b', 'c' ];
  25168. this.object.updateMatrixWorld( true );
  25169. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  25170. var matrixWorld = this.object.matrixWorld;
  25171. var position = this.geometry.attributes.position;
  25172. //
  25173. var objGeometry = this.object.geometry;
  25174. if ( objGeometry && objGeometry.isGeometry ) {
  25175. var vertices = objGeometry.vertices;
  25176. var faces = objGeometry.faces;
  25177. var idx = 0;
  25178. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  25179. var face = faces[ i ];
  25180. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  25181. var vertex = vertices[ face[ keys[ j ] ] ];
  25182. var normal = face.vertexNormals[ j ];
  25183. v1.copy( vertex ).applyMatrix4( matrixWorld );
  25184. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  25185. position.setXYZ( idx, v1.x, v1.y, v1.z );
  25186. idx = idx + 1;
  25187. position.setXYZ( idx, v2.x, v2.y, v2.z );
  25188. idx = idx + 1;
  25189. }
  25190. }
  25191. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  25192. var objPos = objGeometry.attributes.position;
  25193. var objNorm = objGeometry.attributes.normal;
  25194. var idx = 0;
  25195. // for simplicity, ignore index and drawcalls, and render every normal
  25196. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  25197. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  25198. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  25199. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  25200. position.setXYZ( idx, v1.x, v1.y, v1.z );
  25201. idx = idx + 1;
  25202. position.setXYZ( idx, v2.x, v2.y, v2.z );
  25203. idx = idx + 1;
  25204. }
  25205. }
  25206. position.needsUpdate = true;
  25207. };
  25208. }() );
  25209. /**
  25210. * @author alteredq / http://alteredqualia.com/
  25211. * @author mrdoob / http://mrdoob.com/
  25212. * @author WestLangley / http://github.com/WestLangley
  25213. */
  25214. function SpotLightHelper( light, color ) {
  25215. Object3D.call( this );
  25216. this.light = light;
  25217. this.light.updateMatrixWorld();
  25218. this.matrix = light.matrixWorld;
  25219. this.matrixAutoUpdate = false;
  25220. this.color = color;
  25221. var geometry = new BufferGeometry();
  25222. var positions = [
  25223. 0, 0, 0, 0, 0, 1,
  25224. 0, 0, 0, 1, 0, 1,
  25225. 0, 0, 0, - 1, 0, 1,
  25226. 0, 0, 0, 0, 1, 1,
  25227. 0, 0, 0, 0, - 1, 1
  25228. ];
  25229. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  25230. var p1 = ( i / l ) * Math.PI * 2;
  25231. var p2 = ( j / l ) * Math.PI * 2;
  25232. positions.push(
  25233. Math.cos( p1 ), Math.sin( p1 ), 1,
  25234. Math.cos( p2 ), Math.sin( p2 ), 1
  25235. );
  25236. }
  25237. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  25238. var material = new LineBasicMaterial( { fog: false } );
  25239. this.cone = new LineSegments( geometry, material );
  25240. this.add( this.cone );
  25241. this.update();
  25242. }
  25243. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  25244. SpotLightHelper.prototype.constructor = SpotLightHelper;
  25245. SpotLightHelper.prototype.dispose = function () {
  25246. this.cone.geometry.dispose();
  25247. this.cone.material.dispose();
  25248. };
  25249. SpotLightHelper.prototype.update = function () {
  25250. var vector = new Vector3();
  25251. var vector2 = new Vector3();
  25252. return function update() {
  25253. this.light.updateMatrixWorld();
  25254. var coneLength = this.light.distance ? this.light.distance : 1000;
  25255. var coneWidth = coneLength * Math.tan( this.light.angle );
  25256. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  25257. vector.setFromMatrixPosition( this.light.matrixWorld );
  25258. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  25259. this.cone.lookAt( vector2.sub( vector ) );
  25260. if ( this.color !== undefined ) {
  25261. this.cone.material.color.set( this.color );
  25262. } else {
  25263. this.cone.material.color.copy( this.light.color );
  25264. }
  25265. };
  25266. }();
  25267. /**
  25268. * @author Sean Griffin / http://twitter.com/sgrif
  25269. * @author Michael Guerrero / http://realitymeltdown.com
  25270. * @author mrdoob / http://mrdoob.com/
  25271. * @author ikerr / http://verold.com
  25272. * @author Mugen87 / https://github.com/Mugen87
  25273. */
  25274. function getBoneList( object ) {
  25275. var boneList = [];
  25276. if ( object && object.isBone ) {
  25277. boneList.push( object );
  25278. }
  25279. for ( var i = 0; i < object.children.length; i ++ ) {
  25280. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  25281. }
  25282. return boneList;
  25283. }
  25284. function SkeletonHelper( object ) {
  25285. var bones = getBoneList( object );
  25286. var geometry = new BufferGeometry();
  25287. var vertices = [];
  25288. var colors = [];
  25289. var color1 = new Color( 0, 0, 1 );
  25290. var color2 = new Color( 0, 1, 0 );
  25291. for ( var i = 0; i < bones.length; i ++ ) {
  25292. var bone = bones[ i ];
  25293. if ( bone.parent && bone.parent.isBone ) {
  25294. vertices.push( 0, 0, 0 );
  25295. vertices.push( 0, 0, 0 );
  25296. colors.push( color1.r, color1.g, color1.b );
  25297. colors.push( color2.r, color2.g, color2.b );
  25298. }
  25299. }
  25300. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  25301. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  25302. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  25303. LineSegments.call( this, geometry, material );
  25304. this.root = object;
  25305. this.bones = bones;
  25306. this.matrix = object.matrixWorld;
  25307. this.matrixAutoUpdate = false;
  25308. }
  25309. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  25310. SkeletonHelper.prototype.constructor = SkeletonHelper;
  25311. SkeletonHelper.prototype.updateMatrixWorld = function () {
  25312. var vector = new Vector3();
  25313. var boneMatrix = new Matrix4();
  25314. var matrixWorldInv = new Matrix4();
  25315. return function updateMatrixWorld( force ) {
  25316. var bones = this.bones;
  25317. var geometry = this.geometry;
  25318. var position = geometry.getAttribute( 'position' );
  25319. matrixWorldInv.getInverse( this.root.matrixWorld );
  25320. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  25321. var bone = bones[ i ];
  25322. if ( bone.parent && bone.parent.isBone ) {
  25323. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  25324. vector.setFromMatrixPosition( boneMatrix );
  25325. position.setXYZ( j, vector.x, vector.y, vector.z );
  25326. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  25327. vector.setFromMatrixPosition( boneMatrix );
  25328. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  25329. j += 2;
  25330. }
  25331. }
  25332. geometry.getAttribute( 'position' ).needsUpdate = true;
  25333. Object3D.prototype.updateMatrixWorld.call( this, force );
  25334. };
  25335. }();
  25336. /**
  25337. * @author alteredq / http://alteredqualia.com/
  25338. * @author mrdoob / http://mrdoob.com/
  25339. */
  25340. function PointLightHelper( light, sphereSize, color ) {
  25341. this.light = light;
  25342. this.light.updateMatrixWorld();
  25343. this.color = color;
  25344. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  25345. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  25346. Mesh.call( this, geometry, material );
  25347. this.matrix = this.light.matrixWorld;
  25348. this.matrixAutoUpdate = false;
  25349. this.update();
  25350. /*
  25351. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  25352. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  25353. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  25354. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  25355. var d = light.distance;
  25356. if ( d === 0.0 ) {
  25357. this.lightDistance.visible = false;
  25358. } else {
  25359. this.lightDistance.scale.set( d, d, d );
  25360. }
  25361. this.add( this.lightDistance );
  25362. */
  25363. }
  25364. PointLightHelper.prototype = Object.create( Mesh.prototype );
  25365. PointLightHelper.prototype.constructor = PointLightHelper;
  25366. PointLightHelper.prototype.dispose = function () {
  25367. this.geometry.dispose();
  25368. this.material.dispose();
  25369. };
  25370. PointLightHelper.prototype.update = function () {
  25371. if ( this.color !== undefined ) {
  25372. this.material.color.set( this.color );
  25373. } else {
  25374. this.material.color.copy( this.light.color );
  25375. }
  25376. /*
  25377. var d = this.light.distance;
  25378. if ( d === 0.0 ) {
  25379. this.lightDistance.visible = false;
  25380. } else {
  25381. this.lightDistance.visible = true;
  25382. this.lightDistance.scale.set( d, d, d );
  25383. }
  25384. */
  25385. };
  25386. /**
  25387. * @author abelnation / http://github.com/abelnation
  25388. * @author Mugen87 / http://github.com/Mugen87
  25389. * @author WestLangley / http://github.com/WestLangley
  25390. */
  25391. function RectAreaLightHelper( light, color ) {
  25392. Object3D.call( this );
  25393. this.light = light;
  25394. this.light.updateMatrixWorld();
  25395. this.matrix = light.matrixWorld;
  25396. this.matrixAutoUpdate = false;
  25397. this.color = color;
  25398. var material = new LineBasicMaterial( { fog: false } );
  25399. var geometry = new BufferGeometry();
  25400. geometry.addAttribute( 'position', new BufferAttribute( new Float32Array( 5 * 3 ), 3 ) );
  25401. this.line = new Line( geometry, material );
  25402. this.add( this.line );
  25403. this.update();
  25404. }
  25405. RectAreaLightHelper.prototype = Object.create( Object3D.prototype );
  25406. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  25407. RectAreaLightHelper.prototype.dispose = function () {
  25408. this.children[ 0 ].geometry.dispose();
  25409. this.children[ 0 ].material.dispose();
  25410. };
  25411. RectAreaLightHelper.prototype.update = function () {
  25412. // calculate new dimensions of the helper
  25413. var hx = this.light.width * 0.5;
  25414. var hy = this.light.height * 0.5;
  25415. var position = this.line.geometry.attributes.position;
  25416. var array = position.array;
  25417. // update vertices
  25418. array[ 0 ] = hx; array[ 1 ] = - hy; array[ 2 ] = 0;
  25419. array[ 3 ] = hx; array[ 4 ] = hy; array[ 5 ] = 0;
  25420. array[ 6 ] = - hx; array[ 7 ] = hy; array[ 8 ] = 0;
  25421. array[ 9 ] = - hx; array[ 10 ] = - hy; array[ 11 ] = 0;
  25422. array[ 12 ] = hx; array[ 13 ] = - hy; array[ 14 ] = 0;
  25423. position.needsUpdate = true;
  25424. if ( this.color !== undefined ) {
  25425. this.line.material.color.set( this.color );
  25426. } else {
  25427. this.line.material.color.copy( this.light.color );
  25428. }
  25429. };
  25430. /**
  25431. * @author alteredq / http://alteredqualia.com/
  25432. * @author mrdoob / http://mrdoob.com/
  25433. * @author Mugen87 / https://github.com/Mugen87
  25434. */
  25435. function HemisphereLightHelper( light, size, color ) {
  25436. Object3D.call( this );
  25437. this.light = light;
  25438. this.light.updateMatrixWorld();
  25439. this.matrix = light.matrixWorld;
  25440. this.matrixAutoUpdate = false;
  25441. this.color = color;
  25442. var geometry = new OctahedronBufferGeometry( size );
  25443. geometry.rotateY( Math.PI * 0.5 );
  25444. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  25445. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  25446. var position = geometry.getAttribute( 'position' );
  25447. var colors = new Float32Array( position.count * 3 );
  25448. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  25449. this.add( new Mesh( geometry, this.material ) );
  25450. this.update();
  25451. }
  25452. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  25453. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  25454. HemisphereLightHelper.prototype.dispose = function () {
  25455. this.children[ 0 ].geometry.dispose();
  25456. this.children[ 0 ].material.dispose();
  25457. };
  25458. HemisphereLightHelper.prototype.update = function () {
  25459. var vector = new Vector3();
  25460. var color1 = new Color();
  25461. var color2 = new Color();
  25462. return function update() {
  25463. var mesh = this.children[ 0 ];
  25464. if ( this.color !== undefined ) {
  25465. this.material.color.set( this.color );
  25466. } else {
  25467. var colors = mesh.geometry.getAttribute( 'color' );
  25468. color1.copy( this.light.color );
  25469. color2.copy( this.light.groundColor );
  25470. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  25471. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  25472. colors.setXYZ( i, color.r, color.g, color.b );
  25473. }
  25474. colors.needsUpdate = true;
  25475. }
  25476. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  25477. };
  25478. }();
  25479. /**
  25480. * @author mrdoob / http://mrdoob.com/
  25481. */
  25482. function GridHelper( size, divisions, color1, color2 ) {
  25483. size = size || 10;
  25484. divisions = divisions || 10;
  25485. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  25486. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  25487. var center = divisions / 2;
  25488. var step = size / divisions;
  25489. var halfSize = size / 2;
  25490. var vertices = [], colors = [];
  25491. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  25492. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  25493. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  25494. var color = i === center ? color1 : color2;
  25495. color.toArray( colors, j ); j += 3;
  25496. color.toArray( colors, j ); j += 3;
  25497. color.toArray( colors, j ); j += 3;
  25498. color.toArray( colors, j ); j += 3;
  25499. }
  25500. var geometry = new BufferGeometry();
  25501. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  25502. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  25503. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  25504. LineSegments.call( this, geometry, material );
  25505. }
  25506. GridHelper.prototype = Object.create( LineSegments.prototype );
  25507. GridHelper.prototype.constructor = GridHelper;
  25508. /**
  25509. * @author mrdoob / http://mrdoob.com/
  25510. * @author Mugen87 / http://github.com/Mugen87
  25511. * @author Hectate / http://www.github.com/Hectate
  25512. */
  25513. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  25514. radius = radius || 10;
  25515. radials = radials || 16;
  25516. circles = circles || 8;
  25517. divisions = divisions || 64;
  25518. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  25519. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  25520. var vertices = [];
  25521. var colors = [];
  25522. var x, z;
  25523. var v, i, j, r, color;
  25524. // create the radials
  25525. for ( i = 0; i <= radials; i ++ ) {
  25526. v = ( i / radials ) * ( Math.PI * 2 );
  25527. x = Math.sin( v ) * radius;
  25528. z = Math.cos( v ) * radius;
  25529. vertices.push( 0, 0, 0 );
  25530. vertices.push( x, 0, z );
  25531. color = ( i & 1 ) ? color1 : color2;
  25532. colors.push( color.r, color.g, color.b );
  25533. colors.push( color.r, color.g, color.b );
  25534. }
  25535. // create the circles
  25536. for ( i = 0; i <= circles; i ++ ) {
  25537. color = ( i & 1 ) ? color1 : color2;
  25538. r = radius - ( radius / circles * i );
  25539. for ( j = 0; j < divisions; j ++ ) {
  25540. // first vertex
  25541. v = ( j / divisions ) * ( Math.PI * 2 );
  25542. x = Math.sin( v ) * r;
  25543. z = Math.cos( v ) * r;
  25544. vertices.push( x, 0, z );
  25545. colors.push( color.r, color.g, color.b );
  25546. // second vertex
  25547. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  25548. x = Math.sin( v ) * r;
  25549. z = Math.cos( v ) * r;
  25550. vertices.push( x, 0, z );
  25551. colors.push( color.r, color.g, color.b );
  25552. }
  25553. }
  25554. var geometry = new BufferGeometry();
  25555. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  25556. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  25557. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  25558. LineSegments.call( this, geometry, material );
  25559. }
  25560. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  25561. PolarGridHelper.prototype.constructor = PolarGridHelper;
  25562. /**
  25563. * @author mrdoob / http://mrdoob.com/
  25564. * @author WestLangley / http://github.com/WestLangley
  25565. */
  25566. function FaceNormalsHelper( object, size, hex, linewidth ) {
  25567. // FaceNormalsHelper only supports THREE.Geometry
  25568. this.object = object;
  25569. this.size = ( size !== undefined ) ? size : 1;
  25570. var color = ( hex !== undefined ) ? hex : 0xffff00;
  25571. var width = ( linewidth !== undefined ) ? linewidth : 1;
  25572. //
  25573. var nNormals = 0;
  25574. var objGeometry = this.object.geometry;
  25575. if ( objGeometry && objGeometry.isGeometry ) {
  25576. nNormals = objGeometry.faces.length;
  25577. } else {
  25578. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  25579. }
  25580. //
  25581. var geometry = new BufferGeometry();
  25582. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  25583. geometry.addAttribute( 'position', positions );
  25584. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  25585. //
  25586. this.matrixAutoUpdate = false;
  25587. this.update();
  25588. }
  25589. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  25590. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  25591. FaceNormalsHelper.prototype.update = ( function () {
  25592. var v1 = new Vector3();
  25593. var v2 = new Vector3();
  25594. var normalMatrix = new Matrix3();
  25595. return function update() {
  25596. this.object.updateMatrixWorld( true );
  25597. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  25598. var matrixWorld = this.object.matrixWorld;
  25599. var position = this.geometry.attributes.position;
  25600. //
  25601. var objGeometry = this.object.geometry;
  25602. var vertices = objGeometry.vertices;
  25603. var faces = objGeometry.faces;
  25604. var idx = 0;
  25605. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  25606. var face = faces[ i ];
  25607. var normal = face.normal;
  25608. v1.copy( vertices[ face.a ] )
  25609. .add( vertices[ face.b ] )
  25610. .add( vertices[ face.c ] )
  25611. .divideScalar( 3 )
  25612. .applyMatrix4( matrixWorld );
  25613. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  25614. position.setXYZ( idx, v1.x, v1.y, v1.z );
  25615. idx = idx + 1;
  25616. position.setXYZ( idx, v2.x, v2.y, v2.z );
  25617. idx = idx + 1;
  25618. }
  25619. position.needsUpdate = true;
  25620. };
  25621. }() );
  25622. /**
  25623. * @author alteredq / http://alteredqualia.com/
  25624. * @author mrdoob / http://mrdoob.com/
  25625. * @author WestLangley / http://github.com/WestLangley
  25626. */
  25627. function DirectionalLightHelper( light, size, color ) {
  25628. Object3D.call( this );
  25629. this.light = light;
  25630. this.light.updateMatrixWorld();
  25631. this.matrix = light.matrixWorld;
  25632. this.matrixAutoUpdate = false;
  25633. this.color = color;
  25634. if ( size === undefined ) size = 1;
  25635. var geometry = new BufferGeometry();
  25636. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  25637. - size, size, 0,
  25638. size, size, 0,
  25639. size, - size, 0,
  25640. - size, - size, 0,
  25641. - size, size, 0
  25642. ], 3 ) );
  25643. var material = new LineBasicMaterial( { fog: false } );
  25644. this.lightPlane = new Line( geometry, material );
  25645. this.add( this.lightPlane );
  25646. geometry = new BufferGeometry();
  25647. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  25648. this.targetLine = new Line( geometry, material );
  25649. this.add( this.targetLine );
  25650. this.update();
  25651. }
  25652. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  25653. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  25654. DirectionalLightHelper.prototype.dispose = function () {
  25655. this.lightPlane.geometry.dispose();
  25656. this.lightPlane.material.dispose();
  25657. this.targetLine.geometry.dispose();
  25658. this.targetLine.material.dispose();
  25659. };
  25660. DirectionalLightHelper.prototype.update = function () {
  25661. var v1 = new Vector3();
  25662. var v2 = new Vector3();
  25663. var v3 = new Vector3();
  25664. return function update() {
  25665. v1.setFromMatrixPosition( this.light.matrixWorld );
  25666. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  25667. v3.subVectors( v2, v1 );
  25668. this.lightPlane.lookAt( v3 );
  25669. if ( this.color !== undefined ) {
  25670. this.lightPlane.material.color.set( this.color );
  25671. this.targetLine.material.color.set( this.color );
  25672. } else {
  25673. this.lightPlane.material.color.copy( this.light.color );
  25674. this.targetLine.material.color.copy( this.light.color );
  25675. }
  25676. this.targetLine.lookAt( v3 );
  25677. this.targetLine.scale.z = v3.length();
  25678. };
  25679. }();
  25680. /**
  25681. * @author alteredq / http://alteredqualia.com/
  25682. * @author Mugen87 / https://github.com/Mugen87
  25683. *
  25684. * - shows frustum, line of sight and up of the camera
  25685. * - suitable for fast updates
  25686. * - based on frustum visualization in lightgl.js shadowmap example
  25687. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  25688. */
  25689. function CameraHelper( camera ) {
  25690. var geometry = new BufferGeometry();
  25691. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  25692. var vertices = [];
  25693. var colors = [];
  25694. var pointMap = {};
  25695. // colors
  25696. var colorFrustum = new Color( 0xffaa00 );
  25697. var colorCone = new Color( 0xff0000 );
  25698. var colorUp = new Color( 0x00aaff );
  25699. var colorTarget = new Color( 0xffffff );
  25700. var colorCross = new Color( 0x333333 );
  25701. // near
  25702. addLine( 'n1', 'n2', colorFrustum );
  25703. addLine( 'n2', 'n4', colorFrustum );
  25704. addLine( 'n4', 'n3', colorFrustum );
  25705. addLine( 'n3', 'n1', colorFrustum );
  25706. // far
  25707. addLine( 'f1', 'f2', colorFrustum );
  25708. addLine( 'f2', 'f4', colorFrustum );
  25709. addLine( 'f4', 'f3', colorFrustum );
  25710. addLine( 'f3', 'f1', colorFrustum );
  25711. // sides
  25712. addLine( 'n1', 'f1', colorFrustum );
  25713. addLine( 'n2', 'f2', colorFrustum );
  25714. addLine( 'n3', 'f3', colorFrustum );
  25715. addLine( 'n4', 'f4', colorFrustum );
  25716. // cone
  25717. addLine( 'p', 'n1', colorCone );
  25718. addLine( 'p', 'n2', colorCone );
  25719. addLine( 'p', 'n3', colorCone );
  25720. addLine( 'p', 'n4', colorCone );
  25721. // up
  25722. addLine( 'u1', 'u2', colorUp );
  25723. addLine( 'u2', 'u3', colorUp );
  25724. addLine( 'u3', 'u1', colorUp );
  25725. // target
  25726. addLine( 'c', 't', colorTarget );
  25727. addLine( 'p', 'c', colorCross );
  25728. // cross
  25729. addLine( 'cn1', 'cn2', colorCross );
  25730. addLine( 'cn3', 'cn4', colorCross );
  25731. addLine( 'cf1', 'cf2', colorCross );
  25732. addLine( 'cf3', 'cf4', colorCross );
  25733. function addLine( a, b, color ) {
  25734. addPoint( a, color );
  25735. addPoint( b, color );
  25736. }
  25737. function addPoint( id, color ) {
  25738. vertices.push( 0, 0, 0 );
  25739. colors.push( color.r, color.g, color.b );
  25740. if ( pointMap[ id ] === undefined ) {
  25741. pointMap[ id ] = [];
  25742. }
  25743. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  25744. }
  25745. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  25746. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  25747. LineSegments.call( this, geometry, material );
  25748. this.camera = camera;
  25749. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  25750. this.matrix = camera.matrixWorld;
  25751. this.matrixAutoUpdate = false;
  25752. this.pointMap = pointMap;
  25753. this.update();
  25754. }
  25755. CameraHelper.prototype = Object.create( LineSegments.prototype );
  25756. CameraHelper.prototype.constructor = CameraHelper;
  25757. CameraHelper.prototype.update = function () {
  25758. var geometry, pointMap;
  25759. var vector = new Vector3();
  25760. var camera = new Camera();
  25761. function setPoint( point, x, y, z ) {
  25762. vector.set( x, y, z ).unproject( camera );
  25763. var points = pointMap[ point ];
  25764. if ( points !== undefined ) {
  25765. var position = geometry.getAttribute( 'position' );
  25766. for ( var i = 0, l = points.length; i < l; i ++ ) {
  25767. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  25768. }
  25769. }
  25770. }
  25771. return function update() {
  25772. geometry = this.geometry;
  25773. pointMap = this.pointMap;
  25774. var w = 1, h = 1;
  25775. // we need just camera projection matrix
  25776. // world matrix must be identity
  25777. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  25778. // center / target
  25779. setPoint( 'c', 0, 0, - 1 );
  25780. setPoint( 't', 0, 0, 1 );
  25781. // near
  25782. setPoint( 'n1', - w, - h, - 1 );
  25783. setPoint( 'n2', w, - h, - 1 );
  25784. setPoint( 'n3', - w, h, - 1 );
  25785. setPoint( 'n4', w, h, - 1 );
  25786. // far
  25787. setPoint( 'f1', - w, - h, 1 );
  25788. setPoint( 'f2', w, - h, 1 );
  25789. setPoint( 'f3', - w, h, 1 );
  25790. setPoint( 'f4', w, h, 1 );
  25791. // up
  25792. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  25793. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  25794. setPoint( 'u3', 0, h * 2, - 1 );
  25795. // cross
  25796. setPoint( 'cf1', - w, 0, 1 );
  25797. setPoint( 'cf2', w, 0, 1 );
  25798. setPoint( 'cf3', 0, - h, 1 );
  25799. setPoint( 'cf4', 0, h, 1 );
  25800. setPoint( 'cn1', - w, 0, - 1 );
  25801. setPoint( 'cn2', w, 0, - 1 );
  25802. setPoint( 'cn3', 0, - h, - 1 );
  25803. setPoint( 'cn4', 0, h, - 1 );
  25804. geometry.getAttribute( 'position' ).needsUpdate = true;
  25805. };
  25806. }();
  25807. /**
  25808. * @author mrdoob / http://mrdoob.com/
  25809. * @author Mugen87 / http://github.com/Mugen87
  25810. */
  25811. function BoxHelper( object, color ) {
  25812. this.object = object;
  25813. if ( color === undefined ) color = 0xffff00;
  25814. var indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] );
  25815. var positions = new Float32Array( 8 * 3 );
  25816. var geometry = new BufferGeometry();
  25817. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  25818. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  25819. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  25820. this.matrixAutoUpdate = false;
  25821. this.update();
  25822. }
  25823. BoxHelper.prototype = Object.create( LineSegments.prototype );
  25824. BoxHelper.prototype.constructor = BoxHelper;
  25825. BoxHelper.prototype.update = ( function () {
  25826. var box = new Box3();
  25827. return function update( object ) {
  25828. if ( object !== undefined ) {
  25829. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  25830. }
  25831. if ( this.object !== undefined ) {
  25832. box.setFromObject( this.object );
  25833. }
  25834. if ( box.isEmpty() ) return;
  25835. var min = box.min;
  25836. var max = box.max;
  25837. /*
  25838. 5____4
  25839. 1/___0/|
  25840. | 6__|_7
  25841. 2/___3/
  25842. 0: max.x, max.y, max.z
  25843. 1: min.x, max.y, max.z
  25844. 2: min.x, min.y, max.z
  25845. 3: max.x, min.y, max.z
  25846. 4: max.x, max.y, min.z
  25847. 5: min.x, max.y, min.z
  25848. 6: min.x, min.y, min.z
  25849. 7: max.x, min.y, min.z
  25850. */
  25851. var position = this.geometry.attributes.position;
  25852. var array = position.array;
  25853. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  25854. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  25855. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  25856. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  25857. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  25858. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  25859. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  25860. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  25861. position.needsUpdate = true;
  25862. this.geometry.computeBoundingSphere();
  25863. };
  25864. } )();
  25865. BoxHelper.prototype.setFromObject = function ( object ) {
  25866. this.object = object;
  25867. this.update();
  25868. return this;
  25869. };
  25870. /**
  25871. * @author WestLangley / http://github.com/WestLangley
  25872. */
  25873. function Box3Helper( box, hex ) {
  25874. this.type = 'Box3Helper';
  25875. this.box = box;
  25876. var color = ( hex !== undefined ) ? hex : 0xffff00;
  25877. var indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] );
  25878. var positions = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, - 1, 1, 1, 1, - 1, - 1, 1, - 1, - 1, - 1, - 1, 1, - 1, - 1 ];
  25879. var geometry = new BufferGeometry();
  25880. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  25881. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  25882. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  25883. this.geometry.computeBoundingSphere();
  25884. }
  25885. Box3Helper.prototype = Object.create( LineSegments.prototype );
  25886. Box3Helper.prototype.constructor = Box3Helper;
  25887. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  25888. var box = this.box;
  25889. if ( box.isEmpty() ) return;
  25890. box.getCenter( this.position );
  25891. box.getSize( this.scale );
  25892. this.scale.multiplyScalar( 0.5 );
  25893. Object3D.prototype.updateMatrixWorld.call( this, force );
  25894. };
  25895. /**
  25896. * @author WestLangley / http://github.com/WestLangley
  25897. */
  25898. function PlaneHelper( plane, size, hex ) {
  25899. this.type = 'PlaneHelper';
  25900. this.plane = plane;
  25901. this.size = ( size === undefined ) ? 1 : size;
  25902. var color = ( hex !== undefined ) ? hex : 0xffff00;
  25903. var positions = [ 1, - 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, - 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0 ];
  25904. var geometry = new BufferGeometry();
  25905. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  25906. geometry.computeBoundingSphere();
  25907. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  25908. //
  25909. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  25910. var geometry2 = new BufferGeometry();
  25911. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  25912. geometry2.computeBoundingSphere();
  25913. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  25914. }
  25915. PlaneHelper.prototype = Object.create( Line.prototype );
  25916. PlaneHelper.prototype.constructor = PlaneHelper;
  25917. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  25918. var scale = - this.plane.constant;
  25919. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  25920. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  25921. this.lookAt( this.plane.normal );
  25922. Object3D.prototype.updateMatrixWorld.call( this, force );
  25923. };
  25924. /**
  25925. * @author WestLangley / http://github.com/WestLangley
  25926. * @author zz85 / http://github.com/zz85
  25927. * @author bhouston / http://clara.io
  25928. *
  25929. * Creates an arrow for visualizing directions
  25930. *
  25931. * Parameters:
  25932. * dir - Vector3
  25933. * origin - Vector3
  25934. * length - Number
  25935. * color - color in hex value
  25936. * headLength - Number
  25937. * headWidth - Number
  25938. */
  25939. var lineGeometry;
  25940. var coneGeometry;
  25941. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  25942. // dir is assumed to be normalized
  25943. Object3D.call( this );
  25944. if ( color === undefined ) color = 0xffff00;
  25945. if ( length === undefined ) length = 1;
  25946. if ( headLength === undefined ) headLength = 0.2 * length;
  25947. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  25948. if ( lineGeometry === undefined ) {
  25949. lineGeometry = new BufferGeometry();
  25950. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  25951. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  25952. coneGeometry.translate( 0, - 0.5, 0 );
  25953. }
  25954. this.position.copy( origin );
  25955. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  25956. this.line.matrixAutoUpdate = false;
  25957. this.add( this.line );
  25958. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  25959. this.cone.matrixAutoUpdate = false;
  25960. this.add( this.cone );
  25961. this.setDirection( dir );
  25962. this.setLength( length, headLength, headWidth );
  25963. }
  25964. ArrowHelper.prototype = Object.create( Object3D.prototype );
  25965. ArrowHelper.prototype.constructor = ArrowHelper;
  25966. ArrowHelper.prototype.setDirection = ( function () {
  25967. var axis = new Vector3();
  25968. var radians;
  25969. return function setDirection( dir ) {
  25970. // dir is assumed to be normalized
  25971. if ( dir.y > 0.99999 ) {
  25972. this.quaternion.set( 0, 0, 0, 1 );
  25973. } else if ( dir.y < - 0.99999 ) {
  25974. this.quaternion.set( 1, 0, 0, 0 );
  25975. } else {
  25976. axis.set( dir.z, 0, - dir.x ).normalize();
  25977. radians = Math.acos( dir.y );
  25978. this.quaternion.setFromAxisAngle( axis, radians );
  25979. }
  25980. };
  25981. }() );
  25982. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  25983. if ( headLength === undefined ) headLength = 0.2 * length;
  25984. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  25985. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  25986. this.line.updateMatrix();
  25987. this.cone.scale.set( headWidth, headLength, headWidth );
  25988. this.cone.position.y = length;
  25989. this.cone.updateMatrix();
  25990. };
  25991. ArrowHelper.prototype.setColor = function ( color ) {
  25992. this.line.material.color.copy( color );
  25993. this.cone.material.color.copy( color );
  25994. };
  25995. /**
  25996. * @author sroucheray / http://sroucheray.org/
  25997. * @author mrdoob / http://mrdoob.com/
  25998. */
  25999. function AxesHelper( size ) {
  26000. size = size || 1;
  26001. var vertices = [
  26002. 0, 0, 0, size, 0, 0,
  26003. 0, 0, 0, 0, size, 0,
  26004. 0, 0, 0, 0, 0, size
  26005. ];
  26006. var colors = [
  26007. 1, 0, 0, 1, 0.6, 0,
  26008. 0, 1, 0, 0.6, 1, 0,
  26009. 0, 0, 1, 0, 0.6, 1
  26010. ];
  26011. var geometry = new BufferGeometry();
  26012. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26013. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26014. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26015. LineSegments.call( this, geometry, material );
  26016. }
  26017. AxesHelper.prototype = Object.create( LineSegments.prototype );
  26018. AxesHelper.prototype.constructor = AxesHelper;
  26019. /**
  26020. * @author mrdoob / http://mrdoob.com/
  26021. */
  26022. function Face4( a, b, c, d, normal, color, materialIndex ) {
  26023. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  26024. return new Face3( a, b, c, normal, color, materialIndex );
  26025. }
  26026. var LineStrip = 0;
  26027. var LinePieces = 1;
  26028. function MeshFaceMaterial( materials ) {
  26029. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  26030. return materials;
  26031. }
  26032. function MultiMaterial( materials ) {
  26033. if ( materials === undefined ) materials = [];
  26034. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  26035. materials.isMultiMaterial = true;
  26036. materials.materials = materials;
  26037. materials.clone = function () {
  26038. return materials.slice();
  26039. };
  26040. return materials;
  26041. }
  26042. function PointCloud( geometry, material ) {
  26043. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  26044. return new Points( geometry, material );
  26045. }
  26046. function Particle( material ) {
  26047. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  26048. return new Sprite( material );
  26049. }
  26050. function ParticleSystem( geometry, material ) {
  26051. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  26052. return new Points( geometry, material );
  26053. }
  26054. function PointCloudMaterial( parameters ) {
  26055. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  26056. return new PointsMaterial( parameters );
  26057. }
  26058. function ParticleBasicMaterial( parameters ) {
  26059. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  26060. return new PointsMaterial( parameters );
  26061. }
  26062. function ParticleSystemMaterial( parameters ) {
  26063. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  26064. return new PointsMaterial( parameters );
  26065. }
  26066. function Vertex( x, y, z ) {
  26067. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  26068. return new Vector3( x, y, z );
  26069. }
  26070. //
  26071. function DynamicBufferAttribute( array, itemSize ) {
  26072. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  26073. return new BufferAttribute( array, itemSize ).setDynamic( true );
  26074. }
  26075. function Int8Attribute( array, itemSize ) {
  26076. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  26077. return new Int8BufferAttribute( array, itemSize );
  26078. }
  26079. function Uint8Attribute( array, itemSize ) {
  26080. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  26081. return new Uint8BufferAttribute( array, itemSize );
  26082. }
  26083. function Uint8ClampedAttribute( array, itemSize ) {
  26084. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  26085. return new Uint8ClampedBufferAttribute( array, itemSize );
  26086. }
  26087. function Int16Attribute( array, itemSize ) {
  26088. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  26089. return new Int16BufferAttribute( array, itemSize );
  26090. }
  26091. function Uint16Attribute( array, itemSize ) {
  26092. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  26093. return new Uint16BufferAttribute( array, itemSize );
  26094. }
  26095. function Int32Attribute( array, itemSize ) {
  26096. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  26097. return new Int32BufferAttribute( array, itemSize );
  26098. }
  26099. function Uint32Attribute( array, itemSize ) {
  26100. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  26101. return new Uint32BufferAttribute( array, itemSize );
  26102. }
  26103. function Float32Attribute( array, itemSize ) {
  26104. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  26105. return new Float32BufferAttribute( array, itemSize );
  26106. }
  26107. function Float64Attribute( array, itemSize ) {
  26108. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  26109. return new Float64BufferAttribute( array, itemSize );
  26110. }
  26111. //
  26112. Curve.create = function ( construct, getPoint ) {
  26113. console.log( 'THREE.Curve.create() has been deprecated' );
  26114. construct.prototype = Object.create( Curve.prototype );
  26115. construct.prototype.constructor = construct;
  26116. construct.prototype.getPoint = getPoint;
  26117. return construct;
  26118. };
  26119. //
  26120. Object.assign( CurvePath.prototype, {
  26121. createPointsGeometry: function ( divisions ) {
  26122. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  26123. // generate geometry from path points (for Line or Points objects)
  26124. var pts = this.getPoints( divisions );
  26125. return this.createGeometry( pts );
  26126. },
  26127. createSpacedPointsGeometry: function ( divisions ) {
  26128. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  26129. // generate geometry from equidistant sampling along the path
  26130. var pts = this.getSpacedPoints( divisions );
  26131. return this.createGeometry( pts );
  26132. },
  26133. createGeometry: function ( points ) {
  26134. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  26135. var geometry = new Geometry();
  26136. for ( var i = 0, l = points.length; i < l; i ++ ) {
  26137. var point = points[ i ];
  26138. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  26139. }
  26140. return geometry;
  26141. }
  26142. } );
  26143. //
  26144. Object.assign( Path.prototype, {
  26145. fromPoints: function ( points ) {
  26146. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  26147. this.setFromPoints( points );
  26148. }
  26149. } );
  26150. //
  26151. function ClosedSplineCurve3( points ) {
  26152. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  26153. CatmullRomCurve3.call( this, points );
  26154. this.type = 'catmullrom';
  26155. this.closed = true;
  26156. }
  26157. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  26158. //
  26159. function SplineCurve3( points ) {
  26160. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  26161. CatmullRomCurve3.call( this, points );
  26162. this.type = 'catmullrom';
  26163. }
  26164. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  26165. //
  26166. function Spline( points ) {
  26167. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  26168. CatmullRomCurve3.call( this, points );
  26169. this.type = 'catmullrom';
  26170. }
  26171. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  26172. Object.assign( Spline.prototype, {
  26173. initFromArray: function ( /* a */ ) {
  26174. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  26175. },
  26176. getControlPointsArray: function ( /* optionalTarget */ ) {
  26177. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  26178. },
  26179. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  26180. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  26181. }
  26182. } );
  26183. //
  26184. function AxisHelper( size ) {
  26185. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  26186. return new AxesHelper( size );
  26187. }
  26188. function BoundingBoxHelper( object, color ) {
  26189. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  26190. return new BoxHelper( object, color );
  26191. }
  26192. function EdgesHelper( object, hex ) {
  26193. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  26194. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  26195. }
  26196. GridHelper.prototype.setColors = function () {
  26197. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  26198. };
  26199. SkeletonHelper.prototype.update = function () {
  26200. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  26201. };
  26202. function WireframeHelper( object, hex ) {
  26203. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  26204. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  26205. }
  26206. //
  26207. Object.assign( Loader.prototype, {
  26208. extractUrlBase: function ( url ) {
  26209. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  26210. return LoaderUtils.extractUrlBase( url );
  26211. }
  26212. } );
  26213. function XHRLoader( manager ) {
  26214. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  26215. return new FileLoader( manager );
  26216. }
  26217. function BinaryTextureLoader( manager ) {
  26218. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  26219. return new DataTextureLoader( manager );
  26220. }
  26221. //
  26222. Object.assign( Box2.prototype, {
  26223. center: function ( optionalTarget ) {
  26224. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  26225. return this.getCenter( optionalTarget );
  26226. },
  26227. empty: function () {
  26228. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  26229. return this.isEmpty();
  26230. },
  26231. isIntersectionBox: function ( box ) {
  26232. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  26233. return this.intersectsBox( box );
  26234. },
  26235. size: function ( optionalTarget ) {
  26236. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  26237. return this.getSize( optionalTarget );
  26238. }
  26239. } );
  26240. Object.assign( Box3.prototype, {
  26241. center: function ( optionalTarget ) {
  26242. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  26243. return this.getCenter( optionalTarget );
  26244. },
  26245. empty: function () {
  26246. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  26247. return this.isEmpty();
  26248. },
  26249. isIntersectionBox: function ( box ) {
  26250. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  26251. return this.intersectsBox( box );
  26252. },
  26253. isIntersectionSphere: function ( sphere ) {
  26254. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  26255. return this.intersectsSphere( sphere );
  26256. },
  26257. size: function ( optionalTarget ) {
  26258. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  26259. return this.getSize( optionalTarget );
  26260. }
  26261. } );
  26262. Line3.prototype.center = function ( optionalTarget ) {
  26263. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  26264. return this.getCenter( optionalTarget );
  26265. };
  26266. Object.assign( _Math, {
  26267. random16: function () {
  26268. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  26269. return Math.random();
  26270. },
  26271. nearestPowerOfTwo: function ( value ) {
  26272. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  26273. return _Math.floorPowerOfTwo( value );
  26274. },
  26275. nextPowerOfTwo: function ( value ) {
  26276. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  26277. return _Math.ceilPowerOfTwo( value );
  26278. }
  26279. } );
  26280. Object.assign( Matrix3.prototype, {
  26281. flattenToArrayOffset: function ( array, offset ) {
  26282. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  26283. return this.toArray( array, offset );
  26284. },
  26285. multiplyVector3: function ( vector ) {
  26286. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  26287. return vector.applyMatrix3( this );
  26288. },
  26289. multiplyVector3Array: function ( /* a */ ) {
  26290. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  26291. },
  26292. applyToBuffer: function ( buffer /*, offset, length */ ) {
  26293. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  26294. return this.applyToBufferAttribute( buffer );
  26295. },
  26296. applyToVector3Array: function ( /* array, offset, length */ ) {
  26297. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  26298. }
  26299. } );
  26300. Object.assign( Matrix4.prototype, {
  26301. extractPosition: function ( m ) {
  26302. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  26303. return this.copyPosition( m );
  26304. },
  26305. flattenToArrayOffset: function ( array, offset ) {
  26306. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  26307. return this.toArray( array, offset );
  26308. },
  26309. getPosition: function () {
  26310. var v1;
  26311. return function getPosition() {
  26312. if ( v1 === undefined ) v1 = new Vector3();
  26313. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  26314. return v1.setFromMatrixColumn( this, 3 );
  26315. };
  26316. }(),
  26317. setRotationFromQuaternion: function ( q ) {
  26318. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  26319. return this.makeRotationFromQuaternion( q );
  26320. },
  26321. multiplyToArray: function () {
  26322. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  26323. },
  26324. multiplyVector3: function ( vector ) {
  26325. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  26326. return vector.applyMatrix4( this );
  26327. },
  26328. multiplyVector4: function ( vector ) {
  26329. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  26330. return vector.applyMatrix4( this );
  26331. },
  26332. multiplyVector3Array: function ( /* a */ ) {
  26333. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  26334. },
  26335. rotateAxis: function ( v ) {
  26336. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  26337. v.transformDirection( this );
  26338. },
  26339. crossVector: function ( vector ) {
  26340. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  26341. return vector.applyMatrix4( this );
  26342. },
  26343. translate: function () {
  26344. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  26345. },
  26346. rotateX: function () {
  26347. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  26348. },
  26349. rotateY: function () {
  26350. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  26351. },
  26352. rotateZ: function () {
  26353. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  26354. },
  26355. rotateByAxis: function () {
  26356. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  26357. },
  26358. applyToBuffer: function ( buffer /*, offset, length */ ) {
  26359. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  26360. return this.applyToBufferAttribute( buffer );
  26361. },
  26362. applyToVector3Array: function ( /* array, offset, length */ ) {
  26363. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  26364. },
  26365. makeFrustum: function ( left, right, bottom, top, near, far ) {
  26366. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  26367. return this.makePerspective( left, right, top, bottom, near, far );
  26368. }
  26369. } );
  26370. Plane.prototype.isIntersectionLine = function ( line ) {
  26371. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  26372. return this.intersectsLine( line );
  26373. };
  26374. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  26375. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  26376. return vector.applyQuaternion( this );
  26377. };
  26378. Object.assign( Ray.prototype, {
  26379. isIntersectionBox: function ( box ) {
  26380. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  26381. return this.intersectsBox( box );
  26382. },
  26383. isIntersectionPlane: function ( plane ) {
  26384. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  26385. return this.intersectsPlane( plane );
  26386. },
  26387. isIntersectionSphere: function ( sphere ) {
  26388. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  26389. return this.intersectsSphere( sphere );
  26390. }
  26391. } );
  26392. Object.assign( Shape.prototype, {
  26393. extractAllPoints: function ( divisions ) {
  26394. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  26395. return this.extractPoints( divisions );
  26396. },
  26397. extrude: function ( options ) {
  26398. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  26399. return new ExtrudeGeometry( this, options );
  26400. },
  26401. makeGeometry: function ( options ) {
  26402. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  26403. return new ShapeGeometry( this, options );
  26404. }
  26405. } );
  26406. Object.assign( Vector2.prototype, {
  26407. fromAttribute: function ( attribute, index, offset ) {
  26408. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  26409. return this.fromBufferAttribute( attribute, index, offset );
  26410. },
  26411. distanceToManhattan: function ( v ) {
  26412. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  26413. return this.manhattanDistanceTo( v );
  26414. },
  26415. lengthManhattan: function () {
  26416. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  26417. return this.manhattanLength();
  26418. }
  26419. } );
  26420. Object.assign( Vector3.prototype, {
  26421. setEulerFromRotationMatrix: function () {
  26422. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  26423. },
  26424. setEulerFromQuaternion: function () {
  26425. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  26426. },
  26427. getPositionFromMatrix: function ( m ) {
  26428. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  26429. return this.setFromMatrixPosition( m );
  26430. },
  26431. getScaleFromMatrix: function ( m ) {
  26432. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  26433. return this.setFromMatrixScale( m );
  26434. },
  26435. getColumnFromMatrix: function ( index, matrix ) {
  26436. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  26437. return this.setFromMatrixColumn( matrix, index );
  26438. },
  26439. applyProjection: function ( m ) {
  26440. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  26441. return this.applyMatrix4( m );
  26442. },
  26443. fromAttribute: function ( attribute, index, offset ) {
  26444. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  26445. return this.fromBufferAttribute( attribute, index, offset );
  26446. },
  26447. distanceToManhattan: function ( v ) {
  26448. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  26449. return this.manhattanDistanceTo( v );
  26450. },
  26451. lengthManhattan: function () {
  26452. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  26453. return this.manhattanLength();
  26454. }
  26455. } );
  26456. Object.assign( Vector4.prototype, {
  26457. fromAttribute: function ( attribute, index, offset ) {
  26458. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  26459. return this.fromBufferAttribute( attribute, index, offset );
  26460. },
  26461. lengthManhattan: function () {
  26462. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  26463. return this.manhattanLength();
  26464. }
  26465. } );
  26466. //
  26467. Geometry.prototype.computeTangents = function () {
  26468. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  26469. };
  26470. Object.assign( Object3D.prototype, {
  26471. getChildByName: function ( name ) {
  26472. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  26473. return this.getObjectByName( name );
  26474. },
  26475. renderDepth: function () {
  26476. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  26477. },
  26478. translate: function ( distance, axis ) {
  26479. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  26480. return this.translateOnAxis( axis, distance );
  26481. }
  26482. } );
  26483. Object.defineProperties( Object3D.prototype, {
  26484. eulerOrder: {
  26485. get: function () {
  26486. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  26487. return this.rotation.order;
  26488. },
  26489. set: function ( value ) {
  26490. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  26491. this.rotation.order = value;
  26492. }
  26493. },
  26494. useQuaternion: {
  26495. get: function () {
  26496. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  26497. },
  26498. set: function () {
  26499. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  26500. }
  26501. }
  26502. } );
  26503. Object.defineProperties( LOD.prototype, {
  26504. objects: {
  26505. get: function () {
  26506. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  26507. return this.levels;
  26508. }
  26509. }
  26510. } );
  26511. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  26512. get: function () {
  26513. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  26514. },
  26515. set: function () {
  26516. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  26517. }
  26518. } );
  26519. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  26520. get: function () {
  26521. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  26522. return this.arcLengthDivisions;
  26523. },
  26524. set: function ( value ) {
  26525. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  26526. this.arcLengthDivisions = value;
  26527. }
  26528. } );
  26529. //
  26530. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  26531. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  26532. "Use .setFocalLength and .filmGauge for a photographic setup." );
  26533. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  26534. this.setFocalLength( focalLength );
  26535. };
  26536. //
  26537. Object.defineProperties( Light.prototype, {
  26538. onlyShadow: {
  26539. set: function () {
  26540. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  26541. }
  26542. },
  26543. shadowCameraFov: {
  26544. set: function ( value ) {
  26545. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  26546. this.shadow.camera.fov = value;
  26547. }
  26548. },
  26549. shadowCameraLeft: {
  26550. set: function ( value ) {
  26551. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  26552. this.shadow.camera.left = value;
  26553. }
  26554. },
  26555. shadowCameraRight: {
  26556. set: function ( value ) {
  26557. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  26558. this.shadow.camera.right = value;
  26559. }
  26560. },
  26561. shadowCameraTop: {
  26562. set: function ( value ) {
  26563. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  26564. this.shadow.camera.top = value;
  26565. }
  26566. },
  26567. shadowCameraBottom: {
  26568. set: function ( value ) {
  26569. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  26570. this.shadow.camera.bottom = value;
  26571. }
  26572. },
  26573. shadowCameraNear: {
  26574. set: function ( value ) {
  26575. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  26576. this.shadow.camera.near = value;
  26577. }
  26578. },
  26579. shadowCameraFar: {
  26580. set: function ( value ) {
  26581. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  26582. this.shadow.camera.far = value;
  26583. }
  26584. },
  26585. shadowCameraVisible: {
  26586. set: function () {
  26587. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  26588. }
  26589. },
  26590. shadowBias: {
  26591. set: function ( value ) {
  26592. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  26593. this.shadow.bias = value;
  26594. }
  26595. },
  26596. shadowDarkness: {
  26597. set: function () {
  26598. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  26599. }
  26600. },
  26601. shadowMapWidth: {
  26602. set: function ( value ) {
  26603. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  26604. this.shadow.mapSize.width = value;
  26605. }
  26606. },
  26607. shadowMapHeight: {
  26608. set: function ( value ) {
  26609. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  26610. this.shadow.mapSize.height = value;
  26611. }
  26612. }
  26613. } );
  26614. //
  26615. Object.defineProperties( BufferAttribute.prototype, {
  26616. length: {
  26617. get: function () {
  26618. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  26619. return this.array.length;
  26620. }
  26621. }
  26622. } );
  26623. Object.assign( BufferGeometry.prototype, {
  26624. addIndex: function ( index ) {
  26625. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  26626. this.setIndex( index );
  26627. },
  26628. addDrawCall: function ( start, count, indexOffset ) {
  26629. if ( indexOffset !== undefined ) {
  26630. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  26631. }
  26632. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  26633. this.addGroup( start, count );
  26634. },
  26635. clearDrawCalls: function () {
  26636. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  26637. this.clearGroups();
  26638. },
  26639. computeTangents: function () {
  26640. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  26641. },
  26642. computeOffsets: function () {
  26643. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  26644. }
  26645. } );
  26646. Object.defineProperties( BufferGeometry.prototype, {
  26647. drawcalls: {
  26648. get: function () {
  26649. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  26650. return this.groups;
  26651. }
  26652. },
  26653. offsets: {
  26654. get: function () {
  26655. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  26656. return this.groups;
  26657. }
  26658. }
  26659. } );
  26660. //
  26661. Object.defineProperties( Uniform.prototype, {
  26662. dynamic: {
  26663. set: function () {
  26664. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  26665. }
  26666. },
  26667. onUpdate: {
  26668. value: function () {
  26669. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  26670. return this;
  26671. }
  26672. }
  26673. } );
  26674. //
  26675. Object.defineProperties( Material.prototype, {
  26676. wrapAround: {
  26677. get: function () {
  26678. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  26679. },
  26680. set: function () {
  26681. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  26682. }
  26683. },
  26684. wrapRGB: {
  26685. get: function () {
  26686. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  26687. return new Color();
  26688. }
  26689. },
  26690. shading: {
  26691. get: function () {
  26692. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  26693. },
  26694. set: function ( value ) {
  26695. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  26696. this.flatShading = ( value === FlatShading );
  26697. }
  26698. }
  26699. } );
  26700. Object.defineProperties( MeshPhongMaterial.prototype, {
  26701. metal: {
  26702. get: function () {
  26703. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  26704. return false;
  26705. },
  26706. set: function () {
  26707. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  26708. }
  26709. }
  26710. } );
  26711. Object.defineProperties( ShaderMaterial.prototype, {
  26712. derivatives: {
  26713. get: function () {
  26714. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  26715. return this.extensions.derivatives;
  26716. },
  26717. set: function ( value ) {
  26718. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  26719. this.extensions.derivatives = value;
  26720. }
  26721. }
  26722. } );
  26723. //
  26724. Object.assign( WebGLRenderer.prototype, {
  26725. getCurrentRenderTarget: function () {
  26726. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  26727. return this.getRenderTarget();
  26728. },
  26729. getMaxAnisotropy: function () {
  26730. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  26731. return this.capabilities.getMaxAnisotropy();
  26732. },
  26733. getPrecision: function () {
  26734. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  26735. return this.capabilities.precision;
  26736. },
  26737. resetGLState: function () {
  26738. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  26739. return this.state.reset();
  26740. },
  26741. supportsFloatTextures: function () {
  26742. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  26743. return this.extensions.get( 'OES_texture_float' );
  26744. },
  26745. supportsHalfFloatTextures: function () {
  26746. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  26747. return this.extensions.get( 'OES_texture_half_float' );
  26748. },
  26749. supportsStandardDerivatives: function () {
  26750. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  26751. return this.extensions.get( 'OES_standard_derivatives' );
  26752. },
  26753. supportsCompressedTextureS3TC: function () {
  26754. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  26755. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  26756. },
  26757. supportsCompressedTexturePVRTC: function () {
  26758. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  26759. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  26760. },
  26761. supportsBlendMinMax: function () {
  26762. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  26763. return this.extensions.get( 'EXT_blend_minmax' );
  26764. },
  26765. supportsVertexTextures: function () {
  26766. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  26767. return this.capabilities.vertexTextures;
  26768. },
  26769. supportsInstancedArrays: function () {
  26770. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  26771. return this.extensions.get( 'ANGLE_instanced_arrays' );
  26772. },
  26773. enableScissorTest: function ( boolean ) {
  26774. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  26775. this.setScissorTest( boolean );
  26776. },
  26777. initMaterial: function () {
  26778. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  26779. },
  26780. addPrePlugin: function () {
  26781. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  26782. },
  26783. addPostPlugin: function () {
  26784. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  26785. },
  26786. updateShadowMap: function () {
  26787. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  26788. },
  26789. setFaceCulling: function () {
  26790. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  26791. }
  26792. } );
  26793. Object.defineProperties( WebGLRenderer.prototype, {
  26794. shadowMapEnabled: {
  26795. get: function () {
  26796. return this.shadowMap.enabled;
  26797. },
  26798. set: function ( value ) {
  26799. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  26800. this.shadowMap.enabled = value;
  26801. }
  26802. },
  26803. shadowMapType: {
  26804. get: function () {
  26805. return this.shadowMap.type;
  26806. },
  26807. set: function ( value ) {
  26808. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  26809. this.shadowMap.type = value;
  26810. }
  26811. },
  26812. shadowMapCullFace: {
  26813. get: function () {
  26814. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  26815. return undefined;
  26816. },
  26817. set: function ( /* value */ ) {
  26818. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  26819. }
  26820. }
  26821. } );
  26822. Object.defineProperties( WebGLShadowMap.prototype, {
  26823. cullFace: {
  26824. get: function () {
  26825. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  26826. return undefined;
  26827. },
  26828. set: function ( /* cullFace */ ) {
  26829. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  26830. }
  26831. },
  26832. renderReverseSided: {
  26833. get: function () {
  26834. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  26835. return undefined;
  26836. },
  26837. set: function () {
  26838. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  26839. }
  26840. },
  26841. renderSingleSided: {
  26842. get: function () {
  26843. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  26844. return undefined;
  26845. },
  26846. set: function () {
  26847. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  26848. }
  26849. }
  26850. } );
  26851. //
  26852. Object.defineProperties( WebGLRenderTarget.prototype, {
  26853. wrapS: {
  26854. get: function () {
  26855. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  26856. return this.texture.wrapS;
  26857. },
  26858. set: function ( value ) {
  26859. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  26860. this.texture.wrapS = value;
  26861. }
  26862. },
  26863. wrapT: {
  26864. get: function () {
  26865. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  26866. return this.texture.wrapT;
  26867. },
  26868. set: function ( value ) {
  26869. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  26870. this.texture.wrapT = value;
  26871. }
  26872. },
  26873. magFilter: {
  26874. get: function () {
  26875. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  26876. return this.texture.magFilter;
  26877. },
  26878. set: function ( value ) {
  26879. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  26880. this.texture.magFilter = value;
  26881. }
  26882. },
  26883. minFilter: {
  26884. get: function () {
  26885. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  26886. return this.texture.minFilter;
  26887. },
  26888. set: function ( value ) {
  26889. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  26890. this.texture.minFilter = value;
  26891. }
  26892. },
  26893. anisotropy: {
  26894. get: function () {
  26895. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  26896. return this.texture.anisotropy;
  26897. },
  26898. set: function ( value ) {
  26899. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  26900. this.texture.anisotropy = value;
  26901. }
  26902. },
  26903. offset: {
  26904. get: function () {
  26905. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  26906. return this.texture.offset;
  26907. },
  26908. set: function ( value ) {
  26909. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  26910. this.texture.offset = value;
  26911. }
  26912. },
  26913. repeat: {
  26914. get: function () {
  26915. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  26916. return this.texture.repeat;
  26917. },
  26918. set: function ( value ) {
  26919. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  26920. this.texture.repeat = value;
  26921. }
  26922. },
  26923. format: {
  26924. get: function () {
  26925. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  26926. return this.texture.format;
  26927. },
  26928. set: function ( value ) {
  26929. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  26930. this.texture.format = value;
  26931. }
  26932. },
  26933. type: {
  26934. get: function () {
  26935. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  26936. return this.texture.type;
  26937. },
  26938. set: function ( value ) {
  26939. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  26940. this.texture.type = value;
  26941. }
  26942. },
  26943. generateMipmaps: {
  26944. get: function () {
  26945. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  26946. return this.texture.generateMipmaps;
  26947. },
  26948. set: function ( value ) {
  26949. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  26950. this.texture.generateMipmaps = value;
  26951. }
  26952. }
  26953. } );
  26954. //
  26955. Object.assign( WebVRManager.prototype, {
  26956. getStandingMatrix: function () {
  26957. console.warn( 'THREE.WebVRManager: .getStandingMatrix() has been removed.' );
  26958. }
  26959. } );
  26960. Object.defineProperties( WebVRManager.prototype, {
  26961. standing: {
  26962. set: function ( /* value */ ) {
  26963. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  26964. }
  26965. }
  26966. } );
  26967. //
  26968. Audio.prototype.load = function ( file ) {
  26969. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  26970. var scope = this;
  26971. var audioLoader = new AudioLoader();
  26972. audioLoader.load( file, function ( buffer ) {
  26973. scope.setBuffer( buffer );
  26974. } );
  26975. return this;
  26976. };
  26977. AudioAnalyser.prototype.getData = function () {
  26978. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  26979. return this.getFrequencyData();
  26980. };
  26981. //
  26982. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  26983. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  26984. return this.update( renderer, scene );
  26985. };
  26986. //
  26987. var GeometryUtils = {
  26988. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  26989. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  26990. var matrix;
  26991. if ( geometry2.isMesh ) {
  26992. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  26993. matrix = geometry2.matrix;
  26994. geometry2 = geometry2.geometry;
  26995. }
  26996. geometry1.merge( geometry2, matrix, materialIndexOffset );
  26997. },
  26998. center: function ( geometry ) {
  26999. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  27000. return geometry.center();
  27001. }
  27002. };
  27003. var ImageUtils = {
  27004. crossOrigin: undefined,
  27005. loadTexture: function ( url, mapping, onLoad, onError ) {
  27006. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  27007. var loader = new TextureLoader();
  27008. loader.setCrossOrigin( this.crossOrigin );
  27009. var texture = loader.load( url, onLoad, undefined, onError );
  27010. if ( mapping ) texture.mapping = mapping;
  27011. return texture;
  27012. },
  27013. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  27014. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  27015. var loader = new CubeTextureLoader();
  27016. loader.setCrossOrigin( this.crossOrigin );
  27017. var texture = loader.load( urls, onLoad, undefined, onError );
  27018. if ( mapping ) texture.mapping = mapping;
  27019. return texture;
  27020. },
  27021. loadCompressedTexture: function () {
  27022. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  27023. },
  27024. loadCompressedTextureCube: function () {
  27025. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  27026. }
  27027. };
  27028. //
  27029. function Projector() {
  27030. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  27031. this.projectVector = function ( vector, camera ) {
  27032. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  27033. vector.project( camera );
  27034. };
  27035. this.unprojectVector = function ( vector, camera ) {
  27036. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  27037. vector.unproject( camera );
  27038. };
  27039. this.pickingRay = function () {
  27040. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  27041. };
  27042. }
  27043. //
  27044. function CanvasRenderer() {
  27045. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  27046. this.domElement = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  27047. this.clear = function () {};
  27048. this.render = function () {};
  27049. this.setClearColor = function () {};
  27050. this.setSize = function () {};
  27051. }
  27052. //
  27053. var SceneUtils = {
  27054. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  27055. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  27056. },
  27057. detach: function ( /* child, parent, scene */ ) {
  27058. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  27059. },
  27060. attach: function ( /* child, scene, parent */ ) {
  27061. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  27062. }
  27063. };
  27064. //
  27065. function LensFlare() {
  27066. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/LensFlare.js' );
  27067. }
  27068. export { WebGLRenderTargetCube, WebGLRenderTarget, WebGLRenderer, ShaderLib, UniformsLib, UniformsUtils, ShaderChunk, FogExp2, Fog, Scene, Sprite, LOD, SkinnedMesh, Skeleton, Bone, Mesh, LineSegments, LineLoop, Line, Points, Group, VideoTexture, DataTexture, CompressedTexture, CubeTexture, CanvasTexture, DepthTexture, Texture, CompressedTextureLoader, DataTextureLoader, CubeTextureLoader, TextureLoader, ObjectLoader, MaterialLoader, BufferGeometryLoader, DefaultLoadingManager, LoadingManager, JSONLoader, ImageLoader, ImageBitmapLoader, FontLoader, FileLoader, Loader, LoaderUtils, Cache, AudioLoader, SpotLightShadow, SpotLight, PointLight, RectAreaLight, HemisphereLight, DirectionalLightShadow, DirectionalLight, AmbientLight, LightShadow, Light, StereoCamera, PerspectiveCamera, OrthographicCamera, CubeCamera, ArrayCamera, Camera, AudioListener, PositionalAudio, AudioContext, AudioAnalyser, Audio, VectorKeyframeTrack, StringKeyframeTrack, QuaternionKeyframeTrack, NumberKeyframeTrack, ColorKeyframeTrack, BooleanKeyframeTrack, PropertyMixer, PropertyBinding, KeyframeTrack, AnimationUtils, AnimationObjectGroup, AnimationMixer, AnimationClip, Uniform, InstancedBufferGeometry, BufferGeometry, Geometry, InterleavedBufferAttribute, InstancedInterleavedBuffer, InterleavedBuffer, InstancedBufferAttribute, Face3, Object3D, Raycaster, Layers, EventDispatcher, Clock, QuaternionLinearInterpolant, LinearInterpolant, DiscreteInterpolant, CubicInterpolant, Interpolant, Triangle, _Math as Math, Spherical, Cylindrical, Plane, Frustum, Sphere, Ray, Matrix4, Matrix3, Box3, Box2, Line3, Euler, Vector4, Vector3, Vector2, Quaternion, Color, ImmediateRenderObject, VertexNormalsHelper, SpotLightHelper, SkeletonHelper, PointLightHelper, RectAreaLightHelper, HemisphereLightHelper, GridHelper, PolarGridHelper, FaceNormalsHelper, DirectionalLightHelper, CameraHelper, BoxHelper, Box3Helper, PlaneHelper, ArrowHelper, AxesHelper, Shape, Path, ShapePath, Font, CurvePath, Curve, ShapeUtils, WebGLUtils, WireframeGeometry, ParametricGeometry, ParametricBufferGeometry, TetrahedronGeometry, TetrahedronBufferGeometry, OctahedronGeometry, OctahedronBufferGeometry, IcosahedronGeometry, IcosahedronBufferGeometry, DodecahedronGeometry, DodecahedronBufferGeometry, PolyhedronGeometry, PolyhedronBufferGeometry, TubeGeometry, TubeBufferGeometry, TorusKnotGeometry, TorusKnotBufferGeometry, TorusGeometry, TorusBufferGeometry, TextGeometry, TextBufferGeometry, SphereGeometry, SphereBufferGeometry, RingGeometry, RingBufferGeometry, PlaneGeometry, PlaneBufferGeometry, LatheGeometry, LatheBufferGeometry, ShapeGeometry, ShapeBufferGeometry, ExtrudeGeometry, ExtrudeBufferGeometry, EdgesGeometry, ConeGeometry, ConeBufferGeometry, CylinderGeometry, CylinderBufferGeometry, CircleGeometry, CircleBufferGeometry, BoxGeometry, BoxBufferGeometry, ShadowMaterial, SpriteMaterial, RawShaderMaterial, ShaderMaterial, PointsMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshPhongMaterial, MeshToonMaterial, MeshNormalMaterial, MeshLambertMaterial, MeshDepthMaterial, MeshDistanceMaterial, MeshBasicMaterial, LineDashedMaterial, LineBasicMaterial, Material, Float64BufferAttribute, Float32BufferAttribute, Uint32BufferAttribute, Int32BufferAttribute, Uint16BufferAttribute, Int16BufferAttribute, Uint8ClampedBufferAttribute, Uint8BufferAttribute, Int8BufferAttribute, BufferAttribute, ArcCurve, CatmullRomCurve3, CubicBezierCurve, CubicBezierCurve3, EllipseCurve, LineCurve, LineCurve3, QuadraticBezierCurve, QuadraticBezierCurve3, SplineCurve, REVISION, MOUSE, CullFaceNone, CullFaceBack, CullFaceFront, CullFaceFrontBack, FrontFaceDirectionCW, FrontFaceDirectionCCW, BasicShadowMap, PCFShadowMap, PCFSoftShadowMap, FrontSide, BackSide, DoubleSide, FlatShading, SmoothShading, NoColors, FaceColors, VertexColors, NoBlending, NormalBlending, AdditiveBlending, SubtractiveBlending, MultiplyBlending, CustomBlending, AddEquation, SubtractEquation, ReverseSubtractEquation, MinEquation, MaxEquation, ZeroFactor, OneFactor, SrcColorFactor, OneMinusSrcColorFactor, SrcAlphaFactor, OneMinusSrcAlphaFactor, DstAlphaFactor, OneMinusDstAlphaFactor, DstColorFactor, OneMinusDstColorFactor, SrcAlphaSaturateFactor, NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth, MultiplyOperation, MixOperation, AddOperation, NoToneMapping, LinearToneMapping, ReinhardToneMapping, Uncharted2ToneMapping, CineonToneMapping, UVMapping, CubeReflectionMapping, CubeRefractionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping, SphericalReflectionMapping, CubeUVReflectionMapping, CubeUVRefractionMapping, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter, LinearFilter, LinearMipMapNearestFilter, LinearMipMapLinearFilter, UnsignedByteType, ByteType, ShortType, UnsignedShortType, IntType, UnsignedIntType, FloatType, HalfFloatType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShort565Type, UnsignedInt248Type, AlphaFormat, RGBFormat, RGBAFormat, LuminanceFormat, LuminanceAlphaFormat, RGBEFormat, DepthFormat, DepthStencilFormat, RGB_S3TC_DXT1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGB_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_PVRTC_2BPPV1_Format, RGB_ETC1_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, LoopOnce, LoopRepeat, LoopPingPong, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, ZeroCurvatureEnding, ZeroSlopeEnding, WrapAroundEnding, TrianglesDrawMode, TriangleStripDrawMode, TriangleFanDrawMode, LinearEncoding, sRGBEncoding, GammaEncoding, RGBEEncoding, LogLuvEncoding, RGBM7Encoding, RGBM16Encoding, RGBDEncoding, BasicDepthPacking, RGBADepthPacking, BoxGeometry as CubeGeometry, Face4, LineStrip, LinePieces, MeshFaceMaterial, MultiMaterial, PointCloud, Particle, ParticleSystem, PointCloudMaterial, ParticleBasicMaterial, ParticleSystemMaterial, Vertex, DynamicBufferAttribute, Int8Attribute, Uint8Attribute, Uint8ClampedAttribute, Int16Attribute, Uint16Attribute, Int32Attribute, Uint32Attribute, Float32Attribute, Float64Attribute, ClosedSplineCurve3, SplineCurve3, Spline, AxisHelper, BoundingBoxHelper, EdgesHelper, WireframeHelper, XHRLoader, BinaryTextureLoader, GeometryUtils, ImageUtils, Projector, CanvasRenderer, SceneUtils, LensFlare };