Anders and Briegel in Python
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 8 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '75' };
  6. //
  7. if ( typeof define === 'function' && define.amd ) {
  8. define( 'three', THREE );
  9. } else if ( 'undefined' !== typeof exports && 'undefined' !== typeof module ) {
  10. module.exports = THREE;
  11. }
  12. //
  13. if ( Number.EPSILON === undefined ) {
  14. Number.EPSILON = Math.pow( 2, - 52 );
  15. }
  16. //
  17. if ( Math.sign === undefined ) {
  18. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  19. Math.sign = function ( x ) {
  20. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  21. };
  22. }
  23. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  24. // Missing in IE9-11.
  25. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  26. Object.defineProperty( Function.prototype, 'name', {
  27. get: function () {
  28. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  29. }
  30. } );
  31. }
  32. if ( Object.assign === undefined ) {
  33. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  34. Object.defineProperty( Object, 'assign', {
  35. writable: true,
  36. configurable: true,
  37. value: function ( target ) {
  38. 'use strict';
  39. if ( target === undefined || target === null ) {
  40. throw new TypeError( "Cannot convert first argument to object" );
  41. }
  42. var to = Object( target );
  43. for ( var i = 1, n = arguments.length; i !== n; ++ i ) {
  44. var nextSource = arguments[ i ];
  45. if ( nextSource === undefined || nextSource === null ) continue;
  46. nextSource = Object( nextSource );
  47. var keysArray = Object.keys( nextSource );
  48. for ( var nextIndex = 0, len = keysArray.length; nextIndex !== len; ++ nextIndex ) {
  49. var nextKey = keysArray[ nextIndex ];
  50. var desc = Object.getOwnPropertyDescriptor( nextSource, nextKey );
  51. if ( desc !== undefined && desc.enumerable ) {
  52. to[ nextKey ] = nextSource[ nextKey ];
  53. }
  54. }
  55. }
  56. return to;
  57. }
  58. } );
  59. }
  60. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  61. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  62. // GL STATE CONSTANTS
  63. THREE.CullFaceNone = 0;
  64. THREE.CullFaceBack = 1;
  65. THREE.CullFaceFront = 2;
  66. THREE.CullFaceFrontBack = 3;
  67. THREE.FrontFaceDirectionCW = 0;
  68. THREE.FrontFaceDirectionCCW = 1;
  69. // SHADOWING TYPES
  70. THREE.BasicShadowMap = 0;
  71. THREE.PCFShadowMap = 1;
  72. THREE.PCFSoftShadowMap = 2;
  73. // MATERIAL CONSTANTS
  74. // side
  75. THREE.FrontSide = 0;
  76. THREE.BackSide = 1;
  77. THREE.DoubleSide = 2;
  78. // shading
  79. THREE.FlatShading = 1;
  80. THREE.SmoothShading = 2;
  81. // colors
  82. THREE.NoColors = 0;
  83. THREE.FaceColors = 1;
  84. THREE.VertexColors = 2;
  85. // blending modes
  86. THREE.NoBlending = 0;
  87. THREE.NormalBlending = 1;
  88. THREE.AdditiveBlending = 2;
  89. THREE.SubtractiveBlending = 3;
  90. THREE.MultiplyBlending = 4;
  91. THREE.CustomBlending = 5;
  92. // custom blending equations
  93. // (numbers start from 100 not to clash with other
  94. // mappings to OpenGL constants defined in Texture.js)
  95. THREE.AddEquation = 100;
  96. THREE.SubtractEquation = 101;
  97. THREE.ReverseSubtractEquation = 102;
  98. THREE.MinEquation = 103;
  99. THREE.MaxEquation = 104;
  100. // custom blending destination factors
  101. THREE.ZeroFactor = 200;
  102. THREE.OneFactor = 201;
  103. THREE.SrcColorFactor = 202;
  104. THREE.OneMinusSrcColorFactor = 203;
  105. THREE.SrcAlphaFactor = 204;
  106. THREE.OneMinusSrcAlphaFactor = 205;
  107. THREE.DstAlphaFactor = 206;
  108. THREE.OneMinusDstAlphaFactor = 207;
  109. // custom blending source factors
  110. //THREE.ZeroFactor = 200;
  111. //THREE.OneFactor = 201;
  112. //THREE.SrcAlphaFactor = 204;
  113. //THREE.OneMinusSrcAlphaFactor = 205;
  114. //THREE.DstAlphaFactor = 206;
  115. //THREE.OneMinusDstAlphaFactor = 207;
  116. THREE.DstColorFactor = 208;
  117. THREE.OneMinusDstColorFactor = 209;
  118. THREE.SrcAlphaSaturateFactor = 210;
  119. // depth modes
  120. THREE.NeverDepth = 0;
  121. THREE.AlwaysDepth = 1;
  122. THREE.LessDepth = 2;
  123. THREE.LessEqualDepth = 3;
  124. THREE.EqualDepth = 4;
  125. THREE.GreaterEqualDepth = 5;
  126. THREE.GreaterDepth = 6;
  127. THREE.NotEqualDepth = 7;
  128. // TEXTURE CONSTANTS
  129. THREE.MultiplyOperation = 0;
  130. THREE.MixOperation = 1;
  131. THREE.AddOperation = 2;
  132. // Tone Mapping modes
  133. THREE.NoToneMapping = 0; // do not do any tone mapping, not even exposure (required for special purpose passes.)
  134. THREE.LinearToneMapping = 1; // only apply exposure.
  135. THREE.ReinhardToneMapping = 2;
  136. THREE.Uncharted2ToneMapping = 3; // John Hable
  137. THREE.CineonToneMapping = 4; // optimized filmic operator by Jim Hejl and Richard Burgess-Dawson
  138. // Mapping modes
  139. THREE.UVMapping = 300;
  140. THREE.CubeReflectionMapping = 301;
  141. THREE.CubeRefractionMapping = 302;
  142. THREE.EquirectangularReflectionMapping = 303;
  143. THREE.EquirectangularRefractionMapping = 304;
  144. THREE.SphericalReflectionMapping = 305;
  145. THREE.CubeUVReflectionMapping = 306;
  146. THREE.CubeUVRefractionMapping = 307;
  147. // Wrapping modes
  148. THREE.RepeatWrapping = 1000;
  149. THREE.ClampToEdgeWrapping = 1001;
  150. THREE.MirroredRepeatWrapping = 1002;
  151. // Filters
  152. THREE.NearestFilter = 1003;
  153. THREE.NearestMipMapNearestFilter = 1004;
  154. THREE.NearestMipMapLinearFilter = 1005;
  155. THREE.LinearFilter = 1006;
  156. THREE.LinearMipMapNearestFilter = 1007;
  157. THREE.LinearMipMapLinearFilter = 1008;
  158. // Data types
  159. THREE.UnsignedByteType = 1009;
  160. THREE.ByteType = 1010;
  161. THREE.ShortType = 1011;
  162. THREE.UnsignedShortType = 1012;
  163. THREE.IntType = 1013;
  164. THREE.UnsignedIntType = 1014;
  165. THREE.FloatType = 1015;
  166. THREE.HalfFloatType = 1025;
  167. // Pixel types
  168. //THREE.UnsignedByteType = 1009;
  169. THREE.UnsignedShort4444Type = 1016;
  170. THREE.UnsignedShort5551Type = 1017;
  171. THREE.UnsignedShort565Type = 1018;
  172. // Pixel formats
  173. THREE.AlphaFormat = 1019;
  174. THREE.RGBFormat = 1020;
  175. THREE.RGBAFormat = 1021;
  176. THREE.LuminanceFormat = 1022;
  177. THREE.LuminanceAlphaFormat = 1023;
  178. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  179. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  180. // DDS / ST3C Compressed texture formats
  181. THREE.RGB_S3TC_DXT1_Format = 2001;
  182. THREE.RGBA_S3TC_DXT1_Format = 2002;
  183. THREE.RGBA_S3TC_DXT3_Format = 2003;
  184. THREE.RGBA_S3TC_DXT5_Format = 2004;
  185. // PVRTC compressed texture formats
  186. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  187. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  188. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  189. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  190. // ETC compressed texture formats
  191. THREE.RGB_ETC1_Format = 2151;
  192. // Loop styles for AnimationAction
  193. THREE.LoopOnce = 2200;
  194. THREE.LoopRepeat = 2201;
  195. THREE.LoopPingPong = 2202;
  196. // Interpolation
  197. THREE.InterpolateDiscrete = 2300;
  198. THREE.InterpolateLinear = 2301;
  199. THREE.InterpolateSmooth = 2302;
  200. // Interpolant ending modes
  201. THREE.ZeroCurvatureEnding = 2400;
  202. THREE.ZeroSlopeEnding = 2401;
  203. THREE.WrapAroundEnding = 2402;
  204. // Triangle Draw modes
  205. THREE.TrianglesDrawMode = 0;
  206. THREE.TriangleStripDrawMode = 1;
  207. THREE.TriangleFanDrawMode = 2;
  208. // Texture Encodings
  209. THREE.LinearEncoding = 3000; // No encoding at all.
  210. THREE.sRGBEncoding = 3001;
  211. THREE.GammaEncoding = 3007; // uses GAMMA_FACTOR, for backwards compatibility with WebGLRenderer.gammaInput/gammaOutput
  212. // The following Texture Encodings are for RGB-only (no alpha) HDR light emission sources.
  213. // These encodings should not specified as output encodings except in rare situations.
  214. THREE.RGBEEncoding = 3002; // AKA Radiance.
  215. THREE.LogLuvEncoding = 3003;
  216. THREE.RGBM7Encoding = 3004;
  217. THREE.RGBM16Encoding = 3005;
  218. THREE.RGBDEncoding = 3006; // MaxRange is 256.
  219. // File:src/math/Color.js
  220. /**
  221. * @author mrdoob / http://mrdoob.com/
  222. */
  223. THREE.Color = function ( color ) {
  224. if ( arguments.length === 3 ) {
  225. return this.fromArray( arguments );
  226. }
  227. return this.set( color );
  228. };
  229. THREE.Color.prototype = {
  230. constructor: THREE.Color,
  231. r: 1, g: 1, b: 1,
  232. set: function ( value ) {
  233. if ( value instanceof THREE.Color ) {
  234. this.copy( value );
  235. } else if ( typeof value === 'number' ) {
  236. this.setHex( value );
  237. } else if ( typeof value === 'string' ) {
  238. this.setStyle( value );
  239. }
  240. return this;
  241. },
  242. setScalar: function ( scalar ) {
  243. this.r = scalar;
  244. this.g = scalar;
  245. this.b = scalar;
  246. },
  247. setHex: function ( hex ) {
  248. hex = Math.floor( hex );
  249. this.r = ( hex >> 16 & 255 ) / 255;
  250. this.g = ( hex >> 8 & 255 ) / 255;
  251. this.b = ( hex & 255 ) / 255;
  252. return this;
  253. },
  254. setRGB: function ( r, g, b ) {
  255. this.r = r;
  256. this.g = g;
  257. this.b = b;
  258. return this;
  259. },
  260. setHSL: function () {
  261. function hue2rgb( p, q, t ) {
  262. if ( t < 0 ) t += 1;
  263. if ( t > 1 ) t -= 1;
  264. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  265. if ( t < 1 / 2 ) return q;
  266. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  267. return p;
  268. }
  269. return function ( h, s, l ) {
  270. // h,s,l ranges are in 0.0 - 1.0
  271. h = THREE.Math.euclideanModulo( h, 1 );
  272. s = THREE.Math.clamp( s, 0, 1 );
  273. l = THREE.Math.clamp( l, 0, 1 );
  274. if ( s === 0 ) {
  275. this.r = this.g = this.b = l;
  276. } else {
  277. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  278. var q = ( 2 * l ) - p;
  279. this.r = hue2rgb( q, p, h + 1 / 3 );
  280. this.g = hue2rgb( q, p, h );
  281. this.b = hue2rgb( q, p, h - 1 / 3 );
  282. }
  283. return this;
  284. };
  285. }(),
  286. setStyle: function ( style ) {
  287. function handleAlpha( string ) {
  288. if ( string === undefined ) return;
  289. if ( parseFloat( string ) < 1 ) {
  290. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  291. }
  292. }
  293. var m;
  294. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  295. // rgb / hsl
  296. var color;
  297. var name = m[ 1 ];
  298. var components = m[ 2 ];
  299. switch ( name ) {
  300. case 'rgb':
  301. case 'rgba':
  302. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  303. // rgb(255,0,0) rgba(255,0,0,0.5)
  304. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  305. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  306. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  307. handleAlpha( color[ 5 ] );
  308. return this;
  309. }
  310. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  311. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  312. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  313. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  314. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  315. handleAlpha( color[ 5 ] );
  316. return this;
  317. }
  318. break;
  319. case 'hsl':
  320. case 'hsla':
  321. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  322. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  323. var h = parseFloat( color[ 1 ] ) / 360;
  324. var s = parseInt( color[ 2 ], 10 ) / 100;
  325. var l = parseInt( color[ 3 ], 10 ) / 100;
  326. handleAlpha( color[ 5 ] );
  327. return this.setHSL( h, s, l );
  328. }
  329. break;
  330. }
  331. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  332. // hex color
  333. var hex = m[ 1 ];
  334. var size = hex.length;
  335. if ( size === 3 ) {
  336. // #ff0
  337. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  338. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  339. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  340. return this;
  341. } else if ( size === 6 ) {
  342. // #ff0000
  343. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  344. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  345. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  346. return this;
  347. }
  348. }
  349. if ( style && style.length > 0 ) {
  350. // color keywords
  351. var hex = THREE.ColorKeywords[ style ];
  352. if ( hex !== undefined ) {
  353. // red
  354. this.setHex( hex );
  355. } else {
  356. // unknown color
  357. console.warn( 'THREE.Color: Unknown color ' + style );
  358. }
  359. }
  360. return this;
  361. },
  362. clone: function () {
  363. return new this.constructor( this.r, this.g, this.b );
  364. },
  365. copy: function ( color ) {
  366. this.r = color.r;
  367. this.g = color.g;
  368. this.b = color.b;
  369. return this;
  370. },
  371. copyGammaToLinear: function ( color, gammaFactor ) {
  372. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  373. this.r = Math.pow( color.r, gammaFactor );
  374. this.g = Math.pow( color.g, gammaFactor );
  375. this.b = Math.pow( color.b, gammaFactor );
  376. return this;
  377. },
  378. copyLinearToGamma: function ( color, gammaFactor ) {
  379. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  380. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  381. this.r = Math.pow( color.r, safeInverse );
  382. this.g = Math.pow( color.g, safeInverse );
  383. this.b = Math.pow( color.b, safeInverse );
  384. return this;
  385. },
  386. convertGammaToLinear: function () {
  387. var r = this.r, g = this.g, b = this.b;
  388. this.r = r * r;
  389. this.g = g * g;
  390. this.b = b * b;
  391. return this;
  392. },
  393. convertLinearToGamma: function () {
  394. this.r = Math.sqrt( this.r );
  395. this.g = Math.sqrt( this.g );
  396. this.b = Math.sqrt( this.b );
  397. return this;
  398. },
  399. getHex: function () {
  400. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  401. },
  402. getHexString: function () {
  403. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  404. },
  405. getHSL: function ( optionalTarget ) {
  406. // h,s,l ranges are in 0.0 - 1.0
  407. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  408. var r = this.r, g = this.g, b = this.b;
  409. var max = Math.max( r, g, b );
  410. var min = Math.min( r, g, b );
  411. var hue, saturation;
  412. var lightness = ( min + max ) / 2.0;
  413. if ( min === max ) {
  414. hue = 0;
  415. saturation = 0;
  416. } else {
  417. var delta = max - min;
  418. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  419. switch ( max ) {
  420. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  421. case g: hue = ( b - r ) / delta + 2; break;
  422. case b: hue = ( r - g ) / delta + 4; break;
  423. }
  424. hue /= 6;
  425. }
  426. hsl.h = hue;
  427. hsl.s = saturation;
  428. hsl.l = lightness;
  429. return hsl;
  430. },
  431. getStyle: function () {
  432. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  433. },
  434. offsetHSL: function ( h, s, l ) {
  435. var hsl = this.getHSL();
  436. hsl.h += h; hsl.s += s; hsl.l += l;
  437. this.setHSL( hsl.h, hsl.s, hsl.l );
  438. return this;
  439. },
  440. add: function ( color ) {
  441. this.r += color.r;
  442. this.g += color.g;
  443. this.b += color.b;
  444. return this;
  445. },
  446. addColors: function ( color1, color2 ) {
  447. this.r = color1.r + color2.r;
  448. this.g = color1.g + color2.g;
  449. this.b = color1.b + color2.b;
  450. return this;
  451. },
  452. addScalar: function ( s ) {
  453. this.r += s;
  454. this.g += s;
  455. this.b += s;
  456. return this;
  457. },
  458. multiply: function ( color ) {
  459. this.r *= color.r;
  460. this.g *= color.g;
  461. this.b *= color.b;
  462. return this;
  463. },
  464. multiplyScalar: function ( s ) {
  465. this.r *= s;
  466. this.g *= s;
  467. this.b *= s;
  468. return this;
  469. },
  470. lerp: function ( color, alpha ) {
  471. this.r += ( color.r - this.r ) * alpha;
  472. this.g += ( color.g - this.g ) * alpha;
  473. this.b += ( color.b - this.b ) * alpha;
  474. return this;
  475. },
  476. equals: function ( c ) {
  477. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  478. },
  479. fromArray: function ( array, offset ) {
  480. if ( offset === undefined ) offset = 0;
  481. this.r = array[ offset ];
  482. this.g = array[ offset + 1 ];
  483. this.b = array[ offset + 2 ];
  484. return this;
  485. },
  486. toArray: function ( array, offset ) {
  487. if ( array === undefined ) array = [];
  488. if ( offset === undefined ) offset = 0;
  489. array[ offset ] = this.r;
  490. array[ offset + 1 ] = this.g;
  491. array[ offset + 2 ] = this.b;
  492. return array;
  493. }
  494. };
  495. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  496. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  497. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  498. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  499. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  500. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  501. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  502. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  503. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  504. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  505. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  506. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  507. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  508. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  509. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  510. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  511. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  512. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  513. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  514. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  515. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  516. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  517. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  518. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  519. // File:src/math/Quaternion.js
  520. /**
  521. * @author mikael emtinger / http://gomo.se/
  522. * @author alteredq / http://alteredqualia.com/
  523. * @author WestLangley / http://github.com/WestLangley
  524. * @author bhouston / http://clara.io
  525. */
  526. THREE.Quaternion = function ( x, y, z, w ) {
  527. this._x = x || 0;
  528. this._y = y || 0;
  529. this._z = z || 0;
  530. this._w = ( w !== undefined ) ? w : 1;
  531. };
  532. THREE.Quaternion.prototype = {
  533. constructor: THREE.Quaternion,
  534. get x () {
  535. return this._x;
  536. },
  537. set x ( value ) {
  538. this._x = value;
  539. this.onChangeCallback();
  540. },
  541. get y () {
  542. return this._y;
  543. },
  544. set y ( value ) {
  545. this._y = value;
  546. this.onChangeCallback();
  547. },
  548. get z () {
  549. return this._z;
  550. },
  551. set z ( value ) {
  552. this._z = value;
  553. this.onChangeCallback();
  554. },
  555. get w () {
  556. return this._w;
  557. },
  558. set w ( value ) {
  559. this._w = value;
  560. this.onChangeCallback();
  561. },
  562. set: function ( x, y, z, w ) {
  563. this._x = x;
  564. this._y = y;
  565. this._z = z;
  566. this._w = w;
  567. this.onChangeCallback();
  568. return this;
  569. },
  570. clone: function () {
  571. return new this.constructor( this._x, this._y, this._z, this._w );
  572. },
  573. copy: function ( quaternion ) {
  574. this._x = quaternion.x;
  575. this._y = quaternion.y;
  576. this._z = quaternion.z;
  577. this._w = quaternion.w;
  578. this.onChangeCallback();
  579. return this;
  580. },
  581. setFromEuler: function ( euler, update ) {
  582. if ( euler instanceof THREE.Euler === false ) {
  583. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  584. }
  585. // http://www.mathworks.com/matlabcentral/fileexchange/
  586. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  587. // content/SpinCalc.m
  588. var c1 = Math.cos( euler._x / 2 );
  589. var c2 = Math.cos( euler._y / 2 );
  590. var c3 = Math.cos( euler._z / 2 );
  591. var s1 = Math.sin( euler._x / 2 );
  592. var s2 = Math.sin( euler._y / 2 );
  593. var s3 = Math.sin( euler._z / 2 );
  594. var order = euler.order;
  595. if ( order === 'XYZ' ) {
  596. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  597. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  598. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  599. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  600. } else if ( order === 'YXZ' ) {
  601. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  602. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  603. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  604. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  605. } else if ( order === 'ZXY' ) {
  606. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  607. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  608. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  609. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  610. } else if ( order === 'ZYX' ) {
  611. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  612. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  613. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  614. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  615. } else if ( order === 'YZX' ) {
  616. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  617. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  618. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  619. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  620. } else if ( order === 'XZY' ) {
  621. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  622. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  623. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  624. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  625. }
  626. if ( update !== false ) this.onChangeCallback();
  627. return this;
  628. },
  629. setFromAxisAngle: function ( axis, angle ) {
  630. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  631. // assumes axis is normalized
  632. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  633. this._x = axis.x * s;
  634. this._y = axis.y * s;
  635. this._z = axis.z * s;
  636. this._w = Math.cos( halfAngle );
  637. this.onChangeCallback();
  638. return this;
  639. },
  640. setFromRotationMatrix: function ( m ) {
  641. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  642. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  643. var te = m.elements,
  644. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  645. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  646. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  647. trace = m11 + m22 + m33,
  648. s;
  649. if ( trace > 0 ) {
  650. s = 0.5 / Math.sqrt( trace + 1.0 );
  651. this._w = 0.25 / s;
  652. this._x = ( m32 - m23 ) * s;
  653. this._y = ( m13 - m31 ) * s;
  654. this._z = ( m21 - m12 ) * s;
  655. } else if ( m11 > m22 && m11 > m33 ) {
  656. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  657. this._w = ( m32 - m23 ) / s;
  658. this._x = 0.25 * s;
  659. this._y = ( m12 + m21 ) / s;
  660. this._z = ( m13 + m31 ) / s;
  661. } else if ( m22 > m33 ) {
  662. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  663. this._w = ( m13 - m31 ) / s;
  664. this._x = ( m12 + m21 ) / s;
  665. this._y = 0.25 * s;
  666. this._z = ( m23 + m32 ) / s;
  667. } else {
  668. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  669. this._w = ( m21 - m12 ) / s;
  670. this._x = ( m13 + m31 ) / s;
  671. this._y = ( m23 + m32 ) / s;
  672. this._z = 0.25 * s;
  673. }
  674. this.onChangeCallback();
  675. return this;
  676. },
  677. setFromUnitVectors: function () {
  678. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  679. // assumes direction vectors vFrom and vTo are normalized
  680. var v1, r;
  681. var EPS = 0.000001;
  682. return function ( vFrom, vTo ) {
  683. if ( v1 === undefined ) v1 = new THREE.Vector3();
  684. r = vFrom.dot( vTo ) + 1;
  685. if ( r < EPS ) {
  686. r = 0;
  687. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  688. v1.set( - vFrom.y, vFrom.x, 0 );
  689. } else {
  690. v1.set( 0, - vFrom.z, vFrom.y );
  691. }
  692. } else {
  693. v1.crossVectors( vFrom, vTo );
  694. }
  695. this._x = v1.x;
  696. this._y = v1.y;
  697. this._z = v1.z;
  698. this._w = r;
  699. this.normalize();
  700. return this;
  701. };
  702. }(),
  703. inverse: function () {
  704. this.conjugate().normalize();
  705. return this;
  706. },
  707. conjugate: function () {
  708. this._x *= - 1;
  709. this._y *= - 1;
  710. this._z *= - 1;
  711. this.onChangeCallback();
  712. return this;
  713. },
  714. dot: function ( v ) {
  715. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  716. },
  717. lengthSq: function () {
  718. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  719. },
  720. length: function () {
  721. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  722. },
  723. normalize: function () {
  724. var l = this.length();
  725. if ( l === 0 ) {
  726. this._x = 0;
  727. this._y = 0;
  728. this._z = 0;
  729. this._w = 1;
  730. } else {
  731. l = 1 / l;
  732. this._x = this._x * l;
  733. this._y = this._y * l;
  734. this._z = this._z * l;
  735. this._w = this._w * l;
  736. }
  737. this.onChangeCallback();
  738. return this;
  739. },
  740. multiply: function ( q, p ) {
  741. if ( p !== undefined ) {
  742. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  743. return this.multiplyQuaternions( q, p );
  744. }
  745. return this.multiplyQuaternions( this, q );
  746. },
  747. multiplyQuaternions: function ( a, b ) {
  748. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  749. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  750. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  751. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  752. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  753. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  754. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  755. this.onChangeCallback();
  756. return this;
  757. },
  758. slerp: function ( qb, t ) {
  759. if ( t === 0 ) return this;
  760. if ( t === 1 ) return this.copy( qb );
  761. var x = this._x, y = this._y, z = this._z, w = this._w;
  762. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  763. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  764. if ( cosHalfTheta < 0 ) {
  765. this._w = - qb._w;
  766. this._x = - qb._x;
  767. this._y = - qb._y;
  768. this._z = - qb._z;
  769. cosHalfTheta = - cosHalfTheta;
  770. } else {
  771. this.copy( qb );
  772. }
  773. if ( cosHalfTheta >= 1.0 ) {
  774. this._w = w;
  775. this._x = x;
  776. this._y = y;
  777. this._z = z;
  778. return this;
  779. }
  780. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  781. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  782. this._w = 0.5 * ( w + this._w );
  783. this._x = 0.5 * ( x + this._x );
  784. this._y = 0.5 * ( y + this._y );
  785. this._z = 0.5 * ( z + this._z );
  786. return this;
  787. }
  788. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  789. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  790. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  791. this._w = ( w * ratioA + this._w * ratioB );
  792. this._x = ( x * ratioA + this._x * ratioB );
  793. this._y = ( y * ratioA + this._y * ratioB );
  794. this._z = ( z * ratioA + this._z * ratioB );
  795. this.onChangeCallback();
  796. return this;
  797. },
  798. equals: function ( quaternion ) {
  799. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  800. },
  801. fromArray: function ( array, offset ) {
  802. if ( offset === undefined ) offset = 0;
  803. this._x = array[ offset ];
  804. this._y = array[ offset + 1 ];
  805. this._z = array[ offset + 2 ];
  806. this._w = array[ offset + 3 ];
  807. this.onChangeCallback();
  808. return this;
  809. },
  810. toArray: function ( array, offset ) {
  811. if ( array === undefined ) array = [];
  812. if ( offset === undefined ) offset = 0;
  813. array[ offset ] = this._x;
  814. array[ offset + 1 ] = this._y;
  815. array[ offset + 2 ] = this._z;
  816. array[ offset + 3 ] = this._w;
  817. return array;
  818. },
  819. onChange: function ( callback ) {
  820. this.onChangeCallback = callback;
  821. return this;
  822. },
  823. onChangeCallback: function () {}
  824. };
  825. Object.assign( THREE.Quaternion, {
  826. slerp: function( qa, qb, qm, t ) {
  827. return qm.copy( qa ).slerp( qb, t );
  828. },
  829. slerpFlat: function(
  830. dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  831. // fuzz-free, array-based Quaternion SLERP operation
  832. var x0 = src0[ srcOffset0 + 0 ],
  833. y0 = src0[ srcOffset0 + 1 ],
  834. z0 = src0[ srcOffset0 + 2 ],
  835. w0 = src0[ srcOffset0 + 3 ],
  836. x1 = src1[ srcOffset1 + 0 ],
  837. y1 = src1[ srcOffset1 + 1 ],
  838. z1 = src1[ srcOffset1 + 2 ],
  839. w1 = src1[ srcOffset1 + 3 ];
  840. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  841. var s = 1 - t,
  842. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  843. dir = ( cos >= 0 ? 1 : - 1 ),
  844. sqrSin = 1 - cos * cos;
  845. // Skip the Slerp for tiny steps to avoid numeric problems:
  846. if ( sqrSin > Number.EPSILON ) {
  847. var sin = Math.sqrt( sqrSin ),
  848. len = Math.atan2( sin, cos * dir );
  849. s = Math.sin( s * len ) / sin;
  850. t = Math.sin( t * len ) / sin;
  851. }
  852. var tDir = t * dir;
  853. x0 = x0 * s + x1 * tDir;
  854. y0 = y0 * s + y1 * tDir;
  855. z0 = z0 * s + z1 * tDir;
  856. w0 = w0 * s + w1 * tDir;
  857. // Normalize in case we just did a lerp:
  858. if ( s === 1 - t ) {
  859. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  860. x0 *= f;
  861. y0 *= f;
  862. z0 *= f;
  863. w0 *= f;
  864. }
  865. }
  866. dst[ dstOffset ] = x0;
  867. dst[ dstOffset + 1 ] = y0;
  868. dst[ dstOffset + 2 ] = z0;
  869. dst[ dstOffset + 3 ] = w0;
  870. }
  871. } );
  872. // File:src/math/Vector2.js
  873. /**
  874. * @author mrdoob / http://mrdoob.com/
  875. * @author philogb / http://blog.thejit.org/
  876. * @author egraether / http://egraether.com/
  877. * @author zz85 / http://www.lab4games.net/zz85/blog
  878. */
  879. THREE.Vector2 = function ( x, y ) {
  880. this.x = x || 0;
  881. this.y = y || 0;
  882. };
  883. THREE.Vector2.prototype = {
  884. constructor: THREE.Vector2,
  885. get width() {
  886. return this.x;
  887. },
  888. set width( value ) {
  889. this.x = value;
  890. },
  891. get height() {
  892. return this.y;
  893. },
  894. set height( value ) {
  895. this.y = value;
  896. },
  897. //
  898. set: function ( x, y ) {
  899. this.x = x;
  900. this.y = y;
  901. return this;
  902. },
  903. setScalar: function ( scalar ) {
  904. this.x = scalar;
  905. this.y = scalar;
  906. return this;
  907. },
  908. setX: function ( x ) {
  909. this.x = x;
  910. return this;
  911. },
  912. setY: function ( y ) {
  913. this.y = y;
  914. return this;
  915. },
  916. setComponent: function ( index, value ) {
  917. switch ( index ) {
  918. case 0: this.x = value; break;
  919. case 1: this.y = value; break;
  920. default: throw new Error( 'index is out of range: ' + index );
  921. }
  922. },
  923. getComponent: function ( index ) {
  924. switch ( index ) {
  925. case 0: return this.x;
  926. case 1: return this.y;
  927. default: throw new Error( 'index is out of range: ' + index );
  928. }
  929. },
  930. clone: function () {
  931. return new this.constructor( this.x, this.y );
  932. },
  933. copy: function ( v ) {
  934. this.x = v.x;
  935. this.y = v.y;
  936. return this;
  937. },
  938. add: function ( v, w ) {
  939. if ( w !== undefined ) {
  940. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  941. return this.addVectors( v, w );
  942. }
  943. this.x += v.x;
  944. this.y += v.y;
  945. return this;
  946. },
  947. addScalar: function ( s ) {
  948. this.x += s;
  949. this.y += s;
  950. return this;
  951. },
  952. addVectors: function ( a, b ) {
  953. this.x = a.x + b.x;
  954. this.y = a.y + b.y;
  955. return this;
  956. },
  957. addScaledVector: function ( v, s ) {
  958. this.x += v.x * s;
  959. this.y += v.y * s;
  960. return this;
  961. },
  962. sub: function ( v, w ) {
  963. if ( w !== undefined ) {
  964. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  965. return this.subVectors( v, w );
  966. }
  967. this.x -= v.x;
  968. this.y -= v.y;
  969. return this;
  970. },
  971. subScalar: function ( s ) {
  972. this.x -= s;
  973. this.y -= s;
  974. return this;
  975. },
  976. subVectors: function ( a, b ) {
  977. this.x = a.x - b.x;
  978. this.y = a.y - b.y;
  979. return this;
  980. },
  981. multiply: function ( v ) {
  982. this.x *= v.x;
  983. this.y *= v.y;
  984. return this;
  985. },
  986. multiplyScalar: function ( scalar ) {
  987. if ( isFinite( scalar ) ) {
  988. this.x *= scalar;
  989. this.y *= scalar;
  990. } else {
  991. this.x = 0;
  992. this.y = 0;
  993. }
  994. return this;
  995. },
  996. divide: function ( v ) {
  997. this.x /= v.x;
  998. this.y /= v.y;
  999. return this;
  1000. },
  1001. divideScalar: function ( scalar ) {
  1002. return this.multiplyScalar( 1 / scalar );
  1003. },
  1004. min: function ( v ) {
  1005. this.x = Math.min( this.x, v.x );
  1006. this.y = Math.min( this.y, v.y );
  1007. return this;
  1008. },
  1009. max: function ( v ) {
  1010. this.x = Math.max( this.x, v.x );
  1011. this.y = Math.max( this.y, v.y );
  1012. return this;
  1013. },
  1014. clamp: function ( min, max ) {
  1015. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1016. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1017. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1018. return this;
  1019. },
  1020. clampScalar: function () {
  1021. var min, max;
  1022. return function clampScalar( minVal, maxVal ) {
  1023. if ( min === undefined ) {
  1024. min = new THREE.Vector2();
  1025. max = new THREE.Vector2();
  1026. }
  1027. min.set( minVal, minVal );
  1028. max.set( maxVal, maxVal );
  1029. return this.clamp( min, max );
  1030. };
  1031. }(),
  1032. clampLength: function ( min, max ) {
  1033. var length = this.length();
  1034. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1035. return this;
  1036. },
  1037. floor: function () {
  1038. this.x = Math.floor( this.x );
  1039. this.y = Math.floor( this.y );
  1040. return this;
  1041. },
  1042. ceil: function () {
  1043. this.x = Math.ceil( this.x );
  1044. this.y = Math.ceil( this.y );
  1045. return this;
  1046. },
  1047. round: function () {
  1048. this.x = Math.round( this.x );
  1049. this.y = Math.round( this.y );
  1050. return this;
  1051. },
  1052. roundToZero: function () {
  1053. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1054. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1055. return this;
  1056. },
  1057. negate: function () {
  1058. this.x = - this.x;
  1059. this.y = - this.y;
  1060. return this;
  1061. },
  1062. dot: function ( v ) {
  1063. return this.x * v.x + this.y * v.y;
  1064. },
  1065. lengthSq: function () {
  1066. return this.x * this.x + this.y * this.y;
  1067. },
  1068. length: function () {
  1069. return Math.sqrt( this.x * this.x + this.y * this.y );
  1070. },
  1071. lengthManhattan: function() {
  1072. return Math.abs( this.x ) + Math.abs( this.y );
  1073. },
  1074. normalize: function () {
  1075. return this.divideScalar( this.length() );
  1076. },
  1077. angle: function () {
  1078. // computes the angle in radians with respect to the positive x-axis
  1079. var angle = Math.atan2( this.y, this.x );
  1080. if ( angle < 0 ) angle += 2 * Math.PI;
  1081. return angle;
  1082. },
  1083. distanceTo: function ( v ) {
  1084. return Math.sqrt( this.distanceToSquared( v ) );
  1085. },
  1086. distanceToSquared: function ( v ) {
  1087. var dx = this.x - v.x, dy = this.y - v.y;
  1088. return dx * dx + dy * dy;
  1089. },
  1090. setLength: function ( length ) {
  1091. return this.multiplyScalar( length / this.length() );
  1092. },
  1093. lerp: function ( v, alpha ) {
  1094. this.x += ( v.x - this.x ) * alpha;
  1095. this.y += ( v.y - this.y ) * alpha;
  1096. return this;
  1097. },
  1098. lerpVectors: function ( v1, v2, alpha ) {
  1099. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1100. return this;
  1101. },
  1102. equals: function ( v ) {
  1103. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1104. },
  1105. fromArray: function ( array, offset ) {
  1106. if ( offset === undefined ) offset = 0;
  1107. this.x = array[ offset ];
  1108. this.y = array[ offset + 1 ];
  1109. return this;
  1110. },
  1111. toArray: function ( array, offset ) {
  1112. if ( array === undefined ) array = [];
  1113. if ( offset === undefined ) offset = 0;
  1114. array[ offset ] = this.x;
  1115. array[ offset + 1 ] = this.y;
  1116. return array;
  1117. },
  1118. fromAttribute: function ( attribute, index, offset ) {
  1119. if ( offset === undefined ) offset = 0;
  1120. index = index * attribute.itemSize + offset;
  1121. this.x = attribute.array[ index ];
  1122. this.y = attribute.array[ index + 1 ];
  1123. return this;
  1124. },
  1125. rotateAround: function ( center, angle ) {
  1126. var c = Math.cos( angle ), s = Math.sin( angle );
  1127. var x = this.x - center.x;
  1128. var y = this.y - center.y;
  1129. this.x = x * c - y * s + center.x;
  1130. this.y = x * s + y * c + center.y;
  1131. return this;
  1132. }
  1133. };
  1134. // File:src/math/Vector3.js
  1135. /**
  1136. * @author mrdoob / http://mrdoob.com/
  1137. * @author *kile / http://kile.stravaganza.org/
  1138. * @author philogb / http://blog.thejit.org/
  1139. * @author mikael emtinger / http://gomo.se/
  1140. * @author egraether / http://egraether.com/
  1141. * @author WestLangley / http://github.com/WestLangley
  1142. */
  1143. THREE.Vector3 = function ( x, y, z ) {
  1144. this.x = x || 0;
  1145. this.y = y || 0;
  1146. this.z = z || 0;
  1147. };
  1148. THREE.Vector3.prototype = {
  1149. constructor: THREE.Vector3,
  1150. set: function ( x, y, z ) {
  1151. this.x = x;
  1152. this.y = y;
  1153. this.z = z;
  1154. return this;
  1155. },
  1156. setScalar: function ( scalar ) {
  1157. this.x = scalar;
  1158. this.y = scalar;
  1159. this.z = scalar;
  1160. return this;
  1161. },
  1162. setX: function ( x ) {
  1163. this.x = x;
  1164. return this;
  1165. },
  1166. setY: function ( y ) {
  1167. this.y = y;
  1168. return this;
  1169. },
  1170. setZ: function ( z ) {
  1171. this.z = z;
  1172. return this;
  1173. },
  1174. setComponent: function ( index, value ) {
  1175. switch ( index ) {
  1176. case 0: this.x = value; break;
  1177. case 1: this.y = value; break;
  1178. case 2: this.z = value; break;
  1179. default: throw new Error( 'index is out of range: ' + index );
  1180. }
  1181. },
  1182. getComponent: function ( index ) {
  1183. switch ( index ) {
  1184. case 0: return this.x;
  1185. case 1: return this.y;
  1186. case 2: return this.z;
  1187. default: throw new Error( 'index is out of range: ' + index );
  1188. }
  1189. },
  1190. clone: function () {
  1191. return new this.constructor( this.x, this.y, this.z );
  1192. },
  1193. copy: function ( v ) {
  1194. this.x = v.x;
  1195. this.y = v.y;
  1196. this.z = v.z;
  1197. return this;
  1198. },
  1199. add: function ( v, w ) {
  1200. if ( w !== undefined ) {
  1201. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1202. return this.addVectors( v, w );
  1203. }
  1204. this.x += v.x;
  1205. this.y += v.y;
  1206. this.z += v.z;
  1207. return this;
  1208. },
  1209. addScalar: function ( s ) {
  1210. this.x += s;
  1211. this.y += s;
  1212. this.z += s;
  1213. return this;
  1214. },
  1215. addVectors: function ( a, b ) {
  1216. this.x = a.x + b.x;
  1217. this.y = a.y + b.y;
  1218. this.z = a.z + b.z;
  1219. return this;
  1220. },
  1221. addScaledVector: function ( v, s ) {
  1222. this.x += v.x * s;
  1223. this.y += v.y * s;
  1224. this.z += v.z * s;
  1225. return this;
  1226. },
  1227. sub: function ( v, w ) {
  1228. if ( w !== undefined ) {
  1229. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1230. return this.subVectors( v, w );
  1231. }
  1232. this.x -= v.x;
  1233. this.y -= v.y;
  1234. this.z -= v.z;
  1235. return this;
  1236. },
  1237. subScalar: function ( s ) {
  1238. this.x -= s;
  1239. this.y -= s;
  1240. this.z -= s;
  1241. return this;
  1242. },
  1243. subVectors: function ( a, b ) {
  1244. this.x = a.x - b.x;
  1245. this.y = a.y - b.y;
  1246. this.z = a.z - b.z;
  1247. return this;
  1248. },
  1249. multiply: function ( v, w ) {
  1250. if ( w !== undefined ) {
  1251. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1252. return this.multiplyVectors( v, w );
  1253. }
  1254. this.x *= v.x;
  1255. this.y *= v.y;
  1256. this.z *= v.z;
  1257. return this;
  1258. },
  1259. multiplyScalar: function ( scalar ) {
  1260. if ( isFinite( scalar ) ) {
  1261. this.x *= scalar;
  1262. this.y *= scalar;
  1263. this.z *= scalar;
  1264. } else {
  1265. this.x = 0;
  1266. this.y = 0;
  1267. this.z = 0;
  1268. }
  1269. return this;
  1270. },
  1271. multiplyVectors: function ( a, b ) {
  1272. this.x = a.x * b.x;
  1273. this.y = a.y * b.y;
  1274. this.z = a.z * b.z;
  1275. return this;
  1276. },
  1277. applyEuler: function () {
  1278. var quaternion;
  1279. return function applyEuler( euler ) {
  1280. if ( euler instanceof THREE.Euler === false ) {
  1281. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1282. }
  1283. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1284. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1285. return this;
  1286. };
  1287. }(),
  1288. applyAxisAngle: function () {
  1289. var quaternion;
  1290. return function applyAxisAngle( axis, angle ) {
  1291. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1292. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1293. return this;
  1294. };
  1295. }(),
  1296. applyMatrix3: function ( m ) {
  1297. var x = this.x;
  1298. var y = this.y;
  1299. var z = this.z;
  1300. var e = m.elements;
  1301. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1302. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1303. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1304. return this;
  1305. },
  1306. applyMatrix4: function ( m ) {
  1307. // input: THREE.Matrix4 affine matrix
  1308. var x = this.x, y = this.y, z = this.z;
  1309. var e = m.elements;
  1310. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1311. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1312. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1313. return this;
  1314. },
  1315. applyProjection: function ( m ) {
  1316. // input: THREE.Matrix4 projection matrix
  1317. var x = this.x, y = this.y, z = this.z;
  1318. var e = m.elements;
  1319. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1320. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1321. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1322. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1323. return this;
  1324. },
  1325. applyQuaternion: function ( q ) {
  1326. var x = this.x;
  1327. var y = this.y;
  1328. var z = this.z;
  1329. var qx = q.x;
  1330. var qy = q.y;
  1331. var qz = q.z;
  1332. var qw = q.w;
  1333. // calculate quat * vector
  1334. var ix = qw * x + qy * z - qz * y;
  1335. var iy = qw * y + qz * x - qx * z;
  1336. var iz = qw * z + qx * y - qy * x;
  1337. var iw = - qx * x - qy * y - qz * z;
  1338. // calculate result * inverse quat
  1339. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1340. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1341. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1342. return this;
  1343. },
  1344. project: function () {
  1345. var matrix;
  1346. return function project( camera ) {
  1347. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1348. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1349. return this.applyProjection( matrix );
  1350. };
  1351. }(),
  1352. unproject: function () {
  1353. var matrix;
  1354. return function unproject( camera ) {
  1355. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1356. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1357. return this.applyProjection( matrix );
  1358. };
  1359. }(),
  1360. transformDirection: function ( m ) {
  1361. // input: THREE.Matrix4 affine matrix
  1362. // vector interpreted as a direction
  1363. var x = this.x, y = this.y, z = this.z;
  1364. var e = m.elements;
  1365. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1366. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1367. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1368. this.normalize();
  1369. return this;
  1370. },
  1371. divide: function ( v ) {
  1372. this.x /= v.x;
  1373. this.y /= v.y;
  1374. this.z /= v.z;
  1375. return this;
  1376. },
  1377. divideScalar: function ( scalar ) {
  1378. return this.multiplyScalar( 1 / scalar );
  1379. },
  1380. min: function ( v ) {
  1381. this.x = Math.min( this.x, v.x );
  1382. this.y = Math.min( this.y, v.y );
  1383. this.z = Math.min( this.z, v.z );
  1384. return this;
  1385. },
  1386. max: function ( v ) {
  1387. this.x = Math.max( this.x, v.x );
  1388. this.y = Math.max( this.y, v.y );
  1389. this.z = Math.max( this.z, v.z );
  1390. return this;
  1391. },
  1392. clamp: function ( min, max ) {
  1393. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1394. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1395. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1396. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1397. return this;
  1398. },
  1399. clampScalar: function () {
  1400. var min, max;
  1401. return function clampScalar( minVal, maxVal ) {
  1402. if ( min === undefined ) {
  1403. min = new THREE.Vector3();
  1404. max = new THREE.Vector3();
  1405. }
  1406. min.set( minVal, minVal, minVal );
  1407. max.set( maxVal, maxVal, maxVal );
  1408. return this.clamp( min, max );
  1409. };
  1410. }(),
  1411. clampLength: function ( min, max ) {
  1412. var length = this.length();
  1413. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1414. return this;
  1415. },
  1416. floor: function () {
  1417. this.x = Math.floor( this.x );
  1418. this.y = Math.floor( this.y );
  1419. this.z = Math.floor( this.z );
  1420. return this;
  1421. },
  1422. ceil: function () {
  1423. this.x = Math.ceil( this.x );
  1424. this.y = Math.ceil( this.y );
  1425. this.z = Math.ceil( this.z );
  1426. return this;
  1427. },
  1428. round: function () {
  1429. this.x = Math.round( this.x );
  1430. this.y = Math.round( this.y );
  1431. this.z = Math.round( this.z );
  1432. return this;
  1433. },
  1434. roundToZero: function () {
  1435. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1436. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1437. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1438. return this;
  1439. },
  1440. negate: function () {
  1441. this.x = - this.x;
  1442. this.y = - this.y;
  1443. this.z = - this.z;
  1444. return this;
  1445. },
  1446. dot: function ( v ) {
  1447. return this.x * v.x + this.y * v.y + this.z * v.z;
  1448. },
  1449. lengthSq: function () {
  1450. return this.x * this.x + this.y * this.y + this.z * this.z;
  1451. },
  1452. length: function () {
  1453. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1454. },
  1455. lengthManhattan: function () {
  1456. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1457. },
  1458. normalize: function () {
  1459. return this.divideScalar( this.length() );
  1460. },
  1461. setLength: function ( length ) {
  1462. return this.multiplyScalar( length / this.length() );
  1463. },
  1464. lerp: function ( v, alpha ) {
  1465. this.x += ( v.x - this.x ) * alpha;
  1466. this.y += ( v.y - this.y ) * alpha;
  1467. this.z += ( v.z - this.z ) * alpha;
  1468. return this;
  1469. },
  1470. lerpVectors: function ( v1, v2, alpha ) {
  1471. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1472. return this;
  1473. },
  1474. cross: function ( v, w ) {
  1475. if ( w !== undefined ) {
  1476. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1477. return this.crossVectors( v, w );
  1478. }
  1479. var x = this.x, y = this.y, z = this.z;
  1480. this.x = y * v.z - z * v.y;
  1481. this.y = z * v.x - x * v.z;
  1482. this.z = x * v.y - y * v.x;
  1483. return this;
  1484. },
  1485. crossVectors: function ( a, b ) {
  1486. var ax = a.x, ay = a.y, az = a.z;
  1487. var bx = b.x, by = b.y, bz = b.z;
  1488. this.x = ay * bz - az * by;
  1489. this.y = az * bx - ax * bz;
  1490. this.z = ax * by - ay * bx;
  1491. return this;
  1492. },
  1493. projectOnVector: function () {
  1494. var v1, dot;
  1495. return function projectOnVector( vector ) {
  1496. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1497. v1.copy( vector ).normalize();
  1498. dot = this.dot( v1 );
  1499. return this.copy( v1 ).multiplyScalar( dot );
  1500. };
  1501. }(),
  1502. projectOnPlane: function () {
  1503. var v1;
  1504. return function projectOnPlane( planeNormal ) {
  1505. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1506. v1.copy( this ).projectOnVector( planeNormal );
  1507. return this.sub( v1 );
  1508. };
  1509. }(),
  1510. reflect: function () {
  1511. // reflect incident vector off plane orthogonal to normal
  1512. // normal is assumed to have unit length
  1513. var v1;
  1514. return function reflect( normal ) {
  1515. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1516. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1517. };
  1518. }(),
  1519. angleTo: function ( v ) {
  1520. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1521. // clamp, to handle numerical problems
  1522. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1523. },
  1524. distanceTo: function ( v ) {
  1525. return Math.sqrt( this.distanceToSquared( v ) );
  1526. },
  1527. distanceToSquared: function ( v ) {
  1528. var dx = this.x - v.x;
  1529. var dy = this.y - v.y;
  1530. var dz = this.z - v.z;
  1531. return dx * dx + dy * dy + dz * dz;
  1532. },
  1533. setFromSpherical: function( s ) {
  1534. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1535. this.x = sinPhiRadius * Math.sin( s.theta );
  1536. this.y = Math.cos( s.phi ) * s.radius;
  1537. this.z = sinPhiRadius * Math.cos( s.theta );
  1538. return this;
  1539. },
  1540. setFromMatrixPosition: function ( m ) {
  1541. return this.setFromMatrixColumn( m, 3 );
  1542. },
  1543. setFromMatrixScale: function ( m ) {
  1544. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1545. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1546. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1547. this.x = sx;
  1548. this.y = sy;
  1549. this.z = sz;
  1550. return this;
  1551. },
  1552. setFromMatrixColumn: function ( m, index ) {
  1553. if ( typeof m === 'number' ) {
  1554. console.warn( 'THREE.Vector3: setFromMatrixColumn now expects ( matrix, index ).' );
  1555. m = arguments[ 1 ];
  1556. index = arguments[ 0 ];
  1557. }
  1558. return this.fromArray( m.elements, index * 4 );
  1559. },
  1560. equals: function ( v ) {
  1561. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1562. },
  1563. fromArray: function ( array, offset ) {
  1564. if ( offset === undefined ) offset = 0;
  1565. this.x = array[ offset ];
  1566. this.y = array[ offset + 1 ];
  1567. this.z = array[ offset + 2 ];
  1568. return this;
  1569. },
  1570. toArray: function ( array, offset ) {
  1571. if ( array === undefined ) array = [];
  1572. if ( offset === undefined ) offset = 0;
  1573. array[ offset ] = this.x;
  1574. array[ offset + 1 ] = this.y;
  1575. array[ offset + 2 ] = this.z;
  1576. return array;
  1577. },
  1578. fromAttribute: function ( attribute, index, offset ) {
  1579. if ( offset === undefined ) offset = 0;
  1580. index = index * attribute.itemSize + offset;
  1581. this.x = attribute.array[ index ];
  1582. this.y = attribute.array[ index + 1 ];
  1583. this.z = attribute.array[ index + 2 ];
  1584. return this;
  1585. }
  1586. };
  1587. // File:src/math/Vector4.js
  1588. /**
  1589. * @author supereggbert / http://www.paulbrunt.co.uk/
  1590. * @author philogb / http://blog.thejit.org/
  1591. * @author mikael emtinger / http://gomo.se/
  1592. * @author egraether / http://egraether.com/
  1593. * @author WestLangley / http://github.com/WestLangley
  1594. */
  1595. THREE.Vector4 = function ( x, y, z, w ) {
  1596. this.x = x || 0;
  1597. this.y = y || 0;
  1598. this.z = z || 0;
  1599. this.w = ( w !== undefined ) ? w : 1;
  1600. };
  1601. THREE.Vector4.prototype = {
  1602. constructor: THREE.Vector4,
  1603. set: function ( x, y, z, w ) {
  1604. this.x = x;
  1605. this.y = y;
  1606. this.z = z;
  1607. this.w = w;
  1608. return this;
  1609. },
  1610. setScalar: function ( scalar ) {
  1611. this.x = scalar;
  1612. this.y = scalar;
  1613. this.z = scalar;
  1614. this.w = scalar;
  1615. return this;
  1616. },
  1617. setX: function ( x ) {
  1618. this.x = x;
  1619. return this;
  1620. },
  1621. setY: function ( y ) {
  1622. this.y = y;
  1623. return this;
  1624. },
  1625. setZ: function ( z ) {
  1626. this.z = z;
  1627. return this;
  1628. },
  1629. setW: function ( w ) {
  1630. this.w = w;
  1631. return this;
  1632. },
  1633. setComponent: function ( index, value ) {
  1634. switch ( index ) {
  1635. case 0: this.x = value; break;
  1636. case 1: this.y = value; break;
  1637. case 2: this.z = value; break;
  1638. case 3: this.w = value; break;
  1639. default: throw new Error( 'index is out of range: ' + index );
  1640. }
  1641. },
  1642. getComponent: function ( index ) {
  1643. switch ( index ) {
  1644. case 0: return this.x;
  1645. case 1: return this.y;
  1646. case 2: return this.z;
  1647. case 3: return this.w;
  1648. default: throw new Error( 'index is out of range: ' + index );
  1649. }
  1650. },
  1651. clone: function () {
  1652. return new this.constructor( this.x, this.y, this.z, this.w );
  1653. },
  1654. copy: function ( v ) {
  1655. this.x = v.x;
  1656. this.y = v.y;
  1657. this.z = v.z;
  1658. this.w = ( v.w !== undefined ) ? v.w : 1;
  1659. return this;
  1660. },
  1661. add: function ( v, w ) {
  1662. if ( w !== undefined ) {
  1663. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1664. return this.addVectors( v, w );
  1665. }
  1666. this.x += v.x;
  1667. this.y += v.y;
  1668. this.z += v.z;
  1669. this.w += v.w;
  1670. return this;
  1671. },
  1672. addScalar: function ( s ) {
  1673. this.x += s;
  1674. this.y += s;
  1675. this.z += s;
  1676. this.w += s;
  1677. return this;
  1678. },
  1679. addVectors: function ( a, b ) {
  1680. this.x = a.x + b.x;
  1681. this.y = a.y + b.y;
  1682. this.z = a.z + b.z;
  1683. this.w = a.w + b.w;
  1684. return this;
  1685. },
  1686. addScaledVector: function ( v, s ) {
  1687. this.x += v.x * s;
  1688. this.y += v.y * s;
  1689. this.z += v.z * s;
  1690. this.w += v.w * s;
  1691. return this;
  1692. },
  1693. sub: function ( v, w ) {
  1694. if ( w !== undefined ) {
  1695. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1696. return this.subVectors( v, w );
  1697. }
  1698. this.x -= v.x;
  1699. this.y -= v.y;
  1700. this.z -= v.z;
  1701. this.w -= v.w;
  1702. return this;
  1703. },
  1704. subScalar: function ( s ) {
  1705. this.x -= s;
  1706. this.y -= s;
  1707. this.z -= s;
  1708. this.w -= s;
  1709. return this;
  1710. },
  1711. subVectors: function ( a, b ) {
  1712. this.x = a.x - b.x;
  1713. this.y = a.y - b.y;
  1714. this.z = a.z - b.z;
  1715. this.w = a.w - b.w;
  1716. return this;
  1717. },
  1718. multiplyScalar: function ( scalar ) {
  1719. if ( isFinite( scalar ) ) {
  1720. this.x *= scalar;
  1721. this.y *= scalar;
  1722. this.z *= scalar;
  1723. this.w *= scalar;
  1724. } else {
  1725. this.x = 0;
  1726. this.y = 0;
  1727. this.z = 0;
  1728. this.w = 0;
  1729. }
  1730. return this;
  1731. },
  1732. applyMatrix4: function ( m ) {
  1733. var x = this.x;
  1734. var y = this.y;
  1735. var z = this.z;
  1736. var w = this.w;
  1737. var e = m.elements;
  1738. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1739. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1740. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1741. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1742. return this;
  1743. },
  1744. divideScalar: function ( scalar ) {
  1745. return this.multiplyScalar( 1 / scalar );
  1746. },
  1747. setAxisAngleFromQuaternion: function ( q ) {
  1748. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1749. // q is assumed to be normalized
  1750. this.w = 2 * Math.acos( q.w );
  1751. var s = Math.sqrt( 1 - q.w * q.w );
  1752. if ( s < 0.0001 ) {
  1753. this.x = 1;
  1754. this.y = 0;
  1755. this.z = 0;
  1756. } else {
  1757. this.x = q.x / s;
  1758. this.y = q.y / s;
  1759. this.z = q.z / s;
  1760. }
  1761. return this;
  1762. },
  1763. setAxisAngleFromRotationMatrix: function ( m ) {
  1764. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1765. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1766. var angle, x, y, z, // variables for result
  1767. epsilon = 0.01, // margin to allow for rounding errors
  1768. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1769. te = m.elements,
  1770. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1771. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1772. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1773. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1774. && ( Math.abs( m13 - m31 ) < epsilon )
  1775. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1776. // singularity found
  1777. // first check for identity matrix which must have +1 for all terms
  1778. // in leading diagonal and zero in other terms
  1779. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1780. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1781. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1782. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1783. // this singularity is identity matrix so angle = 0
  1784. this.set( 1, 0, 0, 0 );
  1785. return this; // zero angle, arbitrary axis
  1786. }
  1787. // otherwise this singularity is angle = 180
  1788. angle = Math.PI;
  1789. var xx = ( m11 + 1 ) / 2;
  1790. var yy = ( m22 + 1 ) / 2;
  1791. var zz = ( m33 + 1 ) / 2;
  1792. var xy = ( m12 + m21 ) / 4;
  1793. var xz = ( m13 + m31 ) / 4;
  1794. var yz = ( m23 + m32 ) / 4;
  1795. if ( ( xx > yy ) && ( xx > zz ) ) {
  1796. // m11 is the largest diagonal term
  1797. if ( xx < epsilon ) {
  1798. x = 0;
  1799. y = 0.707106781;
  1800. z = 0.707106781;
  1801. } else {
  1802. x = Math.sqrt( xx );
  1803. y = xy / x;
  1804. z = xz / x;
  1805. }
  1806. } else if ( yy > zz ) {
  1807. // m22 is the largest diagonal term
  1808. if ( yy < epsilon ) {
  1809. x = 0.707106781;
  1810. y = 0;
  1811. z = 0.707106781;
  1812. } else {
  1813. y = Math.sqrt( yy );
  1814. x = xy / y;
  1815. z = yz / y;
  1816. }
  1817. } else {
  1818. // m33 is the largest diagonal term so base result on this
  1819. if ( zz < epsilon ) {
  1820. x = 0.707106781;
  1821. y = 0.707106781;
  1822. z = 0;
  1823. } else {
  1824. z = Math.sqrt( zz );
  1825. x = xz / z;
  1826. y = yz / z;
  1827. }
  1828. }
  1829. this.set( x, y, z, angle );
  1830. return this; // return 180 deg rotation
  1831. }
  1832. // as we have reached here there are no singularities so we can handle normally
  1833. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1834. + ( m13 - m31 ) * ( m13 - m31 )
  1835. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1836. if ( Math.abs( s ) < 0.001 ) s = 1;
  1837. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1838. // caught by singularity test above, but I've left it in just in case
  1839. this.x = ( m32 - m23 ) / s;
  1840. this.y = ( m13 - m31 ) / s;
  1841. this.z = ( m21 - m12 ) / s;
  1842. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1843. return this;
  1844. },
  1845. min: function ( v ) {
  1846. this.x = Math.min( this.x, v.x );
  1847. this.y = Math.min( this.y, v.y );
  1848. this.z = Math.min( this.z, v.z );
  1849. this.w = Math.min( this.w, v.w );
  1850. return this;
  1851. },
  1852. max: function ( v ) {
  1853. this.x = Math.max( this.x, v.x );
  1854. this.y = Math.max( this.y, v.y );
  1855. this.z = Math.max( this.z, v.z );
  1856. this.w = Math.max( this.w, v.w );
  1857. return this;
  1858. },
  1859. clamp: function ( min, max ) {
  1860. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1861. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1862. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1863. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1864. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1865. return this;
  1866. },
  1867. clampScalar: function () {
  1868. var min, max;
  1869. return function clampScalar( minVal, maxVal ) {
  1870. if ( min === undefined ) {
  1871. min = new THREE.Vector4();
  1872. max = new THREE.Vector4();
  1873. }
  1874. min.set( minVal, minVal, minVal, minVal );
  1875. max.set( maxVal, maxVal, maxVal, maxVal );
  1876. return this.clamp( min, max );
  1877. };
  1878. }(),
  1879. floor: function () {
  1880. this.x = Math.floor( this.x );
  1881. this.y = Math.floor( this.y );
  1882. this.z = Math.floor( this.z );
  1883. this.w = Math.floor( this.w );
  1884. return this;
  1885. },
  1886. ceil: function () {
  1887. this.x = Math.ceil( this.x );
  1888. this.y = Math.ceil( this.y );
  1889. this.z = Math.ceil( this.z );
  1890. this.w = Math.ceil( this.w );
  1891. return this;
  1892. },
  1893. round: function () {
  1894. this.x = Math.round( this.x );
  1895. this.y = Math.round( this.y );
  1896. this.z = Math.round( this.z );
  1897. this.w = Math.round( this.w );
  1898. return this;
  1899. },
  1900. roundToZero: function () {
  1901. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1902. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1903. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1904. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1905. return this;
  1906. },
  1907. negate: function () {
  1908. this.x = - this.x;
  1909. this.y = - this.y;
  1910. this.z = - this.z;
  1911. this.w = - this.w;
  1912. return this;
  1913. },
  1914. dot: function ( v ) {
  1915. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1916. },
  1917. lengthSq: function () {
  1918. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1919. },
  1920. length: function () {
  1921. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1922. },
  1923. lengthManhattan: function () {
  1924. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1925. },
  1926. normalize: function () {
  1927. return this.divideScalar( this.length() );
  1928. },
  1929. setLength: function ( length ) {
  1930. return this.multiplyScalar( length / this.length() );
  1931. },
  1932. lerp: function ( v, alpha ) {
  1933. this.x += ( v.x - this.x ) * alpha;
  1934. this.y += ( v.y - this.y ) * alpha;
  1935. this.z += ( v.z - this.z ) * alpha;
  1936. this.w += ( v.w - this.w ) * alpha;
  1937. return this;
  1938. },
  1939. lerpVectors: function ( v1, v2, alpha ) {
  1940. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1941. return this;
  1942. },
  1943. equals: function ( v ) {
  1944. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1945. },
  1946. fromArray: function ( array, offset ) {
  1947. if ( offset === undefined ) offset = 0;
  1948. this.x = array[ offset ];
  1949. this.y = array[ offset + 1 ];
  1950. this.z = array[ offset + 2 ];
  1951. this.w = array[ offset + 3 ];
  1952. return this;
  1953. },
  1954. toArray: function ( array, offset ) {
  1955. if ( array === undefined ) array = [];
  1956. if ( offset === undefined ) offset = 0;
  1957. array[ offset ] = this.x;
  1958. array[ offset + 1 ] = this.y;
  1959. array[ offset + 2 ] = this.z;
  1960. array[ offset + 3 ] = this.w;
  1961. return array;
  1962. },
  1963. fromAttribute: function ( attribute, index, offset ) {
  1964. if ( offset === undefined ) offset = 0;
  1965. index = index * attribute.itemSize + offset;
  1966. this.x = attribute.array[ index ];
  1967. this.y = attribute.array[ index + 1 ];
  1968. this.z = attribute.array[ index + 2 ];
  1969. this.w = attribute.array[ index + 3 ];
  1970. return this;
  1971. }
  1972. };
  1973. // File:src/math/Euler.js
  1974. /**
  1975. * @author mrdoob / http://mrdoob.com/
  1976. * @author WestLangley / http://github.com/WestLangley
  1977. * @author bhouston / http://clara.io
  1978. */
  1979. THREE.Euler = function ( x, y, z, order ) {
  1980. this._x = x || 0;
  1981. this._y = y || 0;
  1982. this._z = z || 0;
  1983. this._order = order || THREE.Euler.DefaultOrder;
  1984. };
  1985. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1986. THREE.Euler.DefaultOrder = 'XYZ';
  1987. THREE.Euler.prototype = {
  1988. constructor: THREE.Euler,
  1989. get x () {
  1990. return this._x;
  1991. },
  1992. set x ( value ) {
  1993. this._x = value;
  1994. this.onChangeCallback();
  1995. },
  1996. get y () {
  1997. return this._y;
  1998. },
  1999. set y ( value ) {
  2000. this._y = value;
  2001. this.onChangeCallback();
  2002. },
  2003. get z () {
  2004. return this._z;
  2005. },
  2006. set z ( value ) {
  2007. this._z = value;
  2008. this.onChangeCallback();
  2009. },
  2010. get order () {
  2011. return this._order;
  2012. },
  2013. set order ( value ) {
  2014. this._order = value;
  2015. this.onChangeCallback();
  2016. },
  2017. set: function ( x, y, z, order ) {
  2018. this._x = x;
  2019. this._y = y;
  2020. this._z = z;
  2021. this._order = order || this._order;
  2022. this.onChangeCallback();
  2023. return this;
  2024. },
  2025. clone: function () {
  2026. return new this.constructor( this._x, this._y, this._z, this._order );
  2027. },
  2028. copy: function ( euler ) {
  2029. this._x = euler._x;
  2030. this._y = euler._y;
  2031. this._z = euler._z;
  2032. this._order = euler._order;
  2033. this.onChangeCallback();
  2034. return this;
  2035. },
  2036. setFromRotationMatrix: function ( m, order, update ) {
  2037. var clamp = THREE.Math.clamp;
  2038. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2039. var te = m.elements;
  2040. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2041. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2042. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2043. order = order || this._order;
  2044. if ( order === 'XYZ' ) {
  2045. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2046. if ( Math.abs( m13 ) < 0.99999 ) {
  2047. this._x = Math.atan2( - m23, m33 );
  2048. this._z = Math.atan2( - m12, m11 );
  2049. } else {
  2050. this._x = Math.atan2( m32, m22 );
  2051. this._z = 0;
  2052. }
  2053. } else if ( order === 'YXZ' ) {
  2054. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2055. if ( Math.abs( m23 ) < 0.99999 ) {
  2056. this._y = Math.atan2( m13, m33 );
  2057. this._z = Math.atan2( m21, m22 );
  2058. } else {
  2059. this._y = Math.atan2( - m31, m11 );
  2060. this._z = 0;
  2061. }
  2062. } else if ( order === 'ZXY' ) {
  2063. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2064. if ( Math.abs( m32 ) < 0.99999 ) {
  2065. this._y = Math.atan2( - m31, m33 );
  2066. this._z = Math.atan2( - m12, m22 );
  2067. } else {
  2068. this._y = 0;
  2069. this._z = Math.atan2( m21, m11 );
  2070. }
  2071. } else if ( order === 'ZYX' ) {
  2072. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2073. if ( Math.abs( m31 ) < 0.99999 ) {
  2074. this._x = Math.atan2( m32, m33 );
  2075. this._z = Math.atan2( m21, m11 );
  2076. } else {
  2077. this._x = 0;
  2078. this._z = Math.atan2( - m12, m22 );
  2079. }
  2080. } else if ( order === 'YZX' ) {
  2081. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2082. if ( Math.abs( m21 ) < 0.99999 ) {
  2083. this._x = Math.atan2( - m23, m22 );
  2084. this._y = Math.atan2( - m31, m11 );
  2085. } else {
  2086. this._x = 0;
  2087. this._y = Math.atan2( m13, m33 );
  2088. }
  2089. } else if ( order === 'XZY' ) {
  2090. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2091. if ( Math.abs( m12 ) < 0.99999 ) {
  2092. this._x = Math.atan2( m32, m22 );
  2093. this._y = Math.atan2( m13, m11 );
  2094. } else {
  2095. this._x = Math.atan2( - m23, m33 );
  2096. this._y = 0;
  2097. }
  2098. } else {
  2099. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2100. }
  2101. this._order = order;
  2102. if ( update !== false ) this.onChangeCallback();
  2103. return this;
  2104. },
  2105. setFromQuaternion: function () {
  2106. var matrix;
  2107. return function ( q, order, update ) {
  2108. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2109. matrix.makeRotationFromQuaternion( q );
  2110. this.setFromRotationMatrix( matrix, order, update );
  2111. return this;
  2112. };
  2113. }(),
  2114. setFromVector3: function ( v, order ) {
  2115. return this.set( v.x, v.y, v.z, order || this._order );
  2116. },
  2117. reorder: function () {
  2118. // WARNING: this discards revolution information -bhouston
  2119. var q = new THREE.Quaternion();
  2120. return function ( newOrder ) {
  2121. q.setFromEuler( this );
  2122. this.setFromQuaternion( q, newOrder );
  2123. };
  2124. }(),
  2125. equals: function ( euler ) {
  2126. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2127. },
  2128. fromArray: function ( array ) {
  2129. this._x = array[ 0 ];
  2130. this._y = array[ 1 ];
  2131. this._z = array[ 2 ];
  2132. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2133. this.onChangeCallback();
  2134. return this;
  2135. },
  2136. toArray: function ( array, offset ) {
  2137. if ( array === undefined ) array = [];
  2138. if ( offset === undefined ) offset = 0;
  2139. array[ offset ] = this._x;
  2140. array[ offset + 1 ] = this._y;
  2141. array[ offset + 2 ] = this._z;
  2142. array[ offset + 3 ] = this._order;
  2143. return array;
  2144. },
  2145. toVector3: function ( optionalResult ) {
  2146. if ( optionalResult ) {
  2147. return optionalResult.set( this._x, this._y, this._z );
  2148. } else {
  2149. return new THREE.Vector3( this._x, this._y, this._z );
  2150. }
  2151. },
  2152. onChange: function ( callback ) {
  2153. this.onChangeCallback = callback;
  2154. return this;
  2155. },
  2156. onChangeCallback: function () {}
  2157. };
  2158. // File:src/math/Line3.js
  2159. /**
  2160. * @author bhouston / http://clara.io
  2161. */
  2162. THREE.Line3 = function ( start, end ) {
  2163. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2164. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2165. };
  2166. THREE.Line3.prototype = {
  2167. constructor: THREE.Line3,
  2168. set: function ( start, end ) {
  2169. this.start.copy( start );
  2170. this.end.copy( end );
  2171. return this;
  2172. },
  2173. clone: function () {
  2174. return new this.constructor().copy( this );
  2175. },
  2176. copy: function ( line ) {
  2177. this.start.copy( line.start );
  2178. this.end.copy( line.end );
  2179. return this;
  2180. },
  2181. center: function ( optionalTarget ) {
  2182. var result = optionalTarget || new THREE.Vector3();
  2183. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2184. },
  2185. delta: function ( optionalTarget ) {
  2186. var result = optionalTarget || new THREE.Vector3();
  2187. return result.subVectors( this.end, this.start );
  2188. },
  2189. distanceSq: function () {
  2190. return this.start.distanceToSquared( this.end );
  2191. },
  2192. distance: function () {
  2193. return this.start.distanceTo( this.end );
  2194. },
  2195. at: function ( t, optionalTarget ) {
  2196. var result = optionalTarget || new THREE.Vector3();
  2197. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2198. },
  2199. closestPointToPointParameter: function () {
  2200. var startP = new THREE.Vector3();
  2201. var startEnd = new THREE.Vector3();
  2202. return function ( point, clampToLine ) {
  2203. startP.subVectors( point, this.start );
  2204. startEnd.subVectors( this.end, this.start );
  2205. var startEnd2 = startEnd.dot( startEnd );
  2206. var startEnd_startP = startEnd.dot( startP );
  2207. var t = startEnd_startP / startEnd2;
  2208. if ( clampToLine ) {
  2209. t = THREE.Math.clamp( t, 0, 1 );
  2210. }
  2211. return t;
  2212. };
  2213. }(),
  2214. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2215. var t = this.closestPointToPointParameter( point, clampToLine );
  2216. var result = optionalTarget || new THREE.Vector3();
  2217. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2218. },
  2219. applyMatrix4: function ( matrix ) {
  2220. this.start.applyMatrix4( matrix );
  2221. this.end.applyMatrix4( matrix );
  2222. return this;
  2223. },
  2224. equals: function ( line ) {
  2225. return line.start.equals( this.start ) && line.end.equals( this.end );
  2226. }
  2227. };
  2228. // File:src/math/Box2.js
  2229. /**
  2230. * @author bhouston / http://clara.io
  2231. */
  2232. THREE.Box2 = function ( min, max ) {
  2233. this.min = ( min !== undefined ) ? min : new THREE.Vector2( + Infinity, + Infinity );
  2234. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2235. };
  2236. THREE.Box2.prototype = {
  2237. constructor: THREE.Box2,
  2238. set: function ( min, max ) {
  2239. this.min.copy( min );
  2240. this.max.copy( max );
  2241. return this;
  2242. },
  2243. setFromPoints: function ( points ) {
  2244. this.makeEmpty();
  2245. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2246. this.expandByPoint( points[ i ] );
  2247. }
  2248. return this;
  2249. },
  2250. setFromCenterAndSize: function () {
  2251. var v1 = new THREE.Vector2();
  2252. return function ( center, size ) {
  2253. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2254. this.min.copy( center ).sub( halfSize );
  2255. this.max.copy( center ).add( halfSize );
  2256. return this;
  2257. };
  2258. }(),
  2259. clone: function () {
  2260. return new this.constructor().copy( this );
  2261. },
  2262. copy: function ( box ) {
  2263. this.min.copy( box.min );
  2264. this.max.copy( box.max );
  2265. return this;
  2266. },
  2267. makeEmpty: function () {
  2268. this.min.x = this.min.y = + Infinity;
  2269. this.max.x = this.max.y = - Infinity;
  2270. return this;
  2271. },
  2272. isEmpty: function () {
  2273. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2274. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2275. },
  2276. center: function ( optionalTarget ) {
  2277. var result = optionalTarget || new THREE.Vector2();
  2278. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2279. },
  2280. size: function ( optionalTarget ) {
  2281. var result = optionalTarget || new THREE.Vector2();
  2282. return result.subVectors( this.max, this.min );
  2283. },
  2284. expandByPoint: function ( point ) {
  2285. this.min.min( point );
  2286. this.max.max( point );
  2287. return this;
  2288. },
  2289. expandByVector: function ( vector ) {
  2290. this.min.sub( vector );
  2291. this.max.add( vector );
  2292. return this;
  2293. },
  2294. expandByScalar: function ( scalar ) {
  2295. this.min.addScalar( - scalar );
  2296. this.max.addScalar( scalar );
  2297. return this;
  2298. },
  2299. containsPoint: function ( point ) {
  2300. if ( point.x < this.min.x || point.x > this.max.x ||
  2301. point.y < this.min.y || point.y > this.max.y ) {
  2302. return false;
  2303. }
  2304. return true;
  2305. },
  2306. containsBox: function ( box ) {
  2307. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2308. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2309. return true;
  2310. }
  2311. return false;
  2312. },
  2313. getParameter: function ( point, optionalTarget ) {
  2314. // This can potentially have a divide by zero if the box
  2315. // has a size dimension of 0.
  2316. var result = optionalTarget || new THREE.Vector2();
  2317. return result.set(
  2318. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2319. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2320. );
  2321. },
  2322. intersectsBox: function ( box ) {
  2323. // using 6 splitting planes to rule out intersections.
  2324. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2325. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2326. return false;
  2327. }
  2328. return true;
  2329. },
  2330. clampPoint: function ( point, optionalTarget ) {
  2331. var result = optionalTarget || new THREE.Vector2();
  2332. return result.copy( point ).clamp( this.min, this.max );
  2333. },
  2334. distanceToPoint: function () {
  2335. var v1 = new THREE.Vector2();
  2336. return function ( point ) {
  2337. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2338. return clampedPoint.sub( point ).length();
  2339. };
  2340. }(),
  2341. intersect: function ( box ) {
  2342. this.min.max( box.min );
  2343. this.max.min( box.max );
  2344. return this;
  2345. },
  2346. union: function ( box ) {
  2347. this.min.min( box.min );
  2348. this.max.max( box.max );
  2349. return this;
  2350. },
  2351. translate: function ( offset ) {
  2352. this.min.add( offset );
  2353. this.max.add( offset );
  2354. return this;
  2355. },
  2356. equals: function ( box ) {
  2357. return box.min.equals( this.min ) && box.max.equals( this.max );
  2358. }
  2359. };
  2360. // File:src/math/Box3.js
  2361. /**
  2362. * @author bhouston / http://clara.io
  2363. * @author WestLangley / http://github.com/WestLangley
  2364. */
  2365. THREE.Box3 = function ( min, max ) {
  2366. this.min = ( min !== undefined ) ? min : new THREE.Vector3( + Infinity, + Infinity, + Infinity );
  2367. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2368. };
  2369. THREE.Box3.prototype = {
  2370. constructor: THREE.Box3,
  2371. set: function ( min, max ) {
  2372. this.min.copy( min );
  2373. this.max.copy( max );
  2374. return this;
  2375. },
  2376. setFromArray: function ( array ) {
  2377. this.makeEmpty();
  2378. var minX = + Infinity;
  2379. var minY = + Infinity;
  2380. var minZ = + Infinity;
  2381. var maxX = - Infinity;
  2382. var maxY = - Infinity;
  2383. var maxZ = - Infinity;
  2384. for ( var i = 0, il = array.length; i < il; i += 3 ) {
  2385. var x = array[ i ];
  2386. var y = array[ i + 1 ];
  2387. var z = array[ i + 2 ];
  2388. if ( x < minX ) minX = x;
  2389. if ( y < minY ) minY = y;
  2390. if ( z < minZ ) minZ = z;
  2391. if ( x > maxX ) maxX = x;
  2392. if ( y > maxY ) maxY = y;
  2393. if ( z > maxZ ) maxZ = z;
  2394. }
  2395. this.min.set( minX, minY, minZ );
  2396. this.max.set( maxX, maxY, maxZ );
  2397. },
  2398. setFromPoints: function ( points ) {
  2399. this.makeEmpty();
  2400. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2401. this.expandByPoint( points[ i ] );
  2402. }
  2403. return this;
  2404. },
  2405. setFromCenterAndSize: function () {
  2406. var v1 = new THREE.Vector3();
  2407. return function ( center, size ) {
  2408. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2409. this.min.copy( center ).sub( halfSize );
  2410. this.max.copy( center ).add( halfSize );
  2411. return this;
  2412. };
  2413. }(),
  2414. setFromObject: function () {
  2415. // Computes the world-axis-aligned bounding box of an object (including its children),
  2416. // accounting for both the object's, and children's, world transforms
  2417. var box;
  2418. return function ( object ) {
  2419. if ( box === undefined ) box = new THREE.Box3();
  2420. var scope = this;
  2421. this.makeEmpty();
  2422. object.updateMatrixWorld( true );
  2423. object.traverse( function ( node ) {
  2424. var geometry = node.geometry;
  2425. if ( geometry !== undefined ) {
  2426. if ( geometry.boundingBox === null ) {
  2427. geometry.computeBoundingBox();
  2428. }
  2429. if ( geometry.boundingBox.isEmpty() === false ) {
  2430. box.copy( geometry.boundingBox );
  2431. box.applyMatrix4( node.matrixWorld );
  2432. scope.union( box );
  2433. }
  2434. }
  2435. } );
  2436. return this;
  2437. };
  2438. }(),
  2439. clone: function () {
  2440. return new this.constructor().copy( this );
  2441. },
  2442. copy: function ( box ) {
  2443. this.min.copy( box.min );
  2444. this.max.copy( box.max );
  2445. return this;
  2446. },
  2447. makeEmpty: function () {
  2448. this.min.x = this.min.y = this.min.z = + Infinity;
  2449. this.max.x = this.max.y = this.max.z = - Infinity;
  2450. return this;
  2451. },
  2452. isEmpty: function () {
  2453. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2454. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2455. },
  2456. center: function ( optionalTarget ) {
  2457. var result = optionalTarget || new THREE.Vector3();
  2458. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2459. },
  2460. size: function ( optionalTarget ) {
  2461. var result = optionalTarget || new THREE.Vector3();
  2462. return result.subVectors( this.max, this.min );
  2463. },
  2464. expandByPoint: function ( point ) {
  2465. this.min.min( point );
  2466. this.max.max( point );
  2467. return this;
  2468. },
  2469. expandByVector: function ( vector ) {
  2470. this.min.sub( vector );
  2471. this.max.add( vector );
  2472. return this;
  2473. },
  2474. expandByScalar: function ( scalar ) {
  2475. this.min.addScalar( - scalar );
  2476. this.max.addScalar( scalar );
  2477. return this;
  2478. },
  2479. containsPoint: function ( point ) {
  2480. if ( point.x < this.min.x || point.x > this.max.x ||
  2481. point.y < this.min.y || point.y > this.max.y ||
  2482. point.z < this.min.z || point.z > this.max.z ) {
  2483. return false;
  2484. }
  2485. return true;
  2486. },
  2487. containsBox: function ( box ) {
  2488. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2489. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2490. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2491. return true;
  2492. }
  2493. return false;
  2494. },
  2495. getParameter: function ( point, optionalTarget ) {
  2496. // This can potentially have a divide by zero if the box
  2497. // has a size dimension of 0.
  2498. var result = optionalTarget || new THREE.Vector3();
  2499. return result.set(
  2500. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2501. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2502. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2503. );
  2504. },
  2505. intersectsBox: function ( box ) {
  2506. // using 6 splitting planes to rule out intersections.
  2507. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2508. box.max.y < this.min.y || box.min.y > this.max.y ||
  2509. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2510. return false;
  2511. }
  2512. return true;
  2513. },
  2514. intersectsSphere: ( function () {
  2515. var closestPoint;
  2516. return function intersectsSphere( sphere ) {
  2517. if ( closestPoint === undefined ) closestPoint = new THREE.Vector3();
  2518. // Find the point on the AABB closest to the sphere center.
  2519. this.clampPoint( sphere.center, closestPoint );
  2520. // If that point is inside the sphere, the AABB and sphere intersect.
  2521. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2522. };
  2523. } )(),
  2524. intersectsPlane: function ( plane ) {
  2525. // We compute the minimum and maximum dot product values. If those values
  2526. // are on the same side (back or front) of the plane, then there is no intersection.
  2527. var min, max;
  2528. if ( plane.normal.x > 0 ) {
  2529. min = plane.normal.x * this.min.x;
  2530. max = plane.normal.x * this.max.x;
  2531. } else {
  2532. min = plane.normal.x * this.max.x;
  2533. max = plane.normal.x * this.min.x;
  2534. }
  2535. if ( plane.normal.y > 0 ) {
  2536. min += plane.normal.y * this.min.y;
  2537. max += plane.normal.y * this.max.y;
  2538. } else {
  2539. min += plane.normal.y * this.max.y;
  2540. max += plane.normal.y * this.min.y;
  2541. }
  2542. if ( plane.normal.z > 0 ) {
  2543. min += plane.normal.z * this.min.z;
  2544. max += plane.normal.z * this.max.z;
  2545. } else {
  2546. min += plane.normal.z * this.max.z;
  2547. max += plane.normal.z * this.min.z;
  2548. }
  2549. return ( min <= plane.constant && max >= plane.constant );
  2550. },
  2551. clampPoint: function ( point, optionalTarget ) {
  2552. var result = optionalTarget || new THREE.Vector3();
  2553. return result.copy( point ).clamp( this.min, this.max );
  2554. },
  2555. distanceToPoint: function () {
  2556. var v1 = new THREE.Vector3();
  2557. return function ( point ) {
  2558. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2559. return clampedPoint.sub( point ).length();
  2560. };
  2561. }(),
  2562. getBoundingSphere: function () {
  2563. var v1 = new THREE.Vector3();
  2564. return function ( optionalTarget ) {
  2565. var result = optionalTarget || new THREE.Sphere();
  2566. result.center = this.center();
  2567. result.radius = this.size( v1 ).length() * 0.5;
  2568. return result;
  2569. };
  2570. }(),
  2571. intersect: function ( box ) {
  2572. this.min.max( box.min );
  2573. this.max.min( box.max );
  2574. return this;
  2575. },
  2576. union: function ( box ) {
  2577. this.min.min( box.min );
  2578. this.max.max( box.max );
  2579. return this;
  2580. },
  2581. applyMatrix4: function () {
  2582. var points = [
  2583. new THREE.Vector3(),
  2584. new THREE.Vector3(),
  2585. new THREE.Vector3(),
  2586. new THREE.Vector3(),
  2587. new THREE.Vector3(),
  2588. new THREE.Vector3(),
  2589. new THREE.Vector3(),
  2590. new THREE.Vector3()
  2591. ];
  2592. return function ( matrix ) {
  2593. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2594. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2595. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2596. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2597. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2598. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2599. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2600. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2601. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2602. this.makeEmpty();
  2603. this.setFromPoints( points );
  2604. return this;
  2605. };
  2606. }(),
  2607. translate: function ( offset ) {
  2608. this.min.add( offset );
  2609. this.max.add( offset );
  2610. return this;
  2611. },
  2612. equals: function ( box ) {
  2613. return box.min.equals( this.min ) && box.max.equals( this.max );
  2614. }
  2615. };
  2616. // File:src/math/Matrix3.js
  2617. /**
  2618. * @author alteredq / http://alteredqualia.com/
  2619. * @author WestLangley / http://github.com/WestLangley
  2620. * @author bhouston / http://clara.io
  2621. * @author tschw
  2622. */
  2623. THREE.Matrix3 = function () {
  2624. this.elements = new Float32Array( [
  2625. 1, 0, 0,
  2626. 0, 1, 0,
  2627. 0, 0, 1
  2628. ] );
  2629. if ( arguments.length > 0 ) {
  2630. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2631. }
  2632. };
  2633. THREE.Matrix3.prototype = {
  2634. constructor: THREE.Matrix3,
  2635. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2636. var te = this.elements;
  2637. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  2638. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  2639. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  2640. return this;
  2641. },
  2642. identity: function () {
  2643. this.set(
  2644. 1, 0, 0,
  2645. 0, 1, 0,
  2646. 0, 0, 1
  2647. );
  2648. return this;
  2649. },
  2650. clone: function () {
  2651. return new this.constructor().fromArray( this.elements );
  2652. },
  2653. copy: function ( m ) {
  2654. var me = m.elements;
  2655. this.set(
  2656. me[ 0 ], me[ 3 ], me[ 6 ],
  2657. me[ 1 ], me[ 4 ], me[ 7 ],
  2658. me[ 2 ], me[ 5 ], me[ 8 ]
  2659. );
  2660. return this;
  2661. },
  2662. setFromMatrix4: function( m ) {
  2663. var me = m.elements;
  2664. this.set(
  2665. me[ 0 ], me[ 4 ], me[ 8 ],
  2666. me[ 1 ], me[ 5 ], me[ 9 ],
  2667. me[ 2 ], me[ 6 ], me[ 10 ]
  2668. );
  2669. return this;
  2670. },
  2671. applyToVector3Array: function () {
  2672. var v1;
  2673. return function ( array, offset, length ) {
  2674. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2675. if ( offset === undefined ) offset = 0;
  2676. if ( length === undefined ) length = array.length;
  2677. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2678. v1.fromArray( array, j );
  2679. v1.applyMatrix3( this );
  2680. v1.toArray( array, j );
  2681. }
  2682. return array;
  2683. };
  2684. }(),
  2685. applyToBuffer: function () {
  2686. var v1;
  2687. return function applyToBuffer( buffer, offset, length ) {
  2688. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2689. if ( offset === undefined ) offset = 0;
  2690. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2691. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2692. v1.x = buffer.getX( j );
  2693. v1.y = buffer.getY( j );
  2694. v1.z = buffer.getZ( j );
  2695. v1.applyMatrix3( this );
  2696. buffer.setXYZ( v1.x, v1.y, v1.z );
  2697. }
  2698. return buffer;
  2699. };
  2700. }(),
  2701. multiplyScalar: function ( s ) {
  2702. var te = this.elements;
  2703. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2704. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2705. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2706. return this;
  2707. },
  2708. determinant: function () {
  2709. var te = this.elements;
  2710. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2711. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2712. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2713. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2714. },
  2715. getInverse: function ( matrix, throwOnDegenerate ) {
  2716. if ( matrix instanceof THREE.Matrix4 ) {
  2717. console.warn( "THREE.Matrix3.getInverse no longer takes a Matrix4 argument." );
  2718. }
  2719. var me = matrix.elements,
  2720. te = this.elements,
  2721. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  2722. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  2723. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  2724. t11 = n33 * n22 - n32 * n23,
  2725. t12 = n32 * n13 - n33 * n12,
  2726. t13 = n23 * n12 - n22 * n13,
  2727. det = n11 * t11 + n21 * t12 + n31 * t13;
  2728. if ( det === 0 ) {
  2729. var msg = "THREE.Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2730. if ( throwOnDegenerate || false ) {
  2731. throw new Error( msg );
  2732. } else {
  2733. console.warn( msg );
  2734. }
  2735. return this.identity();
  2736. }
  2737. te[ 0 ] = t11;
  2738. te[ 1 ] = n31 * n23 - n33 * n21;
  2739. te[ 2 ] = n32 * n21 - n31 * n22;
  2740. te[ 3 ] = t12;
  2741. te[ 4 ] = n33 * n11 - n31 * n13;
  2742. te[ 5 ] = n31 * n12 - n32 * n11;
  2743. te[ 6 ] = t13;
  2744. te[ 7 ] = n21 * n13 - n23 * n11;
  2745. te[ 8 ] = n22 * n11 - n21 * n12;
  2746. return this.multiplyScalar( 1 / det );
  2747. },
  2748. transpose: function () {
  2749. var tmp, m = this.elements;
  2750. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2751. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2752. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2753. return this;
  2754. },
  2755. flattenToArrayOffset: function ( array, offset ) {
  2756. var te = this.elements;
  2757. array[ offset ] = te[ 0 ];
  2758. array[ offset + 1 ] = te[ 1 ];
  2759. array[ offset + 2 ] = te[ 2 ];
  2760. array[ offset + 3 ] = te[ 3 ];
  2761. array[ offset + 4 ] = te[ 4 ];
  2762. array[ offset + 5 ] = te[ 5 ];
  2763. array[ offset + 6 ] = te[ 6 ];
  2764. array[ offset + 7 ] = te[ 7 ];
  2765. array[ offset + 8 ] = te[ 8 ];
  2766. return array;
  2767. },
  2768. getNormalMatrix: function ( matrix4 ) {
  2769. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  2770. },
  2771. transposeIntoArray: function ( r ) {
  2772. var m = this.elements;
  2773. r[ 0 ] = m[ 0 ];
  2774. r[ 1 ] = m[ 3 ];
  2775. r[ 2 ] = m[ 6 ];
  2776. r[ 3 ] = m[ 1 ];
  2777. r[ 4 ] = m[ 4 ];
  2778. r[ 5 ] = m[ 7 ];
  2779. r[ 6 ] = m[ 2 ];
  2780. r[ 7 ] = m[ 5 ];
  2781. r[ 8 ] = m[ 8 ];
  2782. return this;
  2783. },
  2784. fromArray: function ( array ) {
  2785. this.elements.set( array );
  2786. return this;
  2787. },
  2788. toArray: function () {
  2789. var te = this.elements;
  2790. return [
  2791. te[ 0 ], te[ 1 ], te[ 2 ],
  2792. te[ 3 ], te[ 4 ], te[ 5 ],
  2793. te[ 6 ], te[ 7 ], te[ 8 ]
  2794. ];
  2795. }
  2796. };
  2797. // File:src/math/Matrix4.js
  2798. /**
  2799. * @author mrdoob / http://mrdoob.com/
  2800. * @author supereggbert / http://www.paulbrunt.co.uk/
  2801. * @author philogb / http://blog.thejit.org/
  2802. * @author jordi_ros / http://plattsoft.com
  2803. * @author D1plo1d / http://github.com/D1plo1d
  2804. * @author alteredq / http://alteredqualia.com/
  2805. * @author mikael emtinger / http://gomo.se/
  2806. * @author timknip / http://www.floorplanner.com/
  2807. * @author bhouston / http://clara.io
  2808. * @author WestLangley / http://github.com/WestLangley
  2809. */
  2810. THREE.Matrix4 = function () {
  2811. this.elements = new Float32Array( [
  2812. 1, 0, 0, 0,
  2813. 0, 1, 0, 0,
  2814. 0, 0, 1, 0,
  2815. 0, 0, 0, 1
  2816. ] );
  2817. if ( arguments.length > 0 ) {
  2818. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2819. }
  2820. };
  2821. THREE.Matrix4.prototype = {
  2822. constructor: THREE.Matrix4,
  2823. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2824. var te = this.elements;
  2825. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2826. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2827. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2828. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2829. return this;
  2830. },
  2831. identity: function () {
  2832. this.set(
  2833. 1, 0, 0, 0,
  2834. 0, 1, 0, 0,
  2835. 0, 0, 1, 0,
  2836. 0, 0, 0, 1
  2837. );
  2838. return this;
  2839. },
  2840. clone: function () {
  2841. return new THREE.Matrix4().fromArray( this.elements );
  2842. },
  2843. copy: function ( m ) {
  2844. this.elements.set( m.elements );
  2845. return this;
  2846. },
  2847. copyPosition: function ( m ) {
  2848. var te = this.elements;
  2849. var me = m.elements;
  2850. te[ 12 ] = me[ 12 ];
  2851. te[ 13 ] = me[ 13 ];
  2852. te[ 14 ] = me[ 14 ];
  2853. return this;
  2854. },
  2855. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2856. xAxis.setFromMatrixColumn( this, 0 );
  2857. yAxis.setFromMatrixColumn( this, 1 );
  2858. zAxis.setFromMatrixColumn( this, 2 );
  2859. return this;
  2860. },
  2861. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2862. this.set(
  2863. xAxis.x, yAxis.x, zAxis.x, 0,
  2864. xAxis.y, yAxis.y, zAxis.y, 0,
  2865. xAxis.z, yAxis.z, zAxis.z, 0,
  2866. 0, 0, 0, 1
  2867. );
  2868. return this;
  2869. },
  2870. extractRotation: function () {
  2871. var v1;
  2872. return function ( m ) {
  2873. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2874. var te = this.elements;
  2875. var me = m.elements;
  2876. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  2877. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  2878. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  2879. te[ 0 ] = me[ 0 ] * scaleX;
  2880. te[ 1 ] = me[ 1 ] * scaleX;
  2881. te[ 2 ] = me[ 2 ] * scaleX;
  2882. te[ 4 ] = me[ 4 ] * scaleY;
  2883. te[ 5 ] = me[ 5 ] * scaleY;
  2884. te[ 6 ] = me[ 6 ] * scaleY;
  2885. te[ 8 ] = me[ 8 ] * scaleZ;
  2886. te[ 9 ] = me[ 9 ] * scaleZ;
  2887. te[ 10 ] = me[ 10 ] * scaleZ;
  2888. return this;
  2889. };
  2890. }(),
  2891. makeRotationFromEuler: function ( euler ) {
  2892. if ( euler instanceof THREE.Euler === false ) {
  2893. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2894. }
  2895. var te = this.elements;
  2896. var x = euler.x, y = euler.y, z = euler.z;
  2897. var a = Math.cos( x ), b = Math.sin( x );
  2898. var c = Math.cos( y ), d = Math.sin( y );
  2899. var e = Math.cos( z ), f = Math.sin( z );
  2900. if ( euler.order === 'XYZ' ) {
  2901. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2902. te[ 0 ] = c * e;
  2903. te[ 4 ] = - c * f;
  2904. te[ 8 ] = d;
  2905. te[ 1 ] = af + be * d;
  2906. te[ 5 ] = ae - bf * d;
  2907. te[ 9 ] = - b * c;
  2908. te[ 2 ] = bf - ae * d;
  2909. te[ 6 ] = be + af * d;
  2910. te[ 10 ] = a * c;
  2911. } else if ( euler.order === 'YXZ' ) {
  2912. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2913. te[ 0 ] = ce + df * b;
  2914. te[ 4 ] = de * b - cf;
  2915. te[ 8 ] = a * d;
  2916. te[ 1 ] = a * f;
  2917. te[ 5 ] = a * e;
  2918. te[ 9 ] = - b;
  2919. te[ 2 ] = cf * b - de;
  2920. te[ 6 ] = df + ce * b;
  2921. te[ 10 ] = a * c;
  2922. } else if ( euler.order === 'ZXY' ) {
  2923. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2924. te[ 0 ] = ce - df * b;
  2925. te[ 4 ] = - a * f;
  2926. te[ 8 ] = de + cf * b;
  2927. te[ 1 ] = cf + de * b;
  2928. te[ 5 ] = a * e;
  2929. te[ 9 ] = df - ce * b;
  2930. te[ 2 ] = - a * d;
  2931. te[ 6 ] = b;
  2932. te[ 10 ] = a * c;
  2933. } else if ( euler.order === 'ZYX' ) {
  2934. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2935. te[ 0 ] = c * e;
  2936. te[ 4 ] = be * d - af;
  2937. te[ 8 ] = ae * d + bf;
  2938. te[ 1 ] = c * f;
  2939. te[ 5 ] = bf * d + ae;
  2940. te[ 9 ] = af * d - be;
  2941. te[ 2 ] = - d;
  2942. te[ 6 ] = b * c;
  2943. te[ 10 ] = a * c;
  2944. } else if ( euler.order === 'YZX' ) {
  2945. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2946. te[ 0 ] = c * e;
  2947. te[ 4 ] = bd - ac * f;
  2948. te[ 8 ] = bc * f + ad;
  2949. te[ 1 ] = f;
  2950. te[ 5 ] = a * e;
  2951. te[ 9 ] = - b * e;
  2952. te[ 2 ] = - d * e;
  2953. te[ 6 ] = ad * f + bc;
  2954. te[ 10 ] = ac - bd * f;
  2955. } else if ( euler.order === 'XZY' ) {
  2956. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2957. te[ 0 ] = c * e;
  2958. te[ 4 ] = - f;
  2959. te[ 8 ] = d * e;
  2960. te[ 1 ] = ac * f + bd;
  2961. te[ 5 ] = a * e;
  2962. te[ 9 ] = ad * f - bc;
  2963. te[ 2 ] = bc * f - ad;
  2964. te[ 6 ] = b * e;
  2965. te[ 10 ] = bd * f + ac;
  2966. }
  2967. // last column
  2968. te[ 3 ] = 0;
  2969. te[ 7 ] = 0;
  2970. te[ 11 ] = 0;
  2971. // bottom row
  2972. te[ 12 ] = 0;
  2973. te[ 13 ] = 0;
  2974. te[ 14 ] = 0;
  2975. te[ 15 ] = 1;
  2976. return this;
  2977. },
  2978. makeRotationFromQuaternion: function ( q ) {
  2979. var te = this.elements;
  2980. var x = q.x, y = q.y, z = q.z, w = q.w;
  2981. var x2 = x + x, y2 = y + y, z2 = z + z;
  2982. var xx = x * x2, xy = x * y2, xz = x * z2;
  2983. var yy = y * y2, yz = y * z2, zz = z * z2;
  2984. var wx = w * x2, wy = w * y2, wz = w * z2;
  2985. te[ 0 ] = 1 - ( yy + zz );
  2986. te[ 4 ] = xy - wz;
  2987. te[ 8 ] = xz + wy;
  2988. te[ 1 ] = xy + wz;
  2989. te[ 5 ] = 1 - ( xx + zz );
  2990. te[ 9 ] = yz - wx;
  2991. te[ 2 ] = xz - wy;
  2992. te[ 6 ] = yz + wx;
  2993. te[ 10 ] = 1 - ( xx + yy );
  2994. // last column
  2995. te[ 3 ] = 0;
  2996. te[ 7 ] = 0;
  2997. te[ 11 ] = 0;
  2998. // bottom row
  2999. te[ 12 ] = 0;
  3000. te[ 13 ] = 0;
  3001. te[ 14 ] = 0;
  3002. te[ 15 ] = 1;
  3003. return this;
  3004. },
  3005. lookAt: function () {
  3006. var x, y, z;
  3007. return function ( eye, target, up ) {
  3008. if ( x === undefined ) x = new THREE.Vector3();
  3009. if ( y === undefined ) y = new THREE.Vector3();
  3010. if ( z === undefined ) z = new THREE.Vector3();
  3011. var te = this.elements;
  3012. z.subVectors( eye, target ).normalize();
  3013. if ( z.lengthSq() === 0 ) {
  3014. z.z = 1;
  3015. }
  3016. x.crossVectors( up, z ).normalize();
  3017. if ( x.lengthSq() === 0 ) {
  3018. z.x += 0.0001;
  3019. x.crossVectors( up, z ).normalize();
  3020. }
  3021. y.crossVectors( z, x );
  3022. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  3023. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  3024. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  3025. return this;
  3026. };
  3027. }(),
  3028. multiply: function ( m, n ) {
  3029. if ( n !== undefined ) {
  3030. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3031. return this.multiplyMatrices( m, n );
  3032. }
  3033. return this.multiplyMatrices( this, m );
  3034. },
  3035. multiplyMatrices: function ( a, b ) {
  3036. var ae = a.elements;
  3037. var be = b.elements;
  3038. var te = this.elements;
  3039. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3040. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3041. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3042. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3043. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3044. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3045. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3046. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3047. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3048. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3049. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3050. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3051. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3052. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3053. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3054. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3055. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3056. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3057. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3058. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3059. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3060. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3061. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3062. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3063. return this;
  3064. },
  3065. multiplyToArray: function ( a, b, r ) {
  3066. var te = this.elements;
  3067. this.multiplyMatrices( a, b );
  3068. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3069. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3070. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3071. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3072. return this;
  3073. },
  3074. multiplyScalar: function ( s ) {
  3075. var te = this.elements;
  3076. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3077. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3078. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3079. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3080. return this;
  3081. },
  3082. applyToVector3Array: function () {
  3083. var v1;
  3084. return function ( array, offset, length ) {
  3085. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3086. if ( offset === undefined ) offset = 0;
  3087. if ( length === undefined ) length = array.length;
  3088. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3089. v1.fromArray( array, j );
  3090. v1.applyMatrix4( this );
  3091. v1.toArray( array, j );
  3092. }
  3093. return array;
  3094. };
  3095. }(),
  3096. applyToBuffer: function () {
  3097. var v1;
  3098. return function applyToBuffer( buffer, offset, length ) {
  3099. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3100. if ( offset === undefined ) offset = 0;
  3101. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3102. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3103. v1.x = buffer.getX( j );
  3104. v1.y = buffer.getY( j );
  3105. v1.z = buffer.getZ( j );
  3106. v1.applyMatrix4( this );
  3107. buffer.setXYZ( v1.x, v1.y, v1.z );
  3108. }
  3109. return buffer;
  3110. };
  3111. }(),
  3112. determinant: function () {
  3113. var te = this.elements;
  3114. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3115. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3116. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3117. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3118. //TODO: make this more efficient
  3119. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3120. return (
  3121. n41 * (
  3122. + n14 * n23 * n32
  3123. - n13 * n24 * n32
  3124. - n14 * n22 * n33
  3125. + n12 * n24 * n33
  3126. + n13 * n22 * n34
  3127. - n12 * n23 * n34
  3128. ) +
  3129. n42 * (
  3130. + n11 * n23 * n34
  3131. - n11 * n24 * n33
  3132. + n14 * n21 * n33
  3133. - n13 * n21 * n34
  3134. + n13 * n24 * n31
  3135. - n14 * n23 * n31
  3136. ) +
  3137. n43 * (
  3138. + n11 * n24 * n32
  3139. - n11 * n22 * n34
  3140. - n14 * n21 * n32
  3141. + n12 * n21 * n34
  3142. + n14 * n22 * n31
  3143. - n12 * n24 * n31
  3144. ) +
  3145. n44 * (
  3146. - n13 * n22 * n31
  3147. - n11 * n23 * n32
  3148. + n11 * n22 * n33
  3149. + n13 * n21 * n32
  3150. - n12 * n21 * n33
  3151. + n12 * n23 * n31
  3152. )
  3153. );
  3154. },
  3155. transpose: function () {
  3156. var te = this.elements;
  3157. var tmp;
  3158. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3159. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3160. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3161. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3162. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3163. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3164. return this;
  3165. },
  3166. flattenToArrayOffset: function ( array, offset ) {
  3167. var te = this.elements;
  3168. array[ offset ] = te[ 0 ];
  3169. array[ offset + 1 ] = te[ 1 ];
  3170. array[ offset + 2 ] = te[ 2 ];
  3171. array[ offset + 3 ] = te[ 3 ];
  3172. array[ offset + 4 ] = te[ 4 ];
  3173. array[ offset + 5 ] = te[ 5 ];
  3174. array[ offset + 6 ] = te[ 6 ];
  3175. array[ offset + 7 ] = te[ 7 ];
  3176. array[ offset + 8 ] = te[ 8 ];
  3177. array[ offset + 9 ] = te[ 9 ];
  3178. array[ offset + 10 ] = te[ 10 ];
  3179. array[ offset + 11 ] = te[ 11 ];
  3180. array[ offset + 12 ] = te[ 12 ];
  3181. array[ offset + 13 ] = te[ 13 ];
  3182. array[ offset + 14 ] = te[ 14 ];
  3183. array[ offset + 15 ] = te[ 15 ];
  3184. return array;
  3185. },
  3186. getPosition: function () {
  3187. var v1;
  3188. return function () {
  3189. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3190. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3191. return v1.setFromMatrixColumn( this, 3 );
  3192. };
  3193. }(),
  3194. setPosition: function ( v ) {
  3195. var te = this.elements;
  3196. te[ 12 ] = v.x;
  3197. te[ 13 ] = v.y;
  3198. te[ 14 ] = v.z;
  3199. return this;
  3200. },
  3201. getInverse: function ( m, throwOnDegenerate ) {
  3202. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3203. var te = this.elements,
  3204. me = m.elements,
  3205. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  3206. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  3207. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  3208. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  3209. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3210. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3211. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3212. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3213. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3214. if ( det === 0 ) {
  3215. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3216. if ( throwOnDegenerate || false ) {
  3217. throw new Error( msg );
  3218. } else {
  3219. console.warn( msg );
  3220. }
  3221. return this.identity();
  3222. }
  3223. te[ 0 ] = t11;
  3224. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3225. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3226. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3227. te[ 4 ] = t12;
  3228. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3229. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3230. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3231. te[ 8 ] = t13;
  3232. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3233. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3234. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3235. te[ 12 ] = t14;
  3236. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3237. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3238. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3239. return this.multiplyScalar( 1 / det );
  3240. },
  3241. scale: function ( v ) {
  3242. var te = this.elements;
  3243. var x = v.x, y = v.y, z = v.z;
  3244. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3245. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3246. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3247. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3248. return this;
  3249. },
  3250. getMaxScaleOnAxis: function () {
  3251. var te = this.elements;
  3252. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3253. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3254. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3255. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3256. },
  3257. makeTranslation: function ( x, y, z ) {
  3258. this.set(
  3259. 1, 0, 0, x,
  3260. 0, 1, 0, y,
  3261. 0, 0, 1, z,
  3262. 0, 0, 0, 1
  3263. );
  3264. return this;
  3265. },
  3266. makeRotationX: function ( theta ) {
  3267. var c = Math.cos( theta ), s = Math.sin( theta );
  3268. this.set(
  3269. 1, 0, 0, 0,
  3270. 0, c, - s, 0,
  3271. 0, s, c, 0,
  3272. 0, 0, 0, 1
  3273. );
  3274. return this;
  3275. },
  3276. makeRotationY: function ( theta ) {
  3277. var c = Math.cos( theta ), s = Math.sin( theta );
  3278. this.set(
  3279. c, 0, s, 0,
  3280. 0, 1, 0, 0,
  3281. - s, 0, c, 0,
  3282. 0, 0, 0, 1
  3283. );
  3284. return this;
  3285. },
  3286. makeRotationZ: function ( theta ) {
  3287. var c = Math.cos( theta ), s = Math.sin( theta );
  3288. this.set(
  3289. c, - s, 0, 0,
  3290. s, c, 0, 0,
  3291. 0, 0, 1, 0,
  3292. 0, 0, 0, 1
  3293. );
  3294. return this;
  3295. },
  3296. makeRotationAxis: function ( axis, angle ) {
  3297. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3298. var c = Math.cos( angle );
  3299. var s = Math.sin( angle );
  3300. var t = 1 - c;
  3301. var x = axis.x, y = axis.y, z = axis.z;
  3302. var tx = t * x, ty = t * y;
  3303. this.set(
  3304. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3305. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3306. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3307. 0, 0, 0, 1
  3308. );
  3309. return this;
  3310. },
  3311. makeScale: function ( x, y, z ) {
  3312. this.set(
  3313. x, 0, 0, 0,
  3314. 0, y, 0, 0,
  3315. 0, 0, z, 0,
  3316. 0, 0, 0, 1
  3317. );
  3318. return this;
  3319. },
  3320. compose: function ( position, quaternion, scale ) {
  3321. this.makeRotationFromQuaternion( quaternion );
  3322. this.scale( scale );
  3323. this.setPosition( position );
  3324. return this;
  3325. },
  3326. decompose: function () {
  3327. var vector, matrix;
  3328. return function ( position, quaternion, scale ) {
  3329. if ( vector === undefined ) vector = new THREE.Vector3();
  3330. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3331. var te = this.elements;
  3332. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3333. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3334. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3335. // if determine is negative, we need to invert one scale
  3336. var det = this.determinant();
  3337. if ( det < 0 ) {
  3338. sx = - sx;
  3339. }
  3340. position.x = te[ 12 ];
  3341. position.y = te[ 13 ];
  3342. position.z = te[ 14 ];
  3343. // scale the rotation part
  3344. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3345. var invSX = 1 / sx;
  3346. var invSY = 1 / sy;
  3347. var invSZ = 1 / sz;
  3348. matrix.elements[ 0 ] *= invSX;
  3349. matrix.elements[ 1 ] *= invSX;
  3350. matrix.elements[ 2 ] *= invSX;
  3351. matrix.elements[ 4 ] *= invSY;
  3352. matrix.elements[ 5 ] *= invSY;
  3353. matrix.elements[ 6 ] *= invSY;
  3354. matrix.elements[ 8 ] *= invSZ;
  3355. matrix.elements[ 9 ] *= invSZ;
  3356. matrix.elements[ 10 ] *= invSZ;
  3357. quaternion.setFromRotationMatrix( matrix );
  3358. scale.x = sx;
  3359. scale.y = sy;
  3360. scale.z = sz;
  3361. return this;
  3362. };
  3363. }(),
  3364. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3365. var te = this.elements;
  3366. var x = 2 * near / ( right - left );
  3367. var y = 2 * near / ( top - bottom );
  3368. var a = ( right + left ) / ( right - left );
  3369. var b = ( top + bottom ) / ( top - bottom );
  3370. var c = - ( far + near ) / ( far - near );
  3371. var d = - 2 * far * near / ( far - near );
  3372. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3373. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3374. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3375. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3376. return this;
  3377. },
  3378. makePerspective: function ( fov, aspect, near, far ) {
  3379. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3380. var ymin = - ymax;
  3381. var xmin = ymin * aspect;
  3382. var xmax = ymax * aspect;
  3383. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3384. },
  3385. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3386. var te = this.elements;
  3387. var w = 1.0 / ( right - left );
  3388. var h = 1.0 / ( top - bottom );
  3389. var p = 1.0 / ( far - near );
  3390. var x = ( right + left ) * w;
  3391. var y = ( top + bottom ) * h;
  3392. var z = ( far + near ) * p;
  3393. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3394. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3395. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3396. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3397. return this;
  3398. },
  3399. equals: function ( matrix ) {
  3400. var te = this.elements;
  3401. var me = matrix.elements;
  3402. for ( var i = 0; i < 16; i ++ ) {
  3403. if ( te[ i ] !== me[ i ] ) return false;
  3404. }
  3405. return true;
  3406. },
  3407. fromArray: function ( array ) {
  3408. this.elements.set( array );
  3409. return this;
  3410. },
  3411. toArray: function () {
  3412. var te = this.elements;
  3413. return [
  3414. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3415. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3416. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3417. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3418. ];
  3419. }
  3420. };
  3421. // File:src/math/Ray.js
  3422. /**
  3423. * @author bhouston / http://clara.io
  3424. */
  3425. THREE.Ray = function ( origin, direction ) {
  3426. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3427. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3428. };
  3429. THREE.Ray.prototype = {
  3430. constructor: THREE.Ray,
  3431. set: function ( origin, direction ) {
  3432. this.origin.copy( origin );
  3433. this.direction.copy( direction );
  3434. return this;
  3435. },
  3436. clone: function () {
  3437. return new this.constructor().copy( this );
  3438. },
  3439. copy: function ( ray ) {
  3440. this.origin.copy( ray.origin );
  3441. this.direction.copy( ray.direction );
  3442. return this;
  3443. },
  3444. at: function ( t, optionalTarget ) {
  3445. var result = optionalTarget || new THREE.Vector3();
  3446. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3447. },
  3448. lookAt: function ( v ) {
  3449. this.direction.copy( v ).sub( this.origin ).normalize();
  3450. },
  3451. recast: function () {
  3452. var v1 = new THREE.Vector3();
  3453. return function ( t ) {
  3454. this.origin.copy( this.at( t, v1 ) );
  3455. return this;
  3456. };
  3457. }(),
  3458. closestPointToPoint: function ( point, optionalTarget ) {
  3459. var result = optionalTarget || new THREE.Vector3();
  3460. result.subVectors( point, this.origin );
  3461. var directionDistance = result.dot( this.direction );
  3462. if ( directionDistance < 0 ) {
  3463. return result.copy( this.origin );
  3464. }
  3465. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3466. },
  3467. distanceToPoint: function ( point ) {
  3468. return Math.sqrt( this.distanceSqToPoint( point ) );
  3469. },
  3470. distanceSqToPoint: function () {
  3471. var v1 = new THREE.Vector3();
  3472. return function ( point ) {
  3473. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3474. // point behind the ray
  3475. if ( directionDistance < 0 ) {
  3476. return this.origin.distanceToSquared( point );
  3477. }
  3478. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3479. return v1.distanceToSquared( point );
  3480. };
  3481. }(),
  3482. distanceSqToSegment: function () {
  3483. var segCenter = new THREE.Vector3();
  3484. var segDir = new THREE.Vector3();
  3485. var diff = new THREE.Vector3();
  3486. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3487. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3488. // It returns the min distance between the ray and the segment
  3489. // defined by v0 and v1
  3490. // It can also set two optional targets :
  3491. // - The closest point on the ray
  3492. // - The closest point on the segment
  3493. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3494. segDir.copy( v1 ).sub( v0 ).normalize();
  3495. diff.copy( this.origin ).sub( segCenter );
  3496. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3497. var a01 = - this.direction.dot( segDir );
  3498. var b0 = diff.dot( this.direction );
  3499. var b1 = - diff.dot( segDir );
  3500. var c = diff.lengthSq();
  3501. var det = Math.abs( 1 - a01 * a01 );
  3502. var s0, s1, sqrDist, extDet;
  3503. if ( det > 0 ) {
  3504. // The ray and segment are not parallel.
  3505. s0 = a01 * b1 - b0;
  3506. s1 = a01 * b0 - b1;
  3507. extDet = segExtent * det;
  3508. if ( s0 >= 0 ) {
  3509. if ( s1 >= - extDet ) {
  3510. if ( s1 <= extDet ) {
  3511. // region 0
  3512. // Minimum at interior points of ray and segment.
  3513. var invDet = 1 / det;
  3514. s0 *= invDet;
  3515. s1 *= invDet;
  3516. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3517. } else {
  3518. // region 1
  3519. s1 = segExtent;
  3520. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3521. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3522. }
  3523. } else {
  3524. // region 5
  3525. s1 = - segExtent;
  3526. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3527. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3528. }
  3529. } else {
  3530. if ( s1 <= - extDet ) {
  3531. // region 4
  3532. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3533. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3534. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3535. } else if ( s1 <= extDet ) {
  3536. // region 3
  3537. s0 = 0;
  3538. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3539. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3540. } else {
  3541. // region 2
  3542. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3543. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3544. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3545. }
  3546. }
  3547. } else {
  3548. // Ray and segment are parallel.
  3549. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3550. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3551. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3552. }
  3553. if ( optionalPointOnRay ) {
  3554. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3555. }
  3556. if ( optionalPointOnSegment ) {
  3557. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3558. }
  3559. return sqrDist;
  3560. };
  3561. }(),
  3562. intersectSphere: function () {
  3563. var v1 = new THREE.Vector3();
  3564. return function ( sphere, optionalTarget ) {
  3565. v1.subVectors( sphere.center, this.origin );
  3566. var tca = v1.dot( this.direction );
  3567. var d2 = v1.dot( v1 ) - tca * tca;
  3568. var radius2 = sphere.radius * sphere.radius;
  3569. if ( d2 > radius2 ) return null;
  3570. var thc = Math.sqrt( radius2 - d2 );
  3571. // t0 = first intersect point - entrance on front of sphere
  3572. var t0 = tca - thc;
  3573. // t1 = second intersect point - exit point on back of sphere
  3574. var t1 = tca + thc;
  3575. // test to see if both t0 and t1 are behind the ray - if so, return null
  3576. if ( t0 < 0 && t1 < 0 ) return null;
  3577. // test to see if t0 is behind the ray:
  3578. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3579. // in order to always return an intersect point that is in front of the ray.
  3580. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3581. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3582. return this.at( t0, optionalTarget );
  3583. }
  3584. }(),
  3585. intersectsSphere: function ( sphere ) {
  3586. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3587. },
  3588. distanceToPlane: function ( plane ) {
  3589. var denominator = plane.normal.dot( this.direction );
  3590. if ( denominator === 0 ) {
  3591. // line is coplanar, return origin
  3592. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3593. return 0;
  3594. }
  3595. // Null is preferable to undefined since undefined means.... it is undefined
  3596. return null;
  3597. }
  3598. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3599. // Return if the ray never intersects the plane
  3600. return t >= 0 ? t : null;
  3601. },
  3602. intersectPlane: function ( plane, optionalTarget ) {
  3603. var t = this.distanceToPlane( plane );
  3604. if ( t === null ) {
  3605. return null;
  3606. }
  3607. return this.at( t, optionalTarget );
  3608. },
  3609. intersectsPlane: function ( plane ) {
  3610. // check if the ray lies on the plane first
  3611. var distToPoint = plane.distanceToPoint( this.origin );
  3612. if ( distToPoint === 0 ) {
  3613. return true;
  3614. }
  3615. var denominator = plane.normal.dot( this.direction );
  3616. if ( denominator * distToPoint < 0 ) {
  3617. return true;
  3618. }
  3619. // ray origin is behind the plane (and is pointing behind it)
  3620. return false;
  3621. },
  3622. intersectBox: function ( box, optionalTarget ) {
  3623. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3624. var invdirx = 1 / this.direction.x,
  3625. invdiry = 1 / this.direction.y,
  3626. invdirz = 1 / this.direction.z;
  3627. var origin = this.origin;
  3628. if ( invdirx >= 0 ) {
  3629. tmin = ( box.min.x - origin.x ) * invdirx;
  3630. tmax = ( box.max.x - origin.x ) * invdirx;
  3631. } else {
  3632. tmin = ( box.max.x - origin.x ) * invdirx;
  3633. tmax = ( box.min.x - origin.x ) * invdirx;
  3634. }
  3635. if ( invdiry >= 0 ) {
  3636. tymin = ( box.min.y - origin.y ) * invdiry;
  3637. tymax = ( box.max.y - origin.y ) * invdiry;
  3638. } else {
  3639. tymin = ( box.max.y - origin.y ) * invdiry;
  3640. tymax = ( box.min.y - origin.y ) * invdiry;
  3641. }
  3642. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3643. // These lines also handle the case where tmin or tmax is NaN
  3644. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3645. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3646. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3647. if ( invdirz >= 0 ) {
  3648. tzmin = ( box.min.z - origin.z ) * invdirz;
  3649. tzmax = ( box.max.z - origin.z ) * invdirz;
  3650. } else {
  3651. tzmin = ( box.max.z - origin.z ) * invdirz;
  3652. tzmax = ( box.min.z - origin.z ) * invdirz;
  3653. }
  3654. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3655. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3656. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3657. //return point closest to the ray (positive side)
  3658. if ( tmax < 0 ) return null;
  3659. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3660. },
  3661. intersectsBox: ( function () {
  3662. var v = new THREE.Vector3();
  3663. return function ( box ) {
  3664. return this.intersectBox( box, v ) !== null;
  3665. };
  3666. } )(),
  3667. intersectTriangle: function () {
  3668. // Compute the offset origin, edges, and normal.
  3669. var diff = new THREE.Vector3();
  3670. var edge1 = new THREE.Vector3();
  3671. var edge2 = new THREE.Vector3();
  3672. var normal = new THREE.Vector3();
  3673. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3674. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3675. edge1.subVectors( b, a );
  3676. edge2.subVectors( c, a );
  3677. normal.crossVectors( edge1, edge2 );
  3678. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3679. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3680. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3681. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3682. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3683. var DdN = this.direction.dot( normal );
  3684. var sign;
  3685. if ( DdN > 0 ) {
  3686. if ( backfaceCulling ) return null;
  3687. sign = 1;
  3688. } else if ( DdN < 0 ) {
  3689. sign = - 1;
  3690. DdN = - DdN;
  3691. } else {
  3692. return null;
  3693. }
  3694. diff.subVectors( this.origin, a );
  3695. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3696. // b1 < 0, no intersection
  3697. if ( DdQxE2 < 0 ) {
  3698. return null;
  3699. }
  3700. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3701. // b2 < 0, no intersection
  3702. if ( DdE1xQ < 0 ) {
  3703. return null;
  3704. }
  3705. // b1+b2 > 1, no intersection
  3706. if ( DdQxE2 + DdE1xQ > DdN ) {
  3707. return null;
  3708. }
  3709. // Line intersects triangle, check if ray does.
  3710. var QdN = - sign * diff.dot( normal );
  3711. // t < 0, no intersection
  3712. if ( QdN < 0 ) {
  3713. return null;
  3714. }
  3715. // Ray intersects triangle.
  3716. return this.at( QdN / DdN, optionalTarget );
  3717. };
  3718. }(),
  3719. applyMatrix4: function ( matrix4 ) {
  3720. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3721. this.origin.applyMatrix4( matrix4 );
  3722. this.direction.sub( this.origin );
  3723. this.direction.normalize();
  3724. return this;
  3725. },
  3726. equals: function ( ray ) {
  3727. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3728. }
  3729. };
  3730. // File:src/math/Sphere.js
  3731. /**
  3732. * @author bhouston / http://clara.io
  3733. * @author mrdoob / http://mrdoob.com/
  3734. */
  3735. THREE.Sphere = function ( center, radius ) {
  3736. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3737. this.radius = ( radius !== undefined ) ? radius : 0;
  3738. };
  3739. THREE.Sphere.prototype = {
  3740. constructor: THREE.Sphere,
  3741. set: function ( center, radius ) {
  3742. this.center.copy( center );
  3743. this.radius = radius;
  3744. return this;
  3745. },
  3746. setFromPoints: function () {
  3747. var box = new THREE.Box3();
  3748. return function ( points, optionalCenter ) {
  3749. var center = this.center;
  3750. if ( optionalCenter !== undefined ) {
  3751. center.copy( optionalCenter );
  3752. } else {
  3753. box.setFromPoints( points ).center( center );
  3754. }
  3755. var maxRadiusSq = 0;
  3756. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3757. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3758. }
  3759. this.radius = Math.sqrt( maxRadiusSq );
  3760. return this;
  3761. };
  3762. }(),
  3763. clone: function () {
  3764. return new this.constructor().copy( this );
  3765. },
  3766. copy: function ( sphere ) {
  3767. this.center.copy( sphere.center );
  3768. this.radius = sphere.radius;
  3769. return this;
  3770. },
  3771. empty: function () {
  3772. return ( this.radius <= 0 );
  3773. },
  3774. containsPoint: function ( point ) {
  3775. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3776. },
  3777. distanceToPoint: function ( point ) {
  3778. return ( point.distanceTo( this.center ) - this.radius );
  3779. },
  3780. intersectsSphere: function ( sphere ) {
  3781. var radiusSum = this.radius + sphere.radius;
  3782. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3783. },
  3784. intersectsBox: function ( box ) {
  3785. return box.intersectsSphere( this );
  3786. },
  3787. intersectsPlane: function ( plane ) {
  3788. // We use the following equation to compute the signed distance from
  3789. // the center of the sphere to the plane.
  3790. //
  3791. // distance = q * n - d
  3792. //
  3793. // If this distance is greater than the radius of the sphere,
  3794. // then there is no intersection.
  3795. return Math.abs( this.center.dot( plane.normal ) - plane.constant ) <= this.radius;
  3796. },
  3797. clampPoint: function ( point, optionalTarget ) {
  3798. var deltaLengthSq = this.center.distanceToSquared( point );
  3799. var result = optionalTarget || new THREE.Vector3();
  3800. result.copy( point );
  3801. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3802. result.sub( this.center ).normalize();
  3803. result.multiplyScalar( this.radius ).add( this.center );
  3804. }
  3805. return result;
  3806. },
  3807. getBoundingBox: function ( optionalTarget ) {
  3808. var box = optionalTarget || new THREE.Box3();
  3809. box.set( this.center, this.center );
  3810. box.expandByScalar( this.radius );
  3811. return box;
  3812. },
  3813. applyMatrix4: function ( matrix ) {
  3814. this.center.applyMatrix4( matrix );
  3815. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3816. return this;
  3817. },
  3818. translate: function ( offset ) {
  3819. this.center.add( offset );
  3820. return this;
  3821. },
  3822. equals: function ( sphere ) {
  3823. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3824. }
  3825. };
  3826. // File:src/math/Frustum.js
  3827. /**
  3828. * @author mrdoob / http://mrdoob.com/
  3829. * @author alteredq / http://alteredqualia.com/
  3830. * @author bhouston / http://clara.io
  3831. */
  3832. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3833. this.planes = [
  3834. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3835. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3836. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3837. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3838. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3839. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3840. ];
  3841. };
  3842. THREE.Frustum.prototype = {
  3843. constructor: THREE.Frustum,
  3844. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3845. var planes = this.planes;
  3846. planes[ 0 ].copy( p0 );
  3847. planes[ 1 ].copy( p1 );
  3848. planes[ 2 ].copy( p2 );
  3849. planes[ 3 ].copy( p3 );
  3850. planes[ 4 ].copy( p4 );
  3851. planes[ 5 ].copy( p5 );
  3852. return this;
  3853. },
  3854. clone: function () {
  3855. return new this.constructor().copy( this );
  3856. },
  3857. copy: function ( frustum ) {
  3858. var planes = this.planes;
  3859. for ( var i = 0; i < 6; i ++ ) {
  3860. planes[ i ].copy( frustum.planes[ i ] );
  3861. }
  3862. return this;
  3863. },
  3864. setFromMatrix: function ( m ) {
  3865. var planes = this.planes;
  3866. var me = m.elements;
  3867. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3868. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3869. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3870. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3871. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3872. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3873. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3874. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3875. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3876. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3877. return this;
  3878. },
  3879. intersectsObject: function () {
  3880. var sphere = new THREE.Sphere();
  3881. return function ( object ) {
  3882. var geometry = object.geometry;
  3883. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3884. sphere.copy( geometry.boundingSphere );
  3885. sphere.applyMatrix4( object.matrixWorld );
  3886. return this.intersectsSphere( sphere );
  3887. };
  3888. }(),
  3889. intersectsSphere: function ( sphere ) {
  3890. var planes = this.planes;
  3891. var center = sphere.center;
  3892. var negRadius = - sphere.radius;
  3893. for ( var i = 0; i < 6; i ++ ) {
  3894. var distance = planes[ i ].distanceToPoint( center );
  3895. if ( distance < negRadius ) {
  3896. return false;
  3897. }
  3898. }
  3899. return true;
  3900. },
  3901. intersectsBox: function () {
  3902. var p1 = new THREE.Vector3(),
  3903. p2 = new THREE.Vector3();
  3904. return function ( box ) {
  3905. var planes = this.planes;
  3906. for ( var i = 0; i < 6 ; i ++ ) {
  3907. var plane = planes[ i ];
  3908. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3909. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3910. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3911. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3912. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3913. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3914. var d1 = plane.distanceToPoint( p1 );
  3915. var d2 = plane.distanceToPoint( p2 );
  3916. // if both outside plane, no intersection
  3917. if ( d1 < 0 && d2 < 0 ) {
  3918. return false;
  3919. }
  3920. }
  3921. return true;
  3922. };
  3923. }(),
  3924. containsPoint: function ( point ) {
  3925. var planes = this.planes;
  3926. for ( var i = 0; i < 6; i ++ ) {
  3927. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3928. return false;
  3929. }
  3930. }
  3931. return true;
  3932. }
  3933. };
  3934. // File:src/math/Plane.js
  3935. /**
  3936. * @author bhouston / http://clara.io
  3937. */
  3938. THREE.Plane = function ( normal, constant ) {
  3939. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3940. this.constant = ( constant !== undefined ) ? constant : 0;
  3941. };
  3942. THREE.Plane.prototype = {
  3943. constructor: THREE.Plane,
  3944. set: function ( normal, constant ) {
  3945. this.normal.copy( normal );
  3946. this.constant = constant;
  3947. return this;
  3948. },
  3949. setComponents: function ( x, y, z, w ) {
  3950. this.normal.set( x, y, z );
  3951. this.constant = w;
  3952. return this;
  3953. },
  3954. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3955. this.normal.copy( normal );
  3956. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3957. return this;
  3958. },
  3959. setFromCoplanarPoints: function () {
  3960. var v1 = new THREE.Vector3();
  3961. var v2 = new THREE.Vector3();
  3962. return function ( a, b, c ) {
  3963. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3964. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3965. this.setFromNormalAndCoplanarPoint( normal, a );
  3966. return this;
  3967. };
  3968. }(),
  3969. clone: function () {
  3970. return new this.constructor().copy( this );
  3971. },
  3972. copy: function ( plane ) {
  3973. this.normal.copy( plane.normal );
  3974. this.constant = plane.constant;
  3975. return this;
  3976. },
  3977. normalize: function () {
  3978. // Note: will lead to a divide by zero if the plane is invalid.
  3979. var inverseNormalLength = 1.0 / this.normal.length();
  3980. this.normal.multiplyScalar( inverseNormalLength );
  3981. this.constant *= inverseNormalLength;
  3982. return this;
  3983. },
  3984. negate: function () {
  3985. this.constant *= - 1;
  3986. this.normal.negate();
  3987. return this;
  3988. },
  3989. distanceToPoint: function ( point ) {
  3990. return this.normal.dot( point ) + this.constant;
  3991. },
  3992. distanceToSphere: function ( sphere ) {
  3993. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3994. },
  3995. projectPoint: function ( point, optionalTarget ) {
  3996. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3997. },
  3998. orthoPoint: function ( point, optionalTarget ) {
  3999. var perpendicularMagnitude = this.distanceToPoint( point );
  4000. var result = optionalTarget || new THREE.Vector3();
  4001. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  4002. },
  4003. intersectLine: function () {
  4004. var v1 = new THREE.Vector3();
  4005. return function ( line, optionalTarget ) {
  4006. var result = optionalTarget || new THREE.Vector3();
  4007. var direction = line.delta( v1 );
  4008. var denominator = this.normal.dot( direction );
  4009. if ( denominator === 0 ) {
  4010. // line is coplanar, return origin
  4011. if ( this.distanceToPoint( line.start ) === 0 ) {
  4012. return result.copy( line.start );
  4013. }
  4014. // Unsure if this is the correct method to handle this case.
  4015. return undefined;
  4016. }
  4017. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4018. if ( t < 0 || t > 1 ) {
  4019. return undefined;
  4020. }
  4021. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  4022. };
  4023. }(),
  4024. intersectsLine: function ( line ) {
  4025. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4026. var startSign = this.distanceToPoint( line.start );
  4027. var endSign = this.distanceToPoint( line.end );
  4028. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4029. },
  4030. intersectsBox: function ( box ) {
  4031. return box.intersectsPlane( this );
  4032. },
  4033. intersectsSphere: function ( sphere ) {
  4034. return sphere.intersectsPlane( this );
  4035. },
  4036. coplanarPoint: function ( optionalTarget ) {
  4037. var result = optionalTarget || new THREE.Vector3();
  4038. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4039. },
  4040. applyMatrix4: function () {
  4041. var v1 = new THREE.Vector3();
  4042. var v2 = new THREE.Vector3();
  4043. var m1 = new THREE.Matrix3();
  4044. return function ( matrix, optionalNormalMatrix ) {
  4045. // compute new normal based on theory here:
  4046. // http://www.songho.ca/opengl/gl_normaltransform.html
  4047. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4048. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  4049. var newCoplanarPoint = this.coplanarPoint( v2 );
  4050. newCoplanarPoint.applyMatrix4( matrix );
  4051. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  4052. return this;
  4053. };
  4054. }(),
  4055. translate: function ( offset ) {
  4056. this.constant = this.constant - offset.dot( this.normal );
  4057. return this;
  4058. },
  4059. equals: function ( plane ) {
  4060. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4061. }
  4062. };
  4063. // File:src/math/Spherical.js
  4064. /**
  4065. * @author bhouston / http://clara.io
  4066. * @author WestLangley / http://github.com/WestLangley
  4067. *
  4068. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  4069. *
  4070. * The poles (phi) are at the positive and negative y axis.
  4071. * The equator starts at positive z.
  4072. */
  4073. THREE.Spherical = function ( radius, phi, theta ) {
  4074. this.radius = ( radius !== undefined ) ? radius : 1.0;
  4075. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  4076. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  4077. return this;
  4078. };
  4079. THREE.Spherical.prototype = {
  4080. constructor: THREE.Spherical,
  4081. set: function ( radius, phi, theta ) {
  4082. this.radius = radius;
  4083. this.phi = phi;
  4084. this.theta = theta;
  4085. },
  4086. clone: function () {
  4087. return new this.constructor().copy( this );
  4088. },
  4089. copy: function ( other ) {
  4090. this.radius.copy( other.radius );
  4091. this.phi.copy( other.phi );
  4092. this.theta.copy( other.theta );
  4093. return this;
  4094. },
  4095. // restrict phi to be betwee EPS and PI-EPS
  4096. makeSafe: function() {
  4097. var EPS = 0.000001;
  4098. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  4099. },
  4100. setFromVector3: function( vec3 ) {
  4101. this.radius = vec3.length();
  4102. if ( this.radius === 0 ) {
  4103. this.theta = 0;
  4104. this.phi = 0;
  4105. } else {
  4106. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  4107. this.phi = Math.acos( THREE.Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  4108. }
  4109. return this;
  4110. },
  4111. };
  4112. // File:src/math/Math.js
  4113. /**
  4114. * @author alteredq / http://alteredqualia.com/
  4115. * @author mrdoob / http://mrdoob.com/
  4116. */
  4117. THREE.Math = {
  4118. generateUUID: function () {
  4119. // http://www.broofa.com/Tools/Math.uuid.htm
  4120. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4121. var uuid = new Array( 36 );
  4122. var rnd = 0, r;
  4123. return function () {
  4124. for ( var i = 0; i < 36; i ++ ) {
  4125. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4126. uuid[ i ] = '-';
  4127. } else if ( i === 14 ) {
  4128. uuid[ i ] = '4';
  4129. } else {
  4130. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4131. r = rnd & 0xf;
  4132. rnd = rnd >> 4;
  4133. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4134. }
  4135. }
  4136. return uuid.join( '' );
  4137. };
  4138. }(),
  4139. clamp: function ( value, min, max ) {
  4140. return Math.max( min, Math.min( max, value ) );
  4141. },
  4142. // compute euclidian modulo of m % n
  4143. // https://en.wikipedia.org/wiki/Modulo_operation
  4144. euclideanModulo: function ( n, m ) {
  4145. return ( ( n % m ) + m ) % m;
  4146. },
  4147. // Linear mapping from range <a1, a2> to range <b1, b2>
  4148. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4149. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4150. },
  4151. // http://en.wikipedia.org/wiki/Smoothstep
  4152. smoothstep: function ( x, min, max ) {
  4153. if ( x <= min ) return 0;
  4154. if ( x >= max ) return 1;
  4155. x = ( x - min ) / ( max - min );
  4156. return x * x * ( 3 - 2 * x );
  4157. },
  4158. smootherstep: function ( x, min, max ) {
  4159. if ( x <= min ) return 0;
  4160. if ( x >= max ) return 1;
  4161. x = ( x - min ) / ( max - min );
  4162. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4163. },
  4164. random16: function () {
  4165. console.warn( 'THREE.Math.random16() has been deprecated. Use Math.random() instead.' );
  4166. return Math.random();
  4167. },
  4168. // Random integer from <low, high> interval
  4169. randInt: function ( low, high ) {
  4170. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4171. },
  4172. // Random float from <low, high> interval
  4173. randFloat: function ( low, high ) {
  4174. return low + Math.random() * ( high - low );
  4175. },
  4176. // Random float from <-range/2, range/2> interval
  4177. randFloatSpread: function ( range ) {
  4178. return range * ( 0.5 - Math.random() );
  4179. },
  4180. degToRad: function () {
  4181. var degreeToRadiansFactor = Math.PI / 180;
  4182. return function ( degrees ) {
  4183. return degrees * degreeToRadiansFactor;
  4184. };
  4185. }(),
  4186. radToDeg: function () {
  4187. var radianToDegreesFactor = 180 / Math.PI;
  4188. return function ( radians ) {
  4189. return radians * radianToDegreesFactor;
  4190. };
  4191. }(),
  4192. isPowerOfTwo: function ( value ) {
  4193. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4194. },
  4195. nearestPowerOfTwo: function ( value ) {
  4196. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  4197. },
  4198. nextPowerOfTwo: function ( value ) {
  4199. value --;
  4200. value |= value >> 1;
  4201. value |= value >> 2;
  4202. value |= value >> 4;
  4203. value |= value >> 8;
  4204. value |= value >> 16;
  4205. value ++;
  4206. return value;
  4207. }
  4208. };
  4209. // File:src/math/Spline.js
  4210. /**
  4211. * Spline from Tween.js, slightly optimized (and trashed)
  4212. * http://sole.github.com/tween.js/examples/05_spline.html
  4213. *
  4214. * @author mrdoob / http://mrdoob.com/
  4215. * @author alteredq / http://alteredqualia.com/
  4216. */
  4217. THREE.Spline = function ( points ) {
  4218. this.points = points;
  4219. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4220. point, intPoint, weight, w2, w3,
  4221. pa, pb, pc, pd;
  4222. this.initFromArray = function ( a ) {
  4223. this.points = [];
  4224. for ( var i = 0; i < a.length; i ++ ) {
  4225. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4226. }
  4227. };
  4228. this.getPoint = function ( k ) {
  4229. point = ( this.points.length - 1 ) * k;
  4230. intPoint = Math.floor( point );
  4231. weight = point - intPoint;
  4232. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4233. c[ 1 ] = intPoint;
  4234. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4235. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4236. pa = this.points[ c[ 0 ] ];
  4237. pb = this.points[ c[ 1 ] ];
  4238. pc = this.points[ c[ 2 ] ];
  4239. pd = this.points[ c[ 3 ] ];
  4240. w2 = weight * weight;
  4241. w3 = weight * w2;
  4242. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4243. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4244. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4245. return v3;
  4246. };
  4247. this.getControlPointsArray = function () {
  4248. var i, p, l = this.points.length,
  4249. coords = [];
  4250. for ( i = 0; i < l; i ++ ) {
  4251. p = this.points[ i ];
  4252. coords[ i ] = [ p.x, p.y, p.z ];
  4253. }
  4254. return coords;
  4255. };
  4256. // approximate length by summing linear segments
  4257. this.getLength = function ( nSubDivisions ) {
  4258. var i, index, nSamples, position,
  4259. point = 0, intPoint = 0, oldIntPoint = 0,
  4260. oldPosition = new THREE.Vector3(),
  4261. tmpVec = new THREE.Vector3(),
  4262. chunkLengths = [],
  4263. totalLength = 0;
  4264. // first point has 0 length
  4265. chunkLengths[ 0 ] = 0;
  4266. if ( ! nSubDivisions ) nSubDivisions = 100;
  4267. nSamples = this.points.length * nSubDivisions;
  4268. oldPosition.copy( this.points[ 0 ] );
  4269. for ( i = 1; i < nSamples; i ++ ) {
  4270. index = i / nSamples;
  4271. position = this.getPoint( index );
  4272. tmpVec.copy( position );
  4273. totalLength += tmpVec.distanceTo( oldPosition );
  4274. oldPosition.copy( position );
  4275. point = ( this.points.length - 1 ) * index;
  4276. intPoint = Math.floor( point );
  4277. if ( intPoint !== oldIntPoint ) {
  4278. chunkLengths[ intPoint ] = totalLength;
  4279. oldIntPoint = intPoint;
  4280. }
  4281. }
  4282. // last point ends with total length
  4283. chunkLengths[ chunkLengths.length ] = totalLength;
  4284. return { chunks: chunkLengths, total: totalLength };
  4285. };
  4286. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4287. var i, j,
  4288. index, indexCurrent, indexNext,
  4289. realDistance,
  4290. sampling, position,
  4291. newpoints = [],
  4292. tmpVec = new THREE.Vector3(),
  4293. sl = this.getLength();
  4294. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4295. for ( i = 1; i < this.points.length; i ++ ) {
  4296. //tmpVec.copy( this.points[ i - 1 ] );
  4297. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4298. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4299. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4300. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4301. indexNext = i / ( this.points.length - 1 );
  4302. for ( j = 1; j < sampling - 1; j ++ ) {
  4303. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4304. position = this.getPoint( index );
  4305. newpoints.push( tmpVec.copy( position ).clone() );
  4306. }
  4307. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4308. }
  4309. this.points = newpoints;
  4310. };
  4311. // Catmull-Rom
  4312. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4313. var v0 = ( p2 - p0 ) * 0.5,
  4314. v1 = ( p3 - p1 ) * 0.5;
  4315. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4316. }
  4317. };
  4318. // File:src/math/Triangle.js
  4319. /**
  4320. * @author bhouston / http://clara.io
  4321. * @author mrdoob / http://mrdoob.com/
  4322. */
  4323. THREE.Triangle = function ( a, b, c ) {
  4324. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4325. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4326. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4327. };
  4328. THREE.Triangle.normal = function () {
  4329. var v0 = new THREE.Vector3();
  4330. return function ( a, b, c, optionalTarget ) {
  4331. var result = optionalTarget || new THREE.Vector3();
  4332. result.subVectors( c, b );
  4333. v0.subVectors( a, b );
  4334. result.cross( v0 );
  4335. var resultLengthSq = result.lengthSq();
  4336. if ( resultLengthSq > 0 ) {
  4337. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4338. }
  4339. return result.set( 0, 0, 0 );
  4340. };
  4341. }();
  4342. // static/instance method to calculate barycentric coordinates
  4343. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4344. THREE.Triangle.barycoordFromPoint = function () {
  4345. var v0 = new THREE.Vector3();
  4346. var v1 = new THREE.Vector3();
  4347. var v2 = new THREE.Vector3();
  4348. return function ( point, a, b, c, optionalTarget ) {
  4349. v0.subVectors( c, a );
  4350. v1.subVectors( b, a );
  4351. v2.subVectors( point, a );
  4352. var dot00 = v0.dot( v0 );
  4353. var dot01 = v0.dot( v1 );
  4354. var dot02 = v0.dot( v2 );
  4355. var dot11 = v1.dot( v1 );
  4356. var dot12 = v1.dot( v2 );
  4357. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4358. var result = optionalTarget || new THREE.Vector3();
  4359. // collinear or singular triangle
  4360. if ( denom === 0 ) {
  4361. // arbitrary location outside of triangle?
  4362. // not sure if this is the best idea, maybe should be returning undefined
  4363. return result.set( - 2, - 1, - 1 );
  4364. }
  4365. var invDenom = 1 / denom;
  4366. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4367. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4368. // barycentric coordinates must always sum to 1
  4369. return result.set( 1 - u - v, v, u );
  4370. };
  4371. }();
  4372. THREE.Triangle.containsPoint = function () {
  4373. var v1 = new THREE.Vector3();
  4374. return function ( point, a, b, c ) {
  4375. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4376. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4377. };
  4378. }();
  4379. THREE.Triangle.prototype = {
  4380. constructor: THREE.Triangle,
  4381. set: function ( a, b, c ) {
  4382. this.a.copy( a );
  4383. this.b.copy( b );
  4384. this.c.copy( c );
  4385. return this;
  4386. },
  4387. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4388. this.a.copy( points[ i0 ] );
  4389. this.b.copy( points[ i1 ] );
  4390. this.c.copy( points[ i2 ] );
  4391. return this;
  4392. },
  4393. clone: function () {
  4394. return new this.constructor().copy( this );
  4395. },
  4396. copy: function ( triangle ) {
  4397. this.a.copy( triangle.a );
  4398. this.b.copy( triangle.b );
  4399. this.c.copy( triangle.c );
  4400. return this;
  4401. },
  4402. area: function () {
  4403. var v0 = new THREE.Vector3();
  4404. var v1 = new THREE.Vector3();
  4405. return function () {
  4406. v0.subVectors( this.c, this.b );
  4407. v1.subVectors( this.a, this.b );
  4408. return v0.cross( v1 ).length() * 0.5;
  4409. };
  4410. }(),
  4411. midpoint: function ( optionalTarget ) {
  4412. var result = optionalTarget || new THREE.Vector3();
  4413. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4414. },
  4415. normal: function ( optionalTarget ) {
  4416. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4417. },
  4418. plane: function ( optionalTarget ) {
  4419. var result = optionalTarget || new THREE.Plane();
  4420. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4421. },
  4422. barycoordFromPoint: function ( point, optionalTarget ) {
  4423. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4424. },
  4425. containsPoint: function ( point ) {
  4426. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4427. },
  4428. equals: function ( triangle ) {
  4429. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4430. }
  4431. };
  4432. // File:src/math/Interpolant.js
  4433. /**
  4434. * Abstract base class of interpolants over parametric samples.
  4435. *
  4436. * The parameter domain is one dimensional, typically the time or a path
  4437. * along a curve defined by the data.
  4438. *
  4439. * The sample values can have any dimensionality and derived classes may
  4440. * apply special interpretations to the data.
  4441. *
  4442. * This class provides the interval seek in a Template Method, deferring
  4443. * the actual interpolation to derived classes.
  4444. *
  4445. * Time complexity is O(1) for linear access crossing at most two points
  4446. * and O(log N) for random access, where N is the number of positions.
  4447. *
  4448. * References:
  4449. *
  4450. * http://www.oodesign.com/template-method-pattern.html
  4451. *
  4452. * @author tschw
  4453. */
  4454. THREE.Interpolant = function(
  4455. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4456. this.parameterPositions = parameterPositions;
  4457. this._cachedIndex = 0;
  4458. this.resultBuffer = resultBuffer !== undefined ?
  4459. resultBuffer : new sampleValues.constructor( sampleSize );
  4460. this.sampleValues = sampleValues;
  4461. this.valueSize = sampleSize;
  4462. };
  4463. THREE.Interpolant.prototype = {
  4464. constructor: THREE.Interpolant,
  4465. evaluate: function( t ) {
  4466. var pp = this.parameterPositions,
  4467. i1 = this._cachedIndex,
  4468. t1 = pp[ i1 ],
  4469. t0 = pp[ i1 - 1 ];
  4470. validate_interval: {
  4471. seek: {
  4472. var right;
  4473. linear_scan: {
  4474. //- See http://jsperf.com/comparison-to-undefined/3
  4475. //- slower code:
  4476. //-
  4477. //- if ( t >= t1 || t1 === undefined ) {
  4478. forward_scan: if ( ! ( t < t1 ) ) {
  4479. for ( var giveUpAt = i1 + 2; ;) {
  4480. if ( t1 === undefined ) {
  4481. if ( t < t0 ) break forward_scan;
  4482. // after end
  4483. i1 = pp.length;
  4484. this._cachedIndex = i1;
  4485. return this.afterEnd_( i1 - 1, t, t0 );
  4486. }
  4487. if ( i1 === giveUpAt ) break; // this loop
  4488. t0 = t1;
  4489. t1 = pp[ ++ i1 ];
  4490. if ( t < t1 ) {
  4491. // we have arrived at the sought interval
  4492. break seek;
  4493. }
  4494. }
  4495. // prepare binary search on the right side of the index
  4496. right = pp.length;
  4497. break linear_scan;
  4498. }
  4499. //- slower code:
  4500. //- if ( t < t0 || t0 === undefined ) {
  4501. if ( ! ( t >= t0 ) ) {
  4502. // looping?
  4503. var t1global = pp[ 1 ];
  4504. if ( t < t1global ) {
  4505. i1 = 2; // + 1, using the scan for the details
  4506. t0 = t1global;
  4507. }
  4508. // linear reverse scan
  4509. for ( var giveUpAt = i1 - 2; ;) {
  4510. if ( t0 === undefined ) {
  4511. // before start
  4512. this._cachedIndex = 0;
  4513. return this.beforeStart_( 0, t, t1 );
  4514. }
  4515. if ( i1 === giveUpAt ) break; // this loop
  4516. t1 = t0;
  4517. t0 = pp[ -- i1 - 1 ];
  4518. if ( t >= t0 ) {
  4519. // we have arrived at the sought interval
  4520. break seek;
  4521. }
  4522. }
  4523. // prepare binary search on the left side of the index
  4524. right = i1;
  4525. i1 = 0;
  4526. break linear_scan;
  4527. }
  4528. // the interval is valid
  4529. break validate_interval;
  4530. } // linear scan
  4531. // binary search
  4532. while ( i1 < right ) {
  4533. var mid = ( i1 + right ) >>> 1;
  4534. if ( t < pp[ mid ] ) {
  4535. right = mid;
  4536. } else {
  4537. i1 = mid + 1;
  4538. }
  4539. }
  4540. t1 = pp[ i1 ];
  4541. t0 = pp[ i1 - 1 ];
  4542. // check boundary cases, again
  4543. if ( t0 === undefined ) {
  4544. this._cachedIndex = 0;
  4545. return this.beforeStart_( 0, t, t1 );
  4546. }
  4547. if ( t1 === undefined ) {
  4548. i1 = pp.length;
  4549. this._cachedIndex = i1;
  4550. return this.afterEnd_( i1 - 1, t0, t );
  4551. }
  4552. } // seek
  4553. this._cachedIndex = i1;
  4554. this.intervalChanged_( i1, t0, t1 );
  4555. } // validate_interval
  4556. return this.interpolate_( i1, t0, t, t1 );
  4557. },
  4558. settings: null, // optional, subclass-specific settings structure
  4559. // Note: The indirection allows central control of many interpolants.
  4560. // --- Protected interface
  4561. DefaultSettings_: {},
  4562. getSettings_: function() {
  4563. return this.settings || this.DefaultSettings_;
  4564. },
  4565. copySampleValue_: function( index ) {
  4566. // copies a sample value to the result buffer
  4567. var result = this.resultBuffer,
  4568. values = this.sampleValues,
  4569. stride = this.valueSize,
  4570. offset = index * stride;
  4571. for ( var i = 0; i !== stride; ++ i ) {
  4572. result[ i ] = values[ offset + i ];
  4573. }
  4574. return result;
  4575. },
  4576. // Template methods for derived classes:
  4577. interpolate_: function( i1, t0, t, t1 ) {
  4578. throw new Error( "call to abstract method" );
  4579. // implementations shall return this.resultBuffer
  4580. },
  4581. intervalChanged_: function( i1, t0, t1 ) {
  4582. // empty
  4583. }
  4584. };
  4585. Object.assign( THREE.Interpolant.prototype, {
  4586. beforeStart_: //( 0, t, t0 ), returns this.resultBuffer
  4587. THREE.Interpolant.prototype.copySampleValue_,
  4588. afterEnd_: //( N-1, tN-1, t ), returns this.resultBuffer
  4589. THREE.Interpolant.prototype.copySampleValue_
  4590. } );
  4591. // File:src/math/interpolants/CubicInterpolant.js
  4592. /**
  4593. * Fast and simple cubic spline interpolant.
  4594. *
  4595. * It was derived from a Hermitian construction setting the first derivative
  4596. * at each sample position to the linear slope between neighboring positions
  4597. * over their parameter interval.
  4598. *
  4599. * @author tschw
  4600. */
  4601. THREE.CubicInterpolant = function(
  4602. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4603. THREE.Interpolant.call(
  4604. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4605. this._weightPrev = -0;
  4606. this._offsetPrev = -0;
  4607. this._weightNext = -0;
  4608. this._offsetNext = -0;
  4609. };
  4610. THREE.CubicInterpolant.prototype =
  4611. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4612. constructor: THREE.CubicInterpolant,
  4613. DefaultSettings_: {
  4614. endingStart: THREE.ZeroCurvatureEnding,
  4615. endingEnd: THREE.ZeroCurvatureEnding
  4616. },
  4617. intervalChanged_: function( i1, t0, t1 ) {
  4618. var pp = this.parameterPositions,
  4619. iPrev = i1 - 2,
  4620. iNext = i1 + 1,
  4621. tPrev = pp[ iPrev ],
  4622. tNext = pp[ iNext ];
  4623. if ( tPrev === undefined ) {
  4624. switch ( this.getSettings_().endingStart ) {
  4625. case THREE.ZeroSlopeEnding:
  4626. // f'(t0) = 0
  4627. iPrev = i1;
  4628. tPrev = 2 * t0 - t1;
  4629. break;
  4630. case THREE.WrapAroundEnding:
  4631. // use the other end of the curve
  4632. iPrev = pp.length - 2;
  4633. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  4634. break;
  4635. default: // ZeroCurvatureEnding
  4636. // f''(t0) = 0 a.k.a. Natural Spline
  4637. iPrev = i1;
  4638. tPrev = t1;
  4639. }
  4640. }
  4641. if ( tNext === undefined ) {
  4642. switch ( this.getSettings_().endingEnd ) {
  4643. case THREE.ZeroSlopeEnding:
  4644. // f'(tN) = 0
  4645. iNext = i1;
  4646. tNext = 2 * t1 - t0;
  4647. break;
  4648. case THREE.WrapAroundEnding:
  4649. // use the other end of the curve
  4650. iNext = 1;
  4651. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  4652. break;
  4653. default: // ZeroCurvatureEnding
  4654. // f''(tN) = 0, a.k.a. Natural Spline
  4655. iNext = i1 - 1;
  4656. tNext = t0;
  4657. }
  4658. }
  4659. var halfDt = ( t1 - t0 ) * 0.5,
  4660. stride = this.valueSize;
  4661. this._weightPrev = halfDt / ( t0 - tPrev );
  4662. this._weightNext = halfDt / ( tNext - t1 );
  4663. this._offsetPrev = iPrev * stride;
  4664. this._offsetNext = iNext * stride;
  4665. },
  4666. interpolate_: function( i1, t0, t, t1 ) {
  4667. var result = this.resultBuffer,
  4668. values = this.sampleValues,
  4669. stride = this.valueSize,
  4670. o1 = i1 * stride, o0 = o1 - stride,
  4671. oP = this._offsetPrev, oN = this._offsetNext,
  4672. wP = this._weightPrev, wN = this._weightNext,
  4673. p = ( t - t0 ) / ( t1 - t0 ),
  4674. pp = p * p,
  4675. ppp = pp * p;
  4676. // evaluate polynomials
  4677. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  4678. var s0 = ( 1 + wP ) * ppp + (-1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  4679. var s1 = (-1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  4680. var sN = wN * ppp - wN * pp;
  4681. // combine data linearly
  4682. for ( var i = 0; i !== stride; ++ i ) {
  4683. result[ i ] =
  4684. sP * values[ oP + i ] +
  4685. s0 * values[ o0 + i ] +
  4686. s1 * values[ o1 + i ] +
  4687. sN * values[ oN + i ];
  4688. }
  4689. return result;
  4690. }
  4691. } );
  4692. // File:src/math/interpolants/DiscreteInterpolant.js
  4693. /**
  4694. *
  4695. * Interpolant that evaluates to the sample value at the position preceeding
  4696. * the parameter.
  4697. *
  4698. * @author tschw
  4699. */
  4700. THREE.DiscreteInterpolant = function(
  4701. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4702. THREE.Interpolant.call(
  4703. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4704. };
  4705. THREE.DiscreteInterpolant.prototype =
  4706. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4707. constructor: THREE.DiscreteInterpolant,
  4708. interpolate_: function( i1, t0, t, t1 ) {
  4709. return this.copySampleValue_( i1 - 1 );
  4710. }
  4711. } );
  4712. // File:src/math/interpolants/LinearInterpolant.js
  4713. /**
  4714. * @author tschw
  4715. */
  4716. THREE.LinearInterpolant = function(
  4717. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4718. THREE.Interpolant.call(
  4719. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4720. };
  4721. THREE.LinearInterpolant.prototype =
  4722. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4723. constructor: THREE.LinearInterpolant,
  4724. interpolate_: function( i1, t0, t, t1 ) {
  4725. var result = this.resultBuffer,
  4726. values = this.sampleValues,
  4727. stride = this.valueSize,
  4728. offset1 = i1 * stride,
  4729. offset0 = offset1 - stride,
  4730. weight1 = ( t - t0 ) / ( t1 - t0 ),
  4731. weight0 = 1 - weight1;
  4732. for ( var i = 0; i !== stride; ++ i ) {
  4733. result[ i ] =
  4734. values[ offset0 + i ] * weight0 +
  4735. values[ offset1 + i ] * weight1;
  4736. }
  4737. return result;
  4738. }
  4739. } );
  4740. // File:src/math/interpolants/QuaternionLinearInterpolant.js
  4741. /**
  4742. * Spherical linear unit quaternion interpolant.
  4743. *
  4744. * @author tschw
  4745. */
  4746. THREE.QuaternionLinearInterpolant = function(
  4747. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4748. THREE.Interpolant.call(
  4749. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4750. };
  4751. THREE.QuaternionLinearInterpolant.prototype =
  4752. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4753. constructor: THREE.QuaternionLinearInterpolant,
  4754. interpolate_: function( i1, t0, t, t1 ) {
  4755. var result = this.resultBuffer,
  4756. values = this.sampleValues,
  4757. stride = this.valueSize,
  4758. offset = i1 * stride,
  4759. alpha = ( t - t0 ) / ( t1 - t0 );
  4760. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  4761. THREE.Quaternion.slerpFlat( result, 0,
  4762. values, offset - stride, values, offset, alpha );
  4763. }
  4764. return result;
  4765. }
  4766. } );
  4767. // File:src/core/Clock.js
  4768. /**
  4769. * @author alteredq / http://alteredqualia.com/
  4770. */
  4771. THREE.Clock = function ( autoStart ) {
  4772. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4773. this.startTime = 0;
  4774. this.oldTime = 0;
  4775. this.elapsedTime = 0;
  4776. this.running = false;
  4777. };
  4778. THREE.Clock.prototype = {
  4779. constructor: THREE.Clock,
  4780. start: function () {
  4781. this.startTime = performance.now();
  4782. this.oldTime = this.startTime;
  4783. this.running = true;
  4784. },
  4785. stop: function () {
  4786. this.getElapsedTime();
  4787. this.running = false;
  4788. },
  4789. getElapsedTime: function () {
  4790. this.getDelta();
  4791. return this.elapsedTime;
  4792. },
  4793. getDelta: function () {
  4794. var diff = 0;
  4795. if ( this.autoStart && ! this.running ) {
  4796. this.start();
  4797. }
  4798. if ( this.running ) {
  4799. var newTime = performance.now();
  4800. diff = 0.001 * ( newTime - this.oldTime );
  4801. this.oldTime = newTime;
  4802. this.elapsedTime += diff;
  4803. }
  4804. return diff;
  4805. }
  4806. };
  4807. // File:src/core/EventDispatcher.js
  4808. /**
  4809. * https://github.com/mrdoob/eventdispatcher.js/
  4810. */
  4811. THREE.EventDispatcher = function () {};
  4812. THREE.EventDispatcher.prototype = {
  4813. constructor: THREE.EventDispatcher,
  4814. apply: function ( object ) {
  4815. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4816. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4817. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4818. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4819. },
  4820. addEventListener: function ( type, listener ) {
  4821. if ( this._listeners === undefined ) this._listeners = {};
  4822. var listeners = this._listeners;
  4823. if ( listeners[ type ] === undefined ) {
  4824. listeners[ type ] = [];
  4825. }
  4826. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4827. listeners[ type ].push( listener );
  4828. }
  4829. },
  4830. hasEventListener: function ( type, listener ) {
  4831. if ( this._listeners === undefined ) return false;
  4832. var listeners = this._listeners;
  4833. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4834. return true;
  4835. }
  4836. return false;
  4837. },
  4838. removeEventListener: function ( type, listener ) {
  4839. if ( this._listeners === undefined ) return;
  4840. var listeners = this._listeners;
  4841. var listenerArray = listeners[ type ];
  4842. if ( listenerArray !== undefined ) {
  4843. var index = listenerArray.indexOf( listener );
  4844. if ( index !== - 1 ) {
  4845. listenerArray.splice( index, 1 );
  4846. }
  4847. }
  4848. },
  4849. dispatchEvent: function ( event ) {
  4850. if ( this._listeners === undefined ) return;
  4851. var listeners = this._listeners;
  4852. var listenerArray = listeners[ event.type ];
  4853. if ( listenerArray !== undefined ) {
  4854. event.target = this;
  4855. var array = [];
  4856. var length = listenerArray.length;
  4857. for ( var i = 0; i < length; i ++ ) {
  4858. array[ i ] = listenerArray[ i ];
  4859. }
  4860. for ( var i = 0; i < length; i ++ ) {
  4861. array[ i ].call( this, event );
  4862. }
  4863. }
  4864. }
  4865. };
  4866. // File:src/core/Layers.js
  4867. /**
  4868. * @author mrdoob / http://mrdoob.com/
  4869. */
  4870. THREE.Layers = function () {
  4871. this.mask = 1;
  4872. };
  4873. THREE.Layers.prototype = {
  4874. constructor: THREE.Layers,
  4875. set: function ( channel ) {
  4876. this.mask = 1 << channel;
  4877. },
  4878. enable: function ( channel ) {
  4879. this.mask |= 1 << channel;
  4880. },
  4881. toggle: function ( channel ) {
  4882. this.mask ^= 1 << channel;
  4883. },
  4884. disable: function ( channel ) {
  4885. this.mask &= ~ ( 1 << channel );
  4886. },
  4887. test: function ( layers ) {
  4888. return ( this.mask & layers.mask ) !== 0;
  4889. }
  4890. };
  4891. // File:src/core/Raycaster.js
  4892. /**
  4893. * @author mrdoob / http://mrdoob.com/
  4894. * @author bhouston / http://clara.io/
  4895. * @author stephomi / http://stephaneginier.com/
  4896. */
  4897. ( function ( THREE ) {
  4898. THREE.Raycaster = function ( origin, direction, near, far ) {
  4899. this.ray = new THREE.Ray( origin, direction );
  4900. // direction is assumed to be normalized (for accurate distance calculations)
  4901. this.near = near || 0;
  4902. this.far = far || Infinity;
  4903. this.params = {
  4904. Mesh: {},
  4905. Line: {},
  4906. LOD: {},
  4907. Points: { threshold: 1 },
  4908. Sprite: {}
  4909. };
  4910. Object.defineProperties( this.params, {
  4911. PointCloud: {
  4912. get: function () {
  4913. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4914. return this.Points;
  4915. }
  4916. }
  4917. } );
  4918. };
  4919. function ascSort( a, b ) {
  4920. return a.distance - b.distance;
  4921. }
  4922. function intersectObject( object, raycaster, intersects, recursive ) {
  4923. if ( object.visible === false ) return;
  4924. object.raycast( raycaster, intersects );
  4925. if ( recursive === true ) {
  4926. var children = object.children;
  4927. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4928. intersectObject( children[ i ], raycaster, intersects, true );
  4929. }
  4930. }
  4931. }
  4932. //
  4933. THREE.Raycaster.prototype = {
  4934. constructor: THREE.Raycaster,
  4935. linePrecision: 1,
  4936. set: function ( origin, direction ) {
  4937. // direction is assumed to be normalized (for accurate distance calculations)
  4938. this.ray.set( origin, direction );
  4939. },
  4940. setFromCamera: function ( coords, camera ) {
  4941. if ( camera instanceof THREE.PerspectiveCamera ) {
  4942. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4943. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4944. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4945. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4946. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4947. } else {
  4948. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4949. }
  4950. },
  4951. intersectObject: function ( object, recursive ) {
  4952. var intersects = [];
  4953. intersectObject( object, this, intersects, recursive );
  4954. intersects.sort( ascSort );
  4955. return intersects;
  4956. },
  4957. intersectObjects: function ( objects, recursive ) {
  4958. var intersects = [];
  4959. if ( Array.isArray( objects ) === false ) {
  4960. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4961. return intersects;
  4962. }
  4963. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4964. intersectObject( objects[ i ], this, intersects, recursive );
  4965. }
  4966. intersects.sort( ascSort );
  4967. return intersects;
  4968. }
  4969. };
  4970. }( THREE ) );
  4971. // File:src/core/Object3D.js
  4972. /**
  4973. * @author mrdoob / http://mrdoob.com/
  4974. * @author mikael emtinger / http://gomo.se/
  4975. * @author alteredq / http://alteredqualia.com/
  4976. * @author WestLangley / http://github.com/WestLangley
  4977. * @author elephantatwork / www.elephantatwork.ch
  4978. */
  4979. THREE.Object3D = function () {
  4980. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4981. this.uuid = THREE.Math.generateUUID();
  4982. this.name = '';
  4983. this.type = 'Object3D';
  4984. this.parent = null;
  4985. this.children = [];
  4986. this.up = THREE.Object3D.DefaultUp.clone();
  4987. var position = new THREE.Vector3();
  4988. var rotation = new THREE.Euler();
  4989. var quaternion = new THREE.Quaternion();
  4990. var scale = new THREE.Vector3( 1, 1, 1 );
  4991. function onRotationChange() {
  4992. quaternion.setFromEuler( rotation, false );
  4993. }
  4994. function onQuaternionChange() {
  4995. rotation.setFromQuaternion( quaternion, undefined, false );
  4996. }
  4997. rotation.onChange( onRotationChange );
  4998. quaternion.onChange( onQuaternionChange );
  4999. Object.defineProperties( this, {
  5000. position: {
  5001. enumerable: true,
  5002. value: position
  5003. },
  5004. rotation: {
  5005. enumerable: true,
  5006. value: rotation
  5007. },
  5008. quaternion: {
  5009. enumerable: true,
  5010. value: quaternion
  5011. },
  5012. scale: {
  5013. enumerable: true,
  5014. value: scale
  5015. },
  5016. modelViewMatrix: {
  5017. value: new THREE.Matrix4()
  5018. },
  5019. normalMatrix: {
  5020. value: new THREE.Matrix3()
  5021. }
  5022. } );
  5023. this.rotationAutoUpdate = true;
  5024. this.matrix = new THREE.Matrix4();
  5025. this.matrixWorld = new THREE.Matrix4();
  5026. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  5027. this.matrixWorldNeedsUpdate = false;
  5028. this.layers = new THREE.Layers();
  5029. this.visible = true;
  5030. this.castShadow = false;
  5031. this.receiveShadow = false;
  5032. this.frustumCulled = true;
  5033. this.renderOrder = 0;
  5034. this.userData = {};
  5035. };
  5036. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  5037. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  5038. THREE.Object3D.prototype = {
  5039. constructor: THREE.Object3D,
  5040. applyMatrix: function ( matrix ) {
  5041. this.matrix.multiplyMatrices( matrix, this.matrix );
  5042. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5043. },
  5044. setRotationFromAxisAngle: function ( axis, angle ) {
  5045. // assumes axis is normalized
  5046. this.quaternion.setFromAxisAngle( axis, angle );
  5047. },
  5048. setRotationFromEuler: function ( euler ) {
  5049. this.quaternion.setFromEuler( euler, true );
  5050. },
  5051. setRotationFromMatrix: function ( m ) {
  5052. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5053. this.quaternion.setFromRotationMatrix( m );
  5054. },
  5055. setRotationFromQuaternion: function ( q ) {
  5056. // assumes q is normalized
  5057. this.quaternion.copy( q );
  5058. },
  5059. rotateOnAxis: function () {
  5060. // rotate object on axis in object space
  5061. // axis is assumed to be normalized
  5062. var q1 = new THREE.Quaternion();
  5063. return function ( axis, angle ) {
  5064. q1.setFromAxisAngle( axis, angle );
  5065. this.quaternion.multiply( q1 );
  5066. return this;
  5067. };
  5068. }(),
  5069. rotateX: function () {
  5070. var v1 = new THREE.Vector3( 1, 0, 0 );
  5071. return function ( angle ) {
  5072. return this.rotateOnAxis( v1, angle );
  5073. };
  5074. }(),
  5075. rotateY: function () {
  5076. var v1 = new THREE.Vector3( 0, 1, 0 );
  5077. return function ( angle ) {
  5078. return this.rotateOnAxis( v1, angle );
  5079. };
  5080. }(),
  5081. rotateZ: function () {
  5082. var v1 = new THREE.Vector3( 0, 0, 1 );
  5083. return function ( angle ) {
  5084. return this.rotateOnAxis( v1, angle );
  5085. };
  5086. }(),
  5087. translateOnAxis: function () {
  5088. // translate object by distance along axis in object space
  5089. // axis is assumed to be normalized
  5090. var v1 = new THREE.Vector3();
  5091. return function ( axis, distance ) {
  5092. v1.copy( axis ).applyQuaternion( this.quaternion );
  5093. this.position.add( v1.multiplyScalar( distance ) );
  5094. return this;
  5095. };
  5096. }(),
  5097. translateX: function () {
  5098. var v1 = new THREE.Vector3( 1, 0, 0 );
  5099. return function ( distance ) {
  5100. return this.translateOnAxis( v1, distance );
  5101. };
  5102. }(),
  5103. translateY: function () {
  5104. var v1 = new THREE.Vector3( 0, 1, 0 );
  5105. return function ( distance ) {
  5106. return this.translateOnAxis( v1, distance );
  5107. };
  5108. }(),
  5109. translateZ: function () {
  5110. var v1 = new THREE.Vector3( 0, 0, 1 );
  5111. return function ( distance ) {
  5112. return this.translateOnAxis( v1, distance );
  5113. };
  5114. }(),
  5115. localToWorld: function ( vector ) {
  5116. return vector.applyMatrix4( this.matrixWorld );
  5117. },
  5118. worldToLocal: function () {
  5119. var m1 = new THREE.Matrix4();
  5120. return function ( vector ) {
  5121. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5122. };
  5123. }(),
  5124. lookAt: function () {
  5125. // This routine does not support objects with rotated and/or translated parent(s)
  5126. var m1 = new THREE.Matrix4();
  5127. return function ( vector ) {
  5128. m1.lookAt( vector, this.position, this.up );
  5129. this.quaternion.setFromRotationMatrix( m1 );
  5130. };
  5131. }(),
  5132. add: function ( object ) {
  5133. if ( arguments.length > 1 ) {
  5134. for ( var i = 0; i < arguments.length; i ++ ) {
  5135. this.add( arguments[ i ] );
  5136. }
  5137. return this;
  5138. }
  5139. if ( object === this ) {
  5140. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5141. return this;
  5142. }
  5143. if ( object instanceof THREE.Object3D ) {
  5144. if ( object.parent !== null ) {
  5145. object.parent.remove( object );
  5146. }
  5147. object.parent = this;
  5148. object.dispatchEvent( { type: 'added' } );
  5149. this.children.push( object );
  5150. } else {
  5151. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5152. }
  5153. return this;
  5154. },
  5155. remove: function ( object ) {
  5156. if ( arguments.length > 1 ) {
  5157. for ( var i = 0; i < arguments.length; i ++ ) {
  5158. this.remove( arguments[ i ] );
  5159. }
  5160. }
  5161. var index = this.children.indexOf( object );
  5162. if ( index !== - 1 ) {
  5163. object.parent = null;
  5164. object.dispatchEvent( { type: 'removed' } );
  5165. this.children.splice( index, 1 );
  5166. }
  5167. },
  5168. getObjectById: function ( id ) {
  5169. return this.getObjectByProperty( 'id', id );
  5170. },
  5171. getObjectByName: function ( name ) {
  5172. return this.getObjectByProperty( 'name', name );
  5173. },
  5174. getObjectByProperty: function ( name, value ) {
  5175. if ( this[ name ] === value ) return this;
  5176. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5177. var child = this.children[ i ];
  5178. var object = child.getObjectByProperty( name, value );
  5179. if ( object !== undefined ) {
  5180. return object;
  5181. }
  5182. }
  5183. return undefined;
  5184. },
  5185. getWorldPosition: function ( optionalTarget ) {
  5186. var result = optionalTarget || new THREE.Vector3();
  5187. this.updateMatrixWorld( true );
  5188. return result.setFromMatrixPosition( this.matrixWorld );
  5189. },
  5190. getWorldQuaternion: function () {
  5191. var position = new THREE.Vector3();
  5192. var scale = new THREE.Vector3();
  5193. return function ( optionalTarget ) {
  5194. var result = optionalTarget || new THREE.Quaternion();
  5195. this.updateMatrixWorld( true );
  5196. this.matrixWorld.decompose( position, result, scale );
  5197. return result;
  5198. };
  5199. }(),
  5200. getWorldRotation: function () {
  5201. var quaternion = new THREE.Quaternion();
  5202. return function ( optionalTarget ) {
  5203. var result = optionalTarget || new THREE.Euler();
  5204. this.getWorldQuaternion( quaternion );
  5205. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5206. };
  5207. }(),
  5208. getWorldScale: function () {
  5209. var position = new THREE.Vector3();
  5210. var quaternion = new THREE.Quaternion();
  5211. return function ( optionalTarget ) {
  5212. var result = optionalTarget || new THREE.Vector3();
  5213. this.updateMatrixWorld( true );
  5214. this.matrixWorld.decompose( position, quaternion, result );
  5215. return result;
  5216. };
  5217. }(),
  5218. getWorldDirection: function () {
  5219. var quaternion = new THREE.Quaternion();
  5220. return function ( optionalTarget ) {
  5221. var result = optionalTarget || new THREE.Vector3();
  5222. this.getWorldQuaternion( quaternion );
  5223. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5224. };
  5225. }(),
  5226. raycast: function () {},
  5227. traverse: function ( callback ) {
  5228. callback( this );
  5229. var children = this.children;
  5230. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5231. children[ i ].traverse( callback );
  5232. }
  5233. },
  5234. traverseVisible: function ( callback ) {
  5235. if ( this.visible === false ) return;
  5236. callback( this );
  5237. var children = this.children;
  5238. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5239. children[ i ].traverseVisible( callback );
  5240. }
  5241. },
  5242. traverseAncestors: function ( callback ) {
  5243. var parent = this.parent;
  5244. if ( parent !== null ) {
  5245. callback( parent );
  5246. parent.traverseAncestors( callback );
  5247. }
  5248. },
  5249. updateMatrix: function () {
  5250. this.matrix.compose( this.position, this.quaternion, this.scale );
  5251. this.matrixWorldNeedsUpdate = true;
  5252. },
  5253. updateMatrixWorld: function ( force ) {
  5254. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  5255. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  5256. if ( this.parent === null ) {
  5257. this.matrixWorld.copy( this.matrix );
  5258. } else {
  5259. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5260. }
  5261. this.matrixWorldNeedsUpdate = false;
  5262. force = true;
  5263. }
  5264. // update children
  5265. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5266. this.children[ i ].updateMatrixWorld( force );
  5267. }
  5268. },
  5269. toJSON: function ( meta ) {
  5270. var isRootObject = ( meta === undefined );
  5271. var output = {};
  5272. // meta is a hash used to collect geometries, materials.
  5273. // not providing it implies that this is the root object
  5274. // being serialized.
  5275. if ( isRootObject ) {
  5276. // initialize meta obj
  5277. meta = {
  5278. geometries: {},
  5279. materials: {},
  5280. textures: {},
  5281. images: {}
  5282. };
  5283. output.metadata = {
  5284. version: 4.4,
  5285. type: 'Object',
  5286. generator: 'Object3D.toJSON'
  5287. };
  5288. }
  5289. // standard Object3D serialization
  5290. var object = {};
  5291. object.uuid = this.uuid;
  5292. object.type = this.type;
  5293. if ( this.name !== '' ) object.name = this.name;
  5294. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5295. if ( this.castShadow === true ) object.castShadow = true;
  5296. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5297. if ( this.visible === false ) object.visible = false;
  5298. object.matrix = this.matrix.toArray();
  5299. //
  5300. if ( this.geometry !== undefined ) {
  5301. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  5302. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  5303. }
  5304. object.geometry = this.geometry.uuid;
  5305. }
  5306. if ( this.material !== undefined ) {
  5307. if ( meta.materials[ this.material.uuid ] === undefined ) {
  5308. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  5309. }
  5310. object.material = this.material.uuid;
  5311. }
  5312. //
  5313. if ( this.children.length > 0 ) {
  5314. object.children = [];
  5315. for ( var i = 0; i < this.children.length; i ++ ) {
  5316. object.children.push( this.children[ i ].toJSON( meta ).object );
  5317. }
  5318. }
  5319. if ( isRootObject ) {
  5320. var geometries = extractFromCache( meta.geometries );
  5321. var materials = extractFromCache( meta.materials );
  5322. var textures = extractFromCache( meta.textures );
  5323. var images = extractFromCache( meta.images );
  5324. if ( geometries.length > 0 ) output.geometries = geometries;
  5325. if ( materials.length > 0 ) output.materials = materials;
  5326. if ( textures.length > 0 ) output.textures = textures;
  5327. if ( images.length > 0 ) output.images = images;
  5328. }
  5329. output.object = object;
  5330. return output;
  5331. // extract data from the cache hash
  5332. // remove metadata on each item
  5333. // and return as array
  5334. function extractFromCache ( cache ) {
  5335. var values = [];
  5336. for ( var key in cache ) {
  5337. var data = cache[ key ];
  5338. delete data.metadata;
  5339. values.push( data );
  5340. }
  5341. return values;
  5342. }
  5343. },
  5344. clone: function ( recursive ) {
  5345. return new this.constructor().copy( this, recursive );
  5346. },
  5347. copy: function ( source, recursive ) {
  5348. if ( recursive === undefined ) recursive = true;
  5349. this.name = source.name;
  5350. this.up.copy( source.up );
  5351. this.position.copy( source.position );
  5352. this.quaternion.copy( source.quaternion );
  5353. this.scale.copy( source.scale );
  5354. this.rotationAutoUpdate = source.rotationAutoUpdate;
  5355. this.matrix.copy( source.matrix );
  5356. this.matrixWorld.copy( source.matrixWorld );
  5357. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5358. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5359. this.visible = source.visible;
  5360. this.castShadow = source.castShadow;
  5361. this.receiveShadow = source.receiveShadow;
  5362. this.frustumCulled = source.frustumCulled;
  5363. this.renderOrder = source.renderOrder;
  5364. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5365. if ( recursive === true ) {
  5366. for ( var i = 0; i < source.children.length; i ++ ) {
  5367. var child = source.children[ i ];
  5368. this.add( child.clone() );
  5369. }
  5370. }
  5371. return this;
  5372. }
  5373. };
  5374. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  5375. THREE.Object3DIdCount = 0;
  5376. // File:src/core/Face3.js
  5377. /**
  5378. * @author mrdoob / http://mrdoob.com/
  5379. * @author alteredq / http://alteredqualia.com/
  5380. */
  5381. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  5382. this.a = a;
  5383. this.b = b;
  5384. this.c = c;
  5385. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  5386. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5387. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  5388. this.vertexColors = Array.isArray( color ) ? color : [];
  5389. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5390. };
  5391. THREE.Face3.prototype = {
  5392. constructor: THREE.Face3,
  5393. clone: function () {
  5394. return new this.constructor().copy( this );
  5395. },
  5396. copy: function ( source ) {
  5397. this.a = source.a;
  5398. this.b = source.b;
  5399. this.c = source.c;
  5400. this.normal.copy( source.normal );
  5401. this.color.copy( source.color );
  5402. this.materialIndex = source.materialIndex;
  5403. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5404. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5405. }
  5406. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5407. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5408. }
  5409. return this;
  5410. }
  5411. };
  5412. // File:src/core/BufferAttribute.js
  5413. /**
  5414. * @author mrdoob / http://mrdoob.com/
  5415. */
  5416. THREE.BufferAttribute = function ( array, itemSize ) {
  5417. this.uuid = THREE.Math.generateUUID();
  5418. this.array = array;
  5419. this.itemSize = itemSize;
  5420. this.dynamic = false;
  5421. this.updateRange = { offset: 0, count: - 1 };
  5422. this.version = 0;
  5423. };
  5424. THREE.BufferAttribute.prototype = {
  5425. constructor: THREE.BufferAttribute,
  5426. get count() {
  5427. return this.array.length / this.itemSize;
  5428. },
  5429. set needsUpdate( value ) {
  5430. if ( value === true ) this.version ++;
  5431. },
  5432. setDynamic: function ( value ) {
  5433. this.dynamic = value;
  5434. return this;
  5435. },
  5436. copy: function ( source ) {
  5437. this.array = new source.array.constructor( source.array );
  5438. this.itemSize = source.itemSize;
  5439. this.dynamic = source.dynamic;
  5440. return this;
  5441. },
  5442. copyAt: function ( index1, attribute, index2 ) {
  5443. index1 *= this.itemSize;
  5444. index2 *= attribute.itemSize;
  5445. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5446. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5447. }
  5448. return this;
  5449. },
  5450. copyArray: function ( array ) {
  5451. this.array.set( array );
  5452. return this;
  5453. },
  5454. copyColorsArray: function ( colors ) {
  5455. var array = this.array, offset = 0;
  5456. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5457. var color = colors[ i ];
  5458. if ( color === undefined ) {
  5459. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5460. color = new THREE.Color();
  5461. }
  5462. array[ offset ++ ] = color.r;
  5463. array[ offset ++ ] = color.g;
  5464. array[ offset ++ ] = color.b;
  5465. }
  5466. return this;
  5467. },
  5468. copyIndicesArray: function ( indices ) {
  5469. var array = this.array, offset = 0;
  5470. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5471. var index = indices[ i ];
  5472. array[ offset ++ ] = index.a;
  5473. array[ offset ++ ] = index.b;
  5474. array[ offset ++ ] = index.c;
  5475. }
  5476. return this;
  5477. },
  5478. copyVector2sArray: function ( vectors ) {
  5479. var array = this.array, offset = 0;
  5480. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5481. var vector = vectors[ i ];
  5482. if ( vector === undefined ) {
  5483. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5484. vector = new THREE.Vector2();
  5485. }
  5486. array[ offset ++ ] = vector.x;
  5487. array[ offset ++ ] = vector.y;
  5488. }
  5489. return this;
  5490. },
  5491. copyVector3sArray: function ( vectors ) {
  5492. var array = this.array, offset = 0;
  5493. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5494. var vector = vectors[ i ];
  5495. if ( vector === undefined ) {
  5496. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5497. vector = new THREE.Vector3();
  5498. }
  5499. array[ offset ++ ] = vector.x;
  5500. array[ offset ++ ] = vector.y;
  5501. array[ offset ++ ] = vector.z;
  5502. }
  5503. return this;
  5504. },
  5505. copyVector4sArray: function ( vectors ) {
  5506. var array = this.array, offset = 0;
  5507. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5508. var vector = vectors[ i ];
  5509. if ( vector === undefined ) {
  5510. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5511. vector = new THREE.Vector4();
  5512. }
  5513. array[ offset ++ ] = vector.x;
  5514. array[ offset ++ ] = vector.y;
  5515. array[ offset ++ ] = vector.z;
  5516. array[ offset ++ ] = vector.w;
  5517. }
  5518. return this;
  5519. },
  5520. set: function ( value, offset ) {
  5521. if ( offset === undefined ) offset = 0;
  5522. this.array.set( value, offset );
  5523. return this;
  5524. },
  5525. getX: function ( index ) {
  5526. return this.array[ index * this.itemSize ];
  5527. },
  5528. setX: function ( index, x ) {
  5529. this.array[ index * this.itemSize ] = x;
  5530. return this;
  5531. },
  5532. getY: function ( index ) {
  5533. return this.array[ index * this.itemSize + 1 ];
  5534. },
  5535. setY: function ( index, y ) {
  5536. this.array[ index * this.itemSize + 1 ] = y;
  5537. return this;
  5538. },
  5539. getZ: function ( index ) {
  5540. return this.array[ index * this.itemSize + 2 ];
  5541. },
  5542. setZ: function ( index, z ) {
  5543. this.array[ index * this.itemSize + 2 ] = z;
  5544. return this;
  5545. },
  5546. getW: function ( index ) {
  5547. return this.array[ index * this.itemSize + 3 ];
  5548. },
  5549. setW: function ( index, w ) {
  5550. this.array[ index * this.itemSize + 3 ] = w;
  5551. return this;
  5552. },
  5553. setXY: function ( index, x, y ) {
  5554. index *= this.itemSize;
  5555. this.array[ index + 0 ] = x;
  5556. this.array[ index + 1 ] = y;
  5557. return this;
  5558. },
  5559. setXYZ: function ( index, x, y, z ) {
  5560. index *= this.itemSize;
  5561. this.array[ index + 0 ] = x;
  5562. this.array[ index + 1 ] = y;
  5563. this.array[ index + 2 ] = z;
  5564. return this;
  5565. },
  5566. setXYZW: function ( index, x, y, z, w ) {
  5567. index *= this.itemSize;
  5568. this.array[ index + 0 ] = x;
  5569. this.array[ index + 1 ] = y;
  5570. this.array[ index + 2 ] = z;
  5571. this.array[ index + 3 ] = w;
  5572. return this;
  5573. },
  5574. clone: function () {
  5575. return new this.constructor().copy( this );
  5576. }
  5577. };
  5578. //
  5579. THREE.Int8Attribute = function ( array, itemSize ) {
  5580. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5581. };
  5582. THREE.Uint8Attribute = function ( array, itemSize ) {
  5583. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5584. };
  5585. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5586. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5587. };
  5588. THREE.Int16Attribute = function ( array, itemSize ) {
  5589. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5590. };
  5591. THREE.Uint16Attribute = function ( array, itemSize ) {
  5592. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5593. };
  5594. THREE.Int32Attribute = function ( array, itemSize ) {
  5595. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5596. };
  5597. THREE.Uint32Attribute = function ( array, itemSize ) {
  5598. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5599. };
  5600. THREE.Float32Attribute = function ( array, itemSize ) {
  5601. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5602. };
  5603. THREE.Float64Attribute = function ( array, itemSize ) {
  5604. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5605. };
  5606. // Deprecated
  5607. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5608. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5609. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5610. };
  5611. // File:src/core/InstancedBufferAttribute.js
  5612. /**
  5613. * @author benaadams / https://twitter.com/ben_a_adams
  5614. */
  5615. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5616. THREE.BufferAttribute.call( this, array, itemSize );
  5617. this.meshPerAttribute = meshPerAttribute || 1;
  5618. };
  5619. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5620. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5621. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5622. THREE.BufferAttribute.prototype.copy.call( this, source );
  5623. this.meshPerAttribute = source.meshPerAttribute;
  5624. return this;
  5625. };
  5626. // File:src/core/InterleavedBuffer.js
  5627. /**
  5628. * @author benaadams / https://twitter.com/ben_a_adams
  5629. */
  5630. THREE.InterleavedBuffer = function ( array, stride ) {
  5631. this.uuid = THREE.Math.generateUUID();
  5632. this.array = array;
  5633. this.stride = stride;
  5634. this.dynamic = false;
  5635. this.updateRange = { offset: 0, count: - 1 };
  5636. this.version = 0;
  5637. };
  5638. THREE.InterleavedBuffer.prototype = {
  5639. constructor: THREE.InterleavedBuffer,
  5640. get length () {
  5641. return this.array.length;
  5642. },
  5643. get count () {
  5644. return this.array.length / this.stride;
  5645. },
  5646. set needsUpdate( value ) {
  5647. if ( value === true ) this.version ++;
  5648. },
  5649. setDynamic: function ( value ) {
  5650. this.dynamic = value;
  5651. return this;
  5652. },
  5653. copy: function ( source ) {
  5654. this.array = new source.array.constructor( source.array );
  5655. this.stride = source.stride;
  5656. this.dynamic = source.dynamic;
  5657. return this;
  5658. },
  5659. copyAt: function ( index1, attribute, index2 ) {
  5660. index1 *= this.stride;
  5661. index2 *= attribute.stride;
  5662. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5663. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5664. }
  5665. return this;
  5666. },
  5667. set: function ( value, offset ) {
  5668. if ( offset === undefined ) offset = 0;
  5669. this.array.set( value, offset );
  5670. return this;
  5671. },
  5672. clone: function () {
  5673. return new this.constructor().copy( this );
  5674. }
  5675. };
  5676. // File:src/core/InstancedInterleavedBuffer.js
  5677. /**
  5678. * @author benaadams / https://twitter.com/ben_a_adams
  5679. */
  5680. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5681. THREE.InterleavedBuffer.call( this, array, stride );
  5682. this.meshPerAttribute = meshPerAttribute || 1;
  5683. };
  5684. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5685. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5686. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5687. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5688. this.meshPerAttribute = source.meshPerAttribute;
  5689. return this;
  5690. };
  5691. // File:src/core/InterleavedBufferAttribute.js
  5692. /**
  5693. * @author benaadams / https://twitter.com/ben_a_adams
  5694. */
  5695. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5696. this.uuid = THREE.Math.generateUUID();
  5697. this.data = interleavedBuffer;
  5698. this.itemSize = itemSize;
  5699. this.offset = offset;
  5700. };
  5701. THREE.InterleavedBufferAttribute.prototype = {
  5702. constructor: THREE.InterleavedBufferAttribute,
  5703. get length() {
  5704. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5705. return this.array.length;
  5706. },
  5707. get count() {
  5708. return this.data.count;
  5709. },
  5710. setX: function ( index, x ) {
  5711. this.data.array[ index * this.data.stride + this.offset ] = x;
  5712. return this;
  5713. },
  5714. setY: function ( index, y ) {
  5715. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5716. return this;
  5717. },
  5718. setZ: function ( index, z ) {
  5719. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5720. return this;
  5721. },
  5722. setW: function ( index, w ) {
  5723. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5724. return this;
  5725. },
  5726. getX: function ( index ) {
  5727. return this.data.array[ index * this.data.stride + this.offset ];
  5728. },
  5729. getY: function ( index ) {
  5730. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5731. },
  5732. getZ: function ( index ) {
  5733. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5734. },
  5735. getW: function ( index ) {
  5736. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5737. },
  5738. setXY: function ( index, x, y ) {
  5739. index = index * this.data.stride + this.offset;
  5740. this.data.array[ index + 0 ] = x;
  5741. this.data.array[ index + 1 ] = y;
  5742. return this;
  5743. },
  5744. setXYZ: function ( index, x, y, z ) {
  5745. index = index * this.data.stride + this.offset;
  5746. this.data.array[ index + 0 ] = x;
  5747. this.data.array[ index + 1 ] = y;
  5748. this.data.array[ index + 2 ] = z;
  5749. return this;
  5750. },
  5751. setXYZW: function ( index, x, y, z, w ) {
  5752. index = index * this.data.stride + this.offset;
  5753. this.data.array[ index + 0 ] = x;
  5754. this.data.array[ index + 1 ] = y;
  5755. this.data.array[ index + 2 ] = z;
  5756. this.data.array[ index + 3 ] = w;
  5757. return this;
  5758. }
  5759. };
  5760. // File:src/core/Geometry.js
  5761. /**
  5762. * @author mrdoob / http://mrdoob.com/
  5763. * @author kile / http://kile.stravaganza.org/
  5764. * @author alteredq / http://alteredqualia.com/
  5765. * @author mikael emtinger / http://gomo.se/
  5766. * @author zz85 / http://www.lab4games.net/zz85/blog
  5767. * @author bhouston / http://clara.io
  5768. */
  5769. THREE.Geometry = function () {
  5770. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5771. this.uuid = THREE.Math.generateUUID();
  5772. this.name = '';
  5773. this.type = 'Geometry';
  5774. this.vertices = [];
  5775. this.colors = [];
  5776. this.faces = [];
  5777. this.faceVertexUvs = [ [] ];
  5778. this.morphTargets = [];
  5779. this.morphNormals = [];
  5780. this.skinWeights = [];
  5781. this.skinIndices = [];
  5782. this.lineDistances = [];
  5783. this.boundingBox = null;
  5784. this.boundingSphere = null;
  5785. // update flags
  5786. this.verticesNeedUpdate = false;
  5787. this.elementsNeedUpdate = false;
  5788. this.uvsNeedUpdate = false;
  5789. this.normalsNeedUpdate = false;
  5790. this.colorsNeedUpdate = false;
  5791. this.lineDistancesNeedUpdate = false;
  5792. this.groupsNeedUpdate = false;
  5793. };
  5794. THREE.Geometry.prototype = {
  5795. constructor: THREE.Geometry,
  5796. applyMatrix: function ( matrix ) {
  5797. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5798. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5799. var vertex = this.vertices[ i ];
  5800. vertex.applyMatrix4( matrix );
  5801. }
  5802. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5803. var face = this.faces[ i ];
  5804. face.normal.applyMatrix3( normalMatrix ).normalize();
  5805. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5806. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5807. }
  5808. }
  5809. if ( this.boundingBox !== null ) {
  5810. this.computeBoundingBox();
  5811. }
  5812. if ( this.boundingSphere !== null ) {
  5813. this.computeBoundingSphere();
  5814. }
  5815. this.verticesNeedUpdate = true;
  5816. this.normalsNeedUpdate = true;
  5817. return this;
  5818. },
  5819. rotateX: function () {
  5820. // rotate geometry around world x-axis
  5821. var m1;
  5822. return function rotateX( angle ) {
  5823. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5824. m1.makeRotationX( angle );
  5825. this.applyMatrix( m1 );
  5826. return this;
  5827. };
  5828. }(),
  5829. rotateY: function () {
  5830. // rotate geometry around world y-axis
  5831. var m1;
  5832. return function rotateY( angle ) {
  5833. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5834. m1.makeRotationY( angle );
  5835. this.applyMatrix( m1 );
  5836. return this;
  5837. };
  5838. }(),
  5839. rotateZ: function () {
  5840. // rotate geometry around world z-axis
  5841. var m1;
  5842. return function rotateZ( angle ) {
  5843. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5844. m1.makeRotationZ( angle );
  5845. this.applyMatrix( m1 );
  5846. return this;
  5847. };
  5848. }(),
  5849. translate: function () {
  5850. // translate geometry
  5851. var m1;
  5852. return function translate( x, y, z ) {
  5853. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5854. m1.makeTranslation( x, y, z );
  5855. this.applyMatrix( m1 );
  5856. return this;
  5857. };
  5858. }(),
  5859. scale: function () {
  5860. // scale geometry
  5861. var m1;
  5862. return function scale( x, y, z ) {
  5863. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5864. m1.makeScale( x, y, z );
  5865. this.applyMatrix( m1 );
  5866. return this;
  5867. };
  5868. }(),
  5869. lookAt: function () {
  5870. var obj;
  5871. return function lookAt( vector ) {
  5872. if ( obj === undefined ) obj = new THREE.Object3D();
  5873. obj.lookAt( vector );
  5874. obj.updateMatrix();
  5875. this.applyMatrix( obj.matrix );
  5876. };
  5877. }(),
  5878. fromBufferGeometry: function ( geometry ) {
  5879. var scope = this;
  5880. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5881. var attributes = geometry.attributes;
  5882. var positions = attributes.position.array;
  5883. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5884. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5885. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5886. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5887. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5888. var tempNormals = [];
  5889. var tempUVs = [];
  5890. var tempUVs2 = [];
  5891. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5892. scope.vertices.push( new THREE.Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  5893. if ( normals !== undefined ) {
  5894. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5895. }
  5896. if ( colors !== undefined ) {
  5897. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5898. }
  5899. if ( uvs !== undefined ) {
  5900. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5901. }
  5902. if ( uvs2 !== undefined ) {
  5903. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5904. }
  5905. }
  5906. function addFace( a, b, c, materialIndex ) {
  5907. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5908. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5909. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5910. scope.faces.push( face );
  5911. if ( uvs !== undefined ) {
  5912. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5913. }
  5914. if ( uvs2 !== undefined ) {
  5915. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5916. }
  5917. }
  5918. if ( indices !== undefined ) {
  5919. var groups = geometry.groups;
  5920. if ( groups.length > 0 ) {
  5921. for ( var i = 0; i < groups.length; i ++ ) {
  5922. var group = groups[ i ];
  5923. var start = group.start;
  5924. var count = group.count;
  5925. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5926. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5927. }
  5928. }
  5929. } else {
  5930. for ( var i = 0; i < indices.length; i += 3 ) {
  5931. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5932. }
  5933. }
  5934. } else {
  5935. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5936. addFace( i, i + 1, i + 2 );
  5937. }
  5938. }
  5939. this.computeFaceNormals();
  5940. if ( geometry.boundingBox !== null ) {
  5941. this.boundingBox = geometry.boundingBox.clone();
  5942. }
  5943. if ( geometry.boundingSphere !== null ) {
  5944. this.boundingSphere = geometry.boundingSphere.clone();
  5945. }
  5946. return this;
  5947. },
  5948. center: function () {
  5949. this.computeBoundingBox();
  5950. var offset = this.boundingBox.center().negate();
  5951. this.translate( offset.x, offset.y, offset.z );
  5952. return offset;
  5953. },
  5954. normalize: function () {
  5955. this.computeBoundingSphere();
  5956. var center = this.boundingSphere.center;
  5957. var radius = this.boundingSphere.radius;
  5958. var s = radius === 0 ? 1 : 1.0 / radius;
  5959. var matrix = new THREE.Matrix4();
  5960. matrix.set(
  5961. s, 0, 0, - s * center.x,
  5962. 0, s, 0, - s * center.y,
  5963. 0, 0, s, - s * center.z,
  5964. 0, 0, 0, 1
  5965. );
  5966. this.applyMatrix( matrix );
  5967. return this;
  5968. },
  5969. computeFaceNormals: function () {
  5970. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5971. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5972. var face = this.faces[ f ];
  5973. var vA = this.vertices[ face.a ];
  5974. var vB = this.vertices[ face.b ];
  5975. var vC = this.vertices[ face.c ];
  5976. cb.subVectors( vC, vB );
  5977. ab.subVectors( vA, vB );
  5978. cb.cross( ab );
  5979. cb.normalize();
  5980. face.normal.copy( cb );
  5981. }
  5982. },
  5983. computeVertexNormals: function ( areaWeighted ) {
  5984. if ( areaWeighted === undefined ) areaWeighted = true;
  5985. var v, vl, f, fl, face, vertices;
  5986. vertices = new Array( this.vertices.length );
  5987. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5988. vertices[ v ] = new THREE.Vector3();
  5989. }
  5990. if ( areaWeighted ) {
  5991. // vertex normals weighted by triangle areas
  5992. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5993. var vA, vB, vC;
  5994. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5995. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5996. face = this.faces[ f ];
  5997. vA = this.vertices[ face.a ];
  5998. vB = this.vertices[ face.b ];
  5999. vC = this.vertices[ face.c ];
  6000. cb.subVectors( vC, vB );
  6001. ab.subVectors( vA, vB );
  6002. cb.cross( ab );
  6003. vertices[ face.a ].add( cb );
  6004. vertices[ face.b ].add( cb );
  6005. vertices[ face.c ].add( cb );
  6006. }
  6007. } else {
  6008. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6009. face = this.faces[ f ];
  6010. vertices[ face.a ].add( face.normal );
  6011. vertices[ face.b ].add( face.normal );
  6012. vertices[ face.c ].add( face.normal );
  6013. }
  6014. }
  6015. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6016. vertices[ v ].normalize();
  6017. }
  6018. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6019. face = this.faces[ f ];
  6020. var vertexNormals = face.vertexNormals;
  6021. if ( vertexNormals.length === 3 ) {
  6022. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  6023. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  6024. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  6025. } else {
  6026. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  6027. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  6028. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  6029. }
  6030. }
  6031. if ( this.faces.length > 0 ) {
  6032. this.normalsNeedUpdate = true;
  6033. }
  6034. },
  6035. computeMorphNormals: function () {
  6036. var i, il, f, fl, face;
  6037. // save original normals
  6038. // - create temp variables on first access
  6039. // otherwise just copy (for faster repeated calls)
  6040. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6041. face = this.faces[ f ];
  6042. if ( ! face.__originalFaceNormal ) {
  6043. face.__originalFaceNormal = face.normal.clone();
  6044. } else {
  6045. face.__originalFaceNormal.copy( face.normal );
  6046. }
  6047. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  6048. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  6049. if ( ! face.__originalVertexNormals[ i ] ) {
  6050. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  6051. } else {
  6052. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  6053. }
  6054. }
  6055. }
  6056. // use temp geometry to compute face and vertex normals for each morph
  6057. var tmpGeo = new THREE.Geometry();
  6058. tmpGeo.faces = this.faces;
  6059. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  6060. // create on first access
  6061. if ( ! this.morphNormals[ i ] ) {
  6062. this.morphNormals[ i ] = {};
  6063. this.morphNormals[ i ].faceNormals = [];
  6064. this.morphNormals[ i ].vertexNormals = [];
  6065. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  6066. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  6067. var faceNormal, vertexNormals;
  6068. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6069. faceNormal = new THREE.Vector3();
  6070. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  6071. dstNormalsFace.push( faceNormal );
  6072. dstNormalsVertex.push( vertexNormals );
  6073. }
  6074. }
  6075. var morphNormals = this.morphNormals[ i ];
  6076. // set vertices to morph target
  6077. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  6078. // compute morph normals
  6079. tmpGeo.computeFaceNormals();
  6080. tmpGeo.computeVertexNormals();
  6081. // store morph normals
  6082. var faceNormal, vertexNormals;
  6083. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6084. face = this.faces[ f ];
  6085. faceNormal = morphNormals.faceNormals[ f ];
  6086. vertexNormals = morphNormals.vertexNormals[ f ];
  6087. faceNormal.copy( face.normal );
  6088. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  6089. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  6090. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  6091. }
  6092. }
  6093. // restore original normals
  6094. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6095. face = this.faces[ f ];
  6096. face.normal = face.__originalFaceNormal;
  6097. face.vertexNormals = face.__originalVertexNormals;
  6098. }
  6099. },
  6100. computeTangents: function () {
  6101. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  6102. },
  6103. computeLineDistances: function () {
  6104. var d = 0;
  6105. var vertices = this.vertices;
  6106. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6107. if ( i > 0 ) {
  6108. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  6109. }
  6110. this.lineDistances[ i ] = d;
  6111. }
  6112. },
  6113. computeBoundingBox: function () {
  6114. if ( this.boundingBox === null ) {
  6115. this.boundingBox = new THREE.Box3();
  6116. }
  6117. this.boundingBox.setFromPoints( this.vertices );
  6118. },
  6119. computeBoundingSphere: function () {
  6120. if ( this.boundingSphere === null ) {
  6121. this.boundingSphere = new THREE.Sphere();
  6122. }
  6123. this.boundingSphere.setFromPoints( this.vertices );
  6124. },
  6125. merge: function ( geometry, matrix, materialIndexOffset ) {
  6126. if ( geometry instanceof THREE.Geometry === false ) {
  6127. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  6128. return;
  6129. }
  6130. var normalMatrix,
  6131. vertexOffset = this.vertices.length,
  6132. vertices1 = this.vertices,
  6133. vertices2 = geometry.vertices,
  6134. faces1 = this.faces,
  6135. faces2 = geometry.faces,
  6136. uvs1 = this.faceVertexUvs[ 0 ],
  6137. uvs2 = geometry.faceVertexUvs[ 0 ];
  6138. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  6139. if ( matrix !== undefined ) {
  6140. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6141. }
  6142. // vertices
  6143. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  6144. var vertex = vertices2[ i ];
  6145. var vertexCopy = vertex.clone();
  6146. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  6147. vertices1.push( vertexCopy );
  6148. }
  6149. // faces
  6150. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  6151. var face = faces2[ i ], faceCopy, normal, color,
  6152. faceVertexNormals = face.vertexNormals,
  6153. faceVertexColors = face.vertexColors;
  6154. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  6155. faceCopy.normal.copy( face.normal );
  6156. if ( normalMatrix !== undefined ) {
  6157. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  6158. }
  6159. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  6160. normal = faceVertexNormals[ j ].clone();
  6161. if ( normalMatrix !== undefined ) {
  6162. normal.applyMatrix3( normalMatrix ).normalize();
  6163. }
  6164. faceCopy.vertexNormals.push( normal );
  6165. }
  6166. faceCopy.color.copy( face.color );
  6167. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  6168. color = faceVertexColors[ j ];
  6169. faceCopy.vertexColors.push( color.clone() );
  6170. }
  6171. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  6172. faces1.push( faceCopy );
  6173. }
  6174. // uvs
  6175. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  6176. var uv = uvs2[ i ], uvCopy = [];
  6177. if ( uv === undefined ) {
  6178. continue;
  6179. }
  6180. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  6181. uvCopy.push( uv[ j ].clone() );
  6182. }
  6183. uvs1.push( uvCopy );
  6184. }
  6185. },
  6186. mergeMesh: function ( mesh ) {
  6187. if ( mesh instanceof THREE.Mesh === false ) {
  6188. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  6189. return;
  6190. }
  6191. mesh.matrixAutoUpdate && mesh.updateMatrix();
  6192. this.merge( mesh.geometry, mesh.matrix );
  6193. },
  6194. /*
  6195. * Checks for duplicate vertices with hashmap.
  6196. * Duplicated vertices are removed
  6197. * and faces' vertices are updated.
  6198. */
  6199. mergeVertices: function () {
  6200. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  6201. var unique = [], changes = [];
  6202. var v, key;
  6203. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  6204. var precision = Math.pow( 10, precisionPoints );
  6205. var i, il, face;
  6206. var indices, j, jl;
  6207. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  6208. v = this.vertices[ i ];
  6209. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  6210. if ( verticesMap[ key ] === undefined ) {
  6211. verticesMap[ key ] = i;
  6212. unique.push( this.vertices[ i ] );
  6213. changes[ i ] = unique.length - 1;
  6214. } else {
  6215. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  6216. changes[ i ] = changes[ verticesMap[ key ] ];
  6217. }
  6218. }
  6219. // if faces are completely degenerate after merging vertices, we
  6220. // have to remove them from the geometry.
  6221. var faceIndicesToRemove = [];
  6222. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  6223. face = this.faces[ i ];
  6224. face.a = changes[ face.a ];
  6225. face.b = changes[ face.b ];
  6226. face.c = changes[ face.c ];
  6227. indices = [ face.a, face.b, face.c ];
  6228. var dupIndex = - 1;
  6229. // if any duplicate vertices are found in a Face3
  6230. // we have to remove the face as nothing can be saved
  6231. for ( var n = 0; n < 3; n ++ ) {
  6232. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  6233. dupIndex = n;
  6234. faceIndicesToRemove.push( i );
  6235. break;
  6236. }
  6237. }
  6238. }
  6239. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  6240. var idx = faceIndicesToRemove[ i ];
  6241. this.faces.splice( idx, 1 );
  6242. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  6243. this.faceVertexUvs[ j ].splice( idx, 1 );
  6244. }
  6245. }
  6246. // Use unique set of vertices
  6247. var diff = this.vertices.length - unique.length;
  6248. this.vertices = unique;
  6249. return diff;
  6250. },
  6251. sortFacesByMaterialIndex: function () {
  6252. var faces = this.faces;
  6253. var length = faces.length;
  6254. // tag faces
  6255. for ( var i = 0; i < length; i ++ ) {
  6256. faces[ i ]._id = i;
  6257. }
  6258. // sort faces
  6259. function materialIndexSort( a, b ) {
  6260. return a.materialIndex - b.materialIndex;
  6261. }
  6262. faces.sort( materialIndexSort );
  6263. // sort uvs
  6264. var uvs1 = this.faceVertexUvs[ 0 ];
  6265. var uvs2 = this.faceVertexUvs[ 1 ];
  6266. var newUvs1, newUvs2;
  6267. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  6268. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  6269. for ( var i = 0; i < length; i ++ ) {
  6270. var id = faces[ i ]._id;
  6271. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  6272. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  6273. }
  6274. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  6275. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  6276. },
  6277. toJSON: function () {
  6278. var data = {
  6279. metadata: {
  6280. version: 4.4,
  6281. type: 'Geometry',
  6282. generator: 'Geometry.toJSON'
  6283. }
  6284. };
  6285. // standard Geometry serialization
  6286. data.uuid = this.uuid;
  6287. data.type = this.type;
  6288. if ( this.name !== '' ) data.name = this.name;
  6289. if ( this.parameters !== undefined ) {
  6290. var parameters = this.parameters;
  6291. for ( var key in parameters ) {
  6292. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6293. }
  6294. return data;
  6295. }
  6296. var vertices = [];
  6297. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6298. var vertex = this.vertices[ i ];
  6299. vertices.push( vertex.x, vertex.y, vertex.z );
  6300. }
  6301. var faces = [];
  6302. var normals = [];
  6303. var normalsHash = {};
  6304. var colors = [];
  6305. var colorsHash = {};
  6306. var uvs = [];
  6307. var uvsHash = {};
  6308. for ( var i = 0; i < this.faces.length; i ++ ) {
  6309. var face = this.faces[ i ];
  6310. var hasMaterial = true;
  6311. var hasFaceUv = false; // deprecated
  6312. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6313. var hasFaceNormal = face.normal.length() > 0;
  6314. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6315. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6316. var hasFaceVertexColor = face.vertexColors.length > 0;
  6317. var faceType = 0;
  6318. faceType = setBit( faceType, 0, 0 ); // isQuad
  6319. faceType = setBit( faceType, 1, hasMaterial );
  6320. faceType = setBit( faceType, 2, hasFaceUv );
  6321. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6322. faceType = setBit( faceType, 4, hasFaceNormal );
  6323. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6324. faceType = setBit( faceType, 6, hasFaceColor );
  6325. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6326. faces.push( faceType );
  6327. faces.push( face.a, face.b, face.c );
  6328. faces.push( face.materialIndex );
  6329. if ( hasFaceVertexUv ) {
  6330. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6331. faces.push(
  6332. getUvIndex( faceVertexUvs[ 0 ] ),
  6333. getUvIndex( faceVertexUvs[ 1 ] ),
  6334. getUvIndex( faceVertexUvs[ 2 ] )
  6335. );
  6336. }
  6337. if ( hasFaceNormal ) {
  6338. faces.push( getNormalIndex( face.normal ) );
  6339. }
  6340. if ( hasFaceVertexNormal ) {
  6341. var vertexNormals = face.vertexNormals;
  6342. faces.push(
  6343. getNormalIndex( vertexNormals[ 0 ] ),
  6344. getNormalIndex( vertexNormals[ 1 ] ),
  6345. getNormalIndex( vertexNormals[ 2 ] )
  6346. );
  6347. }
  6348. if ( hasFaceColor ) {
  6349. faces.push( getColorIndex( face.color ) );
  6350. }
  6351. if ( hasFaceVertexColor ) {
  6352. var vertexColors = face.vertexColors;
  6353. faces.push(
  6354. getColorIndex( vertexColors[ 0 ] ),
  6355. getColorIndex( vertexColors[ 1 ] ),
  6356. getColorIndex( vertexColors[ 2 ] )
  6357. );
  6358. }
  6359. }
  6360. function setBit( value, position, enabled ) {
  6361. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6362. }
  6363. function getNormalIndex( normal ) {
  6364. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6365. if ( normalsHash[ hash ] !== undefined ) {
  6366. return normalsHash[ hash ];
  6367. }
  6368. normalsHash[ hash ] = normals.length / 3;
  6369. normals.push( normal.x, normal.y, normal.z );
  6370. return normalsHash[ hash ];
  6371. }
  6372. function getColorIndex( color ) {
  6373. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6374. if ( colorsHash[ hash ] !== undefined ) {
  6375. return colorsHash[ hash ];
  6376. }
  6377. colorsHash[ hash ] = colors.length;
  6378. colors.push( color.getHex() );
  6379. return colorsHash[ hash ];
  6380. }
  6381. function getUvIndex( uv ) {
  6382. var hash = uv.x.toString() + uv.y.toString();
  6383. if ( uvsHash[ hash ] !== undefined ) {
  6384. return uvsHash[ hash ];
  6385. }
  6386. uvsHash[ hash ] = uvs.length / 2;
  6387. uvs.push( uv.x, uv.y );
  6388. return uvsHash[ hash ];
  6389. }
  6390. data.data = {};
  6391. data.data.vertices = vertices;
  6392. data.data.normals = normals;
  6393. if ( colors.length > 0 ) data.data.colors = colors;
  6394. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6395. data.data.faces = faces;
  6396. return data;
  6397. },
  6398. clone: function () {
  6399. /*
  6400. // Handle primitives
  6401. var parameters = this.parameters;
  6402. if ( parameters !== undefined ) {
  6403. var values = [];
  6404. for ( var key in parameters ) {
  6405. values.push( parameters[ key ] );
  6406. }
  6407. var geometry = Object.create( this.constructor.prototype );
  6408. this.constructor.apply( geometry, values );
  6409. return geometry;
  6410. }
  6411. return new this.constructor().copy( this );
  6412. */
  6413. return new THREE.Geometry().copy( this );
  6414. },
  6415. copy: function ( source ) {
  6416. this.vertices = [];
  6417. this.faces = [];
  6418. this.faceVertexUvs = [ [] ];
  6419. var vertices = source.vertices;
  6420. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6421. this.vertices.push( vertices[ i ].clone() );
  6422. }
  6423. var faces = source.faces;
  6424. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6425. this.faces.push( faces[ i ].clone() );
  6426. }
  6427. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6428. var faceVertexUvs = source.faceVertexUvs[ i ];
  6429. if ( this.faceVertexUvs[ i ] === undefined ) {
  6430. this.faceVertexUvs[ i ] = [];
  6431. }
  6432. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6433. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6434. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6435. var uv = uvs[ k ];
  6436. uvsCopy.push( uv.clone() );
  6437. }
  6438. this.faceVertexUvs[ i ].push( uvsCopy );
  6439. }
  6440. }
  6441. return this;
  6442. },
  6443. dispose: function () {
  6444. this.dispatchEvent( { type: 'dispose' } );
  6445. }
  6446. };
  6447. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  6448. THREE.GeometryIdCount = 0;
  6449. // File:src/core/DirectGeometry.js
  6450. /**
  6451. * @author mrdoob / http://mrdoob.com/
  6452. */
  6453. THREE.DirectGeometry = function () {
  6454. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6455. this.uuid = THREE.Math.generateUUID();
  6456. this.name = '';
  6457. this.type = 'DirectGeometry';
  6458. this.indices = [];
  6459. this.vertices = [];
  6460. this.normals = [];
  6461. this.colors = [];
  6462. this.uvs = [];
  6463. this.uvs2 = [];
  6464. this.groups = [];
  6465. this.morphTargets = {};
  6466. this.skinWeights = [];
  6467. this.skinIndices = [];
  6468. // this.lineDistances = [];
  6469. this.boundingBox = null;
  6470. this.boundingSphere = null;
  6471. // update flags
  6472. this.verticesNeedUpdate = false;
  6473. this.normalsNeedUpdate = false;
  6474. this.colorsNeedUpdate = false;
  6475. this.uvsNeedUpdate = false;
  6476. this.groupsNeedUpdate = false;
  6477. };
  6478. THREE.DirectGeometry.prototype = {
  6479. constructor: THREE.DirectGeometry,
  6480. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6481. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6482. computeFaceNormals: function () {
  6483. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6484. },
  6485. computeVertexNormals: function () {
  6486. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6487. },
  6488. computeGroups: function ( geometry ) {
  6489. var group;
  6490. var groups = [];
  6491. var materialIndex;
  6492. var faces = geometry.faces;
  6493. for ( var i = 0; i < faces.length; i ++ ) {
  6494. var face = faces[ i ];
  6495. // materials
  6496. if ( face.materialIndex !== materialIndex ) {
  6497. materialIndex = face.materialIndex;
  6498. if ( group !== undefined ) {
  6499. group.count = ( i * 3 ) - group.start;
  6500. groups.push( group );
  6501. }
  6502. group = {
  6503. start: i * 3,
  6504. materialIndex: materialIndex
  6505. };
  6506. }
  6507. }
  6508. if ( group !== undefined ) {
  6509. group.count = ( i * 3 ) - group.start;
  6510. groups.push( group );
  6511. }
  6512. this.groups = groups;
  6513. },
  6514. fromGeometry: function ( geometry ) {
  6515. var faces = geometry.faces;
  6516. var vertices = geometry.vertices;
  6517. var faceVertexUvs = geometry.faceVertexUvs;
  6518. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6519. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6520. // morphs
  6521. var morphTargets = geometry.morphTargets;
  6522. var morphTargetsLength = morphTargets.length;
  6523. var morphTargetsPosition;
  6524. if ( morphTargetsLength > 0 ) {
  6525. morphTargetsPosition = [];
  6526. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6527. morphTargetsPosition[ i ] = [];
  6528. }
  6529. this.morphTargets.position = morphTargetsPosition;
  6530. }
  6531. var morphNormals = geometry.morphNormals;
  6532. var morphNormalsLength = morphNormals.length;
  6533. var morphTargetsNormal;
  6534. if ( morphNormalsLength > 0 ) {
  6535. morphTargetsNormal = [];
  6536. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6537. morphTargetsNormal[ i ] = [];
  6538. }
  6539. this.morphTargets.normal = morphTargetsNormal;
  6540. }
  6541. // skins
  6542. var skinIndices = geometry.skinIndices;
  6543. var skinWeights = geometry.skinWeights;
  6544. var hasSkinIndices = skinIndices.length === vertices.length;
  6545. var hasSkinWeights = skinWeights.length === vertices.length;
  6546. //
  6547. for ( var i = 0; i < faces.length; i ++ ) {
  6548. var face = faces[ i ];
  6549. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6550. var vertexNormals = face.vertexNormals;
  6551. if ( vertexNormals.length === 3 ) {
  6552. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6553. } else {
  6554. var normal = face.normal;
  6555. this.normals.push( normal, normal, normal );
  6556. }
  6557. var vertexColors = face.vertexColors;
  6558. if ( vertexColors.length === 3 ) {
  6559. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6560. } else {
  6561. var color = face.color;
  6562. this.colors.push( color, color, color );
  6563. }
  6564. if ( hasFaceVertexUv === true ) {
  6565. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6566. if ( vertexUvs !== undefined ) {
  6567. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6568. } else {
  6569. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6570. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6571. }
  6572. }
  6573. if ( hasFaceVertexUv2 === true ) {
  6574. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6575. if ( vertexUvs !== undefined ) {
  6576. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6577. } else {
  6578. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6579. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6580. }
  6581. }
  6582. // morphs
  6583. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6584. var morphTarget = morphTargets[ j ].vertices;
  6585. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6586. }
  6587. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6588. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6589. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6590. }
  6591. // skins
  6592. if ( hasSkinIndices ) {
  6593. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6594. }
  6595. if ( hasSkinWeights ) {
  6596. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6597. }
  6598. }
  6599. this.computeGroups( geometry );
  6600. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6601. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6602. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6603. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6604. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6605. return this;
  6606. },
  6607. dispose: function () {
  6608. this.dispatchEvent( { type: 'dispose' } );
  6609. }
  6610. };
  6611. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6612. // File:src/core/BufferGeometry.js
  6613. /**
  6614. * @author alteredq / http://alteredqualia.com/
  6615. * @author mrdoob / http://mrdoob.com/
  6616. */
  6617. THREE.BufferGeometry = function () {
  6618. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6619. this.uuid = THREE.Math.generateUUID();
  6620. this.name = '';
  6621. this.type = 'BufferGeometry';
  6622. this.index = null;
  6623. this.attributes = {};
  6624. this.morphAttributes = {};
  6625. this.groups = [];
  6626. this.boundingBox = null;
  6627. this.boundingSphere = null;
  6628. this.drawRange = { start: 0, count: Infinity };
  6629. };
  6630. THREE.BufferGeometry.prototype = {
  6631. constructor: THREE.BufferGeometry,
  6632. getIndex: function () {
  6633. return this.index;
  6634. },
  6635. setIndex: function ( index ) {
  6636. this.index = index;
  6637. },
  6638. addAttribute: function ( name, attribute ) {
  6639. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6640. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6641. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6642. return;
  6643. }
  6644. if ( name === 'index' ) {
  6645. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6646. this.setIndex( attribute );
  6647. return;
  6648. }
  6649. this.attributes[ name ] = attribute;
  6650. return this;
  6651. },
  6652. getAttribute: function ( name ) {
  6653. return this.attributes[ name ];
  6654. },
  6655. removeAttribute: function ( name ) {
  6656. delete this.attributes[ name ];
  6657. return this;
  6658. },
  6659. addGroup: function ( start, count, materialIndex ) {
  6660. this.groups.push( {
  6661. start: start,
  6662. count: count,
  6663. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6664. } );
  6665. },
  6666. clearGroups: function () {
  6667. this.groups = [];
  6668. },
  6669. setDrawRange: function ( start, count ) {
  6670. this.drawRange.start = start;
  6671. this.drawRange.count = count;
  6672. },
  6673. applyMatrix: function ( matrix ) {
  6674. var position = this.attributes.position;
  6675. if ( position !== undefined ) {
  6676. matrix.applyToVector3Array( position.array );
  6677. position.needsUpdate = true;
  6678. }
  6679. var normal = this.attributes.normal;
  6680. if ( normal !== undefined ) {
  6681. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6682. normalMatrix.applyToVector3Array( normal.array );
  6683. normal.needsUpdate = true;
  6684. }
  6685. if ( this.boundingBox !== null ) {
  6686. this.computeBoundingBox();
  6687. }
  6688. if ( this.boundingSphere !== null ) {
  6689. this.computeBoundingSphere();
  6690. }
  6691. return this;
  6692. },
  6693. rotateX: function () {
  6694. // rotate geometry around world x-axis
  6695. var m1;
  6696. return function rotateX( angle ) {
  6697. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6698. m1.makeRotationX( angle );
  6699. this.applyMatrix( m1 );
  6700. return this;
  6701. };
  6702. }(),
  6703. rotateY: function () {
  6704. // rotate geometry around world y-axis
  6705. var m1;
  6706. return function rotateY( angle ) {
  6707. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6708. m1.makeRotationY( angle );
  6709. this.applyMatrix( m1 );
  6710. return this;
  6711. };
  6712. }(),
  6713. rotateZ: function () {
  6714. // rotate geometry around world z-axis
  6715. var m1;
  6716. return function rotateZ( angle ) {
  6717. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6718. m1.makeRotationZ( angle );
  6719. this.applyMatrix( m1 );
  6720. return this;
  6721. };
  6722. }(),
  6723. translate: function () {
  6724. // translate geometry
  6725. var m1;
  6726. return function translate( x, y, z ) {
  6727. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6728. m1.makeTranslation( x, y, z );
  6729. this.applyMatrix( m1 );
  6730. return this;
  6731. };
  6732. }(),
  6733. scale: function () {
  6734. // scale geometry
  6735. var m1;
  6736. return function scale( x, y, z ) {
  6737. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6738. m1.makeScale( x, y, z );
  6739. this.applyMatrix( m1 );
  6740. return this;
  6741. };
  6742. }(),
  6743. lookAt: function () {
  6744. var obj;
  6745. return function lookAt( vector ) {
  6746. if ( obj === undefined ) obj = new THREE.Object3D();
  6747. obj.lookAt( vector );
  6748. obj.updateMatrix();
  6749. this.applyMatrix( obj.matrix );
  6750. };
  6751. }(),
  6752. center: function () {
  6753. this.computeBoundingBox();
  6754. var offset = this.boundingBox.center().negate();
  6755. this.translate( offset.x, offset.y, offset.z );
  6756. return offset;
  6757. },
  6758. setFromObject: function ( object ) {
  6759. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6760. var geometry = object.geometry;
  6761. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6762. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6763. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6764. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6765. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6766. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6767. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6768. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6769. }
  6770. if ( geometry.boundingSphere !== null ) {
  6771. this.boundingSphere = geometry.boundingSphere.clone();
  6772. }
  6773. if ( geometry.boundingBox !== null ) {
  6774. this.boundingBox = geometry.boundingBox.clone();
  6775. }
  6776. } else if ( object instanceof THREE.Mesh ) {
  6777. if ( geometry instanceof THREE.Geometry ) {
  6778. this.fromGeometry( geometry );
  6779. }
  6780. }
  6781. return this;
  6782. },
  6783. updateFromObject: function ( object ) {
  6784. var geometry = object.geometry;
  6785. if ( object instanceof THREE.Mesh ) {
  6786. var direct = geometry.__directGeometry;
  6787. if ( direct === undefined ) {
  6788. return this.fromGeometry( geometry );
  6789. }
  6790. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6791. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6792. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6793. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6794. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6795. geometry.verticesNeedUpdate = false;
  6796. geometry.normalsNeedUpdate = false;
  6797. geometry.colorsNeedUpdate = false;
  6798. geometry.uvsNeedUpdate = false;
  6799. geometry.groupsNeedUpdate = false;
  6800. geometry = direct;
  6801. }
  6802. if ( geometry.verticesNeedUpdate === true ) {
  6803. var attribute = this.attributes.position;
  6804. if ( attribute !== undefined ) {
  6805. attribute.copyVector3sArray( geometry.vertices );
  6806. attribute.needsUpdate = true;
  6807. }
  6808. geometry.verticesNeedUpdate = false;
  6809. }
  6810. if ( geometry.normalsNeedUpdate === true ) {
  6811. var attribute = this.attributes.normal;
  6812. if ( attribute !== undefined ) {
  6813. attribute.copyVector3sArray( geometry.normals );
  6814. attribute.needsUpdate = true;
  6815. }
  6816. geometry.normalsNeedUpdate = false;
  6817. }
  6818. if ( geometry.colorsNeedUpdate === true ) {
  6819. var attribute = this.attributes.color;
  6820. if ( attribute !== undefined ) {
  6821. attribute.copyColorsArray( geometry.colors );
  6822. attribute.needsUpdate = true;
  6823. }
  6824. geometry.colorsNeedUpdate = false;
  6825. }
  6826. if ( geometry.uvsNeedUpdate ) {
  6827. var attribute = this.attributes.uv;
  6828. if ( attribute !== undefined ) {
  6829. attribute.copyVector2sArray( geometry.uvs );
  6830. attribute.needsUpdate = true;
  6831. }
  6832. geometry.uvsNeedUpdate = false;
  6833. }
  6834. if ( geometry.lineDistancesNeedUpdate ) {
  6835. var attribute = this.attributes.lineDistance;
  6836. if ( attribute !== undefined ) {
  6837. attribute.copyArray( geometry.lineDistances );
  6838. attribute.needsUpdate = true;
  6839. }
  6840. geometry.lineDistancesNeedUpdate = false;
  6841. }
  6842. if ( geometry.groupsNeedUpdate ) {
  6843. geometry.computeGroups( object.geometry );
  6844. this.groups = geometry.groups;
  6845. geometry.groupsNeedUpdate = false;
  6846. }
  6847. return this;
  6848. },
  6849. fromGeometry: function ( geometry ) {
  6850. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6851. return this.fromDirectGeometry( geometry.__directGeometry );
  6852. },
  6853. fromDirectGeometry: function ( geometry ) {
  6854. var positions = new Float32Array( geometry.vertices.length * 3 );
  6855. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6856. if ( geometry.normals.length > 0 ) {
  6857. var normals = new Float32Array( geometry.normals.length * 3 );
  6858. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6859. }
  6860. if ( geometry.colors.length > 0 ) {
  6861. var colors = new Float32Array( geometry.colors.length * 3 );
  6862. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6863. }
  6864. if ( geometry.uvs.length > 0 ) {
  6865. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6866. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6867. }
  6868. if ( geometry.uvs2.length > 0 ) {
  6869. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6870. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6871. }
  6872. if ( geometry.indices.length > 0 ) {
  6873. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6874. var indices = new TypeArray( geometry.indices.length * 3 );
  6875. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6876. }
  6877. // groups
  6878. this.groups = geometry.groups;
  6879. // morphs
  6880. for ( var name in geometry.morphTargets ) {
  6881. var array = [];
  6882. var morphTargets = geometry.morphTargets[ name ];
  6883. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6884. var morphTarget = morphTargets[ i ];
  6885. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6886. array.push( attribute.copyVector3sArray( morphTarget ) );
  6887. }
  6888. this.morphAttributes[ name ] = array;
  6889. }
  6890. // skinning
  6891. if ( geometry.skinIndices.length > 0 ) {
  6892. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6893. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6894. }
  6895. if ( geometry.skinWeights.length > 0 ) {
  6896. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6897. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6898. }
  6899. //
  6900. if ( geometry.boundingSphere !== null ) {
  6901. this.boundingSphere = geometry.boundingSphere.clone();
  6902. }
  6903. if ( geometry.boundingBox !== null ) {
  6904. this.boundingBox = geometry.boundingBox.clone();
  6905. }
  6906. return this;
  6907. },
  6908. computeBoundingBox: function () {
  6909. var vector = new THREE.Vector3();
  6910. return function () {
  6911. if ( this.boundingBox === null ) {
  6912. this.boundingBox = new THREE.Box3();
  6913. }
  6914. var positions = this.attributes.position.array;
  6915. if ( positions ) {
  6916. this.boundingBox.setFromArray( positions );
  6917. }
  6918. if ( positions === undefined || positions.length === 0 ) {
  6919. this.boundingBox.min.set( 0, 0, 0 );
  6920. this.boundingBox.max.set( 0, 0, 0 );
  6921. }
  6922. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6923. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6924. }
  6925. };
  6926. }(),
  6927. computeBoundingSphere: function () {
  6928. var box = new THREE.Box3();
  6929. var vector = new THREE.Vector3();
  6930. return function () {
  6931. if ( this.boundingSphere === null ) {
  6932. this.boundingSphere = new THREE.Sphere();
  6933. }
  6934. var positions = this.attributes.position.array;
  6935. if ( positions ) {
  6936. var center = this.boundingSphere.center;
  6937. box.setFromArray( positions );
  6938. box.center( center );
  6939. // hoping to find a boundingSphere with a radius smaller than the
  6940. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6941. var maxRadiusSq = 0;
  6942. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6943. vector.fromArray( positions, i );
  6944. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6945. }
  6946. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6947. if ( isNaN( this.boundingSphere.radius ) ) {
  6948. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6949. }
  6950. }
  6951. };
  6952. }(),
  6953. computeFaceNormals: function () {
  6954. // backwards compatibility
  6955. },
  6956. computeVertexNormals: function () {
  6957. var index = this.index;
  6958. var attributes = this.attributes;
  6959. var groups = this.groups;
  6960. if ( attributes.position ) {
  6961. var positions = attributes.position.array;
  6962. if ( attributes.normal === undefined ) {
  6963. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6964. } else {
  6965. // reset existing normals to zero
  6966. var array = attributes.normal.array;
  6967. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6968. array[ i ] = 0;
  6969. }
  6970. }
  6971. var normals = attributes.normal.array;
  6972. var vA, vB, vC,
  6973. pA = new THREE.Vector3(),
  6974. pB = new THREE.Vector3(),
  6975. pC = new THREE.Vector3(),
  6976. cb = new THREE.Vector3(),
  6977. ab = new THREE.Vector3();
  6978. // indexed elements
  6979. if ( index ) {
  6980. var indices = index.array;
  6981. if ( groups.length === 0 ) {
  6982. this.addGroup( 0, indices.length );
  6983. }
  6984. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6985. var group = groups[ j ];
  6986. var start = group.start;
  6987. var count = group.count;
  6988. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6989. vA = indices[ i + 0 ] * 3;
  6990. vB = indices[ i + 1 ] * 3;
  6991. vC = indices[ i + 2 ] * 3;
  6992. pA.fromArray( positions, vA );
  6993. pB.fromArray( positions, vB );
  6994. pC.fromArray( positions, vC );
  6995. cb.subVectors( pC, pB );
  6996. ab.subVectors( pA, pB );
  6997. cb.cross( ab );
  6998. normals[ vA ] += cb.x;
  6999. normals[ vA + 1 ] += cb.y;
  7000. normals[ vA + 2 ] += cb.z;
  7001. normals[ vB ] += cb.x;
  7002. normals[ vB + 1 ] += cb.y;
  7003. normals[ vB + 2 ] += cb.z;
  7004. normals[ vC ] += cb.x;
  7005. normals[ vC + 1 ] += cb.y;
  7006. normals[ vC + 2 ] += cb.z;
  7007. }
  7008. }
  7009. } else {
  7010. // non-indexed elements (unconnected triangle soup)
  7011. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  7012. pA.fromArray( positions, i );
  7013. pB.fromArray( positions, i + 3 );
  7014. pC.fromArray( positions, i + 6 );
  7015. cb.subVectors( pC, pB );
  7016. ab.subVectors( pA, pB );
  7017. cb.cross( ab );
  7018. normals[ i ] = cb.x;
  7019. normals[ i + 1 ] = cb.y;
  7020. normals[ i + 2 ] = cb.z;
  7021. normals[ i + 3 ] = cb.x;
  7022. normals[ i + 4 ] = cb.y;
  7023. normals[ i + 5 ] = cb.z;
  7024. normals[ i + 6 ] = cb.x;
  7025. normals[ i + 7 ] = cb.y;
  7026. normals[ i + 8 ] = cb.z;
  7027. }
  7028. }
  7029. this.normalizeNormals();
  7030. attributes.normal.needsUpdate = true;
  7031. }
  7032. },
  7033. merge: function ( geometry, offset ) {
  7034. if ( geometry instanceof THREE.BufferGeometry === false ) {
  7035. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  7036. return;
  7037. }
  7038. if ( offset === undefined ) offset = 0;
  7039. var attributes = this.attributes;
  7040. for ( var key in attributes ) {
  7041. if ( geometry.attributes[ key ] === undefined ) continue;
  7042. var attribute1 = attributes[ key ];
  7043. var attributeArray1 = attribute1.array;
  7044. var attribute2 = geometry.attributes[ key ];
  7045. var attributeArray2 = attribute2.array;
  7046. var attributeSize = attribute2.itemSize;
  7047. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7048. attributeArray1[ j ] = attributeArray2[ i ];
  7049. }
  7050. }
  7051. return this;
  7052. },
  7053. normalizeNormals: function () {
  7054. var normals = this.attributes.normal.array;
  7055. var x, y, z, n;
  7056. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  7057. x = normals[ i ];
  7058. y = normals[ i + 1 ];
  7059. z = normals[ i + 2 ];
  7060. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  7061. normals[ i ] *= n;
  7062. normals[ i + 1 ] *= n;
  7063. normals[ i + 2 ] *= n;
  7064. }
  7065. },
  7066. toNonIndexed: function () {
  7067. if ( this.index === null ) {
  7068. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7069. return this;
  7070. }
  7071. var geometry2 = new THREE.BufferGeometry();
  7072. var indices = this.index.array;
  7073. var attributes = this.attributes;
  7074. for ( var name in attributes ) {
  7075. var attribute = attributes[ name ];
  7076. var array = attribute.array;
  7077. var itemSize = attribute.itemSize;
  7078. var array2 = new array.constructor( indices.length * itemSize );
  7079. var index = 0, index2 = 0;
  7080. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7081. index = indices[ i ] * itemSize;
  7082. for ( var j = 0; j < itemSize; j ++ ) {
  7083. array2[ index2 ++ ] = array[ index ++ ];
  7084. }
  7085. }
  7086. geometry2.addAttribute( name, new THREE.BufferAttribute( array2, itemSize ) );
  7087. }
  7088. return geometry2;
  7089. },
  7090. toJSON: function () {
  7091. var data = {
  7092. metadata: {
  7093. version: 4.4,
  7094. type: 'BufferGeometry',
  7095. generator: 'BufferGeometry.toJSON'
  7096. }
  7097. };
  7098. // standard BufferGeometry serialization
  7099. data.uuid = this.uuid;
  7100. data.type = this.type;
  7101. if ( this.name !== '' ) data.name = this.name;
  7102. if ( this.parameters !== undefined ) {
  7103. var parameters = this.parameters;
  7104. for ( var key in parameters ) {
  7105. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7106. }
  7107. return data;
  7108. }
  7109. data.data = { attributes: {} };
  7110. var index = this.index;
  7111. if ( index !== null ) {
  7112. var array = Array.prototype.slice.call( index.array );
  7113. data.data.index = {
  7114. type: index.array.constructor.name,
  7115. array: array
  7116. };
  7117. }
  7118. var attributes = this.attributes;
  7119. for ( var key in attributes ) {
  7120. var attribute = attributes[ key ];
  7121. var array = Array.prototype.slice.call( attribute.array );
  7122. data.data.attributes[ key ] = {
  7123. itemSize: attribute.itemSize,
  7124. type: attribute.array.constructor.name,
  7125. array: array
  7126. };
  7127. }
  7128. var groups = this.groups;
  7129. if ( groups.length > 0 ) {
  7130. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7131. }
  7132. var boundingSphere = this.boundingSphere;
  7133. if ( boundingSphere !== null ) {
  7134. data.data.boundingSphere = {
  7135. center: boundingSphere.center.toArray(),
  7136. radius: boundingSphere.radius
  7137. };
  7138. }
  7139. return data;
  7140. },
  7141. clone: function () {
  7142. /*
  7143. // Handle primitives
  7144. var parameters = this.parameters;
  7145. if ( parameters !== undefined ) {
  7146. var values = [];
  7147. for ( var key in parameters ) {
  7148. values.push( parameters[ key ] );
  7149. }
  7150. var geometry = Object.create( this.constructor.prototype );
  7151. this.constructor.apply( geometry, values );
  7152. return geometry;
  7153. }
  7154. return new this.constructor().copy( this );
  7155. */
  7156. return new THREE.BufferGeometry().copy( this );
  7157. },
  7158. copy: function ( source ) {
  7159. var index = source.index;
  7160. if ( index !== null ) {
  7161. this.setIndex( index.clone() );
  7162. }
  7163. var attributes = source.attributes;
  7164. for ( var name in attributes ) {
  7165. var attribute = attributes[ name ];
  7166. this.addAttribute( name, attribute.clone() );
  7167. }
  7168. var groups = source.groups;
  7169. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7170. var group = groups[ i ];
  7171. this.addGroup( group.start, group.count );
  7172. }
  7173. return this;
  7174. },
  7175. dispose: function () {
  7176. this.dispatchEvent( { type: 'dispose' } );
  7177. }
  7178. };
  7179. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  7180. THREE.BufferGeometry.MaxIndex = 65535;
  7181. // File:src/core/InstancedBufferGeometry.js
  7182. /**
  7183. * @author benaadams / https://twitter.com/ben_a_adams
  7184. */
  7185. THREE.InstancedBufferGeometry = function () {
  7186. THREE.BufferGeometry.call( this );
  7187. this.type = 'InstancedBufferGeometry';
  7188. this.maxInstancedCount = undefined;
  7189. };
  7190. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  7191. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  7192. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  7193. this.groups.push( {
  7194. start: start,
  7195. count: count,
  7196. instances: instances
  7197. } );
  7198. };
  7199. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  7200. var index = source.index;
  7201. if ( index !== null ) {
  7202. this.setIndex( index.clone() );
  7203. }
  7204. var attributes = source.attributes;
  7205. for ( var name in attributes ) {
  7206. var attribute = attributes[ name ];
  7207. this.addAttribute( name, attribute.clone() );
  7208. }
  7209. var groups = source.groups;
  7210. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7211. var group = groups[ i ];
  7212. this.addGroup( group.start, group.count, group.instances );
  7213. }
  7214. return this;
  7215. };
  7216. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  7217. // File:src/core/Uniform.js
  7218. /**
  7219. * @author mrdoob / http://mrdoob.com/
  7220. */
  7221. THREE.Uniform = function ( type, value ) {
  7222. this.type = type;
  7223. this.value = value;
  7224. this.dynamic = false;
  7225. };
  7226. THREE.Uniform.prototype = {
  7227. constructor: THREE.Uniform,
  7228. onUpdate: function ( callback ) {
  7229. this.dynamic = true;
  7230. this.onUpdateCallback = callback;
  7231. return this;
  7232. }
  7233. };
  7234. // File:src/animation/AnimationClip.js
  7235. /**
  7236. *
  7237. * Reusable set of Tracks that represent an animation.
  7238. *
  7239. * @author Ben Houston / http://clara.io/
  7240. * @author David Sarno / http://lighthaus.us/
  7241. */
  7242. THREE.AnimationClip = function ( name, duration, tracks ) {
  7243. this.name = name || THREE.Math.generateUUID();
  7244. this.tracks = tracks;
  7245. this.duration = ( duration !== undefined ) ? duration : -1;
  7246. // this means it should figure out its duration by scanning the tracks
  7247. if ( this.duration < 0 ) {
  7248. this.resetDuration();
  7249. }
  7250. // maybe only do these on demand, as doing them here could potentially slow down loading
  7251. // but leaving these here during development as this ensures a lot of testing of these functions
  7252. this.trim();
  7253. this.optimize();
  7254. };
  7255. THREE.AnimationClip.prototype = {
  7256. constructor: THREE.AnimationClip,
  7257. resetDuration: function() {
  7258. var tracks = this.tracks,
  7259. duration = 0;
  7260. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  7261. var track = this.tracks[ i ];
  7262. duration = Math.max(
  7263. duration, track.times[ track.times.length - 1 ] );
  7264. }
  7265. this.duration = duration;
  7266. },
  7267. trim: function() {
  7268. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7269. this.tracks[ i ].trim( 0, this.duration );
  7270. }
  7271. return this;
  7272. },
  7273. optimize: function() {
  7274. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7275. this.tracks[ i ].optimize();
  7276. }
  7277. return this;
  7278. }
  7279. };
  7280. // Static methods:
  7281. Object.assign( THREE.AnimationClip, {
  7282. parse: function( json ) {
  7283. var tracks = [],
  7284. jsonTracks = json.tracks,
  7285. frameTime = 1.0 / ( json.fps || 1.0 );
  7286. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  7287. tracks.push( THREE.KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  7288. }
  7289. return new THREE.AnimationClip( json.name, json.duration, tracks );
  7290. },
  7291. toJSON: function( clip ) {
  7292. var tracks = [],
  7293. clipTracks = clip.tracks;
  7294. var json = {
  7295. 'name': clip.name,
  7296. 'duration': clip.duration,
  7297. 'tracks': tracks
  7298. };
  7299. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  7300. tracks.push( THREE.KeyframeTrack.toJSON( clipTracks[ i ] ) );
  7301. }
  7302. return json;
  7303. },
  7304. CreateFromMorphTargetSequence: function( name, morphTargetSequence, fps ) {
  7305. var numMorphTargets = morphTargetSequence.length;
  7306. var tracks = [];
  7307. for ( var i = 0; i < numMorphTargets; i ++ ) {
  7308. var times = [];
  7309. var values = [];
  7310. times.push(
  7311. ( i + numMorphTargets - 1 ) % numMorphTargets,
  7312. i,
  7313. ( i + 1 ) % numMorphTargets );
  7314. values.push( 0, 1, 0 );
  7315. var order = THREE.AnimationUtils.getKeyframeOrder( times );
  7316. times = THREE.AnimationUtils.sortedArray( times, 1, order );
  7317. values = THREE.AnimationUtils.sortedArray( values, 1, order );
  7318. // if there is a key at the first frame, duplicate it as the
  7319. // last frame as well for perfect loop.
  7320. if ( times[ 0 ] === 0 ) {
  7321. times.push( numMorphTargets );
  7322. values.push( values[ 0 ] );
  7323. }
  7324. tracks.push(
  7325. new THREE.NumberKeyframeTrack(
  7326. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  7327. times, values
  7328. ).scale( 1.0 / fps ) );
  7329. }
  7330. return new THREE.AnimationClip( name, -1, tracks );
  7331. },
  7332. findByName: function( clipArray, name ) {
  7333. for ( var i = 0; i < clipArray.length; i ++ ) {
  7334. if ( clipArray[ i ].name === name ) {
  7335. return clipArray[ i ];
  7336. }
  7337. }
  7338. return null;
  7339. },
  7340. CreateClipsFromMorphTargetSequences: function( morphTargets, fps ) {
  7341. var animationToMorphTargets = {};
  7342. // tested with https://regex101.com/ on trick sequences
  7343. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  7344. var pattern = /^([\w-]*?)([\d]+)$/;
  7345. // sort morph target names into animation groups based
  7346. // patterns like Walk_001, Walk_002, Run_001, Run_002
  7347. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  7348. var morphTarget = morphTargets[ i ];
  7349. var parts = morphTarget.name.match( pattern );
  7350. if ( parts && parts.length > 1 ) {
  7351. var name = parts[ 1 ];
  7352. var animationMorphTargets = animationToMorphTargets[ name ];
  7353. if ( ! animationMorphTargets ) {
  7354. animationToMorphTargets[ name ] = animationMorphTargets = [];
  7355. }
  7356. animationMorphTargets.push( morphTarget );
  7357. }
  7358. }
  7359. var clips = [];
  7360. for ( var name in animationToMorphTargets ) {
  7361. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps ) );
  7362. }
  7363. return clips;
  7364. },
  7365. // parse the animation.hierarchy format
  7366. parseAnimation: function( animation, bones, nodeName ) {
  7367. if ( ! animation ) {
  7368. console.error( " no animation in JSONLoader data" );
  7369. return null;
  7370. }
  7371. var addNonemptyTrack = function(
  7372. trackType, trackName, animationKeys, propertyName, destTracks ) {
  7373. // only return track if there are actually keys.
  7374. if ( animationKeys.length !== 0 ) {
  7375. var times = [];
  7376. var values = [];
  7377. THREE.AnimationUtils.flattenJSON(
  7378. animationKeys, times, values, propertyName );
  7379. // empty keys are filtered out, so check again
  7380. if ( times.length !== 0 ) {
  7381. destTracks.push( new trackType( trackName, times, values ) );
  7382. }
  7383. }
  7384. };
  7385. var tracks = [];
  7386. var clipName = animation.name || 'default';
  7387. // automatic length determination in AnimationClip.
  7388. var duration = animation.length || -1;
  7389. var fps = animation.fps || 30;
  7390. var hierarchyTracks = animation.hierarchy || [];
  7391. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7392. var animationKeys = hierarchyTracks[ h ].keys;
  7393. // skip empty tracks
  7394. if ( ! animationKeys || animationKeys.length == 0 ) continue;
  7395. // process morph targets in a way exactly compatible
  7396. // with AnimationHandler.init( animation )
  7397. if ( animationKeys[0].morphTargets ) {
  7398. // figure out all morph targets used in this track
  7399. var morphTargetNames = {};
  7400. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7401. if ( animationKeys[k].morphTargets ) {
  7402. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7403. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7404. }
  7405. }
  7406. }
  7407. // create a track for each morph target with all zero
  7408. // morphTargetInfluences except for the keys in which
  7409. // the morphTarget is named.
  7410. for ( var morphTargetName in morphTargetNames ) {
  7411. var times = [];
  7412. var values = [];
  7413. for ( var m = 0;
  7414. m !== animationKeys[k].morphTargets.length; ++ m ) {
  7415. var animationKey = animationKeys[k];
  7416. times.push( animationKey.time );
  7417. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 )
  7418. }
  7419. tracks.push( new THREE.NumberKeyframeTrack(
  7420. '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  7421. }
  7422. duration = morphTargetNames.length * ( fps || 1.0 );
  7423. } else {
  7424. // ...assume skeletal animation
  7425. var boneName = '.bones[' + bones[ h ].name + ']';
  7426. addNonemptyTrack(
  7427. THREE.VectorKeyframeTrack, boneName + '.position',
  7428. animationKeys, 'pos', tracks );
  7429. addNonemptyTrack(
  7430. THREE.QuaternionKeyframeTrack, boneName + '.quaternion',
  7431. animationKeys, 'rot', tracks );
  7432. addNonemptyTrack(
  7433. THREE.VectorKeyframeTrack, boneName + '.scale',
  7434. animationKeys, 'scl', tracks );
  7435. }
  7436. }
  7437. if ( tracks.length === 0 ) {
  7438. return null;
  7439. }
  7440. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7441. return clip;
  7442. }
  7443. } );
  7444. // File:src/animation/AnimationMixer.js
  7445. /**
  7446. *
  7447. * Player for AnimationClips.
  7448. *
  7449. *
  7450. * @author Ben Houston / http://clara.io/
  7451. * @author David Sarno / http://lighthaus.us/
  7452. * @author tschw
  7453. */
  7454. THREE.AnimationMixer = function( root ) {
  7455. this._root = root;
  7456. this._initMemoryManager();
  7457. this._accuIndex = 0;
  7458. this.time = 0;
  7459. this.timeScale = 1.0;
  7460. };
  7461. THREE.AnimationMixer.prototype = {
  7462. constructor: THREE.AnimationMixer,
  7463. // return an action for a clip optionally using a custom root target
  7464. // object (this method allocates a lot of dynamic memory in case a
  7465. // previously unknown clip/root combination is specified)
  7466. clipAction: function( clip, optionalRoot ) {
  7467. var root = optionalRoot || this._root,
  7468. rootUuid = root.uuid,
  7469. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7470. clipObject = ( clip !== clipName ) ? clip : null,
  7471. actionsForClip = this._actionsByClip[ clipName ],
  7472. prototypeAction;
  7473. if ( actionsForClip !== undefined ) {
  7474. var existingAction =
  7475. actionsForClip.actionByRoot[ rootUuid ];
  7476. if ( existingAction !== undefined ) {
  7477. return existingAction;
  7478. }
  7479. // we know the clip, so we don't have to parse all
  7480. // the bindings again but can just copy
  7481. prototypeAction = actionsForClip.knownActions[ 0 ];
  7482. // also, take the clip from the prototype action
  7483. clipObject = prototypeAction._clip;
  7484. if ( clip !== clipName && clip !== clipObject ) {
  7485. throw new Error(
  7486. "Different clips with the same name detected!" );
  7487. }
  7488. }
  7489. // clip must be known when specified via string
  7490. if ( clipObject === null ) return null;
  7491. // allocate all resources required to run it
  7492. var newAction = new THREE.
  7493. AnimationMixer._Action( this, clipObject, optionalRoot );
  7494. this._bindAction( newAction, prototypeAction );
  7495. // and make the action known to the memory manager
  7496. this._addInactiveAction( newAction, clipName, rootUuid );
  7497. return newAction;
  7498. },
  7499. // get an existing action
  7500. existingAction: function( clip, optionalRoot ) {
  7501. var root = optionalRoot || this._root,
  7502. rootUuid = root.uuid,
  7503. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7504. actionsForClip = this._actionsByClip[ clipName ];
  7505. if ( actionsForClip !== undefined ) {
  7506. return actionsForClip.actionByRoot[ rootUuid ] || null;
  7507. }
  7508. return null;
  7509. },
  7510. // deactivates all previously scheduled actions
  7511. stopAllAction: function() {
  7512. var actions = this._actions,
  7513. nActions = this._nActiveActions,
  7514. bindings = this._bindings,
  7515. nBindings = this._nActiveBindings;
  7516. this._nActiveActions = 0;
  7517. this._nActiveBindings = 0;
  7518. for ( var i = 0; i !== nActions; ++ i ) {
  7519. actions[ i ].reset();
  7520. }
  7521. for ( var i = 0; i !== nBindings; ++ i ) {
  7522. bindings[ i ].useCount = 0;
  7523. }
  7524. return this;
  7525. },
  7526. // advance the time and update apply the animation
  7527. update: function( deltaTime ) {
  7528. deltaTime *= this.timeScale;
  7529. var actions = this._actions,
  7530. nActions = this._nActiveActions,
  7531. time = this.time += deltaTime,
  7532. timeDirection = Math.sign( deltaTime ),
  7533. accuIndex = this._accuIndex ^= 1;
  7534. // run active actions
  7535. for ( var i = 0; i !== nActions; ++ i ) {
  7536. var action = actions[ i ];
  7537. if ( action.enabled ) {
  7538. action._update( time, deltaTime, timeDirection, accuIndex );
  7539. }
  7540. }
  7541. // update scene graph
  7542. var bindings = this._bindings,
  7543. nBindings = this._nActiveBindings;
  7544. for ( var i = 0; i !== nBindings; ++ i ) {
  7545. bindings[ i ].apply( accuIndex );
  7546. }
  7547. return this;
  7548. },
  7549. // return this mixer's root target object
  7550. getRoot: function() {
  7551. return this._root;
  7552. },
  7553. // free all resources specific to a particular clip
  7554. uncacheClip: function( clip ) {
  7555. var actions = this._actions,
  7556. clipName = clip.name,
  7557. actionsByClip = this._actionsByClip,
  7558. actionsForClip = actionsByClip[ clipName ];
  7559. if ( actionsForClip !== undefined ) {
  7560. // note: just calling _removeInactiveAction would mess up the
  7561. // iteration state and also require updating the state we can
  7562. // just throw away
  7563. var actionsToRemove = actionsForClip.knownActions;
  7564. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  7565. var action = actionsToRemove[ i ];
  7566. this._deactivateAction( action );
  7567. var cacheIndex = action._cacheIndex,
  7568. lastInactiveAction = actions[ actions.length - 1 ];
  7569. action._cacheIndex = null;
  7570. action._byClipCacheIndex = null;
  7571. lastInactiveAction._cacheIndex = cacheIndex;
  7572. actions[ cacheIndex ] = lastInactiveAction;
  7573. actions.pop();
  7574. this._removeInactiveBindingsForAction( action );
  7575. }
  7576. delete actionsByClip[ clipName ];
  7577. }
  7578. },
  7579. // free all resources specific to a particular root target object
  7580. uncacheRoot: function( root ) {
  7581. var rootUuid = root.uuid,
  7582. actionsByClip = this._actionsByClip;
  7583. for ( var clipName in actionsByClip ) {
  7584. var actionByRoot = actionsByClip[ clipName ].actionByRoot,
  7585. action = actionByRoot[ rootUuid ];
  7586. if ( action !== undefined ) {
  7587. this._deactivateAction( action );
  7588. this._removeInactiveAction( action );
  7589. }
  7590. }
  7591. var bindingsByRoot = this._bindingsByRootAndName,
  7592. bindingByName = bindingsByRoot[ rootUuid ];
  7593. if ( bindingByName !== undefined ) {
  7594. for ( var trackName in bindingByName ) {
  7595. var binding = bindingByName[ trackName ];
  7596. binding.restoreOriginalState();
  7597. this._removeInactiveBinding( binding );
  7598. }
  7599. }
  7600. },
  7601. // remove a targeted clip from the cache
  7602. uncacheAction: function( clip, optionalRoot ) {
  7603. var action = this.existingAction( clip, optionalRoot );
  7604. if ( action !== null ) {
  7605. this._deactivateAction( action );
  7606. this._removeInactiveAction( action );
  7607. }
  7608. }
  7609. };
  7610. THREE.EventDispatcher.prototype.apply( THREE.AnimationMixer.prototype );
  7611. THREE.AnimationMixer._Action =
  7612. function( mixer, clip, localRoot ) {
  7613. this._mixer = mixer;
  7614. this._clip = clip;
  7615. this._localRoot = localRoot || null;
  7616. var tracks = clip.tracks,
  7617. nTracks = tracks.length,
  7618. interpolants = new Array( nTracks );
  7619. var interpolantSettings = {
  7620. endingStart: THREE.ZeroCurvatureEnding,
  7621. endingEnd: THREE.ZeroCurvatureEnding
  7622. };
  7623. for ( var i = 0; i !== nTracks; ++ i ) {
  7624. var interpolant = tracks[ i ].createInterpolant( null );
  7625. interpolants[ i ] = interpolant;
  7626. interpolant.settings = interpolantSettings
  7627. }
  7628. this._interpolantSettings = interpolantSettings;
  7629. this._interpolants = interpolants; // bound by the mixer
  7630. // inside: PropertyMixer (managed by the mixer)
  7631. this._propertyBindings = new Array( nTracks );
  7632. this._cacheIndex = null; // for the memory manager
  7633. this._byClipCacheIndex = null; // for the memory manager
  7634. this._timeScaleInterpolant = null;
  7635. this._weightInterpolant = null;
  7636. this.loop = THREE.LoopRepeat;
  7637. this._loopCount = -1;
  7638. // global mixer time when the action is to be started
  7639. // it's set back to 'null' upon start of the action
  7640. this._startTime = null;
  7641. // scaled local time of the action
  7642. // gets clamped or wrapped to 0..clip.duration according to loop
  7643. this.time = 0;
  7644. this.timeScale = 1;
  7645. this._effectiveTimeScale = 1;
  7646. this.weight = 1;
  7647. this._effectiveWeight = 1;
  7648. this.repetitions = Infinity; // no. of repetitions when looping
  7649. this.paused = false; // false -> zero effective time scale
  7650. this.enabled = true; // true -> zero effective weight
  7651. this.clampWhenFinished = false; // keep feeding the last frame?
  7652. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  7653. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  7654. };
  7655. THREE.AnimationMixer._Action.prototype = {
  7656. constructor: THREE.AnimationMixer._Action,
  7657. // State & Scheduling
  7658. play: function() {
  7659. this._mixer._activateAction( this );
  7660. return this;
  7661. },
  7662. stop: function() {
  7663. this._mixer._deactivateAction( this );
  7664. return this.reset();
  7665. },
  7666. reset: function() {
  7667. this.paused = false;
  7668. this.enabled = true;
  7669. this.time = 0; // restart clip
  7670. this._loopCount = -1; // forget previous loops
  7671. this._startTime = null; // forget scheduling
  7672. return this.stopFading().stopWarping();
  7673. },
  7674. isRunning: function() {
  7675. var start = this._startTime;
  7676. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  7677. this._startTime === null && this._mixer._isActiveAction( this )
  7678. },
  7679. // return true when play has been called
  7680. isScheduled: function() {
  7681. return this._mixer._isActiveAction( this );
  7682. },
  7683. startAt: function( time ) {
  7684. this._startTime = time;
  7685. return this;
  7686. },
  7687. setLoop: function( mode, repetitions ) {
  7688. this.loop = mode;
  7689. this.repetitions = repetitions;
  7690. return this;
  7691. },
  7692. // Weight
  7693. // set the weight stopping any scheduled fading
  7694. // although .enabled = false yields an effective weight of zero, this
  7695. // method does *not* change .enabled, because it would be confusing
  7696. setEffectiveWeight: function( weight ) {
  7697. this.weight = weight;
  7698. // note: same logic as when updated at runtime
  7699. this._effectiveWeight = this.enabled ? weight : 0;
  7700. return this.stopFading();
  7701. },
  7702. // return the weight considering fading and .enabled
  7703. getEffectiveWeight: function() {
  7704. return this._effectiveWeight;
  7705. },
  7706. fadeIn: function( duration ) {
  7707. return this._scheduleFading( duration, 0, 1 );
  7708. },
  7709. fadeOut: function( duration ) {
  7710. return this._scheduleFading( duration, 1, 0 );
  7711. },
  7712. crossFadeFrom: function( fadeOutAction, duration, warp ) {
  7713. var mixer = this._mixer;
  7714. fadeOutAction.fadeOut( duration );
  7715. this.fadeIn( duration );
  7716. if( warp ) {
  7717. var fadeInDuration = this._clip.duration,
  7718. fadeOutDuration = fadeOutAction._clip.duration,
  7719. startEndRatio = fadeOutDuration / fadeInDuration,
  7720. endStartRatio = fadeInDuration / fadeOutDuration;
  7721. fadeOutAction.warp( 1.0, startEndRatio, duration );
  7722. this.warp( endStartRatio, 1.0, duration );
  7723. }
  7724. return this;
  7725. },
  7726. crossFadeTo: function( fadeInAction, duration, warp ) {
  7727. return fadeInAction.crossFadeFrom( this, duration, warp );
  7728. },
  7729. stopFading: function() {
  7730. var weightInterpolant = this._weightInterpolant;
  7731. if ( weightInterpolant !== null ) {
  7732. this._weightInterpolant = null;
  7733. this._mixer._takeBackControlInterpolant( weightInterpolant );
  7734. }
  7735. return this;
  7736. },
  7737. // Time Scale Control
  7738. // set the weight stopping any scheduled warping
  7739. // although .paused = true yields an effective time scale of zero, this
  7740. // method does *not* change .paused, because it would be confusing
  7741. setEffectiveTimeScale: function( timeScale ) {
  7742. this.timeScale = timeScale;
  7743. this._effectiveTimeScale = this.paused ? 0 :timeScale;
  7744. return this.stopWarping();
  7745. },
  7746. // return the time scale considering warping and .paused
  7747. getEffectiveTimeScale: function() {
  7748. return this._effectiveTimeScale;
  7749. },
  7750. setDuration: function( duration ) {
  7751. this.timeScale = this._clip.duration / duration;
  7752. return this.stopWarping();
  7753. },
  7754. syncWith: function( action ) {
  7755. this.time = action.time;
  7756. this.timeScale = action.timeScale;
  7757. return this.stopWarping();
  7758. },
  7759. halt: function( duration ) {
  7760. return this.warp( this._currentTimeScale, 0, duration );
  7761. },
  7762. warp: function( startTimeScale, endTimeScale, duration ) {
  7763. var mixer = this._mixer, now = mixer.time,
  7764. interpolant = this._timeScaleInterpolant,
  7765. timeScale = this.timeScale;
  7766. if ( interpolant === null ) {
  7767. interpolant = mixer._lendControlInterpolant(),
  7768. this._timeScaleInterpolant = interpolant;
  7769. }
  7770. var times = interpolant.parameterPositions,
  7771. values = interpolant.sampleValues;
  7772. times[ 0 ] = now;
  7773. times[ 1 ] = now + duration;
  7774. values[ 0 ] = startTimeScale / timeScale;
  7775. values[ 1 ] = endTimeScale / timeScale;
  7776. return this;
  7777. },
  7778. stopWarping: function() {
  7779. var timeScaleInterpolant = this._timeScaleInterpolant;
  7780. if ( timeScaleInterpolant !== null ) {
  7781. this._timeScaleInterpolant = null;
  7782. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  7783. }
  7784. return this;
  7785. },
  7786. // Object Accessors
  7787. getMixer: function() {
  7788. return this._mixer;
  7789. },
  7790. getClip: function() {
  7791. return this._clip;
  7792. },
  7793. getRoot: function() {
  7794. return this._localRoot || this._mixer._root;
  7795. },
  7796. // Interna
  7797. _update: function( time, deltaTime, timeDirection, accuIndex ) {
  7798. // called by the mixer
  7799. var startTime = this._startTime;
  7800. if ( startTime !== null ) {
  7801. // check for scheduled start of action
  7802. var timeRunning = ( time - startTime ) * timeDirection;
  7803. if ( timeRunning < 0 || timeDirection === 0 ) {
  7804. return; // yet to come / don't decide when delta = 0
  7805. }
  7806. // start
  7807. this._startTime = null; // unschedule
  7808. deltaTime = timeDirection * timeRunning;
  7809. }
  7810. // apply time scale and advance time
  7811. deltaTime *= this._updateTimeScale( time );
  7812. var clipTime = this._updateTime( deltaTime );
  7813. // note: _updateTime may disable the action resulting in
  7814. // an effective weight of 0
  7815. var weight = this._updateWeight( time );
  7816. if ( weight > 0 ) {
  7817. var interpolants = this._interpolants;
  7818. var propertyMixers = this._propertyBindings;
  7819. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  7820. interpolants[ j ].evaluate( clipTime );
  7821. propertyMixers[ j ].accumulate( accuIndex, weight );
  7822. }
  7823. }
  7824. },
  7825. _updateWeight: function( time ) {
  7826. var weight = 0;
  7827. if ( this.enabled ) {
  7828. weight = this.weight;
  7829. var interpolant = this._weightInterpolant;
  7830. if ( interpolant !== null ) {
  7831. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7832. weight *= interpolantValue;
  7833. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7834. this.stopFading();
  7835. if ( interpolantValue === 0 ) {
  7836. // faded out, disable
  7837. this.enabled = false;
  7838. }
  7839. }
  7840. }
  7841. }
  7842. this._effectiveWeight = weight;
  7843. return weight;
  7844. },
  7845. _updateTimeScale: function( time ) {
  7846. var timeScale = 0;
  7847. if ( ! this.paused ) {
  7848. timeScale = this.timeScale;
  7849. var interpolant = this._timeScaleInterpolant;
  7850. if ( interpolant !== null ) {
  7851. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7852. timeScale *= interpolantValue;
  7853. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7854. this.stopWarping();
  7855. if ( timeScale === 0 ) {
  7856. // motion has halted, pause
  7857. this.pause = true;
  7858. } else {
  7859. // warp done - apply final time scale
  7860. this.timeScale = timeScale;
  7861. }
  7862. }
  7863. }
  7864. }
  7865. this._effectiveTimeScale = timeScale;
  7866. return timeScale;
  7867. },
  7868. _updateTime: function( deltaTime ) {
  7869. var time = this.time + deltaTime;
  7870. if ( deltaTime === 0 ) return time;
  7871. var duration = this._clip.duration,
  7872. loop = this.loop,
  7873. loopCount = this._loopCount,
  7874. pingPong = false;
  7875. switch ( loop ) {
  7876. case THREE.LoopOnce:
  7877. if ( loopCount === -1 ) {
  7878. // just started
  7879. this.loopCount = 0;
  7880. this._setEndings( true, true, false );
  7881. }
  7882. if ( time >= duration ) {
  7883. time = duration;
  7884. } else if ( time < 0 ) {
  7885. time = 0;
  7886. } else break;
  7887. // reached the end
  7888. if ( this.clampWhenFinished ) this.pause = true;
  7889. else this.enabled = false;
  7890. this._mixer.dispatchEvent( {
  7891. type: 'finished', action: this,
  7892. direction: deltaTime < 0 ? -1 : 1
  7893. } );
  7894. break;
  7895. case THREE.LoopPingPong:
  7896. pingPong = true;
  7897. case THREE.LoopRepeat:
  7898. if ( loopCount === -1 ) {
  7899. // just started
  7900. if ( deltaTime > 0 ) {
  7901. loopCount = 0;
  7902. this._setEndings(
  7903. true, this.repetitions === 0, pingPong );
  7904. } else {
  7905. // when looping in reverse direction, the initial
  7906. // transition through zero counts as a repetition,
  7907. // so leave loopCount at -1
  7908. this._setEndings(
  7909. this.repetitions === 0, true, pingPong );
  7910. }
  7911. }
  7912. if ( time >= duration || time < 0 ) {
  7913. // wrap around
  7914. var loopDelta = Math.floor( time / duration ); // signed
  7915. time -= duration * loopDelta;
  7916. loopCount += Math.abs( loopDelta );
  7917. var pending = this.repetitions - loopCount;
  7918. if ( pending < 0 ) {
  7919. // stop (switch state, clamp time, fire event)
  7920. if ( this.clampWhenFinished ) this.paused = true;
  7921. else this.enabled = false;
  7922. time = deltaTime > 0 ? duration : 0;
  7923. this._mixer.dispatchEvent( {
  7924. type: 'finished', action: this,
  7925. direction: deltaTime > 0 ? 1 : -1
  7926. } );
  7927. break;
  7928. } else if ( pending === 0 ) {
  7929. // transition to last round
  7930. var atStart = deltaTime < 0;
  7931. this._setEndings( atStart, ! atStart, pingPong );
  7932. } else {
  7933. this._setEndings( false, false, pingPong );
  7934. }
  7935. this._loopCount = loopCount;
  7936. this._mixer.dispatchEvent( {
  7937. type: 'loop', action: this, loopDelta: loopDelta
  7938. } );
  7939. }
  7940. if ( loop === THREE.LoopPingPong && ( loopCount & 1 ) === 1 ) {
  7941. // invert time for the "pong round"
  7942. this.time = time;
  7943. return duration - time;
  7944. }
  7945. break;
  7946. }
  7947. this.time = time;
  7948. return time;
  7949. },
  7950. _setEndings: function( atStart, atEnd, pingPong ) {
  7951. var settings = this._interpolantSettings;
  7952. if ( pingPong ) {
  7953. settings.endingStart = THREE.ZeroSlopeEnding;
  7954. settings.endingEnd = THREE.ZeroSlopeEnding;
  7955. } else {
  7956. // assuming for LoopOnce atStart == atEnd == true
  7957. if ( atStart ) {
  7958. settings.endingStart = this.zeroSlopeAtStart ?
  7959. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7960. } else {
  7961. settings.endingStart = THREE.WrapAroundEnding;
  7962. }
  7963. if ( atEnd ) {
  7964. settings.endingEnd = this.zeroSlopeAtEnd ?
  7965. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7966. } else {
  7967. settings.endingEnd = THREE.WrapAroundEnding;
  7968. }
  7969. }
  7970. },
  7971. _scheduleFading: function( duration, weightNow, weightThen ) {
  7972. var mixer = this._mixer, now = mixer.time,
  7973. interpolant = this._weightInterpolant;
  7974. if ( interpolant === null ) {
  7975. interpolant = mixer._lendControlInterpolant(),
  7976. this._weightInterpolant = interpolant;
  7977. }
  7978. var times = interpolant.parameterPositions,
  7979. values = interpolant.sampleValues;
  7980. times[ 0 ] = now; values[ 0 ] = weightNow;
  7981. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  7982. return this;
  7983. }
  7984. };
  7985. // Implementation details:
  7986. Object.assign( THREE.AnimationMixer.prototype, {
  7987. _bindAction: function( action, prototypeAction ) {
  7988. var root = action._localRoot || this._root,
  7989. tracks = action._clip.tracks,
  7990. nTracks = tracks.length,
  7991. bindings = action._propertyBindings,
  7992. interpolants = action._interpolants,
  7993. rootUuid = root.uuid,
  7994. bindingsByRoot = this._bindingsByRootAndName,
  7995. bindingsByName = bindingsByRoot[ rootUuid ];
  7996. if ( bindingsByName === undefined ) {
  7997. bindingsByName = {};
  7998. bindingsByRoot[ rootUuid ] = bindingsByName;
  7999. }
  8000. for ( var i = 0; i !== nTracks; ++ i ) {
  8001. var track = tracks[ i ],
  8002. trackName = track.name,
  8003. binding = bindingsByName[ trackName ];
  8004. if ( binding !== undefined ) {
  8005. bindings[ i ] = binding;
  8006. } else {
  8007. binding = bindings[ i ];
  8008. if ( binding !== undefined ) {
  8009. // existing binding, make sure the cache knows
  8010. if ( binding._cacheIndex === null ) {
  8011. ++ binding.referenceCount;
  8012. this._addInactiveBinding( binding, rootUuid, trackName );
  8013. }
  8014. continue;
  8015. }
  8016. var path = prototypeAction && prototypeAction.
  8017. _propertyBindings[ i ].binding.parsedPath;
  8018. binding = new THREE.PropertyMixer(
  8019. THREE.PropertyBinding.create( root, trackName, path ),
  8020. track.ValueTypeName, track.getValueSize() );
  8021. ++ binding.referenceCount;
  8022. this._addInactiveBinding( binding, rootUuid, trackName );
  8023. bindings[ i ] = binding;
  8024. }
  8025. interpolants[ i ].resultBuffer = binding.buffer;
  8026. }
  8027. },
  8028. _activateAction: function( action ) {
  8029. if ( ! this._isActiveAction( action ) ) {
  8030. if ( action._cacheIndex === null ) {
  8031. // this action has been forgotten by the cache, but the user
  8032. // appears to be still using it -> rebind
  8033. var rootUuid = ( action._localRoot || this._root ).uuid,
  8034. clipName = action._clip.name,
  8035. actionsForClip = this._actionsByClip[ clipName ];
  8036. this._bindAction( action,
  8037. actionsForClip && actionsForClip.knownActions[ 0 ] );
  8038. this._addInactiveAction( action, clipName, rootUuid );
  8039. }
  8040. var bindings = action._propertyBindings;
  8041. // increment reference counts / sort out state
  8042. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8043. var binding = bindings[ i ];
  8044. if ( binding.useCount ++ === 0 ) {
  8045. this._lendBinding( binding );
  8046. binding.saveOriginalState();
  8047. }
  8048. }
  8049. this._lendAction( action );
  8050. }
  8051. },
  8052. _deactivateAction: function( action ) {
  8053. if ( this._isActiveAction( action ) ) {
  8054. var bindings = action._propertyBindings;
  8055. // decrement reference counts / sort out state
  8056. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8057. var binding = bindings[ i ];
  8058. if ( -- binding.useCount === 0 ) {
  8059. binding.restoreOriginalState();
  8060. this._takeBackBinding( binding );
  8061. }
  8062. }
  8063. this._takeBackAction( action );
  8064. }
  8065. },
  8066. // Memory manager
  8067. _initMemoryManager: function() {
  8068. this._actions = []; // 'nActiveActions' followed by inactive ones
  8069. this._nActiveActions = 0;
  8070. this._actionsByClip = {};
  8071. // inside:
  8072. // {
  8073. // knownActions: Array< _Action > - used as prototypes
  8074. // actionByRoot: _Action - lookup
  8075. // }
  8076. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  8077. this._nActiveBindings = 0;
  8078. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  8079. this._controlInterpolants = []; // same game as above
  8080. this._nActiveControlInterpolants = 0;
  8081. var scope = this;
  8082. this.stats = {
  8083. actions: {
  8084. get total() { return scope._actions.length; },
  8085. get inUse() { return scope._nActiveActions; }
  8086. },
  8087. bindings: {
  8088. get total() { return scope._bindings.length; },
  8089. get inUse() { return scope._nActiveBindings; }
  8090. },
  8091. controlInterpolants: {
  8092. get total() { return scope._controlInterpolants.length; },
  8093. get inUse() { return scope._nActiveControlInterpolants; }
  8094. }
  8095. };
  8096. },
  8097. // Memory management for _Action objects
  8098. _isActiveAction: function( action ) {
  8099. var index = action._cacheIndex;
  8100. return index !== null && index < this._nActiveActions;
  8101. },
  8102. _addInactiveAction: function( action, clipName, rootUuid ) {
  8103. var actions = this._actions,
  8104. actionsByClip = this._actionsByClip,
  8105. actionsForClip = actionsByClip[ clipName ];
  8106. if ( actionsForClip === undefined ) {
  8107. actionsForClip = {
  8108. knownActions: [ action ],
  8109. actionByRoot: {}
  8110. };
  8111. action._byClipCacheIndex = 0;
  8112. actionsByClip[ clipName ] = actionsForClip;
  8113. } else {
  8114. var knownActions = actionsForClip.knownActions;
  8115. action._byClipCacheIndex = knownActions.length;
  8116. knownActions.push( action );
  8117. }
  8118. action._cacheIndex = actions.length;
  8119. actions.push( action );
  8120. actionsForClip.actionByRoot[ rootUuid ] = action;
  8121. },
  8122. _removeInactiveAction: function( action ) {
  8123. var actions = this._actions,
  8124. lastInactiveAction = actions[ actions.length - 1 ],
  8125. cacheIndex = action._cacheIndex;
  8126. lastInactiveAction._cacheIndex = cacheIndex;
  8127. actions[ cacheIndex ] = lastInactiveAction;
  8128. actions.pop();
  8129. action._cacheIndex = null;
  8130. var clipName = action._clip.name,
  8131. actionsByClip = this._actionsByClip,
  8132. actionsForClip = actionsByClip[ clipName ],
  8133. knownActionsForClip = actionsForClip.knownActions,
  8134. lastKnownAction =
  8135. knownActionsForClip[ knownActionsForClip.length - 1 ],
  8136. byClipCacheIndex = action._byClipCacheIndex;
  8137. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  8138. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  8139. knownActionsForClip.pop();
  8140. action._byClipCacheIndex = null;
  8141. var actionByRoot = actionsForClip.actionByRoot,
  8142. rootUuid = ( actions._localRoot || this._root ).uuid;
  8143. delete actionByRoot[ rootUuid ];
  8144. if ( knownActionsForClip.length === 0 ) {
  8145. delete actionsByClip[ clipName ];
  8146. }
  8147. this._removeInactiveBindingsForAction( action );
  8148. },
  8149. _removeInactiveBindingsForAction: function( action ) {
  8150. var bindings = action._propertyBindings;
  8151. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8152. var binding = bindings[ i ];
  8153. if ( -- binding.referenceCount === 0 ) {
  8154. this._removeInactiveBinding( binding );
  8155. }
  8156. }
  8157. },
  8158. _lendAction: function( action ) {
  8159. // [ active actions | inactive actions ]
  8160. // [ active actions >| inactive actions ]
  8161. // s a
  8162. // <-swap->
  8163. // a s
  8164. var actions = this._actions,
  8165. prevIndex = action._cacheIndex,
  8166. lastActiveIndex = this._nActiveActions ++,
  8167. firstInactiveAction = actions[ lastActiveIndex ];
  8168. action._cacheIndex = lastActiveIndex;
  8169. actions[ lastActiveIndex ] = action;
  8170. firstInactiveAction._cacheIndex = prevIndex;
  8171. actions[ prevIndex ] = firstInactiveAction;
  8172. },
  8173. _takeBackAction: function( action ) {
  8174. // [ active actions | inactive actions ]
  8175. // [ active actions |< inactive actions ]
  8176. // a s
  8177. // <-swap->
  8178. // s a
  8179. var actions = this._actions,
  8180. prevIndex = action._cacheIndex,
  8181. firstInactiveIndex = -- this._nActiveActions,
  8182. lastActiveAction = actions[ firstInactiveIndex ];
  8183. action._cacheIndex = firstInactiveIndex;
  8184. actions[ firstInactiveIndex ] = action;
  8185. lastActiveAction._cacheIndex = prevIndex;
  8186. actions[ prevIndex ] = lastActiveAction;
  8187. },
  8188. // Memory management for PropertyMixer objects
  8189. _addInactiveBinding: function( binding, rootUuid, trackName ) {
  8190. var bindingsByRoot = this._bindingsByRootAndName,
  8191. bindingByName = bindingsByRoot[ rootUuid ],
  8192. bindings = this._bindings;
  8193. if ( bindingByName === undefined ) {
  8194. bindingByName = {};
  8195. bindingsByRoot[ rootUuid ] = bindingByName;
  8196. }
  8197. bindingByName[ trackName ] = binding;
  8198. binding._cacheIndex = bindings.length;
  8199. bindings.push( binding );
  8200. },
  8201. _removeInactiveBinding: function( binding ) {
  8202. var bindings = this._bindings,
  8203. propBinding = binding.binding,
  8204. rootUuid = propBinding.rootNode.uuid,
  8205. trackName = propBinding.path,
  8206. bindingsByRoot = this._bindingsByRootAndName,
  8207. bindingByName = bindingsByRoot[ rootUuid ],
  8208. lastInactiveBinding = bindings[ bindings.length - 1 ],
  8209. cacheIndex = binding._cacheIndex;
  8210. lastInactiveBinding._cacheIndex = cacheIndex;
  8211. bindings[ cacheIndex ] = lastInactiveBinding;
  8212. bindings.pop();
  8213. delete bindingByName[ trackName ];
  8214. remove_empty_map: {
  8215. for ( var _ in bindingByName ) break remove_empty_map;
  8216. delete bindingsByRoot[ rootUuid ];
  8217. }
  8218. },
  8219. _lendBinding: function( binding ) {
  8220. var bindings = this._bindings,
  8221. prevIndex = binding._cacheIndex,
  8222. lastActiveIndex = this._nActiveBindings ++,
  8223. firstInactiveBinding = bindings[ lastActiveIndex ];
  8224. binding._cacheIndex = lastActiveIndex;
  8225. bindings[ lastActiveIndex ] = binding;
  8226. firstInactiveBinding._cacheIndex = prevIndex;
  8227. bindings[ prevIndex ] = firstInactiveBinding;
  8228. },
  8229. _takeBackBinding: function( binding ) {
  8230. var bindings = this._bindings,
  8231. prevIndex = binding._cacheIndex,
  8232. firstInactiveIndex = -- this._nActiveBindings,
  8233. lastActiveBinding = bindings[ firstInactiveIndex ];
  8234. binding._cacheIndex = firstInactiveIndex;
  8235. bindings[ firstInactiveIndex ] = binding;
  8236. lastActiveBinding._cacheIndex = prevIndex;
  8237. bindings[ prevIndex ] = lastActiveBinding;
  8238. },
  8239. // Memory management of Interpolants for weight and time scale
  8240. _lendControlInterpolant: function() {
  8241. var interpolants = this._controlInterpolants,
  8242. lastActiveIndex = this._nActiveControlInterpolants ++,
  8243. interpolant = interpolants[ lastActiveIndex ];
  8244. if ( interpolant === undefined ) {
  8245. interpolant = new THREE.LinearInterpolant(
  8246. new Float32Array( 2 ), new Float32Array( 2 ),
  8247. 1, this._controlInterpolantsResultBuffer );
  8248. interpolant.__cacheIndex = lastActiveIndex;
  8249. interpolants[ lastActiveIndex ] = interpolant;
  8250. }
  8251. return interpolant;
  8252. },
  8253. _takeBackControlInterpolant: function( interpolant ) {
  8254. var interpolants = this._controlInterpolants,
  8255. prevIndex = interpolant.__cacheIndex,
  8256. firstInactiveIndex = -- this._nActiveControlInterpolants,
  8257. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  8258. interpolant.__cacheIndex = firstInactiveIndex;
  8259. interpolants[ firstInactiveIndex ] = interpolant;
  8260. lastActiveInterpolant.__cacheIndex = prevIndex;
  8261. interpolants[ prevIndex ] = lastActiveInterpolant;
  8262. },
  8263. _controlInterpolantsResultBuffer: new Float32Array( 1 )
  8264. } );
  8265. // File:src/animation/AnimationObjectGroup.js
  8266. /**
  8267. *
  8268. * A group of objects that receives a shared animation state.
  8269. *
  8270. * Usage:
  8271. *
  8272. * - Add objects you would otherwise pass as 'root' to the
  8273. * constructor or the .clipAction method of AnimationMixer.
  8274. *
  8275. * - Instead pass this object as 'root'.
  8276. *
  8277. * - You can also add and remove objects later when the mixer
  8278. * is running.
  8279. *
  8280. * Note:
  8281. *
  8282. * Objects of this class appear as one object to the mixer,
  8283. * so cache control of the individual objects must be done
  8284. * on the group.
  8285. *
  8286. * Limitation:
  8287. *
  8288. * - The animated properties must be compatible among the
  8289. * all objects in the group.
  8290. *
  8291. * - A single property can either be controlled through a
  8292. * target group or directly, but not both.
  8293. *
  8294. * @author tschw
  8295. */
  8296. THREE.AnimationObjectGroup = function( var_args ) {
  8297. this.uuid = THREE.Math.generateUUID();
  8298. // cached objects followed by the active ones
  8299. this._objects = Array.prototype.slice.call( arguments );
  8300. this.nCachedObjects_ = 0; // threshold
  8301. // note: read by PropertyBinding.Composite
  8302. var indices = {};
  8303. this._indicesByUUID = indices; // for bookkeeping
  8304. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8305. indices[ arguments[ i ].uuid ] = i;
  8306. }
  8307. this._paths = []; // inside: string
  8308. this._parsedPaths = []; // inside: { we don't care, here }
  8309. this._bindings = []; // inside: Array< PropertyBinding >
  8310. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  8311. var scope = this;
  8312. this.stats = {
  8313. objects: {
  8314. get total() { return scope._objects.length; },
  8315. get inUse() { return this.total - scope.nCachedObjects_; }
  8316. },
  8317. get bindingsPerObject() { return scope._bindings.length; }
  8318. };
  8319. };
  8320. THREE.AnimationObjectGroup.prototype = {
  8321. constructor: THREE.AnimationObjectGroup,
  8322. add: function( var_args ) {
  8323. var objects = this._objects,
  8324. nObjects = objects.length,
  8325. nCachedObjects = this.nCachedObjects_,
  8326. indicesByUUID = this._indicesByUUID,
  8327. paths = this._paths,
  8328. parsedPaths = this._parsedPaths,
  8329. bindings = this._bindings,
  8330. nBindings = bindings.length;
  8331. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8332. var object = arguments[ i ],
  8333. uuid = object.uuid,
  8334. index = indicesByUUID[ uuid ];
  8335. if ( index === undefined ) {
  8336. // unknown object -> add it to the ACTIVE region
  8337. index = nObjects ++;
  8338. indicesByUUID[ uuid ] = index;
  8339. objects.push( object );
  8340. // accounting is done, now do the same for all bindings
  8341. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8342. bindings[ j ].push(
  8343. new THREE.PropertyBinding(
  8344. object, paths[ j ], parsedPaths[ j ] ) );
  8345. }
  8346. } else if ( index < nCachedObjects ) {
  8347. var knownObject = objects[ index ];
  8348. // move existing object to the ACTIVE region
  8349. var firstActiveIndex = -- nCachedObjects,
  8350. lastCachedObject = objects[ firstActiveIndex ];
  8351. indicesByUUID[ lastCachedObject.uuid ] = index;
  8352. objects[ index ] = lastCachedObject;
  8353. indicesByUUID[ uuid ] = firstActiveIndex;
  8354. objects[ firstActiveIndex ] = object;
  8355. // accounting is done, now do the same for all bindings
  8356. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8357. var bindingsForPath = bindings[ j ],
  8358. lastCached = bindingsForPath[ firstActiveIndex ],
  8359. binding = bindingsForPath[ index ];
  8360. bindingsForPath[ index ] = lastCached;
  8361. if ( binding === undefined ) {
  8362. // since we do not bother to create new bindings
  8363. // for objects that are cached, the binding may
  8364. // or may not exist
  8365. binding = new THREE.PropertyBinding(
  8366. object, paths[ j ], parsedPaths[ j ] );
  8367. }
  8368. bindingsForPath[ firstActiveIndex ] = binding;
  8369. }
  8370. } else if ( objects[ index ] !== knownObject) {
  8371. console.error( "Different objects with the same UUID " +
  8372. "detected. Clean the caches or recreate your " +
  8373. "infrastructure when reloading scenes..." );
  8374. } // else the object is already where we want it to be
  8375. } // for arguments
  8376. this.nCachedObjects_ = nCachedObjects;
  8377. },
  8378. remove: function( var_args ) {
  8379. var objects = this._objects,
  8380. nObjects = objects.length,
  8381. nCachedObjects = this.nCachedObjects_,
  8382. indicesByUUID = this._indicesByUUID,
  8383. bindings = this._bindings,
  8384. nBindings = bindings.length;
  8385. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8386. var object = arguments[ i ],
  8387. uuid = object.uuid,
  8388. index = indicesByUUID[ uuid ];
  8389. if ( index !== undefined && index >= nCachedObjects ) {
  8390. // move existing object into the CACHED region
  8391. var lastCachedIndex = nCachedObjects ++,
  8392. firstActiveObject = objects[ lastCachedIndex ];
  8393. indicesByUUID[ firstActiveObject.uuid ] = index;
  8394. objects[ index ] = firstActiveObject;
  8395. indicesByUUID[ uuid ] = lastCachedIndex;
  8396. objects[ lastCachedIndex ] = object;
  8397. // accounting is done, now do the same for all bindings
  8398. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8399. var bindingsForPath = bindings[ j ],
  8400. firstActive = bindingsForPath[ lastCachedIndex ],
  8401. binding = bindingsForPath[ index ];
  8402. bindingsForPath[ index ] = firstActive;
  8403. bindingsForPath[ lastCachedIndex ] = binding;
  8404. }
  8405. }
  8406. } // for arguments
  8407. this.nCachedObjects_ = nCachedObjects;
  8408. },
  8409. // remove & forget
  8410. uncache: function( var_args ) {
  8411. var objects = this._objects,
  8412. nObjects = objects.length,
  8413. nCachedObjects = this.nCachedObjects_,
  8414. indicesByUUID = this._indicesByUUID,
  8415. bindings = this._bindings,
  8416. nBindings = bindings.length;
  8417. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8418. var object = arguments[ i ],
  8419. uuid = object.uuid,
  8420. index = indicesByUUID[ uuid ];
  8421. if ( index !== undefined ) {
  8422. delete indicesByUUID[ uuid ];
  8423. if ( index < nCachedObjects ) {
  8424. // object is cached, shrink the CACHED region
  8425. var firstActiveIndex = -- nCachedObjects,
  8426. lastCachedObject = objects[ firstActiveIndex ],
  8427. lastIndex = -- nObjects,
  8428. lastObject = objects[ lastIndex ];
  8429. // last cached object takes this object's place
  8430. indicesByUUID[ lastCachedObject.uuid ] = index;
  8431. objects[ index ] = lastCachedObject;
  8432. // last object goes to the activated slot and pop
  8433. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  8434. objects[ firstActiveIndex ] = lastObject;
  8435. objects.pop();
  8436. // accounting is done, now do the same for all bindings
  8437. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8438. var bindingsForPath = bindings[ j ],
  8439. lastCached = bindingsForPath[ firstActiveIndex ],
  8440. last = bindingsForPath[ lastIndex ];
  8441. bindingsForPath[ index ] = lastCached;
  8442. bindingsForPath[ firstActiveIndex ] = last;
  8443. bindingsForPath.pop();
  8444. }
  8445. } else {
  8446. // object is active, just swap with the last and pop
  8447. var lastIndex = -- nObjects,
  8448. lastObject = objects[ lastIndex ];
  8449. indicesByUUID[ lastObject.uuid ] = index;
  8450. objects[ index ] = lastObject;
  8451. objects.pop();
  8452. // accounting is done, now do the same for all bindings
  8453. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8454. var bindingsForPath = bindings[ j ];
  8455. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  8456. bindingsForPath.pop();
  8457. }
  8458. } // cached or active
  8459. } // if object is known
  8460. } // for arguments
  8461. this.nCachedObjects_ = nCachedObjects;
  8462. },
  8463. // Internal interface used by befriended PropertyBinding.Composite:
  8464. subscribe_: function( path, parsedPath ) {
  8465. // returns an array of bindings for the given path that is changed
  8466. // according to the contained objects in the group
  8467. var indicesByPath = this._bindingsIndicesByPath,
  8468. index = indicesByPath[ path ],
  8469. bindings = this._bindings;
  8470. if ( index !== undefined ) return bindings[ index ];
  8471. var paths = this._paths,
  8472. parsedPaths = this._parsedPaths,
  8473. objects = this._objects,
  8474. nObjects = objects.length,
  8475. nCachedObjects = this.nCachedObjects_,
  8476. bindingsForPath = new Array( nObjects );
  8477. index = bindings.length;
  8478. indicesByPath[ path ] = index;
  8479. paths.push( path );
  8480. parsedPaths.push( parsedPath );
  8481. bindings.push( bindingsForPath );
  8482. for ( var i = nCachedObjects,
  8483. n = objects.length; i !== n; ++ i ) {
  8484. var object = objects[ i ];
  8485. bindingsForPath[ i ] =
  8486. new THREE.PropertyBinding( object, path, parsedPath );
  8487. }
  8488. return bindingsForPath;
  8489. },
  8490. unsubscribe_: function( path ) {
  8491. // tells the group to forget about a property path and no longer
  8492. // update the array previously obtained with 'subscribe_'
  8493. var indicesByPath = this._bindingsIndicesByPath,
  8494. index = indicesByPath[ path ];
  8495. if ( index !== undefined ) {
  8496. var paths = this._paths,
  8497. parsedPaths = this._parsedPaths,
  8498. bindings = this._bindings,
  8499. lastBindingsIndex = bindings.length - 1,
  8500. lastBindings = bindings[ lastBindingsIndex ],
  8501. lastBindingsPath = path[ lastBindingsIndex ];
  8502. indicesByPath[ lastBindingsPath ] = index;
  8503. bindings[ index ] = lastBindings;
  8504. bindings.pop();
  8505. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  8506. parsedPaths.pop();
  8507. paths[ index ] = paths[ lastBindingsIndex ];
  8508. paths.pop();
  8509. }
  8510. }
  8511. };
  8512. // File:src/animation/AnimationUtils.js
  8513. /**
  8514. * @author tschw
  8515. * @author Ben Houston / http://clara.io/
  8516. * @author David Sarno / http://lighthaus.us/
  8517. */
  8518. THREE.AnimationUtils = {
  8519. // same as Array.prototype.slice, but also works on typed arrays
  8520. arraySlice: function( array, from, to ) {
  8521. if ( THREE.AnimationUtils.isTypedArray( array ) ) {
  8522. return new array.constructor( array.subarray( from, to ) );
  8523. }
  8524. return array.slice( from, to );
  8525. },
  8526. // converts an array to a specific type
  8527. convertArray: function( array, type, forceClone ) {
  8528. if ( ! array || // let 'undefined' and 'null' pass
  8529. ! forceClone && array.constructor === type ) return array;
  8530. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  8531. return new type( array ); // create typed array
  8532. }
  8533. return Array.prototype.slice.call( array ); // create Array
  8534. },
  8535. isTypedArray: function( object ) {
  8536. return ArrayBuffer.isView( object ) &&
  8537. ! ( object instanceof DataView );
  8538. },
  8539. // returns an array by which times and values can be sorted
  8540. getKeyframeOrder: function( times ) {
  8541. function compareTime( i, j ) {
  8542. return times[ i ] - times[ j ];
  8543. }
  8544. var n = times.length;
  8545. var result = new Array( n );
  8546. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  8547. result.sort( compareTime );
  8548. return result;
  8549. },
  8550. // uses the array previously returned by 'getKeyframeOrder' to sort data
  8551. sortedArray: function( values, stride, order ) {
  8552. var nValues = values.length;
  8553. var result = new values.constructor( nValues );
  8554. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  8555. var srcOffset = order[ i ] * stride;
  8556. for ( var j = 0; j !== stride; ++ j ) {
  8557. result[ dstOffset ++ ] = values[ srcOffset + j ];
  8558. }
  8559. }
  8560. return result;
  8561. },
  8562. // function for parsing AOS keyframe formats
  8563. flattenJSON: function( jsonKeys, times, values, valuePropertyName ) {
  8564. var i = 1, key = jsonKeys[ 0 ];
  8565. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  8566. key = jsonKeys[ i ++ ];
  8567. }
  8568. if ( key === undefined ) return; // no data
  8569. var value = key[ valuePropertyName ];
  8570. if ( value === undefined ) return; // no data
  8571. if ( Array.isArray( value ) ) {
  8572. do {
  8573. value = key[ valuePropertyName ];
  8574. if ( value !== undefined ) {
  8575. times.push( key.time );
  8576. values.push.apply( values, value ); // push all elements
  8577. }
  8578. key = jsonKeys[ i ++ ];
  8579. } while ( key !== undefined );
  8580. } else if ( value.toArray !== undefined ) {
  8581. // ...assume THREE.Math-ish
  8582. do {
  8583. value = key[ valuePropertyName ];
  8584. if ( value !== undefined ) {
  8585. times.push( key.time );
  8586. value.toArray( values, values.length );
  8587. }
  8588. key = jsonKeys[ i ++ ];
  8589. } while ( key !== undefined );
  8590. } else {
  8591. // otherwise push as-is
  8592. do {
  8593. value = key[ valuePropertyName ];
  8594. if ( value !== undefined ) {
  8595. times.push( key.time );
  8596. values.push( value );
  8597. }
  8598. key = jsonKeys[ i ++ ];
  8599. } while ( key !== undefined );
  8600. }
  8601. }
  8602. };
  8603. // File:src/animation/KeyframeTrack.js
  8604. /**
  8605. *
  8606. * A timed sequence of keyframes for a specific property.
  8607. *
  8608. *
  8609. * @author Ben Houston / http://clara.io/
  8610. * @author David Sarno / http://lighthaus.us/
  8611. * @author tschw
  8612. */
  8613. THREE.KeyframeTrack = function ( name, times, values, interpolation ) {
  8614. if( name === undefined ) throw new Error( "track name is undefined" );
  8615. if( times === undefined || times.length === 0 ) {
  8616. throw new Error( "no keyframes in track named " + name );
  8617. }
  8618. this.name = name;
  8619. this.times = THREE.AnimationUtils.convertArray( times, this.TimeBufferType );
  8620. this.values = THREE.AnimationUtils.convertArray( values, this.ValueBufferType );
  8621. this.setInterpolation( interpolation || this.DefaultInterpolation );
  8622. this.validate();
  8623. this.optimize();
  8624. };
  8625. THREE.KeyframeTrack.prototype = {
  8626. constructor: THREE.KeyframeTrack,
  8627. TimeBufferType: Float32Array,
  8628. ValueBufferType: Float32Array,
  8629. DefaultInterpolation: THREE.InterpolateLinear,
  8630. InterpolantFactoryMethodDiscrete: function( result ) {
  8631. return new THREE.DiscreteInterpolant(
  8632. this.times, this.values, this.getValueSize(), result );
  8633. },
  8634. InterpolantFactoryMethodLinear: function( result ) {
  8635. return new THREE.LinearInterpolant(
  8636. this.times, this.values, this.getValueSize(), result );
  8637. },
  8638. InterpolantFactoryMethodSmooth: function( result ) {
  8639. return new THREE.CubicInterpolant(
  8640. this.times, this.values, this.getValueSize(), result );
  8641. },
  8642. setInterpolation: function( interpolation ) {
  8643. var factoryMethod = undefined;
  8644. switch ( interpolation ) {
  8645. case THREE.InterpolateDiscrete:
  8646. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  8647. break;
  8648. case THREE.InterpolateLinear:
  8649. factoryMethod = this.InterpolantFactoryMethodLinear;
  8650. break;
  8651. case THREE.InterpolateSmooth:
  8652. factoryMethod = this.InterpolantFactoryMethodSmooth;
  8653. break;
  8654. }
  8655. if ( factoryMethod === undefined ) {
  8656. var message = "unsupported interpolation for " +
  8657. this.ValueTypeName + " keyframe track named " + this.name;
  8658. if ( this.createInterpolant === undefined ) {
  8659. // fall back to default, unless the default itself is messed up
  8660. if ( interpolation !== this.DefaultInterpolation ) {
  8661. this.setInterpolation( this.DefaultInterpolation );
  8662. } else {
  8663. throw new Error( message ); // fatal, in this case
  8664. }
  8665. }
  8666. console.warn( message );
  8667. return;
  8668. }
  8669. this.createInterpolant = factoryMethod;
  8670. },
  8671. getInterpolation: function() {
  8672. switch ( this.createInterpolant ) {
  8673. case this.InterpolantFactoryMethodDiscrete:
  8674. return THREE.InterpolateDiscrete;
  8675. case this.InterpolantFactoryMethodLinear:
  8676. return THREE.InterpolateLinear;
  8677. case this.InterpolantFactoryMethodSmooth:
  8678. return THREE.InterpolateSmooth;
  8679. }
  8680. },
  8681. getValueSize: function() {
  8682. return this.values.length / this.times.length;
  8683. },
  8684. // move all keyframes either forwards or backwards in time
  8685. shift: function( timeOffset ) {
  8686. if( timeOffset !== 0.0 ) {
  8687. var times = this.times;
  8688. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8689. times[ i ] += timeOffset;
  8690. }
  8691. }
  8692. return this;
  8693. },
  8694. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  8695. scale: function( timeScale ) {
  8696. if( timeScale !== 1.0 ) {
  8697. var times = this.times;
  8698. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8699. times[ i ] *= timeScale;
  8700. }
  8701. }
  8702. return this;
  8703. },
  8704. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  8705. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  8706. trim: function( startTime, endTime ) {
  8707. var times = this.times,
  8708. nKeys = times.length,
  8709. from = 0,
  8710. to = nKeys - 1;
  8711. while ( from !== nKeys && times[ from ] < startTime ) ++ from;
  8712. while ( to !== -1 && times[ to ] > endTime ) -- to;
  8713. ++ to; // inclusive -> exclusive bound
  8714. if( from !== 0 || to !== nKeys ) {
  8715. // empty tracks are forbidden, so keep at least one keyframe
  8716. if ( from >= to ) to = Math.max( to , 1 ), from = to - 1;
  8717. var stride = this.getValueSize();
  8718. this.times = THREE.AnimationUtils.arraySlice( times, from, to );
  8719. this.values = THREE.AnimationUtils.
  8720. arraySlice( this.values, from * stride, to * stride );
  8721. }
  8722. return this;
  8723. },
  8724. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  8725. validate: function() {
  8726. var valid = true;
  8727. var valueSize = this.getValueSize();
  8728. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  8729. console.error( "invalid value size in track", this );
  8730. valid = false;
  8731. }
  8732. var times = this.times,
  8733. values = this.values,
  8734. nKeys = times.length;
  8735. if( nKeys === 0 ) {
  8736. console.error( "track is empty", this );
  8737. valid = false;
  8738. }
  8739. var prevTime = null;
  8740. for( var i = 0; i !== nKeys; i ++ ) {
  8741. var currTime = times[ i ];
  8742. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  8743. console.error( "time is not a valid number", this, i, currTime );
  8744. valid = false;
  8745. break;
  8746. }
  8747. if( prevTime !== null && prevTime > currTime ) {
  8748. console.error( "out of order keys", this, i, currTime, prevTime );
  8749. valid = false;
  8750. break;
  8751. }
  8752. prevTime = currTime;
  8753. }
  8754. if ( values !== undefined ) {
  8755. if ( THREE.AnimationUtils.isTypedArray( values ) ) {
  8756. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  8757. var value = values[ i ];
  8758. if ( isNaN( value ) ) {
  8759. console.error( "value is not a valid number", this, i, value );
  8760. valid = false;
  8761. break;
  8762. }
  8763. }
  8764. }
  8765. }
  8766. return valid;
  8767. },
  8768. // removes equivalent sequential keys as common in morph target sequences
  8769. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  8770. optimize: function() {
  8771. var times = this.times,
  8772. values = this.values,
  8773. stride = this.getValueSize(),
  8774. writeIndex = 1;
  8775. for( var i = 1, n = times.length - 1; i <= n; ++ i ) {
  8776. var keep = false;
  8777. var time = times[ i ];
  8778. var timeNext = times[ i + 1 ];
  8779. // remove adjacent keyframes scheduled at the same time
  8780. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  8781. // remove unnecessary keyframes same as their neighbors
  8782. var offset = i * stride,
  8783. offsetP = offset - stride,
  8784. offsetN = offset + stride;
  8785. for ( var j = 0; j !== stride; ++ j ) {
  8786. var value = values[ offset + j ];
  8787. if ( value !== values[ offsetP + j ] ||
  8788. value !== values[ offsetN + j ] ) {
  8789. keep = true;
  8790. break;
  8791. }
  8792. }
  8793. }
  8794. // in-place compaction
  8795. if ( keep ) {
  8796. if ( i !== writeIndex ) {
  8797. times[ writeIndex ] = times[ i ];
  8798. var readOffset = i * stride,
  8799. writeOffset = writeIndex * stride;
  8800. for ( var j = 0; j !== stride; ++ j ) {
  8801. values[ writeOffset + j ] = values[ readOffset + j ];
  8802. }
  8803. }
  8804. ++ writeIndex;
  8805. }
  8806. }
  8807. if ( writeIndex !== times.length ) {
  8808. this.times = THREE.AnimationUtils.arraySlice( times, 0, writeIndex );
  8809. this.values = THREE.AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  8810. }
  8811. return this;
  8812. }
  8813. };
  8814. // Static methods:
  8815. Object.assign( THREE.KeyframeTrack, {
  8816. // Serialization (in static context, because of constructor invocation
  8817. // and automatic invocation of .toJSON):
  8818. parse: function( json ) {
  8819. if( json.type === undefined ) {
  8820. throw new Error( "track type undefined, can not parse" );
  8821. }
  8822. var trackType = THREE.KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  8823. if ( json.times === undefined ) {
  8824. console.warn( "legacy JSON format detected, converting" );
  8825. var times = [], values = [];
  8826. THREE.AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  8827. json.times = times;
  8828. json.values = values;
  8829. }
  8830. // derived classes can define a static parse method
  8831. if ( trackType.parse !== undefined ) {
  8832. return trackType.parse( json );
  8833. } else {
  8834. // by default, we asssume a constructor compatible with the base
  8835. return new trackType(
  8836. json.name, json.times, json.values, json.interpolation );
  8837. }
  8838. },
  8839. toJSON: function( track ) {
  8840. var trackType = track.constructor;
  8841. var json;
  8842. // derived classes can define a static toJSON method
  8843. if ( trackType.toJSON !== undefined ) {
  8844. json = trackType.toJSON( track );
  8845. } else {
  8846. // by default, we assume the data can be serialized as-is
  8847. json = {
  8848. 'name': track.name,
  8849. 'times': THREE.AnimationUtils.convertArray( track.times, Array ),
  8850. 'values': THREE.AnimationUtils.convertArray( track.values, Array )
  8851. };
  8852. var interpolation = track.getInterpolation();
  8853. if ( interpolation !== track.DefaultInterpolation ) {
  8854. json.interpolation = interpolation;
  8855. }
  8856. }
  8857. json.type = track.ValueTypeName; // mandatory
  8858. return json;
  8859. },
  8860. _getTrackTypeForValueTypeName: function( typeName ) {
  8861. switch( typeName.toLowerCase() ) {
  8862. case "scalar":
  8863. case "double":
  8864. case "float":
  8865. case "number":
  8866. case "integer":
  8867. return THREE.NumberKeyframeTrack;
  8868. case "vector":
  8869. case "vector2":
  8870. case "vector3":
  8871. case "vector4":
  8872. return THREE.VectorKeyframeTrack;
  8873. case "color":
  8874. return THREE.ColorKeyframeTrack;
  8875. case "quaternion":
  8876. return THREE.QuaternionKeyframeTrack;
  8877. case "bool":
  8878. case "boolean":
  8879. return THREE.BooleanKeyframeTrack;
  8880. case "string":
  8881. return THREE.StringKeyframeTrack;
  8882. };
  8883. throw new Error( "Unsupported typeName: " + typeName );
  8884. }
  8885. } );
  8886. // File:src/animation/PropertyBinding.js
  8887. /**
  8888. *
  8889. * A reference to a real property in the scene graph.
  8890. *
  8891. *
  8892. * @author Ben Houston / http://clara.io/
  8893. * @author David Sarno / http://lighthaus.us/
  8894. * @author tschw
  8895. */
  8896. THREE.PropertyBinding = function ( rootNode, path, parsedPath ) {
  8897. this.path = path;
  8898. this.parsedPath = parsedPath ||
  8899. THREE.PropertyBinding.parseTrackName( path );
  8900. this.node = THREE.PropertyBinding.findNode(
  8901. rootNode, this.parsedPath.nodeName ) || rootNode;
  8902. this.rootNode = rootNode;
  8903. };
  8904. THREE.PropertyBinding.prototype = {
  8905. constructor: THREE.PropertyBinding,
  8906. getValue: function getValue_unbound( targetArray, offset ) {
  8907. this.bind();
  8908. this.getValue( targetArray, offset );
  8909. // Note: This class uses a State pattern on a per-method basis:
  8910. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  8911. // prototype version of these methods with one that represents
  8912. // the bound state. When the property is not found, the methods
  8913. // become no-ops.
  8914. },
  8915. setValue: function getValue_unbound( sourceArray, offset ) {
  8916. this.bind();
  8917. this.setValue( sourceArray, offset );
  8918. },
  8919. // create getter / setter pair for a property in the scene graph
  8920. bind: function() {
  8921. var targetObject = this.node,
  8922. parsedPath = this.parsedPath,
  8923. objectName = parsedPath.objectName,
  8924. propertyName = parsedPath.propertyName,
  8925. propertyIndex = parsedPath.propertyIndex;
  8926. if ( ! targetObject ) {
  8927. targetObject = THREE.PropertyBinding.findNode(
  8928. this.rootNode, parsedPath.nodeName ) || this.rootNode;
  8929. this.node = targetObject;
  8930. }
  8931. // set fail state so we can just 'return' on error
  8932. this.getValue = this._getValue_unavailable;
  8933. this.setValue = this._setValue_unavailable;
  8934. // ensure there is a value node
  8935. if ( ! targetObject ) {
  8936. console.error( " trying to update node for track: " + this.path + " but it wasn't found." );
  8937. return;
  8938. }
  8939. if( objectName ) {
  8940. var objectIndex = parsedPath.objectIndex;
  8941. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  8942. switch ( objectName ) {
  8943. case 'materials':
  8944. if( ! targetObject.material ) {
  8945. console.error( ' can not bind to material as node does not have a material', this );
  8946. return;
  8947. }
  8948. if( ! targetObject.material.materials ) {
  8949. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  8950. return;
  8951. }
  8952. targetObject = targetObject.material.materials;
  8953. break;
  8954. case 'bones':
  8955. if( ! targetObject.skeleton ) {
  8956. console.error( ' can not bind to bones as node does not have a skeleton', this );
  8957. return;
  8958. }
  8959. // potential future optimization: skip this if propertyIndex is already an integer
  8960. // and convert the integer string to a true integer.
  8961. targetObject = targetObject.skeleton.bones;
  8962. // support resolving morphTarget names into indices.
  8963. for ( var i = 0; i < targetObject.length; i ++ ) {
  8964. if ( targetObject[i].name === objectIndex ) {
  8965. objectIndex = i;
  8966. break;
  8967. }
  8968. }
  8969. break;
  8970. default:
  8971. if ( targetObject[ objectName ] === undefined ) {
  8972. console.error( ' can not bind to objectName of node, undefined', this );
  8973. return;
  8974. }
  8975. targetObject = targetObject[ objectName ];
  8976. }
  8977. if ( objectIndex !== undefined ) {
  8978. if( targetObject[ objectIndex ] === undefined ) {
  8979. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  8980. return;
  8981. }
  8982. targetObject = targetObject[ objectIndex ];
  8983. }
  8984. }
  8985. // resolve property
  8986. var nodeProperty = targetObject[ propertyName ];
  8987. if ( ! nodeProperty ) {
  8988. var nodeName = parsedPath.nodeName;
  8989. console.error( " trying to update property for track: " + nodeName +
  8990. '.' + propertyName + " but it wasn't found.", targetObject );
  8991. return;
  8992. }
  8993. // determine versioning scheme
  8994. var versioning = this.Versioning.None;
  8995. if ( targetObject.needsUpdate !== undefined ) { // material
  8996. versioning = this.Versioning.NeedsUpdate;
  8997. this.targetObject = targetObject;
  8998. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  8999. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  9000. this.targetObject = targetObject;
  9001. }
  9002. // determine how the property gets bound
  9003. var bindingType = this.BindingType.Direct;
  9004. if ( propertyIndex !== undefined ) {
  9005. // access a sub element of the property array (only primitives are supported right now)
  9006. if ( propertyName === "morphTargetInfluences" ) {
  9007. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  9008. // support resolving morphTarget names into indices.
  9009. if ( ! targetObject.geometry ) {
  9010. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  9011. return;
  9012. }
  9013. if ( ! targetObject.geometry.morphTargets ) {
  9014. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  9015. return;
  9016. }
  9017. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  9018. if ( targetObject.geometry.morphTargets[i].name === propertyIndex ) {
  9019. propertyIndex = i;
  9020. break;
  9021. }
  9022. }
  9023. }
  9024. bindingType = this.BindingType.ArrayElement;
  9025. this.resolvedProperty = nodeProperty;
  9026. this.propertyIndex = propertyIndex;
  9027. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  9028. // must use copy for Object3D.Euler/Quaternion
  9029. bindingType = this.BindingType.HasFromToArray;
  9030. this.resolvedProperty = nodeProperty;
  9031. } else if ( nodeProperty.length !== undefined ) {
  9032. bindingType = this.BindingType.EntireArray;
  9033. this.resolvedProperty = nodeProperty;
  9034. } else {
  9035. this.propertyName = propertyName;
  9036. }
  9037. // select getter / setter
  9038. this.getValue = this.GetterByBindingType[ bindingType ];
  9039. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  9040. },
  9041. unbind: function() {
  9042. this.node = null;
  9043. // back to the prototype version of getValue / setValue
  9044. // note: avoiding to mutate the shape of 'this' via 'delete'
  9045. this.getValue = this._getValue_unbound;
  9046. this.setValue = this._setValue_unbound;
  9047. }
  9048. };
  9049. Object.assign( THREE.PropertyBinding.prototype, { // prototype, continued
  9050. // these are used to "bind" a nonexistent property
  9051. _getValue_unavailable: function() {},
  9052. _setValue_unavailable: function() {},
  9053. // initial state of these methods that calls 'bind'
  9054. _getValue_unbound: THREE.PropertyBinding.prototype.getValue,
  9055. _setValue_unbound: THREE.PropertyBinding.prototype.setValue,
  9056. BindingType: {
  9057. Direct: 0,
  9058. EntireArray: 1,
  9059. ArrayElement: 2,
  9060. HasFromToArray: 3
  9061. },
  9062. Versioning: {
  9063. None: 0,
  9064. NeedsUpdate: 1,
  9065. MatrixWorldNeedsUpdate: 2
  9066. },
  9067. GetterByBindingType: [
  9068. function getValue_direct( buffer, offset ) {
  9069. buffer[ offset ] = this.node[ this.propertyName ];
  9070. },
  9071. function getValue_array( buffer, offset ) {
  9072. var source = this.resolvedProperty;
  9073. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  9074. buffer[ offset ++ ] = source[ i ];
  9075. }
  9076. },
  9077. function getValue_arrayElement( buffer, offset ) {
  9078. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  9079. },
  9080. function getValue_toArray( buffer, offset ) {
  9081. this.resolvedProperty.toArray( buffer, offset );
  9082. }
  9083. ],
  9084. SetterByBindingTypeAndVersioning: [
  9085. [
  9086. // Direct
  9087. function setValue_direct( buffer, offset ) {
  9088. this.node[ this.propertyName ] = buffer[ offset ];
  9089. },
  9090. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  9091. this.node[ this.propertyName ] = buffer[ offset ];
  9092. this.targetObject.needsUpdate = true;
  9093. },
  9094. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9095. this.node[ this.propertyName ] = buffer[ offset ];
  9096. this.targetObject.matrixWorldNeedsUpdate = true;
  9097. }
  9098. ], [
  9099. // EntireArray
  9100. function setValue_array( buffer, offset ) {
  9101. var dest = this.resolvedProperty;
  9102. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9103. dest[ i ] = buffer[ offset ++ ];
  9104. }
  9105. },
  9106. function setValue_array_setNeedsUpdate( buffer, offset ) {
  9107. var dest = this.resolvedProperty;
  9108. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9109. dest[ i ] = buffer[ offset ++ ];
  9110. }
  9111. this.targetObject.needsUpdate = true;
  9112. },
  9113. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9114. var dest = this.resolvedProperty;
  9115. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9116. dest[ i ] = buffer[ offset ++ ];
  9117. }
  9118. this.targetObject.matrixWorldNeedsUpdate = true;
  9119. }
  9120. ], [
  9121. // ArrayElement
  9122. function setValue_arrayElement( buffer, offset ) {
  9123. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9124. },
  9125. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  9126. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9127. this.targetObject.needsUpdate = true;
  9128. },
  9129. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9130. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9131. this.targetObject.matrixWorldNeedsUpdate = true;
  9132. }
  9133. ], [
  9134. // HasToFromArray
  9135. function setValue_fromArray( buffer, offset ) {
  9136. this.resolvedProperty.fromArray( buffer, offset );
  9137. },
  9138. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  9139. this.resolvedProperty.fromArray( buffer, offset );
  9140. this.targetObject.needsUpdate = true;
  9141. },
  9142. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9143. this.resolvedProperty.fromArray( buffer, offset );
  9144. this.targetObject.matrixWorldNeedsUpdate = true;
  9145. }
  9146. ]
  9147. ]
  9148. } );
  9149. THREE.PropertyBinding.Composite =
  9150. function( targetGroup, path, optionalParsedPath ) {
  9151. var parsedPath = optionalParsedPath ||
  9152. THREE.PropertyBinding.parseTrackName( path );
  9153. this._targetGroup = targetGroup;
  9154. this._bindings = targetGroup.subscribe_( path, parsedPath );
  9155. };
  9156. THREE.PropertyBinding.Composite.prototype = {
  9157. constructor: THREE.PropertyBinding.Composite,
  9158. getValue: function( array, offset ) {
  9159. this.bind(); // bind all binding
  9160. var firstValidIndex = this._targetGroup.nCachedObjects_,
  9161. binding = this._bindings[ firstValidIndex ];
  9162. // and only call .getValue on the first
  9163. if ( binding !== undefined ) binding.getValue( array, offset );
  9164. },
  9165. setValue: function( array, offset ) {
  9166. var bindings = this._bindings;
  9167. for ( var i = this._targetGroup.nCachedObjects_,
  9168. n = bindings.length; i !== n; ++ i ) {
  9169. bindings[ i ].setValue( array, offset );
  9170. }
  9171. },
  9172. bind: function() {
  9173. var bindings = this._bindings;
  9174. for ( var i = this._targetGroup.nCachedObjects_,
  9175. n = bindings.length; i !== n; ++ i ) {
  9176. bindings[ i ].bind();
  9177. }
  9178. },
  9179. unbind: function() {
  9180. var bindings = this._bindings;
  9181. for ( var i = this._targetGroup.nCachedObjects_,
  9182. n = bindings.length; i !== n; ++ i ) {
  9183. bindings[ i ].unbind();
  9184. }
  9185. }
  9186. };
  9187. THREE.PropertyBinding.create = function( root, path, parsedPath ) {
  9188. if ( ! ( root instanceof THREE.AnimationObjectGroup ) ) {
  9189. return new THREE.PropertyBinding( root, path, parsedPath );
  9190. } else {
  9191. return new THREE.PropertyBinding.Composite( root, path, parsedPath );
  9192. }
  9193. };
  9194. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  9195. // matches strings in the form of:
  9196. // nodeName.property
  9197. // nodeName.property[accessor]
  9198. // nodeName.material.property[accessor]
  9199. // uuid.property[accessor]
  9200. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  9201. // parentName/nodeName.property
  9202. // parentName/parentName/nodeName.property[index]
  9203. // .bone[Armature.DEF_cog].position
  9204. // created and tested via https://regex101.com/#javascript
  9205. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_.:\- ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  9206. var matches = re.exec(trackName);
  9207. if( ! matches ) {
  9208. throw new Error( "cannot parse trackName at all: " + trackName );
  9209. }
  9210. if (matches.index === re.lastIndex) {
  9211. re.lastIndex++;
  9212. }
  9213. var results = {
  9214. // directoryName: matches[1], // (tschw) currently unused
  9215. nodeName: matches[3], // allowed to be null, specified root node.
  9216. objectName: matches[5],
  9217. objectIndex: matches[7],
  9218. propertyName: matches[9],
  9219. propertyIndex: matches[11] // allowed to be null, specifies that the whole property is set.
  9220. };
  9221. if( results.propertyName === null || results.propertyName.length === 0 ) {
  9222. throw new Error( "can not parse propertyName from trackName: " + trackName );
  9223. }
  9224. return results;
  9225. };
  9226. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  9227. if( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  9228. return root;
  9229. }
  9230. // search into skeleton bones.
  9231. if( root.skeleton ) {
  9232. var searchSkeleton = function( skeleton ) {
  9233. for( var i = 0; i < skeleton.bones.length; i ++ ) {
  9234. var bone = skeleton.bones[i];
  9235. if( bone.name === nodeName ) {
  9236. return bone;
  9237. }
  9238. }
  9239. return null;
  9240. };
  9241. var bone = searchSkeleton( root.skeleton );
  9242. if( bone ) {
  9243. return bone;
  9244. }
  9245. }
  9246. // search into node subtree.
  9247. if( root.children ) {
  9248. var searchNodeSubtree = function( children ) {
  9249. for( var i = 0; i < children.length; i ++ ) {
  9250. var childNode = children[i];
  9251. if( childNode.name === nodeName || childNode.uuid === nodeName ) {
  9252. return childNode;
  9253. }
  9254. var result = searchNodeSubtree( childNode.children );
  9255. if( result ) return result;
  9256. }
  9257. return null;
  9258. };
  9259. var subTreeNode = searchNodeSubtree( root.children );
  9260. if( subTreeNode ) {
  9261. return subTreeNode;
  9262. }
  9263. }
  9264. return null;
  9265. }
  9266. // File:src/animation/PropertyMixer.js
  9267. /**
  9268. *
  9269. * Buffered scene graph property that allows weighted accumulation.
  9270. *
  9271. *
  9272. * @author Ben Houston / http://clara.io/
  9273. * @author David Sarno / http://lighthaus.us/
  9274. * @author tschw
  9275. */
  9276. THREE.PropertyMixer = function ( binding, typeName, valueSize ) {
  9277. this.binding = binding;
  9278. this.valueSize = valueSize;
  9279. var bufferType = Float64Array,
  9280. mixFunction;
  9281. switch ( typeName ) {
  9282. case 'quaternion': mixFunction = this._slerp; break;
  9283. case 'string':
  9284. case 'bool':
  9285. bufferType = Array, mixFunction = this._select; break;
  9286. default: mixFunction = this._lerp;
  9287. }
  9288. this.buffer = new bufferType( valueSize * 4 );
  9289. // layout: [ incoming | accu0 | accu1 | orig ]
  9290. //
  9291. // interpolators can use .buffer as their .result
  9292. // the data then goes to 'incoming'
  9293. //
  9294. // 'accu0' and 'accu1' are used frame-interleaved for
  9295. // the cumulative result and are compared to detect
  9296. // changes
  9297. //
  9298. // 'orig' stores the original state of the property
  9299. this._mixBufferRegion = mixFunction;
  9300. this.cumulativeWeight = 0;
  9301. this.useCount = 0;
  9302. this.referenceCount = 0;
  9303. };
  9304. THREE.PropertyMixer.prototype = {
  9305. constructor: THREE.PropertyMixer,
  9306. // accumulate data in the 'incoming' region into 'accu<i>'
  9307. accumulate: function( accuIndex, weight ) {
  9308. // note: happily accumulating nothing when weight = 0, the caller knows
  9309. // the weight and shouldn't have made the call in the first place
  9310. var buffer = this.buffer,
  9311. stride = this.valueSize,
  9312. offset = accuIndex * stride + stride,
  9313. currentWeight = this.cumulativeWeight;
  9314. if ( currentWeight === 0 ) {
  9315. // accuN := incoming * weight
  9316. for ( var i = 0; i !== stride; ++ i ) {
  9317. buffer[ offset + i ] = buffer[ i ];
  9318. }
  9319. currentWeight = weight;
  9320. } else {
  9321. // accuN := accuN + incoming * weight
  9322. currentWeight += weight;
  9323. var mix = weight / currentWeight;
  9324. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  9325. }
  9326. this.cumulativeWeight = currentWeight;
  9327. },
  9328. // apply the state of 'accu<i>' to the binding when accus differ
  9329. apply: function( accuIndex ) {
  9330. var stride = this.valueSize,
  9331. buffer = this.buffer,
  9332. offset = accuIndex * stride + stride,
  9333. weight = this.cumulativeWeight,
  9334. binding = this.binding;
  9335. this.cumulativeWeight = 0;
  9336. if ( weight < 1 ) {
  9337. // accuN := accuN + original * ( 1 - cumulativeWeight )
  9338. var originalValueOffset = stride * 3;
  9339. this._mixBufferRegion(
  9340. buffer, offset, originalValueOffset, 1 - weight, stride );
  9341. }
  9342. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  9343. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  9344. // value has changed -> update scene graph
  9345. binding.setValue( buffer, offset );
  9346. break;
  9347. }
  9348. }
  9349. },
  9350. // remember the state of the bound property and copy it to both accus
  9351. saveOriginalState: function() {
  9352. var binding = this.binding;
  9353. var buffer = this.buffer,
  9354. stride = this.valueSize,
  9355. originalValueOffset = stride * 3;
  9356. binding.getValue( buffer, originalValueOffset );
  9357. // accu[0..1] := orig -- initially detect changes against the original
  9358. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  9359. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  9360. }
  9361. this.cumulativeWeight = 0;
  9362. },
  9363. // apply the state previously taken via 'saveOriginalState' to the binding
  9364. restoreOriginalState: function() {
  9365. var originalValueOffset = this.valueSize * 3;
  9366. this.binding.setValue( this.buffer, originalValueOffset );
  9367. },
  9368. // mix functions
  9369. _select: function( buffer, dstOffset, srcOffset, t, stride ) {
  9370. if ( t >= 0.5 ) {
  9371. for ( var i = 0; i !== stride; ++ i ) {
  9372. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  9373. }
  9374. }
  9375. },
  9376. _slerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9377. THREE.Quaternion.slerpFlat( buffer, dstOffset,
  9378. buffer, dstOffset, buffer, srcOffset, t );
  9379. },
  9380. _lerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9381. var s = 1 - t;
  9382. for ( var i = 0; i !== stride; ++ i ) {
  9383. var j = dstOffset + i;
  9384. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  9385. }
  9386. }
  9387. };
  9388. // File:src/animation/tracks/BooleanKeyframeTrack.js
  9389. /**
  9390. *
  9391. * A Track of Boolean keyframe values.
  9392. *
  9393. *
  9394. * @author Ben Houston / http://clara.io/
  9395. * @author David Sarno / http://lighthaus.us/
  9396. * @author tschw
  9397. */
  9398. THREE.BooleanKeyframeTrack = function ( name, times, values ) {
  9399. THREE.KeyframeTrack.call( this, name, times, values );
  9400. };
  9401. THREE.BooleanKeyframeTrack.prototype =
  9402. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9403. constructor: THREE.BooleanKeyframeTrack,
  9404. ValueTypeName: 'bool',
  9405. ValueBufferType: Array,
  9406. DefaultInterpolation: THREE.IntepolateDiscrete,
  9407. InterpolantFactoryMethodLinear: undefined,
  9408. InterpolantFactoryMethodSmooth: undefined
  9409. // Note: Actually this track could have a optimized / compressed
  9410. // representation of a single value and a custom interpolant that
  9411. // computes "firstValue ^ isOdd( index )".
  9412. } );
  9413. // File:src/animation/tracks/NumberKeyframeTrack.js
  9414. /**
  9415. *
  9416. * A Track of numeric keyframe values.
  9417. *
  9418. * @author Ben Houston / http://clara.io/
  9419. * @author David Sarno / http://lighthaus.us/
  9420. * @author tschw
  9421. */
  9422. THREE.NumberKeyframeTrack = function ( name, times, values, interpolation ) {
  9423. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9424. };
  9425. THREE.NumberKeyframeTrack.prototype =
  9426. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9427. constructor: THREE.NumberKeyframeTrack,
  9428. ValueTypeName: 'number',
  9429. // ValueBufferType is inherited
  9430. // DefaultInterpolation is inherited
  9431. } );
  9432. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  9433. /**
  9434. *
  9435. * A Track of quaternion keyframe values.
  9436. *
  9437. * @author Ben Houston / http://clara.io/
  9438. * @author David Sarno / http://lighthaus.us/
  9439. * @author tschw
  9440. */
  9441. THREE.QuaternionKeyframeTrack = function ( name, times, values, interpolation ) {
  9442. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9443. };
  9444. THREE.QuaternionKeyframeTrack.prototype =
  9445. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9446. constructor: THREE.QuaternionKeyframeTrack,
  9447. ValueTypeName: 'quaternion',
  9448. // ValueBufferType is inherited
  9449. DefaultInterpolation: THREE.InterpolateLinear,
  9450. InterpolantFactoryMethodLinear: function( result ) {
  9451. return new THREE.QuaternionLinearInterpolant(
  9452. this.times, this.values, this.getValueSize(), result );
  9453. },
  9454. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  9455. } );
  9456. // File:src/animation/tracks/StringKeyframeTrack.js
  9457. /**
  9458. *
  9459. * A Track that interpolates Strings
  9460. *
  9461. *
  9462. * @author Ben Houston / http://clara.io/
  9463. * @author David Sarno / http://lighthaus.us/
  9464. * @author tschw
  9465. */
  9466. THREE.StringKeyframeTrack = function ( name, times, values, interpolation ) {
  9467. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9468. };
  9469. THREE.StringKeyframeTrack.prototype =
  9470. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9471. constructor: THREE.StringKeyframeTrack,
  9472. ValueTypeName: 'string',
  9473. ValueBufferType: Array,
  9474. DefaultInterpolation: THREE.IntepolateDiscrete,
  9475. InterpolantFactoryMethodLinear: undefined,
  9476. InterpolantFactoryMethodSmooth: undefined
  9477. } );
  9478. // File:src/animation/tracks/VectorKeyframeTrack.js
  9479. /**
  9480. *
  9481. * A Track of vectored keyframe values.
  9482. *
  9483. *
  9484. * @author Ben Houston / http://clara.io/
  9485. * @author David Sarno / http://lighthaus.us/
  9486. * @author tschw
  9487. */
  9488. THREE.VectorKeyframeTrack = function ( name, times, values, interpolation ) {
  9489. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9490. };
  9491. THREE.VectorKeyframeTrack.prototype =
  9492. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9493. constructor: THREE.VectorKeyframeTrack,
  9494. ValueTypeName: 'vector'
  9495. // ValueBufferType is inherited
  9496. // DefaultInterpolation is inherited
  9497. } );
  9498. // File:src/audio/Audio.js
  9499. /**
  9500. * @author mrdoob / http://mrdoob.com/
  9501. */
  9502. THREE.Audio = function ( listener ) {
  9503. THREE.Object3D.call( this );
  9504. this.type = 'Audio';
  9505. this.context = listener.context;
  9506. this.source = this.context.createBufferSource();
  9507. this.source.onended = this.onEnded.bind( this );
  9508. this.gain = this.context.createGain();
  9509. this.gain.connect( listener.getInput() );
  9510. this.autoplay = false;
  9511. this.startTime = 0;
  9512. this.playbackRate = 1;
  9513. this.isPlaying = false;
  9514. this.hasPlaybackControl = true;
  9515. this.sourceType = 'empty';
  9516. this.filter = null;
  9517. };
  9518. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  9519. THREE.Audio.prototype.constructor = THREE.Audio;
  9520. THREE.Audio.prototype.getOutput = function () {
  9521. return this.gain;
  9522. };
  9523. THREE.Audio.prototype.load = function ( file ) {
  9524. var buffer = new THREE.AudioBuffer( this.context );
  9525. buffer.load( file );
  9526. this.setBuffer( buffer );
  9527. return this;
  9528. };
  9529. THREE.Audio.prototype.setNodeSource = function ( audioNode ) {
  9530. this.hasPlaybackControl = false;
  9531. this.sourceType = 'audioNode';
  9532. this.source = audioNode;
  9533. this.connect();
  9534. return this;
  9535. };
  9536. THREE.Audio.prototype.setBuffer = function ( audioBuffer ) {
  9537. var scope = this;
  9538. audioBuffer.onReady( function( buffer ) {
  9539. scope.source.buffer = buffer;
  9540. scope.sourceType = 'buffer';
  9541. if ( scope.autoplay ) scope.play();
  9542. } );
  9543. return this;
  9544. };
  9545. THREE.Audio.prototype.play = function () {
  9546. if ( this.isPlaying === true ) {
  9547. console.warn( 'THREE.Audio: Audio is already playing.' );
  9548. return;
  9549. }
  9550. if ( this.hasPlaybackControl === false ) {
  9551. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9552. return;
  9553. }
  9554. var source = this.context.createBufferSource();
  9555. source.buffer = this.source.buffer;
  9556. source.loop = this.source.loop;
  9557. source.onended = this.source.onended;
  9558. source.start( 0, this.startTime );
  9559. source.playbackRate.value = this.playbackRate;
  9560. this.isPlaying = true;
  9561. this.source = source;
  9562. this.connect();
  9563. };
  9564. THREE.Audio.prototype.pause = function () {
  9565. if ( this.hasPlaybackControl === false ) {
  9566. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9567. return;
  9568. }
  9569. this.source.stop();
  9570. this.startTime = this.context.currentTime;
  9571. };
  9572. THREE.Audio.prototype.stop = function () {
  9573. if ( this.hasPlaybackControl === false ) {
  9574. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9575. return;
  9576. }
  9577. this.source.stop();
  9578. this.startTime = 0;
  9579. };
  9580. THREE.Audio.prototype.connect = function () {
  9581. if ( this.filter !== null ) {
  9582. this.source.connect( this.filter );
  9583. this.filter.connect( this.getOutput() );
  9584. } else {
  9585. this.source.connect( this.getOutput() );
  9586. }
  9587. };
  9588. THREE.Audio.prototype.disconnect = function () {
  9589. if ( this.filter !== null ) {
  9590. this.source.disconnect( this.filter );
  9591. this.filter.disconnect( this.getOutput() );
  9592. } else {
  9593. this.source.disconnect( this.getOutput() );
  9594. }
  9595. };
  9596. THREE.Audio.prototype.getFilter = function () {
  9597. return this.filter;
  9598. };
  9599. THREE.Audio.prototype.setFilter = function ( value ) {
  9600. if ( value === undefined ) value = null;
  9601. if ( this.isPlaying === true ) {
  9602. this.disconnect();
  9603. this.filter = value;
  9604. this.connect();
  9605. } else {
  9606. this.filter = value;
  9607. }
  9608. };
  9609. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  9610. if ( this.hasPlaybackControl === false ) {
  9611. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9612. return;
  9613. }
  9614. this.playbackRate = value;
  9615. if ( this.isPlaying === true ) {
  9616. this.source.playbackRate.value = this.playbackRate;
  9617. }
  9618. };
  9619. THREE.Audio.prototype.getPlaybackRate = function () {
  9620. return this.playbackRate;
  9621. };
  9622. THREE.Audio.prototype.onEnded = function() {
  9623. this.isPlaying = false;
  9624. };
  9625. THREE.Audio.prototype.setLoop = function ( value ) {
  9626. if ( this.hasPlaybackControl === false ) {
  9627. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9628. return;
  9629. }
  9630. this.source.loop = value;
  9631. };
  9632. THREE.Audio.prototype.getLoop = function () {
  9633. if ( this.hasPlaybackControl === false ) {
  9634. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9635. return false;
  9636. }
  9637. return this.source.loop;
  9638. };
  9639. THREE.Audio.prototype.setVolume = function ( value ) {
  9640. this.gain.gain.value = value;
  9641. };
  9642. THREE.Audio.prototype.getVolume = function () {
  9643. return this.gain.gain.value;
  9644. };
  9645. // File:src/audio/AudioAnalyser.js
  9646. /**
  9647. * @author mrdoob / http://mrdoob.com/
  9648. */
  9649. THREE.AudioAnalyser = function ( audio, fftSize ) {
  9650. this.analyser = audio.context.createAnalyser();
  9651. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  9652. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  9653. audio.getOutput().connect( this.analyser );
  9654. };
  9655. THREE.AudioAnalyser.prototype = {
  9656. constructor: THREE.AudioAnalyser,
  9657. getData: function () {
  9658. this.analyser.getByteFrequencyData( this.data );
  9659. return this.data;
  9660. }
  9661. };
  9662. // File:src/audio/AudioBuffer.js
  9663. /**
  9664. * @author mrdoob / http://mrdoob.com/
  9665. */
  9666. THREE.AudioBuffer = function ( context ) {
  9667. this.context = context;
  9668. this.ready = false;
  9669. this.readyCallbacks = [];
  9670. };
  9671. THREE.AudioBuffer.prototype.load = function ( file ) {
  9672. var scope = this;
  9673. var request = new XMLHttpRequest();
  9674. request.open( 'GET', file, true );
  9675. request.responseType = 'arraybuffer';
  9676. request.onload = function ( e ) {
  9677. scope.context.decodeAudioData( this.response, function ( buffer ) {
  9678. scope.buffer = buffer;
  9679. scope.ready = true;
  9680. for ( var i = 0; i < scope.readyCallbacks.length; i ++ ) {
  9681. scope.readyCallbacks[ i ]( scope.buffer );
  9682. }
  9683. scope.readyCallbacks = [];
  9684. } );
  9685. };
  9686. request.send();
  9687. return this;
  9688. };
  9689. THREE.AudioBuffer.prototype.onReady = function ( callback ) {
  9690. if ( this.ready ) {
  9691. callback( this.buffer );
  9692. } else {
  9693. this.readyCallbacks.push( callback );
  9694. }
  9695. };
  9696. // File:src/audio/PositionalAudio.js
  9697. /**
  9698. * @author mrdoob / http://mrdoob.com/
  9699. */
  9700. THREE.PositionalAudio = function ( listener ) {
  9701. THREE.Audio.call( this, listener );
  9702. this.panner = this.context.createPanner();
  9703. this.panner.connect( this.gain );
  9704. };
  9705. THREE.PositionalAudio.prototype = Object.create( THREE.Audio.prototype );
  9706. THREE.PositionalAudio.prototype.constructor = THREE.PositionalAudio;
  9707. THREE.PositionalAudio.prototype.getOutput = function () {
  9708. return this.panner;
  9709. };
  9710. THREE.PositionalAudio.prototype.setRefDistance = function ( value ) {
  9711. this.panner.refDistance = value;
  9712. };
  9713. THREE.PositionalAudio.prototype.getRefDistance = function () {
  9714. return this.panner.refDistance;
  9715. };
  9716. THREE.PositionalAudio.prototype.setRolloffFactor = function ( value ) {
  9717. this.panner.rolloffFactor = value;
  9718. };
  9719. THREE.PositionalAudio.prototype.getRolloffFactor = function () {
  9720. return this.panner.rolloffFactor;
  9721. };
  9722. THREE.PositionalAudio.prototype.setDistanceModel = function ( value ) {
  9723. this.panner.distanceModel = value;
  9724. };
  9725. THREE.PositionalAudio.prototype.getDistanceModel = function () {
  9726. return this.panner.distanceModel;
  9727. };
  9728. THREE.PositionalAudio.prototype.setMaxDistance = function ( value ) {
  9729. this.panner.maxDistance = value;
  9730. };
  9731. THREE.PositionalAudio.prototype.getMaxDistance = function () {
  9732. return this.panner.maxDistance;
  9733. };
  9734. THREE.PositionalAudio.prototype.updateMatrixWorld = ( function () {
  9735. var position = new THREE.Vector3();
  9736. return function updateMatrixWorld( force ) {
  9737. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9738. position.setFromMatrixPosition( this.matrixWorld );
  9739. this.panner.setPosition( position.x, position.y, position.z );
  9740. };
  9741. } )();
  9742. // File:src/audio/AudioListener.js
  9743. /**
  9744. * @author mrdoob / http://mrdoob.com/
  9745. */
  9746. THREE.AudioListener = function () {
  9747. THREE.Object3D.call( this );
  9748. this.type = 'AudioListener';
  9749. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  9750. this.gain = this.context.createGain();
  9751. this.gain.connect( this.context.destination );
  9752. this.filter = null;
  9753. };
  9754. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  9755. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  9756. THREE.AudioListener.prototype.getInput = function () {
  9757. return this.gain;
  9758. };
  9759. THREE.AudioListener.prototype.removeFilter = function ( ) {
  9760. if ( this.filter !== null ) {
  9761. this.gain.disconnect( this.filter );
  9762. this.filter.disconnect( this.context.destination );
  9763. this.gain.connect( this.context.destination );
  9764. this.filter = null;
  9765. }
  9766. };
  9767. THREE.AudioListener.prototype.setFilter = function ( value ) {
  9768. if ( this.filter !== null ) {
  9769. this.gain.disconnect( this.filter );
  9770. this.filter.disconnect( this.context.destination );
  9771. } else {
  9772. this.gain.disconnect( this.context.destination );
  9773. }
  9774. this.filter = value;
  9775. this.gain.connect( this.filter );
  9776. this.filter.connect( this.context.destination );
  9777. };
  9778. THREE.AudioListener.prototype.getFilter = function () {
  9779. return this.filter;
  9780. };
  9781. THREE.AudioListener.prototype.setMasterVolume = function ( value ) {
  9782. this.gain.gain.value = value;
  9783. };
  9784. THREE.AudioListener.prototype.getMasterVolume = function () {
  9785. return this.gain.gain.value;
  9786. };
  9787. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  9788. var position = new THREE.Vector3();
  9789. var quaternion = new THREE.Quaternion();
  9790. var scale = new THREE.Vector3();
  9791. var orientation = new THREE.Vector3();
  9792. return function updateMatrixWorld( force ) {
  9793. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9794. var listener = this.context.listener;
  9795. var up = this.up;
  9796. this.matrixWorld.decompose( position, quaternion, scale );
  9797. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9798. listener.setPosition( position.x, position.y, position.z );
  9799. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  9800. };
  9801. } )();
  9802. // File:src/cameras/Camera.js
  9803. /**
  9804. * @author mrdoob / http://mrdoob.com/
  9805. * @author mikael emtinger / http://gomo.se/
  9806. * @author WestLangley / http://github.com/WestLangley
  9807. */
  9808. THREE.Camera = function () {
  9809. THREE.Object3D.call( this );
  9810. this.type = 'Camera';
  9811. this.matrixWorldInverse = new THREE.Matrix4();
  9812. this.projectionMatrix = new THREE.Matrix4();
  9813. };
  9814. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  9815. THREE.Camera.prototype.constructor = THREE.Camera;
  9816. THREE.Camera.prototype.getWorldDirection = function () {
  9817. var quaternion = new THREE.Quaternion();
  9818. return function ( optionalTarget ) {
  9819. var result = optionalTarget || new THREE.Vector3();
  9820. this.getWorldQuaternion( quaternion );
  9821. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9822. };
  9823. }();
  9824. THREE.Camera.prototype.lookAt = function () {
  9825. // This routine does not support cameras with rotated and/or translated parent(s)
  9826. var m1 = new THREE.Matrix4();
  9827. return function ( vector ) {
  9828. m1.lookAt( this.position, vector, this.up );
  9829. this.quaternion.setFromRotationMatrix( m1 );
  9830. };
  9831. }();
  9832. THREE.Camera.prototype.clone = function () {
  9833. return new this.constructor().copy( this );
  9834. };
  9835. THREE.Camera.prototype.copy = function ( source ) {
  9836. THREE.Object3D.prototype.copy.call( this, source );
  9837. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  9838. this.projectionMatrix.copy( source.projectionMatrix );
  9839. return this;
  9840. };
  9841. // File:src/cameras/CubeCamera.js
  9842. /**
  9843. * Camera for rendering cube maps
  9844. * - renders scene into axis-aligned cube
  9845. *
  9846. * @author alteredq / http://alteredqualia.com/
  9847. */
  9848. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  9849. THREE.Object3D.call( this );
  9850. this.type = 'CubeCamera';
  9851. var fov = 90, aspect = 1;
  9852. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9853. cameraPX.up.set( 0, - 1, 0 );
  9854. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  9855. this.add( cameraPX );
  9856. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9857. cameraNX.up.set( 0, - 1, 0 );
  9858. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  9859. this.add( cameraNX );
  9860. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9861. cameraPY.up.set( 0, 0, 1 );
  9862. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  9863. this.add( cameraPY );
  9864. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9865. cameraNY.up.set( 0, 0, - 1 );
  9866. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  9867. this.add( cameraNY );
  9868. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9869. cameraPZ.up.set( 0, - 1, 0 );
  9870. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  9871. this.add( cameraPZ );
  9872. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9873. cameraNZ.up.set( 0, - 1, 0 );
  9874. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  9875. this.add( cameraNZ );
  9876. var options = { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter };
  9877. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  9878. this.updateCubeMap = function ( renderer, scene ) {
  9879. if ( this.parent === null ) this.updateMatrixWorld();
  9880. var renderTarget = this.renderTarget;
  9881. var generateMipmaps = renderTarget.texture.generateMipmaps;
  9882. renderTarget.texture.generateMipmaps = false;
  9883. renderTarget.activeCubeFace = 0;
  9884. renderer.render( scene, cameraPX, renderTarget );
  9885. renderTarget.activeCubeFace = 1;
  9886. renderer.render( scene, cameraNX, renderTarget );
  9887. renderTarget.activeCubeFace = 2;
  9888. renderer.render( scene, cameraPY, renderTarget );
  9889. renderTarget.activeCubeFace = 3;
  9890. renderer.render( scene, cameraNY, renderTarget );
  9891. renderTarget.activeCubeFace = 4;
  9892. renderer.render( scene, cameraPZ, renderTarget );
  9893. renderTarget.texture.generateMipmaps = generateMipmaps;
  9894. renderTarget.activeCubeFace = 5;
  9895. renderer.render( scene, cameraNZ, renderTarget );
  9896. renderer.setRenderTarget( null );
  9897. };
  9898. };
  9899. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  9900. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  9901. // File:src/cameras/OrthographicCamera.js
  9902. /**
  9903. * @author alteredq / http://alteredqualia.com/
  9904. */
  9905. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  9906. THREE.Camera.call( this );
  9907. this.type = 'OrthographicCamera';
  9908. this.zoom = 1;
  9909. this.left = left;
  9910. this.right = right;
  9911. this.top = top;
  9912. this.bottom = bottom;
  9913. this.near = ( near !== undefined ) ? near : 0.1;
  9914. this.far = ( far !== undefined ) ? far : 2000;
  9915. this.updateProjectionMatrix();
  9916. };
  9917. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  9918. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  9919. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  9920. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  9921. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  9922. var cx = ( this.right + this.left ) / 2;
  9923. var cy = ( this.top + this.bottom ) / 2;
  9924. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  9925. };
  9926. THREE.OrthographicCamera.prototype.copy = function ( source ) {
  9927. THREE.Camera.prototype.copy.call( this, source );
  9928. this.left = source.left;
  9929. this.right = source.right;
  9930. this.top = source.top;
  9931. this.bottom = source.bottom;
  9932. this.near = source.near;
  9933. this.far = source.far;
  9934. this.zoom = source.zoom;
  9935. return this;
  9936. };
  9937. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  9938. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9939. data.object.zoom = this.zoom;
  9940. data.object.left = this.left;
  9941. data.object.right = this.right;
  9942. data.object.top = this.top;
  9943. data.object.bottom = this.bottom;
  9944. data.object.near = this.near;
  9945. data.object.far = this.far;
  9946. return data;
  9947. };
  9948. // File:src/cameras/PerspectiveCamera.js
  9949. /**
  9950. * @author mrdoob / http://mrdoob.com/
  9951. * @author greggman / http://games.greggman.com/
  9952. * @author zz85 / http://www.lab4games.net/zz85/blog
  9953. */
  9954. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  9955. THREE.Camera.call( this );
  9956. this.type = 'PerspectiveCamera';
  9957. this.focalLength = 10;
  9958. this.zoom = 1;
  9959. this.fov = fov !== undefined ? fov : 50;
  9960. this.aspect = aspect !== undefined ? aspect : 1;
  9961. this.near = near !== undefined ? near : 0.1;
  9962. this.far = far !== undefined ? far : 2000;
  9963. this.updateProjectionMatrix();
  9964. };
  9965. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  9966. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  9967. /**
  9968. * Uses Focal Length (in mm) to estimate and set FOV
  9969. * 35mm (full-frame) camera is used if frame size is not specified;
  9970. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  9971. */
  9972. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  9973. if ( frameHeight === undefined ) frameHeight = 24;
  9974. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  9975. this.updateProjectionMatrix();
  9976. };
  9977. /**
  9978. * Sets an offset in a larger frustum. This is useful for multi-window or
  9979. * multi-monitor/multi-machine setups.
  9980. *
  9981. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  9982. * the monitors are in grid like this
  9983. *
  9984. * +---+---+---+
  9985. * | A | B | C |
  9986. * +---+---+---+
  9987. * | D | E | F |
  9988. * +---+---+---+
  9989. *
  9990. * then for each monitor you would call it like this
  9991. *
  9992. * var w = 1920;
  9993. * var h = 1080;
  9994. * var fullWidth = w * 3;
  9995. * var fullHeight = h * 2;
  9996. *
  9997. * --A--
  9998. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  9999. * --B--
  10000. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  10001. * --C--
  10002. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  10003. * --D--
  10004. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  10005. * --E--
  10006. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  10007. * --F--
  10008. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  10009. *
  10010. * Note there is no reason monitors have to be the same size or in a grid.
  10011. */
  10012. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  10013. this.fullWidth = fullWidth;
  10014. this.fullHeight = fullHeight;
  10015. this.x = x;
  10016. this.y = y;
  10017. this.width = width;
  10018. this.height = height;
  10019. this.updateProjectionMatrix();
  10020. };
  10021. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  10022. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  10023. if ( this.fullWidth ) {
  10024. var aspect = this.fullWidth / this.fullHeight;
  10025. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  10026. var bottom = - top;
  10027. var left = aspect * bottom;
  10028. var right = aspect * top;
  10029. var width = Math.abs( right - left );
  10030. var height = Math.abs( top - bottom );
  10031. this.projectionMatrix.makeFrustum(
  10032. left + this.x * width / this.fullWidth,
  10033. left + ( this.x + this.width ) * width / this.fullWidth,
  10034. top - ( this.y + this.height ) * height / this.fullHeight,
  10035. top - this.y * height / this.fullHeight,
  10036. this.near,
  10037. this.far
  10038. );
  10039. } else {
  10040. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  10041. }
  10042. };
  10043. THREE.PerspectiveCamera.prototype.copy = function ( source ) {
  10044. THREE.Camera.prototype.copy.call( this, source );
  10045. this.focalLength = source.focalLength;
  10046. this.zoom = source.zoom;
  10047. this.fov = source.fov;
  10048. this.aspect = source.aspect;
  10049. this.near = source.near;
  10050. this.far = source.far;
  10051. return this;
  10052. };
  10053. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  10054. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10055. data.object.focalLength = this.focalLength;
  10056. data.object.zoom = this.zoom;
  10057. data.object.fov = this.fov;
  10058. data.object.aspect = this.aspect;
  10059. data.object.near = this.near;
  10060. data.object.far = this.far;
  10061. return data;
  10062. };
  10063. // File:src/cameras/StereoCamera.js
  10064. /**
  10065. * @author mrdoob / http://mrdoob.com/
  10066. */
  10067. THREE.StereoCamera = function () {
  10068. this.type = 'StereoCamera';
  10069. this.aspect = 1;
  10070. this.cameraL = new THREE.PerspectiveCamera();
  10071. this.cameraL.layers.enable( 1 );
  10072. this.cameraL.matrixAutoUpdate = false;
  10073. this.cameraR = new THREE.PerspectiveCamera();
  10074. this.cameraR.layers.enable( 2 );
  10075. this.cameraR.matrixAutoUpdate = false;
  10076. };
  10077. THREE.StereoCamera.prototype = {
  10078. constructor: THREE.StereoCamera,
  10079. update: ( function () {
  10080. var focalLength, fov, aspect, near, far;
  10081. var eyeRight = new THREE.Matrix4();
  10082. var eyeLeft = new THREE.Matrix4();
  10083. return function update ( camera ) {
  10084. var needsUpdate = focalLength !== camera.focalLength || fov !== camera.fov ||
  10085. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  10086. far !== camera.far;
  10087. if ( needsUpdate ) {
  10088. focalLength = camera.focalLength;
  10089. fov = camera.fov;
  10090. aspect = camera.aspect * this.aspect;
  10091. near = camera.near;
  10092. far = camera.far;
  10093. // Off-axis stereoscopic effect based on
  10094. // http://paulbourke.net/stereographics/stereorender/
  10095. var projectionMatrix = camera.projectionMatrix.clone();
  10096. var eyeSep = 0.064 / 2;
  10097. var eyeSepOnProjection = eyeSep * near / focalLength;
  10098. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  10099. var xmin, xmax;
  10100. // translate xOffset
  10101. eyeLeft.elements[ 12 ] = - eyeSep;
  10102. eyeRight.elements[ 12 ] = eyeSep;
  10103. // for left eye
  10104. xmin = - ymax * aspect + eyeSepOnProjection;
  10105. xmax = ymax * aspect + eyeSepOnProjection;
  10106. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10107. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10108. this.cameraL.projectionMatrix.copy( projectionMatrix );
  10109. // for right eye
  10110. xmin = - ymax * aspect - eyeSepOnProjection;
  10111. xmax = ymax * aspect - eyeSepOnProjection;
  10112. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10113. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10114. this.cameraR.projectionMatrix.copy( projectionMatrix );
  10115. }
  10116. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  10117. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  10118. };
  10119. } )()
  10120. };
  10121. // File:src/lights/Light.js
  10122. /**
  10123. * @author mrdoob / http://mrdoob.com/
  10124. * @author alteredq / http://alteredqualia.com/
  10125. */
  10126. THREE.Light = function ( color, intensity ) {
  10127. THREE.Object3D.call( this );
  10128. this.type = 'Light';
  10129. this.color = new THREE.Color( color );
  10130. this.intensity = intensity !== undefined ? intensity : 1;
  10131. this.receiveShadow = undefined;
  10132. };
  10133. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  10134. THREE.Light.prototype.constructor = THREE.Light;
  10135. THREE.Light.prototype.copy = function ( source ) {
  10136. THREE.Object3D.prototype.copy.call( this, source );
  10137. this.color.copy( source.color );
  10138. this.intensity = source.intensity;
  10139. return this;
  10140. };
  10141. THREE.Light.prototype.toJSON = function ( meta ) {
  10142. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10143. data.object.color = this.color.getHex();
  10144. data.object.intensity = this.intensity;
  10145. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  10146. if ( this.distance !== undefined ) data.object.distance = this.distance;
  10147. if ( this.angle !== undefined ) data.object.angle = this.angle;
  10148. if ( this.decay !== undefined ) data.object.decay = this.decay;
  10149. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  10150. return data;
  10151. };
  10152. // File:src/lights/LightShadow.js
  10153. /**
  10154. * @author mrdoob / http://mrdoob.com/
  10155. */
  10156. THREE.LightShadow = function ( camera ) {
  10157. this.camera = camera;
  10158. this.bias = 0;
  10159. this.radius = 1;
  10160. this.mapSize = new THREE.Vector2( 512, 512 );
  10161. this.map = null;
  10162. this.matrix = new THREE.Matrix4();
  10163. };
  10164. THREE.LightShadow.prototype = {
  10165. constructor: THREE.LightShadow,
  10166. copy: function ( source ) {
  10167. this.camera = source.camera.clone();
  10168. this.bias = source.bias;
  10169. this.radius = source.radius;
  10170. this.mapSize.copy( source.mapSize );
  10171. return this;
  10172. },
  10173. clone: function () {
  10174. return new this.constructor().copy( this );
  10175. }
  10176. };
  10177. // File:src/lights/AmbientLight.js
  10178. /**
  10179. * @author mrdoob / http://mrdoob.com/
  10180. */
  10181. THREE.AmbientLight = function ( color, intensity ) {
  10182. THREE.Light.call( this, color, intensity );
  10183. this.type = 'AmbientLight';
  10184. this.castShadow = undefined;
  10185. };
  10186. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  10187. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  10188. // File:src/lights/DirectionalLight.js
  10189. /**
  10190. * @author mrdoob / http://mrdoob.com/
  10191. * @author alteredq / http://alteredqualia.com/
  10192. */
  10193. THREE.DirectionalLight = function ( color, intensity ) {
  10194. THREE.Light.call( this, color, intensity );
  10195. this.type = 'DirectionalLight';
  10196. this.position.set( 0, 1, 0 );
  10197. this.updateMatrix();
  10198. this.target = new THREE.Object3D();
  10199. this.shadow = new THREE.LightShadow( new THREE.OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  10200. };
  10201. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  10202. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  10203. THREE.DirectionalLight.prototype.copy = function ( source ) {
  10204. THREE.Light.prototype.copy.call( this, source );
  10205. this.target = source.target.clone();
  10206. this.shadow = source.shadow.clone();
  10207. return this;
  10208. };
  10209. // File:src/lights/HemisphereLight.js
  10210. /**
  10211. * @author alteredq / http://alteredqualia.com/
  10212. */
  10213. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  10214. THREE.Light.call( this, skyColor, intensity );
  10215. this.type = 'HemisphereLight';
  10216. this.castShadow = undefined;
  10217. this.position.set( 0, 1, 0 );
  10218. this.updateMatrix();
  10219. this.groundColor = new THREE.Color( groundColor );
  10220. };
  10221. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  10222. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  10223. THREE.HemisphereLight.prototype.copy = function ( source ) {
  10224. THREE.Light.prototype.copy.call( this, source );
  10225. this.groundColor.copy( source.groundColor );
  10226. return this;
  10227. };
  10228. // File:src/lights/PointLight.js
  10229. /**
  10230. * @author mrdoob / http://mrdoob.com/
  10231. */
  10232. THREE.PointLight = function ( color, intensity, distance, decay ) {
  10233. THREE.Light.call( this, color, intensity );
  10234. this.type = 'PointLight';
  10235. this.distance = ( distance !== undefined ) ? distance : 0;
  10236. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10237. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 90, 1, 0.5, 500 ) );
  10238. };
  10239. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  10240. THREE.PointLight.prototype.constructor = THREE.PointLight;
  10241. Object.defineProperty( THREE.PointLight.prototype, "power", {
  10242. get: function () {
  10243. // intensity = power per solid angle.
  10244. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10245. return this.intensity * 4 * Math.PI;
  10246. },
  10247. set: function ( power ) {
  10248. // intensity = power per solid angle.
  10249. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10250. this.intensity = power / ( 4 * Math.PI );
  10251. }
  10252. } );
  10253. THREE.PointLight.prototype.copy = function ( source ) {
  10254. THREE.Light.prototype.copy.call( this, source );
  10255. this.distance = source.distance;
  10256. this.decay = source.decay;
  10257. this.shadow = source.shadow.clone();
  10258. return this;
  10259. };
  10260. // File:src/lights/SpotLight.js
  10261. /**
  10262. * @author alteredq / http://alteredqualia.com/
  10263. */
  10264. THREE.SpotLight = function ( color, intensity, distance, angle, penumbra, decay ) {
  10265. THREE.Light.call( this, color, intensity );
  10266. this.type = 'SpotLight';
  10267. this.position.set( 0, 1, 0 );
  10268. this.updateMatrix();
  10269. this.target = new THREE.Object3D();
  10270. this.distance = ( distance !== undefined ) ? distance : 0;
  10271. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  10272. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  10273. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10274. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 50, 1, 0.5, 500 ) );
  10275. };
  10276. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  10277. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  10278. Object.defineProperty( THREE.SpotLight.prototype, "power", {
  10279. get: function () {
  10280. // intensity = power per solid angle.
  10281. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10282. return this.intensity * Math.PI;
  10283. },
  10284. set: function ( power ) {
  10285. // intensity = power per solid angle.
  10286. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10287. this.intensity = power / Math.PI;
  10288. }
  10289. } );
  10290. THREE.SpotLight.prototype.copy = function ( source ) {
  10291. THREE.Light.prototype.copy.call( this, source );
  10292. this.distance = source.distance;
  10293. this.angle = source.angle;
  10294. this.penumbra = source.penumbra;
  10295. this.decay = source.decay;
  10296. this.target = source.target.clone();
  10297. this.shadow = source.shadow.clone();
  10298. return this;
  10299. };
  10300. // File:src/loaders/Cache.js
  10301. /**
  10302. * @author mrdoob / http://mrdoob.com/
  10303. */
  10304. THREE.Cache = {
  10305. enabled: false,
  10306. files: {},
  10307. add: function ( key, file ) {
  10308. if ( this.enabled === false ) return;
  10309. // console.log( 'THREE.Cache', 'Adding key:', key );
  10310. this.files[ key ] = file;
  10311. },
  10312. get: function ( key ) {
  10313. if ( this.enabled === false ) return;
  10314. // console.log( 'THREE.Cache', 'Checking key:', key );
  10315. return this.files[ key ];
  10316. },
  10317. remove: function ( key ) {
  10318. delete this.files[ key ];
  10319. },
  10320. clear: function () {
  10321. this.files = {};
  10322. }
  10323. };
  10324. // File:src/loaders/Loader.js
  10325. /**
  10326. * @author alteredq / http://alteredqualia.com/
  10327. */
  10328. THREE.Loader = function () {
  10329. this.onLoadStart = function () {};
  10330. this.onLoadProgress = function () {};
  10331. this.onLoadComplete = function () {};
  10332. };
  10333. THREE.Loader.prototype = {
  10334. constructor: THREE.Loader,
  10335. crossOrigin: undefined,
  10336. extractUrlBase: function ( url ) {
  10337. var parts = url.split( '/' );
  10338. if ( parts.length === 1 ) return './';
  10339. parts.pop();
  10340. return parts.join( '/' ) + '/';
  10341. },
  10342. initMaterials: function ( materials, texturePath, crossOrigin ) {
  10343. var array = [];
  10344. for ( var i = 0; i < materials.length; ++ i ) {
  10345. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  10346. }
  10347. return array;
  10348. },
  10349. createMaterial: ( function () {
  10350. var color, textureLoader, materialLoader;
  10351. return function ( m, texturePath, crossOrigin ) {
  10352. if ( color === undefined ) color = new THREE.Color();
  10353. if ( textureLoader === undefined ) textureLoader = new THREE.TextureLoader();
  10354. if ( materialLoader === undefined ) materialLoader = new THREE.MaterialLoader();
  10355. // convert from old material format
  10356. var textures = {};
  10357. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  10358. var fullPath = texturePath + path;
  10359. var loader = THREE.Loader.Handlers.get( fullPath );
  10360. var texture;
  10361. if ( loader !== null ) {
  10362. texture = loader.load( fullPath );
  10363. } else {
  10364. textureLoader.setCrossOrigin( crossOrigin );
  10365. texture = textureLoader.load( fullPath );
  10366. }
  10367. if ( repeat !== undefined ) {
  10368. texture.repeat.fromArray( repeat );
  10369. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  10370. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  10371. }
  10372. if ( offset !== undefined ) {
  10373. texture.offset.fromArray( offset );
  10374. }
  10375. if ( wrap !== undefined ) {
  10376. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = THREE.RepeatWrapping;
  10377. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = THREE.MirroredRepeatWrapping;
  10378. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = THREE.RepeatWrapping;
  10379. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = THREE.MirroredRepeatWrapping;
  10380. }
  10381. if ( anisotropy !== undefined ) {
  10382. texture.anisotropy = anisotropy;
  10383. }
  10384. var uuid = THREE.Math.generateUUID();
  10385. textures[ uuid ] = texture;
  10386. return uuid;
  10387. }
  10388. //
  10389. var json = {
  10390. uuid: THREE.Math.generateUUID(),
  10391. type: 'MeshLambertMaterial'
  10392. };
  10393. for ( var name in m ) {
  10394. var value = m[ name ];
  10395. switch ( name ) {
  10396. case 'DbgColor':
  10397. case 'DbgIndex':
  10398. case 'opticalDensity':
  10399. case 'illumination':
  10400. break;
  10401. case 'DbgName':
  10402. json.name = value;
  10403. break;
  10404. case 'blending':
  10405. json.blending = THREE[ value ];
  10406. break;
  10407. case 'colorAmbient':
  10408. case 'mapAmbient':
  10409. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  10410. break;
  10411. case 'colorDiffuse':
  10412. json.color = color.fromArray( value ).getHex();
  10413. break;
  10414. case 'colorSpecular':
  10415. json.specular = color.fromArray( value ).getHex();
  10416. break;
  10417. case 'colorEmissive':
  10418. json.emissive = color.fromArray( value ).getHex();
  10419. break;
  10420. case 'specularCoef':
  10421. json.shininess = value;
  10422. break;
  10423. case 'shading':
  10424. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  10425. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  10426. break;
  10427. case 'mapDiffuse':
  10428. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  10429. break;
  10430. case 'mapDiffuseRepeat':
  10431. case 'mapDiffuseOffset':
  10432. case 'mapDiffuseWrap':
  10433. case 'mapDiffuseAnisotropy':
  10434. break;
  10435. case 'mapLight':
  10436. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  10437. break;
  10438. case 'mapLightRepeat':
  10439. case 'mapLightOffset':
  10440. case 'mapLightWrap':
  10441. case 'mapLightAnisotropy':
  10442. break;
  10443. case 'mapAO':
  10444. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  10445. break;
  10446. case 'mapAORepeat':
  10447. case 'mapAOOffset':
  10448. case 'mapAOWrap':
  10449. case 'mapAOAnisotropy':
  10450. break;
  10451. case 'mapBump':
  10452. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  10453. break;
  10454. case 'mapBumpScale':
  10455. json.bumpScale = value;
  10456. break;
  10457. case 'mapBumpRepeat':
  10458. case 'mapBumpOffset':
  10459. case 'mapBumpWrap':
  10460. case 'mapBumpAnisotropy':
  10461. break;
  10462. case 'mapNormal':
  10463. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  10464. break;
  10465. case 'mapNormalFactor':
  10466. json.normalScale = [ value, value ];
  10467. break;
  10468. case 'mapNormalRepeat':
  10469. case 'mapNormalOffset':
  10470. case 'mapNormalWrap':
  10471. case 'mapNormalAnisotropy':
  10472. break;
  10473. case 'mapSpecular':
  10474. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  10475. break;
  10476. case 'mapSpecularRepeat':
  10477. case 'mapSpecularOffset':
  10478. case 'mapSpecularWrap':
  10479. case 'mapSpecularAnisotropy':
  10480. break;
  10481. case 'mapAlpha':
  10482. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  10483. break;
  10484. case 'mapAlphaRepeat':
  10485. case 'mapAlphaOffset':
  10486. case 'mapAlphaWrap':
  10487. case 'mapAlphaAnisotropy':
  10488. break;
  10489. case 'flipSided':
  10490. json.side = THREE.BackSide;
  10491. break;
  10492. case 'doubleSided':
  10493. json.side = THREE.DoubleSide;
  10494. break;
  10495. case 'transparency':
  10496. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  10497. json.opacity = value;
  10498. break;
  10499. case 'depthTest':
  10500. case 'depthWrite':
  10501. case 'colorWrite':
  10502. case 'opacity':
  10503. case 'reflectivity':
  10504. case 'transparent':
  10505. case 'visible':
  10506. case 'wireframe':
  10507. json[ name ] = value;
  10508. break;
  10509. case 'vertexColors':
  10510. if ( value === true ) json.vertexColors = THREE.VertexColors;
  10511. if ( value === 'face' ) json.vertexColors = THREE.FaceColors;
  10512. break;
  10513. default:
  10514. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  10515. break;
  10516. }
  10517. }
  10518. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  10519. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  10520. if ( json.opacity < 1 ) json.transparent = true;
  10521. materialLoader.setTextures( textures );
  10522. return materialLoader.parse( json );
  10523. };
  10524. } )()
  10525. };
  10526. THREE.Loader.Handlers = {
  10527. handlers: [],
  10528. add: function ( regex, loader ) {
  10529. this.handlers.push( regex, loader );
  10530. },
  10531. get: function ( file ) {
  10532. var handlers = this.handlers;
  10533. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  10534. var regex = handlers[ i ];
  10535. var loader = handlers[ i + 1 ];
  10536. if ( regex.test( file ) ) {
  10537. return loader;
  10538. }
  10539. }
  10540. return null;
  10541. }
  10542. };
  10543. // File:src/loaders/XHRLoader.js
  10544. /**
  10545. * @author mrdoob / http://mrdoob.com/
  10546. */
  10547. THREE.XHRLoader = function ( manager ) {
  10548. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10549. };
  10550. THREE.XHRLoader.prototype = {
  10551. constructor: THREE.XHRLoader,
  10552. load: function ( url, onLoad, onProgress, onError ) {
  10553. if ( this.path !== undefined ) url = this.path + url;
  10554. var scope = this;
  10555. var cached = THREE.Cache.get( url );
  10556. if ( cached !== undefined ) {
  10557. if ( onLoad ) {
  10558. setTimeout( function () {
  10559. onLoad( cached );
  10560. }, 0 );
  10561. }
  10562. return cached;
  10563. }
  10564. var request = new XMLHttpRequest();
  10565. request.overrideMimeType( 'text/plain' );
  10566. request.open( 'GET', url, true );
  10567. request.addEventListener( 'load', function ( event ) {
  10568. var response = event.target.response;
  10569. THREE.Cache.add( url, response );
  10570. if ( this.status === 200 ) {
  10571. if ( onLoad ) onLoad( response );
  10572. scope.manager.itemEnd( url );
  10573. } else if ( this.status === 0 ) {
  10574. // Some browsers return HTTP Status 0 when using non-http protocol
  10575. // e.g. 'file://' or 'data://'. Handle as success.
  10576. console.warn( 'THREE.XHRLoader: HTTP Status 0 received.' );
  10577. if ( onLoad ) onLoad( response );
  10578. scope.manager.itemEnd( url );
  10579. } else {
  10580. if ( onError ) onError( event );
  10581. scope.manager.itemError( url );
  10582. }
  10583. }, false );
  10584. if ( onProgress !== undefined ) {
  10585. request.addEventListener( 'progress', function ( event ) {
  10586. onProgress( event );
  10587. }, false );
  10588. }
  10589. request.addEventListener( 'error', function ( event ) {
  10590. if ( onError ) onError( event );
  10591. scope.manager.itemError( url );
  10592. }, false );
  10593. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  10594. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  10595. request.send( null );
  10596. scope.manager.itemStart( url );
  10597. return request;
  10598. },
  10599. setPath: function ( value ) {
  10600. this.path = value;
  10601. },
  10602. setResponseType: function ( value ) {
  10603. this.responseType = value;
  10604. },
  10605. setWithCredentials: function ( value ) {
  10606. this.withCredentials = value;
  10607. }
  10608. };
  10609. // File:src/loaders/FontLoader.js
  10610. /**
  10611. * @author mrdoob / http://mrdoob.com/
  10612. */
  10613. THREE.FontLoader = function ( manager ) {
  10614. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10615. };
  10616. THREE.FontLoader.prototype = {
  10617. constructor: THREE.FontLoader,
  10618. load: function ( url, onLoad, onProgress, onError ) {
  10619. var loader = new THREE.XHRLoader( this.manager );
  10620. loader.load( url, function ( text ) {
  10621. onLoad( new THREE.Font( JSON.parse( text.substring( 65, text.length - 2 ) ) ) );
  10622. }, onProgress, onError );
  10623. }
  10624. };
  10625. // File:src/loaders/ImageLoader.js
  10626. /**
  10627. * @author mrdoob / http://mrdoob.com/
  10628. */
  10629. THREE.ImageLoader = function ( manager ) {
  10630. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10631. };
  10632. THREE.ImageLoader.prototype = {
  10633. constructor: THREE.ImageLoader,
  10634. load: function ( url, onLoad, onProgress, onError ) {
  10635. if ( this.path !== undefined ) url = this.path + url;
  10636. var scope = this;
  10637. var cached = THREE.Cache.get( url );
  10638. if ( cached !== undefined ) {
  10639. scope.manager.itemStart( url );
  10640. if ( onLoad ) {
  10641. setTimeout( function () {
  10642. onLoad( cached );
  10643. scope.manager.itemEnd( url );
  10644. }, 0 );
  10645. } else {
  10646. scope.manager.itemEnd( url );
  10647. }
  10648. return cached;
  10649. }
  10650. var image = document.createElement( 'img' );
  10651. image.addEventListener( 'load', function ( event ) {
  10652. THREE.Cache.add( url, this );
  10653. if ( onLoad ) onLoad( this );
  10654. scope.manager.itemEnd( url );
  10655. }, false );
  10656. if ( onProgress !== undefined ) {
  10657. image.addEventListener( 'progress', function ( event ) {
  10658. onProgress( event );
  10659. }, false );
  10660. }
  10661. image.addEventListener( 'error', function ( event ) {
  10662. if ( onError ) onError( event );
  10663. scope.manager.itemError( url );
  10664. }, false );
  10665. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  10666. scope.manager.itemStart( url );
  10667. image.src = url;
  10668. return image;
  10669. },
  10670. setCrossOrigin: function ( value ) {
  10671. this.crossOrigin = value;
  10672. },
  10673. setPath: function ( value ) {
  10674. this.path = value;
  10675. }
  10676. };
  10677. // File:src/loaders/JSONLoader.js
  10678. /**
  10679. * @author mrdoob / http://mrdoob.com/
  10680. * @author alteredq / http://alteredqualia.com/
  10681. */
  10682. THREE.JSONLoader = function ( manager ) {
  10683. if ( typeof manager === 'boolean' ) {
  10684. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  10685. manager = undefined;
  10686. }
  10687. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10688. this.withCredentials = false;
  10689. };
  10690. THREE.JSONLoader.prototype = {
  10691. constructor: THREE.JSONLoader,
  10692. // Deprecated
  10693. get statusDomElement () {
  10694. if ( this._statusDomElement === undefined ) {
  10695. this._statusDomElement = document.createElement( 'div' );
  10696. }
  10697. console.warn( 'THREE.JSONLoader: .statusDomElement has been removed.' );
  10698. return this._statusDomElement;
  10699. },
  10700. load: function( url, onLoad, onProgress, onError ) {
  10701. var scope = this;
  10702. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  10703. var loader = new THREE.XHRLoader( this.manager );
  10704. loader.setWithCredentials( this.withCredentials );
  10705. loader.load( url, function ( text ) {
  10706. var json = JSON.parse( text );
  10707. var metadata = json.metadata;
  10708. if ( metadata !== undefined ) {
  10709. var type = metadata.type;
  10710. if ( type !== undefined ) {
  10711. if ( type.toLowerCase() === 'object' ) {
  10712. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  10713. return;
  10714. }
  10715. if ( type.toLowerCase() === 'scene' ) {
  10716. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  10717. return;
  10718. }
  10719. }
  10720. }
  10721. var object = scope.parse( json, texturePath );
  10722. onLoad( object.geometry, object.materials );
  10723. }, onProgress, onError );
  10724. },
  10725. setTexturePath: function ( value ) {
  10726. this.texturePath = value;
  10727. },
  10728. parse: function ( json, texturePath ) {
  10729. var geometry = new THREE.Geometry(),
  10730. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  10731. parseModel( scale );
  10732. parseSkin();
  10733. parseMorphing( scale );
  10734. parseAnimations();
  10735. geometry.computeFaceNormals();
  10736. geometry.computeBoundingSphere();
  10737. function parseModel( scale ) {
  10738. function isBitSet( value, position ) {
  10739. return value & ( 1 << position );
  10740. }
  10741. var i, j, fi,
  10742. offset, zLength,
  10743. colorIndex, normalIndex, uvIndex, materialIndex,
  10744. type,
  10745. isQuad,
  10746. hasMaterial,
  10747. hasFaceVertexUv,
  10748. hasFaceNormal, hasFaceVertexNormal,
  10749. hasFaceColor, hasFaceVertexColor,
  10750. vertex, face, faceA, faceB, hex, normal,
  10751. uvLayer, uv, u, v,
  10752. faces = json.faces,
  10753. vertices = json.vertices,
  10754. normals = json.normals,
  10755. colors = json.colors,
  10756. nUvLayers = 0;
  10757. if ( json.uvs !== undefined ) {
  10758. // disregard empty arrays
  10759. for ( i = 0; i < json.uvs.length; i ++ ) {
  10760. if ( json.uvs[ i ].length ) nUvLayers ++;
  10761. }
  10762. for ( i = 0; i < nUvLayers; i ++ ) {
  10763. geometry.faceVertexUvs[ i ] = [];
  10764. }
  10765. }
  10766. offset = 0;
  10767. zLength = vertices.length;
  10768. while ( offset < zLength ) {
  10769. vertex = new THREE.Vector3();
  10770. vertex.x = vertices[ offset ++ ] * scale;
  10771. vertex.y = vertices[ offset ++ ] * scale;
  10772. vertex.z = vertices[ offset ++ ] * scale;
  10773. geometry.vertices.push( vertex );
  10774. }
  10775. offset = 0;
  10776. zLength = faces.length;
  10777. while ( offset < zLength ) {
  10778. type = faces[ offset ++ ];
  10779. isQuad = isBitSet( type, 0 );
  10780. hasMaterial = isBitSet( type, 1 );
  10781. hasFaceVertexUv = isBitSet( type, 3 );
  10782. hasFaceNormal = isBitSet( type, 4 );
  10783. hasFaceVertexNormal = isBitSet( type, 5 );
  10784. hasFaceColor = isBitSet( type, 6 );
  10785. hasFaceVertexColor = isBitSet( type, 7 );
  10786. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  10787. if ( isQuad ) {
  10788. faceA = new THREE.Face3();
  10789. faceA.a = faces[ offset ];
  10790. faceA.b = faces[ offset + 1 ];
  10791. faceA.c = faces[ offset + 3 ];
  10792. faceB = new THREE.Face3();
  10793. faceB.a = faces[ offset + 1 ];
  10794. faceB.b = faces[ offset + 2 ];
  10795. faceB.c = faces[ offset + 3 ];
  10796. offset += 4;
  10797. if ( hasMaterial ) {
  10798. materialIndex = faces[ offset ++ ];
  10799. faceA.materialIndex = materialIndex;
  10800. faceB.materialIndex = materialIndex;
  10801. }
  10802. // to get face <=> uv index correspondence
  10803. fi = geometry.faces.length;
  10804. if ( hasFaceVertexUv ) {
  10805. for ( i = 0; i < nUvLayers; i ++ ) {
  10806. uvLayer = json.uvs[ i ];
  10807. geometry.faceVertexUvs[ i ][ fi ] = [];
  10808. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  10809. for ( j = 0; j < 4; j ++ ) {
  10810. uvIndex = faces[ offset ++ ];
  10811. u = uvLayer[ uvIndex * 2 ];
  10812. v = uvLayer[ uvIndex * 2 + 1 ];
  10813. uv = new THREE.Vector2( u, v );
  10814. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10815. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  10816. }
  10817. }
  10818. }
  10819. if ( hasFaceNormal ) {
  10820. normalIndex = faces[ offset ++ ] * 3;
  10821. faceA.normal.set(
  10822. normals[ normalIndex ++ ],
  10823. normals[ normalIndex ++ ],
  10824. normals[ normalIndex ]
  10825. );
  10826. faceB.normal.copy( faceA.normal );
  10827. }
  10828. if ( hasFaceVertexNormal ) {
  10829. for ( i = 0; i < 4; i ++ ) {
  10830. normalIndex = faces[ offset ++ ] * 3;
  10831. normal = new THREE.Vector3(
  10832. normals[ normalIndex ++ ],
  10833. normals[ normalIndex ++ ],
  10834. normals[ normalIndex ]
  10835. );
  10836. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  10837. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  10838. }
  10839. }
  10840. if ( hasFaceColor ) {
  10841. colorIndex = faces[ offset ++ ];
  10842. hex = colors[ colorIndex ];
  10843. faceA.color.setHex( hex );
  10844. faceB.color.setHex( hex );
  10845. }
  10846. if ( hasFaceVertexColor ) {
  10847. for ( i = 0; i < 4; i ++ ) {
  10848. colorIndex = faces[ offset ++ ];
  10849. hex = colors[ colorIndex ];
  10850. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  10851. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  10852. }
  10853. }
  10854. geometry.faces.push( faceA );
  10855. geometry.faces.push( faceB );
  10856. } else {
  10857. face = new THREE.Face3();
  10858. face.a = faces[ offset ++ ];
  10859. face.b = faces[ offset ++ ];
  10860. face.c = faces[ offset ++ ];
  10861. if ( hasMaterial ) {
  10862. materialIndex = faces[ offset ++ ];
  10863. face.materialIndex = materialIndex;
  10864. }
  10865. // to get face <=> uv index correspondence
  10866. fi = geometry.faces.length;
  10867. if ( hasFaceVertexUv ) {
  10868. for ( i = 0; i < nUvLayers; i ++ ) {
  10869. uvLayer = json.uvs[ i ];
  10870. geometry.faceVertexUvs[ i ][ fi ] = [];
  10871. for ( j = 0; j < 3; j ++ ) {
  10872. uvIndex = faces[ offset ++ ];
  10873. u = uvLayer[ uvIndex * 2 ];
  10874. v = uvLayer[ uvIndex * 2 + 1 ];
  10875. uv = new THREE.Vector2( u, v );
  10876. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10877. }
  10878. }
  10879. }
  10880. if ( hasFaceNormal ) {
  10881. normalIndex = faces[ offset ++ ] * 3;
  10882. face.normal.set(
  10883. normals[ normalIndex ++ ],
  10884. normals[ normalIndex ++ ],
  10885. normals[ normalIndex ]
  10886. );
  10887. }
  10888. if ( hasFaceVertexNormal ) {
  10889. for ( i = 0; i < 3; i ++ ) {
  10890. normalIndex = faces[ offset ++ ] * 3;
  10891. normal = new THREE.Vector3(
  10892. normals[ normalIndex ++ ],
  10893. normals[ normalIndex ++ ],
  10894. normals[ normalIndex ]
  10895. );
  10896. face.vertexNormals.push( normal );
  10897. }
  10898. }
  10899. if ( hasFaceColor ) {
  10900. colorIndex = faces[ offset ++ ];
  10901. face.color.setHex( colors[ colorIndex ] );
  10902. }
  10903. if ( hasFaceVertexColor ) {
  10904. for ( i = 0; i < 3; i ++ ) {
  10905. colorIndex = faces[ offset ++ ];
  10906. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  10907. }
  10908. }
  10909. geometry.faces.push( face );
  10910. }
  10911. }
  10912. };
  10913. function parseSkin() {
  10914. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  10915. if ( json.skinWeights ) {
  10916. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  10917. var x = json.skinWeights[ i ];
  10918. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  10919. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  10920. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  10921. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  10922. }
  10923. }
  10924. if ( json.skinIndices ) {
  10925. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  10926. var a = json.skinIndices[ i ];
  10927. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  10928. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  10929. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  10930. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  10931. }
  10932. }
  10933. geometry.bones = json.bones;
  10934. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  10935. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  10936. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  10937. }
  10938. };
  10939. function parseMorphing( scale ) {
  10940. if ( json.morphTargets !== undefined ) {
  10941. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  10942. geometry.morphTargets[ i ] = {};
  10943. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  10944. geometry.morphTargets[ i ].vertices = [];
  10945. var dstVertices = geometry.morphTargets[ i ].vertices;
  10946. var srcVertices = json.morphTargets[ i ].vertices;
  10947. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  10948. var vertex = new THREE.Vector3();
  10949. vertex.x = srcVertices[ v ] * scale;
  10950. vertex.y = srcVertices[ v + 1 ] * scale;
  10951. vertex.z = srcVertices[ v + 2 ] * scale;
  10952. dstVertices.push( vertex );
  10953. }
  10954. }
  10955. }
  10956. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  10957. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  10958. var faces = geometry.faces;
  10959. var morphColors = json.morphColors[ 0 ].colors;
  10960. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  10961. faces[ i ].color.fromArray( morphColors, i * 3 );
  10962. }
  10963. }
  10964. }
  10965. function parseAnimations() {
  10966. var outputAnimations = [];
  10967. // parse old style Bone/Hierarchy animations
  10968. var animations = [];
  10969. if ( json.animation !== undefined ) {
  10970. animations.push( json.animation );
  10971. }
  10972. if ( json.animations !== undefined ) {
  10973. if ( json.animations.length ) {
  10974. animations = animations.concat( json.animations );
  10975. } else {
  10976. animations.push( json.animations );
  10977. }
  10978. }
  10979. for ( var i = 0; i < animations.length; i ++ ) {
  10980. var clip = THREE.AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  10981. if ( clip ) outputAnimations.push( clip );
  10982. }
  10983. // parse implicit morph animations
  10984. if ( geometry.morphTargets ) {
  10985. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  10986. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  10987. outputAnimations = outputAnimations.concat( morphAnimationClips );
  10988. }
  10989. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  10990. };
  10991. if ( json.materials === undefined || json.materials.length === 0 ) {
  10992. return { geometry: geometry };
  10993. } else {
  10994. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  10995. return { geometry: geometry, materials: materials };
  10996. }
  10997. }
  10998. };
  10999. // File:src/loaders/LoadingManager.js
  11000. /**
  11001. * @author mrdoob / http://mrdoob.com/
  11002. */
  11003. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  11004. var scope = this;
  11005. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  11006. this.onStart = undefined;
  11007. this.onLoad = onLoad;
  11008. this.onProgress = onProgress;
  11009. this.onError = onError;
  11010. this.itemStart = function ( url ) {
  11011. itemsTotal ++;
  11012. if ( isLoading === false ) {
  11013. if ( scope.onStart !== undefined ) {
  11014. scope.onStart( url, itemsLoaded, itemsTotal );
  11015. }
  11016. }
  11017. isLoading = true;
  11018. };
  11019. this.itemEnd = function ( url ) {
  11020. itemsLoaded ++;
  11021. if ( scope.onProgress !== undefined ) {
  11022. scope.onProgress( url, itemsLoaded, itemsTotal );
  11023. }
  11024. if ( itemsLoaded === itemsTotal ) {
  11025. isLoading = false;
  11026. if ( scope.onLoad !== undefined ) {
  11027. scope.onLoad();
  11028. }
  11029. }
  11030. };
  11031. this.itemError = function ( url ) {
  11032. if ( scope.onError !== undefined ) {
  11033. scope.onError( url );
  11034. }
  11035. };
  11036. };
  11037. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  11038. // File:src/loaders/BufferGeometryLoader.js
  11039. /**
  11040. * @author mrdoob / http://mrdoob.com/
  11041. */
  11042. THREE.BufferGeometryLoader = function ( manager ) {
  11043. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11044. };
  11045. THREE.BufferGeometryLoader.prototype = {
  11046. constructor: THREE.BufferGeometryLoader,
  11047. load: function ( url, onLoad, onProgress, onError ) {
  11048. var scope = this;
  11049. var loader = new THREE.XHRLoader( scope.manager );
  11050. loader.load( url, function ( text ) {
  11051. onLoad( scope.parse( JSON.parse( text ) ) );
  11052. }, onProgress, onError );
  11053. },
  11054. parse: function ( json ) {
  11055. var geometry = new THREE.BufferGeometry();
  11056. var index = json.data.index;
  11057. var TYPED_ARRAYS = {
  11058. 'Int8Array': Int8Array,
  11059. 'Uint8Array': Uint8Array,
  11060. 'Uint8ClampedArray': Uint8ClampedArray,
  11061. 'Int16Array': Int16Array,
  11062. 'Uint16Array': Uint16Array,
  11063. 'Int32Array': Int32Array,
  11064. 'Uint32Array': Uint32Array,
  11065. 'Float32Array': Float32Array,
  11066. 'Float64Array': Float64Array
  11067. };
  11068. if ( index !== undefined ) {
  11069. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  11070. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  11071. }
  11072. var attributes = json.data.attributes;
  11073. for ( var key in attributes ) {
  11074. var attribute = attributes[ key ];
  11075. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  11076. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  11077. }
  11078. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  11079. if ( groups !== undefined ) {
  11080. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  11081. var group = groups[ i ];
  11082. geometry.addGroup( group.start, group.count, group.materialIndex );
  11083. }
  11084. }
  11085. var boundingSphere = json.data.boundingSphere;
  11086. if ( boundingSphere !== undefined ) {
  11087. var center = new THREE.Vector3();
  11088. if ( boundingSphere.center !== undefined ) {
  11089. center.fromArray( boundingSphere.center );
  11090. }
  11091. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  11092. }
  11093. return geometry;
  11094. }
  11095. };
  11096. // File:src/loaders/MaterialLoader.js
  11097. /**
  11098. * @author mrdoob / http://mrdoob.com/
  11099. */
  11100. THREE.MaterialLoader = function ( manager ) {
  11101. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11102. this.textures = {};
  11103. };
  11104. THREE.MaterialLoader.prototype = {
  11105. constructor: THREE.MaterialLoader,
  11106. load: function ( url, onLoad, onProgress, onError ) {
  11107. var scope = this;
  11108. var loader = new THREE.XHRLoader( scope.manager );
  11109. loader.load( url, function ( text ) {
  11110. onLoad( scope.parse( JSON.parse( text ) ) );
  11111. }, onProgress, onError );
  11112. },
  11113. setTextures: function ( value ) {
  11114. this.textures = value;
  11115. },
  11116. getTexture: function ( name ) {
  11117. var textures = this.textures;
  11118. if ( textures[ name ] === undefined ) {
  11119. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  11120. }
  11121. return textures[ name ];
  11122. },
  11123. parse: function ( json ) {
  11124. var material = new THREE[ json.type ];
  11125. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  11126. if ( json.name !== undefined ) material.name = json.name;
  11127. if ( json.color !== undefined ) material.color.setHex( json.color );
  11128. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  11129. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  11130. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  11131. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  11132. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  11133. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  11134. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  11135. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  11136. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  11137. if ( json.shading !== undefined ) material.shading = json.shading;
  11138. if ( json.blending !== undefined ) material.blending = json.blending;
  11139. if ( json.side !== undefined ) material.side = json.side;
  11140. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  11141. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  11142. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  11143. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  11144. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  11145. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  11146. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  11147. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  11148. // for PointsMaterial
  11149. if ( json.size !== undefined ) material.size = json.size;
  11150. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  11151. // maps
  11152. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  11153. if ( json.alphaMap !== undefined ) {
  11154. material.alphaMap = this.getTexture( json.alphaMap );
  11155. material.transparent = true;
  11156. }
  11157. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  11158. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  11159. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  11160. if ( json.normalScale !== undefined ) {
  11161. var normalScale = json.normalScale;
  11162. if ( Array.isArray( normalScale ) === false ) {
  11163. // Blender exporter used to export a scalar. See #7459
  11164. normalScale = [ normalScale, normalScale ];
  11165. }
  11166. material.normalScale = new THREE.Vector2().fromArray( normalScale );
  11167. }
  11168. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  11169. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  11170. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  11171. if ( json.roughnessMap !== undefined ) material.roughnessMap = this.getTexture( json.roughnessMap );
  11172. if ( json.metalnessMap !== undefined ) material.metalnessMap = this.getTexture( json.metalnessMap );
  11173. if ( json.emissiveMap !== undefined ) material.emissiveMap = this.getTexture( json.emissiveMap );
  11174. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  11175. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  11176. if ( json.envMap !== undefined ) {
  11177. material.envMap = this.getTexture( json.envMap );
  11178. material.combine = THREE.MultiplyOperation;
  11179. }
  11180. if ( json.reflectivity ) material.reflectivity = json.reflectivity;
  11181. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  11182. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  11183. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  11184. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  11185. // MultiMaterial
  11186. if ( json.materials !== undefined ) {
  11187. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  11188. material.materials.push( this.parse( json.materials[ i ] ) );
  11189. }
  11190. }
  11191. return material;
  11192. }
  11193. };
  11194. // File:src/loaders/ObjectLoader.js
  11195. /**
  11196. * @author mrdoob / http://mrdoob.com/
  11197. */
  11198. THREE.ObjectLoader = function ( manager ) {
  11199. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11200. this.texturePath = '';
  11201. };
  11202. THREE.ObjectLoader.prototype = {
  11203. constructor: THREE.ObjectLoader,
  11204. load: function ( url, onLoad, onProgress, onError ) {
  11205. if ( this.texturePath === '' ) {
  11206. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  11207. }
  11208. var scope = this;
  11209. var loader = new THREE.XHRLoader( scope.manager );
  11210. loader.load( url, function ( text ) {
  11211. scope.parse( JSON.parse( text ), onLoad );
  11212. }, onProgress, onError );
  11213. },
  11214. setTexturePath: function ( value ) {
  11215. this.texturePath = value;
  11216. },
  11217. setCrossOrigin: function ( value ) {
  11218. this.crossOrigin = value;
  11219. },
  11220. parse: function ( json, onLoad ) {
  11221. var geometries = this.parseGeometries( json.geometries );
  11222. var images = this.parseImages( json.images, function () {
  11223. if ( onLoad !== undefined ) onLoad( object );
  11224. } );
  11225. var textures = this.parseTextures( json.textures, images );
  11226. var materials = this.parseMaterials( json.materials, textures );
  11227. var object = this.parseObject( json.object, geometries, materials );
  11228. if ( json.animations ) {
  11229. object.animations = this.parseAnimations( json.animations );
  11230. }
  11231. if ( json.images === undefined || json.images.length === 0 ) {
  11232. if ( onLoad !== undefined ) onLoad( object );
  11233. }
  11234. return object;
  11235. },
  11236. parseGeometries: function ( json ) {
  11237. var geometries = {};
  11238. if ( json !== undefined ) {
  11239. var geometryLoader = new THREE.JSONLoader();
  11240. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  11241. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11242. var geometry;
  11243. var data = json[ i ];
  11244. switch ( data.type ) {
  11245. case 'PlaneGeometry':
  11246. case 'PlaneBufferGeometry':
  11247. geometry = new THREE[ data.type ](
  11248. data.width,
  11249. data.height,
  11250. data.widthSegments,
  11251. data.heightSegments
  11252. );
  11253. break;
  11254. case 'BoxGeometry':
  11255. case 'BoxBufferGeometry':
  11256. case 'CubeGeometry': // backwards compatible
  11257. geometry = new THREE[ data.type ](
  11258. data.width,
  11259. data.height,
  11260. data.depth,
  11261. data.widthSegments,
  11262. data.heightSegments,
  11263. data.depthSegments
  11264. );
  11265. break;
  11266. case 'CircleGeometry':
  11267. case 'CircleBufferGeometry':
  11268. geometry = new THREE[ data.type ](
  11269. data.radius,
  11270. data.segments,
  11271. data.thetaStart,
  11272. data.thetaLength
  11273. );
  11274. break;
  11275. case 'CylinderGeometry':
  11276. case 'CylinderBufferGeometry':
  11277. geometry = new THREE[ data.type ](
  11278. data.radiusTop,
  11279. data.radiusBottom,
  11280. data.height,
  11281. data.radialSegments,
  11282. data.heightSegments,
  11283. data.openEnded,
  11284. data.thetaStart,
  11285. data.thetaLength
  11286. );
  11287. break;
  11288. case 'SphereGeometry':
  11289. case 'SphereBufferGeometry':
  11290. geometry = new THREE[ data.type ](
  11291. data.radius,
  11292. data.widthSegments,
  11293. data.heightSegments,
  11294. data.phiStart,
  11295. data.phiLength,
  11296. data.thetaStart,
  11297. data.thetaLength
  11298. );
  11299. break;
  11300. case 'DodecahedronGeometry':
  11301. geometry = new THREE.DodecahedronGeometry(
  11302. data.radius,
  11303. data.detail
  11304. );
  11305. break;
  11306. case 'IcosahedronGeometry':
  11307. geometry = new THREE.IcosahedronGeometry(
  11308. data.radius,
  11309. data.detail
  11310. );
  11311. break;
  11312. case 'OctahedronGeometry':
  11313. geometry = new THREE.OctahedronGeometry(
  11314. data.radius,
  11315. data.detail
  11316. );
  11317. break;
  11318. case 'TetrahedronGeometry':
  11319. geometry = new THREE.TetrahedronGeometry(
  11320. data.radius,
  11321. data.detail
  11322. );
  11323. break;
  11324. case 'RingGeometry':
  11325. case 'RingBufferGeometry':
  11326. geometry = new THREE[ data.type ](
  11327. data.innerRadius,
  11328. data.outerRadius,
  11329. data.thetaSegments,
  11330. data.phiSegments,
  11331. data.thetaStart,
  11332. data.thetaLength
  11333. );
  11334. break;
  11335. case 'TorusGeometry':
  11336. case 'TorusBufferGeometry':
  11337. geometry = new THREE[ data.type ](
  11338. data.radius,
  11339. data.tube,
  11340. data.radialSegments,
  11341. data.tubularSegments,
  11342. data.arc
  11343. );
  11344. break;
  11345. case 'TorusKnotGeometry':
  11346. case 'TorusKnotBufferGeometry':
  11347. geometry = new THREE[ data.type ](
  11348. data.radius,
  11349. data.tube,
  11350. data.tubularSegments,
  11351. data.radialSegments,
  11352. data.p,
  11353. data.q
  11354. );
  11355. break;
  11356. case 'LatheGeometry':
  11357. geometry = new THREE.LatheGeometry(
  11358. data.points,
  11359. data.segments,
  11360. data.phiStart,
  11361. data.phiLength
  11362. );
  11363. break;
  11364. case 'BufferGeometry':
  11365. geometry = bufferGeometryLoader.parse( data );
  11366. break;
  11367. case 'Geometry':
  11368. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  11369. break;
  11370. default:
  11371. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  11372. continue;
  11373. }
  11374. geometry.uuid = data.uuid;
  11375. if ( data.name !== undefined ) geometry.name = data.name;
  11376. geometries[ data.uuid ] = geometry;
  11377. }
  11378. }
  11379. return geometries;
  11380. },
  11381. parseMaterials: function ( json, textures ) {
  11382. var materials = {};
  11383. if ( json !== undefined ) {
  11384. var loader = new THREE.MaterialLoader();
  11385. loader.setTextures( textures );
  11386. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11387. var material = loader.parse( json[ i ] );
  11388. materials[ material.uuid ] = material;
  11389. }
  11390. }
  11391. return materials;
  11392. },
  11393. parseAnimations: function ( json ) {
  11394. var animations = [];
  11395. for ( var i = 0; i < json.length; i ++ ) {
  11396. var clip = THREE.AnimationClip.parse( json[ i ] );
  11397. animations.push( clip );
  11398. }
  11399. return animations;
  11400. },
  11401. parseImages: function ( json, onLoad ) {
  11402. var scope = this;
  11403. var images = {};
  11404. function loadImage( url ) {
  11405. scope.manager.itemStart( url );
  11406. return loader.load( url, function () {
  11407. scope.manager.itemEnd( url );
  11408. } );
  11409. }
  11410. if ( json !== undefined && json.length > 0 ) {
  11411. var manager = new THREE.LoadingManager( onLoad );
  11412. var loader = new THREE.ImageLoader( manager );
  11413. loader.setCrossOrigin( this.crossOrigin );
  11414. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11415. var image = json[ i ];
  11416. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  11417. images[ image.uuid ] = loadImage( path );
  11418. }
  11419. }
  11420. return images;
  11421. },
  11422. parseTextures: function ( json, images ) {
  11423. function parseConstant( value ) {
  11424. if ( typeof( value ) === 'number' ) return value;
  11425. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  11426. return THREE[ value ];
  11427. }
  11428. var textures = {};
  11429. if ( json !== undefined ) {
  11430. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11431. var data = json[ i ];
  11432. if ( data.image === undefined ) {
  11433. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  11434. }
  11435. if ( images[ data.image ] === undefined ) {
  11436. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  11437. }
  11438. var texture = new THREE.Texture( images[ data.image ] );
  11439. texture.needsUpdate = true;
  11440. texture.uuid = data.uuid;
  11441. if ( data.name !== undefined ) texture.name = data.name;
  11442. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  11443. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  11444. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  11445. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  11446. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  11447. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  11448. if ( Array.isArray( data.wrap ) ) {
  11449. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  11450. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  11451. }
  11452. textures[ data.uuid ] = texture;
  11453. }
  11454. }
  11455. return textures;
  11456. },
  11457. parseObject: function () {
  11458. var matrix = new THREE.Matrix4();
  11459. return function ( data, geometries, materials ) {
  11460. var object;
  11461. function getGeometry( name ) {
  11462. if ( geometries[ name ] === undefined ) {
  11463. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  11464. }
  11465. return geometries[ name ];
  11466. }
  11467. function getMaterial( name ) {
  11468. if ( name === undefined ) return undefined;
  11469. if ( materials[ name ] === undefined ) {
  11470. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  11471. }
  11472. return materials[ name ];
  11473. }
  11474. switch ( data.type ) {
  11475. case 'Scene':
  11476. object = new THREE.Scene();
  11477. break;
  11478. case 'PerspectiveCamera':
  11479. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  11480. break;
  11481. case 'OrthographicCamera':
  11482. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  11483. break;
  11484. case 'AmbientLight':
  11485. object = new THREE.AmbientLight( data.color, data.intensity );
  11486. break;
  11487. case 'DirectionalLight':
  11488. object = new THREE.DirectionalLight( data.color, data.intensity );
  11489. break;
  11490. case 'PointLight':
  11491. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  11492. break;
  11493. case 'SpotLight':
  11494. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  11495. break;
  11496. case 'HemisphereLight':
  11497. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  11498. break;
  11499. case 'Mesh':
  11500. var geometry = getGeometry( data.geometry );
  11501. var material = getMaterial( data.material );
  11502. if ( geometry.bones && geometry.bones.length > 0 ) {
  11503. object = new THREE.SkinnedMesh( geometry, material );
  11504. } else {
  11505. object = new THREE.Mesh( geometry, material );
  11506. }
  11507. break;
  11508. case 'LOD':
  11509. object = new THREE.LOD();
  11510. break;
  11511. case 'Line':
  11512. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  11513. break;
  11514. case 'PointCloud':
  11515. case 'Points':
  11516. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  11517. break;
  11518. case 'Sprite':
  11519. object = new THREE.Sprite( getMaterial( data.material ) );
  11520. break;
  11521. case 'Group':
  11522. object = new THREE.Group();
  11523. break;
  11524. default:
  11525. object = new THREE.Object3D();
  11526. }
  11527. object.uuid = data.uuid;
  11528. if ( data.name !== undefined ) object.name = data.name;
  11529. if ( data.matrix !== undefined ) {
  11530. matrix.fromArray( data.matrix );
  11531. matrix.decompose( object.position, object.quaternion, object.scale );
  11532. } else {
  11533. if ( data.position !== undefined ) object.position.fromArray( data.position );
  11534. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  11535. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  11536. }
  11537. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  11538. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  11539. if ( data.visible !== undefined ) object.visible = data.visible;
  11540. if ( data.userData !== undefined ) object.userData = data.userData;
  11541. if ( data.children !== undefined ) {
  11542. for ( var child in data.children ) {
  11543. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  11544. }
  11545. }
  11546. if ( data.type === 'LOD' ) {
  11547. var levels = data.levels;
  11548. for ( var l = 0; l < levels.length; l ++ ) {
  11549. var level = levels[ l ];
  11550. var child = object.getObjectByProperty( 'uuid', level.object );
  11551. if ( child !== undefined ) {
  11552. object.addLevel( child, level.distance );
  11553. }
  11554. }
  11555. }
  11556. return object;
  11557. };
  11558. }()
  11559. };
  11560. // File:src/loaders/TextureLoader.js
  11561. /**
  11562. * @author mrdoob / http://mrdoob.com/
  11563. */
  11564. THREE.TextureLoader = function ( manager ) {
  11565. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11566. };
  11567. THREE.TextureLoader.prototype = {
  11568. constructor: THREE.TextureLoader,
  11569. load: function ( url, onLoad, onProgress, onError ) {
  11570. var texture = new THREE.Texture();
  11571. var loader = new THREE.ImageLoader( this.manager );
  11572. loader.setCrossOrigin( this.crossOrigin );
  11573. loader.setPath( this.path );
  11574. loader.load( url, function ( image ) {
  11575. texture.image = image;
  11576. texture.needsUpdate = true;
  11577. if ( onLoad !== undefined ) {
  11578. onLoad( texture );
  11579. }
  11580. }, onProgress, onError );
  11581. return texture;
  11582. },
  11583. setCrossOrigin: function ( value ) {
  11584. this.crossOrigin = value;
  11585. },
  11586. setPath: function ( value ) {
  11587. this.path = value;
  11588. }
  11589. };
  11590. // File:src/loaders/CubeTextureLoader.js
  11591. /**
  11592. * @author mrdoob / http://mrdoob.com/
  11593. */
  11594. THREE.CubeTextureLoader = function ( manager ) {
  11595. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11596. };
  11597. THREE.CubeTextureLoader.prototype = {
  11598. constructor: THREE.CubeTextureLoader,
  11599. load: function ( urls, onLoad, onProgress, onError ) {
  11600. var texture = new THREE.CubeTexture();
  11601. var loader = new THREE.ImageLoader( this.manager );
  11602. loader.setCrossOrigin( this.crossOrigin );
  11603. loader.setPath( this.path );
  11604. var loaded = 0;
  11605. function loadTexture( i ) {
  11606. loader.load( urls[ i ], function ( image ) {
  11607. texture.images[ i ] = image;
  11608. loaded ++;
  11609. if ( loaded === 6 ) {
  11610. texture.needsUpdate = true;
  11611. if ( onLoad ) onLoad( texture );
  11612. }
  11613. }, undefined, onError );
  11614. }
  11615. for ( var i = 0; i < urls.length; ++ i ) {
  11616. loadTexture( i );
  11617. }
  11618. return texture;
  11619. },
  11620. setCrossOrigin: function ( value ) {
  11621. this.crossOrigin = value;
  11622. },
  11623. setPath: function ( value ) {
  11624. this.path = value;
  11625. }
  11626. };
  11627. // File:src/loaders/BinaryTextureLoader.js
  11628. /**
  11629. * @author Nikos M. / https://github.com/foo123/
  11630. *
  11631. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  11632. */
  11633. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  11634. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11635. // override in sub classes
  11636. this._parser = null;
  11637. };
  11638. THREE.BinaryTextureLoader.prototype = {
  11639. constructor: THREE.BinaryTextureLoader,
  11640. load: function ( url, onLoad, onProgress, onError ) {
  11641. var scope = this;
  11642. var texture = new THREE.DataTexture();
  11643. var loader = new THREE.XHRLoader( this.manager );
  11644. loader.setResponseType( 'arraybuffer' );
  11645. loader.load( url, function ( buffer ) {
  11646. var texData = scope._parser( buffer );
  11647. if ( ! texData ) return;
  11648. if ( undefined !== texData.image ) {
  11649. texture.image = texData.image;
  11650. } else if ( undefined !== texData.data ) {
  11651. texture.image.width = texData.width;
  11652. texture.image.height = texData.height;
  11653. texture.image.data = texData.data;
  11654. }
  11655. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  11656. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  11657. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  11658. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  11659. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  11660. if ( undefined !== texData.format ) {
  11661. texture.format = texData.format;
  11662. }
  11663. if ( undefined !== texData.type ) {
  11664. texture.type = texData.type;
  11665. }
  11666. if ( undefined !== texData.mipmaps ) {
  11667. texture.mipmaps = texData.mipmaps;
  11668. }
  11669. if ( 1 === texData.mipmapCount ) {
  11670. texture.minFilter = THREE.LinearFilter;
  11671. }
  11672. texture.needsUpdate = true;
  11673. if ( onLoad ) onLoad( texture, texData );
  11674. }, onProgress, onError );
  11675. return texture;
  11676. }
  11677. };
  11678. // File:src/loaders/CompressedTextureLoader.js
  11679. /**
  11680. * @author mrdoob / http://mrdoob.com/
  11681. *
  11682. * Abstract Base class to block based textures loader (dds, pvr, ...)
  11683. */
  11684. THREE.CompressedTextureLoader = function ( manager ) {
  11685. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11686. // override in sub classes
  11687. this._parser = null;
  11688. };
  11689. THREE.CompressedTextureLoader.prototype = {
  11690. constructor: THREE.CompressedTextureLoader,
  11691. load: function ( url, onLoad, onProgress, onError ) {
  11692. var scope = this;
  11693. var images = [];
  11694. var texture = new THREE.CompressedTexture();
  11695. texture.image = images;
  11696. var loader = new THREE.XHRLoader( this.manager );
  11697. loader.setPath( this.path );
  11698. loader.setResponseType( 'arraybuffer' );
  11699. function loadTexture( i ) {
  11700. loader.load( url[ i ], function ( buffer ) {
  11701. var texDatas = scope._parser( buffer, true );
  11702. images[ i ] = {
  11703. width: texDatas.width,
  11704. height: texDatas.height,
  11705. format: texDatas.format,
  11706. mipmaps: texDatas.mipmaps
  11707. };
  11708. loaded += 1;
  11709. if ( loaded === 6 ) {
  11710. if ( texDatas.mipmapCount === 1 )
  11711. texture.minFilter = THREE.LinearFilter;
  11712. texture.format = texDatas.format;
  11713. texture.needsUpdate = true;
  11714. if ( onLoad ) onLoad( texture );
  11715. }
  11716. }, onProgress, onError );
  11717. }
  11718. if ( Array.isArray( url ) ) {
  11719. var loaded = 0;
  11720. for ( var i = 0, il = url.length; i < il; ++ i ) {
  11721. loadTexture( i );
  11722. }
  11723. } else {
  11724. // compressed cubemap texture stored in a single DDS file
  11725. loader.load( url, function ( buffer ) {
  11726. var texDatas = scope._parser( buffer, true );
  11727. if ( texDatas.isCubemap ) {
  11728. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  11729. for ( var f = 0; f < faces; f ++ ) {
  11730. images[ f ] = { mipmaps : [] };
  11731. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  11732. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  11733. images[ f ].format = texDatas.format;
  11734. images[ f ].width = texDatas.width;
  11735. images[ f ].height = texDatas.height;
  11736. }
  11737. }
  11738. } else {
  11739. texture.image.width = texDatas.width;
  11740. texture.image.height = texDatas.height;
  11741. texture.mipmaps = texDatas.mipmaps;
  11742. }
  11743. if ( texDatas.mipmapCount === 1 ) {
  11744. texture.minFilter = THREE.LinearFilter;
  11745. }
  11746. texture.format = texDatas.format;
  11747. texture.needsUpdate = true;
  11748. if ( onLoad ) onLoad( texture );
  11749. }, onProgress, onError );
  11750. }
  11751. return texture;
  11752. },
  11753. setPath: function ( value ) {
  11754. this.path = value;
  11755. }
  11756. };
  11757. // File:src/materials/Material.js
  11758. /**
  11759. * @author mrdoob / http://mrdoob.com/
  11760. * @author alteredq / http://alteredqualia.com/
  11761. */
  11762. THREE.Material = function () {
  11763. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  11764. this.uuid = THREE.Math.generateUUID();
  11765. this.name = '';
  11766. this.type = 'Material';
  11767. this.side = THREE.FrontSide;
  11768. this.opacity = 1;
  11769. this.transparent = false;
  11770. this.blending = THREE.NormalBlending;
  11771. this.blendSrc = THREE.SrcAlphaFactor;
  11772. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  11773. this.blendEquation = THREE.AddEquation;
  11774. this.blendSrcAlpha = null;
  11775. this.blendDstAlpha = null;
  11776. this.blendEquationAlpha = null;
  11777. this.depthFunc = THREE.LessEqualDepth;
  11778. this.depthTest = true;
  11779. this.depthWrite = true;
  11780. this.colorWrite = true;
  11781. this.precision = null; // override the renderer's default precision for this material
  11782. this.polygonOffset = false;
  11783. this.polygonOffsetFactor = 0;
  11784. this.polygonOffsetUnits = 0;
  11785. this.alphaTest = 0;
  11786. this.premultipliedAlpha = false;
  11787. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  11788. this.visible = true;
  11789. this._needsUpdate = true;
  11790. };
  11791. THREE.Material.prototype = {
  11792. constructor: THREE.Material,
  11793. get needsUpdate () {
  11794. return this._needsUpdate;
  11795. },
  11796. set needsUpdate ( value ) {
  11797. if ( value === true ) this.update();
  11798. this._needsUpdate = value;
  11799. },
  11800. setValues: function ( values ) {
  11801. if ( values === undefined ) return;
  11802. for ( var key in values ) {
  11803. var newValue = values[ key ];
  11804. if ( newValue === undefined ) {
  11805. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  11806. continue;
  11807. }
  11808. var currentValue = this[ key ];
  11809. if ( currentValue === undefined ) {
  11810. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  11811. continue;
  11812. }
  11813. if ( currentValue instanceof THREE.Color ) {
  11814. currentValue.set( newValue );
  11815. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  11816. currentValue.copy( newValue );
  11817. } else if ( key === 'overdraw' ) {
  11818. // ensure overdraw is backwards-compatible with legacy boolean type
  11819. this[ key ] = Number( newValue );
  11820. } else {
  11821. this[ key ] = newValue;
  11822. }
  11823. }
  11824. },
  11825. toJSON: function ( meta ) {
  11826. var isRoot = meta === undefined;
  11827. if ( isRoot ) {
  11828. meta = {
  11829. textures: {},
  11830. images: {}
  11831. };
  11832. }
  11833. var data = {
  11834. metadata: {
  11835. version: 4.4,
  11836. type: 'Material',
  11837. generator: 'Material.toJSON'
  11838. }
  11839. };
  11840. // standard Material serialization
  11841. data.uuid = this.uuid;
  11842. data.type = this.type;
  11843. if ( this.name !== '' ) data.name = this.name;
  11844. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  11845. if ( this.roughness !== 0.5 ) data.roughness = this.roughness;
  11846. if ( this.metalness !== 0.5 ) data.metalness = this.metalness;
  11847. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  11848. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  11849. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  11850. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  11851. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  11852. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  11853. if ( this.bumpMap instanceof THREE.Texture ) {
  11854. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  11855. data.bumpScale = this.bumpScale;
  11856. }
  11857. if ( this.normalMap instanceof THREE.Texture ) {
  11858. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  11859. data.normalScale = this.normalScale.toArray();
  11860. }
  11861. if ( this.displacementMap instanceof THREE.Texture ) {
  11862. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  11863. data.displacementScale = this.displacementScale;
  11864. data.displacementBias = this.displacementBias;
  11865. }
  11866. if ( this.roughnessMap instanceof THREE.Texture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  11867. if ( this.metalnessMap instanceof THREE.Texture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  11868. if ( this.emissiveMap instanceof THREE.Texture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  11869. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  11870. if ( this.envMap instanceof THREE.Texture ) {
  11871. data.envMap = this.envMap.toJSON( meta ).uuid;
  11872. data.reflectivity = this.reflectivity; // Scale behind envMap
  11873. }
  11874. if ( this.size !== undefined ) data.size = this.size;
  11875. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  11876. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  11877. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  11878. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  11879. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  11880. if ( this.opacity < 1 ) data.opacity = this.opacity;
  11881. if ( this.transparent === true ) data.transparent = this.transparent;
  11882. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  11883. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  11884. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  11885. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  11886. // TODO: Copied from Object3D.toJSON
  11887. function extractFromCache ( cache ) {
  11888. var values = [];
  11889. for ( var key in cache ) {
  11890. var data = cache[ key ];
  11891. delete data.metadata;
  11892. values.push( data );
  11893. }
  11894. return values;
  11895. }
  11896. if ( isRoot ) {
  11897. var textures = extractFromCache( meta.textures );
  11898. var images = extractFromCache( meta.images );
  11899. if ( textures.length > 0 ) data.textures = textures;
  11900. if ( images.length > 0 ) data.images = images;
  11901. }
  11902. return data;
  11903. },
  11904. clone: function () {
  11905. return new this.constructor().copy( this );
  11906. },
  11907. copy: function ( source ) {
  11908. this.name = source.name;
  11909. this.side = source.side;
  11910. this.opacity = source.opacity;
  11911. this.transparent = source.transparent;
  11912. this.blending = source.blending;
  11913. this.blendSrc = source.blendSrc;
  11914. this.blendDst = source.blendDst;
  11915. this.blendEquation = source.blendEquation;
  11916. this.blendSrcAlpha = source.blendSrcAlpha;
  11917. this.blendDstAlpha = source.blendDstAlpha;
  11918. this.blendEquationAlpha = source.blendEquationAlpha;
  11919. this.depthFunc = source.depthFunc;
  11920. this.depthTest = source.depthTest;
  11921. this.depthWrite = source.depthWrite;
  11922. this.colorWrite = source.colorWrite;
  11923. this.precision = source.precision;
  11924. this.polygonOffset = source.polygonOffset;
  11925. this.polygonOffsetFactor = source.polygonOffsetFactor;
  11926. this.polygonOffsetUnits = source.polygonOffsetUnits;
  11927. this.alphaTest = source.alphaTest;
  11928. this.premultipliedAlpha = source.premultipliedAlpha;
  11929. this.overdraw = source.overdraw;
  11930. this.visible = source.visible;
  11931. return this;
  11932. },
  11933. update: function () {
  11934. this.dispatchEvent( { type: 'update' } );
  11935. },
  11936. dispose: function () {
  11937. this.dispatchEvent( { type: 'dispose' } );
  11938. }
  11939. };
  11940. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  11941. THREE.MaterialIdCount = 0;
  11942. // File:src/materials/LineBasicMaterial.js
  11943. /**
  11944. * @author mrdoob / http://mrdoob.com/
  11945. * @author alteredq / http://alteredqualia.com/
  11946. *
  11947. * parameters = {
  11948. * color: <hex>,
  11949. * opacity: <float>,
  11950. *
  11951. * linewidth: <float>,
  11952. * linecap: "round",
  11953. * linejoin: "round",
  11954. *
  11955. * blending: THREE.NormalBlending,
  11956. * depthTest: <bool>,
  11957. * depthWrite: <bool>,
  11958. *
  11959. * vertexColors: <bool>
  11960. *
  11961. * fog: <bool>
  11962. * }
  11963. */
  11964. THREE.LineBasicMaterial = function ( parameters ) {
  11965. THREE.Material.call( this );
  11966. this.type = 'LineBasicMaterial';
  11967. this.color = new THREE.Color( 0xffffff );
  11968. this.linewidth = 1;
  11969. this.linecap = 'round';
  11970. this.linejoin = 'round';
  11971. this.blending = THREE.NormalBlending;
  11972. this.vertexColors = THREE.NoColors;
  11973. this.fog = true;
  11974. this.setValues( parameters );
  11975. };
  11976. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  11977. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  11978. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  11979. THREE.Material.prototype.copy.call( this, source );
  11980. this.color.copy( source.color );
  11981. this.linewidth = source.linewidth;
  11982. this.linecap = source.linecap;
  11983. this.linejoin = source.linejoin;
  11984. this.vertexColors = source.vertexColors;
  11985. this.fog = source.fog;
  11986. return this;
  11987. };
  11988. // File:src/materials/LineDashedMaterial.js
  11989. /**
  11990. * @author alteredq / http://alteredqualia.com/
  11991. *
  11992. * parameters = {
  11993. * color: <hex>,
  11994. * opacity: <float>,
  11995. *
  11996. * linewidth: <float>,
  11997. *
  11998. * scale: <float>,
  11999. * dashSize: <float>,
  12000. * gapSize: <float>,
  12001. *
  12002. * blending: THREE.NormalBlending,
  12003. * depthTest: <bool>,
  12004. * depthWrite: <bool>,
  12005. *
  12006. * vertexColors: THREE.NoColors / THREE.FaceColors / THREE.VertexColors
  12007. *
  12008. * fog: <bool>
  12009. * }
  12010. */
  12011. THREE.LineDashedMaterial = function ( parameters ) {
  12012. THREE.Material.call( this );
  12013. this.type = 'LineDashedMaterial';
  12014. this.color = new THREE.Color( 0xffffff );
  12015. this.linewidth = 1;
  12016. this.scale = 1;
  12017. this.dashSize = 3;
  12018. this.gapSize = 1;
  12019. this.blending = THREE.NormalBlending;
  12020. this.vertexColors = THREE.NoColors;
  12021. this.fog = true;
  12022. this.setValues( parameters );
  12023. };
  12024. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  12025. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  12026. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  12027. THREE.Material.prototype.copy.call( this, source );
  12028. this.color.copy( source.color );
  12029. this.linewidth = source.linewidth;
  12030. this.scale = source.scale;
  12031. this.dashSize = source.dashSize;
  12032. this.gapSize = source.gapSize;
  12033. this.vertexColors = source.vertexColors;
  12034. this.fog = source.fog;
  12035. return this;
  12036. };
  12037. // File:src/materials/MeshBasicMaterial.js
  12038. /**
  12039. * @author mrdoob / http://mrdoob.com/
  12040. * @author alteredq / http://alteredqualia.com/
  12041. *
  12042. * parameters = {
  12043. * color: <hex>,
  12044. * opacity: <float>,
  12045. * map: new THREE.Texture( <Image> ),
  12046. *
  12047. * aoMap: new THREE.Texture( <Image> ),
  12048. * aoMapIntensity: <float>
  12049. *
  12050. * specularMap: new THREE.Texture( <Image> ),
  12051. *
  12052. * alphaMap: new THREE.Texture( <Image> ),
  12053. *
  12054. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12055. * combine: THREE.Multiply,
  12056. * reflectivity: <float>,
  12057. * refractionRatio: <float>,
  12058. *
  12059. * shading: THREE.SmoothShading,
  12060. * blending: THREE.NormalBlending,
  12061. * depthTest: <bool>,
  12062. * depthWrite: <bool>,
  12063. *
  12064. * wireframe: <boolean>,
  12065. * wireframeLinewidth: <float>,
  12066. *
  12067. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12068. *
  12069. * skinning: <bool>,
  12070. * morphTargets: <bool>,
  12071. *
  12072. * fog: <bool>
  12073. * }
  12074. */
  12075. THREE.MeshBasicMaterial = function ( parameters ) {
  12076. THREE.Material.call( this );
  12077. this.type = 'MeshBasicMaterial';
  12078. this.color = new THREE.Color( 0xffffff ); // emissive
  12079. this.map = null;
  12080. this.aoMap = null;
  12081. this.aoMapIntensity = 1.0;
  12082. this.specularMap = null;
  12083. this.alphaMap = null;
  12084. this.envMap = null;
  12085. this.combine = THREE.MultiplyOperation;
  12086. this.reflectivity = 1;
  12087. this.refractionRatio = 0.98;
  12088. this.fog = true;
  12089. this.shading = THREE.SmoothShading;
  12090. this.blending = THREE.NormalBlending;
  12091. this.wireframe = false;
  12092. this.wireframeLinewidth = 1;
  12093. this.wireframeLinecap = 'round';
  12094. this.wireframeLinejoin = 'round';
  12095. this.vertexColors = THREE.NoColors;
  12096. this.skinning = false;
  12097. this.morphTargets = false;
  12098. this.setValues( parameters );
  12099. };
  12100. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  12101. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  12102. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  12103. THREE.Material.prototype.copy.call( this, source );
  12104. this.color.copy( source.color );
  12105. this.map = source.map;
  12106. this.aoMap = source.aoMap;
  12107. this.aoMapIntensity = source.aoMapIntensity;
  12108. this.specularMap = source.specularMap;
  12109. this.alphaMap = source.alphaMap;
  12110. this.envMap = source.envMap;
  12111. this.combine = source.combine;
  12112. this.reflectivity = source.reflectivity;
  12113. this.refractionRatio = source.refractionRatio;
  12114. this.fog = source.fog;
  12115. this.shading = source.shading;
  12116. this.wireframe = source.wireframe;
  12117. this.wireframeLinewidth = source.wireframeLinewidth;
  12118. this.wireframeLinecap = source.wireframeLinecap;
  12119. this.wireframeLinejoin = source.wireframeLinejoin;
  12120. this.vertexColors = source.vertexColors;
  12121. this.skinning = source.skinning;
  12122. this.morphTargets = source.morphTargets;
  12123. return this;
  12124. };
  12125. // File:src/materials/MeshLambertMaterial.js
  12126. /**
  12127. * @author mrdoob / http://mrdoob.com/
  12128. * @author alteredq / http://alteredqualia.com/
  12129. *
  12130. * parameters = {
  12131. * color: <hex>,
  12132. * opacity: <float>,
  12133. *
  12134. * map: new THREE.Texture( <Image> ),
  12135. *
  12136. * lightMap: new THREE.Texture( <Image> ),
  12137. * lightMapIntensity: <float>
  12138. *
  12139. * aoMap: new THREE.Texture( <Image> ),
  12140. * aoMapIntensity: <float>
  12141. *
  12142. * emissive: <hex>,
  12143. * emissiveIntensity: <float>
  12144. * emissiveMap: new THREE.Texture( <Image> ),
  12145. *
  12146. * specularMap: new THREE.Texture( <Image> ),
  12147. *
  12148. * alphaMap: new THREE.Texture( <Image> ),
  12149. *
  12150. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12151. * combine: THREE.Multiply,
  12152. * reflectivity: <float>,
  12153. * refractionRatio: <float>,
  12154. *
  12155. * blending: THREE.NormalBlending,
  12156. * depthTest: <bool>,
  12157. * depthWrite: <bool>,
  12158. *
  12159. * wireframe: <boolean>,
  12160. * wireframeLinewidth: <float>,
  12161. *
  12162. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12163. *
  12164. * skinning: <bool>,
  12165. * morphTargets: <bool>,
  12166. * morphNormals: <bool>,
  12167. *
  12168. * fog: <bool>
  12169. * }
  12170. */
  12171. THREE.MeshLambertMaterial = function ( parameters ) {
  12172. THREE.Material.call( this );
  12173. this.type = 'MeshLambertMaterial';
  12174. this.color = new THREE.Color( 0xffffff ); // diffuse
  12175. this.map = null;
  12176. this.lightMap = null;
  12177. this.lightMapIntensity = 1.0;
  12178. this.aoMap = null;
  12179. this.aoMapIntensity = 1.0;
  12180. this.emissive = new THREE.Color( 0x000000 );
  12181. this.emissiveIntensity = 1.0;
  12182. this.emissiveMap = null;
  12183. this.specularMap = null;
  12184. this.alphaMap = null;
  12185. this.envMap = null;
  12186. this.combine = THREE.MultiplyOperation;
  12187. this.reflectivity = 1;
  12188. this.refractionRatio = 0.98;
  12189. this.fog = true;
  12190. this.blending = THREE.NormalBlending;
  12191. this.wireframe = false;
  12192. this.wireframeLinewidth = 1;
  12193. this.wireframeLinecap = 'round';
  12194. this.wireframeLinejoin = 'round';
  12195. this.vertexColors = THREE.NoColors;
  12196. this.skinning = false;
  12197. this.morphTargets = false;
  12198. this.morphNormals = false;
  12199. this.setValues( parameters );
  12200. };
  12201. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  12202. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  12203. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  12204. THREE.Material.prototype.copy.call( this, source );
  12205. this.color.copy( source.color );
  12206. this.map = source.map;
  12207. this.lightMap = source.lightMap;
  12208. this.lightMapIntensity = source.lightMapIntensity;
  12209. this.aoMap = source.aoMap;
  12210. this.aoMapIntensity = source.aoMapIntensity;
  12211. this.emissive.copy( source.emissive );
  12212. this.emissiveMap = source.emissiveMap;
  12213. this.emissiveIntensity = source.emissiveIntensity;
  12214. this.specularMap = source.specularMap;
  12215. this.alphaMap = source.alphaMap;
  12216. this.envMap = source.envMap;
  12217. this.combine = source.combine;
  12218. this.reflectivity = source.reflectivity;
  12219. this.refractionRatio = source.refractionRatio;
  12220. this.fog = source.fog;
  12221. this.wireframe = source.wireframe;
  12222. this.wireframeLinewidth = source.wireframeLinewidth;
  12223. this.wireframeLinecap = source.wireframeLinecap;
  12224. this.wireframeLinejoin = source.wireframeLinejoin;
  12225. this.vertexColors = source.vertexColors;
  12226. this.skinning = source.skinning;
  12227. this.morphTargets = source.morphTargets;
  12228. this.morphNormals = source.morphNormals;
  12229. return this;
  12230. };
  12231. // File:src/materials/MeshPhongMaterial.js
  12232. /**
  12233. * @author mrdoob / http://mrdoob.com/
  12234. * @author alteredq / http://alteredqualia.com/
  12235. *
  12236. * parameters = {
  12237. * color: <hex>,
  12238. * specular: <hex>,
  12239. * shininess: <float>,
  12240. * opacity: <float>,
  12241. *
  12242. * map: new THREE.Texture( <Image> ),
  12243. *
  12244. * lightMap: new THREE.Texture( <Image> ),
  12245. * lightMapIntensity: <float>
  12246. *
  12247. * aoMap: new THREE.Texture( <Image> ),
  12248. * aoMapIntensity: <float>
  12249. *
  12250. * emissive: <hex>,
  12251. * emissiveIntensity: <float>
  12252. * emissiveMap: new THREE.Texture( <Image> ),
  12253. *
  12254. * bumpMap: new THREE.Texture( <Image> ),
  12255. * bumpScale: <float>,
  12256. *
  12257. * normalMap: new THREE.Texture( <Image> ),
  12258. * normalScale: <Vector2>,
  12259. *
  12260. * displacementMap: new THREE.Texture( <Image> ),
  12261. * displacementScale: <float>,
  12262. * displacementBias: <float>,
  12263. *
  12264. * specularMap: new THREE.Texture( <Image> ),
  12265. *
  12266. * alphaMap: new THREE.Texture( <Image> ),
  12267. *
  12268. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12269. * combine: THREE.Multiply,
  12270. * reflectivity: <float>,
  12271. * refractionRatio: <float>,
  12272. *
  12273. * shading: THREE.SmoothShading,
  12274. * blending: THREE.NormalBlending,
  12275. * depthTest: <bool>,
  12276. * depthWrite: <bool>,
  12277. *
  12278. * wireframe: <boolean>,
  12279. * wireframeLinewidth: <float>,
  12280. *
  12281. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12282. *
  12283. * skinning: <bool>,
  12284. * morphTargets: <bool>,
  12285. * morphNormals: <bool>,
  12286. *
  12287. * fog: <bool>
  12288. * }
  12289. */
  12290. THREE.MeshPhongMaterial = function ( parameters ) {
  12291. THREE.Material.call( this );
  12292. this.type = 'MeshPhongMaterial';
  12293. this.color = new THREE.Color( 0xffffff ); // diffuse
  12294. this.specular = new THREE.Color( 0x111111 );
  12295. this.shininess = 30;
  12296. this.map = null;
  12297. this.lightMap = null;
  12298. this.lightMapIntensity = 1.0;
  12299. this.aoMap = null;
  12300. this.aoMapIntensity = 1.0;
  12301. this.emissive = new THREE.Color( 0x000000 );
  12302. this.emissiveIntensity = 1.0;
  12303. this.emissiveMap = null;
  12304. this.bumpMap = null;
  12305. this.bumpScale = 1;
  12306. this.normalMap = null;
  12307. this.normalScale = new THREE.Vector2( 1, 1 );
  12308. this.displacementMap = null;
  12309. this.displacementScale = 1;
  12310. this.displacementBias = 0;
  12311. this.specularMap = null;
  12312. this.alphaMap = null;
  12313. this.envMap = null;
  12314. this.combine = THREE.MultiplyOperation;
  12315. this.reflectivity = 1;
  12316. this.refractionRatio = 0.98;
  12317. this.fog = true;
  12318. this.shading = THREE.SmoothShading;
  12319. this.blending = THREE.NormalBlending;
  12320. this.wireframe = false;
  12321. this.wireframeLinewidth = 1;
  12322. this.wireframeLinecap = 'round';
  12323. this.wireframeLinejoin = 'round';
  12324. this.vertexColors = THREE.NoColors;
  12325. this.skinning = false;
  12326. this.morphTargets = false;
  12327. this.morphNormals = false;
  12328. this.setValues( parameters );
  12329. };
  12330. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  12331. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  12332. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  12333. THREE.Material.prototype.copy.call( this, source );
  12334. this.color.copy( source.color );
  12335. this.specular.copy( source.specular );
  12336. this.shininess = source.shininess;
  12337. this.map = source.map;
  12338. this.lightMap = source.lightMap;
  12339. this.lightMapIntensity = source.lightMapIntensity;
  12340. this.aoMap = source.aoMap;
  12341. this.aoMapIntensity = source.aoMapIntensity;
  12342. this.emissive.copy( source.emissive );
  12343. this.emissiveMap = source.emissiveMap;
  12344. this.emissiveIntensity = source.emissiveIntensity;
  12345. this.bumpMap = source.bumpMap;
  12346. this.bumpScale = source.bumpScale;
  12347. this.normalMap = source.normalMap;
  12348. this.normalScale.copy( source.normalScale );
  12349. this.displacementMap = source.displacementMap;
  12350. this.displacementScale = source.displacementScale;
  12351. this.displacementBias = source.displacementBias;
  12352. this.specularMap = source.specularMap;
  12353. this.alphaMap = source.alphaMap;
  12354. this.envMap = source.envMap;
  12355. this.combine = source.combine;
  12356. this.reflectivity = source.reflectivity;
  12357. this.refractionRatio = source.refractionRatio;
  12358. this.fog = source.fog;
  12359. this.shading = source.shading;
  12360. this.wireframe = source.wireframe;
  12361. this.wireframeLinewidth = source.wireframeLinewidth;
  12362. this.wireframeLinecap = source.wireframeLinecap;
  12363. this.wireframeLinejoin = source.wireframeLinejoin;
  12364. this.vertexColors = source.vertexColors;
  12365. this.skinning = source.skinning;
  12366. this.morphTargets = source.morphTargets;
  12367. this.morphNormals = source.morphNormals;
  12368. return this;
  12369. };
  12370. // File:src/materials/MeshStandardMaterial.js
  12371. /**
  12372. * @author WestLangley / http://github.com/WestLangley
  12373. *
  12374. * parameters = {
  12375. * color: <hex>,
  12376. * roughness: <float>,
  12377. * metalness: <float>,
  12378. * opacity: <float>,
  12379. *
  12380. * map: new THREE.Texture( <Image> ),
  12381. *
  12382. * lightMap: new THREE.Texture( <Image> ),
  12383. * lightMapIntensity: <float>
  12384. *
  12385. * aoMap: new THREE.Texture( <Image> ),
  12386. * aoMapIntensity: <float>
  12387. *
  12388. * emissive: <hex>,
  12389. * emissiveIntensity: <float>
  12390. * emissiveMap: new THREE.Texture( <Image> ),
  12391. *
  12392. * bumpMap: new THREE.Texture( <Image> ),
  12393. * bumpScale: <float>,
  12394. *
  12395. * normalMap: new THREE.Texture( <Image> ),
  12396. * normalScale: <Vector2>,
  12397. *
  12398. * displacementMap: new THREE.Texture( <Image> ),
  12399. * displacementScale: <float>,
  12400. * displacementBias: <float>,
  12401. *
  12402. * roughnessMap: new THREE.Texture( <Image> ),
  12403. *
  12404. * metalnessMap: new THREE.Texture( <Image> ),
  12405. *
  12406. * alphaMap: new THREE.Texture( <Image> ),
  12407. *
  12408. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  12409. * envMapIntensity: <float>
  12410. *
  12411. * refractionRatio: <float>,
  12412. *
  12413. * shading: THREE.SmoothShading,
  12414. * blending: THREE.NormalBlending,
  12415. * depthTest: <bool>,
  12416. * depthWrite: <bool>,
  12417. *
  12418. * wireframe: <boolean>,
  12419. * wireframeLinewidth: <float>,
  12420. *
  12421. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12422. *
  12423. * skinning: <bool>,
  12424. * morphTargets: <bool>,
  12425. * morphNormals: <bool>,
  12426. *
  12427. * fog: <bool>
  12428. * }
  12429. */
  12430. THREE.MeshStandardMaterial = function ( parameters ) {
  12431. THREE.Material.call( this );
  12432. this.type = 'MeshStandardMaterial';
  12433. this.color = new THREE.Color( 0xffffff ); // diffuse
  12434. this.roughness = 0.5;
  12435. this.metalness = 0.5;
  12436. this.map = null;
  12437. this.lightMap = null;
  12438. this.lightMapIntensity = 1.0;
  12439. this.aoMap = null;
  12440. this.aoMapIntensity = 1.0;
  12441. this.emissive = new THREE.Color( 0x000000 );
  12442. this.emissiveIntensity = 1.0;
  12443. this.emissiveMap = null;
  12444. this.bumpMap = null;
  12445. this.bumpScale = 1;
  12446. this.normalMap = null;
  12447. this.normalScale = new THREE.Vector2( 1, 1 );
  12448. this.displacementMap = null;
  12449. this.displacementScale = 1;
  12450. this.displacementBias = 0;
  12451. this.roughnessMap = null;
  12452. this.metalnessMap = null;
  12453. this.alphaMap = null;
  12454. this.envMap = null;
  12455. this.envMapIntensity = 1.0;
  12456. this.refractionRatio = 0.98;
  12457. this.fog = true;
  12458. this.shading = THREE.SmoothShading;
  12459. this.blending = THREE.NormalBlending;
  12460. this.wireframe = false;
  12461. this.wireframeLinewidth = 1;
  12462. this.wireframeLinecap = 'round';
  12463. this.wireframeLinejoin = 'round';
  12464. this.vertexColors = THREE.NoColors;
  12465. this.skinning = false;
  12466. this.morphTargets = false;
  12467. this.morphNormals = false;
  12468. this.setValues( parameters );
  12469. };
  12470. THREE.MeshStandardMaterial.prototype = Object.create( THREE.Material.prototype );
  12471. THREE.MeshStandardMaterial.prototype.constructor = THREE.MeshStandardMaterial;
  12472. THREE.MeshStandardMaterial.prototype.copy = function ( source ) {
  12473. THREE.Material.prototype.copy.call( this, source );
  12474. this.color.copy( source.color );
  12475. this.roughness = source.roughness;
  12476. this.metalness = source.metalness;
  12477. this.map = source.map;
  12478. this.lightMap = source.lightMap;
  12479. this.lightMapIntensity = source.lightMapIntensity;
  12480. this.aoMap = source.aoMap;
  12481. this.aoMapIntensity = source.aoMapIntensity;
  12482. this.emissive.copy( source.emissive );
  12483. this.emissiveMap = source.emissiveMap;
  12484. this.emissiveIntensity = source.emissiveIntensity;
  12485. this.bumpMap = source.bumpMap;
  12486. this.bumpScale = source.bumpScale;
  12487. this.normalMap = source.normalMap;
  12488. this.normalScale.copy( source.normalScale );
  12489. this.displacementMap = source.displacementMap;
  12490. this.displacementScale = source.displacementScale;
  12491. this.displacementBias = source.displacementBias;
  12492. this.roughnessMap = source.roughnessMap;
  12493. this.metalnessMap = source.metalnessMap;
  12494. this.alphaMap = source.alphaMap;
  12495. this.envMap = source.envMap;
  12496. this.envMapIntensity = source.envMapIntensity;
  12497. this.refractionRatio = source.refractionRatio;
  12498. this.fog = source.fog;
  12499. this.shading = source.shading;
  12500. this.wireframe = source.wireframe;
  12501. this.wireframeLinewidth = source.wireframeLinewidth;
  12502. this.wireframeLinecap = source.wireframeLinecap;
  12503. this.wireframeLinejoin = source.wireframeLinejoin;
  12504. this.vertexColors = source.vertexColors;
  12505. this.skinning = source.skinning;
  12506. this.morphTargets = source.morphTargets;
  12507. this.morphNormals = source.morphNormals;
  12508. return this;
  12509. };
  12510. // File:src/materials/MeshDepthMaterial.js
  12511. /**
  12512. * @author mrdoob / http://mrdoob.com/
  12513. * @author alteredq / http://alteredqualia.com/
  12514. *
  12515. * parameters = {
  12516. * opacity: <float>,
  12517. *
  12518. * wireframe: <boolean>,
  12519. * wireframeLinewidth: <float>
  12520. * }
  12521. */
  12522. THREE.MeshDepthMaterial = function ( parameters ) {
  12523. THREE.Material.call( this );
  12524. this.type = 'MeshDepthMaterial';
  12525. this.morphTargets = false;
  12526. this.wireframe = false;
  12527. this.wireframeLinewidth = 1;
  12528. this.setValues( parameters );
  12529. };
  12530. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  12531. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  12532. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  12533. THREE.Material.prototype.copy.call( this, source );
  12534. this.wireframe = source.wireframe;
  12535. this.wireframeLinewidth = source.wireframeLinewidth;
  12536. return this;
  12537. };
  12538. // File:src/materials/MeshNormalMaterial.js
  12539. /**
  12540. * @author mrdoob / http://mrdoob.com/
  12541. *
  12542. * parameters = {
  12543. * opacity: <float>,
  12544. *
  12545. * wireframe: <boolean>,
  12546. * wireframeLinewidth: <float>
  12547. * }
  12548. */
  12549. THREE.MeshNormalMaterial = function ( parameters ) {
  12550. THREE.Material.call( this, parameters );
  12551. this.type = 'MeshNormalMaterial';
  12552. this.wireframe = false;
  12553. this.wireframeLinewidth = 1;
  12554. this.morphTargets = false;
  12555. this.setValues( parameters );
  12556. };
  12557. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  12558. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  12559. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  12560. THREE.Material.prototype.copy.call( this, source );
  12561. this.wireframe = source.wireframe;
  12562. this.wireframeLinewidth = source.wireframeLinewidth;
  12563. return this;
  12564. };
  12565. // File:src/materials/MultiMaterial.js
  12566. /**
  12567. * @author mrdoob / http://mrdoob.com/
  12568. */
  12569. THREE.MultiMaterial = function ( materials ) {
  12570. this.uuid = THREE.Math.generateUUID();
  12571. this.type = 'MultiMaterial';
  12572. this.materials = materials instanceof Array ? materials : [];
  12573. this.visible = true;
  12574. };
  12575. THREE.MultiMaterial.prototype = {
  12576. constructor: THREE.MultiMaterial,
  12577. toJSON: function ( meta ) {
  12578. var output = {
  12579. metadata: {
  12580. version: 4.2,
  12581. type: 'material',
  12582. generator: 'MaterialExporter'
  12583. },
  12584. uuid: this.uuid,
  12585. type: this.type,
  12586. materials: []
  12587. };
  12588. var materials = this.materials;
  12589. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  12590. var material = materials[ i ].toJSON( meta );
  12591. delete material.metadata;
  12592. output.materials.push( material );
  12593. }
  12594. output.visible = this.visible;
  12595. return output;
  12596. },
  12597. clone: function () {
  12598. var material = new this.constructor();
  12599. for ( var i = 0; i < this.materials.length; i ++ ) {
  12600. material.materials.push( this.materials[ i ].clone() );
  12601. }
  12602. material.visible = this.visible;
  12603. return material;
  12604. }
  12605. };
  12606. // File:src/materials/PointsMaterial.js
  12607. /**
  12608. * @author mrdoob / http://mrdoob.com/
  12609. * @author alteredq / http://alteredqualia.com/
  12610. *
  12611. * parameters = {
  12612. * color: <hex>,
  12613. * opacity: <float>,
  12614. * map: new THREE.Texture( <Image> ),
  12615. *
  12616. * size: <float>,
  12617. * sizeAttenuation: <bool>,
  12618. *
  12619. * blending: THREE.NormalBlending,
  12620. * depthTest: <bool>,
  12621. * depthWrite: <bool>,
  12622. *
  12623. * vertexColors: <bool>,
  12624. *
  12625. * fog: <bool>
  12626. * }
  12627. */
  12628. THREE.PointsMaterial = function ( parameters ) {
  12629. THREE.Material.call( this );
  12630. this.type = 'PointsMaterial';
  12631. this.color = new THREE.Color( 0xffffff );
  12632. this.map = null;
  12633. this.size = 1;
  12634. this.sizeAttenuation = true;
  12635. this.blending = THREE.NormalBlending;
  12636. this.vertexColors = THREE.NoColors;
  12637. this.fog = true;
  12638. this.setValues( parameters );
  12639. };
  12640. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  12641. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  12642. THREE.PointsMaterial.prototype.copy = function ( source ) {
  12643. THREE.Material.prototype.copy.call( this, source );
  12644. this.color.copy( source.color );
  12645. this.map = source.map;
  12646. this.size = source.size;
  12647. this.sizeAttenuation = source.sizeAttenuation;
  12648. this.vertexColors = source.vertexColors;
  12649. this.fog = source.fog;
  12650. return this;
  12651. };
  12652. // File:src/materials/ShaderMaterial.js
  12653. /**
  12654. * @author alteredq / http://alteredqualia.com/
  12655. *
  12656. * parameters = {
  12657. * defines: { "label" : "value" },
  12658. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  12659. *
  12660. * fragmentShader: <string>,
  12661. * vertexShader: <string>,
  12662. *
  12663. * shading: THREE.SmoothShading,
  12664. *
  12665. * wireframe: <boolean>,
  12666. * wireframeLinewidth: <float>,
  12667. *
  12668. * lights: <bool>,
  12669. *
  12670. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12671. *
  12672. * skinning: <bool>,
  12673. * morphTargets: <bool>,
  12674. * morphNormals: <bool>,
  12675. *
  12676. * fog: <bool>
  12677. * }
  12678. */
  12679. THREE.ShaderMaterial = function ( parameters ) {
  12680. THREE.Material.call( this );
  12681. this.type = 'ShaderMaterial';
  12682. this.defines = {};
  12683. this.uniforms = {};
  12684. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12685. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12686. this.shading = THREE.SmoothShading;
  12687. this.linewidth = 1;
  12688. this.wireframe = false;
  12689. this.wireframeLinewidth = 1;
  12690. this.fog = false; // set to use scene fog
  12691. this.lights = false; // set to use scene lights
  12692. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  12693. this.skinning = false; // set to use skinning attribute streams
  12694. this.morphTargets = false; // set to use morph targets
  12695. this.morphNormals = false; // set to use morph normals
  12696. this.extensions = {
  12697. derivatives: false, // set to use derivatives
  12698. fragDepth: false, // set to use fragment depth values
  12699. drawBuffers: false, // set to use draw buffers
  12700. shaderTextureLOD: false // set to use shader texture LOD
  12701. };
  12702. // When rendered geometry doesn't include these attributes but the material does,
  12703. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12704. this.defaultAttributeValues = {
  12705. 'color': [ 1, 1, 1 ],
  12706. 'uv': [ 0, 0 ],
  12707. 'uv2': [ 0, 0 ]
  12708. };
  12709. this.index0AttributeName = undefined;
  12710. if ( parameters !== undefined ) {
  12711. if ( parameters.attributes !== undefined ) {
  12712. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12713. }
  12714. this.setValues( parameters );
  12715. }
  12716. };
  12717. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  12718. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  12719. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  12720. THREE.Material.prototype.copy.call( this, source );
  12721. this.fragmentShader = source.fragmentShader;
  12722. this.vertexShader = source.vertexShader;
  12723. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  12724. this.defines = source.defines;
  12725. this.shading = source.shading;
  12726. this.wireframe = source.wireframe;
  12727. this.wireframeLinewidth = source.wireframeLinewidth;
  12728. this.fog = source.fog;
  12729. this.lights = source.lights;
  12730. this.vertexColors = source.vertexColors;
  12731. this.skinning = source.skinning;
  12732. this.morphTargets = source.morphTargets;
  12733. this.morphNormals = source.morphNormals;
  12734. this.extensions = source.extensions;
  12735. return this;
  12736. };
  12737. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  12738. var data = THREE.Material.prototype.toJSON.call( this, meta );
  12739. data.uniforms = this.uniforms;
  12740. data.vertexShader = this.vertexShader;
  12741. data.fragmentShader = this.fragmentShader;
  12742. return data;
  12743. };
  12744. // File:src/materials/RawShaderMaterial.js
  12745. /**
  12746. * @author mrdoob / http://mrdoob.com/
  12747. */
  12748. THREE.RawShaderMaterial = function ( parameters ) {
  12749. THREE.ShaderMaterial.call( this, parameters );
  12750. this.type = 'RawShaderMaterial';
  12751. };
  12752. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  12753. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  12754. // File:src/materials/SpriteMaterial.js
  12755. /**
  12756. * @author alteredq / http://alteredqualia.com/
  12757. *
  12758. * parameters = {
  12759. * color: <hex>,
  12760. * opacity: <float>,
  12761. * map: new THREE.Texture( <Image> ),
  12762. *
  12763. * uvOffset: new THREE.Vector2(),
  12764. * uvScale: new THREE.Vector2(),
  12765. *
  12766. * fog: <bool>
  12767. * }
  12768. */
  12769. THREE.SpriteMaterial = function ( parameters ) {
  12770. THREE.Material.call( this );
  12771. this.type = 'SpriteMaterial';
  12772. this.color = new THREE.Color( 0xffffff );
  12773. this.map = null;
  12774. this.rotation = 0;
  12775. this.fog = false;
  12776. // set parameters
  12777. this.setValues( parameters );
  12778. };
  12779. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  12780. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  12781. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  12782. THREE.Material.prototype.copy.call( this, source );
  12783. this.color.copy( source.color );
  12784. this.map = source.map;
  12785. this.rotation = source.rotation;
  12786. this.fog = source.fog;
  12787. return this;
  12788. };
  12789. // File:src/textures/Texture.js
  12790. /**
  12791. * @author mrdoob / http://mrdoob.com/
  12792. * @author alteredq / http://alteredqualia.com/
  12793. * @author szimek / https://github.com/szimek/
  12794. */
  12795. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12796. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  12797. this.uuid = THREE.Math.generateUUID();
  12798. this.name = '';
  12799. this.sourceFile = '';
  12800. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  12801. this.mipmaps = [];
  12802. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  12803. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  12804. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  12805. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  12806. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  12807. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  12808. this.format = format !== undefined ? format : THREE.RGBAFormat;
  12809. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  12810. this.offset = new THREE.Vector2( 0, 0 );
  12811. this.repeat = new THREE.Vector2( 1, 1 );
  12812. this.generateMipmaps = true;
  12813. this.premultiplyAlpha = false;
  12814. this.flipY = true;
  12815. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  12816. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  12817. //
  12818. // Also changing the encoding after already used by a Material will not automatically make the Material
  12819. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  12820. this.encoding = THREE.LinearEncoding;
  12821. this.version = 0;
  12822. this.onUpdate = null;
  12823. };
  12824. THREE.Texture.DEFAULT_IMAGE = undefined;
  12825. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  12826. THREE.Texture.prototype = {
  12827. constructor: THREE.Texture,
  12828. set needsUpdate ( value ) {
  12829. if ( value === true ) this.version ++;
  12830. },
  12831. clone: function () {
  12832. return new this.constructor().copy( this );
  12833. },
  12834. copy: function ( source ) {
  12835. this.image = source.image;
  12836. this.mipmaps = source.mipmaps.slice( 0 );
  12837. this.mapping = source.mapping;
  12838. this.wrapS = source.wrapS;
  12839. this.wrapT = source.wrapT;
  12840. this.magFilter = source.magFilter;
  12841. this.minFilter = source.minFilter;
  12842. this.anisotropy = source.anisotropy;
  12843. this.format = source.format;
  12844. this.type = source.type;
  12845. this.offset.copy( source.offset );
  12846. this.repeat.copy( source.repeat );
  12847. this.generateMipmaps = source.generateMipmaps;
  12848. this.premultiplyAlpha = source.premultiplyAlpha;
  12849. this.flipY = source.flipY;
  12850. this.unpackAlignment = source.unpackAlignment;
  12851. this.encoding = source.encoding;
  12852. return this;
  12853. },
  12854. toJSON: function ( meta ) {
  12855. if ( meta.textures[ this.uuid ] !== undefined ) {
  12856. return meta.textures[ this.uuid ];
  12857. }
  12858. function getDataURL( image ) {
  12859. var canvas;
  12860. if ( image.toDataURL !== undefined ) {
  12861. canvas = image;
  12862. } else {
  12863. canvas = document.createElement( 'canvas' );
  12864. canvas.width = image.width;
  12865. canvas.height = image.height;
  12866. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  12867. }
  12868. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  12869. return canvas.toDataURL( 'image/jpeg', 0.6 );
  12870. } else {
  12871. return canvas.toDataURL( 'image/png' );
  12872. }
  12873. }
  12874. var output = {
  12875. metadata: {
  12876. version: 4.4,
  12877. type: 'Texture',
  12878. generator: 'Texture.toJSON'
  12879. },
  12880. uuid: this.uuid,
  12881. name: this.name,
  12882. mapping: this.mapping,
  12883. repeat: [ this.repeat.x, this.repeat.y ],
  12884. offset: [ this.offset.x, this.offset.y ],
  12885. wrap: [ this.wrapS, this.wrapT ],
  12886. minFilter: this.minFilter,
  12887. magFilter: this.magFilter,
  12888. anisotropy: this.anisotropy
  12889. };
  12890. if ( this.image !== undefined ) {
  12891. // TODO: Move to THREE.Image
  12892. var image = this.image;
  12893. if ( image.uuid === undefined ) {
  12894. image.uuid = THREE.Math.generateUUID(); // UGH
  12895. }
  12896. if ( meta.images[ image.uuid ] === undefined ) {
  12897. meta.images[ image.uuid ] = {
  12898. uuid: image.uuid,
  12899. url: getDataURL( image )
  12900. };
  12901. }
  12902. output.image = image.uuid;
  12903. }
  12904. meta.textures[ this.uuid ] = output;
  12905. return output;
  12906. },
  12907. dispose: function () {
  12908. this.dispatchEvent( { type: 'dispose' } );
  12909. },
  12910. transformUv: function ( uv ) {
  12911. if ( this.mapping !== THREE.UVMapping ) return;
  12912. uv.multiply( this.repeat );
  12913. uv.add( this.offset );
  12914. if ( uv.x < 0 || uv.x > 1 ) {
  12915. switch ( this.wrapS ) {
  12916. case THREE.RepeatWrapping:
  12917. uv.x = uv.x - Math.floor( uv.x );
  12918. break;
  12919. case THREE.ClampToEdgeWrapping:
  12920. uv.x = uv.x < 0 ? 0 : 1;
  12921. break;
  12922. case THREE.MirroredRepeatWrapping:
  12923. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  12924. uv.x = Math.ceil( uv.x ) - uv.x;
  12925. } else {
  12926. uv.x = uv.x - Math.floor( uv.x );
  12927. }
  12928. break;
  12929. }
  12930. }
  12931. if ( uv.y < 0 || uv.y > 1 ) {
  12932. switch ( this.wrapT ) {
  12933. case THREE.RepeatWrapping:
  12934. uv.y = uv.y - Math.floor( uv.y );
  12935. break;
  12936. case THREE.ClampToEdgeWrapping:
  12937. uv.y = uv.y < 0 ? 0 : 1;
  12938. break;
  12939. case THREE.MirroredRepeatWrapping:
  12940. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  12941. uv.y = Math.ceil( uv.y ) - uv.y;
  12942. } else {
  12943. uv.y = uv.y - Math.floor( uv.y );
  12944. }
  12945. break;
  12946. }
  12947. }
  12948. if ( this.flipY ) {
  12949. uv.y = 1 - uv.y;
  12950. }
  12951. }
  12952. };
  12953. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  12954. THREE.TextureIdCount = 0;
  12955. // File:src/textures/CanvasTexture.js
  12956. /**
  12957. * @author mrdoob / http://mrdoob.com/
  12958. */
  12959. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12960. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12961. this.needsUpdate = true;
  12962. };
  12963. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  12964. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  12965. // File:src/textures/CubeTexture.js
  12966. /**
  12967. * @author mrdoob / http://mrdoob.com/
  12968. */
  12969. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12970. images = images !== undefined ? images : [];
  12971. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  12972. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12973. this.flipY = false;
  12974. };
  12975. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  12976. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  12977. Object.defineProperty( THREE.CubeTexture.prototype, 'images', {
  12978. get: function () {
  12979. return this.image;
  12980. },
  12981. set: function ( value ) {
  12982. this.image = value;
  12983. }
  12984. } );
  12985. // File:src/textures/CompressedTexture.js
  12986. /**
  12987. * @author alteredq / http://alteredqualia.com/
  12988. */
  12989. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  12990. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12991. this.image = { width: width, height: height };
  12992. this.mipmaps = mipmaps;
  12993. // no flipping for cube textures
  12994. // (also flipping doesn't work for compressed textures )
  12995. this.flipY = false;
  12996. // can't generate mipmaps for compressed textures
  12997. // mips must be embedded in DDS files
  12998. this.generateMipmaps = false;
  12999. };
  13000. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  13001. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  13002. // File:src/textures/DataTexture.js
  13003. /**
  13004. * @author alteredq / http://alteredqualia.com/
  13005. */
  13006. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  13007. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13008. this.image = { data: data, width: width, height: height };
  13009. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  13010. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  13011. this.flipY = false;
  13012. this.generateMipmaps = false;
  13013. };
  13014. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  13015. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  13016. // File:src/textures/VideoTexture.js
  13017. /**
  13018. * @author mrdoob / http://mrdoob.com/
  13019. */
  13020. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  13021. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13022. this.generateMipmaps = false;
  13023. var scope = this;
  13024. function update() {
  13025. requestAnimationFrame( update );
  13026. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  13027. scope.needsUpdate = true;
  13028. }
  13029. }
  13030. update();
  13031. };
  13032. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  13033. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  13034. // File:src/objects/Group.js
  13035. /**
  13036. * @author mrdoob / http://mrdoob.com/
  13037. */
  13038. THREE.Group = function () {
  13039. THREE.Object3D.call( this );
  13040. this.type = 'Group';
  13041. };
  13042. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  13043. THREE.Group.prototype.constructor = THREE.Group;
  13044. // File:src/objects/Points.js
  13045. /**
  13046. * @author alteredq / http://alteredqualia.com/
  13047. */
  13048. THREE.Points = function ( geometry, material ) {
  13049. THREE.Object3D.call( this );
  13050. this.type = 'Points';
  13051. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  13052. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  13053. };
  13054. THREE.Points.prototype = Object.create( THREE.Object3D.prototype );
  13055. THREE.Points.prototype.constructor = THREE.Points;
  13056. THREE.Points.prototype.raycast = ( function () {
  13057. var inverseMatrix = new THREE.Matrix4();
  13058. var ray = new THREE.Ray();
  13059. var sphere = new THREE.Sphere();
  13060. return function raycast( raycaster, intersects ) {
  13061. var object = this;
  13062. var geometry = this.geometry;
  13063. var matrixWorld = this.matrixWorld;
  13064. var threshold = raycaster.params.Points.threshold;
  13065. // Checking boundingSphere distance to ray
  13066. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13067. sphere.copy( geometry.boundingSphere );
  13068. sphere.applyMatrix4( matrixWorld );
  13069. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13070. //
  13071. inverseMatrix.getInverse( matrixWorld );
  13072. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13073. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  13074. var localThresholdSq = localThreshold * localThreshold;
  13075. var position = new THREE.Vector3();
  13076. function testPoint( point, index ) {
  13077. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  13078. if ( rayPointDistanceSq < localThresholdSq ) {
  13079. var intersectPoint = ray.closestPointToPoint( point );
  13080. intersectPoint.applyMatrix4( matrixWorld );
  13081. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  13082. if ( distance < raycaster.near || distance > raycaster.far ) return;
  13083. intersects.push( {
  13084. distance: distance,
  13085. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  13086. point: intersectPoint.clone(),
  13087. index: index,
  13088. face: null,
  13089. object: object
  13090. } );
  13091. }
  13092. }
  13093. if ( geometry instanceof THREE.BufferGeometry ) {
  13094. var index = geometry.index;
  13095. var attributes = geometry.attributes;
  13096. var positions = attributes.position.array;
  13097. if ( index !== null ) {
  13098. var indices = index.array;
  13099. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  13100. var a = indices[ i ];
  13101. position.fromArray( positions, a * 3 );
  13102. testPoint( position, a );
  13103. }
  13104. } else {
  13105. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  13106. position.fromArray( positions, i * 3 );
  13107. testPoint( position, i );
  13108. }
  13109. }
  13110. } else {
  13111. var vertices = geometry.vertices;
  13112. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  13113. testPoint( vertices[ i ], i );
  13114. }
  13115. }
  13116. };
  13117. }() );
  13118. THREE.Points.prototype.clone = function () {
  13119. return new this.constructor( this.geometry, this.material ).copy( this );
  13120. };
  13121. // File:src/objects/Line.js
  13122. /**
  13123. * @author mrdoob / http://mrdoob.com/
  13124. */
  13125. THREE.Line = function ( geometry, material, mode ) {
  13126. if ( mode === 1 ) {
  13127. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  13128. return new THREE.LineSegments( geometry, material );
  13129. }
  13130. THREE.Object3D.call( this );
  13131. this.type = 'Line';
  13132. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  13133. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  13134. };
  13135. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  13136. THREE.Line.prototype.constructor = THREE.Line;
  13137. THREE.Line.prototype.raycast = ( function () {
  13138. var inverseMatrix = new THREE.Matrix4();
  13139. var ray = new THREE.Ray();
  13140. var sphere = new THREE.Sphere();
  13141. return function raycast( raycaster, intersects ) {
  13142. var precision = raycaster.linePrecision;
  13143. var precisionSq = precision * precision;
  13144. var geometry = this.geometry;
  13145. var matrixWorld = this.matrixWorld;
  13146. // Checking boundingSphere distance to ray
  13147. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13148. sphere.copy( geometry.boundingSphere );
  13149. sphere.applyMatrix4( matrixWorld );
  13150. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13151. //
  13152. inverseMatrix.getInverse( matrixWorld );
  13153. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13154. var vStart = new THREE.Vector3();
  13155. var vEnd = new THREE.Vector3();
  13156. var interSegment = new THREE.Vector3();
  13157. var interRay = new THREE.Vector3();
  13158. var step = this instanceof THREE.LineSegments ? 2 : 1;
  13159. if ( geometry instanceof THREE.BufferGeometry ) {
  13160. var index = geometry.index;
  13161. var attributes = geometry.attributes;
  13162. var positions = attributes.position.array;
  13163. if ( index !== null ) {
  13164. var indices = index.array;
  13165. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  13166. var a = indices[ i ];
  13167. var b = indices[ i + 1 ];
  13168. vStart.fromArray( positions, a * 3 );
  13169. vEnd.fromArray( positions, b * 3 );
  13170. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13171. if ( distSq > precisionSq ) continue;
  13172. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13173. var distance = raycaster.ray.origin.distanceTo( interRay );
  13174. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13175. intersects.push( {
  13176. distance: distance,
  13177. // What do we want? intersection point on the ray or on the segment??
  13178. // point: raycaster.ray.at( distance ),
  13179. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13180. index: i,
  13181. face: null,
  13182. faceIndex: null,
  13183. object: this
  13184. } );
  13185. }
  13186. } else {
  13187. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  13188. vStart.fromArray( positions, 3 * i );
  13189. vEnd.fromArray( positions, 3 * i + 3 );
  13190. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13191. if ( distSq > precisionSq ) continue;
  13192. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13193. var distance = raycaster.ray.origin.distanceTo( interRay );
  13194. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13195. intersects.push( {
  13196. distance: distance,
  13197. // What do we want? intersection point on the ray or on the segment??
  13198. // point: raycaster.ray.at( distance ),
  13199. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13200. index: i,
  13201. face: null,
  13202. faceIndex: null,
  13203. object: this
  13204. } );
  13205. }
  13206. }
  13207. } else if ( geometry instanceof THREE.Geometry ) {
  13208. var vertices = geometry.vertices;
  13209. var nbVertices = vertices.length;
  13210. for ( var i = 0; i < nbVertices - 1; i += step ) {
  13211. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  13212. if ( distSq > precisionSq ) continue;
  13213. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13214. var distance = raycaster.ray.origin.distanceTo( interRay );
  13215. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13216. intersects.push( {
  13217. distance: distance,
  13218. // What do we want? intersection point on the ray or on the segment??
  13219. // point: raycaster.ray.at( distance ),
  13220. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13221. index: i,
  13222. face: null,
  13223. faceIndex: null,
  13224. object: this
  13225. } );
  13226. }
  13227. }
  13228. };
  13229. }() );
  13230. THREE.Line.prototype.clone = function () {
  13231. return new this.constructor( this.geometry, this.material ).copy( this );
  13232. };
  13233. // DEPRECATED
  13234. THREE.LineStrip = 0;
  13235. THREE.LinePieces = 1;
  13236. // File:src/objects/LineSegments.js
  13237. /**
  13238. * @author mrdoob / http://mrdoob.com/
  13239. */
  13240. THREE.LineSegments = function ( geometry, material ) {
  13241. THREE.Line.call( this, geometry, material );
  13242. this.type = 'LineSegments';
  13243. };
  13244. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  13245. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  13246. // File:src/objects/Mesh.js
  13247. /**
  13248. * @author mrdoob / http://mrdoob.com/
  13249. * @author alteredq / http://alteredqualia.com/
  13250. * @author mikael emtinger / http://gomo.se/
  13251. * @author jonobr1 / http://jonobr1.com/
  13252. */
  13253. THREE.Mesh = function ( geometry, material ) {
  13254. THREE.Object3D.call( this );
  13255. this.type = 'Mesh';
  13256. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  13257. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  13258. this.drawMode = THREE.TrianglesDrawMode;
  13259. this.updateMorphTargets();
  13260. };
  13261. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  13262. THREE.Mesh.prototype.constructor = THREE.Mesh;
  13263. THREE.Mesh.prototype.setDrawMode = function ( value ) {
  13264. this.drawMode = value;
  13265. };
  13266. THREE.Mesh.prototype.updateMorphTargets = function () {
  13267. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  13268. this.morphTargetBase = - 1;
  13269. this.morphTargetInfluences = [];
  13270. this.morphTargetDictionary = {};
  13271. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  13272. this.morphTargetInfluences.push( 0 );
  13273. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  13274. }
  13275. }
  13276. };
  13277. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  13278. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  13279. return this.morphTargetDictionary[ name ];
  13280. }
  13281. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  13282. return 0;
  13283. };
  13284. THREE.Mesh.prototype.raycast = ( function () {
  13285. var inverseMatrix = new THREE.Matrix4();
  13286. var ray = new THREE.Ray();
  13287. var sphere = new THREE.Sphere();
  13288. var vA = new THREE.Vector3();
  13289. var vB = new THREE.Vector3();
  13290. var vC = new THREE.Vector3();
  13291. var tempA = new THREE.Vector3();
  13292. var tempB = new THREE.Vector3();
  13293. var tempC = new THREE.Vector3();
  13294. var uvA = new THREE.Vector2();
  13295. var uvB = new THREE.Vector2();
  13296. var uvC = new THREE.Vector2();
  13297. var barycoord = new THREE.Vector3();
  13298. var intersectionPoint = new THREE.Vector3();
  13299. var intersectionPointWorld = new THREE.Vector3();
  13300. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  13301. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  13302. uv1.multiplyScalar( barycoord.x );
  13303. uv2.multiplyScalar( barycoord.y );
  13304. uv3.multiplyScalar( barycoord.z );
  13305. uv1.add( uv2 ).add( uv3 );
  13306. return uv1.clone();
  13307. }
  13308. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ) {
  13309. var intersect;
  13310. var material = object.material;
  13311. if ( material.side === THREE.BackSide ) {
  13312. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  13313. } else {
  13314. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== THREE.DoubleSide, point );
  13315. }
  13316. if ( intersect === null ) return null;
  13317. intersectionPointWorld.copy( point );
  13318. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  13319. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  13320. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  13321. return {
  13322. distance: distance,
  13323. point: intersectionPointWorld.clone(),
  13324. object: object
  13325. };
  13326. }
  13327. function checkBufferGeometryIntersection( object, raycaster, ray, positions, uvs, a, b, c ) {
  13328. vA.fromArray( positions, a * 3 );
  13329. vB.fromArray( positions, b * 3 );
  13330. vC.fromArray( positions, c * 3 );
  13331. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  13332. if ( intersection ) {
  13333. if ( uvs ) {
  13334. uvA.fromArray( uvs, a * 2 );
  13335. uvB.fromArray( uvs, b * 2 );
  13336. uvC.fromArray( uvs, c * 2 );
  13337. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  13338. }
  13339. intersection.face = new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) );
  13340. intersection.faceIndex = a;
  13341. }
  13342. return intersection;
  13343. }
  13344. return function raycast( raycaster, intersects ) {
  13345. var geometry = this.geometry;
  13346. var material = this.material;
  13347. var matrixWorld = this.matrixWorld;
  13348. if ( material === undefined ) return;
  13349. // Checking boundingSphere distance to ray
  13350. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13351. sphere.copy( geometry.boundingSphere );
  13352. sphere.applyMatrix4( matrixWorld );
  13353. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13354. //
  13355. inverseMatrix.getInverse( matrixWorld );
  13356. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13357. // Check boundingBox before continuing
  13358. if ( geometry.boundingBox !== null ) {
  13359. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  13360. }
  13361. var uvs, intersection;
  13362. if ( geometry instanceof THREE.BufferGeometry ) {
  13363. var a, b, c;
  13364. var index = geometry.index;
  13365. var attributes = geometry.attributes;
  13366. var positions = attributes.position.array;
  13367. if ( attributes.uv !== undefined ) {
  13368. uvs = attributes.uv.array;
  13369. }
  13370. if ( index !== null ) {
  13371. var indices = index.array;
  13372. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  13373. a = indices[ i ];
  13374. b = indices[ i + 1 ];
  13375. c = indices[ i + 2 ];
  13376. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13377. if ( intersection ) {
  13378. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  13379. intersects.push( intersection );
  13380. }
  13381. }
  13382. } else {
  13383. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  13384. a = i / 3;
  13385. b = a + 1;
  13386. c = a + 2;
  13387. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13388. if ( intersection ) {
  13389. intersection.index = a; // triangle number in positions buffer semantics
  13390. intersects.push( intersection );
  13391. }
  13392. }
  13393. }
  13394. } else if ( geometry instanceof THREE.Geometry ) {
  13395. var fvA, fvB, fvC;
  13396. var isFaceMaterial = material instanceof THREE.MultiMaterial;
  13397. var materials = isFaceMaterial === true ? material.materials : null;
  13398. var vertices = geometry.vertices;
  13399. var faces = geometry.faces;
  13400. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  13401. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  13402. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  13403. var face = faces[ f ];
  13404. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  13405. if ( faceMaterial === undefined ) continue;
  13406. fvA = vertices[ face.a ];
  13407. fvB = vertices[ face.b ];
  13408. fvC = vertices[ face.c ];
  13409. if ( faceMaterial.morphTargets === true ) {
  13410. var morphTargets = geometry.morphTargets;
  13411. var morphInfluences = this.morphTargetInfluences;
  13412. vA.set( 0, 0, 0 );
  13413. vB.set( 0, 0, 0 );
  13414. vC.set( 0, 0, 0 );
  13415. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  13416. var influence = morphInfluences[ t ];
  13417. if ( influence === 0 ) continue;
  13418. var targets = morphTargets[ t ].vertices;
  13419. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  13420. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  13421. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  13422. }
  13423. vA.add( fvA );
  13424. vB.add( fvB );
  13425. vC.add( fvC );
  13426. fvA = vA;
  13427. fvB = vB;
  13428. fvC = vC;
  13429. }
  13430. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  13431. if ( intersection ) {
  13432. if ( uvs ) {
  13433. var uvs_f = uvs[ f ];
  13434. uvA.copy( uvs_f[ 0 ] );
  13435. uvB.copy( uvs_f[ 1 ] );
  13436. uvC.copy( uvs_f[ 2 ] );
  13437. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  13438. }
  13439. intersection.face = face;
  13440. intersection.faceIndex = f;
  13441. intersects.push( intersection );
  13442. }
  13443. }
  13444. }
  13445. };
  13446. }() );
  13447. THREE.Mesh.prototype.clone = function () {
  13448. return new this.constructor( this.geometry, this.material ).copy( this );
  13449. };
  13450. // File:src/objects/Bone.js
  13451. /**
  13452. * @author mikael emtinger / http://gomo.se/
  13453. * @author alteredq / http://alteredqualia.com/
  13454. * @author ikerr / http://verold.com
  13455. */
  13456. THREE.Bone = function ( skin ) {
  13457. THREE.Object3D.call( this );
  13458. this.type = 'Bone';
  13459. this.skin = skin;
  13460. };
  13461. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  13462. THREE.Bone.prototype.constructor = THREE.Bone;
  13463. THREE.Bone.prototype.copy = function ( source ) {
  13464. THREE.Object3D.prototype.copy.call( this, source );
  13465. this.skin = source.skin;
  13466. return this;
  13467. };
  13468. // File:src/objects/Skeleton.js
  13469. /**
  13470. * @author mikael emtinger / http://gomo.se/
  13471. * @author alteredq / http://alteredqualia.com/
  13472. * @author michael guerrero / http://realitymeltdown.com
  13473. * @author ikerr / http://verold.com
  13474. */
  13475. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  13476. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  13477. this.identityMatrix = new THREE.Matrix4();
  13478. // copy the bone array
  13479. bones = bones || [];
  13480. this.bones = bones.slice( 0 );
  13481. // create a bone texture or an array of floats
  13482. if ( this.useVertexTexture ) {
  13483. // layout (1 matrix = 4 pixels)
  13484. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13485. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13486. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13487. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13488. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13489. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  13490. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  13491. size = Math.max( size, 4 );
  13492. this.boneTextureWidth = size;
  13493. this.boneTextureHeight = size;
  13494. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  13495. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  13496. } else {
  13497. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  13498. }
  13499. // use the supplied bone inverses or calculate the inverses
  13500. if ( boneInverses === undefined ) {
  13501. this.calculateInverses();
  13502. } else {
  13503. if ( this.bones.length === boneInverses.length ) {
  13504. this.boneInverses = boneInverses.slice( 0 );
  13505. } else {
  13506. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  13507. this.boneInverses = [];
  13508. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13509. this.boneInverses.push( new THREE.Matrix4() );
  13510. }
  13511. }
  13512. }
  13513. };
  13514. THREE.Skeleton.prototype.calculateInverses = function () {
  13515. this.boneInverses = [];
  13516. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13517. var inverse = new THREE.Matrix4();
  13518. if ( this.bones[ b ] ) {
  13519. inverse.getInverse( this.bones[ b ].matrixWorld );
  13520. }
  13521. this.boneInverses.push( inverse );
  13522. }
  13523. };
  13524. THREE.Skeleton.prototype.pose = function () {
  13525. var bone;
  13526. // recover the bind-time world matrices
  13527. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13528. bone = this.bones[ b ];
  13529. if ( bone ) {
  13530. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  13531. }
  13532. }
  13533. // compute the local matrices, positions, rotations and scales
  13534. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13535. bone = this.bones[ b ];
  13536. if ( bone ) {
  13537. if ( bone.parent ) {
  13538. bone.matrix.getInverse( bone.parent.matrixWorld );
  13539. bone.matrix.multiply( bone.matrixWorld );
  13540. } else {
  13541. bone.matrix.copy( bone.matrixWorld );
  13542. }
  13543. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  13544. }
  13545. }
  13546. };
  13547. THREE.Skeleton.prototype.update = ( function () {
  13548. var offsetMatrix = new THREE.Matrix4();
  13549. return function update() {
  13550. // flatten bone matrices to array
  13551. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13552. // compute the offset between the current and the original transform
  13553. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  13554. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  13555. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  13556. }
  13557. if ( this.useVertexTexture ) {
  13558. this.boneTexture.needsUpdate = true;
  13559. }
  13560. };
  13561. } )();
  13562. THREE.Skeleton.prototype.clone = function () {
  13563. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  13564. };
  13565. // File:src/objects/SkinnedMesh.js
  13566. /**
  13567. * @author mikael emtinger / http://gomo.se/
  13568. * @author alteredq / http://alteredqualia.com/
  13569. * @author ikerr / http://verold.com
  13570. */
  13571. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  13572. THREE.Mesh.call( this, geometry, material );
  13573. this.type = 'SkinnedMesh';
  13574. this.bindMode = "attached";
  13575. this.bindMatrix = new THREE.Matrix4();
  13576. this.bindMatrixInverse = new THREE.Matrix4();
  13577. // init bones
  13578. // TODO: remove bone creation as there is no reason (other than
  13579. // convenience) for THREE.SkinnedMesh to do this.
  13580. var bones = [];
  13581. if ( this.geometry && this.geometry.bones !== undefined ) {
  13582. var bone, gbone;
  13583. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13584. gbone = this.geometry.bones[ b ];
  13585. bone = new THREE.Bone( this );
  13586. bones.push( bone );
  13587. bone.name = gbone.name;
  13588. bone.position.fromArray( gbone.pos );
  13589. bone.quaternion.fromArray( gbone.rotq );
  13590. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  13591. }
  13592. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13593. gbone = this.geometry.bones[ b ];
  13594. if ( gbone.parent !== - 1 && gbone.parent !== null ) {
  13595. bones[ gbone.parent ].add( bones[ b ] );
  13596. } else {
  13597. this.add( bones[ b ] );
  13598. }
  13599. }
  13600. }
  13601. this.normalizeSkinWeights();
  13602. this.updateMatrixWorld( true );
  13603. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  13604. };
  13605. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  13606. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  13607. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  13608. this.skeleton = skeleton;
  13609. if ( bindMatrix === undefined ) {
  13610. this.updateMatrixWorld( true );
  13611. this.skeleton.calculateInverses();
  13612. bindMatrix = this.matrixWorld;
  13613. }
  13614. this.bindMatrix.copy( bindMatrix );
  13615. this.bindMatrixInverse.getInverse( bindMatrix );
  13616. };
  13617. THREE.SkinnedMesh.prototype.pose = function () {
  13618. this.skeleton.pose();
  13619. };
  13620. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  13621. if ( this.geometry instanceof THREE.Geometry ) {
  13622. for ( var i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  13623. var sw = this.geometry.skinWeights[ i ];
  13624. var scale = 1.0 / sw.lengthManhattan();
  13625. if ( scale !== Infinity ) {
  13626. sw.multiplyScalar( scale );
  13627. } else {
  13628. sw.set( 1, 0, 0, 0 ); // do something reasonable
  13629. }
  13630. }
  13631. } else if ( this.geometry instanceof THREE.BufferGeometry ) {
  13632. var vec = new THREE.Vector4();
  13633. var skinWeight = this.geometry.attributes.skinWeight;
  13634. for ( var i = 0; i < skinWeight.count; i ++ ) {
  13635. vec.x = skinWeight.getX( i );
  13636. vec.y = skinWeight.getY( i );
  13637. vec.z = skinWeight.getZ( i );
  13638. vec.w = skinWeight.getW( i );
  13639. var scale = 1.0 / vec.lengthManhattan();
  13640. if ( scale !== Infinity ) {
  13641. vec.multiplyScalar( scale );
  13642. } else {
  13643. vec.set( 1, 0, 0, 0 ); // do something reasonable
  13644. }
  13645. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  13646. }
  13647. }
  13648. };
  13649. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  13650. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  13651. if ( this.bindMode === "attached" ) {
  13652. this.bindMatrixInverse.getInverse( this.matrixWorld );
  13653. } else if ( this.bindMode === "detached" ) {
  13654. this.bindMatrixInverse.getInverse( this.bindMatrix );
  13655. } else {
  13656. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  13657. }
  13658. };
  13659. THREE.SkinnedMesh.prototype.clone = function() {
  13660. return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this );
  13661. };
  13662. // File:src/objects/LOD.js
  13663. /**
  13664. * @author mikael emtinger / http://gomo.se/
  13665. * @author alteredq / http://alteredqualia.com/
  13666. * @author mrdoob / http://mrdoob.com/
  13667. */
  13668. THREE.LOD = function () {
  13669. THREE.Object3D.call( this );
  13670. this.type = 'LOD';
  13671. Object.defineProperties( this, {
  13672. levels: {
  13673. enumerable: true,
  13674. value: []
  13675. },
  13676. objects: {
  13677. get: function () {
  13678. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  13679. return this.levels;
  13680. }
  13681. }
  13682. } );
  13683. };
  13684. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  13685. THREE.LOD.prototype.constructor = THREE.LOD;
  13686. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  13687. if ( distance === undefined ) distance = 0;
  13688. distance = Math.abs( distance );
  13689. var levels = this.levels;
  13690. for ( var l = 0; l < levels.length; l ++ ) {
  13691. if ( distance < levels[ l ].distance ) {
  13692. break;
  13693. }
  13694. }
  13695. levels.splice( l, 0, { distance: distance, object: object } );
  13696. this.add( object );
  13697. };
  13698. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  13699. var levels = this.levels;
  13700. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13701. if ( distance < levels[ i ].distance ) {
  13702. break;
  13703. }
  13704. }
  13705. return levels[ i - 1 ].object;
  13706. };
  13707. THREE.LOD.prototype.raycast = ( function () {
  13708. var matrixPosition = new THREE.Vector3();
  13709. return function raycast( raycaster, intersects ) {
  13710. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13711. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  13712. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  13713. };
  13714. }() );
  13715. THREE.LOD.prototype.update = function () {
  13716. var v1 = new THREE.Vector3();
  13717. var v2 = new THREE.Vector3();
  13718. return function update( camera ) {
  13719. var levels = this.levels;
  13720. if ( levels.length > 1 ) {
  13721. v1.setFromMatrixPosition( camera.matrixWorld );
  13722. v2.setFromMatrixPosition( this.matrixWorld );
  13723. var distance = v1.distanceTo( v2 );
  13724. levels[ 0 ].object.visible = true;
  13725. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13726. if ( distance >= levels[ i ].distance ) {
  13727. levels[ i - 1 ].object.visible = false;
  13728. levels[ i ].object.visible = true;
  13729. } else {
  13730. break;
  13731. }
  13732. }
  13733. for ( ; i < l; i ++ ) {
  13734. levels[ i ].object.visible = false;
  13735. }
  13736. }
  13737. };
  13738. }();
  13739. THREE.LOD.prototype.copy = function ( source ) {
  13740. THREE.Object3D.prototype.copy.call( this, source, false );
  13741. var levels = source.levels;
  13742. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13743. var level = levels[ i ];
  13744. this.addLevel( level.object.clone(), level.distance );
  13745. }
  13746. return this;
  13747. };
  13748. THREE.LOD.prototype.toJSON = function ( meta ) {
  13749. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  13750. data.object.levels = [];
  13751. var levels = this.levels;
  13752. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13753. var level = levels[ i ];
  13754. data.object.levels.push( {
  13755. object: level.object.uuid,
  13756. distance: level.distance
  13757. } );
  13758. }
  13759. return data;
  13760. };
  13761. // File:src/objects/Sprite.js
  13762. /**
  13763. * @author mikael emtinger / http://gomo.se/
  13764. * @author alteredq / http://alteredqualia.com/
  13765. */
  13766. THREE.Sprite = ( function () {
  13767. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  13768. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  13769. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  13770. var geometry = new THREE.BufferGeometry();
  13771. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  13772. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  13773. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  13774. return function Sprite( material ) {
  13775. THREE.Object3D.call( this );
  13776. this.type = 'Sprite';
  13777. this.geometry = geometry;
  13778. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  13779. };
  13780. } )();
  13781. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  13782. THREE.Sprite.prototype.constructor = THREE.Sprite;
  13783. THREE.Sprite.prototype.raycast = ( function () {
  13784. var matrixPosition = new THREE.Vector3();
  13785. return function raycast( raycaster, intersects ) {
  13786. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13787. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  13788. var guessSizeSq = this.scale.x * this.scale.y;
  13789. if ( distanceSq > guessSizeSq ) {
  13790. return;
  13791. }
  13792. intersects.push( {
  13793. distance: Math.sqrt( distanceSq ),
  13794. point: this.position,
  13795. face: null,
  13796. object: this
  13797. } );
  13798. };
  13799. }() );
  13800. THREE.Sprite.prototype.clone = function () {
  13801. return new this.constructor( this.material ).copy( this );
  13802. };
  13803. // Backwards compatibility
  13804. THREE.Particle = THREE.Sprite;
  13805. // File:src/objects/LensFlare.js
  13806. /**
  13807. * @author mikael emtinger / http://gomo.se/
  13808. * @author alteredq / http://alteredqualia.com/
  13809. */
  13810. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  13811. THREE.Object3D.call( this );
  13812. this.lensFlares = [];
  13813. this.positionScreen = new THREE.Vector3();
  13814. this.customUpdateCallback = undefined;
  13815. if ( texture !== undefined ) {
  13816. this.add( texture, size, distance, blending, color );
  13817. }
  13818. };
  13819. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  13820. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  13821. /*
  13822. * Add: adds another flare
  13823. */
  13824. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  13825. if ( size === undefined ) size = - 1;
  13826. if ( distance === undefined ) distance = 0;
  13827. if ( opacity === undefined ) opacity = 1;
  13828. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  13829. if ( blending === undefined ) blending = THREE.NormalBlending;
  13830. distance = Math.min( distance, Math.max( 0, distance ) );
  13831. this.lensFlares.push( {
  13832. texture: texture, // THREE.Texture
  13833. size: size, // size in pixels (-1 = use texture.width)
  13834. distance: distance, // distance (0-1) from light source (0=at light source)
  13835. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  13836. scale: 1, // scale
  13837. rotation: 0, // rotation
  13838. opacity: opacity, // opacity
  13839. color: color, // color
  13840. blending: blending // blending
  13841. } );
  13842. };
  13843. /*
  13844. * Update lens flares update positions on all flares based on the screen position
  13845. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  13846. */
  13847. THREE.LensFlare.prototype.updateLensFlares = function () {
  13848. var f, fl = this.lensFlares.length;
  13849. var flare;
  13850. var vecX = - this.positionScreen.x * 2;
  13851. var vecY = - this.positionScreen.y * 2;
  13852. for ( f = 0; f < fl; f ++ ) {
  13853. flare = this.lensFlares[ f ];
  13854. flare.x = this.positionScreen.x + vecX * flare.distance;
  13855. flare.y = this.positionScreen.y + vecY * flare.distance;
  13856. flare.wantedRotation = flare.x * Math.PI * 0.25;
  13857. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  13858. }
  13859. };
  13860. THREE.LensFlare.prototype.copy = function ( source ) {
  13861. THREE.Object3D.prototype.copy.call( this, source );
  13862. this.positionScreen.copy( source.positionScreen );
  13863. this.customUpdateCallback = source.customUpdateCallback;
  13864. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  13865. this.lensFlares.push( source.lensFlares[ i ] );
  13866. }
  13867. return this;
  13868. };
  13869. // File:src/scenes/Scene.js
  13870. /**
  13871. * @author mrdoob / http://mrdoob.com/
  13872. */
  13873. THREE.Scene = function () {
  13874. THREE.Object3D.call( this );
  13875. this.type = 'Scene';
  13876. this.fog = null;
  13877. this.overrideMaterial = null;
  13878. this.autoUpdate = true; // checked by the renderer
  13879. };
  13880. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  13881. THREE.Scene.prototype.constructor = THREE.Scene;
  13882. THREE.Scene.prototype.copy = function ( source, recursive ) {
  13883. THREE.Object3D.prototype.copy.call( this, source, recursive );
  13884. if ( source.fog !== null ) this.fog = source.fog.clone();
  13885. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  13886. this.autoUpdate = source.autoUpdate;
  13887. this.matrixAutoUpdate = source.matrixAutoUpdate;
  13888. return this;
  13889. };
  13890. // File:src/scenes/Fog.js
  13891. /**
  13892. * @author mrdoob / http://mrdoob.com/
  13893. * @author alteredq / http://alteredqualia.com/
  13894. */
  13895. THREE.Fog = function ( color, near, far ) {
  13896. this.name = '';
  13897. this.color = new THREE.Color( color );
  13898. this.near = ( near !== undefined ) ? near : 1;
  13899. this.far = ( far !== undefined ) ? far : 1000;
  13900. };
  13901. THREE.Fog.prototype.clone = function () {
  13902. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  13903. };
  13904. // File:src/scenes/FogExp2.js
  13905. /**
  13906. * @author mrdoob / http://mrdoob.com/
  13907. * @author alteredq / http://alteredqualia.com/
  13908. */
  13909. THREE.FogExp2 = function ( color, density ) {
  13910. this.name = '';
  13911. this.color = new THREE.Color( color );
  13912. this.density = ( density !== undefined ) ? density : 0.00025;
  13913. };
  13914. THREE.FogExp2.prototype.clone = function () {
  13915. return new THREE.FogExp2( this.color.getHex(), this.density );
  13916. };
  13917. // File:src/renderers/shaders/ShaderChunk.js
  13918. THREE.ShaderChunk = {};
  13919. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  13920. THREE.ShaderChunk[ 'alphamap_fragment' ] = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  13921. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  13922. THREE.ShaderChunk[ 'alphamap_pars_fragment' ] = "#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif\n";
  13923. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  13924. THREE.ShaderChunk[ 'alphatest_fragment' ] = "#ifdef ALPHATEST\n if ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  13925. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  13926. THREE.ShaderChunk[ 'aomap_fragment' ] = "#ifdef USE_AOMAP\n float ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n #if defined( USE_ENVMAP ) && defined( STANDARD )\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n #endif\n#endif\n";
  13927. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  13928. THREE.ShaderChunk[ 'aomap_pars_fragment' ] = "#ifdef USE_AOMAP\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n#endif";
  13929. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  13930. THREE.ShaderChunk[ 'begin_vertex' ] = "\nvec3 transformed = vec3( position );\n";
  13931. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  13932. THREE.ShaderChunk[ 'beginnormal_vertex' ] = "\nvec3 objectNormal = vec3( normal );\n";
  13933. // File:src/renderers/shaders/ShaderChunk/bsdfs.glsl
  13934. THREE.ShaderChunk[ 'bsdfs' ] = "bool testLightInRange( const in float lightDistance, const in float cutoffDistance ) {\n return any( bvec2( cutoffDistance == 0.0, lightDistance < cutoffDistance ) );\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n if( decayExponent > 0.0 ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n float maxDistanceCutoffFactor = pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n return distanceFalloff * maxDistanceCutoffFactor;\n#else\n return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n#endif\n }\n return 1.0;\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n return RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n return ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n float a2 = pow2( alpha );\n float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n return 1.0 / ( gl * gv );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n float a2 = pow2( alpha );\n float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n return 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 float alpha = pow2( roughness );\n vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n float dotNH = saturate( dot( geometry.normal, halfDir ) );\n float dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n vec3 F = F_Schlick( specularColor, dotLH );\n float G = G_GGX_Smith( alpha, dotNL, dotNV );\n float D = D_GGX( alpha, dotNH );\n return F * ( G * D );\n}\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n return specularColor * AB.x + AB.y;\n}\nfloat G_BlinnPhong_Implicit( ) {\n return 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n return 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 vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n float dotNH = saturate( dot( geometry.normal, halfDir ) );\n float dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n vec3 F = F_Schlick( specularColor, dotLH );\n float G = G_BlinnPhong_Implicit( );\n float D = D_BlinnPhong( shininess, dotNH );\n return F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n return sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n";
  13935. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  13936. THREE.ShaderChunk[ 'bumpmap_pars_fragment' ] = "#ifdef USE_BUMPMAP\n uniform sampler2D bumpMap;\n uniform float bumpScale;\n vec2 dHdxy_fwd() {\n vec2 dSTdx = dFdx( vUv );\n vec2 dSTdy = dFdy( vUv );\n float Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n float dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n float dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n return vec2( dBx, dBy );\n }\n vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n vec3 vSigmaX = dFdx( surf_pos );\n vec3 vSigmaY = dFdy( surf_pos );\n vec3 vN = surf_norm;\n vec3 R1 = cross( vSigmaY, vN );\n vec3 R2 = cross( vN, vSigmaX );\n float fDet = dot( vSigmaX, R1 );\n vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n return normalize( abs( fDet ) * surf_norm - vGrad );\n }\n#endif\n";
  13937. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  13938. THREE.ShaderChunk[ 'color_fragment' ] = "#ifdef USE_COLOR\n diffuseColor.rgb *= vColor;\n#endif";
  13939. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  13940. THREE.ShaderChunk[ 'color_pars_fragment' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif\n";
  13941. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  13942. THREE.ShaderChunk[ 'color_pars_vertex' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif";
  13943. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  13944. THREE.ShaderChunk[ 'color_vertex' ] = "#ifdef USE_COLOR\n vColor.xyz = color.xyz;\n#endif";
  13945. // File:src/renderers/shaders/ShaderChunk/common.glsl
  13946. THREE.ShaderChunk[ 'common' ] = "#define PI 3.14159\n#define PI2 6.28318\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 ) ); }\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n bool visible;\n};\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\nstruct GeometricContext {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n float distance = dot( planeNormal, point - pointOnPlane );\n return - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\n";
  13947. // File:src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl
  13948. THREE.ShaderChunk[ 'cube_uv_reflection_fragment' ] = "#ifdef ENVMAP_TYPE_CUBE_UV\nconst float cubeUV_textureSize = 1024.0;\nint getFaceFromDirection(vec3 direction) {\n vec3 absDirection = abs(direction);\n int face = -1;\n if( absDirection.x > absDirection.z ) {\n if(absDirection.x > absDirection.y )\n face = direction.x > 0.0 ? 0 : 3;\n else\n face = direction.y > 0.0 ? 1 : 4;\n }\n else {\n if(absDirection.z > absDirection.y )\n face = direction.z > 0.0 ? 2 : 5;\n else\n face = direction.y > 0.0 ? 1 : 4;\n }\n return face;\n}\nconst float cubeUV_maxLods1 = log2(cubeUV_textureSize*0.25) - 1.0;\nconst float cubeUV_rangeClamp = exp2((6.0 - 1.0) * 2.0);\nvec2 MipLevelInfo( vec3 vec, float roughnessLevel, float roughness ) {\n float scale = exp2(cubeUV_maxLods1 - roughnessLevel);\n float dxRoughness = dFdx(roughness);\n float dyRoughness = dFdy(roughness);\n vec3 dx = dFdx( vec * scale * dxRoughness );\n vec3 dy = dFdy( vec * scale * dyRoughness );\n float d = max( dot( dx, dx ), dot( dy, dy ) );\n d = clamp(d, 1.0, cubeUV_rangeClamp);\n float mipLevel = 0.5 * log2(d);\n return vec2(floor(mipLevel), fract(mipLevel));\n}\nconst float cubeUV_maxLods2 = log2(cubeUV_textureSize*0.25) - 2.0;\nconst float cubeUV_rcpTextureSize = 1.0 / cubeUV_textureSize;\nvec2 getCubeUV(vec3 direction, float roughnessLevel, float mipLevel) {\n mipLevel = roughnessLevel > cubeUV_maxLods2 - 3.0 ? 0.0 : mipLevel;\n float a = 16.0 * cubeUV_rcpTextureSize;\n vec2 exp2_packed = exp2( vec2( roughnessLevel, mipLevel ) );\n vec2 rcp_exp2_packed = vec2( 1.0 ) / exp2_packed;\n float powScale = exp2_packed.x * exp2_packed.y;\n float scale = rcp_exp2_packed.x * rcp_exp2_packed.y * 0.25;\n float mipOffset = 0.75*(1.0 - rcp_exp2_packed.y) * rcp_exp2_packed.x;\n bool bRes = mipLevel == 0.0;\n scale = bRes && (scale < a) ? a : scale;\n vec3 r;\n vec2 offset;\n int face = getFaceFromDirection(direction);\n float rcpPowScale = 1.0 / powScale;\n if( face == 0) {\n r = vec3(direction.x, -direction.z, direction.y);\n offset = vec2(0.0+mipOffset,0.75 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n }\n else if( face == 1) {\n r = vec3(direction.y, direction.x, direction.z);\n offset = vec2(scale+mipOffset, 0.75 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n }\n else if( face == 2) {\n r = vec3(direction.z, direction.x, direction.y);\n offset = vec2(2.0*scale+mipOffset, 0.75 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n }\n else if( face == 3) {\n r = vec3(direction.x, direction.z, direction.y);\n offset = vec2(0.0+mipOffset,0.5 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n }\n else if( face == 4) {\n r = vec3(direction.y, direction.x, -direction.z);\n offset = vec2(scale+mipOffset, 0.5 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n }\n else {\n r = vec3(direction.z, -direction.x, direction.y);\n offset = vec2(2.0*scale+mipOffset, 0.5 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n }\n r = normalize(r);\n float texelOffset = 0.5 * cubeUV_rcpTextureSize;\n vec2 s = ( r.yz / abs( r.x ) + vec2( 1.0 ) ) * 0.5;\n vec2 base = offset + vec2( texelOffset );\n return base + s * ( scale - 2.0 * texelOffset );\n}\nconst float cubeUV_maxLods3 = log2(cubeUV_textureSize*0.25) - 3.0;\nvec4 textureCubeUV(vec3 reflectedDirection, float roughness ) {\n float roughnessVal = roughness* cubeUV_maxLods3;\n float r1 = floor(roughnessVal);\n float r2 = r1 + 1.0;\n float t = fract(roughnessVal);\n vec2 mipInfo = MipLevelInfo(reflectedDirection, r1, roughness);\n float s = mipInfo.y;\n float level0 = mipInfo.x;\n float level1 = level0 + 1.0;\n level1 = level1 > 5.0 ? 5.0 : level1;\n level0 += min( floor( s + 0.5 ), 5.0 );\n vec2 uv_10 = getCubeUV(reflectedDirection, r1, level0);\n vec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));\n vec2 uv_20 = getCubeUV(reflectedDirection, r2, level0);\n vec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));\n vec4 result = mix(color10, color20, t);\n return vec4(result.rgb, 1.0);\n}\n#endif\n";
  13949. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  13950. THREE.ShaderChunk[ 'defaultnormal_vertex' ] = "#ifdef FLIP_SIDED\n objectNormal = -objectNormal;\n#endif\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  13951. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  13952. THREE.ShaderChunk[ 'displacementmap_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  13953. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  13954. THREE.ShaderChunk[ 'displacementmap_pars_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n#endif\n";
  13955. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  13956. THREE.ShaderChunk[ 'emissivemap_fragment' ] = "#ifdef USE_EMISSIVEMAP\n vec4 emissiveColor = texture2D( emissiveMap, vUv );\n emissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n totalEmissiveRadiance *= emissiveColor.rgb;\n#endif\n";
  13957. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  13958. THREE.ShaderChunk[ 'emissivemap_pars_fragment' ] = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif\n";
  13959. // File:src/renderers/shaders/ShaderChunk/encodings_pars_fragment.glsl
  13960. THREE.ShaderChunk[ 'encodings_pars_fragment' ] = "\nvec4 LinearToLinear( in vec4 value ) {\n return value;\n}\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );\n}\nvec4 sRGBToLinear( in vec4 value ) {\n return 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 return 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 return vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n}\nvec4 LinearToRGBE( in vec4 value ) {\n float maxComponent = max( max( value.r, value.g ), value.b );\n float fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n return vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n}\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\n return vec4( value.xyz * value.w * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n float maxRGB = max( value.x, max( value.g, value.b ) );\n float M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n M = ceil( M * 255.0 ) / 255.0;\n return vec4( value.rgb / ( M * maxRange ), M );\n}\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\n return vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n}\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\n float maxRGB = max( value.x, max( value.g, value.b ) );\n float D = max( maxRange / maxRGB, 1.0 );\n D = min( floor( D ) / 255.0, 1.0 );\n return 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 vec3 Xp_Y_XYZp = value.rgb * cLogLuvM;\n Xp_Y_XYZp = max(Xp_Y_XYZp, vec3(1e-6, 1e-6, 1e-6));\n vec4 vResult;\n vResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\n float Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\n vResult.w = fract(Le);\n vResult.z = (Le - (floor(vResult.w*255.0))/255.0)/255.0;\n return 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 float Le = value.z * 255.0 + value.w;\n vec3 Xp_Y_XYZp;\n Xp_Y_XYZp.y = exp2((Le - 127.0) / 2.0);\n Xp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\n Xp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\n vec3 vRGB = Xp_Y_XYZp.rgb * cLogLuvInverseM;\n return vec4( max(vRGB, 0.0), 1.0 );\n}\n";
  13961. // File:src/renderers/shaders/ShaderChunk/encodings_fragment.glsl
  13962. THREE.ShaderChunk[ 'encodings_fragment' ] = " gl_FragColor = linearToOutputTexel( gl_FragColor );\n";
  13963. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  13964. THREE.ShaderChunk[ 'envmap_fragment' ] = "#ifdef USE_ENVMAP\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n #ifdef ENVMAP_MODE_REFLECTION\n vec3 reflectVec = reflect( cameraToVertex, worldNormal );\n #else\n vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n #endif\n #else\n vec3 reflectVec = vReflect;\n #endif\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n #ifdef ENVMAP_TYPE_CUBE\n vec4 envColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n #elif defined( ENVMAP_TYPE_EQUIREC )\n vec2 sampleUV;\n sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );\n sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n vec4 envColor = texture2D( envMap, sampleUV );\n #elif defined( ENVMAP_TYPE_SPHERE )\n vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));\n vec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\n #endif\n envColor = envMapTexelToLinear( envColor );\n #ifdef ENVMAP_BLENDING_MULTIPLY\n outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n #elif defined( ENVMAP_BLENDING_MIX )\n outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n #elif defined( ENVMAP_BLENDING_ADD )\n outgoingLight += envColor.xyz * specularStrength * reflectivity;\n #endif\n#endif\n";
  13965. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  13966. THREE.ShaderChunk[ 'envmap_pars_fragment' ] = "#if defined( USE_ENVMAP ) || defined( STANDARD )\n uniform float reflectivity;\n uniform float envMapIntenstiy;\n#endif\n#ifdef USE_ENVMAP\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube envMap;\n #else\n uniform sampler2D envMap;\n #endif\n uniform float flipEnvMap;\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( STANDARD )\n uniform float refractionRatio;\n #else\n varying vec3 vReflect;\n #endif\n#endif\n";
  13967. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  13968. THREE.ShaderChunk[ 'envmap_pars_vertex' ] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG ) && ! defined( STANDARD )\n varying vec3 vReflect;\n uniform float refractionRatio;\n#endif\n";
  13969. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  13970. THREE.ShaderChunk[ 'envmap_vertex' ] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG ) && ! defined( STANDARD )\n vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n #ifdef ENVMAP_MODE_REFLECTION\n vReflect = reflect( cameraToVertex, worldNormal );\n #else\n vReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n #endif\n#endif\n";
  13971. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  13972. THREE.ShaderChunk[ 'fog_fragment' ] = "#ifdef USE_FOG\n #ifdef USE_LOGDEPTHBUF_EXT\n float depth = gl_FragDepthEXT / gl_FragCoord.w;\n #else\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n #endif\n #ifdef FOG_EXP2\n float fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * depth * depth * LOG2 ) );\n #else\n float fogFactor = smoothstep( fogNear, fogFar, depth );\n #endif\n gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif\n";
  13973. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  13974. THREE.ShaderChunk[ 'fog_pars_fragment' ] = "#ifdef USE_FOG\n uniform vec3 fogColor;\n #ifdef FOG_EXP2\n uniform float fogDensity;\n #else\n uniform float fogNear;\n uniform float fogFar;\n #endif\n#endif";
  13975. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  13976. THREE.ShaderChunk[ 'lightmap_fragment' ] = "#ifdef USE_LIGHTMAP\n reflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  13977. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  13978. THREE.ShaderChunk[ 'lightmap_pars_fragment' ] = "#ifdef USE_LIGHTMAP\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n#endif";
  13979. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  13980. THREE.ShaderChunk[ '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 vLightBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\n#if NUM_POINT_LIGHTS > 0\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n directLight = getPointDirectLightIrradiance( pointLights[ i ], geometry );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n directLight = getSpotDirectLightIrradiance( spotLights[ i ], geometry );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_DIR_LIGHTS > 0\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directLight = getDirectionalDirectLightIrradiance( directionalLights[ i ], geometry );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_HEMI_LIGHTS > 0\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n vLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n #ifdef DOUBLE_SIDED\n vLightBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n #endif\n }\n#endif\n";
  13981. // File:src/renderers/shaders/ShaderChunk/lights_pars.glsl
  13982. THREE.ShaderChunk[ 'lights_pars' ] = "uniform vec3 ambientLightColor;\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n vec3 irradiance = ambientLightColor;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n return irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n struct DirectionalLight {\n vec3 direction;\n vec3 color;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n IncidentLight getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry ) {\n IncidentLight directLight;\n directLight.color = directionalLight.color;\n directLight.direction = directionalLight.direction;\n directLight.visible = true;\n return directLight;\n }\n#endif\n#if NUM_POINT_LIGHTS > 0\n struct PointLight {\n vec3 position;\n vec3 color;\n float distance;\n float decay;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n IncidentLight getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry ) {\n IncidentLight directLight;\n vec3 lVector = pointLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n float lightDistance = length( lVector );\n if ( testLightInRange( lightDistance, pointLight.distance ) ) {\n directLight.color = pointLight.color;\n directLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n directLight.visible = true;\n } else {\n directLight.color = vec3( 0.0 );\n directLight.visible = false;\n }\n return directLight;\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n struct SpotLight {\n vec3 position;\n vec3 direction;\n vec3 color;\n float distance;\n float decay;\n float coneCos;\n float penumbraCos;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n IncidentLight getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry ) {\n IncidentLight directLight;\n vec3 lVector = spotLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n float lightDistance = length( lVector );\n float angleCos = dot( directLight.direction, spotLight.direction );\n if ( all( bvec2( angleCos > spotLight.coneCos, testLightInRange( lightDistance, spotLight.distance ) ) ) ) {\n float spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n directLight.color = spotLight.color;\n directLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n directLight.visible = true;\n } else {\n directLight.color = vec3( 0.0 );\n directLight.visible = false;\n }\n return directLight;\n }\n#endif\n#if NUM_HEMI_LIGHTS > 0\n struct HemisphereLight {\n vec3 direction;\n vec3 skyColor;\n vec3 groundColor;\n };\n uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n float dotNL = dot( geometry.normal, hemiLight.direction );\n float hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n return irradiance;\n }\n#endif\n#if defined( USE_ENVMAP ) && defined( STANDARD )\n vec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n #ifdef ENVMAP_TYPE_CUBE\n vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n #else\n vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n #endif\n #elif defined( ENVMAP_TYPE_CUBE_UV )\n vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n vec4 envMapColor = textureCubeUV( queryVec, 1.0 );\n #else\n vec4 envMapColor = vec4( 0.0 );\n #endif\n envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n return PI * envMapColor.rgb * envMapIntensity;\n }\n float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {\n float maxMIPLevelScalar = float( maxMIPLevel );\n float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\n return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n }\n vec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {\n #ifdef ENVMAP_MODE_REFLECTION\n vec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\n #else\n vec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\n #endif\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n reflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n float specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );\n #ifdef ENVMAP_TYPE_CUBE\n vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n #else\n vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n #endif\n #elif defined( ENVMAP_TYPE_CUBE_UV )\n vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n vec4 envMapColor = textureCubeUV(queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent));\n #elif defined( ENVMAP_TYPE_EQUIREC )\n vec2 sampleUV;\n sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );\n sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n #else\n vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n #endif\n #elif defined( ENVMAP_TYPE_SPHERE )\n vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n #else\n vec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n #endif\n #endif\n envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n return envMapColor.rgb * envMapIntensity;\n }\n#endif\n";
  13983. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  13984. THREE.ShaderChunk[ 'lights_phong_fragment' ] = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  13985. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  13986. THREE.ShaderChunk[ 'lights_phong_pars_fragment' ] = "#ifdef USE_ENVMAP\n varying vec3 vWorldPosition;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n vec3 diffuseColor;\n vec3 specularColor;\n float specularShininess;\n float specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.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 reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct RE_Direct_BlinnPhong\n#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material ) (0)\n";
  13987. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  13988. THREE.ShaderChunk[ 'lights_phong_pars_vertex' ] = "#ifdef USE_ENVMAP\n varying vec3 vWorldPosition;\n#endif\n";
  13989. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  13990. THREE.ShaderChunk[ 'lights_phong_vertex' ] = "#ifdef USE_ENVMAP\n vWorldPosition = worldPosition.xyz;\n#endif\n";
  13991. // File:src/renderers/shaders/ShaderChunk/lights_standard_fragment.glsl
  13992. THREE.ShaderChunk[ 'lights_standard_fragment' ] = "StandardMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );\nmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n";
  13993. // File:src/renderers/shaders/ShaderChunk/lights_standard_pars_fragment.glsl
  13994. THREE.ShaderChunk[ 'lights_standard_pars_fragment' ] = "struct StandardMaterial {\n vec3 diffuseColor;\n float specularRoughness;\n vec3 specularColor;\n};\nvoid RE_Direct_Standard( const in IncidentLight directLight, const in GeometricContext geometry, const in StandardMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n}\nvoid RE_IndirectDiffuse_Standard( const in vec3 irradiance, const in GeometricContext geometry, const in StandardMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Standard( const in vec3 radiance, const in GeometricContext geometry, const in StandardMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectSpecular += radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n}\n#define RE_Direct RE_Direct_Standard\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Standard\n#define RE_IndirectSpecular RE_IndirectSpecular_Standard\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}\n";
  13995. // File:src/renderers/shaders/ShaderChunk/lights_template.glsl
  13996. THREE.ShaderChunk[ '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 PointLight pointLight;\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n pointLight = pointLights[ i ];\n directLight = getPointDirectLightIrradiance( pointLight, geometry );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n SpotLight spotLight;\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n directLight = getSpotDirectLightIrradiance( spotLight, geometry );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n directLight = getDirectionalDirectLightIrradiance( directionalLight, geometry );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if defined( RE_IndirectDiffuse )\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n #ifdef USE_LIGHTMAP\n vec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n lightMapIrradiance *= PI;\n #endif\n irradiance += lightMapIrradiance;\n #endif\n #if ( NUM_HEMI_LIGHTS > 0 )\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n }\n #endif\n #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n irradiance += getLightProbeIndirectIrradiance( geometry, 8 );\n #endif\n RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n vec3 radiance = getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), 8 );\n RE_IndirectSpecular( radiance, geometry, material, reflectedLight );\n#endif\n";
  13997. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  13998. THREE.ShaderChunk[ 'logdepthbuf_fragment' ] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  13999. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  14000. THREE.ShaderChunk[ 'logdepthbuf_pars_fragment' ] = "#ifdef USE_LOGDEPTHBUF\n uniform float logDepthBufFC;\n #ifdef USE_LOGDEPTHBUF_EXT\n varying float vFragDepth;\n #endif\n#endif\n";
  14001. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  14002. THREE.ShaderChunk[ 'logdepthbuf_pars_vertex' ] = "#ifdef USE_LOGDEPTHBUF\n #ifdef USE_LOGDEPTHBUF_EXT\n varying float vFragDepth;\n #endif\n uniform float logDepthBufFC;\n#endif";
  14003. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  14004. THREE.ShaderChunk[ 'logdepthbuf_vertex' ] = "#ifdef USE_LOGDEPTHBUF\n gl_Position.z = log2(max( EPSILON, gl_Position.w + 1.0 )) * logDepthBufFC;\n #ifdef USE_LOGDEPTHBUF_EXT\n vFragDepth = 1.0 + gl_Position.w;\n #else\n gl_Position.z = (gl_Position.z - 1.0) * gl_Position.w;\n #endif\n#endif\n";
  14005. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  14006. THREE.ShaderChunk[ 'map_fragment' ] = "#ifdef USE_MAP\n vec4 texelColor = texture2D( map, vUv );\n texelColor = mapTexelToLinear( texelColor );\n diffuseColor *= texelColor;\n#endif\n";
  14007. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  14008. THREE.ShaderChunk[ 'map_pars_fragment' ] = "#ifdef USE_MAP\n uniform sampler2D map;\n#endif\n";
  14009. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  14010. THREE.ShaderChunk[ 'map_particle_fragment' ] = "#ifdef USE_MAP\n vec4 mapTexel = texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) * offsetRepeat.zw + offsetRepeat.xy );\n diffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n";
  14011. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  14012. THREE.ShaderChunk[ 'map_particle_pars_fragment' ] = "#ifdef USE_MAP\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n#endif\n";
  14013. // File:src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl
  14014. THREE.ShaderChunk[ 'metalnessmap_fragment' ] = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, vUv );\n metalnessFactor *= texelMetalness.r;\n#endif\n";
  14015. // File:src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl
  14016. THREE.ShaderChunk[ 'metalnessmap_pars_fragment' ] = "#ifdef USE_METALNESSMAP\n uniform sampler2D metalnessMap;\n#endif";
  14017. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  14018. THREE.ShaderChunk[ 'morphnormal_vertex' ] = "#ifdef USE_MORPHNORMALS\n objectNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n objectNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n objectNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n objectNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n#endif\n";
  14019. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  14020. THREE.ShaderChunk[ 'morphtarget_pars_vertex' ] = "#ifdef USE_MORPHTARGETS\n #ifndef USE_MORPHNORMALS\n uniform float morphTargetInfluences[ 8 ];\n #else\n uniform float morphTargetInfluences[ 4 ];\n #endif\n#endif";
  14021. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  14022. THREE.ShaderChunk[ 'morphtarget_vertex' ] = "#ifdef USE_MORPHTARGETS\n transformed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n transformed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n transformed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n transformed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n #ifndef USE_MORPHNORMALS\n transformed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n transformed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n transformed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n transformed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n #endif\n#endif\n";
  14023. // File:src/renderers/shaders/ShaderChunk/normal_fragment.glsl
  14024. THREE.ShaderChunk[ 'normal_fragment' ] = "#ifdef FLAT_SHADED\n vec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n vec3 normal = normalize( cross( fdx, fdy ) );\n#else\n vec3 normal = normalize( vNormal );\n #ifdef DOUBLE_SIDED\n normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n #endif\n#endif\n#ifdef USE_NORMALMAP\n normal = perturbNormal2Arb( -vViewPosition, normal );\n#elif defined( USE_BUMPMAP )\n normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif\n";
  14025. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  14026. THREE.ShaderChunk[ 'normalmap_pars_fragment' ] = "#ifdef USE_NORMALMAP\n uniform sampler2D normalMap;\n uniform vec2 normalScale;\n vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n vec3 q0 = dFdx( eye_pos.xyz );\n vec3 q1 = dFdy( eye_pos.xyz );\n vec2 st0 = dFdx( vUv.st );\n vec2 st1 = dFdy( vUv.st );\n vec3 S = normalize( q0 * st1.t - q1 * st0.t );\n vec3 T = normalize( -q0 * st1.s + q1 * st0.s );\n vec3 N = normalize( surf_norm );\n vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n mapN.xy = normalScale * mapN.xy;\n mat3 tsn = mat3( S, T, N );\n return normalize( tsn * mapN );\n }\n#endif\n";
  14027. // File:src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl
  14028. THREE.ShaderChunk[ 'premultiplied_alpha_fragment' ] = "#ifdef PREMULTIPLIED_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n";
  14029. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  14030. THREE.ShaderChunk[ 'project_vertex' ] = "#ifdef USE_SKINNING\n vec4 mvPosition = modelViewMatrix * skinned;\n#else\n vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n#endif\ngl_Position = projectionMatrix * mvPosition;\n";
  14031. // File:src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl
  14032. THREE.ShaderChunk[ 'roughnessmap_fragment' ] = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, vUv );\n roughnessFactor *= texelRoughness.r;\n#endif\n";
  14033. // File:src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl
  14034. THREE.ShaderChunk[ 'roughnessmap_pars_fragment' ] = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif";
  14035. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  14036. THREE.ShaderChunk[ 'shadowmap_pars_fragment' ] = "#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n #endif\n #if NUM_SPOT_LIGHTS > 0\n uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\n varying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n #endif\n #if NUM_POINT_LIGHTS > 0\n uniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n #endif\n float unpackDepth( const in vec4 rgba_depth ) {\n const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n return dot( rgba_depth, bit_shift );\n }\n float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n return step( compare, unpackDepth( texture2D( depths, uv ) ) );\n }\n float texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\n const vec2 offset = vec2( 0.0, 1.0 );\n vec2 texelSize = vec2( 1.0 ) / size;\n vec2 centroidUV = floor( uv * size + 0.5 ) / size;\n float lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\n float lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\n float rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\n float rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\n vec2 f = fract( uv * size + 0.5 );\n float a = mix( lb, lt, f.y );\n float b = mix( rb, rt, f.y );\n float c = mix( a, b, f.x );\n return c;\n }\n float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n shadowCoord.xyz /= shadowCoord.w;\n shadowCoord.z += shadowBias;\n bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n bool inFrustum = all( inFrustumVec );\n bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n bool frustumTest = all( frustumTestVec );\n if ( frustumTest ) {\n #if defined( SHADOWMAP_TYPE_PCF )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx0 = - texelSize.x * shadowRadius;\n float dy0 = - texelSize.y * shadowRadius;\n float dx1 = + texelSize.x * shadowRadius;\n float dy1 = + texelSize.y * shadowRadius;\n return (\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n ) * ( 1.0 / 9.0 );\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx0 = - texelSize.x * shadowRadius;\n float dy0 = - texelSize.y * shadowRadius;\n float dx1 = + texelSize.x * shadowRadius;\n float dy1 = + texelSize.y * shadowRadius;\n return (\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n ) * ( 1.0 / 9.0 );\n #else\n return texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n #endif\n }\n return 1.0;\n }\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n vec3 absV = abs( v );\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n vec2 planar = v.xy;\n float almostATexel = 1.5 * texelSizeY;\n float almostOne = 1.0 - almostATexel;\n if ( absV.z >= almostOne ) {\n if ( v.z > 0.0 )\n planar.x = 4.0 - v.x;\n } else if ( absV.x >= almostOne ) {\n float signX = sign( v.x );\n planar.x = v.z * signX + 2.0 * signX;\n } else if ( absV.y >= almostOne ) {\n float signY = sign( v.y );\n planar.x = v.x + 2.0 * signY + 2.0;\n planar.y = v.z * signY - 2.0;\n }\n return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n }\n float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n vec3 lightToPosition = shadowCoord.xyz;\n vec3 bd3D = normalize( lightToPosition );\n float dp = ( length( lightToPosition ) - shadowBias ) / 1000.0;\n #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n return (\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n ) * ( 1.0 / 9.0 );\n #else\n return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n #endif\n }\n#endif\n";
  14037. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  14038. THREE.ShaderChunk[ 'shadowmap_pars_vertex' ] = "#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHTS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n #endif\n #if NUM_SPOT_LIGHTS > 0\n uniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHTS ];\n varying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n #endif\n #if NUM_POINT_LIGHTS > 0\n uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHTS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n #endif\n#endif\n";
  14039. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  14040. THREE.ShaderChunk[ 'shadowmap_vertex' ] = "#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\n }\n #endif\n #if NUM_SPOT_LIGHTS > 0\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n vSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\n }\n #endif\n #if NUM_POINT_LIGHTS > 0\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\n }\n #endif\n#endif\n";
  14041. // File:src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl
  14042. THREE.ShaderChunk[ 'shadowmask_pars_fragment' ] = "float getShadowMask() {\n float shadow = 1.0;\n #ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLight;\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n shadow *= bool( directionalLight.shadow ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n }\n #endif\n #if NUM_SPOT_LIGHTS > 0\n SpotLight spotLight;\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n shadow *= bool( spotLight.shadow ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n }\n #endif\n #if NUM_POINT_LIGHTS > 0\n PointLight pointLight;\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n pointLight = pointLights[ i ];\n shadow *= bool( pointLight.shadow ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 1.0;\n }\n #endif\n #endif\n return shadow;\n}\n";
  14043. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  14044. THREE.ShaderChunk[ 'skinbase_vertex' ] = "#ifdef USE_SKINNING\n mat4 boneMatX = getBoneMatrix( skinIndex.x );\n mat4 boneMatY = getBoneMatrix( skinIndex.y );\n mat4 boneMatZ = getBoneMatrix( skinIndex.z );\n mat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";
  14045. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  14046. THREE.ShaderChunk[ 'skinning_pars_vertex' ] = "#ifdef USE_SKINNING\n uniform mat4 bindMatrix;\n uniform mat4 bindMatrixInverse;\n #ifdef BONE_TEXTURE\n uniform sampler2D boneTexture;\n uniform int boneTextureWidth;\n uniform int boneTextureHeight;\n mat4 getBoneMatrix( const in float i ) {\n float j = i * 4.0;\n float x = mod( j, float( boneTextureWidth ) );\n float y = floor( j / float( boneTextureWidth ) );\n float dx = 1.0 / float( boneTextureWidth );\n float dy = 1.0 / float( boneTextureHeight );\n y = dy * ( y + 0.5 );\n vec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n vec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n vec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n vec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n mat4 bone = mat4( v1, v2, v3, v4 );\n return bone;\n }\n #else\n uniform mat4 boneGlobalMatrices[ MAX_BONES ];\n mat4 getBoneMatrix( const in float i ) {\n mat4 bone = boneGlobalMatrices[ int(i) ];\n return bone;\n }\n #endif\n#endif\n";
  14047. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  14048. THREE.ShaderChunk[ 'skinning_vertex' ] = "#ifdef USE_SKINNING\n vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n vec4 skinned = vec4( 0.0 );\n skinned += boneMatX * skinVertex * skinWeight.x;\n skinned += boneMatY * skinVertex * skinWeight.y;\n skinned += boneMatZ * skinVertex * skinWeight.z;\n skinned += boneMatW * skinVertex * skinWeight.w;\n skinned = bindMatrixInverse * skinned;\n#endif\n";
  14049. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  14050. THREE.ShaderChunk[ 'skinnormal_vertex' ] = "#ifdef USE_SKINNING\n mat4 skinMatrix = mat4( 0.0 );\n skinMatrix += skinWeight.x * boneMatX;\n skinMatrix += skinWeight.y * boneMatY;\n skinMatrix += skinWeight.z * boneMatZ;\n skinMatrix += skinWeight.w * boneMatW;\n skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n#endif\n";
  14051. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  14052. THREE.ShaderChunk[ 'specularmap_fragment' ] = "float specularStrength;\n#ifdef USE_SPECULARMAP\n vec4 texelSpecular = texture2D( specularMap, vUv );\n specularStrength = texelSpecular.r;\n#else\n specularStrength = 1.0;\n#endif";
  14053. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  14054. THREE.ShaderChunk[ 'specularmap_pars_fragment' ] = "#ifdef USE_SPECULARMAP\n uniform sampler2D specularMap;\n#endif";
  14055. // File:src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl
  14056. THREE.ShaderChunk[ 'tonemapping_fragment' ] = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif\n";
  14057. // File:src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl
  14058. THREE.ShaderChunk[ 'tonemapping_pars_fragment' ] = "#define saturate(a) clamp( a, 0.0, 1.0 )\nuniform float toneMappingExposure;\nuniform float toneMappingWhitePoint;\nvec3 LinearToneMapping( vec3 color ) {\n return toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n color *= toneMappingExposure;\n return 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 color *= toneMappingExposure;\n return saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n color *= toneMappingExposure;\n color = max( vec3( 0.0 ), color - 0.004 );\n return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\n";
  14059. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  14060. THREE.ShaderChunk[ 'uv2_pars_fragment' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n varying vec2 vUv2;\n#endif";
  14061. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  14062. THREE.ShaderChunk[ 'uv2_pars_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n attribute vec2 uv2;\n varying vec2 vUv2;\n#endif";
  14063. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  14064. THREE.ShaderChunk[ 'uv2_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = uv2;\n#endif";
  14065. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  14066. THREE.ShaderChunk[ '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 varying vec2 vUv;\n#endif";
  14067. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  14068. THREE.ShaderChunk[ '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 varying vec2 vUv;\n uniform vec4 offsetRepeat;\n#endif\n";
  14069. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  14070. THREE.ShaderChunk[ '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 vUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n#endif";
  14071. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  14072. THREE.ShaderChunk[ 'worldpos_vertex' ] = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( STANDARD ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n #ifdef USE_SKINNING\n vec4 worldPosition = modelMatrix * skinned;\n #else\n vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n #endif\n#endif\n";
  14073. // File:src/renderers/shaders/UniformsUtils.js
  14074. /**
  14075. * Uniform Utilities
  14076. */
  14077. THREE.UniformsUtils = {
  14078. merge: function ( uniforms ) {
  14079. var merged = {};
  14080. for ( var u = 0; u < uniforms.length; u ++ ) {
  14081. var tmp = this.clone( uniforms[ u ] );
  14082. for ( var p in tmp ) {
  14083. merged[ p ] = tmp[ p ];
  14084. }
  14085. }
  14086. return merged;
  14087. },
  14088. clone: function ( uniforms_src ) {
  14089. var uniforms_dst = {};
  14090. for ( var u in uniforms_src ) {
  14091. uniforms_dst[ u ] = {};
  14092. for ( var p in uniforms_src[ u ] ) {
  14093. var parameter_src = uniforms_src[ u ][ p ];
  14094. if ( parameter_src instanceof THREE.Color ||
  14095. parameter_src instanceof THREE.Vector2 ||
  14096. parameter_src instanceof THREE.Vector3 ||
  14097. parameter_src instanceof THREE.Vector4 ||
  14098. parameter_src instanceof THREE.Matrix3 ||
  14099. parameter_src instanceof THREE.Matrix4 ||
  14100. parameter_src instanceof THREE.Texture ) {
  14101. uniforms_dst[ u ][ p ] = parameter_src.clone();
  14102. } else if ( Array.isArray( parameter_src ) ) {
  14103. uniforms_dst[ u ][ p ] = parameter_src.slice();
  14104. } else {
  14105. uniforms_dst[ u ][ p ] = parameter_src;
  14106. }
  14107. }
  14108. }
  14109. return uniforms_dst;
  14110. }
  14111. };
  14112. // File:src/renderers/shaders/UniformsLib.js
  14113. /**
  14114. * Uniforms library for shared webgl shaders
  14115. */
  14116. THREE.UniformsLib = {
  14117. common: {
  14118. "diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
  14119. "opacity": { type: "f", value: 1.0 },
  14120. "map": { type: "t", value: null },
  14121. "offsetRepeat": { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  14122. "specularMap": { type: "t", value: null },
  14123. "alphaMap": { type: "t", value: null },
  14124. "envMap": { type: "t", value: null },
  14125. "flipEnvMap": { type: "f", value: - 1 },
  14126. "reflectivity": { type: "f", value: 1.0 },
  14127. "refractionRatio": { type: "f", value: 0.98 }
  14128. },
  14129. aomap: {
  14130. "aoMap": { type: "t", value: null },
  14131. "aoMapIntensity": { type: "f", value: 1 }
  14132. },
  14133. lightmap: {
  14134. "lightMap": { type: "t", value: null },
  14135. "lightMapIntensity": { type: "f", value: 1 }
  14136. },
  14137. emissivemap: {
  14138. "emissiveMap": { type: "t", value: null }
  14139. },
  14140. bumpmap: {
  14141. "bumpMap": { type: "t", value: null },
  14142. "bumpScale": { type: "f", value: 1 }
  14143. },
  14144. normalmap: {
  14145. "normalMap": { type: "t", value: null },
  14146. "normalScale": { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  14147. },
  14148. displacementmap: {
  14149. "displacementMap": { type: "t", value: null },
  14150. "displacementScale": { type: "f", value: 1 },
  14151. "displacementBias": { type: "f", value: 0 }
  14152. },
  14153. roughnessmap: {
  14154. "roughnessMap": { type: "t", value: null }
  14155. },
  14156. metalnessmap: {
  14157. "metalnessMap": { type: "t", value: null }
  14158. },
  14159. fog: {
  14160. "fogDensity": { type: "f", value: 0.00025 },
  14161. "fogNear": { type: "f", value: 1 },
  14162. "fogFar": { type: "f", value: 2000 },
  14163. "fogColor": { type: "c", value: new THREE.Color( 0xffffff ) }
  14164. },
  14165. lights: {
  14166. "ambientLightColor": { type: "fv", value: [] },
  14167. "directionalLights": { type: "sa", value: [], properties: {
  14168. "direction": { type: "v3" },
  14169. "color": { type: "c" },
  14170. "shadow": { type: "i" },
  14171. "shadowBias": { type: "f" },
  14172. "shadowRadius": { type: "f" },
  14173. "shadowMapSize": { type: "v2" }
  14174. } },
  14175. "directionalShadowMap": { type: "tv", value: [] },
  14176. "directionalShadowMatrix": { type: "m4v", value: [] },
  14177. "spotLights": { type: "sa", value: [], properties: {
  14178. "color": { type: "c" },
  14179. "position": { type: "v3" },
  14180. "direction": { type: "v3" },
  14181. "distance": { type: "f" },
  14182. "coneCos": { type: "f" },
  14183. "penumbraCos": { type: "f" },
  14184. "decay": { type: "f" },
  14185. "shadow": { type: "i" },
  14186. "shadowBias": { type: "f" },
  14187. "shadowRadius": { type: "f" },
  14188. "shadowMapSize": { type: "v2" }
  14189. } },
  14190. "spotShadowMap": { type: "tv", value: [] },
  14191. "spotShadowMatrix": { type: "m4v", value: [] },
  14192. "pointLights": { type: "sa", value: [], properties: {
  14193. "color": { type: "c" },
  14194. "position": { type: "v3" },
  14195. "decay": { type: "f" },
  14196. "distance": { type: "f" },
  14197. "shadow": { type: "i" },
  14198. "shadowBias": { type: "f" },
  14199. "shadowRadius": { type: "f" },
  14200. "shadowMapSize": { type: "v2" }
  14201. } },
  14202. "pointShadowMap": { type: "tv", value: [] },
  14203. "pointShadowMatrix": { type: "m4v", value: [] },
  14204. "hemisphereLights": { type: "sa", value: [], properties: {
  14205. "direction": { type: "v3" },
  14206. "skyColor": { type: "c" },
  14207. "groundColor": { type: "c" }
  14208. } }
  14209. },
  14210. points: {
  14211. "diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
  14212. "opacity": { type: "f", value: 1.0 },
  14213. "size": { type: "f", value: 1.0 },
  14214. "scale": { type: "f", value: 1.0 },
  14215. "map": { type: "t", value: null },
  14216. "offsetRepeat": { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) }
  14217. }
  14218. };
  14219. // File:src/renderers/shaders/ShaderLib/cube_frag.glsl
  14220. THREE.ShaderChunk[ 'cube_frag' ] = "uniform samplerCube tCube;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\n #include <logdepthbuf_fragment>\n}\n";
  14221. // File:src/renderers/shaders/ShaderLib/cube_vert.glsl
  14222. THREE.ShaderChunk[ 'cube_vert' ] = "varying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n vWorldPosition = transformDirection( position, modelMatrix );\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n #include <logdepthbuf_vertex>\n}\n";
  14223. // File:src/renderers/shaders/ShaderLib/depth_frag.glsl
  14224. THREE.ShaderChunk[ 'depth_frag' ] = "uniform float mNear;\nuniform float mFar;\nuniform float opacity;\n#include <common>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n #include <logdepthbuf_fragment>\n #ifdef USE_LOGDEPTHBUF_EXT\n float depth = gl_FragDepthEXT / gl_FragCoord.w;\n #else\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n #endif\n float color = 1.0 - smoothstep( mNear, mFar, depth );\n gl_FragColor = vec4( vec3( color ), opacity );\n}\n";
  14225. // File:src/renderers/shaders/ShaderLib/depth_vert.glsl
  14226. THREE.ShaderChunk[ 'depth_vert' ] = "#include <common>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n}\n";
  14227. // File:src/renderers/shaders/ShaderLib/depthRGBA_frag.glsl
  14228. THREE.ShaderChunk[ 'depthRGBA_frag' ] = "#include <common>\n#include <logdepthbuf_pars_fragment>\nvec4 pack_depth( const in float depth ) {\n const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );\n const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );\n vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );\n res -= res.xxyz * bit_mask;\n return res;\n}\nvoid main() {\n #include <logdepthbuf_fragment>\n #ifdef USE_LOGDEPTHBUF_EXT\n gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );\n #else\n gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );\n #endif\n}\n";
  14229. // File:src/renderers/shaders/ShaderLib/depthRGBA_vert.glsl
  14230. THREE.ShaderChunk[ 'depthRGBA_vert' ] = "#include <common>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <skinbase_vertex>\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n}\n";
  14231. // File:src/renderers/shaders/ShaderLib/distanceRGBA_frag.glsl
  14232. THREE.ShaderChunk[ 'distanceRGBA_frag' ] = "uniform vec3 lightPos;\nvarying vec4 vWorldPosition;\n#include <common>\nvec4 pack1K ( float depth ) {\n depth /= 1000.0;\n const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );\n const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );\n vec4 res = mod( depth * bitSh * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );\n res -= res.xxyz * bitMsk;\n return res;\n}\nfloat unpack1K ( vec4 color ) {\n const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n return dot( color, bitSh ) * 1000.0;\n}\nvoid main () {\n gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );\n}\n";
  14233. // File:src/renderers/shaders/ShaderLib/distanceRGBA_vert.glsl
  14234. THREE.ShaderChunk[ 'distanceRGBA_vert' ] = "varying vec4 vWorldPosition;\n#include <common>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\nvoid main() {\n #include <skinbase_vertex>\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <worldpos_vertex>\n vWorldPosition = worldPosition;\n}\n";
  14235. // File:src/renderers/shaders/ShaderLib/equirect_frag.glsl
  14236. THREE.ShaderChunk[ 'equirect_frag' ] = "uniform sampler2D tEquirect;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n vec3 direction = normalize( vWorldPosition );\n vec2 sampleUV;\n sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );\n sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n gl_FragColor = texture2D( tEquirect, sampleUV );\n #include <logdepthbuf_fragment>\n}\n";
  14237. // File:src/renderers/shaders/ShaderLib/equirect_vert.glsl
  14238. THREE.ShaderChunk[ 'equirect_vert' ] = "varying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n vWorldPosition = transformDirection( position, modelMatrix );\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n #include <logdepthbuf_vertex>\n}\n";
  14239. // File:src/renderers/shaders/ShaderLib/linedashed_frag.glsl
  14240. THREE.ShaderChunk[ '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>\nvoid main() {\n if ( mod( vLineDistance, totalSize ) > dashSize ) {\n discard;\n }\n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <logdepthbuf_fragment>\n #include <color_fragment>\n outgoingLight = diffuseColor.rgb;\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14241. // File:src/renderers/shaders/ShaderLib/linedashed_vert.glsl
  14242. THREE.ShaderChunk[ 'linedashed_vert' ] = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <color_vertex>\n vLineDistance = scale * lineDistance;\n vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n gl_Position = projectionMatrix * mvPosition;\n #include <logdepthbuf_vertex>\n}\n";
  14243. // File:src/renderers/shaders/ShaderLib/meshbasic_frag.glsl
  14244. THREE.ShaderChunk[ 'meshbasic_frag' ] = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n varying 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 <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n ReflectedLight reflectedLight;\n reflectedLight.directDiffuse = vec3( 0.0 );\n reflectedLight.directSpecular = vec3( 0.0 );\n reflectedLight.indirectDiffuse = diffuseColor.rgb;\n reflectedLight.indirectSpecular = vec3( 0.0 );\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.indirectDiffuse;\n #include <envmap_fragment>\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14245. // File:src/renderers/shaders/ShaderLib/meshbasic_vert.glsl
  14246. THREE.ShaderChunk[ '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 <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <skinbase_vertex>\n #ifdef USE_ENVMAP\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n #endif\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <worldpos_vertex>\n #include <envmap_vertex>\n}\n";
  14247. // File:src/renderers/shaders/ShaderLib/meshlambert_frag.glsl
  14248. THREE.ShaderChunk[ 'meshlambert_frag' ] = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n varying vec3 vLightBack;\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 <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>\nvoid main() {\n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n #include <emissivemap_fragment>\n reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );\n #include <lightmap_fragment>\n reflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\n #ifdef DOUBLE_SIDED\n reflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n #else\n reflectedLight.directDiffuse = vLightFront;\n #endif\n reflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n #include <envmap_fragment>\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14249. // File:src/renderers/shaders/ShaderLib/meshlambert_vert.glsl
  14250. THREE.ShaderChunk[ 'meshlambert_vert' ] = "#define LAMBERT\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n varying 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 <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <worldpos_vertex>\n #include <envmap_vertex>\n #include <lights_lambert_vertex>\n #include <shadowmap_vertex>\n}\n";
  14251. // File:src/renderers/shaders/ShaderLib/meshphong_frag.glsl
  14252. THREE.ShaderChunk[ 'meshphong_frag' ] = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\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 <emissivemap_pars_fragment>\n#include <envmap_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>\nvoid main() {\n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n #include <normal_fragment>\n #include <emissivemap_fragment>\n #include <lights_phong_fragment>\n #include <lights_template>\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n #include <envmap_fragment>\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14253. // File:src/renderers/shaders/ShaderLib/meshphong_vert.glsl
  14254. THREE.ShaderChunk[ 'meshphong_vert' ] = "#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying 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 <lights_phong_pars_vertex>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n vNormal = normalize( transformedNormal );\n#endif\n #include <begin_vertex>\n #include <displacementmap_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n vViewPosition = - mvPosition.xyz;\n #include <worldpos_vertex>\n #include <envmap_vertex>\n #include <lights_phong_vertex>\n #include <shadowmap_vertex>\n}\n";
  14255. // File:src/renderers/shaders/ShaderLib/meshstandard_frag.glsl
  14256. THREE.ShaderChunk[ 'meshstandard_frag' ] = "#define STANDARD\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\nuniform float envMapIntensity;\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying 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 <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_standard_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>\nvoid main() {\n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n #include <roughnessmap_fragment>\n #include <metalnessmap_fragment>\n #include <normal_fragment>\n #include <emissivemap_fragment>\n #include <lights_standard_fragment>\n #include <lights_template>\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14257. // File:src/renderers/shaders/ShaderLib/meshstandard_vert.glsl
  14258. THREE.ShaderChunk[ 'meshstandard_vert' ] = "#define STANDARD\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying 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 <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n vNormal = normalize( transformedNormal );\n#endif\n #include <begin_vertex>\n #include <displacementmap_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n vViewPosition = - mvPosition.xyz;\n #include <worldpos_vertex>\n #include <envmap_vertex>\n #include <shadowmap_vertex>\n}\n";
  14259. // File:src/renderers/shaders/ShaderLib/normal_frag.glsl
  14260. THREE.ShaderChunk[ 'normal_frag' ] = "uniform float opacity;\nvarying vec3 vNormal;\n#include <common>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );\n #include <logdepthbuf_fragment>\n}\n";
  14261. // File:src/renderers/shaders/ShaderLib/normal_vert.glsl
  14262. THREE.ShaderChunk[ 'normal_vert' ] = "varying vec3 vNormal;\n#include <common>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n vNormal = normalize( normalMatrix * normal );\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n}\n";
  14263. // File:src/renderers/shaders/ShaderLib/points_frag.glsl
  14264. THREE.ShaderChunk[ 'points_frag' ] = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\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>\nvoid main() {\n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <logdepthbuf_fragment>\n #include <map_particle_fragment>\n #include <color_fragment>\n #include <alphatest_fragment>\n outgoingLight = diffuseColor.rgb;\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14265. // File:src/renderers/shaders/ShaderLib/points_vert.glsl
  14266. THREE.ShaderChunk[ 'points_vert' ] = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <color_vertex>\n #include <begin_vertex>\n #include <project_vertex>\n #ifdef USE_SIZEATTENUATION\n gl_PointSize = size * ( scale / - mvPosition.z );\n #else\n gl_PointSize = size;\n #endif\n #include <logdepthbuf_vertex>\n #include <worldpos_vertex>\n #include <shadowmap_vertex>\n}\n";
  14267. // File:src/renderers/shaders/ShaderLib.js
  14268. /**
  14269. * Webgl Shader Library for three.js
  14270. *
  14271. * @author alteredq / http://alteredqualia.com/
  14272. * @author mrdoob / http://mrdoob.com/
  14273. * @author mikael emtinger / http://gomo.se/
  14274. */
  14275. THREE.ShaderLib = {
  14276. 'basic': {
  14277. uniforms: THREE.UniformsUtils.merge( [
  14278. THREE.UniformsLib[ "common" ],
  14279. THREE.UniformsLib[ "aomap" ],
  14280. THREE.UniformsLib[ "fog" ]
  14281. ] ),
  14282. vertexShader: THREE.ShaderChunk['meshbasic_vert'],
  14283. fragmentShader: THREE.ShaderChunk['meshbasic_frag']
  14284. },
  14285. 'lambert': {
  14286. uniforms: THREE.UniformsUtils.merge( [
  14287. THREE.UniformsLib[ "common" ],
  14288. THREE.UniformsLib[ "aomap" ],
  14289. THREE.UniformsLib[ "lightmap" ],
  14290. THREE.UniformsLib[ "emissivemap" ],
  14291. THREE.UniformsLib[ "fog" ],
  14292. THREE.UniformsLib[ "lights" ],
  14293. {
  14294. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  14295. }
  14296. ] ),
  14297. vertexShader: THREE.ShaderChunk['meshlambert_vert'],
  14298. fragmentShader: THREE.ShaderChunk['meshlambert_frag']
  14299. },
  14300. 'phong': {
  14301. uniforms: THREE.UniformsUtils.merge( [
  14302. THREE.UniformsLib[ "common" ],
  14303. THREE.UniformsLib[ "aomap" ],
  14304. THREE.UniformsLib[ "lightmap" ],
  14305. THREE.UniformsLib[ "emissivemap" ],
  14306. THREE.UniformsLib[ "bumpmap" ],
  14307. THREE.UniformsLib[ "normalmap" ],
  14308. THREE.UniformsLib[ "displacementmap" ],
  14309. THREE.UniformsLib[ "fog" ],
  14310. THREE.UniformsLib[ "lights" ],
  14311. {
  14312. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14313. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  14314. "shininess": { type: "f", value: 30 }
  14315. }
  14316. ] ),
  14317. vertexShader: THREE.ShaderChunk['meshphong_vert'],
  14318. fragmentShader: THREE.ShaderChunk['meshphong_frag']
  14319. },
  14320. 'standard': {
  14321. uniforms: THREE.UniformsUtils.merge( [
  14322. THREE.UniformsLib[ "common" ],
  14323. THREE.UniformsLib[ "aomap" ],
  14324. THREE.UniformsLib[ "lightmap" ],
  14325. THREE.UniformsLib[ "emissivemap" ],
  14326. THREE.UniformsLib[ "bumpmap" ],
  14327. THREE.UniformsLib[ "normalmap" ],
  14328. THREE.UniformsLib[ "displacementmap" ],
  14329. THREE.UniformsLib[ "roughnessmap" ],
  14330. THREE.UniformsLib[ "metalnessmap" ],
  14331. THREE.UniformsLib[ "fog" ],
  14332. THREE.UniformsLib[ "lights" ],
  14333. {
  14334. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14335. "roughness": { type: "f", value: 0.5 },
  14336. "metalness": { type: "f", value: 0 },
  14337. "envMapIntensity" : { type: "f", value: 1 } // temporary
  14338. }
  14339. ] ),
  14340. vertexShader: THREE.ShaderChunk['meshstandard_vert'],
  14341. fragmentShader: THREE.ShaderChunk['meshstandard_frag']
  14342. },
  14343. 'points': {
  14344. uniforms: THREE.UniformsUtils.merge( [
  14345. THREE.UniformsLib[ "points" ],
  14346. THREE.UniformsLib[ "fog" ]
  14347. ] ),
  14348. vertexShader: THREE.ShaderChunk['points_vert'],
  14349. fragmentShader: THREE.ShaderChunk['points_frag']
  14350. },
  14351. 'dashed': {
  14352. uniforms: THREE.UniformsUtils.merge( [
  14353. THREE.UniformsLib[ "common" ],
  14354. THREE.UniformsLib[ "fog" ],
  14355. {
  14356. "scale" : { type: "f", value: 1 },
  14357. "dashSize" : { type: "f", value: 1 },
  14358. "totalSize": { type: "f", value: 2 }
  14359. }
  14360. ] ),
  14361. vertexShader: THREE.ShaderChunk['linedashed_vert'],
  14362. fragmentShader: THREE.ShaderChunk['linedashed_frag']
  14363. },
  14364. 'depth': {
  14365. uniforms: {
  14366. "mNear": { type: "f", value: 1.0 },
  14367. "mFar" : { type: "f", value: 2000.0 },
  14368. "opacity" : { type: "f", value: 1.0 }
  14369. },
  14370. vertexShader: THREE.ShaderChunk['depth_vert'],
  14371. fragmentShader: THREE.ShaderChunk['depth_frag']
  14372. },
  14373. 'normal': {
  14374. uniforms: {
  14375. "opacity" : { type: "f", value: 1.0 }
  14376. },
  14377. vertexShader: THREE.ShaderChunk['normal_vert'],
  14378. fragmentShader: THREE.ShaderChunk['normal_frag']
  14379. },
  14380. /* -------------------------------------------------------------------------
  14381. // Cube map shader
  14382. ------------------------------------------------------------------------- */
  14383. 'cube': {
  14384. uniforms: {
  14385. "tCube": { type: "t", value: null },
  14386. "tFlip": { type: "f", value: - 1 }
  14387. },
  14388. vertexShader: THREE.ShaderChunk['cube_vert'],
  14389. fragmentShader: THREE.ShaderChunk['cube_frag']
  14390. },
  14391. /* -------------------------------------------------------------------------
  14392. // Cube map shader
  14393. ------------------------------------------------------------------------- */
  14394. 'equirect': {
  14395. uniforms: {
  14396. "tEquirect": { type: "t", value: null },
  14397. "tFlip": { type: "f", value: - 1 }
  14398. },
  14399. vertexShader: THREE.ShaderChunk['equirect_vert'],
  14400. fragmentShader: THREE.ShaderChunk['equirect_frag']
  14401. },
  14402. /* Depth encoding into RGBA texture
  14403. *
  14404. * based on SpiderGL shadow map example
  14405. * http://spidergl.org/example.php?id=6
  14406. *
  14407. * originally from
  14408. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  14409. *
  14410. * see also
  14411. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  14412. */
  14413. 'depthRGBA': {
  14414. uniforms: {},
  14415. vertexShader: THREE.ShaderChunk['depthRGBA_vert'],
  14416. fragmentShader: THREE.ShaderChunk['depthRGBA_frag']
  14417. },
  14418. 'distanceRGBA': {
  14419. uniforms: {
  14420. "lightPos": { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) }
  14421. },
  14422. vertexShader: THREE.ShaderChunk['distanceRGBA_vert'],
  14423. fragmentShader: THREE.ShaderChunk['distanceRGBA_frag']
  14424. }
  14425. };
  14426. // File:src/renderers/WebGLRenderer.js
  14427. /**
  14428. * @author supereggbert / http://www.paulbrunt.co.uk/
  14429. * @author mrdoob / http://mrdoob.com/
  14430. * @author alteredq / http://alteredqualia.com/
  14431. * @author szimek / https://github.com/szimek/
  14432. */
  14433. THREE.WebGLRenderer = function ( parameters ) {
  14434. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  14435. parameters = parameters || {};
  14436. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  14437. _context = parameters.context !== undefined ? parameters.context : null,
  14438. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14439. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14440. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14441. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14442. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14443. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
  14444. var lights = [];
  14445. var opaqueObjects = [];
  14446. var opaqueObjectsLastIndex = - 1;
  14447. var transparentObjects = [];
  14448. var transparentObjectsLastIndex = - 1;
  14449. var morphInfluences = new Float32Array( 8 );
  14450. var sprites = [];
  14451. var lensFlares = [];
  14452. // public properties
  14453. this.domElement = _canvas;
  14454. this.context = null;
  14455. // clearing
  14456. this.autoClear = true;
  14457. this.autoClearColor = true;
  14458. this.autoClearDepth = true;
  14459. this.autoClearStencil = true;
  14460. // scene graph
  14461. this.sortObjects = true;
  14462. // physically based shading
  14463. this.gammaFactor = 2.0; // for backwards compatibility
  14464. this.gammaInput = false;
  14465. this.gammaOutput = false;
  14466. // physical lights
  14467. this.physicallyCorrectLights = false;
  14468. // tone mapping
  14469. this.toneMapping = THREE.LinearToneMapping;
  14470. this.toneMappingExposure = 1.0;
  14471. this.toneMappingWhitePoint = 1.0;
  14472. // morphs
  14473. this.maxMorphTargets = 8;
  14474. this.maxMorphNormals = 4;
  14475. // flags
  14476. this.autoScaleCubemaps = true;
  14477. // internal properties
  14478. var _this = this,
  14479. // internal state cache
  14480. _currentProgram = null,
  14481. _currentRenderTarget = null,
  14482. _currentFramebuffer = null,
  14483. _currentMaterialId = - 1,
  14484. _currentGeometryProgram = '',
  14485. _currentCamera = null,
  14486. _currentScissor = new THREE.Vector4(),
  14487. _currentScissorTest = null,
  14488. _currentViewport = new THREE.Vector4(),
  14489. //
  14490. _usedTextureUnits = 0,
  14491. //
  14492. _clearColor = new THREE.Color( 0x000000 ),
  14493. _clearAlpha = 0,
  14494. _width = _canvas.width,
  14495. _height = _canvas.height,
  14496. _pixelRatio = 1,
  14497. _scissor = new THREE.Vector4( 0, 0, _width, _height ),
  14498. _scissorTest = false,
  14499. _viewport = new THREE.Vector4( 0, 0, _width, _height ),
  14500. // frustum
  14501. _frustum = new THREE.Frustum(),
  14502. // camera matrices cache
  14503. _projScreenMatrix = new THREE.Matrix4(),
  14504. _vector3 = new THREE.Vector3(),
  14505. // light arrays cache
  14506. _lights = {
  14507. hash: '',
  14508. ambient: [ 0, 0, 0 ],
  14509. directional: [],
  14510. directionalShadowMap: [],
  14511. directionalShadowMatrix: [],
  14512. spot: [],
  14513. spotShadowMap: [],
  14514. spotShadowMatrix: [],
  14515. point: [],
  14516. pointShadowMap: [],
  14517. pointShadowMatrix: [],
  14518. hemi: [],
  14519. shadows: [],
  14520. shadowsPointLight: 0
  14521. },
  14522. // info
  14523. _infoMemory = {
  14524. geometries: 0,
  14525. textures: 0
  14526. },
  14527. _infoRender = {
  14528. calls: 0,
  14529. vertices: 0,
  14530. faces: 0,
  14531. points: 0
  14532. };
  14533. this.info = {
  14534. render: _infoRender,
  14535. memory: _infoMemory,
  14536. programs: null
  14537. };
  14538. // initialize
  14539. var _gl;
  14540. try {
  14541. var attributes = {
  14542. alpha: _alpha,
  14543. depth: _depth,
  14544. stencil: _stencil,
  14545. antialias: _antialias,
  14546. premultipliedAlpha: _premultipliedAlpha,
  14547. preserveDrawingBuffer: _preserveDrawingBuffer
  14548. };
  14549. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  14550. if ( _gl === null ) {
  14551. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14552. throw 'Error creating WebGL context with your selected attributes.';
  14553. } else {
  14554. throw 'Error creating WebGL context.';
  14555. }
  14556. }
  14557. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14558. if ( _gl.getShaderPrecisionFormat === undefined ) {
  14559. _gl.getShaderPrecisionFormat = function () {
  14560. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  14561. };
  14562. }
  14563. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14564. } catch ( error ) {
  14565. console.error( 'THREE.WebGLRenderer: ' + error );
  14566. }
  14567. var extensions = new THREE.WebGLExtensions( _gl );
  14568. extensions.get( 'OES_texture_float' );
  14569. extensions.get( 'OES_texture_float_linear' );
  14570. extensions.get( 'OES_texture_half_float' );
  14571. extensions.get( 'OES_texture_half_float_linear' );
  14572. extensions.get( 'OES_standard_derivatives' );
  14573. extensions.get( 'ANGLE_instanced_arrays' );
  14574. if ( extensions.get( 'OES_element_index_uint' ) ) {
  14575. THREE.BufferGeometry.MaxIndex = 4294967296;
  14576. }
  14577. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  14578. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  14579. var properties = new THREE.WebGLProperties();
  14580. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  14581. var programCache = new THREE.WebGLPrograms( this, capabilities );
  14582. var lightCache = new THREE.WebGLLights();
  14583. this.info.programs = programCache.programs;
  14584. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  14585. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  14586. //
  14587. function getTargetPixelRatio() {
  14588. return _currentRenderTarget === null ? _pixelRatio : 1;
  14589. }
  14590. function glClearColor( r, g, b, a ) {
  14591. if ( _premultipliedAlpha === true ) {
  14592. r *= a; g *= a; b *= a;
  14593. }
  14594. state.clearColor( r, g, b, a );
  14595. }
  14596. function setDefaultGLState() {
  14597. state.init();
  14598. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  14599. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  14600. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14601. }
  14602. function resetGLState() {
  14603. _currentProgram = null;
  14604. _currentCamera = null;
  14605. _currentGeometryProgram = '';
  14606. _currentMaterialId = - 1;
  14607. state.reset();
  14608. }
  14609. setDefaultGLState();
  14610. this.context = _gl;
  14611. this.capabilities = capabilities;
  14612. this.extensions = extensions;
  14613. this.properties = properties;
  14614. this.state = state;
  14615. // shadow map
  14616. var shadowMap = new THREE.WebGLShadowMap( this, _lights, objects );
  14617. this.shadowMap = shadowMap;
  14618. // Plugins
  14619. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  14620. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  14621. // API
  14622. this.getContext = function () {
  14623. return _gl;
  14624. };
  14625. this.getContextAttributes = function () {
  14626. return _gl.getContextAttributes();
  14627. };
  14628. this.forceContextLoss = function () {
  14629. extensions.get( 'WEBGL_lose_context' ).loseContext();
  14630. };
  14631. this.getMaxAnisotropy = ( function () {
  14632. var value;
  14633. return function getMaxAnisotropy() {
  14634. if ( value !== undefined ) return value;
  14635. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  14636. if ( extension !== null ) {
  14637. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  14638. } else {
  14639. value = 0;
  14640. }
  14641. return value;
  14642. };
  14643. } )();
  14644. this.getPrecision = function () {
  14645. return capabilities.precision;
  14646. };
  14647. this.getPixelRatio = function () {
  14648. return _pixelRatio;
  14649. };
  14650. this.setPixelRatio = function ( value ) {
  14651. if ( value === undefined ) return;
  14652. _pixelRatio = value;
  14653. this.setSize( _viewport.z, _viewport.w, false );
  14654. };
  14655. this.getSize = function () {
  14656. return {
  14657. width: _width,
  14658. height: _height
  14659. };
  14660. };
  14661. this.setSize = function ( width, height, updateStyle ) {
  14662. _width = width;
  14663. _height = height;
  14664. _canvas.width = width * _pixelRatio;
  14665. _canvas.height = height * _pixelRatio;
  14666. if ( updateStyle !== false ) {
  14667. _canvas.style.width = width + 'px';
  14668. _canvas.style.height = height + 'px';
  14669. }
  14670. this.setViewport( 0, 0, width, height );
  14671. };
  14672. this.setViewport = function ( x, y, width, height ) {
  14673. state.viewport( _viewport.set( x, y, width, height ) );
  14674. };
  14675. this.setScissor = function ( x, y, width, height ) {
  14676. state.scissor( _scissor.set( x, y, width, height ) );
  14677. };
  14678. this.setScissorTest = function ( boolean ) {
  14679. state.setScissorTest( _scissorTest = boolean );
  14680. };
  14681. // Clearing
  14682. this.getClearColor = function () {
  14683. return _clearColor;
  14684. };
  14685. this.setClearColor = function ( color, alpha ) {
  14686. _clearColor.set( color );
  14687. _clearAlpha = alpha !== undefined ? alpha : 1;
  14688. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14689. };
  14690. this.getClearAlpha = function () {
  14691. return _clearAlpha;
  14692. };
  14693. this.setClearAlpha = function ( alpha ) {
  14694. _clearAlpha = alpha;
  14695. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14696. };
  14697. this.clear = function ( color, depth, stencil ) {
  14698. var bits = 0;
  14699. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  14700. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  14701. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  14702. _gl.clear( bits );
  14703. };
  14704. this.clearColor = function () {
  14705. this.clear( true, false, false );
  14706. };
  14707. this.clearDepth = function () {
  14708. this.clear( false, true, false );
  14709. };
  14710. this.clearStencil = function () {
  14711. this.clear( false, false, true );
  14712. };
  14713. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  14714. this.setRenderTarget( renderTarget );
  14715. this.clear( color, depth, stencil );
  14716. };
  14717. // Reset
  14718. this.resetGLState = resetGLState;
  14719. this.dispose = function() {
  14720. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14721. };
  14722. // Events
  14723. function onContextLost( event ) {
  14724. event.preventDefault();
  14725. resetGLState();
  14726. setDefaultGLState();
  14727. properties.clear();
  14728. }
  14729. function onTextureDispose( event ) {
  14730. var texture = event.target;
  14731. texture.removeEventListener( 'dispose', onTextureDispose );
  14732. deallocateTexture( texture );
  14733. _infoMemory.textures --;
  14734. }
  14735. function onRenderTargetDispose( event ) {
  14736. var renderTarget = event.target;
  14737. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  14738. deallocateRenderTarget( renderTarget );
  14739. _infoMemory.textures --;
  14740. }
  14741. function onMaterialDispose( event ) {
  14742. var material = event.target;
  14743. material.removeEventListener( 'dispose', onMaterialDispose );
  14744. deallocateMaterial( material );
  14745. }
  14746. // Buffer deallocation
  14747. function deallocateTexture( texture ) {
  14748. var textureProperties = properties.get( texture );
  14749. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  14750. // cube texture
  14751. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  14752. } else {
  14753. // 2D texture
  14754. if ( textureProperties.__webglInit === undefined ) return;
  14755. _gl.deleteTexture( textureProperties.__webglTexture );
  14756. }
  14757. // remove all webgl properties
  14758. properties.delete( texture );
  14759. }
  14760. function deallocateRenderTarget( renderTarget ) {
  14761. var renderTargetProperties = properties.get( renderTarget );
  14762. var textureProperties = properties.get( renderTarget.texture );
  14763. if ( ! renderTarget || textureProperties.__webglTexture === undefined ) return;
  14764. _gl.deleteTexture( textureProperties.__webglTexture );
  14765. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  14766. for ( var i = 0; i < 6; i ++ ) {
  14767. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  14768. _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  14769. }
  14770. } else {
  14771. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  14772. _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  14773. }
  14774. properties.delete( renderTarget.texture );
  14775. properties.delete( renderTarget );
  14776. }
  14777. function deallocateMaterial( material ) {
  14778. releaseMaterialProgramReference( material );
  14779. properties.delete( material );
  14780. }
  14781. function releaseMaterialProgramReference( material ) {
  14782. var programInfo = properties.get( material ).program;
  14783. material.program = undefined;
  14784. if ( programInfo !== undefined ) {
  14785. programCache.releaseProgram( programInfo );
  14786. }
  14787. }
  14788. // Buffer rendering
  14789. this.renderBufferImmediate = function ( object, program, material ) {
  14790. state.initAttributes();
  14791. var buffers = properties.get( object );
  14792. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14793. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14794. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14795. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14796. var attributes = program.getAttributes();
  14797. if ( object.hasPositions ) {
  14798. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  14799. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  14800. state.enableAttribute( attributes.position );
  14801. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  14802. }
  14803. if ( object.hasNormals ) {
  14804. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  14805. if ( material.type !== 'MeshPhongMaterial' && material.type !== 'MeshStandardMaterial' && material.shading === THREE.FlatShading ) {
  14806. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  14807. var array = object.normalArray;
  14808. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  14809. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  14810. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  14811. array[ i + 0 ] = nx;
  14812. array[ i + 1 ] = ny;
  14813. array[ i + 2 ] = nz;
  14814. array[ i + 3 ] = nx;
  14815. array[ i + 4 ] = ny;
  14816. array[ i + 5 ] = nz;
  14817. array[ i + 6 ] = nx;
  14818. array[ i + 7 ] = ny;
  14819. array[ i + 8 ] = nz;
  14820. }
  14821. }
  14822. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  14823. state.enableAttribute( attributes.normal );
  14824. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  14825. }
  14826. if ( object.hasUvs && material.map ) {
  14827. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  14828. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  14829. state.enableAttribute( attributes.uv );
  14830. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  14831. }
  14832. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  14833. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  14834. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  14835. state.enableAttribute( attributes.color );
  14836. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  14837. }
  14838. state.disableUnusedAttributes();
  14839. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  14840. object.count = 0;
  14841. };
  14842. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  14843. setMaterial( material );
  14844. var program = setProgram( camera, fog, material, object );
  14845. var updateBuffers = false;
  14846. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  14847. if ( geometryProgram !== _currentGeometryProgram ) {
  14848. _currentGeometryProgram = geometryProgram;
  14849. updateBuffers = true;
  14850. }
  14851. // morph targets
  14852. var morphTargetInfluences = object.morphTargetInfluences;
  14853. if ( morphTargetInfluences !== undefined ) {
  14854. var activeInfluences = [];
  14855. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  14856. var influence = morphTargetInfluences[ i ];
  14857. activeInfluences.push( [ influence, i ] );
  14858. }
  14859. activeInfluences.sort( absNumericalSort );
  14860. if ( activeInfluences.length > 8 ) {
  14861. activeInfluences.length = 8;
  14862. }
  14863. var morphAttributes = geometry.morphAttributes;
  14864. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  14865. var influence = activeInfluences[ i ];
  14866. morphInfluences[ i ] = influence[ 0 ];
  14867. if ( influence[ 0 ] !== 0 ) {
  14868. var index = influence[ 1 ];
  14869. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  14870. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  14871. } else {
  14872. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  14873. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  14874. }
  14875. }
  14876. var uniforms = program.getUniforms();
  14877. if ( uniforms.morphTargetInfluences !== null ) {
  14878. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  14879. }
  14880. updateBuffers = true;
  14881. }
  14882. //
  14883. var index = geometry.index;
  14884. var position = geometry.attributes.position;
  14885. if ( material.wireframe === true ) {
  14886. index = objects.getWireframeAttribute( geometry );
  14887. }
  14888. var renderer;
  14889. if ( index !== null ) {
  14890. renderer = indexedBufferRenderer;
  14891. renderer.setIndex( index );
  14892. } else {
  14893. renderer = bufferRenderer;
  14894. }
  14895. if ( updateBuffers ) {
  14896. setupVertexAttributes( material, program, geometry );
  14897. if ( index !== null ) {
  14898. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  14899. }
  14900. }
  14901. //
  14902. var dataStart = 0;
  14903. var dataCount = Infinity;
  14904. if ( index !== null ) {
  14905. dataCount = index.count;
  14906. } else if ( position !== undefined ) {
  14907. dataCount = position.count;
  14908. }
  14909. var rangeStart = geometry.drawRange.start;
  14910. var rangeCount = geometry.drawRange.count;
  14911. var groupStart = group !== null ? group.start : 0;
  14912. var groupCount = group !== null ? group.count : Infinity;
  14913. var drawStart = Math.max( dataStart, rangeStart, groupStart );
  14914. var drawEnd = Math.min( dataStart + dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  14915. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  14916. //
  14917. if ( object instanceof THREE.Mesh ) {
  14918. if ( material.wireframe === true ) {
  14919. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  14920. renderer.setMode( _gl.LINES );
  14921. } else {
  14922. switch ( object.drawMode ) {
  14923. case THREE.TrianglesDrawMode:
  14924. renderer.setMode( _gl.TRIANGLES );
  14925. break;
  14926. case THREE.TriangleStripDrawMode:
  14927. renderer.setMode( _gl.TRIANGLE_STRIP );
  14928. break;
  14929. case THREE.TriangleFanDrawMode:
  14930. renderer.setMode( _gl.TRIANGLE_FAN );
  14931. break;
  14932. }
  14933. }
  14934. } else if ( object instanceof THREE.Line ) {
  14935. var lineWidth = material.linewidth;
  14936. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  14937. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  14938. if ( object instanceof THREE.LineSegments ) {
  14939. renderer.setMode( _gl.LINES );
  14940. } else {
  14941. renderer.setMode( _gl.LINE_STRIP );
  14942. }
  14943. } else if ( object instanceof THREE.Points ) {
  14944. renderer.setMode( _gl.POINTS );
  14945. }
  14946. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  14947. if ( geometry.maxInstancedCount > 0 ) {
  14948. renderer.renderInstances( geometry, drawStart, drawCount );
  14949. }
  14950. } else {
  14951. renderer.render( drawStart, drawCount );
  14952. }
  14953. };
  14954. function setupVertexAttributes( material, program, geometry, startIndex ) {
  14955. var extension;
  14956. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  14957. extension = extensions.get( 'ANGLE_instanced_arrays' );
  14958. if ( extension === null ) {
  14959. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14960. return;
  14961. }
  14962. }
  14963. if ( startIndex === undefined ) startIndex = 0;
  14964. state.initAttributes();
  14965. var geometryAttributes = geometry.attributes;
  14966. var programAttributes = program.getAttributes();
  14967. var materialDefaultAttributeValues = material.defaultAttributeValues;
  14968. for ( var name in programAttributes ) {
  14969. var programAttribute = programAttributes[ name ];
  14970. if ( programAttribute >= 0 ) {
  14971. var geometryAttribute = geometryAttributes[ name ];
  14972. if ( geometryAttribute !== undefined ) {
  14973. var size = geometryAttribute.itemSize;
  14974. var buffer = objects.getAttributeBuffer( geometryAttribute );
  14975. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  14976. var data = geometryAttribute.data;
  14977. var stride = data.stride;
  14978. var offset = geometryAttribute.offset;
  14979. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  14980. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  14981. if ( geometry.maxInstancedCount === undefined ) {
  14982. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  14983. }
  14984. } else {
  14985. state.enableAttribute( programAttribute );
  14986. }
  14987. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  14988. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  14989. } else {
  14990. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  14991. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  14992. if ( geometry.maxInstancedCount === undefined ) {
  14993. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  14994. }
  14995. } else {
  14996. state.enableAttribute( programAttribute );
  14997. }
  14998. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  14999. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  15000. }
  15001. } else if ( materialDefaultAttributeValues !== undefined ) {
  15002. var value = materialDefaultAttributeValues[ name ];
  15003. if ( value !== undefined ) {
  15004. switch ( value.length ) {
  15005. case 2:
  15006. _gl.vertexAttrib2fv( programAttribute, value );
  15007. break;
  15008. case 3:
  15009. _gl.vertexAttrib3fv( programAttribute, value );
  15010. break;
  15011. case 4:
  15012. _gl.vertexAttrib4fv( programAttribute, value );
  15013. break;
  15014. default:
  15015. _gl.vertexAttrib1fv( programAttribute, value );
  15016. }
  15017. }
  15018. }
  15019. }
  15020. }
  15021. state.disableUnusedAttributes();
  15022. }
  15023. // Sorting
  15024. function absNumericalSort( a, b ) {
  15025. return Math.abs( b[ 0 ] ) - Math.abs( a[ 0 ] );
  15026. }
  15027. function painterSortStable ( a, b ) {
  15028. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15029. return a.object.renderOrder - b.object.renderOrder;
  15030. } else if ( a.material.id !== b.material.id ) {
  15031. return a.material.id - b.material.id;
  15032. } else if ( a.z !== b.z ) {
  15033. return a.z - b.z;
  15034. } else {
  15035. return a.id - b.id;
  15036. }
  15037. }
  15038. function reversePainterSortStable ( a, b ) {
  15039. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15040. return a.object.renderOrder - b.object.renderOrder;
  15041. } if ( a.z !== b.z ) {
  15042. return b.z - a.z;
  15043. } else {
  15044. return a.id - b.id;
  15045. }
  15046. }
  15047. // Rendering
  15048. this.render = function ( scene, camera, renderTarget, forceClear ) {
  15049. if ( camera instanceof THREE.Camera === false ) {
  15050. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15051. return;
  15052. }
  15053. var fog = scene.fog;
  15054. // reset caching for this frame
  15055. _currentGeometryProgram = '';
  15056. _currentMaterialId = - 1;
  15057. _currentCamera = null;
  15058. // update scene graph
  15059. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15060. // update camera matrices and frustum
  15061. if ( camera.parent === null ) camera.updateMatrixWorld();
  15062. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  15063. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15064. _frustum.setFromMatrix( _projScreenMatrix );
  15065. lights.length = 0;
  15066. opaqueObjectsLastIndex = - 1;
  15067. transparentObjectsLastIndex = - 1;
  15068. sprites.length = 0;
  15069. lensFlares.length = 0;
  15070. projectObject( scene, camera );
  15071. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  15072. transparentObjects.length = transparentObjectsLastIndex + 1;
  15073. if ( _this.sortObjects === true ) {
  15074. opaqueObjects.sort( painterSortStable );
  15075. transparentObjects.sort( reversePainterSortStable );
  15076. }
  15077. setupLights( lights, camera );
  15078. //
  15079. shadowMap.render( scene, camera );
  15080. //
  15081. _infoRender.calls = 0;
  15082. _infoRender.vertices = 0;
  15083. _infoRender.faces = 0;
  15084. _infoRender.points = 0;
  15085. if ( renderTarget === undefined ) {
  15086. renderTarget = null;
  15087. }
  15088. this.setRenderTarget( renderTarget );
  15089. if ( this.autoClear || forceClear ) {
  15090. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  15091. }
  15092. //
  15093. if ( scene.overrideMaterial ) {
  15094. var overrideMaterial = scene.overrideMaterial;
  15095. renderObjects( opaqueObjects, camera, fog, overrideMaterial );
  15096. renderObjects( transparentObjects, camera, fog, overrideMaterial );
  15097. } else {
  15098. // opaque pass (front-to-back order)
  15099. state.setBlending( THREE.NoBlending );
  15100. renderObjects( opaqueObjects, camera, fog );
  15101. // transparent pass (back-to-front order)
  15102. renderObjects( transparentObjects, camera, fog );
  15103. }
  15104. // custom render plugins (post pass)
  15105. spritePlugin.render( scene, camera );
  15106. lensFlarePlugin.render( scene, camera, _currentViewport );
  15107. // Generate mipmap if we're using any kind of mipmap filtering
  15108. if ( renderTarget ) {
  15109. var texture = renderTarget.texture;
  15110. if ( texture.generateMipmaps && isPowerOfTwo( renderTarget ) &&
  15111. texture.minFilter !== THREE.NearestFilter &&
  15112. texture.minFilter !== THREE.LinearFilter ) {
  15113. updateRenderTargetMipmap( renderTarget );
  15114. }
  15115. }
  15116. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15117. state.setDepthTest( true );
  15118. state.setDepthWrite( true );
  15119. state.setColorWrite( true );
  15120. // _gl.finish();
  15121. };
  15122. function pushRenderItem( object, geometry, material, z, group ) {
  15123. var array, index;
  15124. // allocate the next position in the appropriate array
  15125. if ( material.transparent ) {
  15126. array = transparentObjects;
  15127. index = ++ transparentObjectsLastIndex;
  15128. } else {
  15129. array = opaqueObjects;
  15130. index = ++ opaqueObjectsLastIndex;
  15131. }
  15132. // recycle existing render item or grow the array
  15133. var renderItem = array[ index ];
  15134. if ( renderItem !== undefined ) {
  15135. renderItem.id = object.id;
  15136. renderItem.object = object;
  15137. renderItem.geometry = geometry;
  15138. renderItem.material = material;
  15139. renderItem.z = _vector3.z;
  15140. renderItem.group = group;
  15141. } else {
  15142. renderItem = {
  15143. id: object.id,
  15144. object: object,
  15145. geometry: geometry,
  15146. material: material,
  15147. z: _vector3.z,
  15148. group: group
  15149. };
  15150. // assert( index === array.length );
  15151. array.push( renderItem );
  15152. }
  15153. }
  15154. function projectObject( object, camera ) {
  15155. if ( object.visible === false ) return;
  15156. if ( object.layers.test( camera.layers ) ) {
  15157. if ( object instanceof THREE.Light ) {
  15158. lights.push( object );
  15159. } else if ( object instanceof THREE.Sprite ) {
  15160. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15161. sprites.push( object );
  15162. }
  15163. } else if ( object instanceof THREE.LensFlare ) {
  15164. lensFlares.push( object );
  15165. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  15166. if ( _this.sortObjects === true ) {
  15167. _vector3.setFromMatrixPosition( object.matrixWorld );
  15168. _vector3.applyProjection( _projScreenMatrix );
  15169. }
  15170. pushRenderItem( object, null, object.material, _vector3.z, null );
  15171. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15172. if ( object instanceof THREE.SkinnedMesh ) {
  15173. object.skeleton.update();
  15174. }
  15175. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15176. var material = object.material;
  15177. if ( material.visible === true ) {
  15178. if ( _this.sortObjects === true ) {
  15179. _vector3.setFromMatrixPosition( object.matrixWorld );
  15180. _vector3.applyProjection( _projScreenMatrix );
  15181. }
  15182. var geometry = objects.update( object );
  15183. if ( material instanceof THREE.MultiMaterial ) {
  15184. var groups = geometry.groups;
  15185. var materials = material.materials;
  15186. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15187. var group = groups[ i ];
  15188. var groupMaterial = materials[ group.materialIndex ];
  15189. if ( groupMaterial.visible === true ) {
  15190. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  15191. }
  15192. }
  15193. } else {
  15194. pushRenderItem( object, geometry, material, _vector3.z, null );
  15195. }
  15196. }
  15197. }
  15198. }
  15199. }
  15200. var children = object.children;
  15201. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15202. projectObject( children[ i ], camera );
  15203. }
  15204. }
  15205. function renderObjects( renderList, camera, fog, overrideMaterial ) {
  15206. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15207. var renderItem = renderList[ i ];
  15208. var object = renderItem.object;
  15209. var geometry = renderItem.geometry;
  15210. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  15211. var group = renderItem.group;
  15212. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15213. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15214. if ( object instanceof THREE.ImmediateRenderObject ) {
  15215. setMaterial( material );
  15216. var program = setProgram( camera, fog, material, object );
  15217. _currentGeometryProgram = '';
  15218. object.render( function ( object ) {
  15219. _this.renderBufferImmediate( object, program, material );
  15220. } );
  15221. } else {
  15222. _this.renderBufferDirect( camera, fog, geometry, material, object, group );
  15223. }
  15224. }
  15225. }
  15226. function initMaterial( material, fog, object ) {
  15227. var materialProperties = properties.get( material );
  15228. var parameters = programCache.getParameters( material, _lights, fog, object );
  15229. var code = programCache.getProgramCode( material, parameters );
  15230. var program = materialProperties.program;
  15231. var programChange = true;
  15232. if ( program === undefined ) {
  15233. // new material
  15234. material.addEventListener( 'dispose', onMaterialDispose );
  15235. } else if ( program.code !== code ) {
  15236. // changed glsl or parameters
  15237. releaseMaterialProgramReference( material );
  15238. } else if ( parameters.shaderID !== undefined ) {
  15239. // same glsl and uniform list
  15240. return;
  15241. } else {
  15242. // only rebuild uniform list
  15243. programChange = false;
  15244. }
  15245. if ( programChange ) {
  15246. if ( parameters.shaderID ) {
  15247. var shader = THREE.ShaderLib[ parameters.shaderID ];
  15248. materialProperties.__webglShader = {
  15249. name: material.type,
  15250. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  15251. vertexShader: shader.vertexShader,
  15252. fragmentShader: shader.fragmentShader
  15253. };
  15254. } else {
  15255. materialProperties.__webglShader = {
  15256. name: material.type,
  15257. uniforms: material.uniforms,
  15258. vertexShader: material.vertexShader,
  15259. fragmentShader: material.fragmentShader
  15260. };
  15261. }
  15262. material.__webglShader = materialProperties.__webglShader;
  15263. program = programCache.acquireProgram( material, parameters, code );
  15264. materialProperties.program = program;
  15265. material.program = program;
  15266. }
  15267. var attributes = program.getAttributes();
  15268. if ( material.morphTargets ) {
  15269. material.numSupportedMorphTargets = 0;
  15270. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15271. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  15272. material.numSupportedMorphTargets ++;
  15273. }
  15274. }
  15275. }
  15276. if ( material.morphNormals ) {
  15277. material.numSupportedMorphNormals = 0;
  15278. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  15279. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  15280. material.numSupportedMorphNormals ++;
  15281. }
  15282. }
  15283. }
  15284. materialProperties.uniformsList = [];
  15285. var uniforms = materialProperties.__webglShader.uniforms,
  15286. uniformLocations = materialProperties.program.getUniforms();
  15287. for ( var u in uniforms ) {
  15288. var location = uniformLocations[ u ];
  15289. if ( location ) {
  15290. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  15291. }
  15292. }
  15293. if ( material instanceof THREE.MeshPhongMaterial ||
  15294. material instanceof THREE.MeshLambertMaterial ||
  15295. material instanceof THREE.MeshStandardMaterial ||
  15296. material.lights ) {
  15297. // store the light setup it was created for
  15298. materialProperties.lightsHash = _lights.hash;
  15299. // wire up the material to this renderer's lighting state
  15300. uniforms.ambientLightColor.value = _lights.ambient;
  15301. uniforms.directionalLights.value = _lights.directional;
  15302. uniforms.spotLights.value = _lights.spot;
  15303. uniforms.pointLights.value = _lights.point;
  15304. uniforms.hemisphereLights.value = _lights.hemi;
  15305. uniforms.directionalShadowMap.value = _lights.directionalShadowMap;
  15306. uniforms.directionalShadowMatrix.value = _lights.directionalShadowMatrix;
  15307. uniforms.spotShadowMap.value = _lights.spotShadowMap;
  15308. uniforms.spotShadowMatrix.value = _lights.spotShadowMatrix;
  15309. uniforms.pointShadowMap.value = _lights.pointShadowMap;
  15310. uniforms.pointShadowMatrix.value = _lights.pointShadowMatrix;
  15311. }
  15312. // detect dynamic uniforms
  15313. materialProperties.hasDynamicUniforms = false;
  15314. for ( var j = 0, jl = materialProperties.uniformsList.length; j < jl; j ++ ) {
  15315. var uniform = materialProperties.uniformsList[ j ][ 0 ];
  15316. if ( uniform.dynamic === true ) {
  15317. materialProperties.hasDynamicUniforms = true;
  15318. break;
  15319. }
  15320. }
  15321. }
  15322. function setMaterial( material ) {
  15323. setMaterialFaces( material );
  15324. if ( material.transparent === true ) {
  15325. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  15326. } else {
  15327. state.setBlending( THREE.NoBlending );
  15328. }
  15329. state.setDepthFunc( material.depthFunc );
  15330. state.setDepthTest( material.depthTest );
  15331. state.setDepthWrite( material.depthWrite );
  15332. state.setColorWrite( material.colorWrite );
  15333. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  15334. }
  15335. function setMaterialFaces( material ) {
  15336. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  15337. state.setFlipSided( material.side === THREE.BackSide );
  15338. }
  15339. function setProgram( camera, fog, material, object ) {
  15340. _usedTextureUnits = 0;
  15341. var materialProperties = properties.get( material );
  15342. if ( materialProperties.program === undefined ) {
  15343. material.needsUpdate = true;
  15344. }
  15345. if ( materialProperties.lightsHash !== undefined &&
  15346. materialProperties.lightsHash !== _lights.hash ) {
  15347. material.needsUpdate = true;
  15348. }
  15349. if ( material.needsUpdate ) {
  15350. initMaterial( material, fog, object );
  15351. material.needsUpdate = false;
  15352. }
  15353. var refreshProgram = false;
  15354. var refreshMaterial = false;
  15355. var refreshLights = false;
  15356. var program = materialProperties.program,
  15357. p_uniforms = program.getUniforms(),
  15358. m_uniforms = materialProperties.__webglShader.uniforms;
  15359. if ( program.id !== _currentProgram ) {
  15360. _gl.useProgram( program.program );
  15361. _currentProgram = program.id;
  15362. refreshProgram = true;
  15363. refreshMaterial = true;
  15364. refreshLights = true;
  15365. }
  15366. if ( material.id !== _currentMaterialId ) {
  15367. _currentMaterialId = material.id;
  15368. refreshMaterial = true;
  15369. }
  15370. if ( refreshProgram || camera !== _currentCamera ) {
  15371. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  15372. if ( capabilities.logarithmicDepthBuffer ) {
  15373. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15374. }
  15375. if ( camera !== _currentCamera ) {
  15376. _currentCamera = camera;
  15377. // lighting uniforms depend on the camera so enforce an update
  15378. // now, in case this material supports lights - or later, when
  15379. // the next material that does gets activated:
  15380. refreshMaterial = true; // set to true on material change
  15381. refreshLights = true; // remains set until update done
  15382. }
  15383. // load material specific uniforms
  15384. // (shader material also gets them for the sake of genericity)
  15385. if ( material instanceof THREE.ShaderMaterial ||
  15386. material instanceof THREE.MeshPhongMaterial ||
  15387. material instanceof THREE.MeshStandardMaterial ||
  15388. material.envMap ) {
  15389. if ( p_uniforms.cameraPosition !== undefined ) {
  15390. _vector3.setFromMatrixPosition( camera.matrixWorld );
  15391. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  15392. }
  15393. }
  15394. if ( material instanceof THREE.MeshPhongMaterial ||
  15395. material instanceof THREE.MeshLambertMaterial ||
  15396. material instanceof THREE.MeshBasicMaterial ||
  15397. material instanceof THREE.MeshStandardMaterial ||
  15398. material instanceof THREE.ShaderMaterial ||
  15399. material.skinning ) {
  15400. if ( p_uniforms.viewMatrix !== undefined ) {
  15401. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  15402. }
  15403. }
  15404. if ( p_uniforms.toneMappingExposure !== undefined ) {
  15405. _gl.uniform1f( p_uniforms.toneMappingExposure, _this.toneMappingExposure );
  15406. }
  15407. if ( p_uniforms.toneMappingWhitePoint !== undefined ) {
  15408. _gl.uniform1f( p_uniforms.toneMappingWhitePoint, _this.toneMappingWhitePoint );
  15409. }
  15410. }
  15411. // skinning uniforms must be set even if material didn't change
  15412. // auto-setting of texture unit for bone texture must go before other textures
  15413. // not sure why, but otherwise weird things happen
  15414. if ( material.skinning ) {
  15415. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  15416. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  15417. }
  15418. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  15419. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  15420. }
  15421. if ( capabilities.floatVertexTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  15422. if ( p_uniforms.boneTexture !== undefined ) {
  15423. var textureUnit = getTextureUnit();
  15424. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  15425. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  15426. }
  15427. if ( p_uniforms.boneTextureWidth !== undefined ) {
  15428. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  15429. }
  15430. if ( p_uniforms.boneTextureHeight !== undefined ) {
  15431. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  15432. }
  15433. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  15434. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  15435. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  15436. }
  15437. }
  15438. }
  15439. if ( refreshMaterial ) {
  15440. if ( material instanceof THREE.MeshPhongMaterial ||
  15441. material instanceof THREE.MeshLambertMaterial ||
  15442. material instanceof THREE.MeshStandardMaterial ||
  15443. material.lights ) {
  15444. // the current material requires lighting info
  15445. // note: all lighting uniforms are always set correctly
  15446. // they simply reference the renderer's state for their
  15447. // values
  15448. //
  15449. // use the current material's .needsUpdate flags to set
  15450. // the GL state when required
  15451. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15452. }
  15453. // refresh uniforms common to several materials
  15454. if ( fog && material.fog ) {
  15455. refreshUniformsFog( m_uniforms, fog );
  15456. }
  15457. if ( material instanceof THREE.MeshBasicMaterial ||
  15458. material instanceof THREE.MeshLambertMaterial ||
  15459. material instanceof THREE.MeshPhongMaterial ||
  15460. material instanceof THREE.MeshStandardMaterial ) {
  15461. refreshUniformsCommon( m_uniforms, material );
  15462. }
  15463. // refresh single material specific uniforms
  15464. if ( material instanceof THREE.LineBasicMaterial ) {
  15465. refreshUniformsLine( m_uniforms, material );
  15466. } else if ( material instanceof THREE.LineDashedMaterial ) {
  15467. refreshUniformsLine( m_uniforms, material );
  15468. refreshUniformsDash( m_uniforms, material );
  15469. } else if ( material instanceof THREE.PointsMaterial ) {
  15470. refreshUniformsPoints( m_uniforms, material );
  15471. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  15472. refreshUniformsLambert( m_uniforms, material );
  15473. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  15474. refreshUniformsPhong( m_uniforms, material );
  15475. } else if ( material instanceof THREE.MeshStandardMaterial ) {
  15476. refreshUniformsStandard( m_uniforms, material );
  15477. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  15478. m_uniforms.mNear.value = camera.near;
  15479. m_uniforms.mFar.value = camera.far;
  15480. m_uniforms.opacity.value = material.opacity;
  15481. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  15482. m_uniforms.opacity.value = material.opacity;
  15483. }
  15484. // load common uniforms
  15485. loadUniformsGeneric( materialProperties.uniformsList );
  15486. }
  15487. loadUniformsMatrices( p_uniforms, object );
  15488. if ( p_uniforms.modelMatrix !== undefined ) {
  15489. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  15490. }
  15491. if ( materialProperties.hasDynamicUniforms === true ) {
  15492. updateDynamicUniforms( materialProperties.uniformsList, object, camera );
  15493. }
  15494. return program;
  15495. }
  15496. function updateDynamicUniforms ( uniforms, object, camera ) {
  15497. var dynamicUniforms = [];
  15498. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  15499. var uniform = uniforms[ j ][ 0 ];
  15500. var onUpdateCallback = uniform.onUpdateCallback;
  15501. if ( onUpdateCallback !== undefined ) {
  15502. onUpdateCallback.bind( uniform )( object, camera );
  15503. dynamicUniforms.push( uniforms[ j ] );
  15504. }
  15505. }
  15506. loadUniformsGeneric( dynamicUniforms );
  15507. }
  15508. // Uniforms (refresh uniforms objects)
  15509. function refreshUniformsCommon ( uniforms, material ) {
  15510. uniforms.opacity.value = material.opacity;
  15511. uniforms.diffuse.value = material.color;
  15512. if ( material.emissive ) {
  15513. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  15514. }
  15515. uniforms.map.value = material.map;
  15516. uniforms.specularMap.value = material.specularMap;
  15517. uniforms.alphaMap.value = material.alphaMap;
  15518. if ( material.aoMap ) {
  15519. uniforms.aoMap.value = material.aoMap;
  15520. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  15521. }
  15522. // uv repeat and offset setting priorities
  15523. // 1. color map
  15524. // 2. specular map
  15525. // 3. normal map
  15526. // 4. bump map
  15527. // 5. alpha map
  15528. // 6. emissive map
  15529. var uvScaleMap;
  15530. if ( material.map ) {
  15531. uvScaleMap = material.map;
  15532. } else if ( material.specularMap ) {
  15533. uvScaleMap = material.specularMap;
  15534. } else if ( material.displacementMap ) {
  15535. uvScaleMap = material.displacementMap;
  15536. } else if ( material.normalMap ) {
  15537. uvScaleMap = material.normalMap;
  15538. } else if ( material.bumpMap ) {
  15539. uvScaleMap = material.bumpMap;
  15540. } else if ( material.roughnessMap ) {
  15541. uvScaleMap = material.roughnessMap;
  15542. } else if ( material.metalnessMap ) {
  15543. uvScaleMap = material.metalnessMap;
  15544. } else if ( material.alphaMap ) {
  15545. uvScaleMap = material.alphaMap;
  15546. } else if ( material.emissiveMap ) {
  15547. uvScaleMap = material.emissiveMap;
  15548. }
  15549. if ( uvScaleMap !== undefined ) {
  15550. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) {
  15551. uvScaleMap = uvScaleMap.texture;
  15552. }
  15553. var offset = uvScaleMap.offset;
  15554. var repeat = uvScaleMap.repeat;
  15555. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15556. }
  15557. uniforms.envMap.value = material.envMap;
  15558. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  15559. uniforms.reflectivity.value = material.reflectivity;
  15560. uniforms.refractionRatio.value = material.refractionRatio;
  15561. }
  15562. function refreshUniformsLine ( uniforms, material ) {
  15563. uniforms.diffuse.value = material.color;
  15564. uniforms.opacity.value = material.opacity;
  15565. }
  15566. function refreshUniformsDash ( uniforms, material ) {
  15567. uniforms.dashSize.value = material.dashSize;
  15568. uniforms.totalSize.value = material.dashSize + material.gapSize;
  15569. uniforms.scale.value = material.scale;
  15570. }
  15571. function refreshUniformsPoints ( uniforms, material ) {
  15572. uniforms.diffuse.value = material.color;
  15573. uniforms.opacity.value = material.opacity;
  15574. uniforms.size.value = material.size * _pixelRatio;
  15575. uniforms.scale.value = _canvas.clientHeight / 2.0; // TODO: Cache this.
  15576. uniforms.map.value = material.map;
  15577. if ( material.map !== null ) {
  15578. var offset = material.map.offset;
  15579. var repeat = material.map.repeat;
  15580. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15581. }
  15582. }
  15583. function refreshUniformsFog ( uniforms, fog ) {
  15584. uniforms.fogColor.value = fog.color;
  15585. if ( fog instanceof THREE.Fog ) {
  15586. uniforms.fogNear.value = fog.near;
  15587. uniforms.fogFar.value = fog.far;
  15588. } else if ( fog instanceof THREE.FogExp2 ) {
  15589. uniforms.fogDensity.value = fog.density;
  15590. }
  15591. }
  15592. function refreshUniformsLambert ( uniforms, material ) {
  15593. if ( material.lightMap ) {
  15594. uniforms.lightMap.value = material.lightMap;
  15595. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15596. }
  15597. if ( material.emissiveMap ) {
  15598. uniforms.emissiveMap.value = material.emissiveMap;
  15599. }
  15600. }
  15601. function refreshUniformsPhong ( uniforms, material ) {
  15602. uniforms.specular.value = material.specular;
  15603. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  15604. if ( material.lightMap ) {
  15605. uniforms.lightMap.value = material.lightMap;
  15606. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15607. }
  15608. if ( material.emissiveMap ) {
  15609. uniforms.emissiveMap.value = material.emissiveMap;
  15610. }
  15611. if ( material.bumpMap ) {
  15612. uniforms.bumpMap.value = material.bumpMap;
  15613. uniforms.bumpScale.value = material.bumpScale;
  15614. }
  15615. if ( material.normalMap ) {
  15616. uniforms.normalMap.value = material.normalMap;
  15617. uniforms.normalScale.value.copy( material.normalScale );
  15618. }
  15619. if ( material.displacementMap ) {
  15620. uniforms.displacementMap.value = material.displacementMap;
  15621. uniforms.displacementScale.value = material.displacementScale;
  15622. uniforms.displacementBias.value = material.displacementBias;
  15623. }
  15624. }
  15625. function refreshUniformsStandard ( uniforms, material ) {
  15626. uniforms.roughness.value = material.roughness;
  15627. uniforms.metalness.value = material.metalness;
  15628. if ( material.roughnessMap ) {
  15629. uniforms.roughnessMap.value = material.roughnessMap;
  15630. }
  15631. if ( material.metalnessMap ) {
  15632. uniforms.metalnessMap.value = material.metalnessMap;
  15633. }
  15634. if ( material.lightMap ) {
  15635. uniforms.lightMap.value = material.lightMap;
  15636. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15637. }
  15638. if ( material.emissiveMap ) {
  15639. uniforms.emissiveMap.value = material.emissiveMap;
  15640. }
  15641. if ( material.bumpMap ) {
  15642. uniforms.bumpMap.value = material.bumpMap;
  15643. uniforms.bumpScale.value = material.bumpScale;
  15644. }
  15645. if ( material.normalMap ) {
  15646. uniforms.normalMap.value = material.normalMap;
  15647. uniforms.normalScale.value.copy( material.normalScale );
  15648. }
  15649. if ( material.displacementMap ) {
  15650. uniforms.displacementMap.value = material.displacementMap;
  15651. uniforms.displacementScale.value = material.displacementScale;
  15652. uniforms.displacementBias.value = material.displacementBias;
  15653. }
  15654. if ( material.envMap ) {
  15655. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15656. uniforms.envMapIntensity.value = material.envMapIntensity;
  15657. }
  15658. }
  15659. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15660. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  15661. uniforms.ambientLightColor.needsUpdate = value;
  15662. uniforms.directionalLights.needsUpdate = value;
  15663. uniforms.pointLights.needsUpdate = value;
  15664. uniforms.spotLights.needsUpdate = value;
  15665. uniforms.hemisphereLights.needsUpdate = value;
  15666. }
  15667. // Uniforms (load to GPU)
  15668. function loadUniformsMatrices ( uniforms, object ) {
  15669. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object.modelViewMatrix.elements );
  15670. if ( uniforms.normalMatrix ) {
  15671. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object.normalMatrix.elements );
  15672. }
  15673. }
  15674. function getTextureUnit() {
  15675. var textureUnit = _usedTextureUnits;
  15676. if ( textureUnit >= capabilities.maxTextures ) {
  15677. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  15678. }
  15679. _usedTextureUnits += 1;
  15680. return textureUnit;
  15681. }
  15682. function loadUniform( uniform, type, location, value ) {
  15683. var texture, textureUnit;
  15684. if ( type === '1i' ) {
  15685. _gl.uniform1i( location, value );
  15686. } else if ( type === '1f' ) {
  15687. _gl.uniform1f( location, value );
  15688. } else if ( type === '2f' ) {
  15689. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  15690. } else if ( type === '3f' ) {
  15691. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  15692. } else if ( type === '4f' ) {
  15693. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  15694. } else if ( type === '1iv' ) {
  15695. _gl.uniform1iv( location, value );
  15696. } else if ( type === '3iv' ) {
  15697. _gl.uniform3iv( location, value );
  15698. } else if ( type === '1fv' ) {
  15699. _gl.uniform1fv( location, value );
  15700. } else if ( type === '2fv' ) {
  15701. _gl.uniform2fv( location, value );
  15702. } else if ( type === '3fv' ) {
  15703. _gl.uniform3fv( location, value );
  15704. } else if ( type === '4fv' ) {
  15705. _gl.uniform4fv( location, value );
  15706. } else if ( type === 'Matrix2fv' ) {
  15707. _gl.uniformMatrix2fv( location, false, value );
  15708. } else if ( type === 'Matrix3fv' ) {
  15709. _gl.uniformMatrix3fv( location, false, value );
  15710. } else if ( type === 'Matrix4fv' ) {
  15711. _gl.uniformMatrix4fv( location, false, value );
  15712. //
  15713. } else if ( type === 'i' ) {
  15714. // single integer
  15715. _gl.uniform1i( location, value );
  15716. } else if ( type === 'f' ) {
  15717. // single float
  15718. _gl.uniform1f( location, value );
  15719. } else if ( type === 'v2' ) {
  15720. // single THREE.Vector2
  15721. _gl.uniform2f( location, value.x, value.y );
  15722. } else if ( type === 'v3' ) {
  15723. // single THREE.Vector3
  15724. _gl.uniform3f( location, value.x, value.y, value.z );
  15725. } else if ( type === 'v4' ) {
  15726. // single THREE.Vector4
  15727. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  15728. } else if ( type === 'c' ) {
  15729. // single THREE.Color
  15730. _gl.uniform3f( location, value.r, value.g, value.b );
  15731. } else if ( type === 's' ) {
  15732. // TODO: Optimize this
  15733. var properties = uniform.properties;
  15734. for ( var name in properties ) {
  15735. var property = properties[ name ];
  15736. var locationProperty = location[ name ];
  15737. var valueProperty = value[ name ];
  15738. loadUniform( property, property.type, locationProperty, valueProperty );
  15739. }
  15740. } else if ( type === 'sa' ) {
  15741. // TODO: Optimize this
  15742. var properties = uniform.properties;
  15743. for ( var i = 0, l = value.length; i < l; i ++ ) {
  15744. for ( var name in properties ) {
  15745. var property = properties[ name ];
  15746. var locationProperty = location[ i ][ name ];
  15747. var valueProperty = value[ i ][ name ];
  15748. loadUniform( property, property.type, locationProperty, valueProperty );
  15749. }
  15750. }
  15751. } else if ( type === 'iv1' ) {
  15752. // flat array of integers (JS or typed array)
  15753. _gl.uniform1iv( location, value );
  15754. } else if ( type === 'iv' ) {
  15755. // flat array of integers with 3 x N size (JS or typed array)
  15756. _gl.uniform3iv( location, value );
  15757. } else if ( type === 'fv1' ) {
  15758. // flat array of floats (JS or typed array)
  15759. _gl.uniform1fv( location, value );
  15760. } else if ( type === 'fv' ) {
  15761. // flat array of floats with 3 x N size (JS or typed array)
  15762. _gl.uniform3fv( location, value );
  15763. } else if ( type === 'v2v' ) {
  15764. // array of THREE.Vector2
  15765. if ( uniform._array === undefined ) {
  15766. uniform._array = new Float32Array( 2 * value.length );
  15767. }
  15768. for ( var i = 0, i2 = 0, il = value.length; i < il; i ++, i2 += 2 ) {
  15769. uniform._array[ i2 + 0 ] = value[ i ].x;
  15770. uniform._array[ i2 + 1 ] = value[ i ].y;
  15771. }
  15772. _gl.uniform2fv( location, uniform._array );
  15773. } else if ( type === 'v3v' ) {
  15774. // array of THREE.Vector3
  15775. if ( uniform._array === undefined ) {
  15776. uniform._array = new Float32Array( 3 * value.length );
  15777. }
  15778. for ( var i = 0, i3 = 0, il = value.length; i < il; i ++, i3 += 3 ) {
  15779. uniform._array[ i3 + 0 ] = value[ i ].x;
  15780. uniform._array[ i3 + 1 ] = value[ i ].y;
  15781. uniform._array[ i3 + 2 ] = value[ i ].z;
  15782. }
  15783. _gl.uniform3fv( location, uniform._array );
  15784. } else if ( type === 'v4v' ) {
  15785. // array of THREE.Vector4
  15786. if ( uniform._array === undefined ) {
  15787. uniform._array = new Float32Array( 4 * value.length );
  15788. }
  15789. for ( var i = 0, i4 = 0, il = value.length; i < il; i ++, i4 += 4 ) {
  15790. uniform._array[ i4 + 0 ] = value[ i ].x;
  15791. uniform._array[ i4 + 1 ] = value[ i ].y;
  15792. uniform._array[ i4 + 2 ] = value[ i ].z;
  15793. uniform._array[ i4 + 3 ] = value[ i ].w;
  15794. }
  15795. _gl.uniform4fv( location, uniform._array );
  15796. } else if ( type === 'm2' ) {
  15797. // single THREE.Matrix2
  15798. _gl.uniformMatrix2fv( location, false, value.elements );
  15799. } else if ( type === 'm3' ) {
  15800. // single THREE.Matrix3
  15801. _gl.uniformMatrix3fv( location, false, value.elements );
  15802. } else if ( type === 'm3v' ) {
  15803. // array of THREE.Matrix3
  15804. if ( uniform._array === undefined ) {
  15805. uniform._array = new Float32Array( 9 * value.length );
  15806. }
  15807. for ( var i = 0, il = value.length; i < il; i ++ ) {
  15808. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  15809. }
  15810. _gl.uniformMatrix3fv( location, false, uniform._array );
  15811. } else if ( type === 'm4' ) {
  15812. // single THREE.Matrix4
  15813. _gl.uniformMatrix4fv( location, false, value.elements );
  15814. } else if ( type === 'm4v' ) {
  15815. // array of THREE.Matrix4
  15816. if ( uniform._array === undefined ) {
  15817. uniform._array = new Float32Array( 16 * value.length );
  15818. }
  15819. for ( var i = 0, il = value.length; i < il; i ++ ) {
  15820. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  15821. }
  15822. _gl.uniformMatrix4fv( location, false, uniform._array );
  15823. } else if ( type === 't' ) {
  15824. // single THREE.Texture (2d or cube)
  15825. texture = value;
  15826. textureUnit = getTextureUnit();
  15827. _gl.uniform1i( location, textureUnit );
  15828. if ( ! texture ) return;
  15829. if ( texture instanceof THREE.CubeTexture ||
  15830. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  15831. // CompressedTexture can have Array in image :/
  15832. setCubeTexture( texture, textureUnit );
  15833. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  15834. setCubeTextureDynamic( texture.texture, textureUnit );
  15835. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  15836. _this.setTexture( texture.texture, textureUnit );
  15837. } else {
  15838. _this.setTexture( texture, textureUnit );
  15839. }
  15840. } else if ( type === 'tv' ) {
  15841. // array of THREE.Texture (2d or cube)
  15842. if ( uniform._array === undefined ) {
  15843. uniform._array = [];
  15844. }
  15845. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  15846. uniform._array[ i ] = getTextureUnit();
  15847. }
  15848. _gl.uniform1iv( location, uniform._array );
  15849. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  15850. texture = uniform.value[ i ];
  15851. textureUnit = uniform._array[ i ];
  15852. if ( ! texture ) continue;
  15853. if ( texture instanceof THREE.CubeTexture ||
  15854. ( texture.image instanceof Array && texture.image.length === 6 ) ) {
  15855. // CompressedTexture can have Array in image :/
  15856. setCubeTexture( texture, textureUnit );
  15857. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  15858. _this.setTexture( texture.texture, textureUnit );
  15859. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  15860. setCubeTextureDynamic( texture.texture, textureUnit );
  15861. } else {
  15862. _this.setTexture( texture, textureUnit );
  15863. }
  15864. }
  15865. } else {
  15866. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  15867. }
  15868. }
  15869. function loadUniformsGeneric( uniforms ) {
  15870. for ( var i = 0, l = uniforms.length; i < l; i ++ ) {
  15871. var uniform = uniforms[ i ][ 0 ];
  15872. // needsUpdate property is not added to all uniforms.
  15873. if ( uniform.needsUpdate === false ) continue;
  15874. var type = uniform.type;
  15875. var location = uniforms[ i ][ 1 ];
  15876. var value = uniform.value;
  15877. loadUniform( uniform, type, location, value );
  15878. }
  15879. }
  15880. function setupLights ( lights, camera ) {
  15881. var l, ll, light,
  15882. r = 0, g = 0, b = 0,
  15883. color,
  15884. intensity,
  15885. distance,
  15886. viewMatrix = camera.matrixWorldInverse,
  15887. directionalLength = 0,
  15888. pointLength = 0,
  15889. spotLength = 0,
  15890. hemiLength = 0,
  15891. shadowsLength = 0;
  15892. _lights.shadowsPointLight = 0;
  15893. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  15894. light = lights[ l ];
  15895. color = light.color;
  15896. intensity = light.intensity;
  15897. distance = light.distance;
  15898. if ( light instanceof THREE.AmbientLight ) {
  15899. r += color.r * intensity;
  15900. g += color.g * intensity;
  15901. b += color.b * intensity;
  15902. } else if ( light instanceof THREE.DirectionalLight ) {
  15903. var uniforms = lightCache.get( light );
  15904. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  15905. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  15906. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  15907. uniforms.direction.sub( _vector3 );
  15908. uniforms.direction.transformDirection( viewMatrix );
  15909. uniforms.shadow = light.castShadow;
  15910. if ( light.castShadow ) {
  15911. uniforms.shadowBias = light.shadow.bias;
  15912. uniforms.shadowRadius = light.shadow.radius;
  15913. uniforms.shadowMapSize = light.shadow.mapSize;
  15914. _lights.shadows[ shadowsLength ++ ] = light;
  15915. }
  15916. _lights.directionalShadowMap[ directionalLength ] = light.shadow.map;
  15917. _lights.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  15918. _lights.directional[ directionalLength ++ ] = uniforms;
  15919. } else if ( light instanceof THREE.SpotLight ) {
  15920. var uniforms = lightCache.get( light );
  15921. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  15922. uniforms.position.applyMatrix4( viewMatrix );
  15923. uniforms.color.copy( color ).multiplyScalar( intensity );
  15924. uniforms.distance = distance;
  15925. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  15926. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  15927. uniforms.direction.sub( _vector3 );
  15928. uniforms.direction.transformDirection( viewMatrix );
  15929. uniforms.coneCos = Math.cos( light.angle );
  15930. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  15931. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  15932. uniforms.shadow = light.castShadow;
  15933. if ( light.castShadow ) {
  15934. uniforms.shadowBias = light.shadow.bias;
  15935. uniforms.shadowRadius = light.shadow.radius;
  15936. uniforms.shadowMapSize = light.shadow.mapSize;
  15937. _lights.shadows[ shadowsLength ++ ] = light;
  15938. }
  15939. _lights.spotShadowMap[ spotLength ] = light.shadow.map;
  15940. _lights.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  15941. _lights.spot[ spotLength ++ ] = uniforms;
  15942. } else if ( light instanceof THREE.PointLight ) {
  15943. var uniforms = lightCache.get( light );
  15944. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  15945. uniforms.position.applyMatrix4( viewMatrix );
  15946. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  15947. uniforms.distance = light.distance;
  15948. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  15949. uniforms.shadow = light.castShadow;
  15950. if ( light.castShadow ) {
  15951. uniforms.shadowBias = light.shadow.bias;
  15952. uniforms.shadowRadius = light.shadow.radius;
  15953. uniforms.shadowMapSize = light.shadow.mapSize;
  15954. _lights.shadows[ shadowsLength ++ ] = light;
  15955. }
  15956. _lights.pointShadowMap[ pointLength ] = light.shadow.map;
  15957. if ( _lights.pointShadowMatrix[ pointLength ] === undefined ) {
  15958. _lights.pointShadowMatrix[ pointLength ] = new THREE.Matrix4();
  15959. }
  15960. // for point lights we set the shadow matrix to be a translation-only matrix
  15961. // equal to inverse of the light's position
  15962. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  15963. _lights.pointShadowMatrix[ pointLength ].identity().setPosition( _vector3 );
  15964. _lights.point[ pointLength ++ ] = uniforms;
  15965. } else if ( light instanceof THREE.HemisphereLight ) {
  15966. var uniforms = lightCache.get( light );
  15967. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  15968. uniforms.direction.transformDirection( viewMatrix );
  15969. uniforms.direction.normalize();
  15970. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  15971. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  15972. _lights.hemi[ hemiLength ++ ] = uniforms;
  15973. }
  15974. }
  15975. _lights.ambient[ 0 ] = r;
  15976. _lights.ambient[ 1 ] = g;
  15977. _lights.ambient[ 2 ] = b;
  15978. _lights.directional.length = directionalLength;
  15979. _lights.spot.length = spotLength;
  15980. _lights.point.length = pointLength;
  15981. _lights.hemi.length = hemiLength;
  15982. _lights.shadows.length = shadowsLength;
  15983. _lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + hemiLength + ',' + shadowsLength;
  15984. }
  15985. // GL state setting
  15986. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  15987. if ( cullFace === THREE.CullFaceNone ) {
  15988. state.disable( _gl.CULL_FACE );
  15989. } else {
  15990. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  15991. _gl.frontFace( _gl.CW );
  15992. } else {
  15993. _gl.frontFace( _gl.CCW );
  15994. }
  15995. if ( cullFace === THREE.CullFaceBack ) {
  15996. _gl.cullFace( _gl.BACK );
  15997. } else if ( cullFace === THREE.CullFaceFront ) {
  15998. _gl.cullFace( _gl.FRONT );
  15999. } else {
  16000. _gl.cullFace( _gl.FRONT_AND_BACK );
  16001. }
  16002. state.enable( _gl.CULL_FACE );
  16003. }
  16004. };
  16005. // Textures
  16006. function setTextureParameters ( textureType, texture, isPowerOfTwoImage ) {
  16007. var extension;
  16008. if ( isPowerOfTwoImage ) {
  16009. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  16010. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  16011. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  16012. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  16013. } else {
  16014. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  16015. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  16016. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  16017. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  16018. }
  16019. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  16020. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  16021. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  16022. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  16023. }
  16024. }
  16025. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  16026. if ( extension ) {
  16027. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  16028. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  16029. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  16030. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  16031. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  16032. }
  16033. }
  16034. }
  16035. function uploadTexture( textureProperties, texture, slot ) {
  16036. if ( textureProperties.__webglInit === undefined ) {
  16037. textureProperties.__webglInit = true;
  16038. texture.addEventListener( 'dispose', onTextureDispose );
  16039. textureProperties.__webglTexture = _gl.createTexture();
  16040. _infoMemory.textures ++;
  16041. }
  16042. state.activeTexture( _gl.TEXTURE0 + slot );
  16043. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16044. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16045. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  16046. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  16047. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  16048. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  16049. image = makePowerOfTwo( image );
  16050. }
  16051. var isPowerOfTwoImage = isPowerOfTwo( image ),
  16052. glFormat = paramThreeToGL( texture.format ),
  16053. glType = paramThreeToGL( texture.type );
  16054. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  16055. var mipmap, mipmaps = texture.mipmaps;
  16056. if ( texture instanceof THREE.DataTexture ) {
  16057. // use manually created mipmaps if available
  16058. // if there are no manual mipmaps
  16059. // set 0 level mipmap and then use GL to generate other mipmap levels
  16060. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  16061. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16062. mipmap = mipmaps[ i ];
  16063. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16064. }
  16065. texture.generateMipmaps = false;
  16066. } else {
  16067. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  16068. }
  16069. } else if ( texture instanceof THREE.CompressedTexture ) {
  16070. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16071. mipmap = mipmaps[ i ];
  16072. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16073. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16074. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16075. } else {
  16076. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  16077. }
  16078. } else {
  16079. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16080. }
  16081. }
  16082. } else {
  16083. // regular Texture (image, video, canvas)
  16084. // use manually created mipmaps if available
  16085. // if there are no manual mipmaps
  16086. // set 0 level mipmap and then use GL to generate other mipmap levels
  16087. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  16088. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16089. mipmap = mipmaps[ i ];
  16090. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  16091. }
  16092. texture.generateMipmaps = false;
  16093. } else {
  16094. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  16095. }
  16096. }
  16097. if ( texture.generateMipmaps && isPowerOfTwoImage ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16098. textureProperties.__version = texture.version;
  16099. if ( texture.onUpdate ) texture.onUpdate( texture );
  16100. }
  16101. this.setTexture = function ( texture, slot ) {
  16102. var textureProperties = properties.get( texture );
  16103. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16104. var image = texture.image;
  16105. if ( image === undefined ) {
  16106. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  16107. return;
  16108. }
  16109. if ( image.complete === false ) {
  16110. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  16111. return;
  16112. }
  16113. uploadTexture( textureProperties, texture, slot );
  16114. return;
  16115. }
  16116. state.activeTexture( _gl.TEXTURE0 + slot );
  16117. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16118. };
  16119. function clampToMaxSize ( image, maxSize ) {
  16120. if ( image.width > maxSize || image.height > maxSize ) {
  16121. // Warning: Scaling through the canvas will only work with images that use
  16122. // premultiplied alpha.
  16123. var scale = maxSize / Math.max( image.width, image.height );
  16124. var canvas = document.createElement( 'canvas' );
  16125. canvas.width = Math.floor( image.width * scale );
  16126. canvas.height = Math.floor( image.height * scale );
  16127. var context = canvas.getContext( '2d' );
  16128. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  16129. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16130. return canvas;
  16131. }
  16132. return image;
  16133. }
  16134. function isPowerOfTwo( image ) {
  16135. return THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height );
  16136. }
  16137. function textureNeedsPowerOfTwo( texture ) {
  16138. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) return true;
  16139. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) return true;
  16140. return false;
  16141. }
  16142. function makePowerOfTwo( image ) {
  16143. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  16144. var canvas = document.createElement( 'canvas' );
  16145. canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
  16146. canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
  16147. var context = canvas.getContext( '2d' );
  16148. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  16149. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16150. return canvas;
  16151. }
  16152. return image;
  16153. }
  16154. function setCubeTexture ( texture, slot ) {
  16155. var textureProperties = properties.get( texture );
  16156. if ( texture.image.length === 6 ) {
  16157. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16158. if ( ! textureProperties.__image__webglTextureCube ) {
  16159. texture.addEventListener( 'dispose', onTextureDispose );
  16160. textureProperties.__image__webglTextureCube = _gl.createTexture();
  16161. _infoMemory.textures ++;
  16162. }
  16163. state.activeTexture( _gl.TEXTURE0 + slot );
  16164. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16165. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16166. var isCompressed = texture instanceof THREE.CompressedTexture;
  16167. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  16168. var cubeImage = [];
  16169. for ( var i = 0; i < 6; i ++ ) {
  16170. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  16171. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  16172. } else {
  16173. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  16174. }
  16175. }
  16176. var image = cubeImage[ 0 ],
  16177. isPowerOfTwoImage = isPowerOfTwo( image ),
  16178. glFormat = paramThreeToGL( texture.format ),
  16179. glType = paramThreeToGL( texture.type );
  16180. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  16181. for ( var i = 0; i < 6; i ++ ) {
  16182. if ( ! isCompressed ) {
  16183. if ( isDataTexture ) {
  16184. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  16185. } else {
  16186. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  16187. }
  16188. } else {
  16189. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  16190. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  16191. mipmap = mipmaps[ j ];
  16192. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16193. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16194. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16195. } else {
  16196. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  16197. }
  16198. } else {
  16199. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16200. }
  16201. }
  16202. }
  16203. }
  16204. if ( texture.generateMipmaps && isPowerOfTwoImage ) {
  16205. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16206. }
  16207. textureProperties.__version = texture.version;
  16208. if ( texture.onUpdate ) texture.onUpdate( texture );
  16209. } else {
  16210. state.activeTexture( _gl.TEXTURE0 + slot );
  16211. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16212. }
  16213. }
  16214. }
  16215. function setCubeTextureDynamic ( texture, slot ) {
  16216. state.activeTexture( _gl.TEXTURE0 + slot );
  16217. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  16218. }
  16219. // Render targets
  16220. // Setup storage for target texture and bind it to correct framebuffer
  16221. function setupFrameBufferTexture ( framebuffer, renderTarget, attachment, textureTarget ) {
  16222. var glFormat = paramThreeToGL( renderTarget.texture.format );
  16223. var glType = paramThreeToGL( renderTarget.texture.type );
  16224. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  16225. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16226. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  16227. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16228. }
  16229. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  16230. function setupRenderBufferStorage ( renderbuffer, renderTarget ) {
  16231. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  16232. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  16233. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  16234. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16235. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  16236. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  16237. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16238. } else {
  16239. // FIXME: We don't support !depth !stencil
  16240. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  16241. }
  16242. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  16243. }
  16244. // Setup GL resources for a non-texture depth buffer
  16245. function setupDepthRenderbuffer( renderTarget ) {
  16246. var renderTargetProperties = properties.get( renderTarget );
  16247. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16248. if ( isCube ) {
  16249. renderTargetProperties.__webglDepthbuffer = [];
  16250. for ( var i = 0; i < 6; i ++ ) {
  16251. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  16252. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  16253. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  16254. }
  16255. } else {
  16256. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  16257. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  16258. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  16259. }
  16260. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16261. }
  16262. // Set up GL resources for the render target
  16263. function setupRenderTarget( renderTarget ) {
  16264. var renderTargetProperties = properties.get( renderTarget );
  16265. var textureProperties = properties.get( renderTarget.texture );
  16266. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  16267. textureProperties.__webglTexture = _gl.createTexture();
  16268. _infoMemory.textures ++;
  16269. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16270. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height );
  16271. // Setup framebuffer
  16272. if ( isCube ) {
  16273. renderTargetProperties.__webglFramebuffer = [];
  16274. for ( var i = 0; i < 6; i ++ ) {
  16275. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  16276. }
  16277. } else {
  16278. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  16279. }
  16280. // Setup color buffer
  16281. if ( isCube ) {
  16282. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  16283. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  16284. for ( var i = 0; i < 6; i ++ ) {
  16285. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  16286. }
  16287. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16288. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  16289. } else {
  16290. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16291. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  16292. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  16293. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16294. state.bindTexture( _gl.TEXTURE_2D, null );
  16295. }
  16296. // Setup depth and stencil buffers
  16297. if ( renderTarget.depthBuffer ) {
  16298. setupDepthRenderbuffer( renderTarget );
  16299. }
  16300. }
  16301. this.getCurrentRenderTarget = function() {
  16302. return _currentRenderTarget;
  16303. }
  16304. this.setRenderTarget = function ( renderTarget ) {
  16305. _currentRenderTarget = renderTarget;
  16306. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  16307. setupRenderTarget( renderTarget );
  16308. }
  16309. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16310. var framebuffer;
  16311. if ( renderTarget ) {
  16312. var renderTargetProperties = properties.get( renderTarget );
  16313. if ( isCube ) {
  16314. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  16315. } else {
  16316. framebuffer = renderTargetProperties.__webglFramebuffer;
  16317. }
  16318. _currentScissor.copy( renderTarget.scissor );
  16319. _currentScissorTest = renderTarget.scissorTest;
  16320. _currentViewport.copy( renderTarget.viewport );
  16321. } else {
  16322. framebuffer = null;
  16323. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  16324. _currentScissorTest = _scissorTest;
  16325. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  16326. }
  16327. if ( _currentFramebuffer !== framebuffer ) {
  16328. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16329. _currentFramebuffer = framebuffer;
  16330. }
  16331. state.scissor( _currentScissor );
  16332. state.setScissorTest( _currentScissorTest );
  16333. state.viewport( _currentViewport );
  16334. if ( isCube ) {
  16335. var textureProperties = properties.get( renderTarget.texture );
  16336. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  16337. }
  16338. };
  16339. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  16340. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  16341. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  16342. return;
  16343. }
  16344. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16345. if ( framebuffer ) {
  16346. var restore = false;
  16347. if ( framebuffer !== _currentFramebuffer ) {
  16348. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16349. restore = true;
  16350. }
  16351. try {
  16352. var texture = renderTarget.texture;
  16353. if ( texture.format !== THREE.RGBAFormat
  16354. && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  16355. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  16356. return;
  16357. }
  16358. if ( texture.type !== THREE.UnsignedByteType
  16359. && paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE )
  16360. && ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) )
  16361. && ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  16362. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  16363. return;
  16364. }
  16365. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  16366. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  16367. } else {
  16368. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  16369. }
  16370. } finally {
  16371. if ( restore ) {
  16372. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  16373. }
  16374. }
  16375. }
  16376. };
  16377. function updateRenderTargetMipmap( renderTarget ) {
  16378. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  16379. var texture = properties.get( renderTarget.texture ).__webglTexture;
  16380. state.bindTexture( target, texture );
  16381. _gl.generateMipmap( target );
  16382. state.bindTexture( target, null );
  16383. }
  16384. // Fallback filters for non-power-of-2 textures
  16385. function filterFallback ( f ) {
  16386. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  16387. return _gl.NEAREST;
  16388. }
  16389. return _gl.LINEAR;
  16390. }
  16391. // Map three.js constants to WebGL constants
  16392. function paramThreeToGL ( p ) {
  16393. var extension;
  16394. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  16395. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  16396. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  16397. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  16398. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  16399. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  16400. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  16401. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  16402. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  16403. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  16404. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  16405. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  16406. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  16407. if ( p === THREE.ByteType ) return _gl.BYTE;
  16408. if ( p === THREE.ShortType ) return _gl.SHORT;
  16409. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  16410. if ( p === THREE.IntType ) return _gl.INT;
  16411. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  16412. if ( p === THREE.FloatType ) return _gl.FLOAT;
  16413. extension = extensions.get( 'OES_texture_half_float' );
  16414. if ( extension !== null ) {
  16415. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  16416. }
  16417. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  16418. if ( p === THREE.RGBFormat ) return _gl.RGB;
  16419. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  16420. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  16421. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  16422. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  16423. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  16424. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  16425. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  16426. if ( p === THREE.OneFactor ) return _gl.ONE;
  16427. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  16428. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  16429. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  16430. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  16431. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  16432. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  16433. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  16434. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  16435. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  16436. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  16437. if ( extension !== null ) {
  16438. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  16439. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  16440. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  16441. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  16442. }
  16443. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  16444. if ( extension !== null ) {
  16445. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  16446. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  16447. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  16448. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  16449. }
  16450. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  16451. if ( extension !== null ) {
  16452. if ( p === THREE.RGB_ETC1_Format ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  16453. }
  16454. extension = extensions.get( 'EXT_blend_minmax' );
  16455. if ( extension !== null ) {
  16456. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  16457. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  16458. }
  16459. return 0;
  16460. }
  16461. };
  16462. // File:src/renderers/WebGLRenderTarget.js
  16463. /**
  16464. * @author szimek / https://github.com/szimek/
  16465. * @author alteredq / http://alteredqualia.com/
  16466. * @author Marius Kintel / https://github.com/kintel
  16467. */
  16468. /*
  16469. In options, we can specify:
  16470. * Texture parameters for an auto-generated target texture
  16471. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  16472. */
  16473. THREE.WebGLRenderTarget = function ( width, height, options ) {
  16474. this.uuid = THREE.Math.generateUUID();
  16475. this.width = width;
  16476. this.height = height;
  16477. this.scissor = new THREE.Vector4( 0, 0, width, height );
  16478. this.scissorTest = false;
  16479. this.viewport = new THREE.Vector4( 0, 0, width, height );
  16480. options = options || {};
  16481. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  16482. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy );
  16483. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  16484. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  16485. };
  16486. THREE.WebGLRenderTarget.prototype = {
  16487. constructor: THREE.WebGLRenderTarget,
  16488. setSize: function ( width, height ) {
  16489. if ( this.width !== width || this.height !== height ) {
  16490. this.width = width;
  16491. this.height = height;
  16492. this.dispose();
  16493. }
  16494. this.viewport.set( 0, 0, width, height );
  16495. this.scissor.set( 0, 0, width, height );
  16496. },
  16497. clone: function () {
  16498. return new this.constructor().copy( this );
  16499. },
  16500. copy: function ( source ) {
  16501. this.width = source.width;
  16502. this.height = source.height;
  16503. this.viewport.copy( source.viewport );
  16504. this.texture = source.texture.clone();
  16505. this.depthBuffer = source.depthBuffer;
  16506. this.stencilBuffer = source.stencilBuffer;
  16507. return this;
  16508. },
  16509. dispose: function () {
  16510. this.dispatchEvent( { type: 'dispose' } );
  16511. }
  16512. };
  16513. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  16514. // File:src/renderers/WebGLRenderTargetCube.js
  16515. /**
  16516. * @author alteredq / http://alteredqualia.com
  16517. */
  16518. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  16519. THREE.WebGLRenderTarget.call( this, width, height, options );
  16520. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  16521. this.activeMipMapLevel = 0;
  16522. };
  16523. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  16524. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  16525. // File:src/renderers/webgl/WebGLBufferRenderer.js
  16526. /**
  16527. * @author mrdoob / http://mrdoob.com/
  16528. */
  16529. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16530. var mode;
  16531. function setMode( value ) {
  16532. mode = value;
  16533. }
  16534. function render( start, count ) {
  16535. _gl.drawArrays( mode, start, count );
  16536. _infoRender.calls ++;
  16537. _infoRender.vertices += count;
  16538. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16539. }
  16540. function renderInstances( geometry ) {
  16541. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16542. if ( extension === null ) {
  16543. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16544. return;
  16545. }
  16546. var position = geometry.attributes.position;
  16547. var count = 0;
  16548. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  16549. count = position.data.count;
  16550. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16551. } else {
  16552. count = position.count;
  16553. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16554. }
  16555. _infoRender.calls ++;
  16556. _infoRender.vertices += count * geometry.maxInstancedCount;
  16557. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16558. }
  16559. this.setMode = setMode;
  16560. this.render = render;
  16561. this.renderInstances = renderInstances;
  16562. };
  16563. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  16564. /**
  16565. * @author mrdoob / http://mrdoob.com/
  16566. */
  16567. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16568. var mode;
  16569. function setMode( value ) {
  16570. mode = value;
  16571. }
  16572. var type, size;
  16573. function setIndex( index ) {
  16574. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  16575. type = _gl.UNSIGNED_INT;
  16576. size = 4;
  16577. } else {
  16578. type = _gl.UNSIGNED_SHORT;
  16579. size = 2;
  16580. }
  16581. }
  16582. function render( start, count ) {
  16583. _gl.drawElements( mode, count, type, start * size );
  16584. _infoRender.calls ++;
  16585. _infoRender.vertices += count;
  16586. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16587. }
  16588. function renderInstances( geometry, start, count ) {
  16589. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16590. if ( extension === null ) {
  16591. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16592. return;
  16593. }
  16594. extension.drawElementsInstancedANGLE( mode, count, type, start * size, geometry.maxInstancedCount );
  16595. _infoRender.calls ++;
  16596. _infoRender.vertices += count * geometry.maxInstancedCount;
  16597. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16598. }
  16599. this.setMode = setMode;
  16600. this.setIndex = setIndex;
  16601. this.render = render;
  16602. this.renderInstances = renderInstances;
  16603. };
  16604. // File:src/renderers/webgl/WebGLExtensions.js
  16605. /**
  16606. * @author mrdoob / http://mrdoob.com/
  16607. */
  16608. THREE.WebGLExtensions = function ( gl ) {
  16609. var extensions = {};
  16610. this.get = function ( name ) {
  16611. if ( extensions[ name ] !== undefined ) {
  16612. return extensions[ name ];
  16613. }
  16614. var extension;
  16615. switch ( name ) {
  16616. case 'EXT_texture_filter_anisotropic':
  16617. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  16618. break;
  16619. case 'WEBGL_compressed_texture_s3tc':
  16620. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  16621. break;
  16622. case 'WEBGL_compressed_texture_pvrtc':
  16623. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  16624. break;
  16625. case 'WEBGL_compressed_texture_etc1':
  16626. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  16627. break;
  16628. default:
  16629. extension = gl.getExtension( name );
  16630. }
  16631. if ( extension === null ) {
  16632. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  16633. }
  16634. extensions[ name ] = extension;
  16635. return extension;
  16636. };
  16637. };
  16638. // File:src/renderers/webgl/WebGLCapabilities.js
  16639. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  16640. function getMaxPrecision( precision ) {
  16641. if ( precision === 'highp' ) {
  16642. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  16643. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  16644. return 'highp';
  16645. }
  16646. precision = 'mediump';
  16647. }
  16648. if ( precision === 'mediump' ) {
  16649. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  16650. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  16651. return 'mediump';
  16652. }
  16653. }
  16654. return 'lowp';
  16655. }
  16656. this.getMaxPrecision = getMaxPrecision;
  16657. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  16658. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  16659. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  16660. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  16661. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  16662. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  16663. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  16664. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  16665. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  16666. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  16667. this.vertexTextures = this.maxVertexTextures > 0;
  16668. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  16669. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  16670. var _maxPrecision = getMaxPrecision( this.precision );
  16671. if ( _maxPrecision !== this.precision ) {
  16672. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  16673. this.precision = _maxPrecision;
  16674. }
  16675. if ( this.logarithmicDepthBuffer ) {
  16676. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  16677. }
  16678. };
  16679. // File:src/renderers/webgl/WebGLGeometries.js
  16680. /**
  16681. * @author mrdoob / http://mrdoob.com/
  16682. */
  16683. THREE.WebGLGeometries = function ( gl, properties, info ) {
  16684. var geometries = {};
  16685. function get( object ) {
  16686. var geometry = object.geometry;
  16687. if ( geometries[ geometry.id ] !== undefined ) {
  16688. return geometries[ geometry.id ];
  16689. }
  16690. geometry.addEventListener( 'dispose', onGeometryDispose );
  16691. var buffergeometry;
  16692. if ( geometry instanceof THREE.BufferGeometry ) {
  16693. buffergeometry = geometry;
  16694. } else if ( geometry instanceof THREE.Geometry ) {
  16695. if ( geometry._bufferGeometry === undefined ) {
  16696. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  16697. }
  16698. buffergeometry = geometry._bufferGeometry;
  16699. }
  16700. geometries[ geometry.id ] = buffergeometry;
  16701. info.memory.geometries ++;
  16702. return buffergeometry;
  16703. }
  16704. function onGeometryDispose( event ) {
  16705. var geometry = event.target;
  16706. var buffergeometry = geometries[ geometry.id ];
  16707. if ( buffergeometry.index !== null ) {
  16708. deleteAttribute( buffergeometry.index );
  16709. }
  16710. deleteAttributes( buffergeometry.attributes );
  16711. geometry.removeEventListener( 'dispose', onGeometryDispose );
  16712. delete geometries[ geometry.id ];
  16713. // TODO
  16714. var property = properties.get( geometry );
  16715. if ( property.wireframe ) {
  16716. deleteAttribute( property.wireframe );
  16717. }
  16718. properties.delete( geometry );
  16719. var bufferproperty = properties.get( buffergeometry );
  16720. if ( bufferproperty.wireframe ) {
  16721. deleteAttribute( bufferproperty.wireframe );
  16722. }
  16723. properties.delete( buffergeometry );
  16724. //
  16725. info.memory.geometries --;
  16726. }
  16727. function getAttributeBuffer( attribute ) {
  16728. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16729. return properties.get( attribute.data ).__webglBuffer;
  16730. }
  16731. return properties.get( attribute ).__webglBuffer;
  16732. }
  16733. function deleteAttribute( attribute ) {
  16734. var buffer = getAttributeBuffer( attribute );
  16735. if ( buffer !== undefined ) {
  16736. gl.deleteBuffer( buffer );
  16737. removeAttributeBuffer( attribute );
  16738. }
  16739. }
  16740. function deleteAttributes( attributes ) {
  16741. for ( var name in attributes ) {
  16742. deleteAttribute( attributes[ name ] );
  16743. }
  16744. }
  16745. function removeAttributeBuffer( attribute ) {
  16746. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16747. properties.delete( attribute.data );
  16748. } else {
  16749. properties.delete( attribute );
  16750. }
  16751. }
  16752. this.get = get;
  16753. };
  16754. // File:src/renderers/webgl/WebGLLights.js
  16755. /**
  16756. * @author mrdoob / http://mrdoob.com/
  16757. */
  16758. THREE.WebGLLights = function () {
  16759. var lights = {};
  16760. this.get = function ( light ) {
  16761. if ( lights[ light.id ] !== undefined ) {
  16762. return lights[ light.id ];
  16763. }
  16764. var uniforms;
  16765. switch ( light.type ) {
  16766. case 'DirectionalLight':
  16767. uniforms = {
  16768. direction: new THREE.Vector3(),
  16769. color: new THREE.Color(),
  16770. shadow: false,
  16771. shadowBias: 0,
  16772. shadowRadius: 1,
  16773. shadowMapSize: new THREE.Vector2()
  16774. };
  16775. break;
  16776. case 'SpotLight':
  16777. uniforms = {
  16778. position: new THREE.Vector3(),
  16779. direction: new THREE.Vector3(),
  16780. color: new THREE.Color(),
  16781. distance: 0,
  16782. coneCos: 0,
  16783. penumbraCos: 0,
  16784. decay: 0,
  16785. shadow: false,
  16786. shadowBias: 0,
  16787. shadowRadius: 1,
  16788. shadowMapSize: new THREE.Vector2()
  16789. };
  16790. break;
  16791. case 'PointLight':
  16792. uniforms = {
  16793. position: new THREE.Vector3(),
  16794. color: new THREE.Color(),
  16795. distance: 0,
  16796. decay: 0,
  16797. shadow: false,
  16798. shadowBias: 0,
  16799. shadowRadius: 1,
  16800. shadowMapSize: new THREE.Vector2()
  16801. };
  16802. break;
  16803. case 'HemisphereLight':
  16804. uniforms = {
  16805. direction: new THREE.Vector3(),
  16806. skyColor: new THREE.Color(),
  16807. groundColor: new THREE.Color()
  16808. };
  16809. break;
  16810. }
  16811. lights[ light.id ] = uniforms;
  16812. return uniforms;
  16813. };
  16814. };
  16815. // File:src/renderers/webgl/WebGLObjects.js
  16816. /**
  16817. * @author mrdoob / http://mrdoob.com/
  16818. */
  16819. THREE.WebGLObjects = function ( gl, properties, info ) {
  16820. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  16821. //
  16822. function update( object ) {
  16823. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  16824. var geometry = geometries.get( object );
  16825. if ( object.geometry instanceof THREE.Geometry ) {
  16826. geometry.updateFromObject( object );
  16827. }
  16828. var index = geometry.index;
  16829. var attributes = geometry.attributes;
  16830. if ( index !== null ) {
  16831. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  16832. }
  16833. for ( var name in attributes ) {
  16834. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  16835. }
  16836. // morph targets
  16837. var morphAttributes = geometry.morphAttributes;
  16838. for ( var name in morphAttributes ) {
  16839. var array = morphAttributes[ name ];
  16840. for ( var i = 0, l = array.length; i < l; i ++ ) {
  16841. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  16842. }
  16843. }
  16844. return geometry;
  16845. }
  16846. function updateAttribute( attribute, bufferType ) {
  16847. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  16848. var attributeProperties = properties.get( data );
  16849. if ( attributeProperties.__webglBuffer === undefined ) {
  16850. createBuffer( attributeProperties, data, bufferType );
  16851. } else if ( attributeProperties.version !== data.version ) {
  16852. updateBuffer( attributeProperties, data, bufferType );
  16853. }
  16854. }
  16855. function createBuffer( attributeProperties, data, bufferType ) {
  16856. attributeProperties.__webglBuffer = gl.createBuffer();
  16857. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16858. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  16859. gl.bufferData( bufferType, data.array, usage );
  16860. attributeProperties.version = data.version;
  16861. }
  16862. function updateBuffer( attributeProperties, data, bufferType ) {
  16863. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16864. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  16865. // Not using update ranges
  16866. gl.bufferSubData( bufferType, 0, data.array );
  16867. } else if ( data.updateRange.count === 0 ) {
  16868. 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.' );
  16869. } else {
  16870. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  16871. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  16872. data.updateRange.count = 0; // reset range
  16873. }
  16874. attributeProperties.version = data.version;
  16875. }
  16876. function getAttributeBuffer( attribute ) {
  16877. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16878. return properties.get( attribute.data ).__webglBuffer;
  16879. }
  16880. return properties.get( attribute ).__webglBuffer;
  16881. }
  16882. function getWireframeAttribute( geometry ) {
  16883. var property = properties.get( geometry );
  16884. if ( property.wireframe !== undefined ) {
  16885. return property.wireframe;
  16886. }
  16887. var indices = [];
  16888. var index = geometry.index;
  16889. var attributes = geometry.attributes;
  16890. var position = attributes.position;
  16891. // console.time( 'wireframe' );
  16892. if ( index !== null ) {
  16893. var edges = {};
  16894. var array = index.array;
  16895. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  16896. var a = array[ i + 0 ];
  16897. var b = array[ i + 1 ];
  16898. var c = array[ i + 2 ];
  16899. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  16900. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  16901. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  16902. }
  16903. } else {
  16904. var array = attributes.position.array;
  16905. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  16906. var a = i + 0;
  16907. var b = i + 1;
  16908. var c = i + 2;
  16909. indices.push( a, b, b, c, c, a );
  16910. }
  16911. }
  16912. // console.timeEnd( 'wireframe' );
  16913. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  16914. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  16915. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  16916. property.wireframe = attribute;
  16917. return attribute;
  16918. }
  16919. function checkEdge( edges, a, b ) {
  16920. if ( a > b ) {
  16921. var tmp = a;
  16922. a = b;
  16923. b = tmp;
  16924. }
  16925. var list = edges[ a ];
  16926. if ( list === undefined ) {
  16927. edges[ a ] = [ b ];
  16928. return true;
  16929. } else if ( list.indexOf( b ) === -1 ) {
  16930. list.push( b );
  16931. return true;
  16932. }
  16933. return false;
  16934. }
  16935. this.getAttributeBuffer = getAttributeBuffer;
  16936. this.getWireframeAttribute = getWireframeAttribute;
  16937. this.update = update;
  16938. };
  16939. // File:src/renderers/webgl/WebGLProgram.js
  16940. THREE.WebGLProgram = ( function () {
  16941. var programIdCount = 0;
  16942. // TODO: Combine the regex
  16943. var structRe = /^([\w\d_]+)\.([\w\d_]+)$/;
  16944. var arrayStructRe = /^([\w\d_]+)\[(\d+)\]\.([\w\d_]+)$/;
  16945. var arrayRe = /^([\w\d_]+)\[0\]$/;
  16946. function getEncodingComponents( encoding ) {
  16947. switch ( encoding ) {
  16948. case THREE.LinearEncoding:
  16949. return [ 'Linear','( value )' ];
  16950. case THREE.sRGBEncoding:
  16951. return [ 'sRGB','( value )' ];
  16952. case THREE.RGBEEncoding:
  16953. return [ 'RGBE','( value )' ];
  16954. case THREE.RGBM7Encoding:
  16955. return [ 'RGBM','( value, 7.0 )' ];
  16956. case THREE.RGBM16Encoding:
  16957. return [ 'RGBM','( value, 16.0 )' ];
  16958. case THREE.RGBDEncoding:
  16959. return [ 'RGBD','( value, 256.0 )' ];
  16960. case THREE.GammaEncoding:
  16961. return [ 'Gamma','( value, float( GAMMA_FACTOR ) )' ];
  16962. default:
  16963. throw new Error( 'unsupported encoding: ' + encoding );
  16964. }
  16965. }
  16966. function getTexelDecodingFunction( functionName, encoding ) {
  16967. var components = getEncodingComponents( encoding );
  16968. return "vec4 " + functionName + "( vec4 value ) { return " + components[ 0 ] + "ToLinear" + components[ 1 ] + "; }";
  16969. }
  16970. function getTexelEncodingFunction( functionName, encoding ) {
  16971. var components = getEncodingComponents( encoding );
  16972. return "vec4 " + functionName + "( vec4 value ) { return LinearTo" + components[ 0 ] + components[ 1 ] + "; }";
  16973. }
  16974. function getToneMappingFunction( functionName, toneMapping ) {
  16975. var toneMappingName;
  16976. switch ( toneMapping ) {
  16977. case THREE.LinearToneMapping:
  16978. toneMappingName = "Linear";
  16979. break;
  16980. case THREE.ReinhardToneMapping:
  16981. toneMappingName = "Reinhard";
  16982. break;
  16983. case THREE.Uncharted2ToneMapping:
  16984. toneMappingName = "Uncharted2";
  16985. break;
  16986. case THREE.CineonToneMapping:
  16987. toneMappingName = "OptimizedCineon";
  16988. break;
  16989. default:
  16990. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  16991. }
  16992. return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }";
  16993. }
  16994. function generateExtensions( extensions, parameters, rendererExtensions ) {
  16995. extensions = extensions || {};
  16996. var chunks = [
  16997. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  16998. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  16999. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  17000. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : '',
  17001. ];
  17002. return chunks.filter( filterEmptyLine ).join( '\n' );
  17003. }
  17004. function generateDefines( defines ) {
  17005. var chunks = [];
  17006. for ( var name in defines ) {
  17007. var value = defines[ name ];
  17008. if ( value === false ) continue;
  17009. chunks.push( '#define ' + name + ' ' + value );
  17010. }
  17011. return chunks.join( '\n' );
  17012. }
  17013. function fetchUniformLocations( gl, program, identifiers ) {
  17014. var uniforms = {};
  17015. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  17016. for ( var i = 0; i < n; i ++ ) {
  17017. var info = gl.getActiveUniform( program, i );
  17018. var name = info.name;
  17019. var location = gl.getUniformLocation( program, name );
  17020. //console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  17021. var matches = structRe.exec( name );
  17022. if ( matches ) {
  17023. var structName = matches[ 1 ];
  17024. var structProperty = matches[ 2 ];
  17025. var uniformsStruct = uniforms[ structName ];
  17026. if ( ! uniformsStruct ) {
  17027. uniformsStruct = uniforms[ structName ] = {};
  17028. }
  17029. uniformsStruct[ structProperty ] = location;
  17030. continue;
  17031. }
  17032. matches = arrayStructRe.exec( name );
  17033. if ( matches ) {
  17034. var arrayName = matches[ 1 ];
  17035. var arrayIndex = matches[ 2 ];
  17036. var arrayProperty = matches[ 3 ];
  17037. var uniformsArray = uniforms[ arrayName ];
  17038. if ( ! uniformsArray ) {
  17039. uniformsArray = uniforms[ arrayName ] = [];
  17040. }
  17041. var uniformsArrayIndex = uniformsArray[ arrayIndex ];
  17042. if ( ! uniformsArrayIndex ) {
  17043. uniformsArrayIndex = uniformsArray[ arrayIndex ] = {};
  17044. }
  17045. uniformsArrayIndex[ arrayProperty ] = location;
  17046. continue;
  17047. }
  17048. matches = arrayRe.exec( name );
  17049. if ( matches ) {
  17050. var arrayName = matches[ 1 ];
  17051. uniforms[ arrayName ] = location;
  17052. continue;
  17053. }
  17054. uniforms[ name ] = location;
  17055. }
  17056. return uniforms;
  17057. }
  17058. function fetchAttributeLocations( gl, program, identifiers ) {
  17059. var attributes = {};
  17060. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  17061. for ( var i = 0; i < n; i ++ ) {
  17062. var info = gl.getActiveAttrib( program, i );
  17063. var name = info.name;
  17064. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  17065. attributes[ name ] = gl.getAttribLocation( program, name );
  17066. }
  17067. return attributes;
  17068. }
  17069. function filterEmptyLine( string ) {
  17070. return string !== '';
  17071. }
  17072. function replaceLightNums( string, parameters ) {
  17073. return string
  17074. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  17075. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  17076. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  17077. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  17078. }
  17079. function parseIncludes( string ) {
  17080. var pattern = /#include +<([\w\d.]+)>/g;
  17081. function replace( match, include ) {
  17082. var replace = THREE.ShaderChunk[ include ];
  17083. if ( replace === undefined ) {
  17084. throw new Error( 'Can not resolve #include <' + include + '>' );
  17085. }
  17086. return parseIncludes( replace );
  17087. }
  17088. return string.replace( pattern, replace );
  17089. }
  17090. function unrollLoops( string ) {
  17091. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  17092. function replace( match, start, end, snippet ) {
  17093. var unroll = '';
  17094. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  17095. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  17096. }
  17097. return unroll;
  17098. }
  17099. return string.replace( pattern, replace );
  17100. }
  17101. return function WebGLProgram( renderer, code, material, parameters ) {
  17102. var gl = renderer.context;
  17103. var extensions = material.extensions;
  17104. var defines = material.defines;
  17105. var vertexShader = material.__webglShader.vertexShader;
  17106. var fragmentShader = material.__webglShader.fragmentShader;
  17107. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  17108. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  17109. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  17110. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  17111. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  17112. }
  17113. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17114. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  17115. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17116. if ( parameters.envMap ) {
  17117. switch ( material.envMap.mapping ) {
  17118. case THREE.CubeReflectionMapping:
  17119. case THREE.CubeRefractionMapping:
  17120. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17121. break;
  17122. case THREE.CubeUVReflectionMapping:
  17123. case THREE.CubeUVRefractionMapping:
  17124. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  17125. break;
  17126. case THREE.EquirectangularReflectionMapping:
  17127. case THREE.EquirectangularRefractionMapping:
  17128. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  17129. break;
  17130. case THREE.SphericalReflectionMapping:
  17131. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  17132. break;
  17133. }
  17134. switch ( material.envMap.mapping ) {
  17135. case THREE.CubeRefractionMapping:
  17136. case THREE.EquirectangularRefractionMapping:
  17137. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  17138. break;
  17139. }
  17140. switch ( material.combine ) {
  17141. case THREE.MultiplyOperation:
  17142. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17143. break;
  17144. case THREE.MixOperation:
  17145. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  17146. break;
  17147. case THREE.AddOperation:
  17148. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  17149. break;
  17150. }
  17151. }
  17152. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  17153. // console.log( 'building new program ' );
  17154. //
  17155. var customExtensions = generateExtensions( extensions, parameters, renderer.extensions );
  17156. var customDefines = generateDefines( defines );
  17157. //
  17158. var program = gl.createProgram();
  17159. var prefixVertex, prefixFragment;
  17160. if ( material instanceof THREE.RawShaderMaterial ) {
  17161. prefixVertex = '';
  17162. prefixFragment = '';
  17163. } else {
  17164. prefixVertex = [
  17165. 'precision ' + parameters.precision + ' float;',
  17166. 'precision ' + parameters.precision + ' int;',
  17167. '#define SHADER_NAME ' + material.__webglShader.name,
  17168. customDefines,
  17169. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  17170. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17171. '#define MAX_BONES ' + parameters.maxBones,
  17172. parameters.map ? '#define USE_MAP' : '',
  17173. parameters.envMap ? '#define USE_ENVMAP' : '',
  17174. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17175. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17176. parameters.aoMap ? '#define USE_AOMAP' : '',
  17177. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17178. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17179. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17180. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  17181. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17182. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17183. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17184. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17185. parameters.vertexColors ? '#define USE_COLOR' : '',
  17186. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17187. parameters.skinning ? '#define USE_SKINNING' : '',
  17188. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  17189. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  17190. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  17191. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17192. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17193. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17194. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17195. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  17196. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  17197. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17198. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17199. 'uniform mat4 modelMatrix;',
  17200. 'uniform mat4 modelViewMatrix;',
  17201. 'uniform mat4 projectionMatrix;',
  17202. 'uniform mat4 viewMatrix;',
  17203. 'uniform mat3 normalMatrix;',
  17204. 'uniform vec3 cameraPosition;',
  17205. 'attribute vec3 position;',
  17206. 'attribute vec3 normal;',
  17207. 'attribute vec2 uv;',
  17208. '#ifdef USE_COLOR',
  17209. ' attribute vec3 color;',
  17210. '#endif',
  17211. '#ifdef USE_MORPHTARGETS',
  17212. ' attribute vec3 morphTarget0;',
  17213. ' attribute vec3 morphTarget1;',
  17214. ' attribute vec3 morphTarget2;',
  17215. ' attribute vec3 morphTarget3;',
  17216. ' #ifdef USE_MORPHNORMALS',
  17217. ' attribute vec3 morphNormal0;',
  17218. ' attribute vec3 morphNormal1;',
  17219. ' attribute vec3 morphNormal2;',
  17220. ' attribute vec3 morphNormal3;',
  17221. ' #else',
  17222. ' attribute vec3 morphTarget4;',
  17223. ' attribute vec3 morphTarget5;',
  17224. ' attribute vec3 morphTarget6;',
  17225. ' attribute vec3 morphTarget7;',
  17226. ' #endif',
  17227. '#endif',
  17228. '#ifdef USE_SKINNING',
  17229. ' attribute vec4 skinIndex;',
  17230. ' attribute vec4 skinWeight;',
  17231. '#endif',
  17232. '\n'
  17233. ].filter( filterEmptyLine ).join( '\n' );
  17234. prefixFragment = [
  17235. customExtensions,
  17236. 'precision ' + parameters.precision + ' float;',
  17237. 'precision ' + parameters.precision + ' int;',
  17238. '#define SHADER_NAME ' + material.__webglShader.name,
  17239. customDefines,
  17240. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  17241. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17242. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  17243. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  17244. parameters.map ? '#define USE_MAP' : '',
  17245. parameters.envMap ? '#define USE_ENVMAP' : '',
  17246. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  17247. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17248. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  17249. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17250. parameters.aoMap ? '#define USE_AOMAP' : '',
  17251. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17252. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17253. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17254. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17255. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17256. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17257. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17258. parameters.vertexColors ? '#define USE_COLOR' : '',
  17259. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17260. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17261. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17262. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17263. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17264. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  17265. parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
  17266. parameters.physicallyCorrectLights ? "#define PHYSICALLY_CORRECT_LIGHTS" : '',
  17267. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17268. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17269. parameters.envMap && renderer.extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  17270. 'uniform mat4 viewMatrix;',
  17271. 'uniform vec3 cameraPosition;',
  17272. ( parameters.toneMapping !== THREE.NoToneMapping ) ? "#define TONE_MAPPING" : '',
  17273. ( parameters.toneMapping !== THREE.NoToneMapping ) ? THREE.ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  17274. ( parameters.toneMapping !== THREE.NoToneMapping ) ? getToneMappingFunction( "toneMapping", parameters.toneMapping ) : '',
  17275. ( parameters.outputEncoding || parameters.mapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ? THREE.ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  17276. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  17277. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  17278. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  17279. parameters.outputEncoding ? getTexelEncodingFunction( "linearToOutputTexel", parameters.outputEncoding ) : '',
  17280. '\n'
  17281. ].filter( filterEmptyLine ).join( '\n' );
  17282. }
  17283. vertexShader = parseIncludes( vertexShader, parameters );
  17284. vertexShader = replaceLightNums( vertexShader, parameters );
  17285. fragmentShader = parseIncludes( fragmentShader, parameters );
  17286. fragmentShader = replaceLightNums( fragmentShader, parameters );
  17287. if ( material instanceof THREE.ShaderMaterial === false ) {
  17288. vertexShader = unrollLoops( vertexShader );
  17289. fragmentShader = unrollLoops( fragmentShader );
  17290. }
  17291. var vertexGlsl = prefixVertex + vertexShader;
  17292. var fragmentGlsl = prefixFragment + fragmentShader;
  17293. // console.log( '*VERTEX*', vertexGlsl );
  17294. // console.log( '*FRAGMENT*', fragmentGlsl );
  17295. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  17296. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  17297. gl.attachShader( program, glVertexShader );
  17298. gl.attachShader( program, glFragmentShader );
  17299. // Force a particular attribute to index 0.
  17300. if ( material.index0AttributeName !== undefined ) {
  17301. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  17302. } else if ( parameters.morphTargets === true ) {
  17303. // programs with morphTargets displace position out of attribute 0
  17304. gl.bindAttribLocation( program, 0, 'position' );
  17305. }
  17306. gl.linkProgram( program );
  17307. var programLog = gl.getProgramInfoLog( program );
  17308. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  17309. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  17310. var runnable = true;
  17311. var haveDiagnostics = true;
  17312. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  17313. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  17314. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  17315. runnable = false;
  17316. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  17317. } else if ( programLog !== '' ) {
  17318. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  17319. } else if ( vertexLog === '' || fragmentLog === '' ) {
  17320. haveDiagnostics = false;
  17321. }
  17322. if ( haveDiagnostics ) {
  17323. this.diagnostics = {
  17324. runnable: runnable,
  17325. material: material,
  17326. programLog: programLog,
  17327. vertexShader: {
  17328. log: vertexLog,
  17329. prefix: prefixVertex
  17330. },
  17331. fragmentShader: {
  17332. log: fragmentLog,
  17333. prefix: prefixFragment
  17334. }
  17335. };
  17336. }
  17337. // clean up
  17338. gl.deleteShader( glVertexShader );
  17339. gl.deleteShader( glFragmentShader );
  17340. // set up caching for uniform locations
  17341. var cachedUniforms;
  17342. this.getUniforms = function() {
  17343. if ( cachedUniforms === undefined ) {
  17344. cachedUniforms = fetchUniformLocations( gl, program );
  17345. }
  17346. return cachedUniforms;
  17347. };
  17348. // set up caching for attribute locations
  17349. var cachedAttributes;
  17350. this.getAttributes = function() {
  17351. if ( cachedAttributes === undefined ) {
  17352. cachedAttributes = fetchAttributeLocations( gl, program );
  17353. }
  17354. return cachedAttributes;
  17355. };
  17356. // free resource
  17357. this.destroy = function() {
  17358. gl.deleteProgram( program );
  17359. this.program = undefined;
  17360. };
  17361. // DEPRECATED
  17362. Object.defineProperties( this, {
  17363. uniforms: {
  17364. get: function() {
  17365. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  17366. return this.getUniforms();
  17367. }
  17368. },
  17369. attributes: {
  17370. get: function() {
  17371. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  17372. return this.getAttributes();
  17373. }
  17374. }
  17375. } );
  17376. //
  17377. this.id = programIdCount ++;
  17378. this.code = code;
  17379. this.usedTimes = 1;
  17380. this.program = program;
  17381. this.vertexShader = glVertexShader;
  17382. this.fragmentShader = glFragmentShader;
  17383. return this;
  17384. };
  17385. } )();
  17386. // File:src/renderers/webgl/WebGLPrograms.js
  17387. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  17388. var programs = [];
  17389. var shaderIDs = {
  17390. MeshDepthMaterial: 'depth',
  17391. MeshNormalMaterial: 'normal',
  17392. MeshBasicMaterial: 'basic',
  17393. MeshLambertMaterial: 'lambert',
  17394. MeshPhongMaterial: 'phong',
  17395. MeshStandardMaterial: 'standard',
  17396. LineBasicMaterial: 'basic',
  17397. LineDashedMaterial: 'dashed',
  17398. PointsMaterial: 'points'
  17399. };
  17400. var parameterNames = [
  17401. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  17402. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  17403. "roughnessMap", "metalnessMap",
  17404. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  17405. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  17406. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  17407. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  17408. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights",
  17409. "shadowMapEnabled", "pointLightShadows", "toneMapping", 'physicallyCorrectLights',
  17410. "shadowMapType",
  17411. "alphaTest", "doubleSided", "flipSided"
  17412. ];
  17413. function allocateBones ( object ) {
  17414. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  17415. return 1024;
  17416. } else {
  17417. // default for when object is not specified
  17418. // ( for example when prebuilding shader to be used with multiple objects )
  17419. //
  17420. // - leave some extra space for other uniforms
  17421. // - limit here is ANGLE's 254 max uniform vectors
  17422. // (up to 54 should be safe)
  17423. var nVertexUniforms = capabilities.maxVertexUniforms;
  17424. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  17425. var maxBones = nVertexMatrices;
  17426. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  17427. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  17428. if ( maxBones < object.skeleton.bones.length ) {
  17429. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  17430. }
  17431. }
  17432. return maxBones;
  17433. }
  17434. }
  17435. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  17436. var encoding;
  17437. if ( ! map ) {
  17438. encoding = THREE.LinearEncoding;
  17439. } else if ( map instanceof THREE.Texture ) {
  17440. encoding = map.encoding;
  17441. } else if ( map instanceof THREE.WebGLRenderTarget ) {
  17442. encoding = map.texture.encoding;
  17443. }
  17444. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  17445. if ( encoding === THREE.LinearEncoding && gammaOverrideLinear ) {
  17446. encoding = THREE.GammaEncoding;
  17447. }
  17448. return encoding;
  17449. }
  17450. this.getParameters = function ( material, lights, fog, object ) {
  17451. var shaderID = shaderIDs[ material.type ];
  17452. // heuristics to create shader parameters according to lights in the scene
  17453. // (not to blow over maxLights budget)
  17454. var maxBones = allocateBones( object );
  17455. var precision = renderer.getPrecision();
  17456. if ( material.precision !== null ) {
  17457. precision = capabilities.getMaxPrecision( material.precision );
  17458. if ( precision !== material.precision ) {
  17459. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  17460. }
  17461. }
  17462. var parameters = {
  17463. shaderID: shaderID,
  17464. precision: precision,
  17465. supportsVertexTextures: capabilities.vertexTextures,
  17466. outputEncoding: getTextureEncodingFromMap( renderer.getCurrentRenderTarget(), renderer.gammaOutput ),
  17467. map: !! material.map,
  17468. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  17469. envMap: !! material.envMap,
  17470. envMapMode: material.envMap && material.envMap.mapping,
  17471. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  17472. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === THREE.CubeUVReflectionMapping ) || ( material.envMap.mapping === THREE.CubeUVRefractionMapping ) ),
  17473. lightMap: !! material.lightMap,
  17474. aoMap: !! material.aoMap,
  17475. emissiveMap: !! material.emissiveMap,
  17476. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  17477. bumpMap: !! material.bumpMap,
  17478. normalMap: !! material.normalMap,
  17479. displacementMap: !! material.displacementMap,
  17480. roughnessMap: !! material.roughnessMap,
  17481. metalnessMap: !! material.metalnessMap,
  17482. specularMap: !! material.specularMap,
  17483. alphaMap: !! material.alphaMap,
  17484. combine: material.combine,
  17485. vertexColors: material.vertexColors,
  17486. fog: fog,
  17487. useFog: material.fog,
  17488. fogExp: fog instanceof THREE.FogExp2,
  17489. flatShading: material.shading === THREE.FlatShading,
  17490. sizeAttenuation: material.sizeAttenuation,
  17491. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  17492. skinning: material.skinning,
  17493. maxBones: maxBones,
  17494. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  17495. morphTargets: material.morphTargets,
  17496. morphNormals: material.morphNormals,
  17497. maxMorphTargets: renderer.maxMorphTargets,
  17498. maxMorphNormals: renderer.maxMorphNormals,
  17499. numDirLights: lights.directional.length,
  17500. numPointLights: lights.point.length,
  17501. numSpotLights: lights.spot.length,
  17502. numHemiLights: lights.hemi.length,
  17503. pointLightShadows: lights.shadowsPointLight,
  17504. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows.length > 0,
  17505. shadowMapType: renderer.shadowMap.type,
  17506. toneMapping: renderer.toneMapping,
  17507. physicallyCorrectLights: renderer.physicallyCorrectLights,
  17508. premultipliedAlpha: material.premultipliedAlpha,
  17509. alphaTest: material.alphaTest,
  17510. doubleSided: material.side === THREE.DoubleSide,
  17511. flipSided: material.side === THREE.BackSide
  17512. };
  17513. return parameters;
  17514. };
  17515. this.getProgramCode = function ( material, parameters ) {
  17516. var chunks = [];
  17517. if ( parameters.shaderID ) {
  17518. chunks.push( parameters.shaderID );
  17519. } else {
  17520. chunks.push( material.fragmentShader );
  17521. chunks.push( material.vertexShader );
  17522. }
  17523. if ( material.defines !== undefined ) {
  17524. for ( var name in material.defines ) {
  17525. chunks.push( name );
  17526. chunks.push( material.defines[ name ] );
  17527. }
  17528. }
  17529. for ( var i = 0; i < parameterNames.length; i ++ ) {
  17530. var parameterName = parameterNames[ i ];
  17531. chunks.push( parameterName );
  17532. chunks.push( parameters[ parameterName ] );
  17533. }
  17534. return chunks.join();
  17535. };
  17536. this.acquireProgram = function ( material, parameters, code ) {
  17537. var program;
  17538. // Check if code has been already compiled
  17539. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  17540. var programInfo = programs[ p ];
  17541. if ( programInfo.code === code ) {
  17542. program = programInfo;
  17543. ++ program.usedTimes;
  17544. break;
  17545. }
  17546. }
  17547. if ( program === undefined ) {
  17548. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  17549. programs.push( program );
  17550. }
  17551. return program;
  17552. };
  17553. this.releaseProgram = function( program ) {
  17554. if ( -- program.usedTimes === 0 ) {
  17555. // Remove from unordered set
  17556. var i = programs.indexOf( program );
  17557. programs[ i ] = programs[ programs.length - 1 ];
  17558. programs.pop();
  17559. // Free WebGL resources
  17560. program.destroy();
  17561. }
  17562. };
  17563. // Exposed for resource monitoring & error feedback via renderer.info:
  17564. this.programs = programs;
  17565. };
  17566. // File:src/renderers/webgl/WebGLProperties.js
  17567. /**
  17568. * @author fordacious / fordacious.github.io
  17569. */
  17570. THREE.WebGLProperties = function () {
  17571. var properties = {};
  17572. this.get = function ( object ) {
  17573. var uuid = object.uuid;
  17574. var map = properties[ uuid ];
  17575. if ( map === undefined ) {
  17576. map = {};
  17577. properties[ uuid ] = map;
  17578. }
  17579. return map;
  17580. };
  17581. this.delete = function ( object ) {
  17582. delete properties[ object.uuid ];
  17583. };
  17584. this.clear = function () {
  17585. properties = {};
  17586. };
  17587. };
  17588. // File:src/renderers/webgl/WebGLShader.js
  17589. THREE.WebGLShader = ( function () {
  17590. function addLineNumbers( string ) {
  17591. var lines = string.split( '\n' );
  17592. for ( var i = 0; i < lines.length; i ++ ) {
  17593. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  17594. }
  17595. return lines.join( '\n' );
  17596. }
  17597. return function WebGLShader( gl, type, string ) {
  17598. var shader = gl.createShader( type );
  17599. gl.shaderSource( shader, string );
  17600. gl.compileShader( shader );
  17601. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  17602. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  17603. }
  17604. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  17605. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  17606. }
  17607. // --enable-privileged-webgl-extension
  17608. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  17609. return shader;
  17610. };
  17611. } )();
  17612. // File:src/renderers/webgl/WebGLShadowMap.js
  17613. /**
  17614. * @author alteredq / http://alteredqualia.com/
  17615. * @author mrdoob / http://mrdoob.com/
  17616. */
  17617. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  17618. var _gl = _renderer.context,
  17619. _state = _renderer.state,
  17620. _frustum = new THREE.Frustum(),
  17621. _projScreenMatrix = new THREE.Matrix4(),
  17622. _shadowMapSize = new THREE.Vector2(),
  17623. _lookTarget = new THREE.Vector3(),
  17624. _lightPositionWorld = new THREE.Vector3(),
  17625. _renderList = [],
  17626. _MorphingFlag = 1,
  17627. _SkinningFlag = 2,
  17628. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  17629. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  17630. _distanceMaterials = new Array( _NumberOfMaterialVariants );
  17631. var cubeDirections = [
  17632. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  17633. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  17634. ];
  17635. var cubeUps = [
  17636. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  17637. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  17638. ];
  17639. var cube2DViewPorts = [
  17640. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  17641. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  17642. ];
  17643. // init
  17644. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  17645. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  17646. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  17647. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  17648. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  17649. var useMorphing = ( i & _MorphingFlag ) !== 0;
  17650. var useSkinning = ( i & _SkinningFlag ) !== 0;
  17651. var depthMaterial = new THREE.ShaderMaterial( {
  17652. uniforms: depthUniforms,
  17653. vertexShader: depthShader.vertexShader,
  17654. fragmentShader: depthShader.fragmentShader,
  17655. morphTargets: useMorphing,
  17656. skinning: useSkinning
  17657. } );
  17658. _depthMaterials[ i ] = depthMaterial;
  17659. var distanceMaterial = new THREE.ShaderMaterial( {
  17660. defines: {
  17661. 'USE_SHADOWMAP': ''
  17662. },
  17663. uniforms: distanceUniforms,
  17664. vertexShader: distanceShader.vertexShader,
  17665. fragmentShader: distanceShader.fragmentShader,
  17666. morphTargets: useMorphing,
  17667. skinning: useSkinning
  17668. } );
  17669. _distanceMaterials[ i ] = distanceMaterial;
  17670. }
  17671. //
  17672. var scope = this;
  17673. this.enabled = false;
  17674. this.autoUpdate = true;
  17675. this.needsUpdate = false;
  17676. this.type = THREE.PCFShadowMap;
  17677. this.cullFace = THREE.CullFaceFront;
  17678. this.render = function ( scene, camera ) {
  17679. var faceCount, isPointLight;
  17680. var shadows = _lights.shadows;
  17681. if ( shadows.length === 0 ) return;
  17682. if ( scope.enabled === false ) return;
  17683. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  17684. // Set GL state for depth map.
  17685. _state.clearColor( 1, 1, 1, 1 );
  17686. _state.disable( _gl.BLEND );
  17687. _state.enable( _gl.CULL_FACE );
  17688. _gl.frontFace( _gl.CCW );
  17689. _gl.cullFace( scope.cullFace === THREE.CullFaceFront ? _gl.FRONT : _gl.BACK );
  17690. _state.setDepthTest( true );
  17691. _state.setScissorTest( false );
  17692. // render depth map
  17693. for ( var i = 0, il = shadows.length; i < il; i ++ ) {
  17694. var light = shadows[ i ];
  17695. var shadow = light.shadow;
  17696. var shadowCamera = shadow.camera;
  17697. _shadowMapSize.copy( shadow.mapSize );
  17698. if ( light instanceof THREE.PointLight ) {
  17699. faceCount = 6;
  17700. isPointLight = true;
  17701. var vpWidth = _shadowMapSize.x;
  17702. var vpHeight = _shadowMapSize.y;
  17703. // These viewports map a cube-map onto a 2D texture with the
  17704. // following orientation:
  17705. //
  17706. // xzXZ
  17707. // y Y
  17708. //
  17709. // X - Positive x direction
  17710. // x - Negative x direction
  17711. // Y - Positive y direction
  17712. // y - Negative y direction
  17713. // Z - Positive z direction
  17714. // z - Negative z direction
  17715. // positive X
  17716. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  17717. // negative X
  17718. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  17719. // positive Z
  17720. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  17721. // negative Z
  17722. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  17723. // positive Y
  17724. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  17725. // negative Y
  17726. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  17727. _shadowMapSize.x *= 4.0;
  17728. _shadowMapSize.y *= 2.0;
  17729. } else {
  17730. faceCount = 1;
  17731. isPointLight = false;
  17732. }
  17733. if ( shadow.map === null ) {
  17734. var pars = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
  17735. shadow.map = new THREE.WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  17736. //
  17737. if ( light instanceof THREE.SpotLight ) {
  17738. shadowCamera.aspect = _shadowMapSize.x / _shadowMapSize.y;
  17739. }
  17740. shadowCamera.updateProjectionMatrix();
  17741. }
  17742. var shadowMap = shadow.map;
  17743. var shadowMatrix = shadow.matrix;
  17744. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  17745. shadowCamera.position.copy( _lightPositionWorld );
  17746. _renderer.setRenderTarget( shadowMap );
  17747. _renderer.clear();
  17748. // render shadow map for each cube face (if omni-directional) or
  17749. // run a single pass if not
  17750. for ( var face = 0; face < faceCount; face ++ ) {
  17751. if ( isPointLight ) {
  17752. _lookTarget.copy( shadowCamera.position );
  17753. _lookTarget.add( cubeDirections[ face ] );
  17754. shadowCamera.up.copy( cubeUps[ face ] );
  17755. shadowCamera.lookAt( _lookTarget );
  17756. var vpDimensions = cube2DViewPorts[ face ];
  17757. _state.viewport( vpDimensions );
  17758. } else {
  17759. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  17760. shadowCamera.lookAt( _lookTarget );
  17761. }
  17762. shadowCamera.updateMatrixWorld();
  17763. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  17764. // compute shadow matrix
  17765. shadowMatrix.set(
  17766. 0.5, 0.0, 0.0, 0.5,
  17767. 0.0, 0.5, 0.0, 0.5,
  17768. 0.0, 0.0, 0.5, 0.5,
  17769. 0.0, 0.0, 0.0, 1.0
  17770. );
  17771. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  17772. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  17773. // update camera matrices and frustum
  17774. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  17775. _frustum.setFromMatrix( _projScreenMatrix );
  17776. // set object matrices & frustum culling
  17777. _renderList.length = 0;
  17778. projectObject( scene, camera, shadowCamera );
  17779. // render shadow map
  17780. // render regular objects
  17781. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  17782. var object = _renderList[ j ];
  17783. var geometry = _objects.update( object );
  17784. var material = object.material;
  17785. if ( material instanceof THREE.MultiMaterial ) {
  17786. var groups = geometry.groups;
  17787. var materials = material.materials;
  17788. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  17789. var group = groups[ k ];
  17790. var groupMaterial = materials[ group.materialIndex ];
  17791. if ( groupMaterial.visible === true ) {
  17792. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  17793. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  17794. }
  17795. }
  17796. } else {
  17797. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  17798. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  17799. }
  17800. }
  17801. }
  17802. }
  17803. // Restore GL state.
  17804. var clearColor = _renderer.getClearColor(),
  17805. clearAlpha = _renderer.getClearAlpha();
  17806. _renderer.setClearColor( clearColor, clearAlpha );
  17807. _state.enable( _gl.BLEND );
  17808. if ( scope.cullFace === THREE.CullFaceFront ) {
  17809. _gl.cullFace( _gl.BACK );
  17810. }
  17811. scope.needsUpdate = false;
  17812. };
  17813. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  17814. var geometry = object.geometry;
  17815. var newMaterial = null;
  17816. var materialVariants = _depthMaterials;
  17817. var customMaterial = object.customDepthMaterial;
  17818. if ( isPointLight ) {
  17819. materialVariants = _distanceMaterials;
  17820. customMaterial = object.customDistanceMaterial;
  17821. }
  17822. if ( ! customMaterial ) {
  17823. var useMorphing = geometry.morphTargets !== undefined &&
  17824. geometry.morphTargets.length > 0 && material.morphTargets;
  17825. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  17826. var variantIndex = 0;
  17827. if ( useMorphing ) variantIndex |= _MorphingFlag;
  17828. if ( useSkinning ) variantIndex |= _SkinningFlag;
  17829. newMaterial = materialVariants[ variantIndex ];
  17830. } else {
  17831. newMaterial = customMaterial;
  17832. }
  17833. newMaterial.visible = material.visible;
  17834. newMaterial.wireframe = material.wireframe;
  17835. newMaterial.wireframeLinewidth = material.wireframeLinewidth;
  17836. if ( isPointLight && newMaterial.uniforms.lightPos !== undefined ) {
  17837. newMaterial.uniforms.lightPos.value.copy( lightPositionWorld );
  17838. }
  17839. return newMaterial;
  17840. }
  17841. function projectObject( object, camera, shadowCamera ) {
  17842. if ( object.visible === false ) return;
  17843. if ( object.layers.test( camera.layers ) && ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) ) {
  17844. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  17845. var material = object.material;
  17846. if ( material.visible === true ) {
  17847. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  17848. _renderList.push( object );
  17849. }
  17850. }
  17851. }
  17852. var children = object.children;
  17853. for ( var i = 0, l = children.length; i < l; i ++ ) {
  17854. projectObject( children[ i ], camera, shadowCamera );
  17855. }
  17856. }
  17857. };
  17858. // File:src/renderers/webgl/WebGLState.js
  17859. /**
  17860. * @author mrdoob / http://mrdoob.com/
  17861. */
  17862. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  17863. var _this = this;
  17864. var color = new THREE.Vector4();
  17865. var newAttributes = new Uint8Array( 16 );
  17866. var enabledAttributes = new Uint8Array( 16 );
  17867. var attributeDivisors = new Uint8Array( 16 );
  17868. var capabilities = {};
  17869. var compressedTextureFormats = null;
  17870. var currentBlending = null;
  17871. var currentBlendEquation = null;
  17872. var currentBlendSrc = null;
  17873. var currentBlendDst = null;
  17874. var currentBlendEquationAlpha = null;
  17875. var currentBlendSrcAlpha = null;
  17876. var currentBlendDstAlpha = null;
  17877. var currentPremultipledAlpha = false;
  17878. var currentDepthFunc = null;
  17879. var currentDepthWrite = null;
  17880. var currentColorWrite = null;
  17881. var currentStencilWrite = null;
  17882. var currentStencilFunc = null;
  17883. var currentStencilRef = null;
  17884. var currentStencilMask = null;
  17885. var currentStencilFail = null;
  17886. var currentStencilZFail = null;
  17887. var currentStencilZPass = null;
  17888. var currentFlipSided = null;
  17889. var currentLineWidth = null;
  17890. var currentPolygonOffsetFactor = null;
  17891. var currentPolygonOffsetUnits = null;
  17892. var currentScissorTest = null;
  17893. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  17894. var currentTextureSlot = undefined;
  17895. var currentBoundTextures = {};
  17896. var currentClearColor = new THREE.Vector4();
  17897. var currentClearDepth = null;
  17898. var currentClearStencil = null;
  17899. var currentScissor = new THREE.Vector4();
  17900. var currentViewport = new THREE.Vector4();
  17901. var emptyTexture = gl.createTexture();
  17902. gl.bindTexture( gl.TEXTURE_2D, emptyTexture );
  17903. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR );
  17904. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 1, 1, 0, gl.RGB, gl.UNSIGNED_BYTE, new Uint8Array( 3 ) );
  17905. this.init = function () {
  17906. this.clearColor( 0, 0, 0, 1 );
  17907. this.clearDepth( 1 );
  17908. this.clearStencil( 0 );
  17909. this.enable( gl.DEPTH_TEST );
  17910. gl.depthFunc( gl.LEQUAL );
  17911. gl.frontFace( gl.CCW );
  17912. gl.cullFace( gl.BACK );
  17913. this.enable( gl.CULL_FACE );
  17914. this.enable( gl.BLEND );
  17915. gl.blendEquation( gl.FUNC_ADD );
  17916. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  17917. };
  17918. this.initAttributes = function () {
  17919. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  17920. newAttributes[ i ] = 0;
  17921. }
  17922. };
  17923. this.enableAttribute = function ( attribute ) {
  17924. newAttributes[ attribute ] = 1;
  17925. if ( enabledAttributes[ attribute ] === 0 ) {
  17926. gl.enableVertexAttribArray( attribute );
  17927. enabledAttributes[ attribute ] = 1;
  17928. }
  17929. if ( attributeDivisors[ attribute ] !== 0 ) {
  17930. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  17931. extension.vertexAttribDivisorANGLE( attribute, 0 );
  17932. attributeDivisors[ attribute ] = 0;
  17933. }
  17934. };
  17935. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  17936. newAttributes[ attribute ] = 1;
  17937. if ( enabledAttributes[ attribute ] === 0 ) {
  17938. gl.enableVertexAttribArray( attribute );
  17939. enabledAttributes[ attribute ] = 1;
  17940. }
  17941. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  17942. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  17943. attributeDivisors[ attribute ] = meshPerAttribute;
  17944. }
  17945. };
  17946. this.disableUnusedAttributes = function () {
  17947. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  17948. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  17949. gl.disableVertexAttribArray( i );
  17950. enabledAttributes[ i ] = 0;
  17951. }
  17952. }
  17953. };
  17954. this.enable = function ( id ) {
  17955. if ( capabilities[ id ] !== true ) {
  17956. gl.enable( id );
  17957. capabilities[ id ] = true;
  17958. }
  17959. };
  17960. this.disable = function ( id ) {
  17961. if ( capabilities[ id ] !== false ) {
  17962. gl.disable( id );
  17963. capabilities[ id ] = false;
  17964. }
  17965. };
  17966. this.getCompressedTextureFormats = function () {
  17967. if ( compressedTextureFormats === null ) {
  17968. compressedTextureFormats = [];
  17969. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  17970. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  17971. extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
  17972. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  17973. for ( var i = 0; i < formats.length; i ++ ) {
  17974. compressedTextureFormats.push( formats[ i ] );
  17975. }
  17976. }
  17977. }
  17978. return compressedTextureFormats;
  17979. };
  17980. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  17981. if ( blending === THREE.NoBlending ) {
  17982. this.disable( gl.BLEND );
  17983. } else {
  17984. this.enable( gl.BLEND );
  17985. }
  17986. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  17987. if ( blending === THREE.AdditiveBlending ) {
  17988. if ( premultipliedAlpha ) {
  17989. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17990. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  17991. } else {
  17992. gl.blendEquation( gl.FUNC_ADD );
  17993. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  17994. }
  17995. } else if ( blending === THREE.SubtractiveBlending ) {
  17996. if ( premultipliedAlpha ) {
  17997. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17998. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  17999. } else {
  18000. gl.blendEquation( gl.FUNC_ADD );
  18001. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  18002. }
  18003. } else if ( blending === THREE.MultiplyBlending ) {
  18004. if ( premultipliedAlpha ) {
  18005. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18006. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.SRC_COLOR, gl.SRC_ALPHA );
  18007. } else {
  18008. gl.blendEquation( gl.FUNC_ADD );
  18009. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  18010. }
  18011. } else {
  18012. if ( premultipliedAlpha ) {
  18013. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18014. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  18015. } else {
  18016. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18017. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  18018. }
  18019. }
  18020. currentBlending = blending;
  18021. currentPremultipledAlpha = premultipliedAlpha;
  18022. }
  18023. if ( blending === THREE.CustomBlending ) {
  18024. blendEquationAlpha = blendEquationAlpha || blendEquation;
  18025. blendSrcAlpha = blendSrcAlpha || blendSrc;
  18026. blendDstAlpha = blendDstAlpha || blendDst;
  18027. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  18028. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  18029. currentBlendEquation = blendEquation;
  18030. currentBlendEquationAlpha = blendEquationAlpha;
  18031. }
  18032. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  18033. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  18034. currentBlendSrc = blendSrc;
  18035. currentBlendDst = blendDst;
  18036. currentBlendSrcAlpha = blendSrcAlpha;
  18037. currentBlendDstAlpha = blendDstAlpha;
  18038. }
  18039. } else {
  18040. currentBlendEquation = null;
  18041. currentBlendSrc = null;
  18042. currentBlendDst = null;
  18043. currentBlendEquationAlpha = null;
  18044. currentBlendSrcAlpha = null;
  18045. currentBlendDstAlpha = null;
  18046. }
  18047. };
  18048. this.setDepthFunc = function ( depthFunc ) {
  18049. if ( currentDepthFunc !== depthFunc ) {
  18050. if ( depthFunc ) {
  18051. switch ( depthFunc ) {
  18052. case THREE.NeverDepth:
  18053. gl.depthFunc( gl.NEVER );
  18054. break;
  18055. case THREE.AlwaysDepth:
  18056. gl.depthFunc( gl.ALWAYS );
  18057. break;
  18058. case THREE.LessDepth:
  18059. gl.depthFunc( gl.LESS );
  18060. break;
  18061. case THREE.LessEqualDepth:
  18062. gl.depthFunc( gl.LEQUAL );
  18063. break;
  18064. case THREE.EqualDepth:
  18065. gl.depthFunc( gl.EQUAL );
  18066. break;
  18067. case THREE.GreaterEqualDepth:
  18068. gl.depthFunc( gl.GEQUAL );
  18069. break;
  18070. case THREE.GreaterDepth:
  18071. gl.depthFunc( gl.GREATER );
  18072. break;
  18073. case THREE.NotEqualDepth:
  18074. gl.depthFunc( gl.NOTEQUAL );
  18075. break;
  18076. default:
  18077. gl.depthFunc( gl.LEQUAL );
  18078. }
  18079. } else {
  18080. gl.depthFunc( gl.LEQUAL );
  18081. }
  18082. currentDepthFunc = depthFunc;
  18083. }
  18084. };
  18085. this.setDepthTest = function ( depthTest ) {
  18086. if ( depthTest ) {
  18087. this.enable( gl.DEPTH_TEST );
  18088. } else {
  18089. this.disable( gl.DEPTH_TEST );
  18090. }
  18091. };
  18092. this.setDepthWrite = function ( depthWrite ) {
  18093. // TODO: Rename to setDepthMask
  18094. if ( currentDepthWrite !== depthWrite ) {
  18095. gl.depthMask( depthWrite );
  18096. currentDepthWrite = depthWrite;
  18097. }
  18098. };
  18099. this.setColorWrite = function ( colorWrite ) {
  18100. // TODO: Rename to setColorMask
  18101. if ( currentColorWrite !== colorWrite ) {
  18102. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  18103. currentColorWrite = colorWrite;
  18104. }
  18105. };
  18106. this.setStencilFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  18107. if ( currentStencilFunc !== stencilFunc ||
  18108. currentStencilRef !== stencilRef ||
  18109. currentStencilMask !== stencilMask ) {
  18110. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  18111. currentStencilFunc = stencilFunc;
  18112. currentStencilRef = stencilRef;
  18113. currentStencilMask = stencilMask;
  18114. }
  18115. };
  18116. this.setStencilOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  18117. if ( currentStencilFail !== stencilFail ||
  18118. currentStencilZFail !== stencilZFail ||
  18119. currentStencilZPass !== stencilZPass ) {
  18120. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  18121. currentStencilFail = stencilFail;
  18122. currentStencilZFail = stencilZFail;
  18123. currentStencilZPass = stencilZPass;
  18124. }
  18125. };
  18126. this.setStencilTest = function ( stencilTest ) {
  18127. if ( stencilTest ) {
  18128. this.enable( gl.STENCIL_TEST );
  18129. } else {
  18130. this.disable( gl.STENCIL_TEST );
  18131. }
  18132. };
  18133. this.setStencilWrite = function ( stencilWrite ) {
  18134. // TODO: Rename to setStencilMask
  18135. if ( currentStencilWrite !== stencilWrite ) {
  18136. gl.stencilMask( stencilWrite );
  18137. currentStencilWrite = stencilWrite;
  18138. }
  18139. };
  18140. this.setFlipSided = function ( flipSided ) {
  18141. if ( currentFlipSided !== flipSided ) {
  18142. if ( flipSided ) {
  18143. gl.frontFace( gl.CW );
  18144. } else {
  18145. gl.frontFace( gl.CCW );
  18146. }
  18147. currentFlipSided = flipSided;
  18148. }
  18149. };
  18150. this.setLineWidth = function ( width ) {
  18151. if ( width !== currentLineWidth ) {
  18152. gl.lineWidth( width );
  18153. currentLineWidth = width;
  18154. }
  18155. };
  18156. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  18157. if ( polygonOffset ) {
  18158. this.enable( gl.POLYGON_OFFSET_FILL );
  18159. } else {
  18160. this.disable( gl.POLYGON_OFFSET_FILL );
  18161. }
  18162. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  18163. gl.polygonOffset( factor, units );
  18164. currentPolygonOffsetFactor = factor;
  18165. currentPolygonOffsetUnits = units;
  18166. }
  18167. };
  18168. this.getScissorTest = function () {
  18169. return currentScissorTest;
  18170. };
  18171. this.setScissorTest = function ( scissorTest ) {
  18172. currentScissorTest = scissorTest;
  18173. if ( scissorTest ) {
  18174. this.enable( gl.SCISSOR_TEST );
  18175. } else {
  18176. this.disable( gl.SCISSOR_TEST );
  18177. }
  18178. };
  18179. // texture
  18180. this.activeTexture = function ( webglSlot ) {
  18181. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  18182. if ( currentTextureSlot !== webglSlot ) {
  18183. gl.activeTexture( webglSlot );
  18184. currentTextureSlot = webglSlot;
  18185. }
  18186. };
  18187. this.bindTexture = function ( webglType, webglTexture ) {
  18188. if ( currentTextureSlot === undefined ) {
  18189. _this.activeTexture();
  18190. }
  18191. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  18192. if ( boundTexture === undefined ) {
  18193. boundTexture = { type: undefined, texture: undefined };
  18194. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  18195. }
  18196. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  18197. gl.bindTexture( webglType, webglTexture || emptyTexture );
  18198. boundTexture.type = webglType;
  18199. boundTexture.texture = webglTexture;
  18200. }
  18201. };
  18202. this.compressedTexImage2D = function () {
  18203. try {
  18204. gl.compressedTexImage2D.apply( gl, arguments );
  18205. } catch ( error ) {
  18206. console.error( error );
  18207. }
  18208. };
  18209. this.texImage2D = function () {
  18210. try {
  18211. gl.texImage2D.apply( gl, arguments );
  18212. } catch ( error ) {
  18213. console.error( error );
  18214. }
  18215. };
  18216. // clear values
  18217. this.clearColor = function ( r, g, b, a ) {
  18218. color.set( r, g, b, a );
  18219. if ( currentClearColor.equals( color ) === false ) {
  18220. gl.clearColor( r, g, b, a );
  18221. currentClearColor.copy( color );
  18222. }
  18223. };
  18224. this.clearDepth = function ( depth ) {
  18225. if ( currentClearDepth !== depth ) {
  18226. gl.clearDepth( depth );
  18227. currentClearDepth = depth;
  18228. }
  18229. };
  18230. this.clearStencil = function ( stencil ) {
  18231. if ( currentClearStencil !== stencil ) {
  18232. gl.clearStencil( stencil );
  18233. currentClearStencil = stencil;
  18234. }
  18235. };
  18236. //
  18237. this.scissor = function ( scissor ) {
  18238. if ( currentScissor.equals( scissor ) === false ) {
  18239. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  18240. currentScissor.copy( scissor );
  18241. }
  18242. };
  18243. this.viewport = function ( viewport ) {
  18244. if ( currentViewport.equals( viewport ) === false ) {
  18245. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  18246. currentViewport.copy( viewport );
  18247. }
  18248. };
  18249. //
  18250. this.reset = function () {
  18251. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  18252. if ( enabledAttributes[ i ] === 1 ) {
  18253. gl.disableVertexAttribArray( i );
  18254. enabledAttributes[ i ] = 0;
  18255. }
  18256. }
  18257. capabilities = {};
  18258. compressedTextureFormats = null;
  18259. currentTextureSlot = undefined;
  18260. currentBoundTextures = {};
  18261. currentBlending = null;
  18262. currentColorWrite = null;
  18263. currentDepthWrite = null;
  18264. currentStencilWrite = null;
  18265. currentFlipSided = null;
  18266. };
  18267. };
  18268. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  18269. /**
  18270. * @author mikael emtinger / http://gomo.se/
  18271. * @author alteredq / http://alteredqualia.com/
  18272. */
  18273. THREE.LensFlarePlugin = function ( renderer, flares ) {
  18274. var gl = renderer.context;
  18275. var state = renderer.state;
  18276. var vertexBuffer, elementBuffer;
  18277. var program, attributes, uniforms;
  18278. var hasVertexTexture;
  18279. var tempTexture, occlusionTexture;
  18280. function init() {
  18281. var vertices = new Float32Array( [
  18282. - 1, - 1, 0, 0,
  18283. 1, - 1, 1, 0,
  18284. 1, 1, 1, 1,
  18285. - 1, 1, 0, 1
  18286. ] );
  18287. var faces = new Uint16Array( [
  18288. 0, 1, 2,
  18289. 0, 2, 3
  18290. ] );
  18291. // buffers
  18292. vertexBuffer = gl.createBuffer();
  18293. elementBuffer = gl.createBuffer();
  18294. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18295. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18296. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18297. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18298. // textures
  18299. tempTexture = gl.createTexture();
  18300. occlusionTexture = gl.createTexture();
  18301. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18302. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  18303. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18304. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18305. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18306. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18307. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18308. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  18309. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18310. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18311. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18312. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18313. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  18314. var shader;
  18315. if ( hasVertexTexture ) {
  18316. shader = {
  18317. vertexShader: [
  18318. "uniform lowp int renderType;",
  18319. "uniform vec3 screenPosition;",
  18320. "uniform vec2 scale;",
  18321. "uniform float rotation;",
  18322. "uniform sampler2D occlusionMap;",
  18323. "attribute vec2 position;",
  18324. "attribute vec2 uv;",
  18325. "varying vec2 vUV;",
  18326. "varying float vVisibility;",
  18327. "void main() {",
  18328. "vUV = uv;",
  18329. "vec2 pos = position;",
  18330. "if ( renderType == 2 ) {",
  18331. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  18332. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  18333. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  18334. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  18335. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  18336. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  18337. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  18338. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  18339. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  18340. "vVisibility = visibility.r / 9.0;",
  18341. "vVisibility *= 1.0 - visibility.g / 9.0;",
  18342. "vVisibility *= visibility.b / 9.0;",
  18343. "vVisibility *= 1.0 - visibility.a / 9.0;",
  18344. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18345. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18346. "}",
  18347. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18348. "}"
  18349. ].join( "\n" ),
  18350. fragmentShader: [
  18351. "uniform lowp int renderType;",
  18352. "uniform sampler2D map;",
  18353. "uniform float opacity;",
  18354. "uniform vec3 color;",
  18355. "varying vec2 vUV;",
  18356. "varying float vVisibility;",
  18357. "void main() {",
  18358. // pink square
  18359. "if ( renderType == 0 ) {",
  18360. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  18361. // restore
  18362. "} else if ( renderType == 1 ) {",
  18363. "gl_FragColor = texture2D( map, vUV );",
  18364. // flare
  18365. "} else {",
  18366. "vec4 texture = texture2D( map, vUV );",
  18367. "texture.a *= opacity * vVisibility;",
  18368. "gl_FragColor = texture;",
  18369. "gl_FragColor.rgb *= color;",
  18370. "}",
  18371. "}"
  18372. ].join( "\n" )
  18373. };
  18374. } else {
  18375. shader = {
  18376. vertexShader: [
  18377. "uniform lowp int renderType;",
  18378. "uniform vec3 screenPosition;",
  18379. "uniform vec2 scale;",
  18380. "uniform float rotation;",
  18381. "attribute vec2 position;",
  18382. "attribute vec2 uv;",
  18383. "varying vec2 vUV;",
  18384. "void main() {",
  18385. "vUV = uv;",
  18386. "vec2 pos = position;",
  18387. "if ( renderType == 2 ) {",
  18388. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18389. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18390. "}",
  18391. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18392. "}"
  18393. ].join( "\n" ),
  18394. fragmentShader: [
  18395. "precision mediump float;",
  18396. "uniform lowp int renderType;",
  18397. "uniform sampler2D map;",
  18398. "uniform sampler2D occlusionMap;",
  18399. "uniform float opacity;",
  18400. "uniform vec3 color;",
  18401. "varying vec2 vUV;",
  18402. "void main() {",
  18403. // pink square
  18404. "if ( renderType == 0 ) {",
  18405. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  18406. // restore
  18407. "} else if ( renderType == 1 ) {",
  18408. "gl_FragColor = texture2D( map, vUV );",
  18409. // flare
  18410. "} else {",
  18411. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  18412. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  18413. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  18414. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  18415. "visibility = ( 1.0 - visibility / 4.0 );",
  18416. "vec4 texture = texture2D( map, vUV );",
  18417. "texture.a *= opacity * visibility;",
  18418. "gl_FragColor = texture;",
  18419. "gl_FragColor.rgb *= color;",
  18420. "}",
  18421. "}"
  18422. ].join( "\n" )
  18423. };
  18424. }
  18425. program = createProgram( shader );
  18426. attributes = {
  18427. vertex: gl.getAttribLocation ( program, "position" ),
  18428. uv: gl.getAttribLocation ( program, "uv" )
  18429. };
  18430. uniforms = {
  18431. renderType: gl.getUniformLocation( program, "renderType" ),
  18432. map: gl.getUniformLocation( program, "map" ),
  18433. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  18434. opacity: gl.getUniformLocation( program, "opacity" ),
  18435. color: gl.getUniformLocation( program, "color" ),
  18436. scale: gl.getUniformLocation( program, "scale" ),
  18437. rotation: gl.getUniformLocation( program, "rotation" ),
  18438. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  18439. };
  18440. }
  18441. /*
  18442. * Render lens flares
  18443. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  18444. * reads these back and calculates occlusion.
  18445. */
  18446. this.render = function ( scene, camera, viewport ) {
  18447. if ( flares.length === 0 ) return;
  18448. var tempPosition = new THREE.Vector3();
  18449. var invAspect = viewport.w / viewport.z,
  18450. halfViewportWidth = viewport.z * 0.5,
  18451. halfViewportHeight = viewport.w * 0.5;
  18452. var size = 16 / viewport.w,
  18453. scale = new THREE.Vector2( size * invAspect, size );
  18454. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  18455. screenPositionPixels = new THREE.Vector2( 1, 1 );
  18456. if ( program === undefined ) {
  18457. init();
  18458. }
  18459. gl.useProgram( program );
  18460. state.initAttributes();
  18461. state.enableAttribute( attributes.vertex );
  18462. state.enableAttribute( attributes.uv );
  18463. state.disableUnusedAttributes();
  18464. // loop through all lens flares to update their occlusion and positions
  18465. // setup gl and common used attribs/uniforms
  18466. gl.uniform1i( uniforms.occlusionMap, 0 );
  18467. gl.uniform1i( uniforms.map, 1 );
  18468. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18469. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  18470. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  18471. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18472. state.disable( gl.CULL_FACE );
  18473. state.setDepthWrite( false );
  18474. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  18475. size = 16 / viewport.w;
  18476. scale.set( size * invAspect, size );
  18477. // calc object screen position
  18478. var flare = flares[ i ];
  18479. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  18480. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  18481. tempPosition.applyProjection( camera.projectionMatrix );
  18482. // setup arrays for gl programs
  18483. screenPosition.copy( tempPosition );
  18484. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  18485. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  18486. // screen cull
  18487. if ( hasVertexTexture || (
  18488. screenPositionPixels.x > 0 &&
  18489. screenPositionPixels.x < viewport.z &&
  18490. screenPositionPixels.y > 0 &&
  18491. screenPositionPixels.y < viewport.w ) ) {
  18492. // save current RGB to temp texture
  18493. state.activeTexture( gl.TEXTURE0 );
  18494. state.bindTexture( gl.TEXTURE_2D, null );
  18495. state.activeTexture( gl.TEXTURE1 );
  18496. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18497. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, viewport.x + screenPositionPixels.x - 8, viewport.y + screenPositionPixels.y - 8, 16, 16, 0 );
  18498. // render pink quad
  18499. gl.uniform1i( uniforms.renderType, 0 );
  18500. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18501. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18502. state.disable( gl.BLEND );
  18503. state.enable( gl.DEPTH_TEST );
  18504. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18505. // copy result to occlusionMap
  18506. state.activeTexture( gl.TEXTURE0 );
  18507. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18508. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, viewport.x + screenPositionPixels.x - 8, viewport.y + screenPositionPixels.y - 8, 16, 16, 0 );
  18509. // restore graphics
  18510. gl.uniform1i( uniforms.renderType, 1 );
  18511. state.disable( gl.DEPTH_TEST );
  18512. state.activeTexture( gl.TEXTURE1 );
  18513. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18514. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18515. // update object positions
  18516. flare.positionScreen.copy( screenPosition );
  18517. if ( flare.customUpdateCallback ) {
  18518. flare.customUpdateCallback( flare );
  18519. } else {
  18520. flare.updateLensFlares();
  18521. }
  18522. // render flares
  18523. gl.uniform1i( uniforms.renderType, 2 );
  18524. state.enable( gl.BLEND );
  18525. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  18526. var sprite = flare.lensFlares[ j ];
  18527. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  18528. screenPosition.x = sprite.x;
  18529. screenPosition.y = sprite.y;
  18530. screenPosition.z = sprite.z;
  18531. size = sprite.size * sprite.scale / viewport.w;
  18532. scale.x = size * invAspect;
  18533. scale.y = size;
  18534. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18535. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18536. gl.uniform1f( uniforms.rotation, sprite.rotation );
  18537. gl.uniform1f( uniforms.opacity, sprite.opacity );
  18538. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  18539. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  18540. renderer.setTexture( sprite.texture, 1 );
  18541. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18542. }
  18543. }
  18544. }
  18545. }
  18546. // restore gl
  18547. state.enable( gl.CULL_FACE );
  18548. state.enable( gl.DEPTH_TEST );
  18549. state.setDepthWrite( true );
  18550. renderer.resetGLState();
  18551. };
  18552. function createProgram ( shader ) {
  18553. var program = gl.createProgram();
  18554. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  18555. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  18556. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  18557. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  18558. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  18559. gl.compileShader( fragmentShader );
  18560. gl.compileShader( vertexShader );
  18561. gl.attachShader( program, fragmentShader );
  18562. gl.attachShader( program, vertexShader );
  18563. gl.linkProgram( program );
  18564. return program;
  18565. }
  18566. };
  18567. // File:src/renderers/webgl/plugins/SpritePlugin.js
  18568. /**
  18569. * @author mikael emtinger / http://gomo.se/
  18570. * @author alteredq / http://alteredqualia.com/
  18571. */
  18572. THREE.SpritePlugin = function ( renderer, sprites ) {
  18573. var gl = renderer.context;
  18574. var state = renderer.state;
  18575. var vertexBuffer, elementBuffer;
  18576. var program, attributes, uniforms;
  18577. var texture;
  18578. // decompose matrixWorld
  18579. var spritePosition = new THREE.Vector3();
  18580. var spriteRotation = new THREE.Quaternion();
  18581. var spriteScale = new THREE.Vector3();
  18582. function init() {
  18583. var vertices = new Float32Array( [
  18584. - 0.5, - 0.5, 0, 0,
  18585. 0.5, - 0.5, 1, 0,
  18586. 0.5, 0.5, 1, 1,
  18587. - 0.5, 0.5, 0, 1
  18588. ] );
  18589. var faces = new Uint16Array( [
  18590. 0, 1, 2,
  18591. 0, 2, 3
  18592. ] );
  18593. vertexBuffer = gl.createBuffer();
  18594. elementBuffer = gl.createBuffer();
  18595. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18596. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18597. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18598. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18599. program = createProgram();
  18600. attributes = {
  18601. position: gl.getAttribLocation ( program, 'position' ),
  18602. uv: gl.getAttribLocation ( program, 'uv' )
  18603. };
  18604. uniforms = {
  18605. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  18606. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  18607. rotation: gl.getUniformLocation( program, 'rotation' ),
  18608. scale: gl.getUniformLocation( program, 'scale' ),
  18609. color: gl.getUniformLocation( program, 'color' ),
  18610. map: gl.getUniformLocation( program, 'map' ),
  18611. opacity: gl.getUniformLocation( program, 'opacity' ),
  18612. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  18613. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  18614. fogType: gl.getUniformLocation( program, 'fogType' ),
  18615. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  18616. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  18617. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  18618. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  18619. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  18620. };
  18621. var canvas = document.createElement( 'canvas' );
  18622. canvas.width = 8;
  18623. canvas.height = 8;
  18624. var context = canvas.getContext( '2d' );
  18625. context.fillStyle = 'white';
  18626. context.fillRect( 0, 0, 8, 8 );
  18627. texture = new THREE.Texture( canvas );
  18628. texture.needsUpdate = true;
  18629. }
  18630. this.render = function ( scene, camera ) {
  18631. if ( sprites.length === 0 ) return;
  18632. // setup gl
  18633. if ( program === undefined ) {
  18634. init();
  18635. }
  18636. gl.useProgram( program );
  18637. state.initAttributes();
  18638. state.enableAttribute( attributes.position );
  18639. state.enableAttribute( attributes.uv );
  18640. state.disableUnusedAttributes();
  18641. state.disable( gl.CULL_FACE );
  18642. state.enable( gl.BLEND );
  18643. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18644. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  18645. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  18646. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18647. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  18648. state.activeTexture( gl.TEXTURE0 );
  18649. gl.uniform1i( uniforms.map, 0 );
  18650. var oldFogType = 0;
  18651. var sceneFogType = 0;
  18652. var fog = scene.fog;
  18653. if ( fog ) {
  18654. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  18655. if ( fog instanceof THREE.Fog ) {
  18656. gl.uniform1f( uniforms.fogNear, fog.near );
  18657. gl.uniform1f( uniforms.fogFar, fog.far );
  18658. gl.uniform1i( uniforms.fogType, 1 );
  18659. oldFogType = 1;
  18660. sceneFogType = 1;
  18661. } else if ( fog instanceof THREE.FogExp2 ) {
  18662. gl.uniform1f( uniforms.fogDensity, fog.density );
  18663. gl.uniform1i( uniforms.fogType, 2 );
  18664. oldFogType = 2;
  18665. sceneFogType = 2;
  18666. }
  18667. } else {
  18668. gl.uniform1i( uniforms.fogType, 0 );
  18669. oldFogType = 0;
  18670. sceneFogType = 0;
  18671. }
  18672. // update positions and sort
  18673. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  18674. var sprite = sprites[ i ];
  18675. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  18676. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  18677. }
  18678. sprites.sort( painterSortStable );
  18679. // render all sprites
  18680. var scale = [];
  18681. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  18682. var sprite = sprites[ i ];
  18683. var material = sprite.material;
  18684. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  18685. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  18686. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  18687. scale[ 0 ] = spriteScale.x;
  18688. scale[ 1 ] = spriteScale.y;
  18689. var fogType = 0;
  18690. if ( scene.fog && material.fog ) {
  18691. fogType = sceneFogType;
  18692. }
  18693. if ( oldFogType !== fogType ) {
  18694. gl.uniform1i( uniforms.fogType, fogType );
  18695. oldFogType = fogType;
  18696. }
  18697. if ( material.map !== null ) {
  18698. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  18699. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  18700. } else {
  18701. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  18702. gl.uniform2f( uniforms.uvScale, 1, 1 );
  18703. }
  18704. gl.uniform1f( uniforms.opacity, material.opacity );
  18705. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  18706. gl.uniform1f( uniforms.rotation, material.rotation );
  18707. gl.uniform2fv( uniforms.scale, scale );
  18708. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  18709. state.setDepthTest( material.depthTest );
  18710. state.setDepthWrite( material.depthWrite );
  18711. if ( material.map && material.map.image && material.map.image.width ) {
  18712. renderer.setTexture( material.map, 0 );
  18713. } else {
  18714. renderer.setTexture( texture, 0 );
  18715. }
  18716. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18717. }
  18718. // restore gl
  18719. state.enable( gl.CULL_FACE );
  18720. renderer.resetGLState();
  18721. };
  18722. function createProgram () {
  18723. var program = gl.createProgram();
  18724. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  18725. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  18726. gl.shaderSource( vertexShader, [
  18727. 'precision ' + renderer.getPrecision() + ' float;',
  18728. 'uniform mat4 modelViewMatrix;',
  18729. 'uniform mat4 projectionMatrix;',
  18730. 'uniform float rotation;',
  18731. 'uniform vec2 scale;',
  18732. 'uniform vec2 uvOffset;',
  18733. 'uniform vec2 uvScale;',
  18734. 'attribute vec2 position;',
  18735. 'attribute vec2 uv;',
  18736. 'varying vec2 vUV;',
  18737. 'void main() {',
  18738. 'vUV = uvOffset + uv * uvScale;',
  18739. 'vec2 alignedPosition = position * scale;',
  18740. 'vec2 rotatedPosition;',
  18741. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  18742. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  18743. 'vec4 finalPosition;',
  18744. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  18745. 'finalPosition.xy += rotatedPosition;',
  18746. 'finalPosition = projectionMatrix * finalPosition;',
  18747. 'gl_Position = finalPosition;',
  18748. '}'
  18749. ].join( '\n' ) );
  18750. gl.shaderSource( fragmentShader, [
  18751. 'precision ' + renderer.getPrecision() + ' float;',
  18752. 'uniform vec3 color;',
  18753. 'uniform sampler2D map;',
  18754. 'uniform float opacity;',
  18755. 'uniform int fogType;',
  18756. 'uniform vec3 fogColor;',
  18757. 'uniform float fogDensity;',
  18758. 'uniform float fogNear;',
  18759. 'uniform float fogFar;',
  18760. 'uniform float alphaTest;',
  18761. 'varying vec2 vUV;',
  18762. 'void main() {',
  18763. 'vec4 texture = texture2D( map, vUV );',
  18764. 'if ( texture.a < alphaTest ) discard;',
  18765. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  18766. 'if ( fogType > 0 ) {',
  18767. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  18768. 'float fogFactor = 0.0;',
  18769. 'if ( fogType == 1 ) {',
  18770. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  18771. '} else {',
  18772. 'const float LOG2 = 1.442695;',
  18773. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  18774. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  18775. '}',
  18776. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  18777. '}',
  18778. '}'
  18779. ].join( '\n' ) );
  18780. gl.compileShader( vertexShader );
  18781. gl.compileShader( fragmentShader );
  18782. gl.attachShader( program, vertexShader );
  18783. gl.attachShader( program, fragmentShader );
  18784. gl.linkProgram( program );
  18785. return program;
  18786. }
  18787. function painterSortStable ( a, b ) {
  18788. if ( a.renderOrder !== b.renderOrder ) {
  18789. return a.renderOrder - b.renderOrder;
  18790. } else if ( a.z !== b.z ) {
  18791. return b.z - a.z;
  18792. } else {
  18793. return b.id - a.id;
  18794. }
  18795. }
  18796. };
  18797. // File:src/Three.Legacy.js
  18798. /**
  18799. * @author mrdoob / http://mrdoob.com/
  18800. */
  18801. Object.defineProperties( THREE.Box2.prototype, {
  18802. empty: {
  18803. value: function () {
  18804. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  18805. return this.isEmpty();
  18806. }
  18807. },
  18808. isIntersectionBox: {
  18809. value: function ( box ) {
  18810. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18811. return this.intersectsBox( box );
  18812. }
  18813. }
  18814. } );
  18815. Object.defineProperties( THREE.Box3.prototype, {
  18816. empty: {
  18817. value: function () {
  18818. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  18819. return this.isEmpty();
  18820. }
  18821. },
  18822. isIntersectionBox: {
  18823. value: function ( box ) {
  18824. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18825. return this.intersectsBox( box );
  18826. }
  18827. },
  18828. isIntersectionSphere: {
  18829. value: function ( sphere ) {
  18830. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  18831. return this.intersectsSphere( sphere );
  18832. }
  18833. }
  18834. } );
  18835. Object.defineProperties( THREE.Matrix3.prototype, {
  18836. multiplyVector3: {
  18837. value: function ( vector ) {
  18838. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  18839. return vector.applyMatrix3( this );
  18840. }
  18841. },
  18842. multiplyVector3Array: {
  18843. value: function ( a ) {
  18844. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  18845. return this.applyToVector3Array( a );
  18846. }
  18847. }
  18848. } );
  18849. Object.defineProperties( THREE.Matrix4.prototype, {
  18850. extractPosition: {
  18851. value: function ( m ) {
  18852. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  18853. return this.copyPosition( m );
  18854. }
  18855. },
  18856. setRotationFromQuaternion: {
  18857. value: function ( q ) {
  18858. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  18859. return this.makeRotationFromQuaternion( q );
  18860. }
  18861. },
  18862. multiplyVector3: {
  18863. value: function ( vector ) {
  18864. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  18865. return vector.applyProjection( this );
  18866. }
  18867. },
  18868. multiplyVector4: {
  18869. value: function ( vector ) {
  18870. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  18871. return vector.applyMatrix4( this );
  18872. }
  18873. },
  18874. multiplyVector3Array: {
  18875. value: function ( a ) {
  18876. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  18877. return this.applyToVector3Array( a );
  18878. }
  18879. },
  18880. rotateAxis: {
  18881. value: function ( v ) {
  18882. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  18883. v.transformDirection( this );
  18884. }
  18885. },
  18886. crossVector: {
  18887. value: function ( vector ) {
  18888. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  18889. return vector.applyMatrix4( this );
  18890. }
  18891. },
  18892. translate: {
  18893. value: function ( v ) {
  18894. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  18895. }
  18896. },
  18897. rotateX: {
  18898. value: function ( angle ) {
  18899. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  18900. }
  18901. },
  18902. rotateY: {
  18903. value: function ( angle ) {
  18904. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  18905. }
  18906. },
  18907. rotateZ: {
  18908. value: function ( angle ) {
  18909. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  18910. }
  18911. },
  18912. rotateByAxis: {
  18913. value: function ( axis, angle ) {
  18914. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  18915. }
  18916. }
  18917. } );
  18918. Object.defineProperties( THREE.Plane.prototype, {
  18919. isIntersectionLine: {
  18920. value: function ( line ) {
  18921. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  18922. return this.intersectsLine( line );
  18923. }
  18924. }
  18925. } );
  18926. Object.defineProperties( THREE.Quaternion.prototype, {
  18927. multiplyVector3: {
  18928. value: function ( vector ) {
  18929. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  18930. return vector.applyQuaternion( this );
  18931. }
  18932. }
  18933. } );
  18934. Object.defineProperties( THREE.Ray.prototype, {
  18935. isIntersectionBox: {
  18936. value: function ( box ) {
  18937. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18938. return this.intersectsBox( box );
  18939. }
  18940. },
  18941. isIntersectionPlane: {
  18942. value: function ( plane ) {
  18943. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  18944. return this.intersectsPlane( plane );
  18945. }
  18946. },
  18947. isIntersectionSphere: {
  18948. value: function ( sphere ) {
  18949. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  18950. return this.intersectsSphere( sphere );
  18951. }
  18952. }
  18953. } );
  18954. Object.defineProperties( THREE.Vector3.prototype, {
  18955. setEulerFromRotationMatrix: {
  18956. value: function () {
  18957. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  18958. }
  18959. },
  18960. setEulerFromQuaternion: {
  18961. value: function () {
  18962. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  18963. }
  18964. },
  18965. getPositionFromMatrix: {
  18966. value: function ( m ) {
  18967. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  18968. return this.setFromMatrixPosition( m );
  18969. }
  18970. },
  18971. getScaleFromMatrix: {
  18972. value: function ( m ) {
  18973. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  18974. return this.setFromMatrixScale( m );
  18975. }
  18976. },
  18977. getColumnFromMatrix: {
  18978. value: function ( index, matrix ) {
  18979. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  18980. return this.setFromMatrixColumn( index, matrix );
  18981. }
  18982. }
  18983. } );
  18984. //
  18985. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  18986. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  18987. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  18988. };
  18989. THREE.Vertex = function ( x, y, z ) {
  18990. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  18991. return new THREE.Vector3( x, y, z );
  18992. };
  18993. //
  18994. Object.defineProperties( THREE.Object3D.prototype, {
  18995. eulerOrder: {
  18996. get: function () {
  18997. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  18998. return this.rotation.order;
  18999. },
  19000. set: function ( value ) {
  19001. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19002. this.rotation.order = value;
  19003. }
  19004. },
  19005. getChildByName: {
  19006. value: function ( name ) {
  19007. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  19008. return this.getObjectByName( name );
  19009. }
  19010. },
  19011. renderDepth: {
  19012. set: function ( value ) {
  19013. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  19014. }
  19015. },
  19016. translate: {
  19017. value: function ( distance, axis ) {
  19018. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  19019. return this.translateOnAxis( axis, distance );
  19020. }
  19021. },
  19022. useQuaternion: {
  19023. get: function () {
  19024. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19025. },
  19026. set: function ( value ) {
  19027. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19028. }
  19029. }
  19030. } );
  19031. //
  19032. Object.defineProperties( THREE, {
  19033. PointCloud: {
  19034. value: function ( geometry, material ) {
  19035. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  19036. return new THREE.Points( geometry, material );
  19037. }
  19038. },
  19039. ParticleSystem: {
  19040. value: function ( geometry, material ) {
  19041. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  19042. return new THREE.Points( geometry, material );
  19043. }
  19044. }
  19045. } );
  19046. //
  19047. Object.defineProperties( THREE.Light.prototype, {
  19048. onlyShadow: {
  19049. set: function ( value ) {
  19050. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  19051. }
  19052. },
  19053. shadowCameraFov: {
  19054. set: function ( value ) {
  19055. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  19056. this.shadow.camera.fov = value;
  19057. }
  19058. },
  19059. shadowCameraLeft: {
  19060. set: function ( value ) {
  19061. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  19062. this.shadow.camera.left = value;
  19063. }
  19064. },
  19065. shadowCameraRight: {
  19066. set: function ( value ) {
  19067. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  19068. this.shadow.camera.right = value;
  19069. }
  19070. },
  19071. shadowCameraTop: {
  19072. set: function ( value ) {
  19073. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  19074. this.shadow.camera.top = value;
  19075. }
  19076. },
  19077. shadowCameraBottom: {
  19078. set: function ( value ) {
  19079. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  19080. this.shadow.camera.bottom = value;
  19081. }
  19082. },
  19083. shadowCameraNear: {
  19084. set: function ( value ) {
  19085. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  19086. this.shadow.camera.near = value;
  19087. }
  19088. },
  19089. shadowCameraFar: {
  19090. set: function ( value ) {
  19091. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  19092. this.shadow.camera.far = value;
  19093. }
  19094. },
  19095. shadowCameraVisible: {
  19096. set: function ( value ) {
  19097. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  19098. }
  19099. },
  19100. shadowBias: {
  19101. set: function ( value ) {
  19102. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  19103. this.shadow.bias = value;
  19104. }
  19105. },
  19106. shadowDarkness: {
  19107. set: function ( value ) {
  19108. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  19109. }
  19110. },
  19111. shadowMapWidth: {
  19112. set: function ( value ) {
  19113. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  19114. this.shadow.mapSize.width = value;
  19115. }
  19116. },
  19117. shadowMapHeight: {
  19118. set: function ( value ) {
  19119. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  19120. this.shadow.mapSize.height = value;
  19121. }
  19122. }
  19123. } );
  19124. //
  19125. Object.defineProperties( THREE.BufferAttribute.prototype, {
  19126. length: {
  19127. get: function () {
  19128. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  19129. return this.array.length;
  19130. }
  19131. }
  19132. } );
  19133. Object.defineProperties( THREE.BufferGeometry.prototype, {
  19134. drawcalls: {
  19135. get: function () {
  19136. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  19137. return this.groups;
  19138. }
  19139. },
  19140. offsets: {
  19141. get: function () {
  19142. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  19143. return this.groups;
  19144. }
  19145. },
  19146. addIndex: {
  19147. value: function ( index ) {
  19148. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  19149. this.setIndex( index );
  19150. }
  19151. },
  19152. addDrawCall: {
  19153. value: function ( start, count, indexOffset ) {
  19154. if ( indexOffset !== undefined ) {
  19155. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  19156. }
  19157. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  19158. this.addGroup( start, count );
  19159. }
  19160. },
  19161. clearDrawCalls: {
  19162. value: function () {
  19163. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  19164. this.clearGroups();
  19165. }
  19166. },
  19167. computeTangents: {
  19168. value: function () {
  19169. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  19170. }
  19171. },
  19172. computeOffsets: {
  19173. value: function () {
  19174. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  19175. }
  19176. }
  19177. } );
  19178. //
  19179. Object.defineProperties( THREE.Material.prototype, {
  19180. wrapAround: {
  19181. get: function () {
  19182. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19183. },
  19184. set: function ( value ) {
  19185. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19186. }
  19187. },
  19188. wrapRGB: {
  19189. get: function () {
  19190. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  19191. return new THREE.Color();
  19192. }
  19193. }
  19194. } );
  19195. Object.defineProperties( THREE, {
  19196. PointCloudMaterial: {
  19197. value: function ( parameters ) {
  19198. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  19199. return new THREE.PointsMaterial( parameters );
  19200. }
  19201. },
  19202. ParticleBasicMaterial: {
  19203. value: function ( parameters ) {
  19204. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  19205. return new THREE.PointsMaterial( parameters );
  19206. }
  19207. },
  19208. ParticleSystemMaterial:{
  19209. value: function ( parameters ) {
  19210. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  19211. return new THREE.PointsMaterial( parameters );
  19212. }
  19213. }
  19214. } );
  19215. Object.defineProperties( THREE.MeshPhongMaterial.prototype, {
  19216. metal: {
  19217. get: function () {
  19218. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  19219. return false;
  19220. },
  19221. set: function ( value ) {
  19222. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  19223. }
  19224. }
  19225. } );
  19226. Object.defineProperties( THREE.ShaderMaterial.prototype, {
  19227. derivatives: {
  19228. get: function () {
  19229. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19230. return this.extensions.derivatives;
  19231. },
  19232. set: function ( value ) {
  19233. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19234. this.extensions.derivatives = value;
  19235. }
  19236. }
  19237. } );
  19238. //
  19239. Object.defineProperties( THREE.WebGLRenderer.prototype, {
  19240. supportsFloatTextures: {
  19241. value: function () {
  19242. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  19243. return this.extensions.get( 'OES_texture_float' );
  19244. }
  19245. },
  19246. supportsHalfFloatTextures: {
  19247. value: function () {
  19248. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  19249. return this.extensions.get( 'OES_texture_half_float' );
  19250. }
  19251. },
  19252. supportsStandardDerivatives: {
  19253. value: function () {
  19254. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  19255. return this.extensions.get( 'OES_standard_derivatives' );
  19256. }
  19257. },
  19258. supportsCompressedTextureS3TC: {
  19259. value: function () {
  19260. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  19261. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  19262. }
  19263. },
  19264. supportsCompressedTexturePVRTC: {
  19265. value: function () {
  19266. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  19267. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  19268. }
  19269. },
  19270. supportsBlendMinMax: {
  19271. value: function () {
  19272. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  19273. return this.extensions.get( 'EXT_blend_minmax' );
  19274. }
  19275. },
  19276. supportsVertexTextures: {
  19277. value: function () {
  19278. return this.capabilities.vertexTextures;
  19279. }
  19280. },
  19281. supportsInstancedArrays: {
  19282. value: function () {
  19283. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  19284. return this.extensions.get( 'ANGLE_instanced_arrays' );
  19285. }
  19286. },
  19287. enableScissorTest: {
  19288. value: function ( boolean ) {
  19289. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  19290. this.setScissorTest( boolean );
  19291. }
  19292. },
  19293. initMaterial: {
  19294. value: function () {
  19295. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  19296. }
  19297. },
  19298. addPrePlugin: {
  19299. value: function () {
  19300. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  19301. }
  19302. },
  19303. addPostPlugin: {
  19304. value: function () {
  19305. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  19306. }
  19307. },
  19308. updateShadowMap: {
  19309. value: function () {
  19310. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  19311. }
  19312. },
  19313. shadowMapEnabled: {
  19314. get: function () {
  19315. return this.shadowMap.enabled;
  19316. },
  19317. set: function ( value ) {
  19318. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  19319. this.shadowMap.enabled = value;
  19320. }
  19321. },
  19322. shadowMapType: {
  19323. get: function () {
  19324. return this.shadowMap.type;
  19325. },
  19326. set: function ( value ) {
  19327. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  19328. this.shadowMap.type = value;
  19329. }
  19330. },
  19331. shadowMapCullFace: {
  19332. get: function () {
  19333. return this.shadowMap.cullFace;
  19334. },
  19335. set: function ( value ) {
  19336. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  19337. this.shadowMap.cullFace = value;
  19338. }
  19339. }
  19340. } );
  19341. //
  19342. Object.defineProperties( THREE.WebGLRenderTarget.prototype, {
  19343. wrapS: {
  19344. get: function () {
  19345. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19346. return this.texture.wrapS;
  19347. },
  19348. set: function ( value ) {
  19349. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19350. this.texture.wrapS = value;
  19351. }
  19352. },
  19353. wrapT: {
  19354. get: function () {
  19355. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19356. return this.texture.wrapT;
  19357. },
  19358. set: function ( value ) {
  19359. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19360. this.texture.wrapT = value;
  19361. }
  19362. },
  19363. magFilter: {
  19364. get: function () {
  19365. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19366. return this.texture.magFilter;
  19367. },
  19368. set: function ( value ) {
  19369. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19370. this.texture.magFilter = value;
  19371. }
  19372. },
  19373. minFilter: {
  19374. get: function () {
  19375. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19376. return this.texture.minFilter;
  19377. },
  19378. set: function ( value ) {
  19379. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19380. this.texture.minFilter = value;
  19381. }
  19382. },
  19383. anisotropy: {
  19384. get: function () {
  19385. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19386. return this.texture.anisotropy;
  19387. },
  19388. set: function ( value ) {
  19389. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19390. this.texture.anisotropy = value;
  19391. }
  19392. },
  19393. offset: {
  19394. get: function () {
  19395. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19396. return this.texture.offset;
  19397. },
  19398. set: function ( value ) {
  19399. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19400. this.texture.offset = value;
  19401. }
  19402. },
  19403. repeat: {
  19404. get: function () {
  19405. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19406. return this.texture.repeat;
  19407. },
  19408. set: function ( value ) {
  19409. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19410. this.texture.repeat = value;
  19411. }
  19412. },
  19413. format: {
  19414. get: function () {
  19415. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19416. return this.texture.format;
  19417. },
  19418. set: function ( value ) {
  19419. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19420. this.texture.format = value;
  19421. }
  19422. },
  19423. type: {
  19424. get: function () {
  19425. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19426. return this.texture.type;
  19427. },
  19428. set: function ( value ) {
  19429. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19430. this.texture.type = value;
  19431. }
  19432. },
  19433. generateMipmaps: {
  19434. get: function () {
  19435. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19436. return this.texture.generateMipmaps;
  19437. },
  19438. set: function ( value ) {
  19439. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19440. this.texture.generateMipmaps = value;
  19441. }
  19442. }
  19443. } );
  19444. //
  19445. THREE.GeometryUtils = {
  19446. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  19447. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  19448. var matrix;
  19449. if ( geometry2 instanceof THREE.Mesh ) {
  19450. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  19451. matrix = geometry2.matrix;
  19452. geometry2 = geometry2.geometry;
  19453. }
  19454. geometry1.merge( geometry2, matrix, materialIndexOffset );
  19455. },
  19456. center: function ( geometry ) {
  19457. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  19458. return geometry.center();
  19459. }
  19460. };
  19461. THREE.ImageUtils = {
  19462. crossOrigin: undefined,
  19463. loadTexture: function ( url, mapping, onLoad, onError ) {
  19464. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  19465. var loader = new THREE.TextureLoader();
  19466. loader.setCrossOrigin( this.crossOrigin );
  19467. var texture = loader.load( url, onLoad, undefined, onError );
  19468. if ( mapping ) texture.mapping = mapping;
  19469. return texture;
  19470. },
  19471. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  19472. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  19473. var loader = new THREE.CubeTextureLoader();
  19474. loader.setCrossOrigin( this.crossOrigin );
  19475. var texture = loader.load( urls, onLoad, undefined, onError );
  19476. if ( mapping ) texture.mapping = mapping;
  19477. return texture;
  19478. },
  19479. loadCompressedTexture: function () {
  19480. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  19481. },
  19482. loadCompressedTextureCube: function () {
  19483. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  19484. }
  19485. };
  19486. //
  19487. THREE.Projector = function () {
  19488. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  19489. this.projectVector = function ( vector, camera ) {
  19490. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  19491. vector.project( camera );
  19492. };
  19493. this.unprojectVector = function ( vector, camera ) {
  19494. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  19495. vector.unproject( camera );
  19496. };
  19497. this.pickingRay = function ( vector, camera ) {
  19498. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  19499. };
  19500. };
  19501. //
  19502. THREE.CanvasRenderer = function () {
  19503. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  19504. this.domElement = document.createElement( 'canvas' );
  19505. this.clear = function () {};
  19506. this.render = function () {};
  19507. this.setClearColor = function () {};
  19508. this.setSize = function () {};
  19509. };
  19510. //
  19511. THREE.MeshFaceMaterial = THREE.MultiMaterial;
  19512. // File:src/extras/CurveUtils.js
  19513. /**
  19514. * @author zz85 / http://www.lab4games.net/zz85/blog
  19515. */
  19516. THREE.CurveUtils = {
  19517. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  19518. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  19519. },
  19520. // Puay Bing, thanks for helping with this derivative!
  19521. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  19522. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  19523. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  19524. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  19525. 3 * t * t * p3;
  19526. },
  19527. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  19528. // To check if my formulas are correct
  19529. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  19530. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  19531. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  19532. var h11 = 3 * t * t - 2 * t; // t3 − t2
  19533. return h00 + h10 + h01 + h11;
  19534. },
  19535. // Catmull-Rom
  19536. interpolate: function( p0, p1, p2, p3, t ) {
  19537. var v0 = ( p2 - p0 ) * 0.5;
  19538. var v1 = ( p3 - p1 ) * 0.5;
  19539. var t2 = t * t;
  19540. var t3 = t * t2;
  19541. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  19542. }
  19543. };
  19544. // File:src/extras/SceneUtils.js
  19545. /**
  19546. * @author alteredq / http://alteredqualia.com/
  19547. */
  19548. THREE.SceneUtils = {
  19549. createMultiMaterialObject: function ( geometry, materials ) {
  19550. var group = new THREE.Group();
  19551. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  19552. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  19553. }
  19554. return group;
  19555. },
  19556. detach: function ( child, parent, scene ) {
  19557. child.applyMatrix( parent.matrixWorld );
  19558. parent.remove( child );
  19559. scene.add( child );
  19560. },
  19561. attach: function ( child, scene, parent ) {
  19562. var matrixWorldInverse = new THREE.Matrix4();
  19563. matrixWorldInverse.getInverse( parent.matrixWorld );
  19564. child.applyMatrix( matrixWorldInverse );
  19565. scene.remove( child );
  19566. parent.add( child );
  19567. }
  19568. };
  19569. // File:src/extras/ShapeUtils.js
  19570. /**
  19571. * @author zz85 / http://www.lab4games.net/zz85/blog
  19572. */
  19573. THREE.ShapeUtils = {
  19574. // calculate area of the contour polygon
  19575. area: function ( contour ) {
  19576. var n = contour.length;
  19577. var a = 0.0;
  19578. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  19579. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  19580. }
  19581. return a * 0.5;
  19582. },
  19583. triangulate: ( function () {
  19584. /**
  19585. * This code is a quick port of code written in C++ which was submitted to
  19586. * flipcode.com by John W. Ratcliff // July 22, 2000
  19587. * See original code and more information here:
  19588. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  19589. *
  19590. * ported to actionscript by Zevan Rosser
  19591. * www.actionsnippet.com
  19592. *
  19593. * ported to javascript by Joshua Koo
  19594. * http://www.lab4games.net/zz85/blog
  19595. *
  19596. */
  19597. function snip( contour, u, v, w, n, verts ) {
  19598. var p;
  19599. var ax, ay, bx, by;
  19600. var cx, cy, px, py;
  19601. ax = contour[ verts[ u ] ].x;
  19602. ay = contour[ verts[ u ] ].y;
  19603. bx = contour[ verts[ v ] ].x;
  19604. by = contour[ verts[ v ] ].y;
  19605. cx = contour[ verts[ w ] ].x;
  19606. cy = contour[ verts[ w ] ].y;
  19607. if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  19608. var aX, aY, bX, bY, cX, cY;
  19609. var apx, apy, bpx, bpy, cpx, cpy;
  19610. var cCROSSap, bCROSScp, aCROSSbp;
  19611. aX = cx - bx; aY = cy - by;
  19612. bX = ax - cx; bY = ay - cy;
  19613. cX = bx - ax; cY = by - ay;
  19614. for ( p = 0; p < n; p ++ ) {
  19615. px = contour[ verts[ p ] ].x;
  19616. py = contour[ verts[ p ] ].y;
  19617. if ( ( ( px === ax ) && ( py === ay ) ) ||
  19618. ( ( px === bx ) && ( py === by ) ) ||
  19619. ( ( px === cx ) && ( py === cy ) ) ) continue;
  19620. apx = px - ax; apy = py - ay;
  19621. bpx = px - bx; bpy = py - by;
  19622. cpx = px - cx; cpy = py - cy;
  19623. // see if p is inside triangle abc
  19624. aCROSSbp = aX * bpy - aY * bpx;
  19625. cCROSSap = cX * apy - cY * apx;
  19626. bCROSScp = bX * cpy - bY * cpx;
  19627. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  19628. }
  19629. return true;
  19630. }
  19631. // takes in an contour array and returns
  19632. return function ( contour, indices ) {
  19633. var n = contour.length;
  19634. if ( n < 3 ) return null;
  19635. var result = [],
  19636. verts = [],
  19637. vertIndices = [];
  19638. /* we want a counter-clockwise polygon in verts */
  19639. var u, v, w;
  19640. if ( THREE.ShapeUtils.area( contour ) > 0.0 ) {
  19641. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  19642. } else {
  19643. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  19644. }
  19645. var nv = n;
  19646. /* remove nv - 2 vertices, creating 1 triangle every time */
  19647. var count = 2 * nv; /* error detection */
  19648. for ( v = nv - 1; nv > 2; ) {
  19649. /* if we loop, it is probably a non-simple polygon */
  19650. if ( ( count -- ) <= 0 ) {
  19651. //** Triangulate: ERROR - probable bad polygon!
  19652. //throw ( "Warning, unable to triangulate polygon!" );
  19653. //return null;
  19654. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  19655. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  19656. if ( indices ) return vertIndices;
  19657. return result;
  19658. }
  19659. /* three consecutive vertices in current polygon, <u,v,w> */
  19660. u = v; if ( nv <= u ) u = 0; /* previous */
  19661. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  19662. w = v + 1; if ( nv <= w ) w = 0; /* next */
  19663. if ( snip( contour, u, v, w, nv, verts ) ) {
  19664. var a, b, c, s, t;
  19665. /* true names of the vertices */
  19666. a = verts[ u ];
  19667. b = verts[ v ];
  19668. c = verts[ w ];
  19669. /* output Triangle */
  19670. result.push( [ contour[ a ],
  19671. contour[ b ],
  19672. contour[ c ] ] );
  19673. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  19674. /* remove v from the remaining polygon */
  19675. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  19676. verts[ s ] = verts[ t ];
  19677. }
  19678. nv --;
  19679. /* reset error detection counter */
  19680. count = 2 * nv;
  19681. }
  19682. }
  19683. if ( indices ) return vertIndices;
  19684. return result;
  19685. }
  19686. } )(),
  19687. triangulateShape: function ( contour, holes ) {
  19688. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  19689. // inOtherPt needs to be collinear to the inSegment
  19690. if ( inSegPt1.x !== inSegPt2.x ) {
  19691. if ( inSegPt1.x < inSegPt2.x ) {
  19692. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  19693. } else {
  19694. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  19695. }
  19696. } else {
  19697. if ( inSegPt1.y < inSegPt2.y ) {
  19698. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  19699. } else {
  19700. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  19701. }
  19702. }
  19703. }
  19704. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  19705. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  19706. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  19707. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  19708. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  19709. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  19710. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  19711. if ( Math.abs( limit ) > Number.EPSILON ) {
  19712. // not parallel
  19713. var perpSeg2;
  19714. if ( limit > 0 ) {
  19715. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  19716. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  19717. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  19718. } else {
  19719. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  19720. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  19721. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  19722. }
  19723. // i.e. to reduce rounding errors
  19724. // intersection at endpoint of segment#1?
  19725. if ( perpSeg2 === 0 ) {
  19726. if ( ( inExcludeAdjacentSegs ) &&
  19727. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  19728. return [ inSeg1Pt1 ];
  19729. }
  19730. if ( perpSeg2 === limit ) {
  19731. if ( ( inExcludeAdjacentSegs ) &&
  19732. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  19733. return [ inSeg1Pt2 ];
  19734. }
  19735. // intersection at endpoint of segment#2?
  19736. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  19737. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  19738. // return real intersection point
  19739. var factorSeg1 = perpSeg2 / limit;
  19740. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  19741. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  19742. } else {
  19743. // parallel or collinear
  19744. if ( ( perpSeg1 !== 0 ) ||
  19745. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  19746. // they are collinear or degenerate
  19747. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  19748. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  19749. // both segments are points
  19750. if ( seg1Pt && seg2Pt ) {
  19751. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  19752. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  19753. return [ inSeg1Pt1 ]; // they are the same point
  19754. }
  19755. // segment#1 is a single point
  19756. if ( seg1Pt ) {
  19757. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  19758. return [ inSeg1Pt1 ];
  19759. }
  19760. // segment#2 is a single point
  19761. if ( seg2Pt ) {
  19762. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  19763. return [ inSeg2Pt1 ];
  19764. }
  19765. // they are collinear segments, which might overlap
  19766. var seg1min, seg1max, seg1minVal, seg1maxVal;
  19767. var seg2min, seg2max, seg2minVal, seg2maxVal;
  19768. if ( seg1dx !== 0 ) {
  19769. // the segments are NOT on a vertical line
  19770. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  19771. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  19772. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  19773. } else {
  19774. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  19775. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  19776. }
  19777. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  19778. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  19779. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  19780. } else {
  19781. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  19782. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  19783. }
  19784. } else {
  19785. // the segments are on a vertical line
  19786. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  19787. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  19788. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  19789. } else {
  19790. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  19791. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  19792. }
  19793. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  19794. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  19795. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  19796. } else {
  19797. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  19798. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  19799. }
  19800. }
  19801. if ( seg1minVal <= seg2minVal ) {
  19802. if ( seg1maxVal < seg2minVal ) return [];
  19803. if ( seg1maxVal === seg2minVal ) {
  19804. if ( inExcludeAdjacentSegs ) return [];
  19805. return [ seg2min ];
  19806. }
  19807. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  19808. return [ seg2min, seg2max ];
  19809. } else {
  19810. if ( seg1minVal > seg2maxVal ) return [];
  19811. if ( seg1minVal === seg2maxVal ) {
  19812. if ( inExcludeAdjacentSegs ) return [];
  19813. return [ seg1min ];
  19814. }
  19815. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  19816. return [ seg1min, seg2max ];
  19817. }
  19818. }
  19819. }
  19820. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  19821. // The order of legs is important
  19822. // translation of all points, so that Vertex is at (0,0)
  19823. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  19824. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  19825. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  19826. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  19827. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  19828. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  19829. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  19830. // angle != 180 deg.
  19831. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  19832. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  19833. if ( from2toAngle > 0 ) {
  19834. // main angle < 180 deg.
  19835. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  19836. } else {
  19837. // main angle > 180 deg.
  19838. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  19839. }
  19840. } else {
  19841. // angle == 180 deg.
  19842. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  19843. return ( from2otherAngle > 0 );
  19844. }
  19845. }
  19846. function removeHoles( contour, holes ) {
  19847. var shape = contour.concat(); // work on this shape
  19848. var hole;
  19849. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  19850. // Check if hole point lies within angle around shape point
  19851. var lastShapeIdx = shape.length - 1;
  19852. var prevShapeIdx = inShapeIdx - 1;
  19853. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  19854. var nextShapeIdx = inShapeIdx + 1;
  19855. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  19856. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  19857. if ( ! insideAngle ) {
  19858. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  19859. return false;
  19860. }
  19861. // Check if shape point lies within angle around hole point
  19862. var lastHoleIdx = hole.length - 1;
  19863. var prevHoleIdx = inHoleIdx - 1;
  19864. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  19865. var nextHoleIdx = inHoleIdx + 1;
  19866. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  19867. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  19868. if ( ! insideAngle ) {
  19869. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  19870. return false;
  19871. }
  19872. return true;
  19873. }
  19874. function intersectsShapeEdge( inShapePt, inHolePt ) {
  19875. // checks for intersections with shape edges
  19876. var sIdx, nextIdx, intersection;
  19877. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  19878. nextIdx = sIdx + 1; nextIdx %= shape.length;
  19879. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  19880. if ( intersection.length > 0 ) return true;
  19881. }
  19882. return false;
  19883. }
  19884. var indepHoles = [];
  19885. function intersectsHoleEdge( inShapePt, inHolePt ) {
  19886. // checks for intersections with hole edges
  19887. var ihIdx, chkHole,
  19888. hIdx, nextIdx, intersection;
  19889. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  19890. chkHole = holes[ indepHoles[ ihIdx ]];
  19891. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  19892. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  19893. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  19894. if ( intersection.length > 0 ) return true;
  19895. }
  19896. }
  19897. return false;
  19898. }
  19899. var holeIndex, shapeIndex,
  19900. shapePt, holePt,
  19901. holeIdx, cutKey, failedCuts = [],
  19902. tmpShape1, tmpShape2,
  19903. tmpHole1, tmpHole2;
  19904. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  19905. indepHoles.push( h );
  19906. }
  19907. var minShapeIndex = 0;
  19908. var counter = indepHoles.length * 2;
  19909. while ( indepHoles.length > 0 ) {
  19910. counter --;
  19911. if ( counter < 0 ) {
  19912. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  19913. break;
  19914. }
  19915. // search for shape-vertex and hole-vertex,
  19916. // which can be connected without intersections
  19917. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  19918. shapePt = shape[ shapeIndex ];
  19919. holeIndex = - 1;
  19920. // search for hole which can be reached without intersections
  19921. for ( var h = 0; h < indepHoles.length; h ++ ) {
  19922. holeIdx = indepHoles[ h ];
  19923. // prevent multiple checks
  19924. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  19925. if ( failedCuts[ cutKey ] !== undefined ) continue;
  19926. hole = holes[ holeIdx ];
  19927. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  19928. holePt = hole[ h2 ];
  19929. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  19930. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  19931. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  19932. holeIndex = h2;
  19933. indepHoles.splice( h, 1 );
  19934. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  19935. tmpShape2 = shape.slice( shapeIndex );
  19936. tmpHole1 = hole.slice( holeIndex );
  19937. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  19938. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  19939. minShapeIndex = shapeIndex;
  19940. // Debug only, to show the selected cuts
  19941. // glob_CutLines.push( [ shapePt, holePt ] );
  19942. break;
  19943. }
  19944. if ( holeIndex >= 0 ) break; // hole-vertex found
  19945. failedCuts[ cutKey ] = true; // remember failure
  19946. }
  19947. if ( holeIndex >= 0 ) break; // hole-vertex found
  19948. }
  19949. }
  19950. return shape; /* shape with no holes */
  19951. }
  19952. var i, il, f, face,
  19953. key, index,
  19954. allPointsMap = {};
  19955. // To maintain reference to old shape, one must match coordinates, or offset the indices from original arrays. It's probably easier to do the first.
  19956. var allpoints = contour.concat();
  19957. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  19958. Array.prototype.push.apply( allpoints, holes[ h ] );
  19959. }
  19960. //console.log( "allpoints",allpoints, allpoints.length );
  19961. // prepare all points map
  19962. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  19963. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  19964. if ( allPointsMap[ key ] !== undefined ) {
  19965. console.warn( "THREE.Shape: Duplicate point", key );
  19966. }
  19967. allPointsMap[ key ] = i;
  19968. }
  19969. // remove holes by cutting paths to holes and adding them to the shape
  19970. var shapeWithoutHoles = removeHoles( contour, holes );
  19971. var triangles = THREE.ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  19972. //console.log( "triangles",triangles, triangles.length );
  19973. // check all face vertices against all points map
  19974. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  19975. face = triangles[ i ];
  19976. for ( f = 0; f < 3; f ++ ) {
  19977. key = face[ f ].x + ":" + face[ f ].y;
  19978. index = allPointsMap[ key ];
  19979. if ( index !== undefined ) {
  19980. face[ f ] = index;
  19981. }
  19982. }
  19983. }
  19984. return triangles.concat();
  19985. },
  19986. isClockWise: function ( pts ) {
  19987. return THREE.ShapeUtils.area( pts ) < 0;
  19988. },
  19989. // Bezier Curves formulas obtained from
  19990. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  19991. // Quad Bezier Functions
  19992. b2: ( function () {
  19993. function b2p0( t, p ) {
  19994. var k = 1 - t;
  19995. return k * k * p;
  19996. }
  19997. function b2p1( t, p ) {
  19998. return 2 * ( 1 - t ) * t * p;
  19999. }
  20000. function b2p2( t, p ) {
  20001. return t * t * p;
  20002. }
  20003. return function ( t, p0, p1, p2 ) {
  20004. return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
  20005. };
  20006. } )(),
  20007. // Cubic Bezier Functions
  20008. b3: ( function () {
  20009. function b3p0( t, p ) {
  20010. var k = 1 - t;
  20011. return k * k * k * p;
  20012. }
  20013. function b3p1( t, p ) {
  20014. var k = 1 - t;
  20015. return 3 * k * k * t * p;
  20016. }
  20017. function b3p2( t, p ) {
  20018. var k = 1 - t;
  20019. return 3 * k * t * t * p;
  20020. }
  20021. function b3p3( t, p ) {
  20022. return t * t * t * p;
  20023. }
  20024. return function ( t, p0, p1, p2, p3 ) {
  20025. return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
  20026. };
  20027. } )()
  20028. };
  20029. // File:src/extras/core/Curve.js
  20030. /**
  20031. * @author zz85 / http://www.lab4games.net/zz85/blog
  20032. * Extensible curve object
  20033. *
  20034. * Some common of Curve methods
  20035. * .getPoint(t), getTangent(t)
  20036. * .getPointAt(u), getTagentAt(u)
  20037. * .getPoints(), .getSpacedPoints()
  20038. * .getLength()
  20039. * .updateArcLengths()
  20040. *
  20041. * This following classes subclasses THREE.Curve:
  20042. *
  20043. * -- 2d classes --
  20044. * THREE.LineCurve
  20045. * THREE.QuadraticBezierCurve
  20046. * THREE.CubicBezierCurve
  20047. * THREE.SplineCurve
  20048. * THREE.ArcCurve
  20049. * THREE.EllipseCurve
  20050. *
  20051. * -- 3d classes --
  20052. * THREE.LineCurve3
  20053. * THREE.QuadraticBezierCurve3
  20054. * THREE.CubicBezierCurve3
  20055. * THREE.SplineCurve3
  20056. * THREE.ClosedSplineCurve3
  20057. *
  20058. * A series of curves can be represented as a THREE.CurvePath
  20059. *
  20060. **/
  20061. /**************************************************************
  20062. * Abstract Curve base class
  20063. **************************************************************/
  20064. THREE.Curve = function () {
  20065. };
  20066. THREE.Curve.prototype = {
  20067. constructor: THREE.Curve,
  20068. // Virtual base class method to overwrite and implement in subclasses
  20069. // - t [0 .. 1]
  20070. getPoint: function ( t ) {
  20071. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  20072. return null;
  20073. },
  20074. // Get point at relative position in curve according to arc length
  20075. // - u [0 .. 1]
  20076. getPointAt: function ( u ) {
  20077. var t = this.getUtoTmapping( u );
  20078. return this.getPoint( t );
  20079. },
  20080. // Get sequence of points using getPoint( t )
  20081. getPoints: function ( divisions ) {
  20082. if ( ! divisions ) divisions = 5;
  20083. var d, pts = [];
  20084. for ( d = 0; d <= divisions; d ++ ) {
  20085. pts.push( this.getPoint( d / divisions ) );
  20086. }
  20087. return pts;
  20088. },
  20089. // Get sequence of points using getPointAt( u )
  20090. getSpacedPoints: function ( divisions ) {
  20091. if ( ! divisions ) divisions = 5;
  20092. var d, pts = [];
  20093. for ( d = 0; d <= divisions; d ++ ) {
  20094. pts.push( this.getPointAt( d / divisions ) );
  20095. }
  20096. return pts;
  20097. },
  20098. // Get total curve arc length
  20099. getLength: function () {
  20100. var lengths = this.getLengths();
  20101. return lengths[ lengths.length - 1 ];
  20102. },
  20103. // Get list of cumulative segment lengths
  20104. getLengths: function ( divisions ) {
  20105. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  20106. if ( this.cacheArcLengths
  20107. && ( this.cacheArcLengths.length === divisions + 1 )
  20108. && ! this.needsUpdate ) {
  20109. //console.log( "cached", this.cacheArcLengths );
  20110. return this.cacheArcLengths;
  20111. }
  20112. this.needsUpdate = false;
  20113. var cache = [];
  20114. var current, last = this.getPoint( 0 );
  20115. var p, sum = 0;
  20116. cache.push( 0 );
  20117. for ( p = 1; p <= divisions; p ++ ) {
  20118. current = this.getPoint ( p / divisions );
  20119. sum += current.distanceTo( last );
  20120. cache.push( sum );
  20121. last = current;
  20122. }
  20123. this.cacheArcLengths = cache;
  20124. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  20125. },
  20126. updateArcLengths: function() {
  20127. this.needsUpdate = true;
  20128. this.getLengths();
  20129. },
  20130. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  20131. getUtoTmapping: function ( u, distance ) {
  20132. var arcLengths = this.getLengths();
  20133. var i = 0, il = arcLengths.length;
  20134. var targetArcLength; // The targeted u distance value to get
  20135. if ( distance ) {
  20136. targetArcLength = distance;
  20137. } else {
  20138. targetArcLength = u * arcLengths[ il - 1 ];
  20139. }
  20140. //var time = Date.now();
  20141. // binary search for the index with largest value smaller than target u distance
  20142. var low = 0, high = il - 1, comparison;
  20143. while ( low <= high ) {
  20144. 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
  20145. comparison = arcLengths[ i ] - targetArcLength;
  20146. if ( comparison < 0 ) {
  20147. low = i + 1;
  20148. } else if ( comparison > 0 ) {
  20149. high = i - 1;
  20150. } else {
  20151. high = i;
  20152. break;
  20153. // DONE
  20154. }
  20155. }
  20156. i = high;
  20157. //console.log('b' , i, low, high, Date.now()- time);
  20158. if ( arcLengths[ i ] === targetArcLength ) {
  20159. var t = i / ( il - 1 );
  20160. return t;
  20161. }
  20162. // we could get finer grain at lengths, or use simple interpolation between two points
  20163. var lengthBefore = arcLengths[ i ];
  20164. var lengthAfter = arcLengths[ i + 1 ];
  20165. var segmentLength = lengthAfter - lengthBefore;
  20166. // determine where we are between the 'before' and 'after' points
  20167. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  20168. // add that fractional amount to t
  20169. var t = ( i + segmentFraction ) / ( il - 1 );
  20170. return t;
  20171. },
  20172. // Returns a unit vector tangent at t
  20173. // In case any sub curve does not implement its tangent derivation,
  20174. // 2 points a small delta apart will be used to find its gradient
  20175. // which seems to give a reasonable approximation
  20176. getTangent: function( t ) {
  20177. var delta = 0.0001;
  20178. var t1 = t - delta;
  20179. var t2 = t + delta;
  20180. // Capping in case of danger
  20181. if ( t1 < 0 ) t1 = 0;
  20182. if ( t2 > 1 ) t2 = 1;
  20183. var pt1 = this.getPoint( t1 );
  20184. var pt2 = this.getPoint( t2 );
  20185. var vec = pt2.clone().sub( pt1 );
  20186. return vec.normalize();
  20187. },
  20188. getTangentAt: function ( u ) {
  20189. var t = this.getUtoTmapping( u );
  20190. return this.getTangent( t );
  20191. }
  20192. };
  20193. // TODO: Transformation for Curves?
  20194. /**************************************************************
  20195. * 3D Curves
  20196. **************************************************************/
  20197. // A Factory method for creating new curve subclasses
  20198. THREE.Curve.create = function ( constructor, getPointFunc ) {
  20199. constructor.prototype = Object.create( THREE.Curve.prototype );
  20200. constructor.prototype.constructor = constructor;
  20201. constructor.prototype.getPoint = getPointFunc;
  20202. return constructor;
  20203. };
  20204. // File:src/extras/core/CurvePath.js
  20205. /**
  20206. * @author zz85 / http://www.lab4games.net/zz85/blog
  20207. *
  20208. **/
  20209. /**************************************************************
  20210. * Curved Path - a curve path is simply a array of connected
  20211. * curves, but retains the api of a curve
  20212. **************************************************************/
  20213. THREE.CurvePath = function () {
  20214. this.curves = [];
  20215. this.autoClose = false; // Automatically closes the path
  20216. };
  20217. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  20218. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  20219. THREE.CurvePath.prototype.add = function ( curve ) {
  20220. this.curves.push( curve );
  20221. };
  20222. /*
  20223. THREE.CurvePath.prototype.checkConnection = function() {
  20224. // TODO
  20225. // If the ending of curve is not connected to the starting
  20226. // or the next curve, then, this is not a real path
  20227. };
  20228. */
  20229. THREE.CurvePath.prototype.closePath = function() {
  20230. // TODO Test
  20231. // and verify for vector3 (needs to implement equals)
  20232. // Add a line curve if start and end of lines are not connected
  20233. var startPoint = this.curves[ 0 ].getPoint( 0 );
  20234. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  20235. if ( ! startPoint.equals( endPoint ) ) {
  20236. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  20237. }
  20238. };
  20239. // To get accurate point with reference to
  20240. // entire path distance at time t,
  20241. // following has to be done:
  20242. // 1. Length of each sub path have to be known
  20243. // 2. Locate and identify type of curve
  20244. // 3. Get t for the curve
  20245. // 4. Return curve.getPointAt(t')
  20246. THREE.CurvePath.prototype.getPoint = function( t ) {
  20247. var d = t * this.getLength();
  20248. var curveLengths = this.getCurveLengths();
  20249. var i = 0;
  20250. // To think about boundaries points.
  20251. while ( i < curveLengths.length ) {
  20252. if ( curveLengths[ i ] >= d ) {
  20253. var diff = curveLengths[ i ] - d;
  20254. var curve = this.curves[ i ];
  20255. var u = 1 - diff / curve.getLength();
  20256. return curve.getPointAt( u );
  20257. }
  20258. i ++;
  20259. }
  20260. return null;
  20261. // loop where sum != 0, sum > d , sum+1 <d
  20262. };
  20263. /*
  20264. THREE.CurvePath.prototype.getTangent = function( t ) {
  20265. };
  20266. */
  20267. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  20268. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  20269. // getPoint() depends on getLength
  20270. THREE.CurvePath.prototype.getLength = function() {
  20271. var lens = this.getCurveLengths();
  20272. return lens[ lens.length - 1 ];
  20273. };
  20274. // Compute lengths and cache them
  20275. // We cannot overwrite getLengths() because UtoT mapping uses it.
  20276. THREE.CurvePath.prototype.getCurveLengths = function() {
  20277. // We use cache values if curves and cache array are same length
  20278. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  20279. return this.cacheLengths;
  20280. }
  20281. // Get length of sub-curve
  20282. // Push sums into cached array
  20283. var lengths = [], sums = 0;
  20284. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  20285. sums += this.curves[ i ].getLength();
  20286. lengths.push( sums );
  20287. }
  20288. this.cacheLengths = lengths;
  20289. return lengths;
  20290. };
  20291. /**************************************************************
  20292. * Create Geometries Helpers
  20293. **************************************************************/
  20294. /// Generate geometry from path points (for Line or Points objects)
  20295. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  20296. var pts = this.getPoints( divisions );
  20297. return this.createGeometry( pts );
  20298. };
  20299. // Generate geometry from equidistant sampling along the path
  20300. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  20301. var pts = this.getSpacedPoints( divisions );
  20302. return this.createGeometry( pts );
  20303. };
  20304. THREE.CurvePath.prototype.createGeometry = function( points ) {
  20305. var geometry = new THREE.Geometry();
  20306. for ( var i = 0, l = points.length; i < l; i ++ ) {
  20307. var point = points[ i ];
  20308. geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
  20309. }
  20310. return geometry;
  20311. };
  20312. // File:src/extras/core/Font.js
  20313. /**
  20314. * @author zz85 / http://www.lab4games.net/zz85/blog
  20315. * @author mrdoob / http://mrdoob.com/
  20316. */
  20317. THREE.Font = function ( data ) {
  20318. this.data = data;
  20319. };
  20320. THREE.Font.prototype = {
  20321. constructor: THREE.Font,
  20322. generateShapes: function ( text, size, divisions ) {
  20323. function createPaths( text ) {
  20324. var chars = String( text ).split( '' );
  20325. var scale = size / data.resolution;
  20326. var offset = 0;
  20327. var paths = [];
  20328. for ( var i = 0; i < chars.length; i ++ ) {
  20329. var ret = createPath( chars[ i ], scale, offset );
  20330. offset += ret.offset;
  20331. paths.push( ret.path );
  20332. }
  20333. return paths;
  20334. }
  20335. function createPath( c, scale, offset ) {
  20336. var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
  20337. if ( ! glyph ) return;
  20338. var path = new THREE.Path();
  20339. var pts = [], b2 = THREE.ShapeUtils.b2, b3 = THREE.ShapeUtils.b3;
  20340. var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
  20341. if ( glyph.o ) {
  20342. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  20343. for ( var i = 0, l = outline.length; i < l; ) {
  20344. var action = outline[ i ++ ];
  20345. switch ( action ) {
  20346. case 'm': // moveTo
  20347. x = outline[ i ++ ] * scale + offset;
  20348. y = outline[ i ++ ] * scale;
  20349. path.moveTo( x, y );
  20350. break;
  20351. case 'l': // lineTo
  20352. x = outline[ i ++ ] * scale + offset;
  20353. y = outline[ i ++ ] * scale;
  20354. path.lineTo( x, y );
  20355. break;
  20356. case 'q': // quadraticCurveTo
  20357. cpx = outline[ i ++ ] * scale + offset;
  20358. cpy = outline[ i ++ ] * scale;
  20359. cpx1 = outline[ i ++ ] * scale + offset;
  20360. cpy1 = outline[ i ++ ] * scale;
  20361. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  20362. laste = pts[ pts.length - 1 ];
  20363. if ( laste ) {
  20364. cpx0 = laste.x;
  20365. cpy0 = laste.y;
  20366. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  20367. var t = i2 / divisions;
  20368. b2( t, cpx0, cpx1, cpx );
  20369. b2( t, cpy0, cpy1, cpy );
  20370. }
  20371. }
  20372. break;
  20373. case 'b': // bezierCurveTo
  20374. cpx = outline[ i ++ ] * scale + offset;
  20375. cpy = outline[ i ++ ] * scale;
  20376. cpx1 = outline[ i ++ ] * scale + offset;
  20377. cpy1 = outline[ i ++ ] * scale;
  20378. cpx2 = outline[ i ++ ] * scale + offset;
  20379. cpy2 = outline[ i ++ ] * scale;
  20380. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  20381. laste = pts[ pts.length - 1 ];
  20382. if ( laste ) {
  20383. cpx0 = laste.x;
  20384. cpy0 = laste.y;
  20385. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  20386. var t = i2 / divisions;
  20387. b3( t, cpx0, cpx1, cpx2, cpx );
  20388. b3( t, cpy0, cpy1, cpy2, cpy );
  20389. }
  20390. }
  20391. break;
  20392. }
  20393. }
  20394. }
  20395. return { offset: glyph.ha * scale, path: path };
  20396. }
  20397. //
  20398. if ( size === undefined ) size = 100;
  20399. if ( divisions === undefined ) divisions = 4;
  20400. var data = this.data;
  20401. var paths = createPaths( text );
  20402. var shapes = [];
  20403. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  20404. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  20405. }
  20406. return shapes;
  20407. }
  20408. };
  20409. // File:src/extras/core/Path.js
  20410. /**
  20411. * @author zz85 / http://www.lab4games.net/zz85/blog
  20412. * Creates free form 2d path using series of points, lines or curves.
  20413. *
  20414. **/
  20415. THREE.Path = function ( points ) {
  20416. THREE.CurvePath.call( this );
  20417. this.actions = [];
  20418. if ( points ) {
  20419. this.fromPoints( points );
  20420. }
  20421. };
  20422. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  20423. THREE.Path.prototype.constructor = THREE.Path;
  20424. // TODO Clean up PATH API
  20425. // Create path using straight lines to connect all points
  20426. // - vectors: array of Vector2
  20427. THREE.Path.prototype.fromPoints = function ( vectors ) {
  20428. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  20429. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  20430. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  20431. }
  20432. };
  20433. // startPath() endPath()?
  20434. THREE.Path.prototype.moveTo = function ( x, y ) {
  20435. this.actions.push( { action: 'moveTo', args: [ x, y ] } );
  20436. };
  20437. THREE.Path.prototype.lineTo = function ( x, y ) {
  20438. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20439. var x0 = lastargs[ lastargs.length - 2 ];
  20440. var y0 = lastargs[ lastargs.length - 1 ];
  20441. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  20442. this.curves.push( curve );
  20443. this.actions.push( { action: 'lineTo', args: [ x, y ] } );
  20444. };
  20445. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  20446. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20447. var x0 = lastargs[ lastargs.length - 2 ];
  20448. var y0 = lastargs[ lastargs.length - 1 ];
  20449. var curve = new THREE.QuadraticBezierCurve(
  20450. new THREE.Vector2( x0, y0 ),
  20451. new THREE.Vector2( aCPx, aCPy ),
  20452. new THREE.Vector2( aX, aY )
  20453. );
  20454. this.curves.push( curve );
  20455. this.actions.push( { action: 'quadraticCurveTo', args: [ aCPx, aCPy, aX, aY ] } );
  20456. };
  20457. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  20458. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20459. var x0 = lastargs[ lastargs.length - 2 ];
  20460. var y0 = lastargs[ lastargs.length - 1 ];
  20461. var curve = new THREE.CubicBezierCurve(
  20462. new THREE.Vector2( x0, y0 ),
  20463. new THREE.Vector2( aCP1x, aCP1y ),
  20464. new THREE.Vector2( aCP2x, aCP2y ),
  20465. new THREE.Vector2( aX, aY )
  20466. );
  20467. this.curves.push( curve );
  20468. this.actions.push( { action: 'bezierCurveTo', args: [ aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ] } );
  20469. };
  20470. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  20471. var args = Array.prototype.slice.call( arguments );
  20472. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20473. var x0 = lastargs[ lastargs.length - 2 ];
  20474. var y0 = lastargs[ lastargs.length - 1 ];
  20475. var npts = [ new THREE.Vector2( x0, y0 ) ];
  20476. Array.prototype.push.apply( npts, pts );
  20477. var curve = new THREE.SplineCurve( npts );
  20478. this.curves.push( curve );
  20479. this.actions.push( { action: 'splineThru', args: args } );
  20480. };
  20481. // FUTURE: Change the API or follow canvas API?
  20482. THREE.Path.prototype.arc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20483. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20484. var x0 = lastargs[ lastargs.length - 2 ];
  20485. var y0 = lastargs[ lastargs.length - 1 ];
  20486. this.absarc( aX + x0, aY + y0, aRadius,
  20487. aStartAngle, aEndAngle, aClockwise );
  20488. };
  20489. THREE.Path.prototype.absarc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20490. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  20491. };
  20492. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20493. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20494. var x0 = lastargs[ lastargs.length - 2 ];
  20495. var y0 = lastargs[ lastargs.length - 1 ];
  20496. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20497. };
  20498. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20499. var args = [
  20500. aX, aY,
  20501. xRadius, yRadius,
  20502. aStartAngle, aEndAngle,
  20503. aClockwise,
  20504. aRotation || 0 // aRotation is optional.
  20505. ];
  20506. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20507. this.curves.push( curve );
  20508. var lastPoint = curve.getPoint( 1 );
  20509. args.push( lastPoint.x );
  20510. args.push( lastPoint.y );
  20511. this.actions.push( { action: 'ellipse', args: args } );
  20512. };
  20513. THREE.Path.prototype.getSpacedPoints = function ( divisions ) {
  20514. if ( ! divisions ) divisions = 40;
  20515. var points = [];
  20516. for ( var i = 0; i < divisions; i ++ ) {
  20517. points.push( this.getPoint( i / divisions ) );
  20518. //if ( !this.getPoint( i / divisions ) ) throw "DIE";
  20519. }
  20520. if ( this.autoClose ) {
  20521. points.push( points[ 0 ] );
  20522. }
  20523. return points;
  20524. };
  20525. /* Return an array of vectors based on contour of the path */
  20526. THREE.Path.prototype.getPoints = function( divisions ) {
  20527. divisions = divisions || 12;
  20528. var b2 = THREE.ShapeUtils.b2;
  20529. var b3 = THREE.ShapeUtils.b3;
  20530. var points = [];
  20531. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  20532. laste, tx, ty;
  20533. for ( var i = 0, l = this.actions.length; i < l; i ++ ) {
  20534. var item = this.actions[ i ];
  20535. var action = item.action;
  20536. var args = item.args;
  20537. switch ( action ) {
  20538. case 'moveTo':
  20539. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20540. break;
  20541. case 'lineTo':
  20542. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20543. break;
  20544. case 'quadraticCurveTo':
  20545. cpx = args[ 2 ];
  20546. cpy = args[ 3 ];
  20547. cpx1 = args[ 0 ];
  20548. cpy1 = args[ 1 ];
  20549. if ( points.length > 0 ) {
  20550. laste = points[ points.length - 1 ];
  20551. cpx0 = laste.x;
  20552. cpy0 = laste.y;
  20553. } else {
  20554. laste = this.actions[ i - 1 ].args;
  20555. cpx0 = laste[ laste.length - 2 ];
  20556. cpy0 = laste[ laste.length - 1 ];
  20557. }
  20558. for ( var j = 1; j <= divisions; j ++ ) {
  20559. var t = j / divisions;
  20560. tx = b2( t, cpx0, cpx1, cpx );
  20561. ty = b2( t, cpy0, cpy1, cpy );
  20562. points.push( new THREE.Vector2( tx, ty ) );
  20563. }
  20564. break;
  20565. case 'bezierCurveTo':
  20566. cpx = args[ 4 ];
  20567. cpy = args[ 5 ];
  20568. cpx1 = args[ 0 ];
  20569. cpy1 = args[ 1 ];
  20570. cpx2 = args[ 2 ];
  20571. cpy2 = args[ 3 ];
  20572. if ( points.length > 0 ) {
  20573. laste = points[ points.length - 1 ];
  20574. cpx0 = laste.x;
  20575. cpy0 = laste.y;
  20576. } else {
  20577. laste = this.actions[ i - 1 ].args;
  20578. cpx0 = laste[ laste.length - 2 ];
  20579. cpy0 = laste[ laste.length - 1 ];
  20580. }
  20581. for ( var j = 1; j <= divisions; j ++ ) {
  20582. var t = j / divisions;
  20583. tx = b3( t, cpx0, cpx1, cpx2, cpx );
  20584. ty = b3( t, cpy0, cpy1, cpy2, cpy );
  20585. points.push( new THREE.Vector2( tx, ty ) );
  20586. }
  20587. break;
  20588. case 'splineThru':
  20589. laste = this.actions[ i - 1 ].args;
  20590. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  20591. var spts = [ last ];
  20592. var n = divisions * args[ 0 ].length;
  20593. spts = spts.concat( args[ 0 ] );
  20594. var spline = new THREE.SplineCurve( spts );
  20595. for ( var j = 1; j <= n; j ++ ) {
  20596. points.push( spline.getPointAt( j / n ) );
  20597. }
  20598. break;
  20599. case 'arc':
  20600. var aX = args[ 0 ], aY = args[ 1 ],
  20601. aRadius = args[ 2 ],
  20602. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  20603. aClockwise = !! args[ 5 ];
  20604. var deltaAngle = aEndAngle - aStartAngle;
  20605. var angle;
  20606. var tdivisions = divisions * 2;
  20607. for ( var j = 1; j <= tdivisions; j ++ ) {
  20608. var t = j / tdivisions;
  20609. if ( ! aClockwise ) {
  20610. t = 1 - t;
  20611. }
  20612. angle = aStartAngle + t * deltaAngle;
  20613. tx = aX + aRadius * Math.cos( angle );
  20614. ty = aY + aRadius * Math.sin( angle );
  20615. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  20616. points.push( new THREE.Vector2( tx, ty ) );
  20617. }
  20618. //console.log(points);
  20619. break;
  20620. case 'ellipse':
  20621. var aX = args[ 0 ], aY = args[ 1 ],
  20622. xRadius = args[ 2 ],
  20623. yRadius = args[ 3 ],
  20624. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  20625. aClockwise = !! args[ 6 ],
  20626. aRotation = args[ 7 ];
  20627. var deltaAngle = aEndAngle - aStartAngle;
  20628. var angle;
  20629. var tdivisions = divisions * 2;
  20630. var cos, sin;
  20631. if ( aRotation !== 0 ) {
  20632. cos = Math.cos( aRotation );
  20633. sin = Math.sin( aRotation );
  20634. }
  20635. for ( var j = 1; j <= tdivisions; j ++ ) {
  20636. var t = j / tdivisions;
  20637. if ( ! aClockwise ) {
  20638. t = 1 - t;
  20639. }
  20640. angle = aStartAngle + t * deltaAngle;
  20641. tx = aX + xRadius * Math.cos( angle );
  20642. ty = aY + yRadius * Math.sin( angle );
  20643. if ( aRotation !== 0 ) {
  20644. var x = tx, y = ty;
  20645. // Rotate the point about the center of the ellipse.
  20646. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  20647. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  20648. }
  20649. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  20650. points.push( new THREE.Vector2( tx, ty ) );
  20651. }
  20652. //console.log(points);
  20653. break;
  20654. } // end switch
  20655. }
  20656. // Normalize to remove the closing point by default.
  20657. var lastPoint = points[ points.length - 1 ];
  20658. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < Number.EPSILON &&
  20659. Math.abs( lastPoint.y - points[ 0 ].y ) < Number.EPSILON )
  20660. points.splice( points.length - 1, 1 );
  20661. if ( this.autoClose ) {
  20662. points.push( points[ 0 ] );
  20663. }
  20664. return points;
  20665. };
  20666. //
  20667. // Breaks path into shapes
  20668. //
  20669. // Assumptions (if parameter isCCW==true the opposite holds):
  20670. // - solid shapes are defined clockwise (CW)
  20671. // - holes are defined counterclockwise (CCW)
  20672. //
  20673. // If parameter noHoles==true:
  20674. // - all subPaths are regarded as solid shapes
  20675. // - definition order CW/CCW has no relevance
  20676. //
  20677. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  20678. function extractSubpaths( inActions ) {
  20679. var subPaths = [], lastPath = new THREE.Path();
  20680. for ( var i = 0, l = inActions.length; i < l; i ++ ) {
  20681. var item = inActions[ i ];
  20682. var args = item.args;
  20683. var action = item.action;
  20684. if ( action === 'moveTo' ) {
  20685. if ( lastPath.actions.length !== 0 ) {
  20686. subPaths.push( lastPath );
  20687. lastPath = new THREE.Path();
  20688. }
  20689. }
  20690. lastPath[ action ].apply( lastPath, args );
  20691. }
  20692. if ( lastPath.actions.length !== 0 ) {
  20693. subPaths.push( lastPath );
  20694. }
  20695. // console.log(subPaths);
  20696. return subPaths;
  20697. }
  20698. function toShapesNoHoles( inSubpaths ) {
  20699. var shapes = [];
  20700. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  20701. var tmpPath = inSubpaths[ i ];
  20702. var tmpShape = new THREE.Shape();
  20703. tmpShape.actions = tmpPath.actions;
  20704. tmpShape.curves = tmpPath.curves;
  20705. shapes.push( tmpShape );
  20706. }
  20707. //console.log("shape", shapes);
  20708. return shapes;
  20709. }
  20710. function isPointInsidePolygon( inPt, inPolygon ) {
  20711. var polyLen = inPolygon.length;
  20712. // inPt on polygon contour => immediate success or
  20713. // toggling of inside/outside at every single! intersection point of an edge
  20714. // with the horizontal line through inPt, left of inPt
  20715. // not counting lowerY endpoints of edges and whole edges on that line
  20716. var inside = false;
  20717. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  20718. var edgeLowPt = inPolygon[ p ];
  20719. var edgeHighPt = inPolygon[ q ];
  20720. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  20721. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  20722. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  20723. // not parallel
  20724. if ( edgeDy < 0 ) {
  20725. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  20726. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  20727. }
  20728. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  20729. if ( inPt.y === edgeLowPt.y ) {
  20730. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  20731. // continue; // no intersection or edgeLowPt => doesn't count !!!
  20732. } else {
  20733. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  20734. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  20735. if ( perpEdge < 0 ) continue;
  20736. inside = ! inside; // true intersection left of inPt
  20737. }
  20738. } else {
  20739. // parallel or collinear
  20740. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  20741. // edge lies on the same horizontal line as inPt
  20742. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  20743. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  20744. // continue;
  20745. }
  20746. }
  20747. return inside;
  20748. }
  20749. var isClockWise = THREE.ShapeUtils.isClockWise;
  20750. var subPaths = extractSubpaths( this.actions );
  20751. if ( subPaths.length === 0 ) return [];
  20752. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  20753. var solid, tmpPath, tmpShape, shapes = [];
  20754. if ( subPaths.length === 1 ) {
  20755. tmpPath = subPaths[ 0 ];
  20756. tmpShape = new THREE.Shape();
  20757. tmpShape.actions = tmpPath.actions;
  20758. tmpShape.curves = tmpPath.curves;
  20759. shapes.push( tmpShape );
  20760. return shapes;
  20761. }
  20762. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  20763. holesFirst = isCCW ? ! holesFirst : holesFirst;
  20764. // console.log("Holes first", holesFirst);
  20765. var betterShapeHoles = [];
  20766. var newShapes = [];
  20767. var newShapeHoles = [];
  20768. var mainIdx = 0;
  20769. var tmpPoints;
  20770. newShapes[ mainIdx ] = undefined;
  20771. newShapeHoles[ mainIdx ] = [];
  20772. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  20773. tmpPath = subPaths[ i ];
  20774. tmpPoints = tmpPath.getPoints();
  20775. solid = isClockWise( tmpPoints );
  20776. solid = isCCW ? ! solid : solid;
  20777. if ( solid ) {
  20778. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  20779. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  20780. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  20781. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  20782. if ( holesFirst ) mainIdx ++;
  20783. newShapeHoles[ mainIdx ] = [];
  20784. //console.log('cw', i);
  20785. } else {
  20786. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  20787. //console.log('ccw', i);
  20788. }
  20789. }
  20790. // only Holes? -> probably all Shapes with wrong orientation
  20791. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  20792. if ( newShapes.length > 1 ) {
  20793. var ambiguous = false;
  20794. var toChange = [];
  20795. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  20796. betterShapeHoles[ sIdx ] = [];
  20797. }
  20798. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  20799. var sho = newShapeHoles[ sIdx ];
  20800. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  20801. var ho = sho[ hIdx ];
  20802. var hole_unassigned = true;
  20803. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  20804. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  20805. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  20806. if ( hole_unassigned ) {
  20807. hole_unassigned = false;
  20808. betterShapeHoles[ s2Idx ].push( ho );
  20809. } else {
  20810. ambiguous = true;
  20811. }
  20812. }
  20813. }
  20814. if ( hole_unassigned ) {
  20815. betterShapeHoles[ sIdx ].push( ho );
  20816. }
  20817. }
  20818. }
  20819. // console.log("ambiguous: ", ambiguous);
  20820. if ( toChange.length > 0 ) {
  20821. // console.log("to change: ", toChange);
  20822. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  20823. }
  20824. }
  20825. var tmpHoles;
  20826. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  20827. tmpShape = newShapes[ i ].s;
  20828. shapes.push( tmpShape );
  20829. tmpHoles = newShapeHoles[ i ];
  20830. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  20831. tmpShape.holes.push( tmpHoles[ j ].h );
  20832. }
  20833. }
  20834. //console.log("shape", shapes);
  20835. return shapes;
  20836. };
  20837. // File:src/extras/core/Shape.js
  20838. /**
  20839. * @author zz85 / http://www.lab4games.net/zz85/blog
  20840. * Defines a 2d shape plane using paths.
  20841. **/
  20842. // STEP 1 Create a path.
  20843. // STEP 2 Turn path into shape.
  20844. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  20845. // STEP 3a - Extract points from each shape, turn to vertices
  20846. // STEP 3b - Triangulate each shape, add faces.
  20847. THREE.Shape = function () {
  20848. THREE.Path.apply( this, arguments );
  20849. this.holes = [];
  20850. };
  20851. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  20852. THREE.Shape.prototype.constructor = THREE.Shape;
  20853. // Convenience method to return ExtrudeGeometry
  20854. THREE.Shape.prototype.extrude = function ( options ) {
  20855. return new THREE.ExtrudeGeometry( this, options );
  20856. };
  20857. // Convenience method to return ShapeGeometry
  20858. THREE.Shape.prototype.makeGeometry = function ( options ) {
  20859. return new THREE.ShapeGeometry( this, options );
  20860. };
  20861. // Get points of holes
  20862. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  20863. var holesPts = [];
  20864. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  20865. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  20866. }
  20867. return holesPts;
  20868. };
  20869. // Get points of shape and holes (keypoints based on segments parameter)
  20870. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  20871. return {
  20872. shape: this.getPoints( divisions ),
  20873. holes: this.getPointsHoles( divisions )
  20874. };
  20875. };
  20876. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  20877. return this.extractAllPoints( divisions );
  20878. };
  20879. // File:src/extras/curves/LineCurve.js
  20880. /**************************************************************
  20881. * Line
  20882. **************************************************************/
  20883. THREE.LineCurve = function ( v1, v2 ) {
  20884. this.v1 = v1;
  20885. this.v2 = v2;
  20886. };
  20887. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  20888. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  20889. THREE.LineCurve.prototype.getPoint = function ( t ) {
  20890. var point = this.v2.clone().sub( this.v1 );
  20891. point.multiplyScalar( t ).add( this.v1 );
  20892. return point;
  20893. };
  20894. // Line curve is linear, so we can overwrite default getPointAt
  20895. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  20896. return this.getPoint( u );
  20897. };
  20898. THREE.LineCurve.prototype.getTangent = function( t ) {
  20899. var tangent = this.v2.clone().sub( this.v1 );
  20900. return tangent.normalize();
  20901. };
  20902. // File:src/extras/curves/QuadraticBezierCurve.js
  20903. /**************************************************************
  20904. * Quadratic Bezier curve
  20905. **************************************************************/
  20906. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  20907. this.v0 = v0;
  20908. this.v1 = v1;
  20909. this.v2 = v2;
  20910. };
  20911. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  20912. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  20913. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  20914. var b2 = THREE.ShapeUtils.b2;
  20915. return new THREE.Vector2(
  20916. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  20917. b2( t, this.v0.y, this.v1.y, this.v2.y )
  20918. );
  20919. };
  20920. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  20921. var tangentQuadraticBezier = THREE.CurveUtils.tangentQuadraticBezier;
  20922. return new THREE.Vector2(
  20923. tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x ),
  20924. tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y )
  20925. ).normalize();
  20926. };
  20927. // File:src/extras/curves/CubicBezierCurve.js
  20928. /**************************************************************
  20929. * Cubic Bezier curve
  20930. **************************************************************/
  20931. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  20932. this.v0 = v0;
  20933. this.v1 = v1;
  20934. this.v2 = v2;
  20935. this.v3 = v3;
  20936. };
  20937. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  20938. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  20939. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  20940. var b3 = THREE.ShapeUtils.b3;
  20941. return new THREE.Vector2(
  20942. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  20943. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  20944. );
  20945. };
  20946. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  20947. var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
  20948. return new THREE.Vector2(
  20949. tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  20950. tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  20951. ).normalize();
  20952. };
  20953. // File:src/extras/curves/SplineCurve.js
  20954. /**************************************************************
  20955. * Spline curve
  20956. **************************************************************/
  20957. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  20958. this.points = ( points == undefined ) ? [] : points;
  20959. };
  20960. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  20961. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  20962. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  20963. var points = this.points;
  20964. var point = ( points.length - 1 ) * t;
  20965. var intPoint = Math.floor( point );
  20966. var weight = point - intPoint;
  20967. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  20968. var point1 = points[ intPoint ];
  20969. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  20970. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  20971. var interpolate = THREE.CurveUtils.interpolate;
  20972. return new THREE.Vector2(
  20973. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  20974. interpolate( point0.y, point1.y, point2.y, point3.y, weight )
  20975. );
  20976. };
  20977. // File:src/extras/curves/EllipseCurve.js
  20978. /**************************************************************
  20979. * Ellipse curve
  20980. **************************************************************/
  20981. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20982. this.aX = aX;
  20983. this.aY = aY;
  20984. this.xRadius = xRadius;
  20985. this.yRadius = yRadius;
  20986. this.aStartAngle = aStartAngle;
  20987. this.aEndAngle = aEndAngle;
  20988. this.aClockwise = aClockwise;
  20989. this.aRotation = aRotation || 0;
  20990. };
  20991. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  20992. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  20993. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  20994. var deltaAngle = this.aEndAngle - this.aStartAngle;
  20995. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  20996. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  20997. var angle;
  20998. if ( this.aClockwise === true ) {
  20999. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  21000. } else {
  21001. angle = this.aStartAngle + t * deltaAngle;
  21002. }
  21003. var x = this.aX + this.xRadius * Math.cos( angle );
  21004. var y = this.aY + this.yRadius * Math.sin( angle );
  21005. if ( this.aRotation !== 0 ) {
  21006. var cos = Math.cos( this.aRotation );
  21007. var sin = Math.sin( this.aRotation );
  21008. var tx = x, ty = y;
  21009. // Rotate the point about the center of the ellipse.
  21010. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  21011. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  21012. }
  21013. return new THREE.Vector2( x, y );
  21014. };
  21015. // File:src/extras/curves/ArcCurve.js
  21016. /**************************************************************
  21017. * Arc curve
  21018. **************************************************************/
  21019. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21020. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21021. };
  21022. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  21023. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  21024. // File:src/extras/curves/LineCurve3.js
  21025. /**************************************************************
  21026. * Line3D
  21027. **************************************************************/
  21028. THREE.LineCurve3 = THREE.Curve.create(
  21029. function ( v1, v2 ) {
  21030. this.v1 = v1;
  21031. this.v2 = v2;
  21032. },
  21033. function ( t ) {
  21034. var vector = new THREE.Vector3();
  21035. vector.subVectors( this.v2, this.v1 ); // diff
  21036. vector.multiplyScalar( t );
  21037. vector.add( this.v1 );
  21038. return vector;
  21039. }
  21040. );
  21041. // File:src/extras/curves/QuadraticBezierCurve3.js
  21042. /**************************************************************
  21043. * Quadratic Bezier 3D curve
  21044. **************************************************************/
  21045. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  21046. function ( v0, v1, v2 ) {
  21047. this.v0 = v0;
  21048. this.v1 = v1;
  21049. this.v2 = v2;
  21050. },
  21051. function ( t ) {
  21052. var b2 = THREE.ShapeUtils.b2;
  21053. return new THREE.Vector3(
  21054. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21055. b2( t, this.v0.y, this.v1.y, this.v2.y ),
  21056. b2( t, this.v0.z, this.v1.z, this.v2.z )
  21057. );
  21058. }
  21059. );
  21060. // File:src/extras/curves/CubicBezierCurve3.js
  21061. /**************************************************************
  21062. * Cubic Bezier 3D curve
  21063. **************************************************************/
  21064. THREE.CubicBezierCurve3 = THREE.Curve.create(
  21065. function ( v0, v1, v2, v3 ) {
  21066. this.v0 = v0;
  21067. this.v1 = v1;
  21068. this.v2 = v2;
  21069. this.v3 = v3;
  21070. },
  21071. function ( t ) {
  21072. var b3 = THREE.ShapeUtils.b3;
  21073. return new THREE.Vector3(
  21074. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21075. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
  21076. b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z )
  21077. );
  21078. }
  21079. );
  21080. // File:src/extras/curves/SplineCurve3.js
  21081. /**************************************************************
  21082. * Spline 3D curve
  21083. **************************************************************/
  21084. THREE.SplineCurve3 = THREE.Curve.create(
  21085. function ( points /* array of Vector3 */ ) {
  21086. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  21087. this.points = ( points == undefined ) ? [] : points;
  21088. },
  21089. function ( t ) {
  21090. var points = this.points;
  21091. var point = ( points.length - 1 ) * t;
  21092. var intPoint = Math.floor( point );
  21093. var weight = point - intPoint;
  21094. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  21095. var point1 = points[ intPoint ];
  21096. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21097. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21098. var interpolate = THREE.CurveUtils.interpolate;
  21099. return new THREE.Vector3(
  21100. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21101. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  21102. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  21103. );
  21104. }
  21105. );
  21106. // File:src/extras/curves/CatmullRomCurve3.js
  21107. /**
  21108. * @author zz85 https://github.com/zz85
  21109. *
  21110. * Centripetal CatmullRom Curve - which is useful for avoiding
  21111. * cusps and self-intersections in non-uniform catmull rom curves.
  21112. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21113. *
  21114. * curve.type accepts centripetal(default), chordal and catmullrom
  21115. * curve.tension is used for catmullrom which defaults to 0.5
  21116. */
  21117. THREE.CatmullRomCurve3 = ( function() {
  21118. var
  21119. tmp = new THREE.Vector3(),
  21120. px = new CubicPoly(),
  21121. py = new CubicPoly(),
  21122. pz = new CubicPoly();
  21123. /*
  21124. Based on an optimized c++ solution in
  21125. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21126. - http://ideone.com/NoEbVM
  21127. This CubicPoly class could be used for reusing some variables and calculations,
  21128. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21129. which can be placed in CurveUtils.
  21130. */
  21131. function CubicPoly() {
  21132. }
  21133. /*
  21134. * Compute coefficients for a cubic polynomial
  21135. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21136. * such that
  21137. * p(0) = x0, p(1) = x1
  21138. * and
  21139. * p'(0) = t0, p'(1) = t1.
  21140. */
  21141. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  21142. this.c0 = x0;
  21143. this.c1 = t0;
  21144. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21145. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21146. };
  21147. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21148. // compute tangents when parameterized in [t1,t2]
  21149. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21150. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21151. // rescale tangents for parametrization in [0,1]
  21152. t1 *= dt1;
  21153. t2 *= dt1;
  21154. // initCubicPoly
  21155. this.init( x1, x2, t1, t2 );
  21156. };
  21157. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  21158. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  21159. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21160. };
  21161. CubicPoly.prototype.calc = function( t ) {
  21162. var t2 = t * t;
  21163. var t3 = t2 * t;
  21164. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  21165. };
  21166. // Subclass Three.js curve
  21167. return THREE.Curve.create(
  21168. function ( p /* array of Vector3 */ ) {
  21169. this.points = p || [];
  21170. this.closed = false;
  21171. },
  21172. function ( t ) {
  21173. var points = this.points,
  21174. point, intPoint, weight, l;
  21175. l = points.length;
  21176. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  21177. point = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21178. intPoint = Math.floor( point );
  21179. weight = point - intPoint;
  21180. if ( this.closed ) {
  21181. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  21182. } else if ( weight === 0 && intPoint === l - 1 ) {
  21183. intPoint = l - 2;
  21184. weight = 1;
  21185. }
  21186. var p0, p1, p2, p3; // 4 points
  21187. if ( this.closed || intPoint > 0 ) {
  21188. p0 = points[ ( intPoint - 1 ) % l ];
  21189. } else {
  21190. // extrapolate first point
  21191. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21192. p0 = tmp;
  21193. }
  21194. p1 = points[ intPoint % l ];
  21195. p2 = points[ ( intPoint + 1 ) % l ];
  21196. if ( this.closed || intPoint + 2 < l ) {
  21197. p3 = points[ ( intPoint + 2 ) % l ];
  21198. } else {
  21199. // extrapolate last point
  21200. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21201. p3 = tmp;
  21202. }
  21203. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  21204. // init Centripetal / Chordal Catmull-Rom
  21205. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  21206. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21207. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21208. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21209. // safety check for repeated points
  21210. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21211. if ( dt0 < 1e-4 ) dt0 = dt1;
  21212. if ( dt2 < 1e-4 ) dt2 = dt1;
  21213. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21214. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21215. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21216. } else if ( this.type === 'catmullrom' ) {
  21217. var tension = this.tension !== undefined ? this.tension : 0.5;
  21218. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  21219. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  21220. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  21221. }
  21222. var v = new THREE.Vector3(
  21223. px.calc( weight ),
  21224. py.calc( weight ),
  21225. pz.calc( weight )
  21226. );
  21227. return v;
  21228. }
  21229. );
  21230. } )();
  21231. // File:src/extras/curves/ClosedSplineCurve3.js
  21232. /**************************************************************
  21233. * Closed Spline 3D curve
  21234. **************************************************************/
  21235. THREE.ClosedSplineCurve3 = function ( points ) {
  21236. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Please use THREE.CatmullRomCurve3.' );
  21237. THREE.CatmullRomCurve3.call( this, points );
  21238. this.type = 'catmullrom';
  21239. this.closed = true;
  21240. };
  21241. THREE.ClosedSplineCurve3.prototype = Object.create( THREE.CatmullRomCurve3.prototype );
  21242. // File:src/extras/geometries/BoxGeometry.js
  21243. /**
  21244. * @author mrdoob / http://mrdoob.com/
  21245. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  21246. */
  21247. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21248. THREE.Geometry.call( this );
  21249. this.type = 'BoxGeometry';
  21250. this.parameters = {
  21251. width: width,
  21252. height: height,
  21253. depth: depth,
  21254. widthSegments: widthSegments,
  21255. heightSegments: heightSegments,
  21256. depthSegments: depthSegments
  21257. };
  21258. this.fromBufferGeometry( new THREE.BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  21259. this.mergeVertices();
  21260. };
  21261. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21262. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  21263. THREE.CubeGeometry = THREE.BoxGeometry;
  21264. // File:src/extras/geometries/BoxBufferGeometry.js
  21265. /**
  21266. * @author Mugen87 / https://github.com/Mugen87
  21267. */
  21268. THREE.BoxBufferGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21269. THREE.BufferGeometry.call( this );
  21270. this.type = 'BoxBufferGeometry';
  21271. this.parameters = {
  21272. width: width,
  21273. height: height,
  21274. depth: depth,
  21275. widthSegments: widthSegments,
  21276. heightSegments: heightSegments,
  21277. depthSegments: depthSegments
  21278. };
  21279. var scope = this;
  21280. // segments
  21281. widthSegments = Math.floor( widthSegments ) || 1;
  21282. heightSegments = Math.floor( heightSegments ) || 1;
  21283. depthSegments = Math.floor( depthSegments ) || 1;
  21284. // these are used to calculate buffer length
  21285. var vertexCount = calculateVertexCount( widthSegments, heightSegments, depthSegments );
  21286. var indexCount = ( vertexCount / 4 ) * 6;
  21287. // buffers
  21288. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  21289. var vertices = new Float32Array( vertexCount * 3 );
  21290. var normals = new Float32Array( vertexCount * 3 );
  21291. var uvs = new Float32Array( vertexCount * 2 );
  21292. // offset variables
  21293. var vertexBufferOffset = 0;
  21294. var uvBufferOffset = 0;
  21295. var indexBufferOffset = 0;
  21296. var numberOfVertices = 0;
  21297. // group variables
  21298. var groupStart = 0;
  21299. // build each side of the box geometry
  21300. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  21301. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  21302. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  21303. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  21304. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  21305. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  21306. // build geometry
  21307. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  21308. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  21309. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21310. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21311. // helper functions
  21312. function calculateVertexCount ( w, h, d ) {
  21313. var segments = 0;
  21314. // calculate the amount of segments for each side
  21315. segments += w * h * 2; // xy
  21316. segments += w * d * 2; // xz
  21317. segments += d * h * 2; // zy
  21318. return segments * 4; // four vertices per segments
  21319. }
  21320. function buildPlane ( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  21321. var segmentWidth = width / gridX;
  21322. var segmentHeight = height / gridY;
  21323. var widthHalf = width / 2;
  21324. var heightHalf = height / 2;
  21325. var depthHalf = depth / 2;
  21326. var gridX1 = gridX + 1;
  21327. var gridY1 = gridY + 1;
  21328. var vertexCounter = 0;
  21329. var groupCount = 0;
  21330. var vector = new THREE.Vector3();
  21331. // generate vertices, normals and uvs
  21332. for ( var iy = 0; iy < gridY1; iy ++ ) {
  21333. var y = iy * segmentHeight - heightHalf;
  21334. for ( var ix = 0; ix < gridX1; ix ++ ) {
  21335. var x = ix * segmentWidth - widthHalf;
  21336. // set values to correct vector component
  21337. vector[ u ] = x * udir;
  21338. vector[ v ] = y * vdir;
  21339. vector[ w ] = depthHalf;
  21340. // now apply vector to vertex buffer
  21341. vertices[ vertexBufferOffset ] = vector.x;
  21342. vertices[ vertexBufferOffset + 1 ] = vector.y;
  21343. vertices[ vertexBufferOffset + 2 ] = vector.z;
  21344. // set values to correct vector component
  21345. vector[ u ] = 0;
  21346. vector[ v ] = 0;
  21347. vector[ w ] = depth > 0 ? 1 : - 1;
  21348. // now apply vector to normal buffer
  21349. normals[ vertexBufferOffset ] = vector.x;
  21350. normals[ vertexBufferOffset + 1 ] = vector.y;
  21351. normals[ vertexBufferOffset + 2 ] = vector.z;
  21352. // uvs
  21353. uvs[ uvBufferOffset ] = ix / gridX;
  21354. uvs[ uvBufferOffset + 1 ] = 1 - ( iy / gridY );
  21355. // update offsets and counters
  21356. vertexBufferOffset += 3;
  21357. uvBufferOffset += 2;
  21358. vertexCounter += 1;
  21359. }
  21360. }
  21361. // 1. you need three indices to draw a single face
  21362. // 2. a single segment consists of two faces
  21363. // 3. so we need to generate six (2*3) indices per segment
  21364. for ( iy = 0; iy < gridY; iy ++ ) {
  21365. for ( ix = 0; ix < gridX; ix ++ ) {
  21366. // indices
  21367. var a = numberOfVertices + ix + gridX1 * iy;
  21368. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  21369. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  21370. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  21371. // face one
  21372. indices[ indexBufferOffset ] = a;
  21373. indices[ indexBufferOffset + 1 ] = b;
  21374. indices[ indexBufferOffset + 2 ] = d;
  21375. // face two
  21376. indices[ indexBufferOffset + 3 ] = b;
  21377. indices[ indexBufferOffset + 4 ] = c;
  21378. indices[ indexBufferOffset + 5 ] = d;
  21379. // update offsets and counters
  21380. indexBufferOffset += 6;
  21381. groupCount += 6;
  21382. }
  21383. }
  21384. // add a group to the geometry. this will ensure multi material support
  21385. scope.addGroup( groupStart, groupCount, materialIndex );
  21386. // calculate new start value for groups
  21387. groupStart += groupCount;
  21388. // update total number of vertices
  21389. numberOfVertices += vertexCounter;
  21390. }
  21391. };
  21392. THREE.BoxBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21393. THREE.BoxBufferGeometry.prototype.constructor = THREE.BoxBufferGeometry;
  21394. // File:src/extras/geometries/CircleGeometry.js
  21395. /**
  21396. * @author hughes
  21397. */
  21398. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21399. THREE.Geometry.call( this );
  21400. this.type = 'CircleGeometry';
  21401. this.parameters = {
  21402. radius: radius,
  21403. segments: segments,
  21404. thetaStart: thetaStart,
  21405. thetaLength: thetaLength
  21406. };
  21407. this.fromBufferGeometry( new THREE.CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  21408. };
  21409. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21410. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  21411. // File:src/extras/geometries/CircleBufferGeometry.js
  21412. /**
  21413. * @author benaadams / https://twitter.com/ben_a_adams
  21414. */
  21415. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21416. THREE.BufferGeometry.call( this );
  21417. this.type = 'CircleBufferGeometry';
  21418. this.parameters = {
  21419. radius: radius,
  21420. segments: segments,
  21421. thetaStart: thetaStart,
  21422. thetaLength: thetaLength
  21423. };
  21424. radius = radius || 50;
  21425. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  21426. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21427. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  21428. var vertices = segments + 2;
  21429. var positions = new Float32Array( vertices * 3 );
  21430. var normals = new Float32Array( vertices * 3 );
  21431. var uvs = new Float32Array( vertices * 2 );
  21432. // center data is already zero, but need to set a few extras
  21433. normals[ 2 ] = 1.0;
  21434. uvs[ 0 ] = 0.5;
  21435. uvs[ 1 ] = 0.5;
  21436. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  21437. var segment = thetaStart + s / segments * thetaLength;
  21438. positions[ i ] = radius * Math.cos( segment );
  21439. positions[ i + 1 ] = radius * Math.sin( segment );
  21440. normals[ i + 2 ] = 1; // normal z
  21441. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  21442. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  21443. }
  21444. var indices = [];
  21445. for ( var i = 1; i <= segments; i ++ ) {
  21446. indices.push( i, i + 1, 0 );
  21447. }
  21448. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  21449. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  21450. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21451. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21452. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  21453. };
  21454. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21455. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  21456. // File:src/extras/geometries/CylinderBufferGeometry.js
  21457. /**
  21458. * @author Mugen87 / https://github.com/Mugen87
  21459. */
  21460. THREE.CylinderBufferGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  21461. THREE.BufferGeometry.call( this );
  21462. this.type = 'CylinderBufferGeometry';
  21463. this.parameters = {
  21464. radiusTop: radiusTop,
  21465. radiusBottom: radiusBottom,
  21466. height: height,
  21467. radialSegments: radialSegments,
  21468. heightSegments: heightSegments,
  21469. openEnded: openEnded,
  21470. thetaStart: thetaStart,
  21471. thetaLength: thetaLength
  21472. };
  21473. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  21474. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  21475. height = height !== undefined ? height : 100;
  21476. radialSegments = Math.floor( radialSegments ) || 8;
  21477. heightSegments = Math.floor( heightSegments ) || 1;
  21478. openEnded = openEnded !== undefined ? openEnded : false;
  21479. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21480. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  21481. // used to calculate buffer length
  21482. var vertexCount = calculateVertexCount();
  21483. var indexCount = calculateIndexCount();
  21484. // buffers
  21485. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  21486. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  21487. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  21488. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  21489. // helper variables
  21490. var index = 0, indexOffset = 0, indexArray = [], halfHeight = height / 2;
  21491. // generate geometry
  21492. generateTorso();
  21493. if( openEnded === false ) {
  21494. if( radiusTop > 0 ) {
  21495. generateCap( true );
  21496. }
  21497. if( radiusBottom > 0 ) {
  21498. generateCap( false );
  21499. }
  21500. }
  21501. // build geometry
  21502. this.setIndex( indices );
  21503. this.addAttribute( 'position', vertices );
  21504. this.addAttribute( 'normal', normals );
  21505. this.addAttribute( 'uv', uvs );
  21506. // helper functions
  21507. function calculateVertexCount () {
  21508. var count = ( radialSegments + 1 ) * ( heightSegments + 1 );
  21509. if ( openEnded === false ) {
  21510. count += ( ( radialSegments + 1 ) * 2 ) + ( radialSegments * 2 );
  21511. }
  21512. return count;
  21513. }
  21514. function calculateIndexCount () {
  21515. var count = radialSegments * heightSegments * 2 * 3;
  21516. if ( openEnded === false ) {
  21517. count += radialSegments * 2 * 3;
  21518. }
  21519. return count;
  21520. }
  21521. function generateTorso () {
  21522. var x, y;
  21523. var normal = new THREE.Vector3();
  21524. var vertex = new THREE.Vector3();
  21525. // this will be used to calculate the normal
  21526. var tanTheta = ( radiusBottom - radiusTop ) / height;
  21527. // generate vertices, normals and uvs
  21528. for ( y = 0; y <= heightSegments; y ++ ) {
  21529. var indexRow = [];
  21530. var v = y / heightSegments;
  21531. // calculate the radius of the current row
  21532. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  21533. for ( x = 0; x <= radialSegments; x ++ ) {
  21534. var u = x / radialSegments;
  21535. // vertex
  21536. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  21537. vertex.y = - v * height + halfHeight;
  21538. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  21539. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  21540. // normal
  21541. normal.copy( vertex );
  21542. // handle special case if radiusTop/radiusBottom is zero
  21543. if( ( radiusTop === 0 && y === 0 ) || ( radiusBottom === 0 && y === heightSegments ) ) {
  21544. normal.x = Math.sin( u * thetaLength + thetaStart );
  21545. normal.z = Math.cos( u * thetaLength + thetaStart );
  21546. }
  21547. normal.setY( Math.sqrt( normal.x * normal.x + normal.z * normal.z ) * tanTheta ).normalize();
  21548. normals.setXYZ( index, normal.x, normal.y, normal.z );
  21549. // uv
  21550. uvs.setXY( index, u, 1 - v );
  21551. // save index of vertex in respective row
  21552. indexRow.push( index );
  21553. // increase index
  21554. index ++;
  21555. }
  21556. // now save vertices of the row in our index array
  21557. indexArray.push( indexRow );
  21558. }
  21559. // generate indices
  21560. for ( x = 0; x < radialSegments; x ++ ) {
  21561. for ( y = 0; y < heightSegments; y ++ ) {
  21562. // we use the index array to access the correct indices
  21563. var i1 = indexArray[ y ][ x ];
  21564. var i2 = indexArray[ y + 1 ][ x ];
  21565. var i3 = indexArray[ y + 1 ][ x + 1 ];
  21566. var i4 = indexArray[ y ][ x + 1 ];
  21567. // face one
  21568. indices.setX( indexOffset, i1 ); indexOffset++;
  21569. indices.setX( indexOffset, i2 ); indexOffset++;
  21570. indices.setX( indexOffset, i4 ); indexOffset++;
  21571. // face two
  21572. indices.setX( indexOffset, i2 ); indexOffset++;
  21573. indices.setX( indexOffset, i3 ); indexOffset++;
  21574. indices.setX( indexOffset, i4 ); indexOffset++;
  21575. }
  21576. }
  21577. }
  21578. function generateCap ( top ) {
  21579. var x, centerIndexStart, centerIndexEnd;
  21580. var uv = new THREE.Vector2();
  21581. var vertex = new THREE.Vector3();
  21582. var radius = ( top === true ) ? radiusTop : radiusBottom;
  21583. var sign = ( top === true ) ? 1 : - 1;
  21584. // save the index of the first center vertex
  21585. centerIndexStart = index;
  21586. // first we generate the center vertex data of the cap.
  21587. // because the geometry needs one set of uvs per face,
  21588. // we must generate a center vertex per face/segment
  21589. for ( x = 1; x <= radialSegments; x ++ ) {
  21590. // vertex
  21591. vertices.setXYZ( index, 0, halfHeight * sign, 0 );
  21592. // normal
  21593. normals.setXYZ( index, 0, sign, 0 );
  21594. // uv
  21595. if( top === true ) {
  21596. uv.x = x / radialSegments;
  21597. uv.y = 0;
  21598. } else {
  21599. uv.x = ( x - 1 ) / radialSegments;
  21600. uv.y = 1;
  21601. }
  21602. uvs.setXY( index, uv.x, uv.y );
  21603. // increase index
  21604. index++;
  21605. }
  21606. // save the index of the last center vertex
  21607. centerIndexEnd = index;
  21608. // now we generate the surrounding vertices, normals and uvs
  21609. for ( x = 0; x <= radialSegments; x ++ ) {
  21610. var u = x / radialSegments;
  21611. // vertex
  21612. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  21613. vertex.y = halfHeight * sign;
  21614. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  21615. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  21616. // normal
  21617. normals.setXYZ( index, 0, sign, 0 );
  21618. // uv
  21619. uvs.setXY( index, u, ( top === true ) ? 1 : 0 );
  21620. // increase index
  21621. index ++;
  21622. }
  21623. // generate indices
  21624. for ( x = 0; x < radialSegments; x ++ ) {
  21625. var c = centerIndexStart + x;
  21626. var i = centerIndexEnd + x;
  21627. if( top === true ) {
  21628. // face top
  21629. indices.setX( indexOffset, i ); indexOffset++;
  21630. indices.setX( indexOffset, i + 1 ); indexOffset++;
  21631. indices.setX( indexOffset, c ); indexOffset++;
  21632. } else {
  21633. // face bottom
  21634. indices.setX( indexOffset, i + 1); indexOffset++;
  21635. indices.setX( indexOffset, i ); indexOffset++;
  21636. indices.setX( indexOffset, c ); indexOffset++;
  21637. }
  21638. }
  21639. }
  21640. };
  21641. THREE.CylinderBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21642. THREE.CylinderBufferGeometry.prototype.constructor = THREE.CylinderBufferGeometry;
  21643. // File:src/extras/geometries/CylinderGeometry.js
  21644. /**
  21645. * @author mrdoob / http://mrdoob.com/
  21646. */
  21647. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  21648. THREE.Geometry.call( this );
  21649. this.type = 'CylinderGeometry';
  21650. this.parameters = {
  21651. radiusTop: radiusTop,
  21652. radiusBottom: radiusBottom,
  21653. height: height,
  21654. radialSegments: radialSegments,
  21655. heightSegments: heightSegments,
  21656. openEnded: openEnded,
  21657. thetaStart: thetaStart,
  21658. thetaLength: thetaLength
  21659. };
  21660. this.fromBufferGeometry( new THREE.CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  21661. this.mergeVertices();
  21662. };
  21663. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21664. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  21665. // File:src/extras/geometries/EdgesGeometry.js
  21666. /**
  21667. * @author WestLangley / http://github.com/WestLangley
  21668. */
  21669. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  21670. THREE.BufferGeometry.call( this );
  21671. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  21672. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  21673. var edge = [ 0, 0 ], hash = {};
  21674. function sortFunction( a, b ) {
  21675. return a - b;
  21676. }
  21677. var keys = [ 'a', 'b', 'c' ];
  21678. var geometry2;
  21679. if ( geometry instanceof THREE.BufferGeometry ) {
  21680. geometry2 = new THREE.Geometry();
  21681. geometry2.fromBufferGeometry( geometry );
  21682. } else {
  21683. geometry2 = geometry.clone();
  21684. }
  21685. geometry2.mergeVertices();
  21686. geometry2.computeFaceNormals();
  21687. var vertices = geometry2.vertices;
  21688. var faces = geometry2.faces;
  21689. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21690. var face = faces[ i ];
  21691. for ( var j = 0; j < 3; j ++ ) {
  21692. edge[ 0 ] = face[ keys[ j ] ];
  21693. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  21694. edge.sort( sortFunction );
  21695. var key = edge.toString();
  21696. if ( hash[ key ] === undefined ) {
  21697. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  21698. } else {
  21699. hash[ key ].face2 = i;
  21700. }
  21701. }
  21702. }
  21703. var coords = [];
  21704. for ( var key in hash ) {
  21705. var h = hash[ key ];
  21706. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  21707. var vertex = vertices[ h.vert1 ];
  21708. coords.push( vertex.x );
  21709. coords.push( vertex.y );
  21710. coords.push( vertex.z );
  21711. vertex = vertices[ h.vert2 ];
  21712. coords.push( vertex.x );
  21713. coords.push( vertex.y );
  21714. coords.push( vertex.z );
  21715. }
  21716. }
  21717. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  21718. };
  21719. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21720. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  21721. // File:src/extras/geometries/ExtrudeGeometry.js
  21722. /**
  21723. * @author zz85 / http://www.lab4games.net/zz85/blog
  21724. *
  21725. * Creates extruded geometry from a path shape.
  21726. *
  21727. * parameters = {
  21728. *
  21729. * curveSegments: <int>, // number of points on the curves
  21730. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  21731. * amount: <int>, // Depth to extrude the shape
  21732. *
  21733. * bevelEnabled: <bool>, // turn on bevel
  21734. * bevelThickness: <float>, // how deep into the original shape bevel goes
  21735. * bevelSize: <float>, // how far from shape outline is bevel
  21736. * bevelSegments: <int>, // number of bevel layers
  21737. *
  21738. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  21739. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  21740. *
  21741. * uvGenerator: <Object> // object that provides UV generator functions
  21742. *
  21743. * }
  21744. **/
  21745. THREE.ExtrudeGeometry = function ( shapes, options ) {
  21746. if ( typeof( shapes ) === "undefined" ) {
  21747. shapes = [];
  21748. return;
  21749. }
  21750. THREE.Geometry.call( this );
  21751. this.type = 'ExtrudeGeometry';
  21752. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  21753. this.addShapeList( shapes, options );
  21754. this.computeFaceNormals();
  21755. // can't really use automatic vertex normals
  21756. // as then front and back sides get smoothed too
  21757. // should do separate smoothing just for sides
  21758. //this.computeVertexNormals();
  21759. //console.log( "took", ( Date.now() - startTime ) );
  21760. };
  21761. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21762. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  21763. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  21764. var sl = shapes.length;
  21765. for ( var s = 0; s < sl; s ++ ) {
  21766. var shape = shapes[ s ];
  21767. this.addShape( shape, options );
  21768. }
  21769. };
  21770. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  21771. var amount = options.amount !== undefined ? options.amount : 100;
  21772. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  21773. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  21774. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  21775. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  21776. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  21777. var steps = options.steps !== undefined ? options.steps : 1;
  21778. var extrudePath = options.extrudePath;
  21779. var extrudePts, extrudeByPath = false;
  21780. // Use default WorldUVGenerator if no UV generators are specified.
  21781. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  21782. var splineTube, binormal, normal, position2;
  21783. if ( extrudePath ) {
  21784. extrudePts = extrudePath.getSpacedPoints( steps );
  21785. extrudeByPath = true;
  21786. bevelEnabled = false; // bevels not supported for path extrusion
  21787. // SETUP TNB variables
  21788. // Reuse TNB from TubeGeomtry for now.
  21789. // TODO1 - have a .isClosed in spline?
  21790. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  21791. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  21792. binormal = new THREE.Vector3();
  21793. normal = new THREE.Vector3();
  21794. position2 = new THREE.Vector3();
  21795. }
  21796. // Safeguards if bevels are not enabled
  21797. if ( ! bevelEnabled ) {
  21798. bevelSegments = 0;
  21799. bevelThickness = 0;
  21800. bevelSize = 0;
  21801. }
  21802. // Variables initialization
  21803. var ahole, h, hl; // looping of holes
  21804. var scope = this;
  21805. var shapesOffset = this.vertices.length;
  21806. var shapePoints = shape.extractPoints( curveSegments );
  21807. var vertices = shapePoints.shape;
  21808. var holes = shapePoints.holes;
  21809. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  21810. if ( reverse ) {
  21811. vertices = vertices.reverse();
  21812. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  21813. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21814. ahole = holes[ h ];
  21815. if ( THREE.ShapeUtils.isClockWise( ahole ) ) {
  21816. holes[ h ] = ahole.reverse();
  21817. }
  21818. }
  21819. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  21820. }
  21821. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  21822. /* Vertices */
  21823. var contour = vertices; // vertices has all points but contour has only points of circumference
  21824. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21825. ahole = holes[ h ];
  21826. vertices = vertices.concat( ahole );
  21827. }
  21828. function scalePt2 ( pt, vec, size ) {
  21829. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  21830. return vec.clone().multiplyScalar( size ).add( pt );
  21831. }
  21832. var b, bs, t, z,
  21833. vert, vlen = vertices.length,
  21834. face, flen = faces.length;
  21835. // Find directions for point movement
  21836. function getBevelVec( inPt, inPrev, inNext ) {
  21837. // computes for inPt the corresponding point inPt' on a new contour
  21838. // shifted by 1 unit (length of normalized vector) to the left
  21839. // if we walk along contour clockwise, this new contour is outside the old one
  21840. //
  21841. // inPt' is the intersection of the two lines parallel to the two
  21842. // adjacent edges of inPt at a distance of 1 unit on the left side.
  21843. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  21844. // good reading for geometry algorithms (here: line-line intersection)
  21845. // http://geomalgorithms.com/a05-_intersect-1.html
  21846. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  21847. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  21848. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  21849. // check for collinear edges
  21850. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  21851. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  21852. // not collinear
  21853. // length of vectors for normalizing
  21854. var v_prev_len = Math.sqrt( v_prev_lensq );
  21855. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  21856. // shift adjacent points by unit vectors to the left
  21857. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  21858. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  21859. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  21860. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  21861. // scaling factor for v_prev to intersection point
  21862. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  21863. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  21864. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  21865. // vector from inPt to intersection point
  21866. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  21867. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  21868. // Don't normalize!, otherwise sharp corners become ugly
  21869. // but prevent crazy spikes
  21870. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  21871. if ( v_trans_lensq <= 2 ) {
  21872. return new THREE.Vector2( v_trans_x, v_trans_y );
  21873. } else {
  21874. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  21875. }
  21876. } else {
  21877. // handle special case of collinear edges
  21878. var direction_eq = false; // assumes: opposite
  21879. if ( v_prev_x > Number.EPSILON ) {
  21880. if ( v_next_x > Number.EPSILON ) {
  21881. direction_eq = true;
  21882. }
  21883. } else {
  21884. if ( v_prev_x < - Number.EPSILON ) {
  21885. if ( v_next_x < - Number.EPSILON ) {
  21886. direction_eq = true;
  21887. }
  21888. } else {
  21889. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  21890. direction_eq = true;
  21891. }
  21892. }
  21893. }
  21894. if ( direction_eq ) {
  21895. // console.log("Warning: lines are a straight sequence");
  21896. v_trans_x = - v_prev_y;
  21897. v_trans_y = v_prev_x;
  21898. shrink_by = Math.sqrt( v_prev_lensq );
  21899. } else {
  21900. // console.log("Warning: lines are a straight spike");
  21901. v_trans_x = v_prev_x;
  21902. v_trans_y = v_prev_y;
  21903. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  21904. }
  21905. }
  21906. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  21907. }
  21908. var contourMovements = [];
  21909. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  21910. if ( j === il ) j = 0;
  21911. if ( k === il ) k = 0;
  21912. // (j)---(i)---(k)
  21913. // console.log('i,j,k', i, j , k)
  21914. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  21915. }
  21916. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  21917. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21918. ahole = holes[ h ];
  21919. oneHoleMovements = [];
  21920. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  21921. if ( j === il ) j = 0;
  21922. if ( k === il ) k = 0;
  21923. // (j)---(i)---(k)
  21924. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  21925. }
  21926. holesMovements.push( oneHoleMovements );
  21927. verticesMovements = verticesMovements.concat( oneHoleMovements );
  21928. }
  21929. // Loop bevelSegments, 1 for the front, 1 for the back
  21930. for ( b = 0; b < bevelSegments; b ++ ) {
  21931. //for ( b = bevelSegments; b > 0; b -- ) {
  21932. t = b / bevelSegments;
  21933. z = bevelThickness * ( 1 - t );
  21934. //z = bevelThickness * t;
  21935. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  21936. //bs = bevelSize * t; // linear
  21937. // contract shape
  21938. for ( i = 0, il = contour.length; i < il; i ++ ) {
  21939. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  21940. v( vert.x, vert.y, - z );
  21941. }
  21942. // expand holes
  21943. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21944. ahole = holes[ h ];
  21945. oneHoleMovements = holesMovements[ h ];
  21946. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  21947. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  21948. v( vert.x, vert.y, - z );
  21949. }
  21950. }
  21951. }
  21952. bs = bevelSize;
  21953. // Back facing vertices
  21954. for ( i = 0; i < vlen; i ++ ) {
  21955. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  21956. if ( ! extrudeByPath ) {
  21957. v( vert.x, vert.y, 0 );
  21958. } else {
  21959. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  21960. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  21961. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  21962. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  21963. v( position2.x, position2.y, position2.z );
  21964. }
  21965. }
  21966. // Add stepped vertices...
  21967. // Including front facing vertices
  21968. var s;
  21969. for ( s = 1; s <= steps; s ++ ) {
  21970. for ( i = 0; i < vlen; i ++ ) {
  21971. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  21972. if ( ! extrudeByPath ) {
  21973. v( vert.x, vert.y, amount / steps * s );
  21974. } else {
  21975. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  21976. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  21977. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  21978. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  21979. v( position2.x, position2.y, position2.z );
  21980. }
  21981. }
  21982. }
  21983. // Add bevel segments planes
  21984. //for ( b = 1; b <= bevelSegments; b ++ ) {
  21985. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  21986. t = b / bevelSegments;
  21987. z = bevelThickness * ( 1 - t );
  21988. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  21989. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  21990. // contract shape
  21991. for ( i = 0, il = contour.length; i < il; i ++ ) {
  21992. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  21993. v( vert.x, vert.y, amount + z );
  21994. }
  21995. // expand holes
  21996. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21997. ahole = holes[ h ];
  21998. oneHoleMovements = holesMovements[ h ];
  21999. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22000. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22001. if ( ! extrudeByPath ) {
  22002. v( vert.x, vert.y, amount + z );
  22003. } else {
  22004. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  22005. }
  22006. }
  22007. }
  22008. }
  22009. /* Faces */
  22010. // Top and bottom faces
  22011. buildLidFaces();
  22012. // Sides faces
  22013. buildSideFaces();
  22014. ///// Internal functions
  22015. function buildLidFaces() {
  22016. if ( bevelEnabled ) {
  22017. var layer = 0; // steps + 1
  22018. var offset = vlen * layer;
  22019. // Bottom faces
  22020. for ( i = 0; i < flen; i ++ ) {
  22021. face = faces[ i ];
  22022. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  22023. }
  22024. layer = steps + bevelSegments * 2;
  22025. offset = vlen * layer;
  22026. // Top faces
  22027. for ( i = 0; i < flen; i ++ ) {
  22028. face = faces[ i ];
  22029. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  22030. }
  22031. } else {
  22032. // Bottom faces
  22033. for ( i = 0; i < flen; i ++ ) {
  22034. face = faces[ i ];
  22035. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  22036. }
  22037. // Top faces
  22038. for ( i = 0; i < flen; i ++ ) {
  22039. face = faces[ i ];
  22040. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  22041. }
  22042. }
  22043. }
  22044. // Create faces for the z-sides of the shape
  22045. function buildSideFaces() {
  22046. var layeroffset = 0;
  22047. sidewalls( contour, layeroffset );
  22048. layeroffset += contour.length;
  22049. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22050. ahole = holes[ h ];
  22051. sidewalls( ahole, layeroffset );
  22052. //, true
  22053. layeroffset += ahole.length;
  22054. }
  22055. }
  22056. function sidewalls( contour, layeroffset ) {
  22057. var j, k;
  22058. i = contour.length;
  22059. while ( -- i >= 0 ) {
  22060. j = i;
  22061. k = i - 1;
  22062. if ( k < 0 ) k = contour.length - 1;
  22063. //console.log('b', i,j, i-1, k,vertices.length);
  22064. var s = 0, sl = steps + bevelSegments * 2;
  22065. for ( s = 0; s < sl; s ++ ) {
  22066. var slen1 = vlen * s;
  22067. var slen2 = vlen * ( s + 1 );
  22068. var a = layeroffset + j + slen1,
  22069. b = layeroffset + k + slen1,
  22070. c = layeroffset + k + slen2,
  22071. d = layeroffset + j + slen2;
  22072. f4( a, b, c, d, contour, s, sl, j, k );
  22073. }
  22074. }
  22075. }
  22076. function v( x, y, z ) {
  22077. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  22078. }
  22079. function f3( a, b, c ) {
  22080. a += shapesOffset;
  22081. b += shapesOffset;
  22082. c += shapesOffset;
  22083. scope.faces.push( new THREE.Face3( a, b, c, null, null, 0 ) );
  22084. var uvs = uvgen.generateTopUV( scope, a, b, c );
  22085. scope.faceVertexUvs[ 0 ].push( uvs );
  22086. }
  22087. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  22088. a += shapesOffset;
  22089. b += shapesOffset;
  22090. c += shapesOffset;
  22091. d += shapesOffset;
  22092. scope.faces.push( new THREE.Face3( a, b, d, null, null, 1 ) );
  22093. scope.faces.push( new THREE.Face3( b, c, d, null, null, 1 ) );
  22094. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  22095. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  22096. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  22097. }
  22098. };
  22099. THREE.ExtrudeGeometry.WorldUVGenerator = {
  22100. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  22101. var vertices = geometry.vertices;
  22102. var a = vertices[ indexA ];
  22103. var b = vertices[ indexB ];
  22104. var c = vertices[ indexC ];
  22105. return [
  22106. new THREE.Vector2( a.x, a.y ),
  22107. new THREE.Vector2( b.x, b.y ),
  22108. new THREE.Vector2( c.x, c.y )
  22109. ];
  22110. },
  22111. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  22112. var vertices = geometry.vertices;
  22113. var a = vertices[ indexA ];
  22114. var b = vertices[ indexB ];
  22115. var c = vertices[ indexC ];
  22116. var d = vertices[ indexD ];
  22117. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  22118. return [
  22119. new THREE.Vector2( a.x, 1 - a.z ),
  22120. new THREE.Vector2( b.x, 1 - b.z ),
  22121. new THREE.Vector2( c.x, 1 - c.z ),
  22122. new THREE.Vector2( d.x, 1 - d.z )
  22123. ];
  22124. } else {
  22125. return [
  22126. new THREE.Vector2( a.y, 1 - a.z ),
  22127. new THREE.Vector2( b.y, 1 - b.z ),
  22128. new THREE.Vector2( c.y, 1 - c.z ),
  22129. new THREE.Vector2( d.y, 1 - d.z )
  22130. ];
  22131. }
  22132. }
  22133. };
  22134. // File:src/extras/geometries/ShapeGeometry.js
  22135. /**
  22136. * @author jonobr1 / http://jonobr1.com
  22137. *
  22138. * Creates a one-sided polygonal geometry from a path shape. Similar to
  22139. * ExtrudeGeometry.
  22140. *
  22141. * parameters = {
  22142. *
  22143. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  22144. *
  22145. * material: <int> // material index for front and back faces
  22146. * uvGenerator: <Object> // object that provides UV generator functions
  22147. *
  22148. * }
  22149. **/
  22150. THREE.ShapeGeometry = function ( shapes, options ) {
  22151. THREE.Geometry.call( this );
  22152. this.type = 'ShapeGeometry';
  22153. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  22154. this.addShapeList( shapes, options );
  22155. this.computeFaceNormals();
  22156. };
  22157. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22158. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  22159. /**
  22160. * Add an array of shapes to THREE.ShapeGeometry.
  22161. */
  22162. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  22163. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  22164. this.addShape( shapes[ i ], options );
  22165. }
  22166. return this;
  22167. };
  22168. /**
  22169. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  22170. */
  22171. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  22172. if ( options === undefined ) options = {};
  22173. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  22174. var material = options.material;
  22175. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  22176. //
  22177. var i, l, hole;
  22178. var shapesOffset = this.vertices.length;
  22179. var shapePoints = shape.extractPoints( curveSegments );
  22180. var vertices = shapePoints.shape;
  22181. var holes = shapePoints.holes;
  22182. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22183. if ( reverse ) {
  22184. vertices = vertices.reverse();
  22185. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  22186. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22187. hole = holes[ i ];
  22188. if ( THREE.ShapeUtils.isClockWise( hole ) ) {
  22189. holes[ i ] = hole.reverse();
  22190. }
  22191. }
  22192. reverse = false;
  22193. }
  22194. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22195. // Vertices
  22196. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22197. hole = holes[ i ];
  22198. vertices = vertices.concat( hole );
  22199. }
  22200. //
  22201. var vert, vlen = vertices.length;
  22202. var face, flen = faces.length;
  22203. for ( i = 0; i < vlen; i ++ ) {
  22204. vert = vertices[ i ];
  22205. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  22206. }
  22207. for ( i = 0; i < flen; i ++ ) {
  22208. face = faces[ i ];
  22209. var a = face[ 0 ] + shapesOffset;
  22210. var b = face[ 1 ] + shapesOffset;
  22211. var c = face[ 2 ] + shapesOffset;
  22212. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  22213. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  22214. }
  22215. };
  22216. // File:src/extras/geometries/LatheBufferGeometry.js
  22217. /**
  22218. * @author Mugen87 / https://github.com/Mugen87
  22219. */
  22220. // points - to create a closed torus, one must use a set of points
  22221. // like so: [ a, b, c, d, a ], see first is the same as last.
  22222. // segments - the number of circumference segments to create
  22223. // phiStart - the starting radian
  22224. // phiLength - the radian (0 to 2PI) range of the lathed section
  22225. // 2PI is a closed lathe, less than 2PI is a portion.
  22226. THREE.LatheBufferGeometry = function ( points, segments, phiStart, phiLength ) {
  22227. THREE.BufferGeometry.call( this );
  22228. this.type = 'LatheBufferGeometry';
  22229. this.parameters = {
  22230. points: points,
  22231. segments: segments,
  22232. phiStart: phiStart,
  22233. phiLength: phiLength
  22234. };
  22235. segments = Math.floor( segments ) || 12;
  22236. phiStart = phiStart || 0;
  22237. phiLength = phiLength || Math.PI * 2;
  22238. // clamp phiLength so it's in range of [ 0, 2PI ]
  22239. phiLength = THREE.Math.clamp( phiLength, 0, Math.PI * 2 );
  22240. // these are used to calculate buffer length
  22241. var vertexCount = ( segments + 1 ) * points.length;
  22242. var indexCount = segments * points.length * 2 * 3;
  22243. // buffers
  22244. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  22245. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22246. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22247. // helper variables
  22248. var index = 0, indexOffset = 0, base;
  22249. var inversePointLength = 1.0 / ( points.length - 1 );
  22250. var inverseSegments = 1.0 / segments;
  22251. var vertex = new THREE.Vector3();
  22252. var uv = new THREE.Vector2();
  22253. var i, j;
  22254. // generate vertices and uvs
  22255. for ( i = 0; i <= segments; i ++ ) {
  22256. var phi = phiStart + i * inverseSegments * phiLength;
  22257. var sin = Math.sin( phi );
  22258. var cos = Math.cos( phi );
  22259. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  22260. // vertex
  22261. vertex.x = points[ j ].x * sin;
  22262. vertex.y = points[ j ].y;
  22263. vertex.z = points[ j ].x * cos;
  22264. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22265. // uv
  22266. uv.x = i / segments;
  22267. uv.y = j / ( points.length - 1 );
  22268. uvs.setXY( index, uv.x, uv.y );
  22269. // increase index
  22270. index ++;
  22271. }
  22272. }
  22273. // generate indices
  22274. for ( i = 0; i < segments; i ++ ) {
  22275. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  22276. base = j + i * points.length;
  22277. // indices
  22278. var a = base;
  22279. var b = base + points.length;
  22280. var c = base + points.length + 1;
  22281. var d = base + 1;
  22282. // face one
  22283. indices.setX( indexOffset, a ); indexOffset++;
  22284. indices.setX( indexOffset, b ); indexOffset++;
  22285. indices.setX( indexOffset, d ); indexOffset++;
  22286. // face two
  22287. indices.setX( indexOffset, b ); indexOffset++;
  22288. indices.setX( indexOffset, c ); indexOffset++;
  22289. indices.setX( indexOffset, d ); indexOffset++;
  22290. }
  22291. }
  22292. // build geometry
  22293. this.setIndex( indices );
  22294. this.addAttribute( 'position', vertices );
  22295. this.addAttribute( 'uv', uvs );
  22296. // generate normals
  22297. this.computeVertexNormals();
  22298. // if the geometry is closed, we need to average the normals along the seam.
  22299. // because the corresponding vertices are identical (but still have different UVs).
  22300. if( phiLength === Math.PI * 2 ) {
  22301. var normals = this.attributes.normal.array;
  22302. var n1 = new THREE.Vector3();
  22303. var n2 = new THREE.Vector3();
  22304. var n = new THREE.Vector3();
  22305. // this is the buffer offset for the last line of vertices
  22306. base = segments * points.length * 3;
  22307. for( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  22308. // select the normal of the vertex in the first line
  22309. n1.x = normals[ j + 0 ];
  22310. n1.y = normals[ j + 1 ];
  22311. n1.z = normals[ j + 2 ];
  22312. // select the normal of the vertex in the last line
  22313. n2.x = normals[ base + j + 0 ];
  22314. n2.y = normals[ base + j + 1 ];
  22315. n2.z = normals[ base + j + 2 ];
  22316. // average normals
  22317. n.addVectors( n1, n2 ).normalize();
  22318. // assign the new values to both normals
  22319. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  22320. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  22321. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  22322. } // next row
  22323. }
  22324. };
  22325. THREE.LatheBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22326. THREE.LatheBufferGeometry.prototype.constructor = THREE.LatheBufferGeometry;
  22327. // File:src/extras/geometries/LatheGeometry.js
  22328. /**
  22329. * @author astrodud / http://astrodud.isgreat.org/
  22330. * @author zz85 / https://github.com/zz85
  22331. * @author bhouston / http://clara.io
  22332. */
  22333. // points - to create a closed torus, one must use a set of points
  22334. // like so: [ a, b, c, d, a ], see first is the same as last.
  22335. // segments - the number of circumference segments to create
  22336. // phiStart - the starting radian
  22337. // phiLength - the radian (0 to 2PI) range of the lathed section
  22338. // 2PI is a closed lathe, less than 2PI is a portion.
  22339. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  22340. THREE.Geometry.call( this );
  22341. this.type = 'LatheGeometry';
  22342. this.parameters = {
  22343. points: points,
  22344. segments: segments,
  22345. phiStart: phiStart,
  22346. phiLength: phiLength
  22347. };
  22348. this.fromBufferGeometry( new THREE.LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  22349. this.mergeVertices();
  22350. };
  22351. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22352. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  22353. // File:src/extras/geometries/PlaneGeometry.js
  22354. /**
  22355. * @author mrdoob / http://mrdoob.com/
  22356. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22357. */
  22358. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  22359. THREE.Geometry.call( this );
  22360. this.type = 'PlaneGeometry';
  22361. this.parameters = {
  22362. width: width,
  22363. height: height,
  22364. widthSegments: widthSegments,
  22365. heightSegments: heightSegments
  22366. };
  22367. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  22368. };
  22369. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22370. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  22371. // File:src/extras/geometries/PlaneBufferGeometry.js
  22372. /**
  22373. * @author mrdoob / http://mrdoob.com/
  22374. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22375. */
  22376. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  22377. THREE.BufferGeometry.call( this );
  22378. this.type = 'PlaneBufferGeometry';
  22379. this.parameters = {
  22380. width: width,
  22381. height: height,
  22382. widthSegments: widthSegments,
  22383. heightSegments: heightSegments
  22384. };
  22385. var width_half = width / 2;
  22386. var height_half = height / 2;
  22387. var gridX = Math.floor( widthSegments ) || 1;
  22388. var gridY = Math.floor( heightSegments ) || 1;
  22389. var gridX1 = gridX + 1;
  22390. var gridY1 = gridY + 1;
  22391. var segment_width = width / gridX;
  22392. var segment_height = height / gridY;
  22393. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  22394. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  22395. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  22396. var offset = 0;
  22397. var offset2 = 0;
  22398. for ( var iy = 0; iy < gridY1; iy ++ ) {
  22399. var y = iy * segment_height - height_half;
  22400. for ( var ix = 0; ix < gridX1; ix ++ ) {
  22401. var x = ix * segment_width - width_half;
  22402. vertices[ offset ] = x;
  22403. vertices[ offset + 1 ] = - y;
  22404. normals[ offset + 2 ] = 1;
  22405. uvs[ offset2 ] = ix / gridX;
  22406. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  22407. offset += 3;
  22408. offset2 += 2;
  22409. }
  22410. }
  22411. offset = 0;
  22412. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  22413. for ( var iy = 0; iy < gridY; iy ++ ) {
  22414. for ( var ix = 0; ix < gridX; ix ++ ) {
  22415. var a = ix + gridX1 * iy;
  22416. var b = ix + gridX1 * ( iy + 1 );
  22417. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  22418. var d = ( ix + 1 ) + gridX1 * iy;
  22419. indices[ offset ] = a;
  22420. indices[ offset + 1 ] = b;
  22421. indices[ offset + 2 ] = d;
  22422. indices[ offset + 3 ] = b;
  22423. indices[ offset + 4 ] = c;
  22424. indices[ offset + 5 ] = d;
  22425. offset += 6;
  22426. }
  22427. }
  22428. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  22429. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  22430. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  22431. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  22432. };
  22433. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22434. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  22435. // File:src/extras/geometries/RingBufferGeometry.js
  22436. /**
  22437. * @author Mugen87 / https://github.com/Mugen87
  22438. */
  22439. THREE.RingBufferGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  22440. THREE.BufferGeometry.call( this );
  22441. this.type = 'RingBufferGeometry';
  22442. this.parameters = {
  22443. innerRadius: innerRadius,
  22444. outerRadius: outerRadius,
  22445. thetaSegments: thetaSegments,
  22446. phiSegments: phiSegments,
  22447. thetaStart: thetaStart,
  22448. thetaLength: thetaLength
  22449. };
  22450. innerRadius = innerRadius || 20;
  22451. outerRadius = outerRadius || 50;
  22452. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  22453. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  22454. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  22455. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  22456. // these are used to calculate buffer length
  22457. var vertexCount = ( thetaSegments + 1 ) * ( phiSegments + 1 );
  22458. var indexCount = thetaSegments * phiSegments * 2 * 3;
  22459. // buffers
  22460. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  22461. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22462. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22463. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22464. // some helper variables
  22465. var index = 0, indexOffset = 0, segment;
  22466. var radius = innerRadius;
  22467. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  22468. var vertex = new THREE.Vector3();
  22469. var uv = new THREE.Vector2();
  22470. var j, i;
  22471. // generate vertices, normals and uvs
  22472. // values are generate from the inside of the ring to the outside
  22473. for ( j = 0; j <= phiSegments; j ++ ) {
  22474. for ( i = 0; i <= thetaSegments; i ++ ) {
  22475. segment = thetaStart + i / thetaSegments * thetaLength;
  22476. // vertex
  22477. vertex.x = radius * Math.cos( segment );
  22478. vertex.y = radius * Math.sin( segment );
  22479. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22480. // normal
  22481. normals.setXYZ( index, 0, 0, 1 );
  22482. // uv
  22483. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  22484. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  22485. uvs.setXY( index, uv.x, uv.y );
  22486. // increase index
  22487. index++;
  22488. }
  22489. // increase the radius for next row of vertices
  22490. radius += radiusStep;
  22491. }
  22492. // generate indices
  22493. for ( j = 0; j < phiSegments; j ++ ) {
  22494. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  22495. for ( i = 0; i < thetaSegments; i ++ ) {
  22496. segment = i + thetaSegmentLevel;
  22497. // indices
  22498. var a = segment;
  22499. var b = segment + thetaSegments + 1;
  22500. var c = segment + thetaSegments + 2;
  22501. var d = segment + 1;
  22502. // face one
  22503. indices.setX( indexOffset, a ); indexOffset++;
  22504. indices.setX( indexOffset, b ); indexOffset++;
  22505. indices.setX( indexOffset, c ); indexOffset++;
  22506. // face two
  22507. indices.setX( indexOffset, a ); indexOffset++;
  22508. indices.setX( indexOffset, c ); indexOffset++;
  22509. indices.setX( indexOffset, d ); indexOffset++;
  22510. }
  22511. }
  22512. // build geometry
  22513. this.setIndex( indices );
  22514. this.addAttribute( 'position', vertices );
  22515. this.addAttribute( 'normal', normals );
  22516. this.addAttribute( 'uv', uvs );
  22517. };
  22518. THREE.RingBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22519. THREE.RingBufferGeometry.prototype.constructor = THREE.RingBufferGeometry;
  22520. // File:src/extras/geometries/RingGeometry.js
  22521. /**
  22522. * @author Kaleb Murphy
  22523. */
  22524. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  22525. THREE.Geometry.call( this );
  22526. this.type = 'RingGeometry';
  22527. this.parameters = {
  22528. innerRadius: innerRadius,
  22529. outerRadius: outerRadius,
  22530. thetaSegments: thetaSegments,
  22531. phiSegments: phiSegments,
  22532. thetaStart: thetaStart,
  22533. thetaLength: thetaLength
  22534. };
  22535. this.fromBufferGeometry( new THREE.RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  22536. };
  22537. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22538. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  22539. // File:src/extras/geometries/SphereGeometry.js
  22540. /**
  22541. * @author mrdoob / http://mrdoob.com/
  22542. */
  22543. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  22544. THREE.Geometry.call( this );
  22545. this.type = 'SphereGeometry';
  22546. this.parameters = {
  22547. radius: radius,
  22548. widthSegments: widthSegments,
  22549. heightSegments: heightSegments,
  22550. phiStart: phiStart,
  22551. phiLength: phiLength,
  22552. thetaStart: thetaStart,
  22553. thetaLength: thetaLength
  22554. };
  22555. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  22556. };
  22557. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22558. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  22559. // File:src/extras/geometries/SphereBufferGeometry.js
  22560. /**
  22561. * @author benaadams / https://twitter.com/ben_a_adams
  22562. * based on THREE.SphereGeometry
  22563. */
  22564. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  22565. THREE.BufferGeometry.call( this );
  22566. this.type = 'SphereBufferGeometry';
  22567. this.parameters = {
  22568. radius: radius,
  22569. widthSegments: widthSegments,
  22570. heightSegments: heightSegments,
  22571. phiStart: phiStart,
  22572. phiLength: phiLength,
  22573. thetaStart: thetaStart,
  22574. thetaLength: thetaLength
  22575. };
  22576. radius = radius || 50;
  22577. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  22578. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  22579. phiStart = phiStart !== undefined ? phiStart : 0;
  22580. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  22581. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  22582. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  22583. var thetaEnd = thetaStart + thetaLength;
  22584. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  22585. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22586. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22587. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22588. var index = 0, vertices = [], normal = new THREE.Vector3();
  22589. for ( var y = 0; y <= heightSegments; y ++ ) {
  22590. var verticesRow = [];
  22591. var v = y / heightSegments;
  22592. for ( var x = 0; x <= widthSegments; x ++ ) {
  22593. var u = x / widthSegments;
  22594. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  22595. var py = radius * Math.cos( thetaStart + v * thetaLength );
  22596. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  22597. normal.set( px, py, pz ).normalize();
  22598. positions.setXYZ( index, px, py, pz );
  22599. normals.setXYZ( index, normal.x, normal.y, normal.z );
  22600. uvs.setXY( index, u, 1 - v );
  22601. verticesRow.push( index );
  22602. index ++;
  22603. }
  22604. vertices.push( verticesRow );
  22605. }
  22606. var indices = [];
  22607. for ( var y = 0; y < heightSegments; y ++ ) {
  22608. for ( var x = 0; x < widthSegments; x ++ ) {
  22609. var v1 = vertices[ y ][ x + 1 ];
  22610. var v2 = vertices[ y ][ x ];
  22611. var v3 = vertices[ y + 1 ][ x ];
  22612. var v4 = vertices[ y + 1 ][ x + 1 ];
  22613. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  22614. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  22615. }
  22616. }
  22617. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  22618. this.addAttribute( 'position', positions );
  22619. this.addAttribute( 'normal', normals );
  22620. this.addAttribute( 'uv', uvs );
  22621. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22622. };
  22623. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22624. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  22625. // File:src/extras/geometries/TextGeometry.js
  22626. /**
  22627. * @author zz85 / http://www.lab4games.net/zz85/blog
  22628. * @author alteredq / http://alteredqualia.com/
  22629. *
  22630. * Text = 3D Text
  22631. *
  22632. * parameters = {
  22633. * font: <THREE.Font>, // font
  22634. *
  22635. * size: <float>, // size of the text
  22636. * height: <float>, // thickness to extrude text
  22637. * curveSegments: <int>, // number of points on the curves
  22638. *
  22639. * bevelEnabled: <bool>, // turn on bevel
  22640. * bevelThickness: <float>, // how deep into text bevel goes
  22641. * bevelSize: <float> // how far from text outline is bevel
  22642. * }
  22643. */
  22644. THREE.TextGeometry = function ( text, parameters ) {
  22645. parameters = parameters || {};
  22646. var font = parameters.font;
  22647. if ( font instanceof THREE.Font === false ) {
  22648. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  22649. return new THREE.Geometry();
  22650. }
  22651. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  22652. // translate parameters to ExtrudeGeometry API
  22653. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  22654. // defaults
  22655. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  22656. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  22657. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  22658. THREE.ExtrudeGeometry.call( this, shapes, parameters );
  22659. this.type = 'TextGeometry';
  22660. };
  22661. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  22662. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  22663. // File:src/extras/geometries/TorusBufferGeometry.js
  22664. /**
  22665. * @author Mugen87 / https://github.com/Mugen87
  22666. */
  22667. THREE.TorusBufferGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  22668. THREE.BufferGeometry.call( this );
  22669. this.type = 'TorusBufferGeometry';
  22670. this.parameters = {
  22671. radius: radius,
  22672. tube: tube,
  22673. radialSegments: radialSegments,
  22674. tubularSegments: tubularSegments,
  22675. arc: arc
  22676. };
  22677. radius = radius || 100;
  22678. tube = tube || 40;
  22679. radialSegments = Math.floor( radialSegments ) || 8;
  22680. tubularSegments = Math.floor( tubularSegments ) || 6;
  22681. arc = arc || Math.PI * 2;
  22682. // used to calculate buffer length
  22683. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  22684. var indexCount = radialSegments * tubularSegments * 2 * 3;
  22685. // buffers
  22686. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  22687. var vertices = new Float32Array( vertexCount * 3 );
  22688. var normals = new Float32Array( vertexCount * 3 );
  22689. var uvs = new Float32Array( vertexCount * 2 );
  22690. // offset variables
  22691. var vertexBufferOffset = 0;
  22692. var uvBufferOffset = 0;
  22693. var indexBufferOffset = 0;
  22694. // helper variables
  22695. var center = new THREE.Vector3();
  22696. var vertex = new THREE.Vector3();
  22697. var normal = new THREE.Vector3();
  22698. var j, i;
  22699. // generate vertices, normals and uvs
  22700. for ( j = 0; j <= radialSegments; j ++ ) {
  22701. for ( i = 0; i <= tubularSegments; i ++ ) {
  22702. var u = i / tubularSegments * arc;
  22703. var v = j / radialSegments * Math.PI * 2;
  22704. // vertex
  22705. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  22706. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  22707. vertex.z = tube * Math.sin( v );
  22708. vertices[ vertexBufferOffset ] = vertex.x;
  22709. vertices[ vertexBufferOffset + 1 ] = vertex.y;
  22710. vertices[ vertexBufferOffset + 2 ] = vertex.z;
  22711. // this vector is used to calculate the normal
  22712. center.x = radius * Math.cos( u );
  22713. center.y = radius * Math.sin( u );
  22714. // normal
  22715. normal.subVectors( vertex, center ).normalize();
  22716. normals[ vertexBufferOffset ] = normal.x;
  22717. normals[ vertexBufferOffset + 1 ] = normal.y;
  22718. normals[ vertexBufferOffset + 2 ] = normal.z;
  22719. // uv
  22720. uvs[ uvBufferOffset ] = i / tubularSegments;
  22721. uvs[ uvBufferOffset + 1 ] = j / radialSegments;
  22722. // update offsets
  22723. vertexBufferOffset += 3;
  22724. uvBufferOffset += 2;
  22725. }
  22726. }
  22727. // generate indices
  22728. for ( j = 1; j <= radialSegments; j ++ ) {
  22729. for ( i = 1; i <= tubularSegments; i ++ ) {
  22730. // indices
  22731. var a = ( tubularSegments + 1 ) * j + i - 1;
  22732. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  22733. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  22734. var d = ( tubularSegments + 1 ) * j + i;
  22735. // face one
  22736. indices[ indexBufferOffset ] = a;
  22737. indices[ indexBufferOffset + 1 ] = b;
  22738. indices[ indexBufferOffset + 2 ] = d;
  22739. // face two
  22740. indices[ indexBufferOffset + 3 ] = b;
  22741. indices[ indexBufferOffset + 4 ] = c;
  22742. indices[ indexBufferOffset + 5 ] = d;
  22743. // update offset
  22744. indexBufferOffset += 6;
  22745. }
  22746. }
  22747. // build geometry
  22748. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  22749. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  22750. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  22751. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  22752. };
  22753. THREE.TorusBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22754. THREE.TorusBufferGeometry.prototype.constructor = THREE.TorusBufferGeometry;
  22755. // File:src/extras/geometries/TorusGeometry.js
  22756. /**
  22757. * @author oosmoxiecode
  22758. * @author mrdoob / http://mrdoob.com/
  22759. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  22760. */
  22761. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  22762. THREE.Geometry.call( this );
  22763. this.type = 'TorusGeometry';
  22764. this.parameters = {
  22765. radius: radius,
  22766. tube: tube,
  22767. radialSegments: radialSegments,
  22768. tubularSegments: tubularSegments,
  22769. arc: arc
  22770. };
  22771. this.fromBufferGeometry( new THREE.TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  22772. };
  22773. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22774. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  22775. // File:src/extras/geometries/TorusKnotBufferGeometry.js
  22776. /**
  22777. * @author Mugen87 / https://github.com/Mugen87
  22778. *
  22779. * see: http://www.blackpawn.com/texts/pqtorus/
  22780. */
  22781. THREE.TorusKnotBufferGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q ) {
  22782. THREE.BufferGeometry.call( this );
  22783. this.type = 'TorusKnotBufferGeometry';
  22784. this.parameters = {
  22785. radius: radius,
  22786. tube: tube,
  22787. tubularSegments: tubularSegments,
  22788. radialSegments: radialSegments,
  22789. p: p,
  22790. q: q
  22791. };
  22792. radius = radius || 100;
  22793. tube = tube || 40;
  22794. tubularSegments = Math.floor( tubularSegments ) || 64;
  22795. radialSegments = Math.floor( radialSegments ) || 8;
  22796. p = p || 2;
  22797. q = q || 3;
  22798. // used to calculate buffer length
  22799. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  22800. var indexCount = radialSegments * tubularSegments * 2 * 3;
  22801. // buffers
  22802. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  22803. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22804. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22805. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22806. // helper variables
  22807. var i, j, index = 0, indexOffset = 0;
  22808. var vertex = new THREE.Vector3();
  22809. var normal = new THREE.Vector3();
  22810. var uv = new THREE.Vector2();
  22811. var P1 = new THREE.Vector3();
  22812. var P2 = new THREE.Vector3();
  22813. var B = new THREE.Vector3();
  22814. var T = new THREE.Vector3();
  22815. var N = new THREE.Vector3();
  22816. // generate vertices, normals and uvs
  22817. for ( i = 0; i <= tubularSegments; ++ i ) {
  22818. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  22819. var u = i / tubularSegments * p * Math.PI * 2;
  22820. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  22821. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  22822. calculatePositionOnCurve( u, p, q, radius, P1 );
  22823. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  22824. // calculate orthonormal basis
  22825. T.subVectors( P2, P1 );
  22826. N.addVectors( P2, P1 );
  22827. B.crossVectors( T, N );
  22828. N.crossVectors( B, T );
  22829. // normalize B, N. T can be ignored, we don't use it
  22830. B.normalize();
  22831. N.normalize();
  22832. for ( j = 0; j <= radialSegments; ++ j ) {
  22833. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  22834. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  22835. var v = j / radialSegments * Math.PI * 2;
  22836. var cx = - tube * Math.cos( v );
  22837. var cy = tube * Math.sin( v );
  22838. // now calculate the final vertex position.
  22839. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  22840. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  22841. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  22842. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  22843. // vertex
  22844. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22845. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  22846. normal.subVectors( vertex, P1 ).normalize();
  22847. normals.setXYZ( index, normal.x, normal.y, normal.z );
  22848. // uv
  22849. uv.x = i / tubularSegments;
  22850. uv.y = j / radialSegments;
  22851. uvs.setXY( index, uv.x, uv.y );
  22852. // increase index
  22853. index ++;
  22854. }
  22855. }
  22856. // generate indices
  22857. for ( j = 1; j <= tubularSegments; j ++ ) {
  22858. for ( i = 1; i <= radialSegments; i ++ ) {
  22859. // indices
  22860. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  22861. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  22862. var c = ( radialSegments + 1 ) * j + i;
  22863. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  22864. // face one
  22865. indices.setX( indexOffset, a ); indexOffset++;
  22866. indices.setX( indexOffset, b ); indexOffset++;
  22867. indices.setX( indexOffset, d ); indexOffset++;
  22868. // face two
  22869. indices.setX( indexOffset, b ); indexOffset++;
  22870. indices.setX( indexOffset, c ); indexOffset++;
  22871. indices.setX( indexOffset, d ); indexOffset++;
  22872. }
  22873. }
  22874. // build geometry
  22875. this.setIndex( indices );
  22876. this.addAttribute( 'position', vertices );
  22877. this.addAttribute( 'normal', normals );
  22878. this.addAttribute( 'uv', uvs );
  22879. // this function calculates the current position on the torus curve
  22880. function calculatePositionOnCurve( u, p, q, radius, position ) {
  22881. var cu = Math.cos( u );
  22882. var su = Math.sin( u );
  22883. var quOverP = q / p * u;
  22884. var cs = Math.cos( quOverP );
  22885. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  22886. position.y = radius * ( 2 + cs ) * su * 0.5;
  22887. position.z = radius * Math.sin( quOverP ) * 0.5;
  22888. }
  22889. };
  22890. THREE.TorusKnotBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22891. THREE.TorusKnotBufferGeometry.prototype.constructor = THREE.TorusKnotBufferGeometry;
  22892. // File:src/extras/geometries/TorusKnotGeometry.js
  22893. /**
  22894. * @author oosmoxiecode
  22895. */
  22896. THREE.TorusKnotGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  22897. THREE.Geometry.call( this );
  22898. this.type = 'TorusKnotGeometry';
  22899. this.parameters = {
  22900. radius: radius,
  22901. tube: tube,
  22902. tubularSegments: tubularSegments,
  22903. radialSegments: radialSegments,
  22904. p: p,
  22905. q: q
  22906. };
  22907. if( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  22908. this.fromBufferGeometry( new THREE.TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  22909. this.mergeVertices();
  22910. };
  22911. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22912. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  22913. // File:src/extras/geometries/TubeGeometry.js
  22914. /**
  22915. * @author WestLangley / https://github.com/WestLangley
  22916. * @author zz85 / https://github.com/zz85
  22917. * @author miningold / https://github.com/miningold
  22918. * @author jonobr1 / https://github.com/jonobr1
  22919. *
  22920. * Modified from the TorusKnotGeometry by @oosmoxiecode
  22921. *
  22922. * Creates a tube which extrudes along a 3d spline
  22923. *
  22924. * Uses parallel transport frames as described in
  22925. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22926. */
  22927. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  22928. THREE.Geometry.call( this );
  22929. this.type = 'TubeGeometry';
  22930. this.parameters = {
  22931. path: path,
  22932. segments: segments,
  22933. radius: radius,
  22934. radialSegments: radialSegments,
  22935. closed: closed,
  22936. taper: taper
  22937. };
  22938. segments = segments || 64;
  22939. radius = radius || 1;
  22940. radialSegments = radialSegments || 8;
  22941. closed = closed || false;
  22942. taper = taper || THREE.TubeGeometry.NoTaper;
  22943. var grid = [];
  22944. var scope = this,
  22945. tangent,
  22946. normal,
  22947. binormal,
  22948. numpoints = segments + 1,
  22949. u, v, r,
  22950. cx, cy,
  22951. pos, pos2 = new THREE.Vector3(),
  22952. i, j,
  22953. ip, jp,
  22954. a, b, c, d,
  22955. uva, uvb, uvc, uvd;
  22956. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  22957. tangents = frames.tangents,
  22958. normals = frames.normals,
  22959. binormals = frames.binormals;
  22960. // proxy internals
  22961. this.tangents = tangents;
  22962. this.normals = normals;
  22963. this.binormals = binormals;
  22964. function vert( x, y, z ) {
  22965. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  22966. }
  22967. // construct the grid
  22968. for ( i = 0; i < numpoints; i ++ ) {
  22969. grid[ i ] = [];
  22970. u = i / ( numpoints - 1 );
  22971. pos = path.getPointAt( u );
  22972. tangent = tangents[ i ];
  22973. normal = normals[ i ];
  22974. binormal = binormals[ i ];
  22975. r = radius * taper( u );
  22976. for ( j = 0; j < radialSegments; j ++ ) {
  22977. v = j / radialSegments * 2 * Math.PI;
  22978. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  22979. cy = r * Math.sin( v );
  22980. pos2.copy( pos );
  22981. pos2.x += cx * normal.x + cy * binormal.x;
  22982. pos2.y += cx * normal.y + cy * binormal.y;
  22983. pos2.z += cx * normal.z + cy * binormal.z;
  22984. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  22985. }
  22986. }
  22987. // construct the mesh
  22988. for ( i = 0; i < segments; i ++ ) {
  22989. for ( j = 0; j < radialSegments; j ++ ) {
  22990. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  22991. jp = ( j + 1 ) % radialSegments;
  22992. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  22993. b = grid[ ip ][ j ];
  22994. c = grid[ ip ][ jp ];
  22995. d = grid[ i ][ jp ];
  22996. uva = new THREE.Vector2( i / segments, j / radialSegments );
  22997. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  22998. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  22999. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  23000. this.faces.push( new THREE.Face3( a, b, d ) );
  23001. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  23002. this.faces.push( new THREE.Face3( b, c, d ) );
  23003. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  23004. }
  23005. }
  23006. this.computeFaceNormals();
  23007. this.computeVertexNormals();
  23008. };
  23009. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23010. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  23011. THREE.TubeGeometry.NoTaper = function ( u ) {
  23012. return 1;
  23013. };
  23014. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  23015. return Math.sin( Math.PI * u );
  23016. };
  23017. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  23018. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  23019. var normal = new THREE.Vector3(),
  23020. tangents = [],
  23021. normals = [],
  23022. binormals = [],
  23023. vec = new THREE.Vector3(),
  23024. mat = new THREE.Matrix4(),
  23025. numpoints = segments + 1,
  23026. theta,
  23027. smallest,
  23028. tx, ty, tz,
  23029. i, u;
  23030. // expose internals
  23031. this.tangents = tangents;
  23032. this.normals = normals;
  23033. this.binormals = binormals;
  23034. // compute the tangent vectors for each segment on the path
  23035. for ( i = 0; i < numpoints; i ++ ) {
  23036. u = i / ( numpoints - 1 );
  23037. tangents[ i ] = path.getTangentAt( u );
  23038. tangents[ i ].normalize();
  23039. }
  23040. initialNormal3();
  23041. /*
  23042. function initialNormal1(lastBinormal) {
  23043. // fixed start binormal. Has dangers of 0 vectors
  23044. normals[ 0 ] = new THREE.Vector3();
  23045. binormals[ 0 ] = new THREE.Vector3();
  23046. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  23047. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  23048. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23049. }
  23050. function initialNormal2() {
  23051. // This uses the Frenet-Serret formula for deriving binormal
  23052. var t2 = path.getTangentAt( epsilon );
  23053. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  23054. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  23055. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  23056. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23057. }
  23058. */
  23059. function initialNormal3() {
  23060. // select an initial normal vector perpendicular to the first tangent vector,
  23061. // and in the direction of the smallest tangent xyz component
  23062. normals[ 0 ] = new THREE.Vector3();
  23063. binormals[ 0 ] = new THREE.Vector3();
  23064. smallest = Number.MAX_VALUE;
  23065. tx = Math.abs( tangents[ 0 ].x );
  23066. ty = Math.abs( tangents[ 0 ].y );
  23067. tz = Math.abs( tangents[ 0 ].z );
  23068. if ( tx <= smallest ) {
  23069. smallest = tx;
  23070. normal.set( 1, 0, 0 );
  23071. }
  23072. if ( ty <= smallest ) {
  23073. smallest = ty;
  23074. normal.set( 0, 1, 0 );
  23075. }
  23076. if ( tz <= smallest ) {
  23077. normal.set( 0, 0, 1 );
  23078. }
  23079. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  23080. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  23081. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  23082. }
  23083. // compute the slowly-varying normal and binormal vectors for each segment on the path
  23084. for ( i = 1; i < numpoints; i ++ ) {
  23085. normals[ i ] = normals[ i - 1 ].clone();
  23086. binormals[ i ] = binormals[ i - 1 ].clone();
  23087. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  23088. if ( vec.length() > Number.EPSILON ) {
  23089. vec.normalize();
  23090. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  23091. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  23092. }
  23093. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23094. }
  23095. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  23096. if ( closed ) {
  23097. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  23098. theta /= ( numpoints - 1 );
  23099. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  23100. theta = - theta;
  23101. }
  23102. for ( i = 1; i < numpoints; i ++ ) {
  23103. // twist a little...
  23104. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  23105. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23106. }
  23107. }
  23108. };
  23109. // File:src/extras/geometries/PolyhedronGeometry.js
  23110. /**
  23111. * @author clockworkgeek / https://github.com/clockworkgeek
  23112. * @author timothypratley / https://github.com/timothypratley
  23113. * @author WestLangley / http://github.com/WestLangley
  23114. */
  23115. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  23116. THREE.Geometry.call( this );
  23117. this.type = 'PolyhedronGeometry';
  23118. this.parameters = {
  23119. vertices: vertices,
  23120. indices: indices,
  23121. radius: radius,
  23122. detail: detail
  23123. };
  23124. radius = radius || 1;
  23125. detail = detail || 0;
  23126. var that = this;
  23127. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  23128. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  23129. }
  23130. var p = this.vertices;
  23131. var faces = [];
  23132. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  23133. var v1 = p[ indices[ i ] ];
  23134. var v2 = p[ indices[ i + 1 ] ];
  23135. var v3 = p[ indices[ i + 2 ] ];
  23136. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, j );
  23137. }
  23138. var centroid = new THREE.Vector3();
  23139. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23140. subdivide( faces[ i ], detail );
  23141. }
  23142. // Handle case when face straddles the seam
  23143. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  23144. var uvs = this.faceVertexUvs[ 0 ][ i ];
  23145. var x0 = uvs[ 0 ].x;
  23146. var x1 = uvs[ 1 ].x;
  23147. var x2 = uvs[ 2 ].x;
  23148. var max = Math.max( x0, x1, x2 );
  23149. var min = Math.min( x0, x1, x2 );
  23150. if ( max > 0.9 && min < 0.1 ) {
  23151. // 0.9 is somewhat arbitrary
  23152. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  23153. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  23154. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  23155. }
  23156. }
  23157. // Apply radius
  23158. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  23159. this.vertices[ i ].multiplyScalar( radius );
  23160. }
  23161. // Merge vertices
  23162. this.mergeVertices();
  23163. this.computeFaceNormals();
  23164. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  23165. // Project vector onto sphere's surface
  23166. function prepare( vector ) {
  23167. var vertex = vector.normalize().clone();
  23168. vertex.index = that.vertices.push( vertex ) - 1;
  23169. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  23170. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  23171. var v = inclination( vector ) / Math.PI + 0.5;
  23172. vertex.uv = new THREE.Vector2( u, 1 - v );
  23173. return vertex;
  23174. }
  23175. // Approximate a curved face with recursively sub-divided triangles.
  23176. function make( v1, v2, v3, materialIndex ) {
  23177. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, materialIndex );
  23178. that.faces.push( face );
  23179. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  23180. var azi = azimuth( centroid );
  23181. that.faceVertexUvs[ 0 ].push( [
  23182. correctUV( v1.uv, v1, azi ),
  23183. correctUV( v2.uv, v2, azi ),
  23184. correctUV( v3.uv, v3, azi )
  23185. ] );
  23186. }
  23187. // Analytically subdivide a face to the required detail level.
  23188. function subdivide( face, detail ) {
  23189. var cols = Math.pow( 2, detail );
  23190. var a = prepare( that.vertices[ face.a ] );
  23191. var b = prepare( that.vertices[ face.b ] );
  23192. var c = prepare( that.vertices[ face.c ] );
  23193. var v = [];
  23194. var materialIndex = face.materialIndex;
  23195. // Construct all of the vertices for this subdivision.
  23196. for ( var i = 0 ; i <= cols; i ++ ) {
  23197. v[ i ] = [];
  23198. var aj = prepare( a.clone().lerp( c, i / cols ) );
  23199. var bj = prepare( b.clone().lerp( c, i / cols ) );
  23200. var rows = cols - i;
  23201. for ( var j = 0; j <= rows; j ++ ) {
  23202. if ( j === 0 && i === cols ) {
  23203. v[ i ][ j ] = aj;
  23204. } else {
  23205. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  23206. }
  23207. }
  23208. }
  23209. // Construct all of the faces.
  23210. for ( var i = 0; i < cols ; i ++ ) {
  23211. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  23212. var k = Math.floor( j / 2 );
  23213. if ( j % 2 === 0 ) {
  23214. make(
  23215. v[ i ][ k + 1 ],
  23216. v[ i + 1 ][ k ],
  23217. v[ i ][ k ],
  23218. materialIndex
  23219. );
  23220. } else {
  23221. make(
  23222. v[ i ][ k + 1 ],
  23223. v[ i + 1 ][ k + 1 ],
  23224. v[ i + 1 ][ k ],
  23225. materialIndex
  23226. );
  23227. }
  23228. }
  23229. }
  23230. }
  23231. // Angle around the Y axis, counter-clockwise when looking from above.
  23232. function azimuth( vector ) {
  23233. return Math.atan2( vector.z, - vector.x );
  23234. }
  23235. // Angle above the XZ plane.
  23236. function inclination( vector ) {
  23237. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  23238. }
  23239. // Texture fixing helper. Spheres have some odd behaviours.
  23240. function correctUV( uv, vector, azimuth ) {
  23241. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  23242. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  23243. return uv.clone();
  23244. }
  23245. };
  23246. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23247. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  23248. // File:src/extras/geometries/DodecahedronGeometry.js
  23249. /**
  23250. * @author Abe Pazos / https://hamoid.com
  23251. */
  23252. THREE.DodecahedronGeometry = function ( radius, detail ) {
  23253. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23254. var r = 1 / t;
  23255. var vertices = [
  23256. // (±1, ±1, ±1)
  23257. - 1, - 1, - 1, - 1, - 1, 1,
  23258. - 1, 1, - 1, - 1, 1, 1,
  23259. 1, - 1, - 1, 1, - 1, 1,
  23260. 1, 1, - 1, 1, 1, 1,
  23261. // (0, ±1/φ, ±φ)
  23262. 0, - r, - t, 0, - r, t,
  23263. 0, r, - t, 0, r, t,
  23264. // (±1/φ, ±φ, 0)
  23265. - r, - t, 0, - r, t, 0,
  23266. r, - t, 0, r, t, 0,
  23267. // (±φ, 0, ±1/φ)
  23268. - t, 0, - r, t, 0, - r,
  23269. - t, 0, r, t, 0, r
  23270. ];
  23271. var indices = [
  23272. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  23273. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  23274. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  23275. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  23276. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  23277. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  23278. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  23279. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  23280. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  23281. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  23282. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  23283. 1, 12, 14, 1, 14, 5, 1, 5, 9
  23284. ];
  23285. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23286. this.type = 'DodecahedronGeometry';
  23287. this.parameters = {
  23288. radius: radius,
  23289. detail: detail
  23290. };
  23291. };
  23292. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23293. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  23294. // File:src/extras/geometries/IcosahedronGeometry.js
  23295. /**
  23296. * @author timothypratley / https://github.com/timothypratley
  23297. */
  23298. THREE.IcosahedronGeometry = function ( radius, detail ) {
  23299. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23300. var vertices = [
  23301. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  23302. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  23303. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  23304. ];
  23305. var indices = [
  23306. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  23307. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  23308. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  23309. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  23310. ];
  23311. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23312. this.type = 'IcosahedronGeometry';
  23313. this.parameters = {
  23314. radius: radius,
  23315. detail: detail
  23316. };
  23317. };
  23318. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23319. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  23320. // File:src/extras/geometries/OctahedronGeometry.js
  23321. /**
  23322. * @author timothypratley / https://github.com/timothypratley
  23323. */
  23324. THREE.OctahedronGeometry = function ( radius, detail ) {
  23325. var vertices = [
  23326. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  23327. ];
  23328. var indices = [
  23329. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  23330. ];
  23331. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23332. this.type = 'OctahedronGeometry';
  23333. this.parameters = {
  23334. radius: radius,
  23335. detail: detail
  23336. };
  23337. };
  23338. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23339. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  23340. // File:src/extras/geometries/TetrahedronGeometry.js
  23341. /**
  23342. * @author timothypratley / https://github.com/timothypratley
  23343. */
  23344. THREE.TetrahedronGeometry = function ( radius, detail ) {
  23345. var vertices = [
  23346. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  23347. ];
  23348. var indices = [
  23349. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  23350. ];
  23351. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23352. this.type = 'TetrahedronGeometry';
  23353. this.parameters = {
  23354. radius: radius,
  23355. detail: detail
  23356. };
  23357. };
  23358. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23359. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  23360. // File:src/extras/geometries/ParametricGeometry.js
  23361. /**
  23362. * @author zz85 / https://github.com/zz85
  23363. * Parametric Surfaces Geometry
  23364. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  23365. *
  23366. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  23367. *
  23368. */
  23369. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  23370. THREE.Geometry.call( this );
  23371. this.type = 'ParametricGeometry';
  23372. this.parameters = {
  23373. func: func,
  23374. slices: slices,
  23375. stacks: stacks
  23376. };
  23377. var verts = this.vertices;
  23378. var faces = this.faces;
  23379. var uvs = this.faceVertexUvs[ 0 ];
  23380. var i, j, p;
  23381. var u, v;
  23382. var sliceCount = slices + 1;
  23383. for ( i = 0; i <= stacks; i ++ ) {
  23384. v = i / stacks;
  23385. for ( j = 0; j <= slices; j ++ ) {
  23386. u = j / slices;
  23387. p = func( u, v );
  23388. verts.push( p );
  23389. }
  23390. }
  23391. var a, b, c, d;
  23392. var uva, uvb, uvc, uvd;
  23393. for ( i = 0; i < stacks; i ++ ) {
  23394. for ( j = 0; j < slices; j ++ ) {
  23395. a = i * sliceCount + j;
  23396. b = i * sliceCount + j + 1;
  23397. c = ( i + 1 ) * sliceCount + j + 1;
  23398. d = ( i + 1 ) * sliceCount + j;
  23399. uva = new THREE.Vector2( j / slices, i / stacks );
  23400. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  23401. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  23402. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  23403. faces.push( new THREE.Face3( a, b, d ) );
  23404. uvs.push( [ uva, uvb, uvd ] );
  23405. faces.push( new THREE.Face3( b, c, d ) );
  23406. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  23407. }
  23408. }
  23409. // console.log(this);
  23410. // magic bullet
  23411. // var diff = this.mergeVertices();
  23412. // console.log('removed ', diff, ' vertices by merging');
  23413. this.computeFaceNormals();
  23414. this.computeVertexNormals();
  23415. };
  23416. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23417. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  23418. // File:src/extras/geometries/WireframeGeometry.js
  23419. /**
  23420. * @author mrdoob / http://mrdoob.com/
  23421. */
  23422. THREE.WireframeGeometry = function ( geometry ) {
  23423. THREE.BufferGeometry.call( this );
  23424. var edge = [ 0, 0 ], hash = {};
  23425. function sortFunction( a, b ) {
  23426. return a - b;
  23427. }
  23428. var keys = [ 'a', 'b', 'c' ];
  23429. if ( geometry instanceof THREE.Geometry ) {
  23430. var vertices = geometry.vertices;
  23431. var faces = geometry.faces;
  23432. var numEdges = 0;
  23433. // allocate maximal size
  23434. var edges = new Uint32Array( 6 * faces.length );
  23435. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23436. var face = faces[ i ];
  23437. for ( var j = 0; j < 3; j ++ ) {
  23438. edge[ 0 ] = face[ keys[ j ] ];
  23439. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  23440. edge.sort( sortFunction );
  23441. var key = edge.toString();
  23442. if ( hash[ key ] === undefined ) {
  23443. edges[ 2 * numEdges ] = edge[ 0 ];
  23444. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  23445. hash[ key ] = true;
  23446. numEdges ++;
  23447. }
  23448. }
  23449. }
  23450. var coords = new Float32Array( numEdges * 2 * 3 );
  23451. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  23452. for ( var j = 0; j < 2; j ++ ) {
  23453. var vertex = vertices[ edges [ 2 * i + j ] ];
  23454. var index = 6 * i + 3 * j;
  23455. coords[ index + 0 ] = vertex.x;
  23456. coords[ index + 1 ] = vertex.y;
  23457. coords[ index + 2 ] = vertex.z;
  23458. }
  23459. }
  23460. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23461. } else if ( geometry instanceof THREE.BufferGeometry ) {
  23462. if ( geometry.index !== null ) {
  23463. // Indexed BufferGeometry
  23464. var indices = geometry.index.array;
  23465. var vertices = geometry.attributes.position;
  23466. var groups = geometry.groups;
  23467. var numEdges = 0;
  23468. if ( groups.length === 0 ) {
  23469. geometry.addGroup( 0, indices.length );
  23470. }
  23471. // allocate maximal size
  23472. var edges = new Uint32Array( 2 * indices.length );
  23473. for ( var o = 0, ol = groups.length; o < ol; ++ o ) {
  23474. var group = groups[ o ];
  23475. var start = group.start;
  23476. var count = group.count;
  23477. for ( var i = start, il = start + count; i < il; i += 3 ) {
  23478. for ( var j = 0; j < 3; j ++ ) {
  23479. edge[ 0 ] = indices[ i + j ];
  23480. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  23481. edge.sort( sortFunction );
  23482. var key = edge.toString();
  23483. if ( hash[ key ] === undefined ) {
  23484. edges[ 2 * numEdges ] = edge[ 0 ];
  23485. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  23486. hash[ key ] = true;
  23487. numEdges ++;
  23488. }
  23489. }
  23490. }
  23491. }
  23492. var coords = new Float32Array( numEdges * 2 * 3 );
  23493. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  23494. for ( var j = 0; j < 2; j ++ ) {
  23495. var index = 6 * i + 3 * j;
  23496. var index2 = edges[ 2 * i + j ];
  23497. coords[ index + 0 ] = vertices.getX( index2 );
  23498. coords[ index + 1 ] = vertices.getY( index2 );
  23499. coords[ index + 2 ] = vertices.getZ( index2 );
  23500. }
  23501. }
  23502. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23503. } else {
  23504. // non-indexed BufferGeometry
  23505. var vertices = geometry.attributes.position.array;
  23506. var numEdges = vertices.length / 3;
  23507. var numTris = numEdges / 3;
  23508. var coords = new Float32Array( numEdges * 2 * 3 );
  23509. for ( var i = 0, l = numTris; i < l; i ++ ) {
  23510. for ( var j = 0; j < 3; j ++ ) {
  23511. var index = 18 * i + 6 * j;
  23512. var index1 = 9 * i + 3 * j;
  23513. coords[ index + 0 ] = vertices[ index1 ];
  23514. coords[ index + 1 ] = vertices[ index1 + 1 ];
  23515. coords[ index + 2 ] = vertices[ index1 + 2 ];
  23516. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  23517. coords[ index + 3 ] = vertices[ index2 ];
  23518. coords[ index + 4 ] = vertices[ index2 + 1 ];
  23519. coords[ index + 5 ] = vertices[ index2 + 2 ];
  23520. }
  23521. }
  23522. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23523. }
  23524. }
  23525. };
  23526. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23527. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  23528. // File:src/extras/helpers/AxisHelper.js
  23529. /**
  23530. * @author sroucheray / http://sroucheray.org/
  23531. * @author mrdoob / http://mrdoob.com/
  23532. */
  23533. THREE.AxisHelper = function ( size ) {
  23534. size = size || 1;
  23535. var vertices = new Float32Array( [
  23536. 0, 0, 0, size, 0, 0,
  23537. 0, 0, 0, 0, size, 0,
  23538. 0, 0, 0, 0, 0, size
  23539. ] );
  23540. var colors = new Float32Array( [
  23541. 1, 0, 0, 1, 0.6, 0,
  23542. 0, 1, 0, 0.6, 1, 0,
  23543. 0, 0, 1, 0, 0.6, 1
  23544. ] );
  23545. var geometry = new THREE.BufferGeometry();
  23546. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  23547. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  23548. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  23549. THREE.LineSegments.call( this, geometry, material );
  23550. };
  23551. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23552. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  23553. // File:src/extras/helpers/ArrowHelper.js
  23554. /**
  23555. * @author WestLangley / http://github.com/WestLangley
  23556. * @author zz85 / http://github.com/zz85
  23557. * @author bhouston / http://clara.io
  23558. *
  23559. * Creates an arrow for visualizing directions
  23560. *
  23561. * Parameters:
  23562. * dir - Vector3
  23563. * origin - Vector3
  23564. * length - Number
  23565. * color - color in hex value
  23566. * headLength - Number
  23567. * headWidth - Number
  23568. */
  23569. THREE.ArrowHelper = ( function () {
  23570. var lineGeometry = new THREE.Geometry();
  23571. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  23572. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  23573. coneGeometry.translate( 0, - 0.5, 0 );
  23574. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  23575. // dir is assumed to be normalized
  23576. THREE.Object3D.call( this );
  23577. if ( color === undefined ) color = 0xffff00;
  23578. if ( length === undefined ) length = 1;
  23579. if ( headLength === undefined ) headLength = 0.2 * length;
  23580. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  23581. this.position.copy( origin );
  23582. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  23583. this.line.matrixAutoUpdate = false;
  23584. this.add( this.line );
  23585. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  23586. this.cone.matrixAutoUpdate = false;
  23587. this.add( this.cone );
  23588. this.setDirection( dir );
  23589. this.setLength( length, headLength, headWidth );
  23590. }
  23591. }() );
  23592. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  23593. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  23594. THREE.ArrowHelper.prototype.setDirection = ( function () {
  23595. var axis = new THREE.Vector3();
  23596. var radians;
  23597. return function setDirection( dir ) {
  23598. // dir is assumed to be normalized
  23599. if ( dir.y > 0.99999 ) {
  23600. this.quaternion.set( 0, 0, 0, 1 );
  23601. } else if ( dir.y < - 0.99999 ) {
  23602. this.quaternion.set( 1, 0, 0, 0 );
  23603. } else {
  23604. axis.set( dir.z, 0, - dir.x ).normalize();
  23605. radians = Math.acos( dir.y );
  23606. this.quaternion.setFromAxisAngle( axis, radians );
  23607. }
  23608. };
  23609. }() );
  23610. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  23611. if ( headLength === undefined ) headLength = 0.2 * length;
  23612. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  23613. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  23614. this.line.updateMatrix();
  23615. this.cone.scale.set( headWidth, headLength, headWidth );
  23616. this.cone.position.y = length;
  23617. this.cone.updateMatrix();
  23618. };
  23619. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  23620. this.line.material.color.set( color );
  23621. this.cone.material.color.set( color );
  23622. };
  23623. // File:src/extras/helpers/BoxHelper.js
  23624. /**
  23625. * @author mrdoob / http://mrdoob.com/
  23626. */
  23627. THREE.BoxHelper = function ( object ) {
  23628. 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 ] );
  23629. var positions = new Float32Array( 8 * 3 );
  23630. var geometry = new THREE.BufferGeometry();
  23631. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  23632. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  23633. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  23634. if ( object !== undefined ) {
  23635. this.update( object );
  23636. }
  23637. };
  23638. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23639. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  23640. THREE.BoxHelper.prototype.update = ( function () {
  23641. var box = new THREE.Box3();
  23642. return function ( object ) {
  23643. box.setFromObject( object );
  23644. if ( box.isEmpty() ) return;
  23645. var min = box.min;
  23646. var max = box.max;
  23647. /*
  23648. 5____4
  23649. 1/___0/|
  23650. | 6__|_7
  23651. 2/___3/
  23652. 0: max.x, max.y, max.z
  23653. 1: min.x, max.y, max.z
  23654. 2: min.x, min.y, max.z
  23655. 3: max.x, min.y, max.z
  23656. 4: max.x, max.y, min.z
  23657. 5: min.x, max.y, min.z
  23658. 6: min.x, min.y, min.z
  23659. 7: max.x, min.y, min.z
  23660. */
  23661. var position = this.geometry.attributes.position;
  23662. var array = position.array;
  23663. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  23664. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  23665. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  23666. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  23667. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  23668. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  23669. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  23670. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  23671. position.needsUpdate = true;
  23672. this.geometry.computeBoundingSphere();
  23673. };
  23674. } )();
  23675. // File:src/extras/helpers/BoundingBoxHelper.js
  23676. /**
  23677. * @author WestLangley / http://github.com/WestLangley
  23678. */
  23679. // a helper to show the world-axis-aligned bounding box for an object
  23680. THREE.BoundingBoxHelper = function ( object, hex ) {
  23681. var color = ( hex !== undefined ) ? hex : 0x888888;
  23682. this.object = object;
  23683. this.box = new THREE.Box3();
  23684. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  23685. };
  23686. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  23687. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  23688. THREE.BoundingBoxHelper.prototype.update = function () {
  23689. this.box.setFromObject( this.object );
  23690. this.box.size( this.scale );
  23691. this.box.center( this.position );
  23692. };
  23693. // File:src/extras/helpers/CameraHelper.js
  23694. /**
  23695. * @author alteredq / http://alteredqualia.com/
  23696. *
  23697. * - shows frustum, line of sight and up of the camera
  23698. * - suitable for fast updates
  23699. * - based on frustum visualization in lightgl.js shadowmap example
  23700. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  23701. */
  23702. THREE.CameraHelper = function ( camera ) {
  23703. var geometry = new THREE.Geometry();
  23704. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  23705. var pointMap = {};
  23706. // colors
  23707. var hexFrustum = 0xffaa00;
  23708. var hexCone = 0xff0000;
  23709. var hexUp = 0x00aaff;
  23710. var hexTarget = 0xffffff;
  23711. var hexCross = 0x333333;
  23712. // near
  23713. addLine( "n1", "n2", hexFrustum );
  23714. addLine( "n2", "n4", hexFrustum );
  23715. addLine( "n4", "n3", hexFrustum );
  23716. addLine( "n3", "n1", hexFrustum );
  23717. // far
  23718. addLine( "f1", "f2", hexFrustum );
  23719. addLine( "f2", "f4", hexFrustum );
  23720. addLine( "f4", "f3", hexFrustum );
  23721. addLine( "f3", "f1", hexFrustum );
  23722. // sides
  23723. addLine( "n1", "f1", hexFrustum );
  23724. addLine( "n2", "f2", hexFrustum );
  23725. addLine( "n3", "f3", hexFrustum );
  23726. addLine( "n4", "f4", hexFrustum );
  23727. // cone
  23728. addLine( "p", "n1", hexCone );
  23729. addLine( "p", "n2", hexCone );
  23730. addLine( "p", "n3", hexCone );
  23731. addLine( "p", "n4", hexCone );
  23732. // up
  23733. addLine( "u1", "u2", hexUp );
  23734. addLine( "u2", "u3", hexUp );
  23735. addLine( "u3", "u1", hexUp );
  23736. // target
  23737. addLine( "c", "t", hexTarget );
  23738. addLine( "p", "c", hexCross );
  23739. // cross
  23740. addLine( "cn1", "cn2", hexCross );
  23741. addLine( "cn3", "cn4", hexCross );
  23742. addLine( "cf1", "cf2", hexCross );
  23743. addLine( "cf3", "cf4", hexCross );
  23744. function addLine( a, b, hex ) {
  23745. addPoint( a, hex );
  23746. addPoint( b, hex );
  23747. }
  23748. function addPoint( id, hex ) {
  23749. geometry.vertices.push( new THREE.Vector3() );
  23750. geometry.colors.push( new THREE.Color( hex ) );
  23751. if ( pointMap[ id ] === undefined ) {
  23752. pointMap[ id ] = [];
  23753. }
  23754. pointMap[ id ].push( geometry.vertices.length - 1 );
  23755. }
  23756. THREE.LineSegments.call( this, geometry, material );
  23757. this.camera = camera;
  23758. this.camera.updateProjectionMatrix();
  23759. this.matrix = camera.matrixWorld;
  23760. this.matrixAutoUpdate = false;
  23761. this.pointMap = pointMap;
  23762. this.update();
  23763. };
  23764. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23765. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  23766. THREE.CameraHelper.prototype.update = function () {
  23767. var geometry, pointMap;
  23768. var vector = new THREE.Vector3();
  23769. var camera = new THREE.Camera();
  23770. function setPoint( point, x, y, z ) {
  23771. vector.set( x, y, z ).unproject( camera );
  23772. var points = pointMap[ point ];
  23773. if ( points !== undefined ) {
  23774. for ( var i = 0, il = points.length; i < il; i ++ ) {
  23775. geometry.vertices[ points[ i ] ].copy( vector );
  23776. }
  23777. }
  23778. }
  23779. return function () {
  23780. geometry = this.geometry;
  23781. pointMap = this.pointMap;
  23782. var w = 1, h = 1;
  23783. // we need just camera projection matrix
  23784. // world matrix must be identity
  23785. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  23786. // center / target
  23787. setPoint( "c", 0, 0, - 1 );
  23788. setPoint( "t", 0, 0, 1 );
  23789. // near
  23790. setPoint( "n1", - w, - h, - 1 );
  23791. setPoint( "n2", w, - h, - 1 );
  23792. setPoint( "n3", - w, h, - 1 );
  23793. setPoint( "n4", w, h, - 1 );
  23794. // far
  23795. setPoint( "f1", - w, - h, 1 );
  23796. setPoint( "f2", w, - h, 1 );
  23797. setPoint( "f3", - w, h, 1 );
  23798. setPoint( "f4", w, h, 1 );
  23799. // up
  23800. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  23801. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  23802. setPoint( "u3", 0, h * 2, - 1 );
  23803. // cross
  23804. setPoint( "cf1", - w, 0, 1 );
  23805. setPoint( "cf2", w, 0, 1 );
  23806. setPoint( "cf3", 0, - h, 1 );
  23807. setPoint( "cf4", 0, h, 1 );
  23808. setPoint( "cn1", - w, 0, - 1 );
  23809. setPoint( "cn2", w, 0, - 1 );
  23810. setPoint( "cn3", 0, - h, - 1 );
  23811. setPoint( "cn4", 0, h, - 1 );
  23812. geometry.verticesNeedUpdate = true;
  23813. };
  23814. }();
  23815. // File:src/extras/helpers/DirectionalLightHelper.js
  23816. /**
  23817. * @author alteredq / http://alteredqualia.com/
  23818. * @author mrdoob / http://mrdoob.com/
  23819. * @author WestLangley / http://github.com/WestLangley
  23820. */
  23821. THREE.DirectionalLightHelper = function ( light, size ) {
  23822. THREE.Object3D.call( this );
  23823. this.light = light;
  23824. this.light.updateMatrixWorld();
  23825. this.matrix = light.matrixWorld;
  23826. this.matrixAutoUpdate = false;
  23827. size = size || 1;
  23828. var geometry = new THREE.Geometry();
  23829. geometry.vertices.push(
  23830. new THREE.Vector3( - size, size, 0 ),
  23831. new THREE.Vector3( size, size, 0 ),
  23832. new THREE.Vector3( size, - size, 0 ),
  23833. new THREE.Vector3( - size, - size, 0 ),
  23834. new THREE.Vector3( - size, size, 0 )
  23835. );
  23836. var material = new THREE.LineBasicMaterial( { fog: false } );
  23837. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23838. this.lightPlane = new THREE.Line( geometry, material );
  23839. this.add( this.lightPlane );
  23840. geometry = new THREE.Geometry();
  23841. geometry.vertices.push(
  23842. new THREE.Vector3(),
  23843. new THREE.Vector3()
  23844. );
  23845. material = new THREE.LineBasicMaterial( { fog: false } );
  23846. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23847. this.targetLine = new THREE.Line( geometry, material );
  23848. this.add( this.targetLine );
  23849. this.update();
  23850. };
  23851. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23852. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  23853. THREE.DirectionalLightHelper.prototype.dispose = function () {
  23854. this.lightPlane.geometry.dispose();
  23855. this.lightPlane.material.dispose();
  23856. this.targetLine.geometry.dispose();
  23857. this.targetLine.material.dispose();
  23858. };
  23859. THREE.DirectionalLightHelper.prototype.update = function () {
  23860. var v1 = new THREE.Vector3();
  23861. var v2 = new THREE.Vector3();
  23862. var v3 = new THREE.Vector3();
  23863. return function () {
  23864. v1.setFromMatrixPosition( this.light.matrixWorld );
  23865. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  23866. v3.subVectors( v2, v1 );
  23867. this.lightPlane.lookAt( v3 );
  23868. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23869. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  23870. this.targetLine.geometry.verticesNeedUpdate = true;
  23871. this.targetLine.material.color.copy( this.lightPlane.material.color );
  23872. };
  23873. }();
  23874. // File:src/extras/helpers/EdgesHelper.js
  23875. /**
  23876. * @author WestLangley / http://github.com/WestLangley
  23877. * @param object THREE.Mesh whose geometry will be used
  23878. * @param hex line color
  23879. * @param thresholdAngle the minimum angle (in degrees),
  23880. * between the face normals of adjacent faces,
  23881. * that is required to render an edge. A value of 10 means
  23882. * an edge is only rendered if the angle is at least 10 degrees.
  23883. */
  23884. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  23885. var color = ( hex !== undefined ) ? hex : 0xffffff;
  23886. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  23887. this.matrix = object.matrixWorld;
  23888. this.matrixAutoUpdate = false;
  23889. };
  23890. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23891. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  23892. // File:src/extras/helpers/FaceNormalsHelper.js
  23893. /**
  23894. * @author mrdoob / http://mrdoob.com/
  23895. * @author WestLangley / http://github.com/WestLangley
  23896. */
  23897. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  23898. // FaceNormalsHelper only supports THREE.Geometry
  23899. this.object = object;
  23900. this.size = ( size !== undefined ) ? size : 1;
  23901. var color = ( hex !== undefined ) ? hex : 0xffff00;
  23902. var width = ( linewidth !== undefined ) ? linewidth : 1;
  23903. //
  23904. var nNormals = 0;
  23905. var objGeometry = this.object.geometry;
  23906. if ( objGeometry instanceof THREE.Geometry ) {
  23907. nNormals = objGeometry.faces.length;
  23908. } else {
  23909. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  23910. }
  23911. //
  23912. var geometry = new THREE.BufferGeometry();
  23913. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  23914. geometry.addAttribute( 'position', positions );
  23915. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  23916. //
  23917. this.matrixAutoUpdate = false;
  23918. this.update();
  23919. };
  23920. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23921. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  23922. THREE.FaceNormalsHelper.prototype.update = ( function () {
  23923. var v1 = new THREE.Vector3();
  23924. var v2 = new THREE.Vector3();
  23925. var normalMatrix = new THREE.Matrix3();
  23926. return function update() {
  23927. this.object.updateMatrixWorld( true );
  23928. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  23929. var matrixWorld = this.object.matrixWorld;
  23930. var position = this.geometry.attributes.position;
  23931. //
  23932. var objGeometry = this.object.geometry;
  23933. var vertices = objGeometry.vertices;
  23934. var faces = objGeometry.faces;
  23935. var idx = 0;
  23936. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23937. var face = faces[ i ];
  23938. var normal = face.normal;
  23939. v1.copy( vertices[ face.a ] )
  23940. .add( vertices[ face.b ] )
  23941. .add( vertices[ face.c ] )
  23942. .divideScalar( 3 )
  23943. .applyMatrix4( matrixWorld );
  23944. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  23945. position.setXYZ( idx, v1.x, v1.y, v1.z );
  23946. idx = idx + 1;
  23947. position.setXYZ( idx, v2.x, v2.y, v2.z );
  23948. idx = idx + 1;
  23949. }
  23950. position.needsUpdate = true;
  23951. return this;
  23952. }
  23953. }() );
  23954. // File:src/extras/helpers/GridHelper.js
  23955. /**
  23956. * @author mrdoob / http://mrdoob.com/
  23957. */
  23958. THREE.GridHelper = function ( size, step ) {
  23959. var geometry = new THREE.Geometry();
  23960. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  23961. this.color1 = new THREE.Color( 0x444444 );
  23962. this.color2 = new THREE.Color( 0x888888 );
  23963. for ( var i = - size; i <= size; i += step ) {
  23964. geometry.vertices.push(
  23965. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  23966. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  23967. );
  23968. var color = i === 0 ? this.color1 : this.color2;
  23969. geometry.colors.push( color, color, color, color );
  23970. }
  23971. THREE.LineSegments.call( this, geometry, material );
  23972. };
  23973. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23974. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  23975. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  23976. this.color1.set( colorCenterLine );
  23977. this.color2.set( colorGrid );
  23978. this.geometry.colorsNeedUpdate = true;
  23979. };
  23980. // File:src/extras/helpers/HemisphereLightHelper.js
  23981. /**
  23982. * @author alteredq / http://alteredqualia.com/
  23983. * @author mrdoob / http://mrdoob.com/
  23984. */
  23985. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  23986. THREE.Object3D.call( this );
  23987. this.light = light;
  23988. this.light.updateMatrixWorld();
  23989. this.matrix = light.matrixWorld;
  23990. this.matrixAutoUpdate = false;
  23991. this.colors = [ new THREE.Color(), new THREE.Color() ];
  23992. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  23993. geometry.rotateX( - Math.PI / 2 );
  23994. for ( var i = 0, il = 8; i < il; i ++ ) {
  23995. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  23996. }
  23997. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  23998. this.lightSphere = new THREE.Mesh( geometry, material );
  23999. this.add( this.lightSphere );
  24000. this.update();
  24001. };
  24002. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24003. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  24004. THREE.HemisphereLightHelper.prototype.dispose = function () {
  24005. this.lightSphere.geometry.dispose();
  24006. this.lightSphere.material.dispose();
  24007. };
  24008. THREE.HemisphereLightHelper.prototype.update = function () {
  24009. var vector = new THREE.Vector3();
  24010. return function () {
  24011. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  24012. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  24013. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  24014. this.lightSphere.geometry.colorsNeedUpdate = true;
  24015. }
  24016. }();
  24017. // File:src/extras/helpers/PointLightHelper.js
  24018. /**
  24019. * @author alteredq / http://alteredqualia.com/
  24020. * @author mrdoob / http://mrdoob.com/
  24021. */
  24022. THREE.PointLightHelper = function ( light, sphereSize ) {
  24023. this.light = light;
  24024. this.light.updateMatrixWorld();
  24025. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  24026. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  24027. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24028. THREE.Mesh.call( this, geometry, material );
  24029. this.matrix = this.light.matrixWorld;
  24030. this.matrixAutoUpdate = false;
  24031. /*
  24032. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  24033. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  24034. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  24035. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  24036. var d = light.distance;
  24037. if ( d === 0.0 ) {
  24038. this.lightDistance.visible = false;
  24039. } else {
  24040. this.lightDistance.scale.set( d, d, d );
  24041. }
  24042. this.add( this.lightDistance );
  24043. */
  24044. };
  24045. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  24046. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  24047. THREE.PointLightHelper.prototype.dispose = function () {
  24048. this.geometry.dispose();
  24049. this.material.dispose();
  24050. };
  24051. THREE.PointLightHelper.prototype.update = function () {
  24052. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24053. /*
  24054. var d = this.light.distance;
  24055. if ( d === 0.0 ) {
  24056. this.lightDistance.visible = false;
  24057. } else {
  24058. this.lightDistance.visible = true;
  24059. this.lightDistance.scale.set( d, d, d );
  24060. }
  24061. */
  24062. };
  24063. // File:src/extras/helpers/SkeletonHelper.js
  24064. /**
  24065. * @author Sean Griffin / http://twitter.com/sgrif
  24066. * @author Michael Guerrero / http://realitymeltdown.com
  24067. * @author mrdoob / http://mrdoob.com/
  24068. * @author ikerr / http://verold.com
  24069. */
  24070. THREE.SkeletonHelper = function ( object ) {
  24071. this.bones = this.getBoneList( object );
  24072. var geometry = new THREE.Geometry();
  24073. for ( var i = 0; i < this.bones.length; i ++ ) {
  24074. var bone = this.bones[ i ];
  24075. if ( bone.parent instanceof THREE.Bone ) {
  24076. geometry.vertices.push( new THREE.Vector3() );
  24077. geometry.vertices.push( new THREE.Vector3() );
  24078. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  24079. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  24080. }
  24081. }
  24082. geometry.dynamic = true;
  24083. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  24084. THREE.LineSegments.call( this, geometry, material );
  24085. this.root = object;
  24086. this.matrix = object.matrixWorld;
  24087. this.matrixAutoUpdate = false;
  24088. this.update();
  24089. };
  24090. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24091. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  24092. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  24093. var boneList = [];
  24094. if ( object instanceof THREE.Bone ) {
  24095. boneList.push( object );
  24096. }
  24097. for ( var i = 0; i < object.children.length; i ++ ) {
  24098. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  24099. }
  24100. return boneList;
  24101. };
  24102. THREE.SkeletonHelper.prototype.update = function () {
  24103. var geometry = this.geometry;
  24104. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  24105. var boneMatrix = new THREE.Matrix4();
  24106. var j = 0;
  24107. for ( var i = 0; i < this.bones.length; i ++ ) {
  24108. var bone = this.bones[ i ];
  24109. if ( bone.parent instanceof THREE.Bone ) {
  24110. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  24111. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  24112. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  24113. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  24114. j += 2;
  24115. }
  24116. }
  24117. geometry.verticesNeedUpdate = true;
  24118. geometry.computeBoundingSphere();
  24119. };
  24120. // File:src/extras/helpers/SpotLightHelper.js
  24121. /**
  24122. * @author alteredq / http://alteredqualia.com/
  24123. * @author mrdoob / http://mrdoob.com/
  24124. * @author WestLangley / http://github.com/WestLangley
  24125. */
  24126. THREE.SpotLightHelper = function ( light ) {
  24127. THREE.Object3D.call( this );
  24128. this.light = light;
  24129. this.light.updateMatrixWorld();
  24130. this.matrix = light.matrixWorld;
  24131. this.matrixAutoUpdate = false;
  24132. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  24133. geometry.translate( 0, - 0.5, 0 );
  24134. geometry.rotateX( - Math.PI / 2 );
  24135. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  24136. this.cone = new THREE.Mesh( geometry, material );
  24137. this.add( this.cone );
  24138. this.update();
  24139. };
  24140. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24141. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  24142. THREE.SpotLightHelper.prototype.dispose = function () {
  24143. this.cone.geometry.dispose();
  24144. this.cone.material.dispose();
  24145. };
  24146. THREE.SpotLightHelper.prototype.update = function () {
  24147. var vector = new THREE.Vector3();
  24148. var vector2 = new THREE.Vector3();
  24149. return function () {
  24150. var coneLength = this.light.distance ? this.light.distance : 10000;
  24151. var coneWidth = coneLength * Math.tan( this.light.angle );
  24152. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  24153. vector.setFromMatrixPosition( this.light.matrixWorld );
  24154. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  24155. this.cone.lookAt( vector2.sub( vector ) );
  24156. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24157. };
  24158. }();
  24159. // File:src/extras/helpers/VertexNormalsHelper.js
  24160. /**
  24161. * @author mrdoob / http://mrdoob.com/
  24162. * @author WestLangley / http://github.com/WestLangley
  24163. */
  24164. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  24165. this.object = object;
  24166. this.size = ( size !== undefined ) ? size : 1;
  24167. var color = ( hex !== undefined ) ? hex : 0xff0000;
  24168. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24169. //
  24170. var nNormals = 0;
  24171. var objGeometry = this.object.geometry;
  24172. if ( objGeometry instanceof THREE.Geometry ) {
  24173. nNormals = objGeometry.faces.length * 3;
  24174. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24175. nNormals = objGeometry.attributes.normal.count
  24176. }
  24177. //
  24178. var geometry = new THREE.BufferGeometry();
  24179. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  24180. geometry.addAttribute( 'position', positions );
  24181. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  24182. //
  24183. this.matrixAutoUpdate = false;
  24184. this.update();
  24185. };
  24186. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24187. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  24188. THREE.VertexNormalsHelper.prototype.update = ( function () {
  24189. var v1 = new THREE.Vector3();
  24190. var v2 = new THREE.Vector3();
  24191. var normalMatrix = new THREE.Matrix3();
  24192. return function update() {
  24193. var keys = [ 'a', 'b', 'c' ];
  24194. this.object.updateMatrixWorld( true );
  24195. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24196. var matrixWorld = this.object.matrixWorld;
  24197. var position = this.geometry.attributes.position;
  24198. //
  24199. var objGeometry = this.object.geometry;
  24200. if ( objGeometry instanceof THREE.Geometry ) {
  24201. var vertices = objGeometry.vertices;
  24202. var faces = objGeometry.faces;
  24203. var idx = 0;
  24204. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24205. var face = faces[ i ];
  24206. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  24207. var vertex = vertices[ face[ keys[ j ] ] ];
  24208. var normal = face.vertexNormals[ j ];
  24209. v1.copy( vertex ).applyMatrix4( matrixWorld );
  24210. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24211. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24212. idx = idx + 1;
  24213. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24214. idx = idx + 1;
  24215. }
  24216. }
  24217. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24218. var objPos = objGeometry.attributes.position;
  24219. var objNorm = objGeometry.attributes.normal;
  24220. var idx = 0;
  24221. // for simplicity, ignore index and drawcalls, and render every normal
  24222. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  24223. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  24224. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  24225. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24226. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24227. idx = idx + 1;
  24228. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24229. idx = idx + 1;
  24230. }
  24231. }
  24232. position.needsUpdate = true;
  24233. return this;
  24234. }
  24235. }() );
  24236. // File:src/extras/helpers/WireframeHelper.js
  24237. /**
  24238. * @author mrdoob / http://mrdoob.com/
  24239. */
  24240. THREE.WireframeHelper = function ( object, hex ) {
  24241. var color = ( hex !== undefined ) ? hex : 0xffffff;
  24242. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  24243. this.matrix = object.matrixWorld;
  24244. this.matrixAutoUpdate = false;
  24245. };
  24246. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24247. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  24248. // File:src/extras/objects/ImmediateRenderObject.js
  24249. /**
  24250. * @author alteredq / http://alteredqualia.com/
  24251. */
  24252. THREE.ImmediateRenderObject = function ( material ) {
  24253. THREE.Object3D.call( this );
  24254. this.material = material;
  24255. this.render = function ( renderCallback ) {};
  24256. };
  24257. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  24258. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  24259. // File:src/extras/objects/MorphBlendMesh.js
  24260. /**
  24261. * @author alteredq / http://alteredqualia.com/
  24262. */
  24263. THREE.MorphBlendMesh = function( geometry, material ) {
  24264. THREE.Mesh.call( this, geometry, material );
  24265. this.animationsMap = {};
  24266. this.animationsList = [];
  24267. // prepare default animation
  24268. // (all frames played together in 1 second)
  24269. var numFrames = this.geometry.morphTargets.length;
  24270. var name = "__default";
  24271. var startFrame = 0;
  24272. var endFrame = numFrames - 1;
  24273. var fps = numFrames / 1;
  24274. this.createAnimation( name, startFrame, endFrame, fps );
  24275. this.setAnimationWeight( name, 1 );
  24276. };
  24277. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  24278. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  24279. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  24280. var animation = {
  24281. start: start,
  24282. end: end,
  24283. length: end - start + 1,
  24284. fps: fps,
  24285. duration: ( end - start ) / fps,
  24286. lastFrame: 0,
  24287. currentFrame: 0,
  24288. active: false,
  24289. time: 0,
  24290. direction: 1,
  24291. weight: 1,
  24292. directionBackwards: false,
  24293. mirroredLoop: false
  24294. };
  24295. this.animationsMap[ name ] = animation;
  24296. this.animationsList.push( animation );
  24297. };
  24298. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  24299. var pattern = /([a-z]+)_?(\d+)/i;
  24300. var firstAnimation, frameRanges = {};
  24301. var geometry = this.geometry;
  24302. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  24303. var morph = geometry.morphTargets[ i ];
  24304. var chunks = morph.name.match( pattern );
  24305. if ( chunks && chunks.length > 1 ) {
  24306. var name = chunks[ 1 ];
  24307. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  24308. var range = frameRanges[ name ];
  24309. if ( i < range.start ) range.start = i;
  24310. if ( i > range.end ) range.end = i;
  24311. if ( ! firstAnimation ) firstAnimation = name;
  24312. }
  24313. }
  24314. for ( var name in frameRanges ) {
  24315. var range = frameRanges[ name ];
  24316. this.createAnimation( name, range.start, range.end, fps );
  24317. }
  24318. this.firstAnimation = firstAnimation;
  24319. };
  24320. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  24321. var animation = this.animationsMap[ name ];
  24322. if ( animation ) {
  24323. animation.direction = 1;
  24324. animation.directionBackwards = false;
  24325. }
  24326. };
  24327. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  24328. var animation = this.animationsMap[ name ];
  24329. if ( animation ) {
  24330. animation.direction = - 1;
  24331. animation.directionBackwards = true;
  24332. }
  24333. };
  24334. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  24335. var animation = this.animationsMap[ name ];
  24336. if ( animation ) {
  24337. animation.fps = fps;
  24338. animation.duration = ( animation.end - animation.start ) / animation.fps;
  24339. }
  24340. };
  24341. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  24342. var animation = this.animationsMap[ name ];
  24343. if ( animation ) {
  24344. animation.duration = duration;
  24345. animation.fps = ( animation.end - animation.start ) / animation.duration;
  24346. }
  24347. };
  24348. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  24349. var animation = this.animationsMap[ name ];
  24350. if ( animation ) {
  24351. animation.weight = weight;
  24352. }
  24353. };
  24354. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  24355. var animation = this.animationsMap[ name ];
  24356. if ( animation ) {
  24357. animation.time = time;
  24358. }
  24359. };
  24360. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  24361. var time = 0;
  24362. var animation = this.animationsMap[ name ];
  24363. if ( animation ) {
  24364. time = animation.time;
  24365. }
  24366. return time;
  24367. };
  24368. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  24369. var duration = - 1;
  24370. var animation = this.animationsMap[ name ];
  24371. if ( animation ) {
  24372. duration = animation.duration;
  24373. }
  24374. return duration;
  24375. };
  24376. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  24377. var animation = this.animationsMap[ name ];
  24378. if ( animation ) {
  24379. animation.time = 0;
  24380. animation.active = true;
  24381. } else {
  24382. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  24383. }
  24384. };
  24385. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  24386. var animation = this.animationsMap[ name ];
  24387. if ( animation ) {
  24388. animation.active = false;
  24389. }
  24390. };
  24391. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  24392. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  24393. var animation = this.animationsList[ i ];
  24394. if ( ! animation.active ) continue;
  24395. var frameTime = animation.duration / animation.length;
  24396. animation.time += animation.direction * delta;
  24397. if ( animation.mirroredLoop ) {
  24398. if ( animation.time > animation.duration || animation.time < 0 ) {
  24399. animation.direction *= - 1;
  24400. if ( animation.time > animation.duration ) {
  24401. animation.time = animation.duration;
  24402. animation.directionBackwards = true;
  24403. }
  24404. if ( animation.time < 0 ) {
  24405. animation.time = 0;
  24406. animation.directionBackwards = false;
  24407. }
  24408. }
  24409. } else {
  24410. animation.time = animation.time % animation.duration;
  24411. if ( animation.time < 0 ) animation.time += animation.duration;
  24412. }
  24413. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  24414. var weight = animation.weight;
  24415. if ( keyframe !== animation.currentFrame ) {
  24416. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  24417. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  24418. this.morphTargetInfluences[ keyframe ] = 0;
  24419. animation.lastFrame = animation.currentFrame;
  24420. animation.currentFrame = keyframe;
  24421. }
  24422. var mix = ( animation.time % frameTime ) / frameTime;
  24423. if ( animation.directionBackwards ) mix = 1 - mix;
  24424. if ( animation.currentFrame !== animation.lastFrame ) {
  24425. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  24426. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  24427. } else {
  24428. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  24429. }
  24430. }
  24431. };