three.js 888 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '75dev' };
  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. // Mapping modes
  133. THREE.UVMapping = 300;
  134. THREE.CubeReflectionMapping = 301;
  135. THREE.CubeRefractionMapping = 302;
  136. THREE.EquirectangularReflectionMapping = 303;
  137. THREE.EquirectangularRefractionMapping = 304;
  138. THREE.SphericalReflectionMapping = 305;
  139. // Wrapping modes
  140. THREE.RepeatWrapping = 1000;
  141. THREE.ClampToEdgeWrapping = 1001;
  142. THREE.MirroredRepeatWrapping = 1002;
  143. // Filters
  144. THREE.NearestFilter = 1003;
  145. THREE.NearestMipMapNearestFilter = 1004;
  146. THREE.NearestMipMapLinearFilter = 1005;
  147. THREE.LinearFilter = 1006;
  148. THREE.LinearMipMapNearestFilter = 1007;
  149. THREE.LinearMipMapLinearFilter = 1008;
  150. // Data types
  151. THREE.UnsignedByteType = 1009;
  152. THREE.ByteType = 1010;
  153. THREE.ShortType = 1011;
  154. THREE.UnsignedShortType = 1012;
  155. THREE.IntType = 1013;
  156. THREE.UnsignedIntType = 1014;
  157. THREE.FloatType = 1015;
  158. THREE.HalfFloatType = 1025;
  159. // Pixel types
  160. //THREE.UnsignedByteType = 1009;
  161. THREE.UnsignedShort4444Type = 1016;
  162. THREE.UnsignedShort5551Type = 1017;
  163. THREE.UnsignedShort565Type = 1018;
  164. // Pixel formats
  165. THREE.AlphaFormat = 1019;
  166. THREE.RGBFormat = 1020;
  167. THREE.RGBAFormat = 1021;
  168. THREE.LuminanceFormat = 1022;
  169. THREE.LuminanceAlphaFormat = 1023;
  170. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  171. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  172. // DDS / ST3C Compressed texture formats
  173. THREE.RGB_S3TC_DXT1_Format = 2001;
  174. THREE.RGBA_S3TC_DXT1_Format = 2002;
  175. THREE.RGBA_S3TC_DXT3_Format = 2003;
  176. THREE.RGBA_S3TC_DXT5_Format = 2004;
  177. // PVRTC compressed texture formats
  178. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  179. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  180. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  181. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  182. // ETC compressed texture formats
  183. THREE.RGB_ETC1_Format = 2151;
  184. // Loop styles for AnimationAction
  185. THREE.LoopOnce = 2200;
  186. THREE.LoopRepeat = 2201;
  187. THREE.LoopPingPong = 2202;
  188. // Interpolation
  189. THREE.InterpolateDiscrete = 2300;
  190. THREE.InterpolateLinear = 2301;
  191. THREE.InterpolateSmooth = 2302;
  192. // Interpolant ending modes
  193. THREE.ZeroCurvatureEnding = 2400;
  194. THREE.ZeroSlopeEnding = 2401;
  195. THREE.WrapAroundEnding = 2402;
  196. // Triangle Draw modes
  197. THREE.TrianglesDrawMode = 0;
  198. THREE.TriangleStripDrawMode = 1;
  199. THREE.TriangleFanDrawMode = 2;
  200. // File:src/math/Color.js
  201. /**
  202. * @author mrdoob / http://mrdoob.com/
  203. */
  204. THREE.Color = function ( color ) {
  205. if ( arguments.length === 3 ) {
  206. return this.fromArray( arguments );
  207. }
  208. return this.set( color );
  209. };
  210. THREE.Color.prototype = {
  211. constructor: THREE.Color,
  212. r: 1, g: 1, b: 1,
  213. set: function ( value ) {
  214. if ( value instanceof THREE.Color ) {
  215. this.copy( value );
  216. } else if ( typeof value === 'number' ) {
  217. this.setHex( value );
  218. } else if ( typeof value === 'string' ) {
  219. this.setStyle( value );
  220. }
  221. return this;
  222. },
  223. setScalar: function ( scalar ) {
  224. this.r = scalar;
  225. this.g = scalar;
  226. this.b = scalar;
  227. },
  228. setHex: function ( hex ) {
  229. hex = Math.floor( hex );
  230. this.r = ( hex >> 16 & 255 ) / 255;
  231. this.g = ( hex >> 8 & 255 ) / 255;
  232. this.b = ( hex & 255 ) / 255;
  233. return this;
  234. },
  235. setRGB: function ( r, g, b ) {
  236. this.r = r;
  237. this.g = g;
  238. this.b = b;
  239. return this;
  240. },
  241. setHSL: function () {
  242. function hue2rgb( p, q, t ) {
  243. if ( t < 0 ) t += 1;
  244. if ( t > 1 ) t -= 1;
  245. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  246. if ( t < 1 / 2 ) return q;
  247. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  248. return p;
  249. }
  250. return function ( h, s, l ) {
  251. // h,s,l ranges are in 0.0 - 1.0
  252. h = THREE.Math.euclideanModulo( h, 1 );
  253. s = THREE.Math.clamp( s, 0, 1 );
  254. l = THREE.Math.clamp( l, 0, 1 );
  255. if ( s === 0 ) {
  256. this.r = this.g = this.b = l;
  257. } else {
  258. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  259. var q = ( 2 * l ) - p;
  260. this.r = hue2rgb( q, p, h + 1 / 3 );
  261. this.g = hue2rgb( q, p, h );
  262. this.b = hue2rgb( q, p, h - 1 / 3 );
  263. }
  264. return this;
  265. };
  266. }(),
  267. setStyle: function ( style ) {
  268. function handleAlpha( string ) {
  269. if ( string === undefined ) return;
  270. if ( parseFloat( string ) < 1 ) {
  271. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  272. }
  273. }
  274. var m;
  275. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  276. // rgb / hsl
  277. var color;
  278. var name = m[ 1 ];
  279. var components = m[ 2 ];
  280. switch ( name ) {
  281. case 'rgb':
  282. case 'rgba':
  283. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  284. // rgb(255,0,0) rgba(255,0,0,0.5)
  285. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  286. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  287. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  288. handleAlpha( color[ 5 ] );
  289. return this;
  290. }
  291. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  292. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  293. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  294. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  295. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  296. handleAlpha( color[ 5 ] );
  297. return this;
  298. }
  299. break;
  300. case 'hsl':
  301. case 'hsla':
  302. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  303. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  304. var h = parseFloat( color[ 1 ] ) / 360;
  305. var s = parseInt( color[ 2 ], 10 ) / 100;
  306. var l = parseInt( color[ 3 ], 10 ) / 100;
  307. handleAlpha( color[ 5 ] );
  308. return this.setHSL( h, s, l );
  309. }
  310. break;
  311. }
  312. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  313. // hex color
  314. var hex = m[ 1 ];
  315. var size = hex.length;
  316. if ( size === 3 ) {
  317. // #ff0
  318. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  319. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  320. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  321. return this;
  322. } else if ( size === 6 ) {
  323. // #ff0000
  324. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  325. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  326. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  327. return this;
  328. }
  329. }
  330. if ( style && style.length > 0 ) {
  331. // color keywords
  332. var hex = THREE.ColorKeywords[ style ];
  333. if ( hex !== undefined ) {
  334. // red
  335. this.setHex( hex );
  336. } else {
  337. // unknown color
  338. console.warn( 'THREE.Color: Unknown color ' + style );
  339. }
  340. }
  341. return this;
  342. },
  343. clone: function () {
  344. return new this.constructor( this.r, this.g, this.b );
  345. },
  346. copy: function ( color ) {
  347. this.r = color.r;
  348. this.g = color.g;
  349. this.b = color.b;
  350. return this;
  351. },
  352. copyGammaToLinear: function ( color, gammaFactor ) {
  353. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  354. this.r = Math.pow( color.r, gammaFactor );
  355. this.g = Math.pow( color.g, gammaFactor );
  356. this.b = Math.pow( color.b, gammaFactor );
  357. return this;
  358. },
  359. copyLinearToGamma: function ( color, gammaFactor ) {
  360. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  361. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  362. this.r = Math.pow( color.r, safeInverse );
  363. this.g = Math.pow( color.g, safeInverse );
  364. this.b = Math.pow( color.b, safeInverse );
  365. return this;
  366. },
  367. convertGammaToLinear: function () {
  368. var r = this.r, g = this.g, b = this.b;
  369. this.r = r * r;
  370. this.g = g * g;
  371. this.b = b * b;
  372. return this;
  373. },
  374. convertLinearToGamma: function () {
  375. this.r = Math.sqrt( this.r );
  376. this.g = Math.sqrt( this.g );
  377. this.b = Math.sqrt( this.b );
  378. return this;
  379. },
  380. getHex: function () {
  381. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  382. },
  383. getHexString: function () {
  384. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  385. },
  386. getHSL: function ( optionalTarget ) {
  387. // h,s,l ranges are in 0.0 - 1.0
  388. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  389. var r = this.r, g = this.g, b = this.b;
  390. var max = Math.max( r, g, b );
  391. var min = Math.min( r, g, b );
  392. var hue, saturation;
  393. var lightness = ( min + max ) / 2.0;
  394. if ( min === max ) {
  395. hue = 0;
  396. saturation = 0;
  397. } else {
  398. var delta = max - min;
  399. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  400. switch ( max ) {
  401. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  402. case g: hue = ( b - r ) / delta + 2; break;
  403. case b: hue = ( r - g ) / delta + 4; break;
  404. }
  405. hue /= 6;
  406. }
  407. hsl.h = hue;
  408. hsl.s = saturation;
  409. hsl.l = lightness;
  410. return hsl;
  411. },
  412. getStyle: function () {
  413. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  414. },
  415. offsetHSL: function ( h, s, l ) {
  416. var hsl = this.getHSL();
  417. hsl.h += h; hsl.s += s; hsl.l += l;
  418. this.setHSL( hsl.h, hsl.s, hsl.l );
  419. return this;
  420. },
  421. add: function ( color ) {
  422. this.r += color.r;
  423. this.g += color.g;
  424. this.b += color.b;
  425. return this;
  426. },
  427. addColors: function ( color1, color2 ) {
  428. this.r = color1.r + color2.r;
  429. this.g = color1.g + color2.g;
  430. this.b = color1.b + color2.b;
  431. return this;
  432. },
  433. addScalar: function ( s ) {
  434. this.r += s;
  435. this.g += s;
  436. this.b += s;
  437. return this;
  438. },
  439. multiply: function ( color ) {
  440. this.r *= color.r;
  441. this.g *= color.g;
  442. this.b *= color.b;
  443. return this;
  444. },
  445. multiplyScalar: function ( s ) {
  446. this.r *= s;
  447. this.g *= s;
  448. this.b *= s;
  449. return this;
  450. },
  451. lerp: function ( color, alpha ) {
  452. this.r += ( color.r - this.r ) * alpha;
  453. this.g += ( color.g - this.g ) * alpha;
  454. this.b += ( color.b - this.b ) * alpha;
  455. return this;
  456. },
  457. equals: function ( c ) {
  458. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  459. },
  460. fromArray: function ( array, offset ) {
  461. if ( offset === undefined ) offset = 0;
  462. this.r = array[ offset ];
  463. this.g = array[ offset + 1 ];
  464. this.b = array[ offset + 2 ];
  465. return this;
  466. },
  467. toArray: function ( array, offset ) {
  468. if ( array === undefined ) array = [];
  469. if ( offset === undefined ) offset = 0;
  470. array[ offset ] = this.r;
  471. array[ offset + 1 ] = this.g;
  472. array[ offset + 2 ] = this.b;
  473. return array;
  474. }
  475. };
  476. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  477. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  478. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  479. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  480. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  481. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  482. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  483. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  484. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  485. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  486. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  487. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  488. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  489. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  490. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  491. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  492. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  493. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  494. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  495. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  496. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  497. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  498. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  499. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  500. // File:src/math/Quaternion.js
  501. /**
  502. * @author mikael emtinger / http://gomo.se/
  503. * @author alteredq / http://alteredqualia.com/
  504. * @author WestLangley / http://github.com/WestLangley
  505. * @author bhouston / http://clara.io
  506. */
  507. THREE.Quaternion = function ( x, y, z, w ) {
  508. this._x = x || 0;
  509. this._y = y || 0;
  510. this._z = z || 0;
  511. this._w = ( w !== undefined ) ? w : 1;
  512. };
  513. THREE.Quaternion.prototype = {
  514. constructor: THREE.Quaternion,
  515. get x () {
  516. return this._x;
  517. },
  518. set x ( value ) {
  519. this._x = value;
  520. this.onChangeCallback();
  521. },
  522. get y () {
  523. return this._y;
  524. },
  525. set y ( value ) {
  526. this._y = value;
  527. this.onChangeCallback();
  528. },
  529. get z () {
  530. return this._z;
  531. },
  532. set z ( value ) {
  533. this._z = value;
  534. this.onChangeCallback();
  535. },
  536. get w () {
  537. return this._w;
  538. },
  539. set w ( value ) {
  540. this._w = value;
  541. this.onChangeCallback();
  542. },
  543. set: function ( x, y, z, w ) {
  544. this._x = x;
  545. this._y = y;
  546. this._z = z;
  547. this._w = w;
  548. this.onChangeCallback();
  549. return this;
  550. },
  551. clone: function () {
  552. return new this.constructor( this._x, this._y, this._z, this._w );
  553. },
  554. copy: function ( quaternion ) {
  555. this._x = quaternion.x;
  556. this._y = quaternion.y;
  557. this._z = quaternion.z;
  558. this._w = quaternion.w;
  559. this.onChangeCallback();
  560. return this;
  561. },
  562. setFromEuler: function ( euler, update ) {
  563. if ( euler instanceof THREE.Euler === false ) {
  564. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  565. }
  566. // http://www.mathworks.com/matlabcentral/fileexchange/
  567. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  568. // content/SpinCalc.m
  569. var c1 = Math.cos( euler._x / 2 );
  570. var c2 = Math.cos( euler._y / 2 );
  571. var c3 = Math.cos( euler._z / 2 );
  572. var s1 = Math.sin( euler._x / 2 );
  573. var s2 = Math.sin( euler._y / 2 );
  574. var s3 = Math.sin( euler._z / 2 );
  575. var order = euler.order;
  576. if ( order === 'XYZ' ) {
  577. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  578. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  579. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  580. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  581. } else if ( order === 'YXZ' ) {
  582. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  583. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  584. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  585. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  586. } else if ( order === 'ZXY' ) {
  587. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  588. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  589. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  590. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  591. } else if ( order === 'ZYX' ) {
  592. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  593. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  594. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  595. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  596. } else if ( order === 'YZX' ) {
  597. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  598. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  599. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  600. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  601. } else if ( order === 'XZY' ) {
  602. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  603. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  604. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  605. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  606. }
  607. if ( update !== false ) this.onChangeCallback();
  608. return this;
  609. },
  610. setFromAxisAngle: function ( axis, angle ) {
  611. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  612. // assumes axis is normalized
  613. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  614. this._x = axis.x * s;
  615. this._y = axis.y * s;
  616. this._z = axis.z * s;
  617. this._w = Math.cos( halfAngle );
  618. this.onChangeCallback();
  619. return this;
  620. },
  621. setFromRotationMatrix: function ( m ) {
  622. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  623. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  624. var te = m.elements,
  625. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  626. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  627. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  628. trace = m11 + m22 + m33,
  629. s;
  630. if ( trace > 0 ) {
  631. s = 0.5 / Math.sqrt( trace + 1.0 );
  632. this._w = 0.25 / s;
  633. this._x = ( m32 - m23 ) * s;
  634. this._y = ( m13 - m31 ) * s;
  635. this._z = ( m21 - m12 ) * s;
  636. } else if ( m11 > m22 && m11 > m33 ) {
  637. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  638. this._w = ( m32 - m23 ) / s;
  639. this._x = 0.25 * s;
  640. this._y = ( m12 + m21 ) / s;
  641. this._z = ( m13 + m31 ) / s;
  642. } else if ( m22 > m33 ) {
  643. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  644. this._w = ( m13 - m31 ) / s;
  645. this._x = ( m12 + m21 ) / s;
  646. this._y = 0.25 * s;
  647. this._z = ( m23 + m32 ) / s;
  648. } else {
  649. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  650. this._w = ( m21 - m12 ) / s;
  651. this._x = ( m13 + m31 ) / s;
  652. this._y = ( m23 + m32 ) / s;
  653. this._z = 0.25 * s;
  654. }
  655. this.onChangeCallback();
  656. return this;
  657. },
  658. setFromUnitVectors: function () {
  659. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  660. // assumes direction vectors vFrom and vTo are normalized
  661. var v1, r;
  662. var EPS = 0.000001;
  663. return function ( vFrom, vTo ) {
  664. if ( v1 === undefined ) v1 = new THREE.Vector3();
  665. r = vFrom.dot( vTo ) + 1;
  666. if ( r < EPS ) {
  667. r = 0;
  668. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  669. v1.set( - vFrom.y, vFrom.x, 0 );
  670. } else {
  671. v1.set( 0, - vFrom.z, vFrom.y );
  672. }
  673. } else {
  674. v1.crossVectors( vFrom, vTo );
  675. }
  676. this._x = v1.x;
  677. this._y = v1.y;
  678. this._z = v1.z;
  679. this._w = r;
  680. this.normalize();
  681. return this;
  682. };
  683. }(),
  684. inverse: function () {
  685. this.conjugate().normalize();
  686. return this;
  687. },
  688. conjugate: function () {
  689. this._x *= - 1;
  690. this._y *= - 1;
  691. this._z *= - 1;
  692. this.onChangeCallback();
  693. return this;
  694. },
  695. dot: function ( v ) {
  696. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  697. },
  698. lengthSq: function () {
  699. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  700. },
  701. length: function () {
  702. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  703. },
  704. normalize: function () {
  705. var l = this.length();
  706. if ( l === 0 ) {
  707. this._x = 0;
  708. this._y = 0;
  709. this._z = 0;
  710. this._w = 1;
  711. } else {
  712. l = 1 / l;
  713. this._x = this._x * l;
  714. this._y = this._y * l;
  715. this._z = this._z * l;
  716. this._w = this._w * l;
  717. }
  718. this.onChangeCallback();
  719. return this;
  720. },
  721. multiply: function ( q, p ) {
  722. if ( p !== undefined ) {
  723. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  724. return this.multiplyQuaternions( q, p );
  725. }
  726. return this.multiplyQuaternions( this, q );
  727. },
  728. multiplyQuaternions: function ( a, b ) {
  729. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  730. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  731. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  732. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  733. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  734. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  735. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  736. this.onChangeCallback();
  737. return this;
  738. },
  739. slerp: function ( qb, t ) {
  740. if ( t === 0 ) return this;
  741. if ( t === 1 ) return this.copy( qb );
  742. var x = this._x, y = this._y, z = this._z, w = this._w;
  743. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  744. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  745. if ( cosHalfTheta < 0 ) {
  746. this._w = - qb._w;
  747. this._x = - qb._x;
  748. this._y = - qb._y;
  749. this._z = - qb._z;
  750. cosHalfTheta = - cosHalfTheta;
  751. } else {
  752. this.copy( qb );
  753. }
  754. if ( cosHalfTheta >= 1.0 ) {
  755. this._w = w;
  756. this._x = x;
  757. this._y = y;
  758. this._z = z;
  759. return this;
  760. }
  761. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  762. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  763. this._w = 0.5 * ( w + this._w );
  764. this._x = 0.5 * ( x + this._x );
  765. this._y = 0.5 * ( y + this._y );
  766. this._z = 0.5 * ( z + this._z );
  767. return this;
  768. }
  769. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  770. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  771. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  772. this._w = ( w * ratioA + this._w * ratioB );
  773. this._x = ( x * ratioA + this._x * ratioB );
  774. this._y = ( y * ratioA + this._y * ratioB );
  775. this._z = ( z * ratioA + this._z * ratioB );
  776. this.onChangeCallback();
  777. return this;
  778. },
  779. equals: function ( quaternion ) {
  780. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  781. },
  782. fromArray: function ( array, offset ) {
  783. if ( offset === undefined ) offset = 0;
  784. this._x = array[ offset ];
  785. this._y = array[ offset + 1 ];
  786. this._z = array[ offset + 2 ];
  787. this._w = array[ offset + 3 ];
  788. this.onChangeCallback();
  789. return this;
  790. },
  791. toArray: function ( array, offset ) {
  792. if ( array === undefined ) array = [];
  793. if ( offset === undefined ) offset = 0;
  794. array[ offset ] = this._x;
  795. array[ offset + 1 ] = this._y;
  796. array[ offset + 2 ] = this._z;
  797. array[ offset + 3 ] = this._w;
  798. return array;
  799. },
  800. onChange: function ( callback ) {
  801. this.onChangeCallback = callback;
  802. return this;
  803. },
  804. onChangeCallback: function () {}
  805. };
  806. Object.assign( THREE.Quaternion, {
  807. slerp: function( qa, qb, qm, t ) {
  808. return qm.copy( qa ).slerp( qb, t );
  809. },
  810. slerpFlat: function(
  811. dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  812. // fuzz-free, array-based Quaternion SLERP operation
  813. var x0 = src0[ srcOffset0 + 0 ],
  814. y0 = src0[ srcOffset0 + 1 ],
  815. z0 = src0[ srcOffset0 + 2 ],
  816. w0 = src0[ srcOffset0 + 3 ],
  817. x1 = src1[ srcOffset1 + 0 ],
  818. y1 = src1[ srcOffset1 + 1 ],
  819. z1 = src1[ srcOffset1 + 2 ],
  820. w1 = src1[ srcOffset1 + 3 ];
  821. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  822. var s = 1 - t,
  823. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  824. dir = ( cos >= 0 ? 1 : - 1 ),
  825. sqrSin = 1 - cos * cos;
  826. // Skip the Slerp for tiny steps to avoid numeric problems:
  827. if ( sqrSin > Number.EPSILON ) {
  828. var sin = Math.sqrt( sqrSin ),
  829. len = Math.atan2( sin, cos * dir );
  830. s = Math.sin( s * len ) / sin;
  831. t = Math.sin( t * len ) / sin;
  832. }
  833. var tDir = t * dir;
  834. x0 = x0 * s + x1 * tDir;
  835. y0 = y0 * s + y1 * tDir;
  836. z0 = z0 * s + z1 * tDir;
  837. w0 = w0 * s + w1 * tDir;
  838. // Normalize in case we just did a lerp:
  839. if ( s === 1 - t ) {
  840. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  841. x0 *= f;
  842. y0 *= f;
  843. z0 *= f;
  844. w0 *= f;
  845. }
  846. }
  847. dst[ dstOffset ] = x0;
  848. dst[ dstOffset + 1 ] = y0;
  849. dst[ dstOffset + 2 ] = z0;
  850. dst[ dstOffset + 3 ] = w0;
  851. }
  852. } );
  853. // File:src/math/Vector2.js
  854. /**
  855. * @author mrdoob / http://mrdoob.com/
  856. * @author philogb / http://blog.thejit.org/
  857. * @author egraether / http://egraether.com/
  858. * @author zz85 / http://www.lab4games.net/zz85/blog
  859. */
  860. THREE.Vector2 = function ( x, y ) {
  861. this.x = x || 0;
  862. this.y = y || 0;
  863. };
  864. THREE.Vector2.prototype = {
  865. constructor: THREE.Vector2,
  866. get width() {
  867. return this.x;
  868. },
  869. set width( value ) {
  870. this.x = value;
  871. },
  872. get height() {
  873. return this.y;
  874. },
  875. set height( value ) {
  876. this.y = value;
  877. },
  878. //
  879. set: function ( x, y ) {
  880. this.x = x;
  881. this.y = y;
  882. return this;
  883. },
  884. setScalar: function ( scalar ) {
  885. this.x = scalar;
  886. this.y = scalar;
  887. return this;
  888. },
  889. setX: function ( x ) {
  890. this.x = x;
  891. return this;
  892. },
  893. setY: function ( y ) {
  894. this.y = y;
  895. return this;
  896. },
  897. setComponent: function ( index, value ) {
  898. switch ( index ) {
  899. case 0: this.x = value; break;
  900. case 1: this.y = value; break;
  901. default: throw new Error( 'index is out of range: ' + index );
  902. }
  903. },
  904. getComponent: function ( index ) {
  905. switch ( index ) {
  906. case 0: return this.x;
  907. case 1: return this.y;
  908. default: throw new Error( 'index is out of range: ' + index );
  909. }
  910. },
  911. clone: function () {
  912. return new this.constructor( this.x, this.y );
  913. },
  914. copy: function ( v ) {
  915. this.x = v.x;
  916. this.y = v.y;
  917. return this;
  918. },
  919. add: function ( v, w ) {
  920. if ( w !== undefined ) {
  921. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  922. return this.addVectors( v, w );
  923. }
  924. this.x += v.x;
  925. this.y += v.y;
  926. return this;
  927. },
  928. addScalar: function ( s ) {
  929. this.x += s;
  930. this.y += s;
  931. return this;
  932. },
  933. addVectors: function ( a, b ) {
  934. this.x = a.x + b.x;
  935. this.y = a.y + b.y;
  936. return this;
  937. },
  938. addScaledVector: function ( v, s ) {
  939. this.x += v.x * s;
  940. this.y += v.y * s;
  941. return this;
  942. },
  943. sub: function ( v, w ) {
  944. if ( w !== undefined ) {
  945. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  946. return this.subVectors( v, w );
  947. }
  948. this.x -= v.x;
  949. this.y -= v.y;
  950. return this;
  951. },
  952. subScalar: function ( s ) {
  953. this.x -= s;
  954. this.y -= s;
  955. return this;
  956. },
  957. subVectors: function ( a, b ) {
  958. this.x = a.x - b.x;
  959. this.y = a.y - b.y;
  960. return this;
  961. },
  962. multiply: function ( v ) {
  963. this.x *= v.x;
  964. this.y *= v.y;
  965. return this;
  966. },
  967. multiplyScalar: function ( scalar ) {
  968. if ( isFinite( scalar ) ) {
  969. this.x *= scalar;
  970. this.y *= scalar;
  971. } else {
  972. this.x = 0;
  973. this.y = 0;
  974. }
  975. return this;
  976. },
  977. divide: function ( v ) {
  978. this.x /= v.x;
  979. this.y /= v.y;
  980. return this;
  981. },
  982. divideScalar: function ( scalar ) {
  983. return this.multiplyScalar( 1 / scalar );
  984. },
  985. min: function ( v ) {
  986. this.x = Math.min( this.x, v.x );
  987. this.y = Math.min( this.y, v.y );
  988. return this;
  989. },
  990. max: function ( v ) {
  991. this.x = Math.max( this.x, v.x );
  992. this.y = Math.max( this.y, v.y );
  993. return this;
  994. },
  995. clamp: function ( min, max ) {
  996. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  997. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  998. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  999. return this;
  1000. },
  1001. clampScalar: function () {
  1002. var min, max;
  1003. return function clampScalar( minVal, maxVal ) {
  1004. if ( min === undefined ) {
  1005. min = new THREE.Vector2();
  1006. max = new THREE.Vector2();
  1007. }
  1008. min.set( minVal, minVal );
  1009. max.set( maxVal, maxVal );
  1010. return this.clamp( min, max );
  1011. };
  1012. }(),
  1013. clampLength: function ( min, max ) {
  1014. var length = this.length();
  1015. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1016. return this;
  1017. },
  1018. floor: function () {
  1019. this.x = Math.floor( this.x );
  1020. this.y = Math.floor( this.y );
  1021. return this;
  1022. },
  1023. ceil: function () {
  1024. this.x = Math.ceil( this.x );
  1025. this.y = Math.ceil( this.y );
  1026. return this;
  1027. },
  1028. round: function () {
  1029. this.x = Math.round( this.x );
  1030. this.y = Math.round( this.y );
  1031. return this;
  1032. },
  1033. roundToZero: function () {
  1034. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1035. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1036. return this;
  1037. },
  1038. negate: function () {
  1039. this.x = - this.x;
  1040. this.y = - this.y;
  1041. return this;
  1042. },
  1043. dot: function ( v ) {
  1044. return this.x * v.x + this.y * v.y;
  1045. },
  1046. lengthSq: function () {
  1047. return this.x * this.x + this.y * this.y;
  1048. },
  1049. length: function () {
  1050. return Math.sqrt( this.x * this.x + this.y * this.y );
  1051. },
  1052. lengthManhattan: function() {
  1053. return Math.abs( this.x ) + Math.abs( this.y );
  1054. },
  1055. normalize: function () {
  1056. return this.divideScalar( this.length() );
  1057. },
  1058. angle: function () {
  1059. // computes the angle in radians with respect to the positive x-axis
  1060. var angle = Math.atan2( this.y, this.x );
  1061. if ( angle < 0 ) angle += 2 * Math.PI;
  1062. return angle;
  1063. },
  1064. distanceTo: function ( v ) {
  1065. return Math.sqrt( this.distanceToSquared( v ) );
  1066. },
  1067. distanceToSquared: function ( v ) {
  1068. var dx = this.x - v.x, dy = this.y - v.y;
  1069. return dx * dx + dy * dy;
  1070. },
  1071. setLength: function ( length ) {
  1072. return this.multiplyScalar( length / this.length() );
  1073. },
  1074. lerp: function ( v, alpha ) {
  1075. this.x += ( v.x - this.x ) * alpha;
  1076. this.y += ( v.y - this.y ) * alpha;
  1077. return this;
  1078. },
  1079. lerpVectors: function ( v1, v2, alpha ) {
  1080. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1081. return this;
  1082. },
  1083. equals: function ( v ) {
  1084. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1085. },
  1086. fromArray: function ( array, offset ) {
  1087. if ( offset === undefined ) offset = 0;
  1088. this.x = array[ offset ];
  1089. this.y = array[ offset + 1 ];
  1090. return this;
  1091. },
  1092. toArray: function ( array, offset ) {
  1093. if ( array === undefined ) array = [];
  1094. if ( offset === undefined ) offset = 0;
  1095. array[ offset ] = this.x;
  1096. array[ offset + 1 ] = this.y;
  1097. return array;
  1098. },
  1099. fromAttribute: function ( attribute, index, offset ) {
  1100. if ( offset === undefined ) offset = 0;
  1101. index = index * attribute.itemSize + offset;
  1102. this.x = attribute.array[ index ];
  1103. this.y = attribute.array[ index + 1 ];
  1104. return this;
  1105. },
  1106. rotateAround: function ( center, angle ) {
  1107. var c = Math.cos( angle ), s = Math.sin( angle );
  1108. var x = this.x - center.x;
  1109. var y = this.y - center.y;
  1110. this.x = x * c - y * s + center.x;
  1111. this.y = x * s + y * c + center.y;
  1112. return this;
  1113. }
  1114. };
  1115. // File:src/math/Vector3.js
  1116. /**
  1117. * @author mrdoob / http://mrdoob.com/
  1118. * @author *kile / http://kile.stravaganza.org/
  1119. * @author philogb / http://blog.thejit.org/
  1120. * @author mikael emtinger / http://gomo.se/
  1121. * @author egraether / http://egraether.com/
  1122. * @author WestLangley / http://github.com/WestLangley
  1123. */
  1124. THREE.Vector3 = function ( x, y, z ) {
  1125. this.x = x || 0;
  1126. this.y = y || 0;
  1127. this.z = z || 0;
  1128. };
  1129. THREE.Vector3.prototype = {
  1130. constructor: THREE.Vector3,
  1131. set: function ( x, y, z ) {
  1132. this.x = x;
  1133. this.y = y;
  1134. this.z = z;
  1135. return this;
  1136. },
  1137. setScalar: function ( scalar ) {
  1138. this.x = scalar;
  1139. this.y = scalar;
  1140. this.z = scalar;
  1141. return this;
  1142. },
  1143. setX: function ( x ) {
  1144. this.x = x;
  1145. return this;
  1146. },
  1147. setY: function ( y ) {
  1148. this.y = y;
  1149. return this;
  1150. },
  1151. setZ: function ( z ) {
  1152. this.z = z;
  1153. return this;
  1154. },
  1155. setComponent: function ( index, value ) {
  1156. switch ( index ) {
  1157. case 0: this.x = value; break;
  1158. case 1: this.y = value; break;
  1159. case 2: this.z = value; break;
  1160. default: throw new Error( 'index is out of range: ' + index );
  1161. }
  1162. },
  1163. getComponent: function ( index ) {
  1164. switch ( index ) {
  1165. case 0: return this.x;
  1166. case 1: return this.y;
  1167. case 2: return this.z;
  1168. default: throw new Error( 'index is out of range: ' + index );
  1169. }
  1170. },
  1171. clone: function () {
  1172. return new this.constructor( this.x, this.y, this.z );
  1173. },
  1174. copy: function ( v ) {
  1175. this.x = v.x;
  1176. this.y = v.y;
  1177. this.z = v.z;
  1178. return this;
  1179. },
  1180. add: function ( v, w ) {
  1181. if ( w !== undefined ) {
  1182. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1183. return this.addVectors( v, w );
  1184. }
  1185. this.x += v.x;
  1186. this.y += v.y;
  1187. this.z += v.z;
  1188. return this;
  1189. },
  1190. addScalar: function ( s ) {
  1191. this.x += s;
  1192. this.y += s;
  1193. this.z += s;
  1194. return this;
  1195. },
  1196. addVectors: function ( a, b ) {
  1197. this.x = a.x + b.x;
  1198. this.y = a.y + b.y;
  1199. this.z = a.z + b.z;
  1200. return this;
  1201. },
  1202. addScaledVector: function ( v, s ) {
  1203. this.x += v.x * s;
  1204. this.y += v.y * s;
  1205. this.z += v.z * s;
  1206. return this;
  1207. },
  1208. sub: function ( v, w ) {
  1209. if ( w !== undefined ) {
  1210. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1211. return this.subVectors( v, w );
  1212. }
  1213. this.x -= v.x;
  1214. this.y -= v.y;
  1215. this.z -= v.z;
  1216. return this;
  1217. },
  1218. subScalar: function ( s ) {
  1219. this.x -= s;
  1220. this.y -= s;
  1221. this.z -= s;
  1222. return this;
  1223. },
  1224. subVectors: function ( a, b ) {
  1225. this.x = a.x - b.x;
  1226. this.y = a.y - b.y;
  1227. this.z = a.z - b.z;
  1228. return this;
  1229. },
  1230. multiply: function ( v, w ) {
  1231. if ( w !== undefined ) {
  1232. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1233. return this.multiplyVectors( v, w );
  1234. }
  1235. this.x *= v.x;
  1236. this.y *= v.y;
  1237. this.z *= v.z;
  1238. return this;
  1239. },
  1240. multiplyScalar: function ( scalar ) {
  1241. if ( isFinite( scalar ) ) {
  1242. this.x *= scalar;
  1243. this.y *= scalar;
  1244. this.z *= scalar;
  1245. } else {
  1246. this.x = 0;
  1247. this.y = 0;
  1248. this.z = 0;
  1249. }
  1250. return this;
  1251. },
  1252. multiplyVectors: function ( a, b ) {
  1253. this.x = a.x * b.x;
  1254. this.y = a.y * b.y;
  1255. this.z = a.z * b.z;
  1256. return this;
  1257. },
  1258. applyEuler: function () {
  1259. var quaternion;
  1260. return function applyEuler( euler ) {
  1261. if ( euler instanceof THREE.Euler === false ) {
  1262. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1263. }
  1264. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1265. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1266. return this;
  1267. };
  1268. }(),
  1269. applyAxisAngle: function () {
  1270. var quaternion;
  1271. return function applyAxisAngle( axis, angle ) {
  1272. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1273. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1274. return this;
  1275. };
  1276. }(),
  1277. applyMatrix3: function ( m ) {
  1278. var x = this.x;
  1279. var y = this.y;
  1280. var z = this.z;
  1281. var e = m.elements;
  1282. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1283. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1284. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1285. return this;
  1286. },
  1287. applyMatrix4: function ( m ) {
  1288. // input: THREE.Matrix4 affine matrix
  1289. var x = this.x, y = this.y, z = this.z;
  1290. var e = m.elements;
  1291. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1292. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1293. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1294. return this;
  1295. },
  1296. applyProjection: function ( m ) {
  1297. // input: THREE.Matrix4 projection matrix
  1298. var x = this.x, y = this.y, z = this.z;
  1299. var e = m.elements;
  1300. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1301. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1302. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1303. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1304. return this;
  1305. },
  1306. applyQuaternion: function ( q ) {
  1307. var x = this.x;
  1308. var y = this.y;
  1309. var z = this.z;
  1310. var qx = q.x;
  1311. var qy = q.y;
  1312. var qz = q.z;
  1313. var qw = q.w;
  1314. // calculate quat * vector
  1315. var ix = qw * x + qy * z - qz * y;
  1316. var iy = qw * y + qz * x - qx * z;
  1317. var iz = qw * z + qx * y - qy * x;
  1318. var iw = - qx * x - qy * y - qz * z;
  1319. // calculate result * inverse quat
  1320. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1321. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1322. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1323. return this;
  1324. },
  1325. project: function () {
  1326. var matrix;
  1327. return function project( camera ) {
  1328. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1329. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1330. return this.applyProjection( matrix );
  1331. };
  1332. }(),
  1333. unproject: function () {
  1334. var matrix;
  1335. return function unproject( camera ) {
  1336. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1337. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1338. return this.applyProjection( matrix );
  1339. };
  1340. }(),
  1341. transformDirection: function ( m ) {
  1342. // input: THREE.Matrix4 affine matrix
  1343. // vector interpreted as a direction
  1344. var x = this.x, y = this.y, z = this.z;
  1345. var e = m.elements;
  1346. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1347. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1348. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1349. this.normalize();
  1350. return this;
  1351. },
  1352. divide: function ( v ) {
  1353. this.x /= v.x;
  1354. this.y /= v.y;
  1355. this.z /= v.z;
  1356. return this;
  1357. },
  1358. divideScalar: function ( scalar ) {
  1359. return this.multiplyScalar( 1 / scalar );
  1360. },
  1361. min: function ( v ) {
  1362. this.x = Math.min( this.x, v.x );
  1363. this.y = Math.min( this.y, v.y );
  1364. this.z = Math.min( this.z, v.z );
  1365. return this;
  1366. },
  1367. max: function ( v ) {
  1368. this.x = Math.max( this.x, v.x );
  1369. this.y = Math.max( this.y, v.y );
  1370. this.z = Math.max( this.z, v.z );
  1371. return this;
  1372. },
  1373. clamp: function ( min, max ) {
  1374. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1375. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1376. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1377. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1378. return this;
  1379. },
  1380. clampScalar: function () {
  1381. var min, max;
  1382. return function clampScalar( minVal, maxVal ) {
  1383. if ( min === undefined ) {
  1384. min = new THREE.Vector3();
  1385. max = new THREE.Vector3();
  1386. }
  1387. min.set( minVal, minVal, minVal );
  1388. max.set( maxVal, maxVal, maxVal );
  1389. return this.clamp( min, max );
  1390. };
  1391. }(),
  1392. clampLength: function ( min, max ) {
  1393. var length = this.length();
  1394. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1395. return this;
  1396. },
  1397. floor: function () {
  1398. this.x = Math.floor( this.x );
  1399. this.y = Math.floor( this.y );
  1400. this.z = Math.floor( this.z );
  1401. return this;
  1402. },
  1403. ceil: function () {
  1404. this.x = Math.ceil( this.x );
  1405. this.y = Math.ceil( this.y );
  1406. this.z = Math.ceil( this.z );
  1407. return this;
  1408. },
  1409. round: function () {
  1410. this.x = Math.round( this.x );
  1411. this.y = Math.round( this.y );
  1412. this.z = Math.round( this.z );
  1413. return this;
  1414. },
  1415. roundToZero: function () {
  1416. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1417. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1418. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1419. return this;
  1420. },
  1421. negate: function () {
  1422. this.x = - this.x;
  1423. this.y = - this.y;
  1424. this.z = - this.z;
  1425. return this;
  1426. },
  1427. dot: function ( v ) {
  1428. return this.x * v.x + this.y * v.y + this.z * v.z;
  1429. },
  1430. lengthSq: function () {
  1431. return this.x * this.x + this.y * this.y + this.z * this.z;
  1432. },
  1433. length: function () {
  1434. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1435. },
  1436. lengthManhattan: function () {
  1437. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1438. },
  1439. normalize: function () {
  1440. return this.divideScalar( this.length() );
  1441. },
  1442. setLength: function ( length ) {
  1443. return this.multiplyScalar( length / this.length() );
  1444. },
  1445. lerp: function ( v, alpha ) {
  1446. this.x += ( v.x - this.x ) * alpha;
  1447. this.y += ( v.y - this.y ) * alpha;
  1448. this.z += ( v.z - this.z ) * alpha;
  1449. return this;
  1450. },
  1451. lerpVectors: function ( v1, v2, alpha ) {
  1452. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1453. return this;
  1454. },
  1455. cross: function ( v, w ) {
  1456. if ( w !== undefined ) {
  1457. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1458. return this.crossVectors( v, w );
  1459. }
  1460. var x = this.x, y = this.y, z = this.z;
  1461. this.x = y * v.z - z * v.y;
  1462. this.y = z * v.x - x * v.z;
  1463. this.z = x * v.y - y * v.x;
  1464. return this;
  1465. },
  1466. crossVectors: function ( a, b ) {
  1467. var ax = a.x, ay = a.y, az = a.z;
  1468. var bx = b.x, by = b.y, bz = b.z;
  1469. this.x = ay * bz - az * by;
  1470. this.y = az * bx - ax * bz;
  1471. this.z = ax * by - ay * bx;
  1472. return this;
  1473. },
  1474. projectOnVector: function () {
  1475. var v1, dot;
  1476. return function projectOnVector( vector ) {
  1477. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1478. v1.copy( vector ).normalize();
  1479. dot = this.dot( v1 );
  1480. return this.copy( v1 ).multiplyScalar( dot );
  1481. };
  1482. }(),
  1483. projectOnPlane: function () {
  1484. var v1;
  1485. return function projectOnPlane( planeNormal ) {
  1486. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1487. v1.copy( this ).projectOnVector( planeNormal );
  1488. return this.sub( v1 );
  1489. }
  1490. }(),
  1491. reflect: function () {
  1492. // reflect incident vector off plane orthogonal to normal
  1493. // normal is assumed to have unit length
  1494. var v1;
  1495. return function reflect( normal ) {
  1496. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1497. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1498. }
  1499. }(),
  1500. angleTo: function ( v ) {
  1501. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1502. // clamp, to handle numerical problems
  1503. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1504. },
  1505. distanceTo: function ( v ) {
  1506. return Math.sqrt( this.distanceToSquared( v ) );
  1507. },
  1508. distanceToSquared: function ( v ) {
  1509. var dx = this.x - v.x;
  1510. var dy = this.y - v.y;
  1511. var dz = this.z - v.z;
  1512. return dx * dx + dy * dy + dz * dz;
  1513. },
  1514. setFromMatrixPosition: function ( m ) {
  1515. this.x = m.elements[ 12 ];
  1516. this.y = m.elements[ 13 ];
  1517. this.z = m.elements[ 14 ];
  1518. return this;
  1519. },
  1520. setFromMatrixScale: function ( m ) {
  1521. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1522. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1523. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1524. this.x = sx;
  1525. this.y = sy;
  1526. this.z = sz;
  1527. return this;
  1528. },
  1529. setFromMatrixColumn: function ( index, matrix ) {
  1530. var offset = index * 4;
  1531. var me = matrix.elements;
  1532. this.x = me[ offset ];
  1533. this.y = me[ offset + 1 ];
  1534. this.z = me[ offset + 2 ];
  1535. return this;
  1536. },
  1537. equals: function ( v ) {
  1538. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1539. },
  1540. fromArray: function ( array, offset ) {
  1541. if ( offset === undefined ) offset = 0;
  1542. this.x = array[ offset ];
  1543. this.y = array[ offset + 1 ];
  1544. this.z = array[ offset + 2 ];
  1545. return this;
  1546. },
  1547. toArray: function ( array, offset ) {
  1548. if ( array === undefined ) array = [];
  1549. if ( offset === undefined ) offset = 0;
  1550. array[ offset ] = this.x;
  1551. array[ offset + 1 ] = this.y;
  1552. array[ offset + 2 ] = this.z;
  1553. return array;
  1554. },
  1555. fromAttribute: function ( attribute, index, offset ) {
  1556. if ( offset === undefined ) offset = 0;
  1557. index = index * attribute.itemSize + offset;
  1558. this.x = attribute.array[ index ];
  1559. this.y = attribute.array[ index + 1 ];
  1560. this.z = attribute.array[ index + 2 ];
  1561. return this;
  1562. }
  1563. };
  1564. // File:src/math/Vector4.js
  1565. /**
  1566. * @author supereggbert / http://www.paulbrunt.co.uk/
  1567. * @author philogb / http://blog.thejit.org/
  1568. * @author mikael emtinger / http://gomo.se/
  1569. * @author egraether / http://egraether.com/
  1570. * @author WestLangley / http://github.com/WestLangley
  1571. */
  1572. THREE.Vector4 = function ( x, y, z, w ) {
  1573. this.x = x || 0;
  1574. this.y = y || 0;
  1575. this.z = z || 0;
  1576. this.w = ( w !== undefined ) ? w : 1;
  1577. };
  1578. THREE.Vector4.prototype = {
  1579. constructor: THREE.Vector4,
  1580. set: function ( x, y, z, w ) {
  1581. this.x = x;
  1582. this.y = y;
  1583. this.z = z;
  1584. this.w = w;
  1585. return this;
  1586. },
  1587. setScalar: function ( scalar ) {
  1588. this.x = scalar;
  1589. this.y = scalar;
  1590. this.z = scalar;
  1591. this.w = scalar;
  1592. return this;
  1593. },
  1594. setX: function ( x ) {
  1595. this.x = x;
  1596. return this;
  1597. },
  1598. setY: function ( y ) {
  1599. this.y = y;
  1600. return this;
  1601. },
  1602. setZ: function ( z ) {
  1603. this.z = z;
  1604. return this;
  1605. },
  1606. setW: function ( w ) {
  1607. this.w = w;
  1608. return this;
  1609. },
  1610. setComponent: function ( index, value ) {
  1611. switch ( index ) {
  1612. case 0: this.x = value; break;
  1613. case 1: this.y = value; break;
  1614. case 2: this.z = value; break;
  1615. case 3: this.w = value; break;
  1616. default: throw new Error( 'index is out of range: ' + index );
  1617. }
  1618. },
  1619. getComponent: function ( index ) {
  1620. switch ( index ) {
  1621. case 0: return this.x;
  1622. case 1: return this.y;
  1623. case 2: return this.z;
  1624. case 3: return this.w;
  1625. default: throw new Error( 'index is out of range: ' + index );
  1626. }
  1627. },
  1628. clone: function () {
  1629. return new this.constructor( this.x, this.y, this.z, this.w );
  1630. },
  1631. copy: function ( v ) {
  1632. this.x = v.x;
  1633. this.y = v.y;
  1634. this.z = v.z;
  1635. this.w = ( v.w !== undefined ) ? v.w : 1;
  1636. return this;
  1637. },
  1638. add: function ( v, w ) {
  1639. if ( w !== undefined ) {
  1640. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1641. return this.addVectors( v, w );
  1642. }
  1643. this.x += v.x;
  1644. this.y += v.y;
  1645. this.z += v.z;
  1646. this.w += v.w;
  1647. return this;
  1648. },
  1649. addScalar: function ( s ) {
  1650. this.x += s;
  1651. this.y += s;
  1652. this.z += s;
  1653. this.w += s;
  1654. return this;
  1655. },
  1656. addVectors: function ( a, b ) {
  1657. this.x = a.x + b.x;
  1658. this.y = a.y + b.y;
  1659. this.z = a.z + b.z;
  1660. this.w = a.w + b.w;
  1661. return this;
  1662. },
  1663. addScaledVector: function ( v, s ) {
  1664. this.x += v.x * s;
  1665. this.y += v.y * s;
  1666. this.z += v.z * s;
  1667. this.w += v.w * s;
  1668. return this;
  1669. },
  1670. sub: function ( v, w ) {
  1671. if ( w !== undefined ) {
  1672. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1673. return this.subVectors( v, w );
  1674. }
  1675. this.x -= v.x;
  1676. this.y -= v.y;
  1677. this.z -= v.z;
  1678. this.w -= v.w;
  1679. return this;
  1680. },
  1681. subScalar: function ( s ) {
  1682. this.x -= s;
  1683. this.y -= s;
  1684. this.z -= s;
  1685. this.w -= s;
  1686. return this;
  1687. },
  1688. subVectors: function ( a, b ) {
  1689. this.x = a.x - b.x;
  1690. this.y = a.y - b.y;
  1691. this.z = a.z - b.z;
  1692. this.w = a.w - b.w;
  1693. return this;
  1694. },
  1695. multiplyScalar: function ( scalar ) {
  1696. if ( isFinite( scalar ) ) {
  1697. this.x *= scalar;
  1698. this.y *= scalar;
  1699. this.z *= scalar;
  1700. this.w *= scalar;
  1701. } else {
  1702. this.x = 0;
  1703. this.y = 0;
  1704. this.z = 0;
  1705. this.w = 0;
  1706. }
  1707. return this;
  1708. },
  1709. applyMatrix4: function ( m ) {
  1710. var x = this.x;
  1711. var y = this.y;
  1712. var z = this.z;
  1713. var w = this.w;
  1714. var e = m.elements;
  1715. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1716. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1717. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1718. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1719. return this;
  1720. },
  1721. divideScalar: function ( scalar ) {
  1722. return this.multiplyScalar( 1 / scalar );
  1723. },
  1724. setAxisAngleFromQuaternion: function ( q ) {
  1725. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1726. // q is assumed to be normalized
  1727. this.w = 2 * Math.acos( q.w );
  1728. var s = Math.sqrt( 1 - q.w * q.w );
  1729. if ( s < 0.0001 ) {
  1730. this.x = 1;
  1731. this.y = 0;
  1732. this.z = 0;
  1733. } else {
  1734. this.x = q.x / s;
  1735. this.y = q.y / s;
  1736. this.z = q.z / s;
  1737. }
  1738. return this;
  1739. },
  1740. setAxisAngleFromRotationMatrix: function ( m ) {
  1741. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1742. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1743. var angle, x, y, z, // variables for result
  1744. epsilon = 0.01, // margin to allow for rounding errors
  1745. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1746. te = m.elements,
  1747. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1748. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1749. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1750. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1751. && ( Math.abs( m13 - m31 ) < epsilon )
  1752. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1753. // singularity found
  1754. // first check for identity matrix which must have +1 for all terms
  1755. // in leading diagonal and zero in other terms
  1756. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1757. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1758. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1759. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1760. // this singularity is identity matrix so angle = 0
  1761. this.set( 1, 0, 0, 0 );
  1762. return this; // zero angle, arbitrary axis
  1763. }
  1764. // otherwise this singularity is angle = 180
  1765. angle = Math.PI;
  1766. var xx = ( m11 + 1 ) / 2;
  1767. var yy = ( m22 + 1 ) / 2;
  1768. var zz = ( m33 + 1 ) / 2;
  1769. var xy = ( m12 + m21 ) / 4;
  1770. var xz = ( m13 + m31 ) / 4;
  1771. var yz = ( m23 + m32 ) / 4;
  1772. if ( ( xx > yy ) && ( xx > zz ) ) {
  1773. // m11 is the largest diagonal term
  1774. if ( xx < epsilon ) {
  1775. x = 0;
  1776. y = 0.707106781;
  1777. z = 0.707106781;
  1778. } else {
  1779. x = Math.sqrt( xx );
  1780. y = xy / x;
  1781. z = xz / x;
  1782. }
  1783. } else if ( yy > zz ) {
  1784. // m22 is the largest diagonal term
  1785. if ( yy < epsilon ) {
  1786. x = 0.707106781;
  1787. y = 0;
  1788. z = 0.707106781;
  1789. } else {
  1790. y = Math.sqrt( yy );
  1791. x = xy / y;
  1792. z = yz / y;
  1793. }
  1794. } else {
  1795. // m33 is the largest diagonal term so base result on this
  1796. if ( zz < epsilon ) {
  1797. x = 0.707106781;
  1798. y = 0.707106781;
  1799. z = 0;
  1800. } else {
  1801. z = Math.sqrt( zz );
  1802. x = xz / z;
  1803. y = yz / z;
  1804. }
  1805. }
  1806. this.set( x, y, z, angle );
  1807. return this; // return 180 deg rotation
  1808. }
  1809. // as we have reached here there are no singularities so we can handle normally
  1810. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1811. + ( m13 - m31 ) * ( m13 - m31 )
  1812. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1813. if ( Math.abs( s ) < 0.001 ) s = 1;
  1814. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1815. // caught by singularity test above, but I've left it in just in case
  1816. this.x = ( m32 - m23 ) / s;
  1817. this.y = ( m13 - m31 ) / s;
  1818. this.z = ( m21 - m12 ) / s;
  1819. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1820. return this;
  1821. },
  1822. min: function ( v ) {
  1823. this.x = Math.min( this.x, v.x );
  1824. this.y = Math.min( this.y, v.y );
  1825. this.z = Math.min( this.z, v.z );
  1826. this.w = Math.min( this.w, v.w );
  1827. return this;
  1828. },
  1829. max: function ( v ) {
  1830. this.x = Math.max( this.x, v.x );
  1831. this.y = Math.max( this.y, v.y );
  1832. this.z = Math.max( this.z, v.z );
  1833. this.w = Math.max( this.w, v.w );
  1834. return this;
  1835. },
  1836. clamp: function ( min, max ) {
  1837. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1838. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1839. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1840. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1841. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1842. return this;
  1843. },
  1844. clampScalar: function () {
  1845. var min, max;
  1846. return function clampScalar( minVal, maxVal ) {
  1847. if ( min === undefined ) {
  1848. min = new THREE.Vector4();
  1849. max = new THREE.Vector4();
  1850. }
  1851. min.set( minVal, minVal, minVal, minVal );
  1852. max.set( maxVal, maxVal, maxVal, maxVal );
  1853. return this.clamp( min, max );
  1854. };
  1855. }(),
  1856. floor: function () {
  1857. this.x = Math.floor( this.x );
  1858. this.y = Math.floor( this.y );
  1859. this.z = Math.floor( this.z );
  1860. this.w = Math.floor( this.w );
  1861. return this;
  1862. },
  1863. ceil: function () {
  1864. this.x = Math.ceil( this.x );
  1865. this.y = Math.ceil( this.y );
  1866. this.z = Math.ceil( this.z );
  1867. this.w = Math.ceil( this.w );
  1868. return this;
  1869. },
  1870. round: function () {
  1871. this.x = Math.round( this.x );
  1872. this.y = Math.round( this.y );
  1873. this.z = Math.round( this.z );
  1874. this.w = Math.round( this.w );
  1875. return this;
  1876. },
  1877. roundToZero: function () {
  1878. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1879. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1880. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1881. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1882. return this;
  1883. },
  1884. negate: function () {
  1885. this.x = - this.x;
  1886. this.y = - this.y;
  1887. this.z = - this.z;
  1888. this.w = - this.w;
  1889. return this;
  1890. },
  1891. dot: function ( v ) {
  1892. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1893. },
  1894. lengthSq: function () {
  1895. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1896. },
  1897. length: function () {
  1898. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1899. },
  1900. lengthManhattan: function () {
  1901. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1902. },
  1903. normalize: function () {
  1904. return this.divideScalar( this.length() );
  1905. },
  1906. setLength: function ( length ) {
  1907. return this.multiplyScalar( length / this.length() );
  1908. },
  1909. lerp: function ( v, alpha ) {
  1910. this.x += ( v.x - this.x ) * alpha;
  1911. this.y += ( v.y - this.y ) * alpha;
  1912. this.z += ( v.z - this.z ) * alpha;
  1913. this.w += ( v.w - this.w ) * alpha;
  1914. return this;
  1915. },
  1916. lerpVectors: function ( v1, v2, alpha ) {
  1917. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1918. return this;
  1919. },
  1920. equals: function ( v ) {
  1921. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1922. },
  1923. fromArray: function ( array, offset ) {
  1924. if ( offset === undefined ) offset = 0;
  1925. this.x = array[ offset ];
  1926. this.y = array[ offset + 1 ];
  1927. this.z = array[ offset + 2 ];
  1928. this.w = array[ offset + 3 ];
  1929. return this;
  1930. },
  1931. toArray: function ( array, offset ) {
  1932. if ( array === undefined ) array = [];
  1933. if ( offset === undefined ) offset = 0;
  1934. array[ offset ] = this.x;
  1935. array[ offset + 1 ] = this.y;
  1936. array[ offset + 2 ] = this.z;
  1937. array[ offset + 3 ] = this.w;
  1938. return array;
  1939. },
  1940. fromAttribute: function ( attribute, index, offset ) {
  1941. if ( offset === undefined ) offset = 0;
  1942. index = index * attribute.itemSize + offset;
  1943. this.x = attribute.array[ index ];
  1944. this.y = attribute.array[ index + 1 ];
  1945. this.z = attribute.array[ index + 2 ];
  1946. this.w = attribute.array[ index + 3 ];
  1947. return this;
  1948. }
  1949. };
  1950. // File:src/math/Euler.js
  1951. /**
  1952. * @author mrdoob / http://mrdoob.com/
  1953. * @author WestLangley / http://github.com/WestLangley
  1954. * @author bhouston / http://clara.io
  1955. */
  1956. THREE.Euler = function ( x, y, z, order ) {
  1957. this._x = x || 0;
  1958. this._y = y || 0;
  1959. this._z = z || 0;
  1960. this._order = order || THREE.Euler.DefaultOrder;
  1961. };
  1962. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1963. THREE.Euler.DefaultOrder = 'XYZ';
  1964. THREE.Euler.prototype = {
  1965. constructor: THREE.Euler,
  1966. get x () {
  1967. return this._x;
  1968. },
  1969. set x ( value ) {
  1970. this._x = value;
  1971. this.onChangeCallback();
  1972. },
  1973. get y () {
  1974. return this._y;
  1975. },
  1976. set y ( value ) {
  1977. this._y = value;
  1978. this.onChangeCallback();
  1979. },
  1980. get z () {
  1981. return this._z;
  1982. },
  1983. set z ( value ) {
  1984. this._z = value;
  1985. this.onChangeCallback();
  1986. },
  1987. get order () {
  1988. return this._order;
  1989. },
  1990. set order ( value ) {
  1991. this._order = value;
  1992. this.onChangeCallback();
  1993. },
  1994. set: function ( x, y, z, order ) {
  1995. this._x = x;
  1996. this._y = y;
  1997. this._z = z;
  1998. this._order = order || this._order;
  1999. this.onChangeCallback();
  2000. return this;
  2001. },
  2002. clone: function () {
  2003. return new this.constructor( this._x, this._y, this._z, this._order );
  2004. },
  2005. copy: function ( euler ) {
  2006. this._x = euler._x;
  2007. this._y = euler._y;
  2008. this._z = euler._z;
  2009. this._order = euler._order;
  2010. this.onChangeCallback();
  2011. return this;
  2012. },
  2013. setFromRotationMatrix: function ( m, order, update ) {
  2014. var clamp = THREE.Math.clamp;
  2015. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2016. var te = m.elements;
  2017. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2018. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2019. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2020. order = order || this._order;
  2021. if ( order === 'XYZ' ) {
  2022. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2023. if ( Math.abs( m13 ) < 0.99999 ) {
  2024. this._x = Math.atan2( - m23, m33 );
  2025. this._z = Math.atan2( - m12, m11 );
  2026. } else {
  2027. this._x = Math.atan2( m32, m22 );
  2028. this._z = 0;
  2029. }
  2030. } else if ( order === 'YXZ' ) {
  2031. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2032. if ( Math.abs( m23 ) < 0.99999 ) {
  2033. this._y = Math.atan2( m13, m33 );
  2034. this._z = Math.atan2( m21, m22 );
  2035. } else {
  2036. this._y = Math.atan2( - m31, m11 );
  2037. this._z = 0;
  2038. }
  2039. } else if ( order === 'ZXY' ) {
  2040. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2041. if ( Math.abs( m32 ) < 0.99999 ) {
  2042. this._y = Math.atan2( - m31, m33 );
  2043. this._z = Math.atan2( - m12, m22 );
  2044. } else {
  2045. this._y = 0;
  2046. this._z = Math.atan2( m21, m11 );
  2047. }
  2048. } else if ( order === 'ZYX' ) {
  2049. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2050. if ( Math.abs( m31 ) < 0.99999 ) {
  2051. this._x = Math.atan2( m32, m33 );
  2052. this._z = Math.atan2( m21, m11 );
  2053. } else {
  2054. this._x = 0;
  2055. this._z = Math.atan2( - m12, m22 );
  2056. }
  2057. } else if ( order === 'YZX' ) {
  2058. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2059. if ( Math.abs( m21 ) < 0.99999 ) {
  2060. this._x = Math.atan2( - m23, m22 );
  2061. this._y = Math.atan2( - m31, m11 );
  2062. } else {
  2063. this._x = 0;
  2064. this._y = Math.atan2( m13, m33 );
  2065. }
  2066. } else if ( order === 'XZY' ) {
  2067. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2068. if ( Math.abs( m12 ) < 0.99999 ) {
  2069. this._x = Math.atan2( m32, m22 );
  2070. this._y = Math.atan2( m13, m11 );
  2071. } else {
  2072. this._x = Math.atan2( - m23, m33 );
  2073. this._y = 0;
  2074. }
  2075. } else {
  2076. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2077. }
  2078. this._order = order;
  2079. if ( update !== false ) this.onChangeCallback();
  2080. return this;
  2081. },
  2082. setFromQuaternion: function () {
  2083. var matrix;
  2084. return function ( q, order, update ) {
  2085. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2086. matrix.makeRotationFromQuaternion( q );
  2087. this.setFromRotationMatrix( matrix, order, update );
  2088. return this;
  2089. };
  2090. }(),
  2091. setFromVector3: function ( v, order ) {
  2092. return this.set( v.x, v.y, v.z, order || this._order );
  2093. },
  2094. reorder: function () {
  2095. // WARNING: this discards revolution information -bhouston
  2096. var q = new THREE.Quaternion();
  2097. return function ( newOrder ) {
  2098. q.setFromEuler( this );
  2099. this.setFromQuaternion( q, newOrder );
  2100. };
  2101. }(),
  2102. equals: function ( euler ) {
  2103. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2104. },
  2105. fromArray: function ( array ) {
  2106. this._x = array[ 0 ];
  2107. this._y = array[ 1 ];
  2108. this._z = array[ 2 ];
  2109. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2110. this.onChangeCallback();
  2111. return this;
  2112. },
  2113. toArray: function ( array, offset ) {
  2114. if ( array === undefined ) array = [];
  2115. if ( offset === undefined ) offset = 0;
  2116. array[ offset ] = this._x;
  2117. array[ offset + 1 ] = this._y;
  2118. array[ offset + 2 ] = this._z;
  2119. array[ offset + 3 ] = this._order;
  2120. return array;
  2121. },
  2122. toVector3: function ( optionalResult ) {
  2123. if ( optionalResult ) {
  2124. return optionalResult.set( this._x, this._y, this._z );
  2125. } else {
  2126. return new THREE.Vector3( this._x, this._y, this._z );
  2127. }
  2128. },
  2129. onChange: function ( callback ) {
  2130. this.onChangeCallback = callback;
  2131. return this;
  2132. },
  2133. onChangeCallback: function () {}
  2134. };
  2135. // File:src/math/Line3.js
  2136. /**
  2137. * @author bhouston / http://clara.io
  2138. */
  2139. THREE.Line3 = function ( start, end ) {
  2140. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2141. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2142. };
  2143. THREE.Line3.prototype = {
  2144. constructor: THREE.Line3,
  2145. set: function ( start, end ) {
  2146. this.start.copy( start );
  2147. this.end.copy( end );
  2148. return this;
  2149. },
  2150. clone: function () {
  2151. return new this.constructor().copy( this );
  2152. },
  2153. copy: function ( line ) {
  2154. this.start.copy( line.start );
  2155. this.end.copy( line.end );
  2156. return this;
  2157. },
  2158. center: function ( optionalTarget ) {
  2159. var result = optionalTarget || new THREE.Vector3();
  2160. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2161. },
  2162. delta: function ( optionalTarget ) {
  2163. var result = optionalTarget || new THREE.Vector3();
  2164. return result.subVectors( this.end, this.start );
  2165. },
  2166. distanceSq: function () {
  2167. return this.start.distanceToSquared( this.end );
  2168. },
  2169. distance: function () {
  2170. return this.start.distanceTo( this.end );
  2171. },
  2172. at: function ( t, optionalTarget ) {
  2173. var result = optionalTarget || new THREE.Vector3();
  2174. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2175. },
  2176. closestPointToPointParameter: function () {
  2177. var startP = new THREE.Vector3();
  2178. var startEnd = new THREE.Vector3();
  2179. return function ( point, clampToLine ) {
  2180. startP.subVectors( point, this.start );
  2181. startEnd.subVectors( this.end, this.start );
  2182. var startEnd2 = startEnd.dot( startEnd );
  2183. var startEnd_startP = startEnd.dot( startP );
  2184. var t = startEnd_startP / startEnd2;
  2185. if ( clampToLine ) {
  2186. t = THREE.Math.clamp( t, 0, 1 );
  2187. }
  2188. return t;
  2189. };
  2190. }(),
  2191. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2192. var t = this.closestPointToPointParameter( point, clampToLine );
  2193. var result = optionalTarget || new THREE.Vector3();
  2194. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2195. },
  2196. applyMatrix4: function ( matrix ) {
  2197. this.start.applyMatrix4( matrix );
  2198. this.end.applyMatrix4( matrix );
  2199. return this;
  2200. },
  2201. equals: function ( line ) {
  2202. return line.start.equals( this.start ) && line.end.equals( this.end );
  2203. }
  2204. };
  2205. // File:src/math/Box2.js
  2206. /**
  2207. * @author bhouston / http://clara.io
  2208. */
  2209. THREE.Box2 = function ( min, max ) {
  2210. this.min = ( min !== undefined ) ? min : new THREE.Vector2( + Infinity, + Infinity );
  2211. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2212. };
  2213. THREE.Box2.prototype = {
  2214. constructor: THREE.Box2,
  2215. set: function ( min, max ) {
  2216. this.min.copy( min );
  2217. this.max.copy( max );
  2218. return this;
  2219. },
  2220. setFromPoints: function ( points ) {
  2221. this.makeEmpty();
  2222. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2223. this.expandByPoint( points[ i ] );
  2224. }
  2225. return this;
  2226. },
  2227. setFromCenterAndSize: function () {
  2228. var v1 = new THREE.Vector2();
  2229. return function ( center, size ) {
  2230. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2231. this.min.copy( center ).sub( halfSize );
  2232. this.max.copy( center ).add( halfSize );
  2233. return this;
  2234. };
  2235. }(),
  2236. clone: function () {
  2237. return new this.constructor().copy( this );
  2238. },
  2239. copy: function ( box ) {
  2240. this.min.copy( box.min );
  2241. this.max.copy( box.max );
  2242. return this;
  2243. },
  2244. makeEmpty: function () {
  2245. this.min.x = this.min.y = + Infinity;
  2246. this.max.x = this.max.y = - Infinity;
  2247. return this;
  2248. },
  2249. isEmpty: function () {
  2250. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2251. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2252. },
  2253. center: function ( optionalTarget ) {
  2254. var result = optionalTarget || new THREE.Vector2();
  2255. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2256. },
  2257. size: function ( optionalTarget ) {
  2258. var result = optionalTarget || new THREE.Vector2();
  2259. return result.subVectors( this.max, this.min );
  2260. },
  2261. expandByPoint: function ( point ) {
  2262. this.min.min( point );
  2263. this.max.max( point );
  2264. return this;
  2265. },
  2266. expandByVector: function ( vector ) {
  2267. this.min.sub( vector );
  2268. this.max.add( vector );
  2269. return this;
  2270. },
  2271. expandByScalar: function ( scalar ) {
  2272. this.min.addScalar( - scalar );
  2273. this.max.addScalar( scalar );
  2274. return this;
  2275. },
  2276. containsPoint: function ( point ) {
  2277. if ( point.x < this.min.x || point.x > this.max.x ||
  2278. point.y < this.min.y || point.y > this.max.y ) {
  2279. return false;
  2280. }
  2281. return true;
  2282. },
  2283. containsBox: function ( box ) {
  2284. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2285. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2286. return true;
  2287. }
  2288. return false;
  2289. },
  2290. getParameter: function ( point, optionalTarget ) {
  2291. // This can potentially have a divide by zero if the box
  2292. // has a size dimension of 0.
  2293. var result = optionalTarget || new THREE.Vector2();
  2294. return result.set(
  2295. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2296. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2297. );
  2298. },
  2299. intersectsBox: function ( box ) {
  2300. // using 6 splitting planes to rule out intersections.
  2301. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2302. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2303. return false;
  2304. }
  2305. return true;
  2306. },
  2307. clampPoint: function ( point, optionalTarget ) {
  2308. var result = optionalTarget || new THREE.Vector2();
  2309. return result.copy( point ).clamp( this.min, this.max );
  2310. },
  2311. distanceToPoint: function () {
  2312. var v1 = new THREE.Vector2();
  2313. return function ( point ) {
  2314. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2315. return clampedPoint.sub( point ).length();
  2316. };
  2317. }(),
  2318. intersect: function ( box ) {
  2319. this.min.max( box.min );
  2320. this.max.min( box.max );
  2321. return this;
  2322. },
  2323. union: function ( box ) {
  2324. this.min.min( box.min );
  2325. this.max.max( box.max );
  2326. return this;
  2327. },
  2328. translate: function ( offset ) {
  2329. this.min.add( offset );
  2330. this.max.add( offset );
  2331. return this;
  2332. },
  2333. equals: function ( box ) {
  2334. return box.min.equals( this.min ) && box.max.equals( this.max );
  2335. }
  2336. };
  2337. // File:src/math/Box3.js
  2338. /**
  2339. * @author bhouston / http://clara.io
  2340. * @author WestLangley / http://github.com/WestLangley
  2341. */
  2342. THREE.Box3 = function ( min, max ) {
  2343. this.min = ( min !== undefined ) ? min : new THREE.Vector3( + Infinity, + Infinity, + Infinity );
  2344. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2345. };
  2346. THREE.Box3.prototype = {
  2347. constructor: THREE.Box3,
  2348. set: function ( min, max ) {
  2349. this.min.copy( min );
  2350. this.max.copy( max );
  2351. return this;
  2352. },
  2353. setFromArray: function ( array ) {
  2354. this.makeEmpty();
  2355. var minX = + Infinity;
  2356. var minY = + Infinity;
  2357. var minZ = + Infinity;
  2358. var maxX = - Infinity;
  2359. var maxY = - Infinity;
  2360. var maxZ = - Infinity;
  2361. for ( var i = 0, il = array.length; i < il; i += 3 ) {
  2362. var x = array[ i ];
  2363. var y = array[ i + 1 ];
  2364. var z = array[ i + 2 ];
  2365. if ( x < minX ) minX = x;
  2366. if ( y < minY ) minY = y;
  2367. if ( z < minZ ) minZ = z;
  2368. if ( x > maxX ) maxX = x;
  2369. if ( y > maxY ) maxY = y;
  2370. if ( z > maxZ ) maxZ = z;
  2371. }
  2372. this.min.set( minX, minY, minZ );
  2373. this.max.set( maxX, maxY, maxZ );
  2374. },
  2375. setFromPoints: function ( points ) {
  2376. this.makeEmpty();
  2377. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2378. this.expandByPoint( points[ i ] );
  2379. }
  2380. return this;
  2381. },
  2382. setFromCenterAndSize: function () {
  2383. var v1 = new THREE.Vector3();
  2384. return function ( center, size ) {
  2385. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2386. this.min.copy( center ).sub( halfSize );
  2387. this.max.copy( center ).add( halfSize );
  2388. return this;
  2389. };
  2390. }(),
  2391. setFromObject: function () {
  2392. // Computes the world-axis-aligned bounding box of an object (including its children),
  2393. // accounting for both the object's, and children's, world transforms
  2394. var box;
  2395. return function ( object ) {
  2396. if ( box === undefined ) box = new THREE.Box3();
  2397. var scope = this;
  2398. this.makeEmpty();
  2399. object.updateMatrixWorld( true );
  2400. object.traverse( function ( node ) {
  2401. var geometry = node.geometry;
  2402. if ( geometry !== undefined ) {
  2403. if ( geometry.boundingBox === null ) {
  2404. geometry.computeBoundingBox();
  2405. }
  2406. box.copy( geometry.boundingBox );
  2407. box.applyMatrix4( node.matrixWorld );
  2408. scope.union( box );
  2409. }
  2410. } );
  2411. return this;
  2412. };
  2413. }(),
  2414. clone: function () {
  2415. return new this.constructor().copy( this );
  2416. },
  2417. copy: function ( box ) {
  2418. this.min.copy( box.min );
  2419. this.max.copy( box.max );
  2420. return this;
  2421. },
  2422. makeEmpty: function () {
  2423. this.min.x = this.min.y = this.min.z = + Infinity;
  2424. this.max.x = this.max.y = this.max.z = - Infinity;
  2425. return this;
  2426. },
  2427. isEmpty: function () {
  2428. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2429. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2430. },
  2431. center: function ( optionalTarget ) {
  2432. var result = optionalTarget || new THREE.Vector3();
  2433. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2434. },
  2435. size: function ( optionalTarget ) {
  2436. var result = optionalTarget || new THREE.Vector3();
  2437. return result.subVectors( this.max, this.min );
  2438. },
  2439. expandByPoint: function ( point ) {
  2440. this.min.min( point );
  2441. this.max.max( point );
  2442. return this;
  2443. },
  2444. expandByVector: function ( vector ) {
  2445. this.min.sub( vector );
  2446. this.max.add( vector );
  2447. return this;
  2448. },
  2449. expandByScalar: function ( scalar ) {
  2450. this.min.addScalar( - scalar );
  2451. this.max.addScalar( scalar );
  2452. return this;
  2453. },
  2454. containsPoint: function ( point ) {
  2455. if ( point.x < this.min.x || point.x > this.max.x ||
  2456. point.y < this.min.y || point.y > this.max.y ||
  2457. point.z < this.min.z || point.z > this.max.z ) {
  2458. return false;
  2459. }
  2460. return true;
  2461. },
  2462. containsBox: function ( box ) {
  2463. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2464. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2465. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2466. return true;
  2467. }
  2468. return false;
  2469. },
  2470. getParameter: function ( point, optionalTarget ) {
  2471. // This can potentially have a divide by zero if the box
  2472. // has a size dimension of 0.
  2473. var result = optionalTarget || new THREE.Vector3();
  2474. return result.set(
  2475. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2476. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2477. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2478. );
  2479. },
  2480. intersectsBox: function ( box ) {
  2481. // using 6 splitting planes to rule out intersections.
  2482. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2483. box.max.y < this.min.y || box.min.y > this.max.y ||
  2484. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2485. return false;
  2486. }
  2487. return true;
  2488. },
  2489. intersectsSphere: ( function () {
  2490. var closestPoint;
  2491. return function intersectsSphere( sphere ) {
  2492. if ( closestPoint === undefined ) closestPoint = new THREE.Vector3();
  2493. // Find the point on the AABB closest to the sphere center.
  2494. this.clampPoint( sphere.center, closestPoint );
  2495. // If that point is inside the sphere, the AABB and sphere intersect.
  2496. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2497. };
  2498. } )(),
  2499. intersectsPlane: function ( plane ) {
  2500. // We compute the minimum and maximum dot product values. If those values
  2501. // are on the same side (back or front) of the plane, then there is no intersection.
  2502. var min, max;
  2503. if ( plane.normal.x > 0 ) {
  2504. min = plane.normal.x * this.min.x;
  2505. max = plane.normal.x * this.max.x;
  2506. } else {
  2507. min = plane.normal.x * this.max.x;
  2508. max = plane.normal.x * this.min.x;
  2509. }
  2510. if ( plane.normal.y > 0 ) {
  2511. min += plane.normal.y * this.min.y;
  2512. max += plane.normal.y * this.max.y;
  2513. } else {
  2514. min += plane.normal.y * this.max.y;
  2515. max += plane.normal.y * this.min.y;
  2516. }
  2517. if ( plane.normal.z > 0 ) {
  2518. min += plane.normal.z * this.min.z;
  2519. max += plane.normal.z * this.max.z;
  2520. } else {
  2521. min += plane.normal.z * this.max.z;
  2522. max += plane.normal.z * this.min.z;
  2523. }
  2524. return ( min <= plane.constant && max >= plane.constant );
  2525. },
  2526. clampPoint: function ( point, optionalTarget ) {
  2527. var result = optionalTarget || new THREE.Vector3();
  2528. return result.copy( point ).clamp( this.min, this.max );
  2529. },
  2530. distanceToPoint: function () {
  2531. var v1 = new THREE.Vector3();
  2532. return function ( point ) {
  2533. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2534. return clampedPoint.sub( point ).length();
  2535. };
  2536. }(),
  2537. getBoundingSphere: function () {
  2538. var v1 = new THREE.Vector3();
  2539. return function ( optionalTarget ) {
  2540. var result = optionalTarget || new THREE.Sphere();
  2541. result.center = this.center();
  2542. result.radius = this.size( v1 ).length() * 0.5;
  2543. return result;
  2544. };
  2545. }(),
  2546. intersect: function ( box ) {
  2547. this.min.max( box.min );
  2548. this.max.min( box.max );
  2549. return this;
  2550. },
  2551. union: function ( box ) {
  2552. this.min.min( box.min );
  2553. this.max.max( box.max );
  2554. return this;
  2555. },
  2556. applyMatrix4: function () {
  2557. var points = [
  2558. new THREE.Vector3(),
  2559. new THREE.Vector3(),
  2560. new THREE.Vector3(),
  2561. new THREE.Vector3(),
  2562. new THREE.Vector3(),
  2563. new THREE.Vector3(),
  2564. new THREE.Vector3(),
  2565. new THREE.Vector3()
  2566. ];
  2567. return function ( matrix ) {
  2568. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2569. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2570. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2571. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2572. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2573. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2574. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2575. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2576. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2577. this.makeEmpty();
  2578. this.setFromPoints( points );
  2579. return this;
  2580. };
  2581. }(),
  2582. translate: function ( offset ) {
  2583. this.min.add( offset );
  2584. this.max.add( offset );
  2585. return this;
  2586. },
  2587. equals: function ( box ) {
  2588. return box.min.equals( this.min ) && box.max.equals( this.max );
  2589. }
  2590. };
  2591. // File:src/math/Matrix3.js
  2592. /**
  2593. * @author alteredq / http://alteredqualia.com/
  2594. * @author WestLangley / http://github.com/WestLangley
  2595. * @author bhouston / http://clara.io
  2596. */
  2597. THREE.Matrix3 = function () {
  2598. this.elements = new Float32Array( [
  2599. 1, 0, 0,
  2600. 0, 1, 0,
  2601. 0, 0, 1
  2602. ] );
  2603. if ( arguments.length > 0 ) {
  2604. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2605. }
  2606. };
  2607. THREE.Matrix3.prototype = {
  2608. constructor: THREE.Matrix3,
  2609. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2610. var te = this.elements;
  2611. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2612. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2613. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2614. return this;
  2615. },
  2616. identity: function () {
  2617. this.set(
  2618. 1, 0, 0,
  2619. 0, 1, 0,
  2620. 0, 0, 1
  2621. );
  2622. return this;
  2623. },
  2624. clone: function () {
  2625. return new this.constructor().fromArray( this.elements );
  2626. },
  2627. copy: function ( m ) {
  2628. var me = m.elements;
  2629. this.set(
  2630. me[ 0 ], me[ 3 ], me[ 6 ],
  2631. me[ 1 ], me[ 4 ], me[ 7 ],
  2632. me[ 2 ], me[ 5 ], me[ 8 ]
  2633. );
  2634. return this;
  2635. },
  2636. applyToVector3Array: function () {
  2637. var v1;
  2638. return function ( array, offset, length ) {
  2639. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2640. if ( offset === undefined ) offset = 0;
  2641. if ( length === undefined ) length = array.length;
  2642. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2643. v1.fromArray( array, j );
  2644. v1.applyMatrix3( this );
  2645. v1.toArray( array, j );
  2646. }
  2647. return array;
  2648. };
  2649. }(),
  2650. applyToBuffer: function () {
  2651. var v1;
  2652. return function applyToBuffer( buffer, offset, length ) {
  2653. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2654. if ( offset === undefined ) offset = 0;
  2655. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2656. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2657. v1.x = buffer.getX( j );
  2658. v1.y = buffer.getY( j );
  2659. v1.z = buffer.getZ( j );
  2660. v1.applyMatrix3( this );
  2661. buffer.setXYZ( v1.x, v1.y, v1.z );
  2662. }
  2663. return buffer;
  2664. };
  2665. }(),
  2666. multiplyScalar: function ( s ) {
  2667. var te = this.elements;
  2668. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2669. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2670. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2671. return this;
  2672. },
  2673. determinant: function () {
  2674. var te = this.elements;
  2675. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2676. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2677. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2678. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2679. },
  2680. getInverse: function ( matrix, throwOnDegenerate ) {
  2681. // input: THREE.Matrix4
  2682. // ( based on http://code.google.com/p/webgl-mjs/ )
  2683. var me = matrix.elements;
  2684. var te = this.elements;
  2685. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2686. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2687. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2688. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2689. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2690. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2691. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2692. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2693. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2694. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2695. // no inverse
  2696. if ( det === 0 ) {
  2697. var msg = "THREE.Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2698. if ( throwOnDegenerate || false ) {
  2699. throw new Error( msg );
  2700. } else {
  2701. console.warn( msg );
  2702. }
  2703. this.identity();
  2704. return this;
  2705. }
  2706. this.multiplyScalar( 1.0 / det );
  2707. return this;
  2708. },
  2709. transpose: function () {
  2710. var tmp, m = this.elements;
  2711. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2712. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2713. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2714. return this;
  2715. },
  2716. flattenToArrayOffset: function ( array, offset ) {
  2717. var te = this.elements;
  2718. array[ offset ] = te[ 0 ];
  2719. array[ offset + 1 ] = te[ 1 ];
  2720. array[ offset + 2 ] = te[ 2 ];
  2721. array[ offset + 3 ] = te[ 3 ];
  2722. array[ offset + 4 ] = te[ 4 ];
  2723. array[ offset + 5 ] = te[ 5 ];
  2724. array[ offset + 6 ] = te[ 6 ];
  2725. array[ offset + 7 ] = te[ 7 ];
  2726. array[ offset + 8 ] = te[ 8 ];
  2727. return array;
  2728. },
  2729. getNormalMatrix: function ( m ) {
  2730. // input: THREE.Matrix4
  2731. this.getInverse( m ).transpose();
  2732. return this;
  2733. },
  2734. transposeIntoArray: function ( r ) {
  2735. var m = this.elements;
  2736. r[ 0 ] = m[ 0 ];
  2737. r[ 1 ] = m[ 3 ];
  2738. r[ 2 ] = m[ 6 ];
  2739. r[ 3 ] = m[ 1 ];
  2740. r[ 4 ] = m[ 4 ];
  2741. r[ 5 ] = m[ 7 ];
  2742. r[ 6 ] = m[ 2 ];
  2743. r[ 7 ] = m[ 5 ];
  2744. r[ 8 ] = m[ 8 ];
  2745. return this;
  2746. },
  2747. fromArray: function ( array ) {
  2748. this.elements.set( array );
  2749. return this;
  2750. },
  2751. toArray: function () {
  2752. var te = this.elements;
  2753. return [
  2754. te[ 0 ], te[ 1 ], te[ 2 ],
  2755. te[ 3 ], te[ 4 ], te[ 5 ],
  2756. te[ 6 ], te[ 7 ], te[ 8 ]
  2757. ];
  2758. }
  2759. };
  2760. // File:src/math/Matrix4.js
  2761. /**
  2762. * @author mrdoob / http://mrdoob.com/
  2763. * @author supereggbert / http://www.paulbrunt.co.uk/
  2764. * @author philogb / http://blog.thejit.org/
  2765. * @author jordi_ros / http://plattsoft.com
  2766. * @author D1plo1d / http://github.com/D1plo1d
  2767. * @author alteredq / http://alteredqualia.com/
  2768. * @author mikael emtinger / http://gomo.se/
  2769. * @author timknip / http://www.floorplanner.com/
  2770. * @author bhouston / http://clara.io
  2771. * @author WestLangley / http://github.com/WestLangley
  2772. */
  2773. THREE.Matrix4 = function () {
  2774. this.elements = new Float32Array( [
  2775. 1, 0, 0, 0,
  2776. 0, 1, 0, 0,
  2777. 0, 0, 1, 0,
  2778. 0, 0, 0, 1
  2779. ] );
  2780. if ( arguments.length > 0 ) {
  2781. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2782. }
  2783. };
  2784. THREE.Matrix4.prototype = {
  2785. constructor: THREE.Matrix4,
  2786. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2787. var te = this.elements;
  2788. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2789. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2790. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2791. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2792. return this;
  2793. },
  2794. identity: function () {
  2795. this.set(
  2796. 1, 0, 0, 0,
  2797. 0, 1, 0, 0,
  2798. 0, 0, 1, 0,
  2799. 0, 0, 0, 1
  2800. );
  2801. return this;
  2802. },
  2803. clone: function () {
  2804. return new THREE.Matrix4().fromArray( this.elements );
  2805. },
  2806. copy: function ( m ) {
  2807. this.elements.set( m.elements );
  2808. return this;
  2809. },
  2810. copyPosition: function ( m ) {
  2811. var te = this.elements;
  2812. var me = m.elements;
  2813. te[ 12 ] = me[ 12 ];
  2814. te[ 13 ] = me[ 13 ];
  2815. te[ 14 ] = me[ 14 ];
  2816. return this;
  2817. },
  2818. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2819. var te = this.elements;
  2820. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2821. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2822. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2823. return this;
  2824. },
  2825. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2826. this.set(
  2827. xAxis.x, yAxis.x, zAxis.x, 0,
  2828. xAxis.y, yAxis.y, zAxis.y, 0,
  2829. xAxis.z, yAxis.z, zAxis.z, 0,
  2830. 0, 0, 0, 1
  2831. );
  2832. return this;
  2833. },
  2834. extractRotation: function () {
  2835. var v1;
  2836. return function ( m ) {
  2837. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2838. var te = this.elements;
  2839. var me = m.elements;
  2840. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2841. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2842. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2843. te[ 0 ] = me[ 0 ] * scaleX;
  2844. te[ 1 ] = me[ 1 ] * scaleX;
  2845. te[ 2 ] = me[ 2 ] * scaleX;
  2846. te[ 4 ] = me[ 4 ] * scaleY;
  2847. te[ 5 ] = me[ 5 ] * scaleY;
  2848. te[ 6 ] = me[ 6 ] * scaleY;
  2849. te[ 8 ] = me[ 8 ] * scaleZ;
  2850. te[ 9 ] = me[ 9 ] * scaleZ;
  2851. te[ 10 ] = me[ 10 ] * scaleZ;
  2852. return this;
  2853. };
  2854. }(),
  2855. makeRotationFromEuler: function ( euler ) {
  2856. if ( euler instanceof THREE.Euler === false ) {
  2857. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2858. }
  2859. var te = this.elements;
  2860. var x = euler.x, y = euler.y, z = euler.z;
  2861. var a = Math.cos( x ), b = Math.sin( x );
  2862. var c = Math.cos( y ), d = Math.sin( y );
  2863. var e = Math.cos( z ), f = Math.sin( z );
  2864. if ( euler.order === 'XYZ' ) {
  2865. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2866. te[ 0 ] = c * e;
  2867. te[ 4 ] = - c * f;
  2868. te[ 8 ] = d;
  2869. te[ 1 ] = af + be * d;
  2870. te[ 5 ] = ae - bf * d;
  2871. te[ 9 ] = - b * c;
  2872. te[ 2 ] = bf - ae * d;
  2873. te[ 6 ] = be + af * d;
  2874. te[ 10 ] = a * c;
  2875. } else if ( euler.order === 'YXZ' ) {
  2876. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2877. te[ 0 ] = ce + df * b;
  2878. te[ 4 ] = de * b - cf;
  2879. te[ 8 ] = a * d;
  2880. te[ 1 ] = a * f;
  2881. te[ 5 ] = a * e;
  2882. te[ 9 ] = - b;
  2883. te[ 2 ] = cf * b - de;
  2884. te[ 6 ] = df + ce * b;
  2885. te[ 10 ] = a * c;
  2886. } else if ( euler.order === 'ZXY' ) {
  2887. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2888. te[ 0 ] = ce - df * b;
  2889. te[ 4 ] = - a * f;
  2890. te[ 8 ] = de + cf * b;
  2891. te[ 1 ] = cf + de * b;
  2892. te[ 5 ] = a * e;
  2893. te[ 9 ] = df - ce * b;
  2894. te[ 2 ] = - a * d;
  2895. te[ 6 ] = b;
  2896. te[ 10 ] = a * c;
  2897. } else if ( euler.order === 'ZYX' ) {
  2898. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2899. te[ 0 ] = c * e;
  2900. te[ 4 ] = be * d - af;
  2901. te[ 8 ] = ae * d + bf;
  2902. te[ 1 ] = c * f;
  2903. te[ 5 ] = bf * d + ae;
  2904. te[ 9 ] = af * d - be;
  2905. te[ 2 ] = - d;
  2906. te[ 6 ] = b * c;
  2907. te[ 10 ] = a * c;
  2908. } else if ( euler.order === 'YZX' ) {
  2909. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2910. te[ 0 ] = c * e;
  2911. te[ 4 ] = bd - ac * f;
  2912. te[ 8 ] = bc * f + ad;
  2913. te[ 1 ] = f;
  2914. te[ 5 ] = a * e;
  2915. te[ 9 ] = - b * e;
  2916. te[ 2 ] = - d * e;
  2917. te[ 6 ] = ad * f + bc;
  2918. te[ 10 ] = ac - bd * f;
  2919. } else if ( euler.order === 'XZY' ) {
  2920. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2921. te[ 0 ] = c * e;
  2922. te[ 4 ] = - f;
  2923. te[ 8 ] = d * e;
  2924. te[ 1 ] = ac * f + bd;
  2925. te[ 5 ] = a * e;
  2926. te[ 9 ] = ad * f - bc;
  2927. te[ 2 ] = bc * f - ad;
  2928. te[ 6 ] = b * e;
  2929. te[ 10 ] = bd * f + ac;
  2930. }
  2931. // last column
  2932. te[ 3 ] = 0;
  2933. te[ 7 ] = 0;
  2934. te[ 11 ] = 0;
  2935. // bottom row
  2936. te[ 12 ] = 0;
  2937. te[ 13 ] = 0;
  2938. te[ 14 ] = 0;
  2939. te[ 15 ] = 1;
  2940. return this;
  2941. },
  2942. makeRotationFromQuaternion: function ( q ) {
  2943. var te = this.elements;
  2944. var x = q.x, y = q.y, z = q.z, w = q.w;
  2945. var x2 = x + x, y2 = y + y, z2 = z + z;
  2946. var xx = x * x2, xy = x * y2, xz = x * z2;
  2947. var yy = y * y2, yz = y * z2, zz = z * z2;
  2948. var wx = w * x2, wy = w * y2, wz = w * z2;
  2949. te[ 0 ] = 1 - ( yy + zz );
  2950. te[ 4 ] = xy - wz;
  2951. te[ 8 ] = xz + wy;
  2952. te[ 1 ] = xy + wz;
  2953. te[ 5 ] = 1 - ( xx + zz );
  2954. te[ 9 ] = yz - wx;
  2955. te[ 2 ] = xz - wy;
  2956. te[ 6 ] = yz + wx;
  2957. te[ 10 ] = 1 - ( xx + yy );
  2958. // last column
  2959. te[ 3 ] = 0;
  2960. te[ 7 ] = 0;
  2961. te[ 11 ] = 0;
  2962. // bottom row
  2963. te[ 12 ] = 0;
  2964. te[ 13 ] = 0;
  2965. te[ 14 ] = 0;
  2966. te[ 15 ] = 1;
  2967. return this;
  2968. },
  2969. lookAt: function () {
  2970. var x, y, z;
  2971. return function ( eye, target, up ) {
  2972. if ( x === undefined ) x = new THREE.Vector3();
  2973. if ( y === undefined ) y = new THREE.Vector3();
  2974. if ( z === undefined ) z = new THREE.Vector3();
  2975. var te = this.elements;
  2976. z.subVectors( eye, target ).normalize();
  2977. if ( z.lengthSq() === 0 ) {
  2978. z.z = 1;
  2979. }
  2980. x.crossVectors( up, z ).normalize();
  2981. if ( x.lengthSq() === 0 ) {
  2982. z.x += 0.0001;
  2983. x.crossVectors( up, z ).normalize();
  2984. }
  2985. y.crossVectors( z, x );
  2986. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2987. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2988. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2989. return this;
  2990. };
  2991. }(),
  2992. multiply: function ( m, n ) {
  2993. if ( n !== undefined ) {
  2994. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2995. return this.multiplyMatrices( m, n );
  2996. }
  2997. return this.multiplyMatrices( this, m );
  2998. },
  2999. multiplyMatrices: function ( a, b ) {
  3000. var ae = a.elements;
  3001. var be = b.elements;
  3002. var te = this.elements;
  3003. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3004. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3005. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3006. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3007. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3008. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3009. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3010. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3011. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3012. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3013. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3014. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3015. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3016. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3017. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3018. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3019. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3020. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3021. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3022. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3023. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3024. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3025. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3026. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3027. return this;
  3028. },
  3029. multiplyToArray: function ( a, b, r ) {
  3030. var te = this.elements;
  3031. this.multiplyMatrices( a, b );
  3032. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3033. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3034. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3035. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3036. return this;
  3037. },
  3038. multiplyScalar: function ( s ) {
  3039. var te = this.elements;
  3040. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3041. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3042. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3043. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3044. return this;
  3045. },
  3046. applyToVector3Array: function () {
  3047. var v1;
  3048. return function ( array, offset, length ) {
  3049. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3050. if ( offset === undefined ) offset = 0;
  3051. if ( length === undefined ) length = array.length;
  3052. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3053. v1.fromArray( array, j );
  3054. v1.applyMatrix4( this );
  3055. v1.toArray( array, j );
  3056. }
  3057. return array;
  3058. };
  3059. }(),
  3060. applyToBuffer: function () {
  3061. var v1;
  3062. return function applyToBuffer( buffer, offset, length ) {
  3063. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3064. if ( offset === undefined ) offset = 0;
  3065. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3066. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3067. v1.x = buffer.getX( j );
  3068. v1.y = buffer.getY( j );
  3069. v1.z = buffer.getZ( j );
  3070. v1.applyMatrix4( this );
  3071. buffer.setXYZ( v1.x, v1.y, v1.z );
  3072. }
  3073. return buffer;
  3074. };
  3075. }(),
  3076. determinant: function () {
  3077. var te = this.elements;
  3078. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3079. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3080. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3081. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3082. //TODO: make this more efficient
  3083. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3084. return (
  3085. n41 * (
  3086. + n14 * n23 * n32
  3087. - n13 * n24 * n32
  3088. - n14 * n22 * n33
  3089. + n12 * n24 * n33
  3090. + n13 * n22 * n34
  3091. - n12 * n23 * n34
  3092. ) +
  3093. n42 * (
  3094. + n11 * n23 * n34
  3095. - n11 * n24 * n33
  3096. + n14 * n21 * n33
  3097. - n13 * n21 * n34
  3098. + n13 * n24 * n31
  3099. - n14 * n23 * n31
  3100. ) +
  3101. n43 * (
  3102. + n11 * n24 * n32
  3103. - n11 * n22 * n34
  3104. - n14 * n21 * n32
  3105. + n12 * n21 * n34
  3106. + n14 * n22 * n31
  3107. - n12 * n24 * n31
  3108. ) +
  3109. n44 * (
  3110. - n13 * n22 * n31
  3111. - n11 * n23 * n32
  3112. + n11 * n22 * n33
  3113. + n13 * n21 * n32
  3114. - n12 * n21 * n33
  3115. + n12 * n23 * n31
  3116. )
  3117. );
  3118. },
  3119. transpose: function () {
  3120. var te = this.elements;
  3121. var tmp;
  3122. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3123. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3124. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3125. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3126. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3127. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3128. return this;
  3129. },
  3130. flattenToArrayOffset: function ( array, offset ) {
  3131. var te = this.elements;
  3132. array[ offset ] = te[ 0 ];
  3133. array[ offset + 1 ] = te[ 1 ];
  3134. array[ offset + 2 ] = te[ 2 ];
  3135. array[ offset + 3 ] = te[ 3 ];
  3136. array[ offset + 4 ] = te[ 4 ];
  3137. array[ offset + 5 ] = te[ 5 ];
  3138. array[ offset + 6 ] = te[ 6 ];
  3139. array[ offset + 7 ] = te[ 7 ];
  3140. array[ offset + 8 ] = te[ 8 ];
  3141. array[ offset + 9 ] = te[ 9 ];
  3142. array[ offset + 10 ] = te[ 10 ];
  3143. array[ offset + 11 ] = te[ 11 ];
  3144. array[ offset + 12 ] = te[ 12 ];
  3145. array[ offset + 13 ] = te[ 13 ];
  3146. array[ offset + 14 ] = te[ 14 ];
  3147. array[ offset + 15 ] = te[ 15 ];
  3148. return array;
  3149. },
  3150. getPosition: function () {
  3151. var v1;
  3152. return function () {
  3153. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3154. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3155. var te = this.elements;
  3156. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3157. };
  3158. }(),
  3159. setPosition: function ( v ) {
  3160. var te = this.elements;
  3161. te[ 12 ] = v.x;
  3162. te[ 13 ] = v.y;
  3163. te[ 14 ] = v.z;
  3164. return this;
  3165. },
  3166. getInverse: function ( m, throwOnInvertible ) {
  3167. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3168. var te = this.elements;
  3169. var me = m.elements;
  3170. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3171. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3172. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3173. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3174. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3175. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3176. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3177. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3178. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3179. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3180. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3181. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3182. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3183. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3184. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3185. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3186. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3187. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3188. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3189. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3190. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3191. if ( det === 0 ) {
  3192. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3193. if ( throwOnInvertible || false ) {
  3194. throw new Error( msg );
  3195. } else {
  3196. console.warn( msg );
  3197. }
  3198. this.identity();
  3199. return this;
  3200. }
  3201. this.multiplyScalar( 1 / det );
  3202. return this;
  3203. },
  3204. scale: function ( v ) {
  3205. var te = this.elements;
  3206. var x = v.x, y = v.y, z = v.z;
  3207. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3208. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3209. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3210. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3211. return this;
  3212. },
  3213. getMaxScaleOnAxis: function () {
  3214. var te = this.elements;
  3215. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3216. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3217. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3218. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3219. },
  3220. makeTranslation: function ( x, y, z ) {
  3221. this.set(
  3222. 1, 0, 0, x,
  3223. 0, 1, 0, y,
  3224. 0, 0, 1, z,
  3225. 0, 0, 0, 1
  3226. );
  3227. return this;
  3228. },
  3229. makeRotationX: function ( theta ) {
  3230. var c = Math.cos( theta ), s = Math.sin( theta );
  3231. this.set(
  3232. 1, 0, 0, 0,
  3233. 0, c, - s, 0,
  3234. 0, s, c, 0,
  3235. 0, 0, 0, 1
  3236. );
  3237. return this;
  3238. },
  3239. makeRotationY: function ( theta ) {
  3240. var c = Math.cos( theta ), s = Math.sin( theta );
  3241. this.set(
  3242. c, 0, s, 0,
  3243. 0, 1, 0, 0,
  3244. - s, 0, c, 0,
  3245. 0, 0, 0, 1
  3246. );
  3247. return this;
  3248. },
  3249. makeRotationZ: function ( theta ) {
  3250. var c = Math.cos( theta ), s = Math.sin( theta );
  3251. this.set(
  3252. c, - s, 0, 0,
  3253. s, c, 0, 0,
  3254. 0, 0, 1, 0,
  3255. 0, 0, 0, 1
  3256. );
  3257. return this;
  3258. },
  3259. makeRotationAxis: function ( axis, angle ) {
  3260. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3261. var c = Math.cos( angle );
  3262. var s = Math.sin( angle );
  3263. var t = 1 - c;
  3264. var x = axis.x, y = axis.y, z = axis.z;
  3265. var tx = t * x, ty = t * y;
  3266. this.set(
  3267. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3268. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3269. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3270. 0, 0, 0, 1
  3271. );
  3272. return this;
  3273. },
  3274. makeScale: function ( x, y, z ) {
  3275. this.set(
  3276. x, 0, 0, 0,
  3277. 0, y, 0, 0,
  3278. 0, 0, z, 0,
  3279. 0, 0, 0, 1
  3280. );
  3281. return this;
  3282. },
  3283. compose: function ( position, quaternion, scale ) {
  3284. this.makeRotationFromQuaternion( quaternion );
  3285. this.scale( scale );
  3286. this.setPosition( position );
  3287. return this;
  3288. },
  3289. decompose: function () {
  3290. var vector, matrix;
  3291. return function ( position, quaternion, scale ) {
  3292. if ( vector === undefined ) vector = new THREE.Vector3();
  3293. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3294. var te = this.elements;
  3295. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3296. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3297. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3298. // if determine is negative, we need to invert one scale
  3299. var det = this.determinant();
  3300. if ( det < 0 ) {
  3301. sx = - sx;
  3302. }
  3303. position.x = te[ 12 ];
  3304. position.y = te[ 13 ];
  3305. position.z = te[ 14 ];
  3306. // scale the rotation part
  3307. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3308. var invSX = 1 / sx;
  3309. var invSY = 1 / sy;
  3310. var invSZ = 1 / sz;
  3311. matrix.elements[ 0 ] *= invSX;
  3312. matrix.elements[ 1 ] *= invSX;
  3313. matrix.elements[ 2 ] *= invSX;
  3314. matrix.elements[ 4 ] *= invSY;
  3315. matrix.elements[ 5 ] *= invSY;
  3316. matrix.elements[ 6 ] *= invSY;
  3317. matrix.elements[ 8 ] *= invSZ;
  3318. matrix.elements[ 9 ] *= invSZ;
  3319. matrix.elements[ 10 ] *= invSZ;
  3320. quaternion.setFromRotationMatrix( matrix );
  3321. scale.x = sx;
  3322. scale.y = sy;
  3323. scale.z = sz;
  3324. return this;
  3325. };
  3326. }(),
  3327. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3328. var te = this.elements;
  3329. var x = 2 * near / ( right - left );
  3330. var y = 2 * near / ( top - bottom );
  3331. var a = ( right + left ) / ( right - left );
  3332. var b = ( top + bottom ) / ( top - bottom );
  3333. var c = - ( far + near ) / ( far - near );
  3334. var d = - 2 * far * near / ( far - near );
  3335. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3336. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3337. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3338. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3339. return this;
  3340. },
  3341. makePerspective: function ( fov, aspect, near, far ) {
  3342. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3343. var ymin = - ymax;
  3344. var xmin = ymin * aspect;
  3345. var xmax = ymax * aspect;
  3346. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3347. },
  3348. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3349. var te = this.elements;
  3350. var w = right - left;
  3351. var h = top - bottom;
  3352. var p = far - near;
  3353. var x = ( right + left ) / w;
  3354. var y = ( top + bottom ) / h;
  3355. var z = ( far + near ) / p;
  3356. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3357. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3358. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3359. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3360. return this;
  3361. },
  3362. equals: function ( matrix ) {
  3363. var te = this.elements;
  3364. var me = matrix.elements;
  3365. for ( var i = 0; i < 16; i ++ ) {
  3366. if ( te[ i ] !== me[ i ] ) return false;
  3367. }
  3368. return true;
  3369. },
  3370. fromArray: function ( array ) {
  3371. this.elements.set( array );
  3372. return this;
  3373. },
  3374. toArray: function () {
  3375. var te = this.elements;
  3376. return [
  3377. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3378. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3379. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3380. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3381. ];
  3382. }
  3383. };
  3384. // File:src/math/Ray.js
  3385. /**
  3386. * @author bhouston / http://clara.io
  3387. */
  3388. THREE.Ray = function ( origin, direction ) {
  3389. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3390. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3391. };
  3392. THREE.Ray.prototype = {
  3393. constructor: THREE.Ray,
  3394. set: function ( origin, direction ) {
  3395. this.origin.copy( origin );
  3396. this.direction.copy( direction );
  3397. return this;
  3398. },
  3399. clone: function () {
  3400. return new this.constructor().copy( this );
  3401. },
  3402. copy: function ( ray ) {
  3403. this.origin.copy( ray.origin );
  3404. this.direction.copy( ray.direction );
  3405. return this;
  3406. },
  3407. at: function ( t, optionalTarget ) {
  3408. var result = optionalTarget || new THREE.Vector3();
  3409. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3410. },
  3411. lookAt: function ( v ) {
  3412. this.direction.copy( v ).sub( this.origin ).normalize();
  3413. },
  3414. recast: function () {
  3415. var v1 = new THREE.Vector3();
  3416. return function ( t ) {
  3417. this.origin.copy( this.at( t, v1 ) );
  3418. return this;
  3419. };
  3420. }(),
  3421. closestPointToPoint: function ( point, optionalTarget ) {
  3422. var result = optionalTarget || new THREE.Vector3();
  3423. result.subVectors( point, this.origin );
  3424. var directionDistance = result.dot( this.direction );
  3425. if ( directionDistance < 0 ) {
  3426. return result.copy( this.origin );
  3427. }
  3428. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3429. },
  3430. distanceToPoint: function ( point ) {
  3431. return Math.sqrt( this.distanceSqToPoint( point ) );
  3432. },
  3433. distanceSqToPoint: function () {
  3434. var v1 = new THREE.Vector3();
  3435. return function ( point ) {
  3436. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3437. // point behind the ray
  3438. if ( directionDistance < 0 ) {
  3439. return this.origin.distanceToSquared( point );
  3440. }
  3441. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3442. return v1.distanceToSquared( point );
  3443. };
  3444. }(),
  3445. distanceSqToSegment: function () {
  3446. var segCenter = new THREE.Vector3();
  3447. var segDir = new THREE.Vector3();
  3448. var diff = new THREE.Vector3();
  3449. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3450. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3451. // It returns the min distance between the ray and the segment
  3452. // defined by v0 and v1
  3453. // It can also set two optional targets :
  3454. // - The closest point on the ray
  3455. // - The closest point on the segment
  3456. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3457. segDir.copy( v1 ).sub( v0 ).normalize();
  3458. diff.copy( this.origin ).sub( segCenter );
  3459. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3460. var a01 = - this.direction.dot( segDir );
  3461. var b0 = diff.dot( this.direction );
  3462. var b1 = - diff.dot( segDir );
  3463. var c = diff.lengthSq();
  3464. var det = Math.abs( 1 - a01 * a01 );
  3465. var s0, s1, sqrDist, extDet;
  3466. if ( det > 0 ) {
  3467. // The ray and segment are not parallel.
  3468. s0 = a01 * b1 - b0;
  3469. s1 = a01 * b0 - b1;
  3470. extDet = segExtent * det;
  3471. if ( s0 >= 0 ) {
  3472. if ( s1 >= - extDet ) {
  3473. if ( s1 <= extDet ) {
  3474. // region 0
  3475. // Minimum at interior points of ray and segment.
  3476. var invDet = 1 / det;
  3477. s0 *= invDet;
  3478. s1 *= invDet;
  3479. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3480. } else {
  3481. // region 1
  3482. s1 = segExtent;
  3483. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3484. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3485. }
  3486. } else {
  3487. // region 5
  3488. s1 = - segExtent;
  3489. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3490. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3491. }
  3492. } else {
  3493. if ( s1 <= - extDet ) {
  3494. // region 4
  3495. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3496. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3497. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3498. } else if ( s1 <= extDet ) {
  3499. // region 3
  3500. s0 = 0;
  3501. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3502. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3503. } else {
  3504. // region 2
  3505. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3506. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3507. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3508. }
  3509. }
  3510. } else {
  3511. // Ray and segment are parallel.
  3512. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3513. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3514. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3515. }
  3516. if ( optionalPointOnRay ) {
  3517. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3518. }
  3519. if ( optionalPointOnSegment ) {
  3520. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3521. }
  3522. return sqrDist;
  3523. };
  3524. }(),
  3525. intersectSphere: function () {
  3526. var v1 = new THREE.Vector3();
  3527. return function ( sphere, optionalTarget ) {
  3528. v1.subVectors( sphere.center, this.origin );
  3529. var tca = v1.dot( this.direction );
  3530. var d2 = v1.dot( v1 ) - tca * tca;
  3531. var radius2 = sphere.radius * sphere.radius;
  3532. if ( d2 > radius2 ) return null;
  3533. var thc = Math.sqrt( radius2 - d2 );
  3534. // t0 = first intersect point - entrance on front of sphere
  3535. var t0 = tca - thc;
  3536. // t1 = second intersect point - exit point on back of sphere
  3537. var t1 = tca + thc;
  3538. // test to see if both t0 and t1 are behind the ray - if so, return null
  3539. if ( t0 < 0 && t1 < 0 ) return null;
  3540. // test to see if t0 is behind the ray:
  3541. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3542. // in order to always return an intersect point that is in front of the ray.
  3543. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3544. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3545. return this.at( t0, optionalTarget );
  3546. }
  3547. }(),
  3548. intersectsSphere: function ( sphere ) {
  3549. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3550. },
  3551. distanceToPlane: function ( plane ) {
  3552. var denominator = plane.normal.dot( this.direction );
  3553. if ( denominator === 0 ) {
  3554. // line is coplanar, return origin
  3555. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3556. return 0;
  3557. }
  3558. // Null is preferable to undefined since undefined means.... it is undefined
  3559. return null;
  3560. }
  3561. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3562. // Return if the ray never intersects the plane
  3563. return t >= 0 ? t : null;
  3564. },
  3565. intersectPlane: function ( plane, optionalTarget ) {
  3566. var t = this.distanceToPlane( plane );
  3567. if ( t === null ) {
  3568. return null;
  3569. }
  3570. return this.at( t, optionalTarget );
  3571. },
  3572. intersectsPlane: function ( plane ) {
  3573. // check if the ray lies on the plane first
  3574. var distToPoint = plane.distanceToPoint( this.origin );
  3575. if ( distToPoint === 0 ) {
  3576. return true;
  3577. }
  3578. var denominator = plane.normal.dot( this.direction );
  3579. if ( denominator * distToPoint < 0 ) {
  3580. return true;
  3581. }
  3582. // ray origin is behind the plane (and is pointing behind it)
  3583. return false;
  3584. },
  3585. intersectBox: function ( box, optionalTarget ) {
  3586. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3587. var invdirx = 1 / this.direction.x,
  3588. invdiry = 1 / this.direction.y,
  3589. invdirz = 1 / this.direction.z;
  3590. var origin = this.origin;
  3591. if ( invdirx >= 0 ) {
  3592. tmin = ( box.min.x - origin.x ) * invdirx;
  3593. tmax = ( box.max.x - origin.x ) * invdirx;
  3594. } else {
  3595. tmin = ( box.max.x - origin.x ) * invdirx;
  3596. tmax = ( box.min.x - origin.x ) * invdirx;
  3597. }
  3598. if ( invdiry >= 0 ) {
  3599. tymin = ( box.min.y - origin.y ) * invdiry;
  3600. tymax = ( box.max.y - origin.y ) * invdiry;
  3601. } else {
  3602. tymin = ( box.max.y - origin.y ) * invdiry;
  3603. tymax = ( box.min.y - origin.y ) * invdiry;
  3604. }
  3605. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3606. // These lines also handle the case where tmin or tmax is NaN
  3607. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3608. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3609. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3610. if ( invdirz >= 0 ) {
  3611. tzmin = ( box.min.z - origin.z ) * invdirz;
  3612. tzmax = ( box.max.z - origin.z ) * invdirz;
  3613. } else {
  3614. tzmin = ( box.max.z - origin.z ) * invdirz;
  3615. tzmax = ( box.min.z - origin.z ) * invdirz;
  3616. }
  3617. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3618. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3619. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3620. //return point closest to the ray (positive side)
  3621. if ( tmax < 0 ) return null;
  3622. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3623. },
  3624. intersectsBox: ( function () {
  3625. var v = new THREE.Vector3();
  3626. return function ( box ) {
  3627. return this.intersectBox( box, v ) !== null;
  3628. };
  3629. } )(),
  3630. intersectTriangle: function () {
  3631. // Compute the offset origin, edges, and normal.
  3632. var diff = new THREE.Vector3();
  3633. var edge1 = new THREE.Vector3();
  3634. var edge2 = new THREE.Vector3();
  3635. var normal = new THREE.Vector3();
  3636. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3637. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3638. edge1.subVectors( b, a );
  3639. edge2.subVectors( c, a );
  3640. normal.crossVectors( edge1, edge2 );
  3641. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3642. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3643. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3644. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3645. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3646. var DdN = this.direction.dot( normal );
  3647. var sign;
  3648. if ( DdN > 0 ) {
  3649. if ( backfaceCulling ) return null;
  3650. sign = 1;
  3651. } else if ( DdN < 0 ) {
  3652. sign = - 1;
  3653. DdN = - DdN;
  3654. } else {
  3655. return null;
  3656. }
  3657. diff.subVectors( this.origin, a );
  3658. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3659. // b1 < 0, no intersection
  3660. if ( DdQxE2 < 0 ) {
  3661. return null;
  3662. }
  3663. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3664. // b2 < 0, no intersection
  3665. if ( DdE1xQ < 0 ) {
  3666. return null;
  3667. }
  3668. // b1+b2 > 1, no intersection
  3669. if ( DdQxE2 + DdE1xQ > DdN ) {
  3670. return null;
  3671. }
  3672. // Line intersects triangle, check if ray does.
  3673. var QdN = - sign * diff.dot( normal );
  3674. // t < 0, no intersection
  3675. if ( QdN < 0 ) {
  3676. return null;
  3677. }
  3678. // Ray intersects triangle.
  3679. return this.at( QdN / DdN, optionalTarget );
  3680. };
  3681. }(),
  3682. applyMatrix4: function ( matrix4 ) {
  3683. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3684. this.origin.applyMatrix4( matrix4 );
  3685. this.direction.sub( this.origin );
  3686. this.direction.normalize();
  3687. return this;
  3688. },
  3689. equals: function ( ray ) {
  3690. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3691. }
  3692. };
  3693. // File:src/math/Sphere.js
  3694. /**
  3695. * @author bhouston / http://clara.io
  3696. * @author mrdoob / http://mrdoob.com/
  3697. */
  3698. THREE.Sphere = function ( center, radius ) {
  3699. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3700. this.radius = ( radius !== undefined ) ? radius : 0;
  3701. };
  3702. THREE.Sphere.prototype = {
  3703. constructor: THREE.Sphere,
  3704. set: function ( center, radius ) {
  3705. this.center.copy( center );
  3706. this.radius = radius;
  3707. return this;
  3708. },
  3709. setFromPoints: function () {
  3710. var box = new THREE.Box3();
  3711. return function ( points, optionalCenter ) {
  3712. var center = this.center;
  3713. if ( optionalCenter !== undefined ) {
  3714. center.copy( optionalCenter );
  3715. } else {
  3716. box.setFromPoints( points ).center( center );
  3717. }
  3718. var maxRadiusSq = 0;
  3719. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3720. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3721. }
  3722. this.radius = Math.sqrt( maxRadiusSq );
  3723. return this;
  3724. };
  3725. }(),
  3726. clone: function () {
  3727. return new this.constructor().copy( this );
  3728. },
  3729. copy: function ( sphere ) {
  3730. this.center.copy( sphere.center );
  3731. this.radius = sphere.radius;
  3732. return this;
  3733. },
  3734. empty: function () {
  3735. return ( this.radius <= 0 );
  3736. },
  3737. containsPoint: function ( point ) {
  3738. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3739. },
  3740. distanceToPoint: function ( point ) {
  3741. return ( point.distanceTo( this.center ) - this.radius );
  3742. },
  3743. intersectsSphere: function ( sphere ) {
  3744. var radiusSum = this.radius + sphere.radius;
  3745. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3746. },
  3747. intersectsBox: function ( box ) {
  3748. return box.intersectsSphere( this );
  3749. },
  3750. intersectsPlane: function ( plane ) {
  3751. // We use the following equation to compute the signed distance from
  3752. // the center of the sphere to the plane.
  3753. //
  3754. // distance = q * n - d
  3755. //
  3756. // If this distance is greater than the radius of the sphere,
  3757. // then there is no intersection.
  3758. return Math.abs( this.center.dot( plane.normal ) - plane.constant ) <= this.radius;
  3759. },
  3760. clampPoint: function ( point, optionalTarget ) {
  3761. var deltaLengthSq = this.center.distanceToSquared( point );
  3762. var result = optionalTarget || new THREE.Vector3();
  3763. result.copy( point );
  3764. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3765. result.sub( this.center ).normalize();
  3766. result.multiplyScalar( this.radius ).add( this.center );
  3767. }
  3768. return result;
  3769. },
  3770. getBoundingBox: function ( optionalTarget ) {
  3771. var box = optionalTarget || new THREE.Box3();
  3772. box.set( this.center, this.center );
  3773. box.expandByScalar( this.radius );
  3774. return box;
  3775. },
  3776. applyMatrix4: function ( matrix ) {
  3777. this.center.applyMatrix4( matrix );
  3778. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3779. return this;
  3780. },
  3781. translate: function ( offset ) {
  3782. this.center.add( offset );
  3783. return this;
  3784. },
  3785. equals: function ( sphere ) {
  3786. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3787. }
  3788. };
  3789. // File:src/math/Frustum.js
  3790. /**
  3791. * @author mrdoob / http://mrdoob.com/
  3792. * @author alteredq / http://alteredqualia.com/
  3793. * @author bhouston / http://clara.io
  3794. */
  3795. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3796. this.planes = [
  3797. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3798. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3799. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3800. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3801. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3802. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3803. ];
  3804. };
  3805. THREE.Frustum.prototype = {
  3806. constructor: THREE.Frustum,
  3807. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3808. var planes = this.planes;
  3809. planes[ 0 ].copy( p0 );
  3810. planes[ 1 ].copy( p1 );
  3811. planes[ 2 ].copy( p2 );
  3812. planes[ 3 ].copy( p3 );
  3813. planes[ 4 ].copy( p4 );
  3814. planes[ 5 ].copy( p5 );
  3815. return this;
  3816. },
  3817. clone: function () {
  3818. return new this.constructor().copy( this );
  3819. },
  3820. copy: function ( frustum ) {
  3821. var planes = this.planes;
  3822. for ( var i = 0; i < 6; i ++ ) {
  3823. planes[ i ].copy( frustum.planes[ i ] );
  3824. }
  3825. return this;
  3826. },
  3827. setFromMatrix: function ( m ) {
  3828. var planes = this.planes;
  3829. var me = m.elements;
  3830. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3831. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3832. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3833. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3834. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3835. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3836. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3837. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3838. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3839. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3840. return this;
  3841. },
  3842. intersectsObject: function () {
  3843. var sphere = new THREE.Sphere();
  3844. return function ( object ) {
  3845. var geometry = object.geometry;
  3846. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3847. sphere.copy( geometry.boundingSphere );
  3848. sphere.applyMatrix4( object.matrixWorld );
  3849. return this.intersectsSphere( sphere );
  3850. };
  3851. }(),
  3852. intersectsSphere: function ( sphere ) {
  3853. var planes = this.planes;
  3854. var center = sphere.center;
  3855. var negRadius = - sphere.radius;
  3856. for ( var i = 0; i < 6; i ++ ) {
  3857. var distance = planes[ i ].distanceToPoint( center );
  3858. if ( distance < negRadius ) {
  3859. return false;
  3860. }
  3861. }
  3862. return true;
  3863. },
  3864. intersectsBox: function () {
  3865. var p1 = new THREE.Vector3(),
  3866. p2 = new THREE.Vector3();
  3867. return function ( box ) {
  3868. var planes = this.planes;
  3869. for ( var i = 0; i < 6 ; i ++ ) {
  3870. var plane = planes[ i ];
  3871. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3872. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3873. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3874. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3875. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3876. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3877. var d1 = plane.distanceToPoint( p1 );
  3878. var d2 = plane.distanceToPoint( p2 );
  3879. // if both outside plane, no intersection
  3880. if ( d1 < 0 && d2 < 0 ) {
  3881. return false;
  3882. }
  3883. }
  3884. return true;
  3885. };
  3886. }(),
  3887. containsPoint: function ( point ) {
  3888. var planes = this.planes;
  3889. for ( var i = 0; i < 6; i ++ ) {
  3890. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3891. return false;
  3892. }
  3893. }
  3894. return true;
  3895. }
  3896. };
  3897. // File:src/math/Plane.js
  3898. /**
  3899. * @author bhouston / http://clara.io
  3900. */
  3901. THREE.Plane = function ( normal, constant ) {
  3902. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3903. this.constant = ( constant !== undefined ) ? constant : 0;
  3904. };
  3905. THREE.Plane.prototype = {
  3906. constructor: THREE.Plane,
  3907. set: function ( normal, constant ) {
  3908. this.normal.copy( normal );
  3909. this.constant = constant;
  3910. return this;
  3911. },
  3912. setComponents: function ( x, y, z, w ) {
  3913. this.normal.set( x, y, z );
  3914. this.constant = w;
  3915. return this;
  3916. },
  3917. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3918. this.normal.copy( normal );
  3919. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3920. return this;
  3921. },
  3922. setFromCoplanarPoints: function () {
  3923. var v1 = new THREE.Vector3();
  3924. var v2 = new THREE.Vector3();
  3925. return function ( a, b, c ) {
  3926. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3927. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3928. this.setFromNormalAndCoplanarPoint( normal, a );
  3929. return this;
  3930. };
  3931. }(),
  3932. clone: function () {
  3933. return new this.constructor().copy( this );
  3934. },
  3935. copy: function ( plane ) {
  3936. this.normal.copy( plane.normal );
  3937. this.constant = plane.constant;
  3938. return this;
  3939. },
  3940. normalize: function () {
  3941. // Note: will lead to a divide by zero if the plane is invalid.
  3942. var inverseNormalLength = 1.0 / this.normal.length();
  3943. this.normal.multiplyScalar( inverseNormalLength );
  3944. this.constant *= inverseNormalLength;
  3945. return this;
  3946. },
  3947. negate: function () {
  3948. this.constant *= - 1;
  3949. this.normal.negate();
  3950. return this;
  3951. },
  3952. distanceToPoint: function ( point ) {
  3953. return this.normal.dot( point ) + this.constant;
  3954. },
  3955. distanceToSphere: function ( sphere ) {
  3956. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3957. },
  3958. projectPoint: function ( point, optionalTarget ) {
  3959. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3960. },
  3961. orthoPoint: function ( point, optionalTarget ) {
  3962. var perpendicularMagnitude = this.distanceToPoint( point );
  3963. var result = optionalTarget || new THREE.Vector3();
  3964. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3965. },
  3966. intersectLine: function () {
  3967. var v1 = new THREE.Vector3();
  3968. return function ( line, optionalTarget ) {
  3969. var result = optionalTarget || new THREE.Vector3();
  3970. var direction = line.delta( v1 );
  3971. var denominator = this.normal.dot( direction );
  3972. if ( denominator === 0 ) {
  3973. // line is coplanar, return origin
  3974. if ( this.distanceToPoint( line.start ) === 0 ) {
  3975. return result.copy( line.start );
  3976. }
  3977. // Unsure if this is the correct method to handle this case.
  3978. return undefined;
  3979. }
  3980. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3981. if ( t < 0 || t > 1 ) {
  3982. return undefined;
  3983. }
  3984. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  3985. };
  3986. }(),
  3987. intersectsLine: function ( line ) {
  3988. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3989. var startSign = this.distanceToPoint( line.start );
  3990. var endSign = this.distanceToPoint( line.end );
  3991. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3992. },
  3993. intersectsBox: function ( box ) {
  3994. return box.intersectsPlane( this );
  3995. },
  3996. intersectsSphere: function ( sphere ) {
  3997. return sphere.intersectsPlane( this );
  3998. },
  3999. coplanarPoint: function ( optionalTarget ) {
  4000. var result = optionalTarget || new THREE.Vector3();
  4001. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4002. },
  4003. applyMatrix4: function () {
  4004. var v1 = new THREE.Vector3();
  4005. var v2 = new THREE.Vector3();
  4006. var m1 = new THREE.Matrix3();
  4007. return function ( matrix, optionalNormalMatrix ) {
  4008. // compute new normal based on theory here:
  4009. // http://www.songho.ca/opengl/gl_normaltransform.html
  4010. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4011. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  4012. var newCoplanarPoint = this.coplanarPoint( v2 );
  4013. newCoplanarPoint.applyMatrix4( matrix );
  4014. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  4015. return this;
  4016. };
  4017. }(),
  4018. translate: function ( offset ) {
  4019. this.constant = this.constant - offset.dot( this.normal );
  4020. return this;
  4021. },
  4022. equals: function ( plane ) {
  4023. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4024. }
  4025. };
  4026. // File:src/math/Math.js
  4027. /**
  4028. * @author alteredq / http://alteredqualia.com/
  4029. * @author mrdoob / http://mrdoob.com/
  4030. */
  4031. THREE.Math = {
  4032. generateUUID: function () {
  4033. // http://www.broofa.com/Tools/Math.uuid.htm
  4034. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4035. var uuid = new Array( 36 );
  4036. var rnd = 0, r;
  4037. return function () {
  4038. for ( var i = 0; i < 36; i ++ ) {
  4039. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4040. uuid[ i ] = '-';
  4041. } else if ( i === 14 ) {
  4042. uuid[ i ] = '4';
  4043. } else {
  4044. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4045. r = rnd & 0xf;
  4046. rnd = rnd >> 4;
  4047. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4048. }
  4049. }
  4050. return uuid.join( '' );
  4051. };
  4052. }(),
  4053. clamp: function ( value, min, max ) {
  4054. return Math.max( min, Math.min( max, value ) );
  4055. },
  4056. // compute euclidian modulo of m % n
  4057. // https://en.wikipedia.org/wiki/Modulo_operation
  4058. euclideanModulo: function ( n, m ) {
  4059. return ( ( n % m ) + m ) % m;
  4060. },
  4061. // Linear mapping from range <a1, a2> to range <b1, b2>
  4062. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4063. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4064. },
  4065. // http://en.wikipedia.org/wiki/Smoothstep
  4066. smoothstep: function ( x, min, max ) {
  4067. if ( x <= min ) return 0;
  4068. if ( x >= max ) return 1;
  4069. x = ( x - min ) / ( max - min );
  4070. return x * x * ( 3 - 2 * x );
  4071. },
  4072. smootherstep: function ( x, min, max ) {
  4073. if ( x <= min ) return 0;
  4074. if ( x >= max ) return 1;
  4075. x = ( x - min ) / ( max - min );
  4076. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4077. },
  4078. random16: function () {
  4079. console.warn( 'THREE.Math.random16() has been deprecated. Use Math.random() instead.' );
  4080. return Math.random();
  4081. },
  4082. // Random integer from <low, high> interval
  4083. randInt: function ( low, high ) {
  4084. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4085. },
  4086. // Random float from <low, high> interval
  4087. randFloat: function ( low, high ) {
  4088. return low + Math.random() * ( high - low );
  4089. },
  4090. // Random float from <-range/2, range/2> interval
  4091. randFloatSpread: function ( range ) {
  4092. return range * ( 0.5 - Math.random() );
  4093. },
  4094. degToRad: function () {
  4095. var degreeToRadiansFactor = Math.PI / 180;
  4096. return function ( degrees ) {
  4097. return degrees * degreeToRadiansFactor;
  4098. };
  4099. }(),
  4100. radToDeg: function () {
  4101. var radianToDegreesFactor = 180 / Math.PI;
  4102. return function ( radians ) {
  4103. return radians * radianToDegreesFactor;
  4104. };
  4105. }(),
  4106. isPowerOfTwo: function ( value ) {
  4107. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4108. },
  4109. nearestPowerOfTwo: function ( value ) {
  4110. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  4111. },
  4112. nextPowerOfTwo: function ( value ) {
  4113. value --;
  4114. value |= value >> 1;
  4115. value |= value >> 2;
  4116. value |= value >> 4;
  4117. value |= value >> 8;
  4118. value |= value >> 16;
  4119. value ++;
  4120. return value;
  4121. }
  4122. };
  4123. // File:src/math/Spline.js
  4124. /**
  4125. * Spline from Tween.js, slightly optimized (and trashed)
  4126. * http://sole.github.com/tween.js/examples/05_spline.html
  4127. *
  4128. * @author mrdoob / http://mrdoob.com/
  4129. * @author alteredq / http://alteredqualia.com/
  4130. */
  4131. THREE.Spline = function ( points ) {
  4132. this.points = points;
  4133. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4134. point, intPoint, weight, w2, w3,
  4135. pa, pb, pc, pd;
  4136. this.initFromArray = function ( a ) {
  4137. this.points = [];
  4138. for ( var i = 0; i < a.length; i ++ ) {
  4139. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4140. }
  4141. };
  4142. this.getPoint = function ( k ) {
  4143. point = ( this.points.length - 1 ) * k;
  4144. intPoint = Math.floor( point );
  4145. weight = point - intPoint;
  4146. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4147. c[ 1 ] = intPoint;
  4148. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4149. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4150. pa = this.points[ c[ 0 ] ];
  4151. pb = this.points[ c[ 1 ] ];
  4152. pc = this.points[ c[ 2 ] ];
  4153. pd = this.points[ c[ 3 ] ];
  4154. w2 = weight * weight;
  4155. w3 = weight * w2;
  4156. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4157. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4158. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4159. return v3;
  4160. };
  4161. this.getControlPointsArray = function () {
  4162. var i, p, l = this.points.length,
  4163. coords = [];
  4164. for ( i = 0; i < l; i ++ ) {
  4165. p = this.points[ i ];
  4166. coords[ i ] = [ p.x, p.y, p.z ];
  4167. }
  4168. return coords;
  4169. };
  4170. // approximate length by summing linear segments
  4171. this.getLength = function ( nSubDivisions ) {
  4172. var i, index, nSamples, position,
  4173. point = 0, intPoint = 0, oldIntPoint = 0,
  4174. oldPosition = new THREE.Vector3(),
  4175. tmpVec = new THREE.Vector3(),
  4176. chunkLengths = [],
  4177. totalLength = 0;
  4178. // first point has 0 length
  4179. chunkLengths[ 0 ] = 0;
  4180. if ( ! nSubDivisions ) nSubDivisions = 100;
  4181. nSamples = this.points.length * nSubDivisions;
  4182. oldPosition.copy( this.points[ 0 ] );
  4183. for ( i = 1; i < nSamples; i ++ ) {
  4184. index = i / nSamples;
  4185. position = this.getPoint( index );
  4186. tmpVec.copy( position );
  4187. totalLength += tmpVec.distanceTo( oldPosition );
  4188. oldPosition.copy( position );
  4189. point = ( this.points.length - 1 ) * index;
  4190. intPoint = Math.floor( point );
  4191. if ( intPoint !== oldIntPoint ) {
  4192. chunkLengths[ intPoint ] = totalLength;
  4193. oldIntPoint = intPoint;
  4194. }
  4195. }
  4196. // last point ends with total length
  4197. chunkLengths[ chunkLengths.length ] = totalLength;
  4198. return { chunks: chunkLengths, total: totalLength };
  4199. };
  4200. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4201. var i, j,
  4202. index, indexCurrent, indexNext,
  4203. realDistance,
  4204. sampling, position,
  4205. newpoints = [],
  4206. tmpVec = new THREE.Vector3(),
  4207. sl = this.getLength();
  4208. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4209. for ( i = 1; i < this.points.length; i ++ ) {
  4210. //tmpVec.copy( this.points[ i - 1 ] );
  4211. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4212. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4213. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4214. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4215. indexNext = i / ( this.points.length - 1 );
  4216. for ( j = 1; j < sampling - 1; j ++ ) {
  4217. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4218. position = this.getPoint( index );
  4219. newpoints.push( tmpVec.copy( position ).clone() );
  4220. }
  4221. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4222. }
  4223. this.points = newpoints;
  4224. };
  4225. // Catmull-Rom
  4226. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4227. var v0 = ( p2 - p0 ) * 0.5,
  4228. v1 = ( p3 - p1 ) * 0.5;
  4229. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4230. }
  4231. };
  4232. // File:src/math/Triangle.js
  4233. /**
  4234. * @author bhouston / http://clara.io
  4235. * @author mrdoob / http://mrdoob.com/
  4236. */
  4237. THREE.Triangle = function ( a, b, c ) {
  4238. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4239. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4240. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4241. };
  4242. THREE.Triangle.normal = function () {
  4243. var v0 = new THREE.Vector3();
  4244. return function ( a, b, c, optionalTarget ) {
  4245. var result = optionalTarget || new THREE.Vector3();
  4246. result.subVectors( c, b );
  4247. v0.subVectors( a, b );
  4248. result.cross( v0 );
  4249. var resultLengthSq = result.lengthSq();
  4250. if ( resultLengthSq > 0 ) {
  4251. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4252. }
  4253. return result.set( 0, 0, 0 );
  4254. };
  4255. }();
  4256. // static/instance method to calculate barycentric coordinates
  4257. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4258. THREE.Triangle.barycoordFromPoint = function () {
  4259. var v0 = new THREE.Vector3();
  4260. var v1 = new THREE.Vector3();
  4261. var v2 = new THREE.Vector3();
  4262. return function ( point, a, b, c, optionalTarget ) {
  4263. v0.subVectors( c, a );
  4264. v1.subVectors( b, a );
  4265. v2.subVectors( point, a );
  4266. var dot00 = v0.dot( v0 );
  4267. var dot01 = v0.dot( v1 );
  4268. var dot02 = v0.dot( v2 );
  4269. var dot11 = v1.dot( v1 );
  4270. var dot12 = v1.dot( v2 );
  4271. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4272. var result = optionalTarget || new THREE.Vector3();
  4273. // collinear or singular triangle
  4274. if ( denom === 0 ) {
  4275. // arbitrary location outside of triangle?
  4276. // not sure if this is the best idea, maybe should be returning undefined
  4277. return result.set( - 2, - 1, - 1 );
  4278. }
  4279. var invDenom = 1 / denom;
  4280. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4281. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4282. // barycentric coordinates must always sum to 1
  4283. return result.set( 1 - u - v, v, u );
  4284. };
  4285. }();
  4286. THREE.Triangle.containsPoint = function () {
  4287. var v1 = new THREE.Vector3();
  4288. return function ( point, a, b, c ) {
  4289. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4290. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4291. };
  4292. }();
  4293. THREE.Triangle.prototype = {
  4294. constructor: THREE.Triangle,
  4295. set: function ( a, b, c ) {
  4296. this.a.copy( a );
  4297. this.b.copy( b );
  4298. this.c.copy( c );
  4299. return this;
  4300. },
  4301. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4302. this.a.copy( points[ i0 ] );
  4303. this.b.copy( points[ i1 ] );
  4304. this.c.copy( points[ i2 ] );
  4305. return this;
  4306. },
  4307. clone: function () {
  4308. return new this.constructor().copy( this );
  4309. },
  4310. copy: function ( triangle ) {
  4311. this.a.copy( triangle.a );
  4312. this.b.copy( triangle.b );
  4313. this.c.copy( triangle.c );
  4314. return this;
  4315. },
  4316. area: function () {
  4317. var v0 = new THREE.Vector3();
  4318. var v1 = new THREE.Vector3();
  4319. return function () {
  4320. v0.subVectors( this.c, this.b );
  4321. v1.subVectors( this.a, this.b );
  4322. return v0.cross( v1 ).length() * 0.5;
  4323. };
  4324. }(),
  4325. midpoint: function ( optionalTarget ) {
  4326. var result = optionalTarget || new THREE.Vector3();
  4327. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4328. },
  4329. normal: function ( optionalTarget ) {
  4330. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4331. },
  4332. plane: function ( optionalTarget ) {
  4333. var result = optionalTarget || new THREE.Plane();
  4334. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4335. },
  4336. barycoordFromPoint: function ( point, optionalTarget ) {
  4337. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4338. },
  4339. containsPoint: function ( point ) {
  4340. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4341. },
  4342. equals: function ( triangle ) {
  4343. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4344. }
  4345. };
  4346. // File:src/math/Interpolant.js
  4347. /**
  4348. * Abstract base class of interpolants over parametric samples.
  4349. *
  4350. * The parameter domain is one dimensional, typically the time or a path
  4351. * along a curve defined by the data.
  4352. *
  4353. * The sample values can have any dimensionality and derived classes may
  4354. * apply special interpretations to the data.
  4355. *
  4356. * This class provides the interval seek in a Template Method, deferring
  4357. * the actual interpolation to derived classes.
  4358. *
  4359. * Time complexity is O(1) for linear access crossing at most two points
  4360. * and O(log N) for random access, where N is the number of positions.
  4361. *
  4362. * References:
  4363. *
  4364. * http://www.oodesign.com/template-method-pattern.html
  4365. *
  4366. * @author tschw
  4367. */
  4368. THREE.Interpolant = function(
  4369. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4370. this.parameterPositions = parameterPositions;
  4371. this._cachedIndex = 0;
  4372. this.resultBuffer = resultBuffer !== undefined ?
  4373. resultBuffer : new sampleValues.constructor( sampleSize );
  4374. this.sampleValues = sampleValues;
  4375. this.valueSize = sampleSize;
  4376. };
  4377. THREE.Interpolant.prototype = {
  4378. constructor: THREE.Interpolant,
  4379. evaluate: function( t ) {
  4380. var pp = this.parameterPositions,
  4381. i1 = this._cachedIndex,
  4382. t1 = pp[ i1 ],
  4383. t0 = pp[ i1 - 1 ];
  4384. validate_interval: {
  4385. seek: {
  4386. var right;
  4387. linear_scan: {
  4388. //- See http://jsperf.com/comparison-to-undefined/3
  4389. //- slower code:
  4390. //-
  4391. //- if ( t >= t1 || t1 === undefined ) {
  4392. forward_scan: if ( ! ( t < t1 ) ) {
  4393. for ( var giveUpAt = i1 + 2; ;) {
  4394. if ( t1 === undefined ) {
  4395. if ( t < t0 ) break forward_scan;
  4396. // after end
  4397. i1 = pp.length;
  4398. this._cachedIndex = i1;
  4399. return this.afterEnd_( i1 - 1, t, t0 );
  4400. }
  4401. if ( i1 === giveUpAt ) break; // this loop
  4402. t0 = t1;
  4403. t1 = pp[ ++ i1 ];
  4404. if ( t < t1 ) {
  4405. // we have arrived at the sought interval
  4406. break seek;
  4407. }
  4408. }
  4409. // prepare binary search on the right side of the index
  4410. right = pp.length;
  4411. break linear_scan;
  4412. }
  4413. //- slower code:
  4414. //- if ( t < t0 || t0 === undefined ) {
  4415. if ( ! ( t >= t0 ) ) {
  4416. // looping?
  4417. var t1global = pp[ 1 ];
  4418. if ( t < t1global ) {
  4419. i1 = 2; // + 1, using the scan for the details
  4420. t0 = t1global;
  4421. }
  4422. // linear reverse scan
  4423. for ( var giveUpAt = i1 - 2; ;) {
  4424. if ( t0 === undefined ) {
  4425. // before start
  4426. this._cachedIndex = 0;
  4427. return this.beforeStart_( 0, t, t1 );
  4428. }
  4429. if ( i1 === giveUpAt ) break; // this loop
  4430. t1 = t0;
  4431. t0 = pp[ -- i1 - 1 ];
  4432. if ( t >= t0 ) {
  4433. // we have arrived at the sought interval
  4434. break seek;
  4435. }
  4436. }
  4437. // prepare binary search on the left side of the index
  4438. right = i1;
  4439. i1 = 0;
  4440. break linear_scan;
  4441. }
  4442. // the interval is valid
  4443. break validate_interval;
  4444. } // linear scan
  4445. // binary search
  4446. while ( i1 < right ) {
  4447. var mid = ( i1 + right ) >>> 1;
  4448. if ( t < pp[ mid ] ) {
  4449. right = mid;
  4450. } else {
  4451. i1 = mid + 1;
  4452. }
  4453. }
  4454. t1 = pp[ i1 ];
  4455. t0 = pp[ i1 - 1 ];
  4456. // check boundary cases, again
  4457. if ( t0 === undefined ) {
  4458. this._cachedIndex = 0;
  4459. return this.beforeStart_( 0, t, t1 );
  4460. }
  4461. if ( t1 === undefined ) {
  4462. i1 = pp.length;
  4463. this._cachedIndex = i1;
  4464. return this.afterEnd_( i1 - 1, t0, t );
  4465. }
  4466. } // seek
  4467. this._cachedIndex = i1;
  4468. this.intervalChanged_( i1, t0, t1 );
  4469. } // validate_interval
  4470. return this.interpolate_( i1, t0, t, t1 );
  4471. },
  4472. settings: null, // optional, subclass-specific settings structure
  4473. // Note: The indirection allows central control of many interpolants.
  4474. // --- Protected interface
  4475. DefaultSettings_: {},
  4476. getSettings_: function() {
  4477. return this.settings || this.DefaultSettings_;
  4478. },
  4479. copySampleValue_: function( index ) {
  4480. // copies a sample value to the result buffer
  4481. var result = this.resultBuffer,
  4482. values = this.sampleValues,
  4483. stride = this.valueSize,
  4484. offset = index * stride;
  4485. for ( var i = 0; i !== stride; ++ i ) {
  4486. result[ i ] = values[ offset + i ];
  4487. }
  4488. return result;
  4489. },
  4490. // Template methods for derived classes:
  4491. interpolate_: function( i1, t0, t, t1 ) {
  4492. throw new Error( "call to abstract method" );
  4493. // implementations shall return this.resultBuffer
  4494. },
  4495. intervalChanged_: function( i1, t0, t1 ) {
  4496. // empty
  4497. }
  4498. };
  4499. Object.assign( THREE.Interpolant.prototype, {
  4500. beforeStart_: //( 0, t, t0 ), returns this.resultBuffer
  4501. THREE.Interpolant.prototype.copySampleValue_,
  4502. afterEnd_: //( N-1, tN-1, t ), returns this.resultBuffer
  4503. THREE.Interpolant.prototype.copySampleValue_
  4504. } );
  4505. // File:src/math/interpolants/CubicInterpolant.js
  4506. /**
  4507. * Fast and simple cubic spline interpolant.
  4508. *
  4509. * It was derived from a Hermitian construction setting the first derivative
  4510. * at each sample position to the linear slope between neighboring positions
  4511. * over their parameter interval.
  4512. *
  4513. * @author tschw
  4514. */
  4515. THREE.CubicInterpolant = function(
  4516. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4517. THREE.Interpolant.call(
  4518. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4519. this._weightPrev = -0;
  4520. this._offsetPrev = -0;
  4521. this._weightNext = -0;
  4522. this._offsetNext = -0;
  4523. };
  4524. THREE.CubicInterpolant.prototype =
  4525. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4526. constructor: THREE.CubicInterpolant,
  4527. DefaultSettings_: {
  4528. endingStart: THREE.ZeroCurvatureEnding,
  4529. endingEnd: THREE.ZeroCurvatureEnding
  4530. },
  4531. intervalChanged_: function( i1, t0, t1 ) {
  4532. var pp = this.parameterPositions,
  4533. iPrev = i1 - 2,
  4534. iNext = i1 + 1,
  4535. tPrev = pp[ iPrev ],
  4536. tNext = pp[ iNext ];
  4537. if ( tPrev === undefined ) {
  4538. switch ( this.getSettings_().endingStart ) {
  4539. case THREE.ZeroSlopeEnding:
  4540. // f'(t0) = 0
  4541. iPrev = i1;
  4542. tPrev = 2 * t0 - t1;
  4543. break;
  4544. case THREE.WrapAroundEnding:
  4545. // use the other end of the curve
  4546. iPrev = pp.length - 2;
  4547. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  4548. break;
  4549. default: // ZeroCurvatureEnding
  4550. // f''(t0) = 0 a.k.a. Natural Spline
  4551. iPrev = i1;
  4552. tPrev = t1;
  4553. }
  4554. }
  4555. if ( tNext === undefined ) {
  4556. switch ( this.getSettings_().endingEnd ) {
  4557. case THREE.ZeroSlopeEnding:
  4558. // f'(tN) = 0
  4559. iNext = i1;
  4560. tNext = 2 * t1 - t0;
  4561. break;
  4562. case THREE.WrapAroundEnding:
  4563. // use the other end of the curve
  4564. iNext = 1;
  4565. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  4566. break;
  4567. default: // ZeroCurvatureEnding
  4568. // f''(tN) = 0, a.k.a. Natural Spline
  4569. iNext = i1 - 1;
  4570. tNext = t0;
  4571. }
  4572. }
  4573. var halfDt = ( t1 - t0 ) * 0.5,
  4574. stride = this.valueSize;
  4575. this._weightPrev = halfDt / ( t0 - tPrev );
  4576. this._weightNext = halfDt / ( tNext - t1 );
  4577. this._offsetPrev = iPrev * stride;
  4578. this._offsetNext = iNext * stride;
  4579. },
  4580. interpolate_: function( i1, t0, t, t1 ) {
  4581. var result = this.resultBuffer,
  4582. values = this.sampleValues,
  4583. stride = this.valueSize,
  4584. o1 = i1 * stride, o0 = o1 - stride,
  4585. oP = this._offsetPrev, oN = this._offsetNext,
  4586. wP = this._weightPrev, wN = this._weightNext,
  4587. p = ( t - t0 ) / ( t1 - t0 ),
  4588. pp = p * p,
  4589. ppp = pp * p;
  4590. // evaluate polynomials
  4591. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  4592. var s0 = ( 1 + wP ) * ppp + (-1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  4593. var s1 = (-1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  4594. var sN = wN * ppp - wN * pp;
  4595. // combine data linearly
  4596. for ( var i = 0; i !== stride; ++ i ) {
  4597. result[ i ] =
  4598. sP * values[ oP + i ] +
  4599. s0 * values[ o0 + i ] +
  4600. s1 * values[ o1 + i ] +
  4601. sN * values[ oN + i ];
  4602. }
  4603. return result;
  4604. }
  4605. } );
  4606. // File:src/math/interpolants/DiscreteInterpolant.js
  4607. /**
  4608. *
  4609. * Interpolant that evaluates to the sample value at the position preceeding
  4610. * the parameter.
  4611. *
  4612. * @author tschw
  4613. */
  4614. THREE.DiscreteInterpolant = function(
  4615. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4616. THREE.Interpolant.call(
  4617. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4618. };
  4619. THREE.DiscreteInterpolant.prototype =
  4620. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4621. constructor: THREE.DiscreteInterpolant,
  4622. interpolate_: function( i1, t0, t, t1 ) {
  4623. return this.copySampleValue_( i1 - 1 );
  4624. }
  4625. } );
  4626. // File:src/math/interpolants/LinearInterpolant.js
  4627. /**
  4628. * @author tschw
  4629. */
  4630. THREE.LinearInterpolant = function(
  4631. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4632. THREE.Interpolant.call(
  4633. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4634. };
  4635. THREE.LinearInterpolant.prototype =
  4636. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4637. constructor: THREE.LinearInterpolant,
  4638. interpolate_: function( i1, t0, t, t1 ) {
  4639. var result = this.resultBuffer,
  4640. values = this.sampleValues,
  4641. stride = this.valueSize,
  4642. offset1 = i1 * stride,
  4643. offset0 = offset1 - stride,
  4644. weight1 = ( t - t0 ) / ( t1 - t0 ),
  4645. weight0 = 1 - weight1;
  4646. for ( var i = 0; i !== stride; ++ i ) {
  4647. result[ i ] =
  4648. values[ offset0 + i ] * weight0 +
  4649. values[ offset1 + i ] * weight1;
  4650. }
  4651. return result;
  4652. }
  4653. } );
  4654. // File:src/math/interpolants/QuaternionLinearInterpolant.js
  4655. /**
  4656. * Spherical linear unit quaternion interpolant.
  4657. *
  4658. * @author tschw
  4659. */
  4660. THREE.QuaternionLinearInterpolant = function(
  4661. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4662. THREE.Interpolant.call(
  4663. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4664. };
  4665. THREE.QuaternionLinearInterpolant.prototype =
  4666. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4667. constructor: THREE.QuaternionLinearInterpolant,
  4668. interpolate_: function( i1, t0, t, t1 ) {
  4669. var result = this.resultBuffer,
  4670. values = this.sampleValues,
  4671. stride = this.valueSize,
  4672. offset = i1 * stride,
  4673. alpha = ( t - t0 ) / ( t1 - t0 );
  4674. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  4675. THREE.Quaternion.slerpFlat( result, 0,
  4676. values, offset - stride, values, offset, alpha );
  4677. }
  4678. return result;
  4679. }
  4680. } );
  4681. // File:src/core/Clock.js
  4682. /**
  4683. * @author alteredq / http://alteredqualia.com/
  4684. */
  4685. THREE.Clock = function ( autoStart ) {
  4686. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4687. this.startTime = 0;
  4688. this.oldTime = 0;
  4689. this.elapsedTime = 0;
  4690. this.running = false;
  4691. };
  4692. THREE.Clock.prototype = {
  4693. constructor: THREE.Clock,
  4694. start: function () {
  4695. this.startTime = performance.now();
  4696. this.oldTime = this.startTime;
  4697. this.running = true;
  4698. },
  4699. stop: function () {
  4700. this.getElapsedTime();
  4701. this.running = false;
  4702. },
  4703. getElapsedTime: function () {
  4704. this.getDelta();
  4705. return this.elapsedTime;
  4706. },
  4707. getDelta: function () {
  4708. var diff = 0;
  4709. if ( this.autoStart && ! this.running ) {
  4710. this.start();
  4711. }
  4712. if ( this.running ) {
  4713. var newTime = performance.now();
  4714. diff = 0.001 * ( newTime - this.oldTime );
  4715. this.oldTime = newTime;
  4716. this.elapsedTime += diff;
  4717. }
  4718. return diff;
  4719. }
  4720. };
  4721. // File:src/core/EventDispatcher.js
  4722. /**
  4723. * https://github.com/mrdoob/eventdispatcher.js/
  4724. */
  4725. THREE.EventDispatcher = function () {};
  4726. THREE.EventDispatcher.prototype = {
  4727. constructor: THREE.EventDispatcher,
  4728. apply: function ( object ) {
  4729. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4730. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4731. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4732. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4733. },
  4734. addEventListener: function ( type, listener ) {
  4735. if ( this._listeners === undefined ) this._listeners = {};
  4736. var listeners = this._listeners;
  4737. if ( listeners[ type ] === undefined ) {
  4738. listeners[ type ] = [];
  4739. }
  4740. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4741. listeners[ type ].push( listener );
  4742. }
  4743. },
  4744. hasEventListener: function ( type, listener ) {
  4745. if ( this._listeners === undefined ) return false;
  4746. var listeners = this._listeners;
  4747. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4748. return true;
  4749. }
  4750. return false;
  4751. },
  4752. removeEventListener: function ( type, listener ) {
  4753. if ( this._listeners === undefined ) return;
  4754. var listeners = this._listeners;
  4755. var listenerArray = listeners[ type ];
  4756. if ( listenerArray !== undefined ) {
  4757. var index = listenerArray.indexOf( listener );
  4758. if ( index !== - 1 ) {
  4759. listenerArray.splice( index, 1 );
  4760. }
  4761. }
  4762. },
  4763. dispatchEvent: function ( event ) {
  4764. if ( this._listeners === undefined ) return;
  4765. var listeners = this._listeners;
  4766. var listenerArray = listeners[ event.type ];
  4767. if ( listenerArray !== undefined ) {
  4768. event.target = this;
  4769. var array = [];
  4770. var length = listenerArray.length;
  4771. for ( var i = 0; i < length; i ++ ) {
  4772. array[ i ] = listenerArray[ i ];
  4773. }
  4774. for ( var i = 0; i < length; i ++ ) {
  4775. array[ i ].call( this, event );
  4776. }
  4777. }
  4778. }
  4779. };
  4780. // File:src/core/Layers.js
  4781. /**
  4782. * @author mrdoob / http://mrdoob.com/
  4783. */
  4784. THREE.Layers = function () {
  4785. this.mask = 1;
  4786. };
  4787. THREE.Layers.prototype = {
  4788. constructor: THREE.Layers,
  4789. set: function ( channel ) {
  4790. this.mask = 1 << channel;
  4791. },
  4792. enable: function ( channel ) {
  4793. this.mask |= 1 << channel;
  4794. },
  4795. toggle: function ( channel ) {
  4796. this.mask ^= 1 << channel;
  4797. },
  4798. disable: function ( channel ) {
  4799. this.mask &= ~ ( 1 << channel );
  4800. },
  4801. test: function ( layers ) {
  4802. return ( this.mask & layers.mask ) !== 0;
  4803. }
  4804. };
  4805. // File:src/core/Raycaster.js
  4806. /**
  4807. * @author mrdoob / http://mrdoob.com/
  4808. * @author bhouston / http://clara.io/
  4809. * @author stephomi / http://stephaneginier.com/
  4810. */
  4811. ( function ( THREE ) {
  4812. THREE.Raycaster = function ( origin, direction, near, far ) {
  4813. this.ray = new THREE.Ray( origin, direction );
  4814. // direction is assumed to be normalized (for accurate distance calculations)
  4815. this.near = near || 0;
  4816. this.far = far || Infinity;
  4817. this.params = {
  4818. Mesh: {},
  4819. Line: {},
  4820. LOD: {},
  4821. Points: { threshold: 1 },
  4822. Sprite: {}
  4823. };
  4824. Object.defineProperties( this.params, {
  4825. PointCloud: {
  4826. get: function () {
  4827. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4828. return this.Points;
  4829. }
  4830. }
  4831. } );
  4832. };
  4833. function ascSort( a, b ) {
  4834. return a.distance - b.distance;
  4835. }
  4836. function intersectObject( object, raycaster, intersects, recursive ) {
  4837. if ( object.visible === false ) return;
  4838. object.raycast( raycaster, intersects );
  4839. if ( recursive === true ) {
  4840. var children = object.children;
  4841. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4842. intersectObject( children[ i ], raycaster, intersects, true );
  4843. }
  4844. }
  4845. }
  4846. //
  4847. THREE.Raycaster.prototype = {
  4848. constructor: THREE.Raycaster,
  4849. linePrecision: 1,
  4850. set: function ( origin, direction ) {
  4851. // direction is assumed to be normalized (for accurate distance calculations)
  4852. this.ray.set( origin, direction );
  4853. },
  4854. setFromCamera: function ( coords, camera ) {
  4855. if ( camera instanceof THREE.PerspectiveCamera ) {
  4856. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4857. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4858. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4859. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4860. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4861. } else {
  4862. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4863. }
  4864. },
  4865. intersectObject: function ( object, recursive ) {
  4866. var intersects = [];
  4867. intersectObject( object, this, intersects, recursive );
  4868. intersects.sort( ascSort );
  4869. return intersects;
  4870. },
  4871. intersectObjects: function ( objects, recursive ) {
  4872. var intersects = [];
  4873. if ( Array.isArray( objects ) === false ) {
  4874. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4875. return intersects;
  4876. }
  4877. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4878. intersectObject( objects[ i ], this, intersects, recursive );
  4879. }
  4880. intersects.sort( ascSort );
  4881. return intersects;
  4882. }
  4883. };
  4884. }( THREE ) );
  4885. // File:src/core/Object3D.js
  4886. /**
  4887. * @author mrdoob / http://mrdoob.com/
  4888. * @author mikael emtinger / http://gomo.se/
  4889. * @author alteredq / http://alteredqualia.com/
  4890. * @author WestLangley / http://github.com/WestLangley
  4891. * @author elephantatwork / www.elephantatwork.ch
  4892. */
  4893. THREE.Object3D = function () {
  4894. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4895. this.uuid = THREE.Math.generateUUID();
  4896. this.name = '';
  4897. this.type = 'Object3D';
  4898. this.parent = null;
  4899. this.children = [];
  4900. this.up = THREE.Object3D.DefaultUp.clone();
  4901. var position = new THREE.Vector3();
  4902. var rotation = new THREE.Euler();
  4903. var quaternion = new THREE.Quaternion();
  4904. var scale = new THREE.Vector3( 1, 1, 1 );
  4905. function onRotationChange() {
  4906. quaternion.setFromEuler( rotation, false );
  4907. }
  4908. function onQuaternionChange() {
  4909. rotation.setFromQuaternion( quaternion, undefined, false );
  4910. }
  4911. rotation.onChange( onRotationChange );
  4912. quaternion.onChange( onQuaternionChange );
  4913. Object.defineProperties( this, {
  4914. position: {
  4915. enumerable: true,
  4916. value: position
  4917. },
  4918. rotation: {
  4919. enumerable: true,
  4920. value: rotation
  4921. },
  4922. quaternion: {
  4923. enumerable: true,
  4924. value: quaternion
  4925. },
  4926. scale: {
  4927. enumerable: true,
  4928. value: scale
  4929. },
  4930. modelViewMatrix: {
  4931. value: new THREE.Matrix4()
  4932. },
  4933. normalMatrix: {
  4934. value: new THREE.Matrix3()
  4935. }
  4936. } );
  4937. this.rotationAutoUpdate = true;
  4938. this.matrix = new THREE.Matrix4();
  4939. this.matrixWorld = new THREE.Matrix4();
  4940. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  4941. this.matrixWorldNeedsUpdate = false;
  4942. this.layers = new THREE.Layers();
  4943. this.visible = true;
  4944. this.castShadow = false;
  4945. this.receiveShadow = false;
  4946. this.frustumCulled = true;
  4947. this.renderOrder = 0;
  4948. this.userData = {};
  4949. };
  4950. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4951. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  4952. THREE.Object3D.prototype = {
  4953. constructor: THREE.Object3D,
  4954. applyMatrix: function ( matrix ) {
  4955. this.matrix.multiplyMatrices( matrix, this.matrix );
  4956. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4957. },
  4958. setRotationFromAxisAngle: function ( axis, angle ) {
  4959. // assumes axis is normalized
  4960. this.quaternion.setFromAxisAngle( axis, angle );
  4961. },
  4962. setRotationFromEuler: function ( euler ) {
  4963. this.quaternion.setFromEuler( euler, true );
  4964. },
  4965. setRotationFromMatrix: function ( m ) {
  4966. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4967. this.quaternion.setFromRotationMatrix( m );
  4968. },
  4969. setRotationFromQuaternion: function ( q ) {
  4970. // assumes q is normalized
  4971. this.quaternion.copy( q );
  4972. },
  4973. rotateOnAxis: function () {
  4974. // rotate object on axis in object space
  4975. // axis is assumed to be normalized
  4976. var q1 = new THREE.Quaternion();
  4977. return function ( axis, angle ) {
  4978. q1.setFromAxisAngle( axis, angle );
  4979. this.quaternion.multiply( q1 );
  4980. return this;
  4981. };
  4982. }(),
  4983. rotateX: function () {
  4984. var v1 = new THREE.Vector3( 1, 0, 0 );
  4985. return function ( angle ) {
  4986. return this.rotateOnAxis( v1, angle );
  4987. };
  4988. }(),
  4989. rotateY: function () {
  4990. var v1 = new THREE.Vector3( 0, 1, 0 );
  4991. return function ( angle ) {
  4992. return this.rotateOnAxis( v1, angle );
  4993. };
  4994. }(),
  4995. rotateZ: function () {
  4996. var v1 = new THREE.Vector3( 0, 0, 1 );
  4997. return function ( angle ) {
  4998. return this.rotateOnAxis( v1, angle );
  4999. };
  5000. }(),
  5001. translateOnAxis: function () {
  5002. // translate object by distance along axis in object space
  5003. // axis is assumed to be normalized
  5004. var v1 = new THREE.Vector3();
  5005. return function ( axis, distance ) {
  5006. v1.copy( axis ).applyQuaternion( this.quaternion );
  5007. this.position.add( v1.multiplyScalar( distance ) );
  5008. return this;
  5009. };
  5010. }(),
  5011. translateX: function () {
  5012. var v1 = new THREE.Vector3( 1, 0, 0 );
  5013. return function ( distance ) {
  5014. return this.translateOnAxis( v1, distance );
  5015. };
  5016. }(),
  5017. translateY: function () {
  5018. var v1 = new THREE.Vector3( 0, 1, 0 );
  5019. return function ( distance ) {
  5020. return this.translateOnAxis( v1, distance );
  5021. };
  5022. }(),
  5023. translateZ: function () {
  5024. var v1 = new THREE.Vector3( 0, 0, 1 );
  5025. return function ( distance ) {
  5026. return this.translateOnAxis( v1, distance );
  5027. };
  5028. }(),
  5029. localToWorld: function ( vector ) {
  5030. return vector.applyMatrix4( this.matrixWorld );
  5031. },
  5032. worldToLocal: function () {
  5033. var m1 = new THREE.Matrix4();
  5034. return function ( vector ) {
  5035. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5036. };
  5037. }(),
  5038. lookAt: function () {
  5039. // This routine does not support objects with rotated and/or translated parent(s)
  5040. var m1 = new THREE.Matrix4();
  5041. return function ( vector ) {
  5042. m1.lookAt( vector, this.position, this.up );
  5043. this.quaternion.setFromRotationMatrix( m1 );
  5044. };
  5045. }(),
  5046. add: function ( object ) {
  5047. if ( arguments.length > 1 ) {
  5048. for ( var i = 0; i < arguments.length; i ++ ) {
  5049. this.add( arguments[ i ] );
  5050. }
  5051. return this;
  5052. }
  5053. if ( object === this ) {
  5054. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5055. return this;
  5056. }
  5057. if ( object instanceof THREE.Object3D ) {
  5058. if ( object.parent !== null ) {
  5059. object.parent.remove( object );
  5060. }
  5061. object.parent = this;
  5062. object.dispatchEvent( { type: 'added' } );
  5063. this.children.push( object );
  5064. } else {
  5065. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5066. }
  5067. return this;
  5068. },
  5069. remove: function ( object ) {
  5070. if ( arguments.length > 1 ) {
  5071. for ( var i = 0; i < arguments.length; i ++ ) {
  5072. this.remove( arguments[ i ] );
  5073. }
  5074. }
  5075. var index = this.children.indexOf( object );
  5076. if ( index !== - 1 ) {
  5077. object.parent = null;
  5078. object.dispatchEvent( { type: 'removed' } );
  5079. this.children.splice( index, 1 );
  5080. }
  5081. },
  5082. getObjectById: function ( id ) {
  5083. return this.getObjectByProperty( 'id', id );
  5084. },
  5085. getObjectByName: function ( name ) {
  5086. return this.getObjectByProperty( 'name', name );
  5087. },
  5088. getObjectByProperty: function ( name, value ) {
  5089. if ( this[ name ] === value ) return this;
  5090. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5091. var child = this.children[ i ];
  5092. var object = child.getObjectByProperty( name, value );
  5093. if ( object !== undefined ) {
  5094. return object;
  5095. }
  5096. }
  5097. return undefined;
  5098. },
  5099. getWorldPosition: function ( optionalTarget ) {
  5100. var result = optionalTarget || new THREE.Vector3();
  5101. this.updateMatrixWorld( true );
  5102. return result.setFromMatrixPosition( this.matrixWorld );
  5103. },
  5104. getWorldQuaternion: function () {
  5105. var position = new THREE.Vector3();
  5106. var scale = new THREE.Vector3();
  5107. return function ( optionalTarget ) {
  5108. var result = optionalTarget || new THREE.Quaternion();
  5109. this.updateMatrixWorld( true );
  5110. this.matrixWorld.decompose( position, result, scale );
  5111. return result;
  5112. };
  5113. }(),
  5114. getWorldRotation: function () {
  5115. var quaternion = new THREE.Quaternion();
  5116. return function ( optionalTarget ) {
  5117. var result = optionalTarget || new THREE.Euler();
  5118. this.getWorldQuaternion( quaternion );
  5119. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5120. };
  5121. }(),
  5122. getWorldScale: function () {
  5123. var position = new THREE.Vector3();
  5124. var quaternion = new THREE.Quaternion();
  5125. return function ( optionalTarget ) {
  5126. var result = optionalTarget || new THREE.Vector3();
  5127. this.updateMatrixWorld( true );
  5128. this.matrixWorld.decompose( position, quaternion, result );
  5129. return result;
  5130. };
  5131. }(),
  5132. getWorldDirection: function () {
  5133. var quaternion = new THREE.Quaternion();
  5134. return function ( optionalTarget ) {
  5135. var result = optionalTarget || new THREE.Vector3();
  5136. this.getWorldQuaternion( quaternion );
  5137. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5138. };
  5139. }(),
  5140. raycast: function () {},
  5141. traverse: function ( callback ) {
  5142. callback( this );
  5143. var children = this.children;
  5144. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5145. children[ i ].traverse( callback );
  5146. }
  5147. },
  5148. traverseVisible: function ( callback ) {
  5149. if ( this.visible === false ) return;
  5150. callback( this );
  5151. var children = this.children;
  5152. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5153. children[ i ].traverseVisible( callback );
  5154. }
  5155. },
  5156. traverseAncestors: function ( callback ) {
  5157. var parent = this.parent;
  5158. if ( parent !== null ) {
  5159. callback( parent );
  5160. parent.traverseAncestors( callback );
  5161. }
  5162. },
  5163. updateMatrix: function () {
  5164. this.matrix.compose( this.position, this.quaternion, this.scale );
  5165. this.matrixWorldNeedsUpdate = true;
  5166. },
  5167. updateMatrixWorld: function ( force ) {
  5168. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  5169. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  5170. if ( this.parent === null ) {
  5171. this.matrixWorld.copy( this.matrix );
  5172. } else {
  5173. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5174. }
  5175. this.matrixWorldNeedsUpdate = false;
  5176. force = true;
  5177. }
  5178. // update children
  5179. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5180. this.children[ i ].updateMatrixWorld( force );
  5181. }
  5182. },
  5183. toJSON: function ( meta ) {
  5184. var isRootObject = ( meta === undefined );
  5185. var output = {};
  5186. // meta is a hash used to collect geometries, materials.
  5187. // not providing it implies that this is the root object
  5188. // being serialized.
  5189. if ( isRootObject ) {
  5190. // initialize meta obj
  5191. meta = {
  5192. geometries: {},
  5193. materials: {},
  5194. textures: {},
  5195. images: {}
  5196. };
  5197. output.metadata = {
  5198. version: 4.4,
  5199. type: 'Object',
  5200. generator: 'Object3D.toJSON'
  5201. };
  5202. }
  5203. // standard Object3D serialization
  5204. var object = {};
  5205. object.uuid = this.uuid;
  5206. object.type = this.type;
  5207. if ( this.name !== '' ) object.name = this.name;
  5208. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5209. if ( this.castShadow === true ) object.castShadow = true;
  5210. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5211. if ( this.visible === false ) object.visible = false;
  5212. object.matrix = this.matrix.toArray();
  5213. //
  5214. if ( this.geometry !== undefined ) {
  5215. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  5216. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  5217. }
  5218. object.geometry = this.geometry.uuid;
  5219. }
  5220. if ( this.material !== undefined ) {
  5221. if ( meta.materials[ this.material.uuid ] === undefined ) {
  5222. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  5223. }
  5224. object.material = this.material.uuid;
  5225. }
  5226. //
  5227. if ( this.children.length > 0 ) {
  5228. object.children = [];
  5229. for ( var i = 0; i < this.children.length; i ++ ) {
  5230. object.children.push( this.children[ i ].toJSON( meta ).object );
  5231. }
  5232. }
  5233. if ( isRootObject ) {
  5234. var geometries = extractFromCache( meta.geometries );
  5235. var materials = extractFromCache( meta.materials );
  5236. var textures = extractFromCache( meta.textures );
  5237. var images = extractFromCache( meta.images );
  5238. if ( geometries.length > 0 ) output.geometries = geometries;
  5239. if ( materials.length > 0 ) output.materials = materials;
  5240. if ( textures.length > 0 ) output.textures = textures;
  5241. if ( images.length > 0 ) output.images = images;
  5242. }
  5243. output.object = object;
  5244. return output;
  5245. // extract data from the cache hash
  5246. // remove metadata on each item
  5247. // and return as array
  5248. function extractFromCache ( cache ) {
  5249. var values = [];
  5250. for ( var key in cache ) {
  5251. var data = cache[ key ];
  5252. delete data.metadata;
  5253. values.push( data );
  5254. }
  5255. return values;
  5256. }
  5257. },
  5258. clone: function ( recursive ) {
  5259. return new this.constructor().copy( this, recursive );
  5260. },
  5261. copy: function ( source, recursive ) {
  5262. if ( recursive === undefined ) recursive = true;
  5263. this.name = source.name;
  5264. this.up.copy( source.up );
  5265. this.position.copy( source.position );
  5266. this.quaternion.copy( source.quaternion );
  5267. this.scale.copy( source.scale );
  5268. this.rotationAutoUpdate = source.rotationAutoUpdate;
  5269. this.matrix.copy( source.matrix );
  5270. this.matrixWorld.copy( source.matrixWorld );
  5271. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5272. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5273. this.visible = source.visible;
  5274. this.castShadow = source.castShadow;
  5275. this.receiveShadow = source.receiveShadow;
  5276. this.frustumCulled = source.frustumCulled;
  5277. this.renderOrder = source.renderOrder;
  5278. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5279. if ( recursive === true ) {
  5280. for ( var i = 0; i < source.children.length; i ++ ) {
  5281. var child = source.children[ i ];
  5282. this.add( child.clone() );
  5283. }
  5284. }
  5285. return this;
  5286. }
  5287. };
  5288. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  5289. THREE.Object3DIdCount = 0;
  5290. // File:src/core/Face3.js
  5291. /**
  5292. * @author mrdoob / http://mrdoob.com/
  5293. * @author alteredq / http://alteredqualia.com/
  5294. */
  5295. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  5296. this.a = a;
  5297. this.b = b;
  5298. this.c = c;
  5299. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  5300. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5301. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  5302. this.vertexColors = Array.isArray( color ) ? color : [];
  5303. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5304. };
  5305. THREE.Face3.prototype = {
  5306. constructor: THREE.Face3,
  5307. clone: function () {
  5308. return new this.constructor().copy( this );
  5309. },
  5310. copy: function ( source ) {
  5311. this.a = source.a;
  5312. this.b = source.b;
  5313. this.c = source.c;
  5314. this.normal.copy( source.normal );
  5315. this.color.copy( source.color );
  5316. this.materialIndex = source.materialIndex;
  5317. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5318. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5319. }
  5320. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5321. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5322. }
  5323. return this;
  5324. }
  5325. };
  5326. // File:src/core/BufferAttribute.js
  5327. /**
  5328. * @author mrdoob / http://mrdoob.com/
  5329. */
  5330. THREE.BufferAttribute = function ( array, itemSize ) {
  5331. this.uuid = THREE.Math.generateUUID();
  5332. this.array = array;
  5333. this.itemSize = itemSize;
  5334. this.dynamic = false;
  5335. this.updateRange = { offset: 0, count: - 1 };
  5336. this.version = 0;
  5337. };
  5338. THREE.BufferAttribute.prototype = {
  5339. constructor: THREE.BufferAttribute,
  5340. get count() {
  5341. return this.array.length / this.itemSize;
  5342. },
  5343. set needsUpdate( value ) {
  5344. if ( value === true ) this.version ++;
  5345. },
  5346. setDynamic: function ( value ) {
  5347. this.dynamic = value;
  5348. return this;
  5349. },
  5350. copy: function ( source ) {
  5351. this.array = new source.array.constructor( source.array );
  5352. this.itemSize = source.itemSize;
  5353. this.dynamic = source.dynamic;
  5354. return this;
  5355. },
  5356. copyAt: function ( index1, attribute, index2 ) {
  5357. index1 *= this.itemSize;
  5358. index2 *= attribute.itemSize;
  5359. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5360. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5361. }
  5362. return this;
  5363. },
  5364. copyArray: function ( array ) {
  5365. this.array.set( array );
  5366. return this;
  5367. },
  5368. copyColorsArray: function ( colors ) {
  5369. var array = this.array, offset = 0;
  5370. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5371. var color = colors[ i ];
  5372. if ( color === undefined ) {
  5373. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5374. color = new THREE.Color();
  5375. }
  5376. array[ offset ++ ] = color.r;
  5377. array[ offset ++ ] = color.g;
  5378. array[ offset ++ ] = color.b;
  5379. }
  5380. return this;
  5381. },
  5382. copyIndicesArray: function ( indices ) {
  5383. var array = this.array, offset = 0;
  5384. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5385. var index = indices[ i ];
  5386. array[ offset ++ ] = index.a;
  5387. array[ offset ++ ] = index.b;
  5388. array[ offset ++ ] = index.c;
  5389. }
  5390. return this;
  5391. },
  5392. copyVector2sArray: function ( vectors ) {
  5393. var array = this.array, offset = 0;
  5394. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5395. var vector = vectors[ i ];
  5396. if ( vector === undefined ) {
  5397. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5398. vector = new THREE.Vector2();
  5399. }
  5400. array[ offset ++ ] = vector.x;
  5401. array[ offset ++ ] = vector.y;
  5402. }
  5403. return this;
  5404. },
  5405. copyVector3sArray: function ( vectors ) {
  5406. var array = this.array, offset = 0;
  5407. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5408. var vector = vectors[ i ];
  5409. if ( vector === undefined ) {
  5410. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5411. vector = new THREE.Vector3();
  5412. }
  5413. array[ offset ++ ] = vector.x;
  5414. array[ offset ++ ] = vector.y;
  5415. array[ offset ++ ] = vector.z;
  5416. }
  5417. return this;
  5418. },
  5419. copyVector4sArray: function ( vectors ) {
  5420. var array = this.array, offset = 0;
  5421. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5422. var vector = vectors[ i ];
  5423. if ( vector === undefined ) {
  5424. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5425. vector = new THREE.Vector4();
  5426. }
  5427. array[ offset ++ ] = vector.x;
  5428. array[ offset ++ ] = vector.y;
  5429. array[ offset ++ ] = vector.z;
  5430. array[ offset ++ ] = vector.w;
  5431. }
  5432. return this;
  5433. },
  5434. set: function ( value, offset ) {
  5435. if ( offset === undefined ) offset = 0;
  5436. this.array.set( value, offset );
  5437. return this;
  5438. },
  5439. getX: function ( index ) {
  5440. return this.array[ index * this.itemSize ];
  5441. },
  5442. setX: function ( index, x ) {
  5443. this.array[ index * this.itemSize ] = x;
  5444. return this;
  5445. },
  5446. getY: function ( index ) {
  5447. return this.array[ index * this.itemSize + 1 ];
  5448. },
  5449. setY: function ( index, y ) {
  5450. this.array[ index * this.itemSize + 1 ] = y;
  5451. return this;
  5452. },
  5453. getZ: function ( index ) {
  5454. return this.array[ index * this.itemSize + 2 ];
  5455. },
  5456. setZ: function ( index, z ) {
  5457. this.array[ index * this.itemSize + 2 ] = z;
  5458. return this;
  5459. },
  5460. getW: function ( index ) {
  5461. return this.array[ index * this.itemSize + 3 ];
  5462. },
  5463. setW: function ( index, w ) {
  5464. this.array[ index * this.itemSize + 3 ] = w;
  5465. return this;
  5466. },
  5467. setXY: function ( index, x, y ) {
  5468. index *= this.itemSize;
  5469. this.array[ index + 0 ] = x;
  5470. this.array[ index + 1 ] = y;
  5471. return this;
  5472. },
  5473. setXYZ: function ( index, x, y, z ) {
  5474. index *= this.itemSize;
  5475. this.array[ index + 0 ] = x;
  5476. this.array[ index + 1 ] = y;
  5477. this.array[ index + 2 ] = z;
  5478. return this;
  5479. },
  5480. setXYZW: function ( index, x, y, z, w ) {
  5481. index *= this.itemSize;
  5482. this.array[ index + 0 ] = x;
  5483. this.array[ index + 1 ] = y;
  5484. this.array[ index + 2 ] = z;
  5485. this.array[ index + 3 ] = w;
  5486. return this;
  5487. },
  5488. clone: function () {
  5489. return new this.constructor().copy( this );
  5490. }
  5491. };
  5492. //
  5493. THREE.Int8Attribute = function ( array, itemSize ) {
  5494. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5495. };
  5496. THREE.Uint8Attribute = function ( array, itemSize ) {
  5497. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5498. };
  5499. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5500. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5501. };
  5502. THREE.Int16Attribute = function ( array, itemSize ) {
  5503. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5504. };
  5505. THREE.Uint16Attribute = function ( array, itemSize ) {
  5506. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5507. };
  5508. THREE.Int32Attribute = function ( array, itemSize ) {
  5509. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5510. };
  5511. THREE.Uint32Attribute = function ( array, itemSize ) {
  5512. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5513. };
  5514. THREE.Float32Attribute = function ( array, itemSize ) {
  5515. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5516. };
  5517. THREE.Float64Attribute = function ( array, itemSize ) {
  5518. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5519. };
  5520. // Deprecated
  5521. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5522. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5523. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5524. };
  5525. // File:src/core/InstancedBufferAttribute.js
  5526. /**
  5527. * @author benaadams / https://twitter.com/ben_a_adams
  5528. */
  5529. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5530. THREE.BufferAttribute.call( this, array, itemSize );
  5531. this.meshPerAttribute = meshPerAttribute || 1;
  5532. };
  5533. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5534. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5535. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5536. THREE.BufferAttribute.prototype.copy.call( this, source );
  5537. this.meshPerAttribute = source.meshPerAttribute;
  5538. return this;
  5539. };
  5540. // File:src/core/InterleavedBuffer.js
  5541. /**
  5542. * @author benaadams / https://twitter.com/ben_a_adams
  5543. */
  5544. THREE.InterleavedBuffer = function ( array, stride ) {
  5545. this.uuid = THREE.Math.generateUUID();
  5546. this.array = array;
  5547. this.stride = stride;
  5548. this.dynamic = false;
  5549. this.updateRange = { offset: 0, count: - 1 };
  5550. this.version = 0;
  5551. };
  5552. THREE.InterleavedBuffer.prototype = {
  5553. constructor: THREE.InterleavedBuffer,
  5554. get length () {
  5555. return this.array.length;
  5556. },
  5557. get count () {
  5558. return this.array.length / this.stride;
  5559. },
  5560. set needsUpdate( value ) {
  5561. if ( value === true ) this.version ++;
  5562. },
  5563. setDynamic: function ( value ) {
  5564. this.dynamic = value;
  5565. return this;
  5566. },
  5567. copy: function ( source ) {
  5568. this.array = new source.array.constructor( source.array );
  5569. this.stride = source.stride;
  5570. this.dynamic = source.dynamic;
  5571. return this;
  5572. },
  5573. copyAt: function ( index1, attribute, index2 ) {
  5574. index1 *= this.stride;
  5575. index2 *= attribute.stride;
  5576. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5577. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5578. }
  5579. return this;
  5580. },
  5581. set: function ( value, offset ) {
  5582. if ( offset === undefined ) offset = 0;
  5583. this.array.set( value, offset );
  5584. return this;
  5585. },
  5586. clone: function () {
  5587. return new this.constructor().copy( this );
  5588. }
  5589. };
  5590. // File:src/core/InstancedInterleavedBuffer.js
  5591. /**
  5592. * @author benaadams / https://twitter.com/ben_a_adams
  5593. */
  5594. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5595. THREE.InterleavedBuffer.call( this, array, stride );
  5596. this.meshPerAttribute = meshPerAttribute || 1;
  5597. };
  5598. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5599. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5600. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5601. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5602. this.meshPerAttribute = source.meshPerAttribute;
  5603. return this;
  5604. };
  5605. // File:src/core/InterleavedBufferAttribute.js
  5606. /**
  5607. * @author benaadams / https://twitter.com/ben_a_adams
  5608. */
  5609. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5610. this.uuid = THREE.Math.generateUUID();
  5611. this.data = interleavedBuffer;
  5612. this.itemSize = itemSize;
  5613. this.offset = offset;
  5614. };
  5615. THREE.InterleavedBufferAttribute.prototype = {
  5616. constructor: THREE.InterleavedBufferAttribute,
  5617. get length() {
  5618. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5619. return this.array.length;
  5620. },
  5621. get count() {
  5622. return this.data.count;
  5623. },
  5624. setX: function ( index, x ) {
  5625. this.data.array[ index * this.data.stride + this.offset ] = x;
  5626. return this;
  5627. },
  5628. setY: function ( index, y ) {
  5629. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5630. return this;
  5631. },
  5632. setZ: function ( index, z ) {
  5633. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5634. return this;
  5635. },
  5636. setW: function ( index, w ) {
  5637. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5638. return this;
  5639. },
  5640. getX: function ( index ) {
  5641. return this.data.array[ index * this.data.stride + this.offset ];
  5642. },
  5643. getY: function ( index ) {
  5644. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5645. },
  5646. getZ: function ( index ) {
  5647. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5648. },
  5649. getW: function ( index ) {
  5650. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5651. },
  5652. setXY: function ( index, x, y ) {
  5653. index = index * this.data.stride + this.offset;
  5654. this.data.array[ index + 0 ] = x;
  5655. this.data.array[ index + 1 ] = y;
  5656. return this;
  5657. },
  5658. setXYZ: function ( index, x, y, z ) {
  5659. index = index * this.data.stride + this.offset;
  5660. this.data.array[ index + 0 ] = x;
  5661. this.data.array[ index + 1 ] = y;
  5662. this.data.array[ index + 2 ] = z;
  5663. return this;
  5664. },
  5665. setXYZW: function ( index, x, y, z, w ) {
  5666. index = index * this.data.stride + this.offset;
  5667. this.data.array[ index + 0 ] = x;
  5668. this.data.array[ index + 1 ] = y;
  5669. this.data.array[ index + 2 ] = z;
  5670. this.data.array[ index + 3 ] = w;
  5671. return this;
  5672. }
  5673. };
  5674. // File:src/core/Geometry.js
  5675. /**
  5676. * @author mrdoob / http://mrdoob.com/
  5677. * @author kile / http://kile.stravaganza.org/
  5678. * @author alteredq / http://alteredqualia.com/
  5679. * @author mikael emtinger / http://gomo.se/
  5680. * @author zz85 / http://www.lab4games.net/zz85/blog
  5681. * @author bhouston / http://clara.io
  5682. */
  5683. THREE.Geometry = function () {
  5684. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5685. this.uuid = THREE.Math.generateUUID();
  5686. this.name = '';
  5687. this.type = 'Geometry';
  5688. this.vertices = [];
  5689. this.colors = [];
  5690. this.faces = [];
  5691. this.faceVertexUvs = [ [] ];
  5692. this.morphTargets = [];
  5693. this.morphNormals = [];
  5694. this.skinWeights = [];
  5695. this.skinIndices = [];
  5696. this.lineDistances = [];
  5697. this.boundingBox = null;
  5698. this.boundingSphere = null;
  5699. // update flags
  5700. this.verticesNeedUpdate = false;
  5701. this.elementsNeedUpdate = false;
  5702. this.uvsNeedUpdate = false;
  5703. this.normalsNeedUpdate = false;
  5704. this.colorsNeedUpdate = false;
  5705. this.lineDistancesNeedUpdate = false;
  5706. this.groupsNeedUpdate = false;
  5707. };
  5708. THREE.Geometry.prototype = {
  5709. constructor: THREE.Geometry,
  5710. applyMatrix: function ( matrix ) {
  5711. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5712. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5713. var vertex = this.vertices[ i ];
  5714. vertex.applyMatrix4( matrix );
  5715. }
  5716. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5717. var face = this.faces[ i ];
  5718. face.normal.applyMatrix3( normalMatrix ).normalize();
  5719. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5720. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5721. }
  5722. }
  5723. if ( this.boundingBox !== null ) {
  5724. this.computeBoundingBox();
  5725. }
  5726. if ( this.boundingSphere !== null ) {
  5727. this.computeBoundingSphere();
  5728. }
  5729. this.verticesNeedUpdate = true;
  5730. this.normalsNeedUpdate = true;
  5731. },
  5732. rotateX: function () {
  5733. // rotate geometry around world x-axis
  5734. var m1;
  5735. return function rotateX( angle ) {
  5736. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5737. m1.makeRotationX( angle );
  5738. this.applyMatrix( m1 );
  5739. return this;
  5740. };
  5741. }(),
  5742. rotateY: function () {
  5743. // rotate geometry around world y-axis
  5744. var m1;
  5745. return function rotateY( angle ) {
  5746. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5747. m1.makeRotationY( angle );
  5748. this.applyMatrix( m1 );
  5749. return this;
  5750. };
  5751. }(),
  5752. rotateZ: function () {
  5753. // rotate geometry around world z-axis
  5754. var m1;
  5755. return function rotateZ( angle ) {
  5756. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5757. m1.makeRotationZ( angle );
  5758. this.applyMatrix( m1 );
  5759. return this;
  5760. };
  5761. }(),
  5762. translate: function () {
  5763. // translate geometry
  5764. var m1;
  5765. return function translate( x, y, z ) {
  5766. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5767. m1.makeTranslation( x, y, z );
  5768. this.applyMatrix( m1 );
  5769. return this;
  5770. };
  5771. }(),
  5772. scale: function () {
  5773. // scale geometry
  5774. var m1;
  5775. return function scale( x, y, z ) {
  5776. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5777. m1.makeScale( x, y, z );
  5778. this.applyMatrix( m1 );
  5779. return this;
  5780. };
  5781. }(),
  5782. lookAt: function () {
  5783. var obj;
  5784. return function lookAt( vector ) {
  5785. if ( obj === undefined ) obj = new THREE.Object3D();
  5786. obj.lookAt( vector );
  5787. obj.updateMatrix();
  5788. this.applyMatrix( obj.matrix );
  5789. };
  5790. }(),
  5791. fromBufferGeometry: function ( geometry ) {
  5792. var scope = this;
  5793. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5794. var attributes = geometry.attributes;
  5795. var positions = attributes.position.array;
  5796. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5797. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5798. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5799. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5800. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5801. var tempNormals = [];
  5802. var tempUVs = [];
  5803. var tempUVs2 = [];
  5804. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5805. scope.vertices.push( new THREE.Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  5806. if ( normals !== undefined ) {
  5807. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5808. }
  5809. if ( colors !== undefined ) {
  5810. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5811. }
  5812. if ( uvs !== undefined ) {
  5813. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5814. }
  5815. if ( uvs2 !== undefined ) {
  5816. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5817. }
  5818. }
  5819. function addFace( a, b, c ) {
  5820. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5821. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5822. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5823. scope.faces.push( face );
  5824. if ( uvs !== undefined ) {
  5825. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5826. }
  5827. if ( uvs2 !== undefined ) {
  5828. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5829. }
  5830. }
  5831. if ( indices !== undefined ) {
  5832. var groups = geometry.groups;
  5833. if ( groups.length > 0 ) {
  5834. for ( var i = 0; i < groups.length; i ++ ) {
  5835. var group = groups[ i ];
  5836. var start = group.start;
  5837. var count = group.count;
  5838. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5839. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ] );
  5840. }
  5841. }
  5842. } else {
  5843. for ( var i = 0; i < indices.length; i += 3 ) {
  5844. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5845. }
  5846. }
  5847. } else {
  5848. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5849. addFace( i, i + 1, i + 2 );
  5850. }
  5851. }
  5852. this.computeFaceNormals();
  5853. if ( geometry.boundingBox !== null ) {
  5854. this.boundingBox = geometry.boundingBox.clone();
  5855. }
  5856. if ( geometry.boundingSphere !== null ) {
  5857. this.boundingSphere = geometry.boundingSphere.clone();
  5858. }
  5859. return this;
  5860. },
  5861. center: function () {
  5862. this.computeBoundingBox();
  5863. var offset = this.boundingBox.center().negate();
  5864. this.translate( offset.x, offset.y, offset.z );
  5865. return offset;
  5866. },
  5867. normalize: function () {
  5868. this.computeBoundingSphere();
  5869. var center = this.boundingSphere.center;
  5870. var radius = this.boundingSphere.radius;
  5871. var s = radius === 0 ? 1 : 1.0 / radius;
  5872. var matrix = new THREE.Matrix4();
  5873. matrix.set(
  5874. s, 0, 0, - s * center.x,
  5875. 0, s, 0, - s * center.y,
  5876. 0, 0, s, - s * center.z,
  5877. 0, 0, 0, 1
  5878. );
  5879. this.applyMatrix( matrix );
  5880. return this;
  5881. },
  5882. computeFaceNormals: function () {
  5883. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5884. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5885. var face = this.faces[ f ];
  5886. var vA = this.vertices[ face.a ];
  5887. var vB = this.vertices[ face.b ];
  5888. var vC = this.vertices[ face.c ];
  5889. cb.subVectors( vC, vB );
  5890. ab.subVectors( vA, vB );
  5891. cb.cross( ab );
  5892. cb.normalize();
  5893. face.normal.copy( cb );
  5894. }
  5895. },
  5896. computeVertexNormals: function ( areaWeighted ) {
  5897. if ( areaWeighted === undefined ) areaWeighted = true;
  5898. var v, vl, f, fl, face, vertices;
  5899. vertices = new Array( this.vertices.length );
  5900. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5901. vertices[ v ] = new THREE.Vector3();
  5902. }
  5903. if ( areaWeighted ) {
  5904. // vertex normals weighted by triangle areas
  5905. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5906. var vA, vB, vC;
  5907. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5908. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5909. face = this.faces[ f ];
  5910. vA = this.vertices[ face.a ];
  5911. vB = this.vertices[ face.b ];
  5912. vC = this.vertices[ face.c ];
  5913. cb.subVectors( vC, vB );
  5914. ab.subVectors( vA, vB );
  5915. cb.cross( ab );
  5916. vertices[ face.a ].add( cb );
  5917. vertices[ face.b ].add( cb );
  5918. vertices[ face.c ].add( cb );
  5919. }
  5920. } else {
  5921. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5922. face = this.faces[ f ];
  5923. vertices[ face.a ].add( face.normal );
  5924. vertices[ face.b ].add( face.normal );
  5925. vertices[ face.c ].add( face.normal );
  5926. }
  5927. }
  5928. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5929. vertices[ v ].normalize();
  5930. }
  5931. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5932. face = this.faces[ f ];
  5933. var vertexNormals = face.vertexNormals;
  5934. if ( vertexNormals.length === 3 ) {
  5935. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5936. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5937. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5938. } else {
  5939. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5940. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5941. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5942. }
  5943. }
  5944. if ( this.faces.length > 0 ) {
  5945. this.normalsNeedUpdate = true;
  5946. }
  5947. },
  5948. computeMorphNormals: function () {
  5949. var i, il, f, fl, face;
  5950. // save original normals
  5951. // - create temp variables on first access
  5952. // otherwise just copy (for faster repeated calls)
  5953. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5954. face = this.faces[ f ];
  5955. if ( ! face.__originalFaceNormal ) {
  5956. face.__originalFaceNormal = face.normal.clone();
  5957. } else {
  5958. face.__originalFaceNormal.copy( face.normal );
  5959. }
  5960. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5961. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5962. if ( ! face.__originalVertexNormals[ i ] ) {
  5963. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5964. } else {
  5965. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5966. }
  5967. }
  5968. }
  5969. // use temp geometry to compute face and vertex normals for each morph
  5970. var tmpGeo = new THREE.Geometry();
  5971. tmpGeo.faces = this.faces;
  5972. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5973. // create on first access
  5974. if ( ! this.morphNormals[ i ] ) {
  5975. this.morphNormals[ i ] = {};
  5976. this.morphNormals[ i ].faceNormals = [];
  5977. this.morphNormals[ i ].vertexNormals = [];
  5978. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5979. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5980. var faceNormal, vertexNormals;
  5981. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5982. faceNormal = new THREE.Vector3();
  5983. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5984. dstNormalsFace.push( faceNormal );
  5985. dstNormalsVertex.push( vertexNormals );
  5986. }
  5987. }
  5988. var morphNormals = this.morphNormals[ i ];
  5989. // set vertices to morph target
  5990. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5991. // compute morph normals
  5992. tmpGeo.computeFaceNormals();
  5993. tmpGeo.computeVertexNormals();
  5994. // store morph normals
  5995. var faceNormal, vertexNormals;
  5996. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5997. face = this.faces[ f ];
  5998. faceNormal = morphNormals.faceNormals[ f ];
  5999. vertexNormals = morphNormals.vertexNormals[ f ];
  6000. faceNormal.copy( face.normal );
  6001. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  6002. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  6003. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  6004. }
  6005. }
  6006. // restore original normals
  6007. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6008. face = this.faces[ f ];
  6009. face.normal = face.__originalFaceNormal;
  6010. face.vertexNormals = face.__originalVertexNormals;
  6011. }
  6012. },
  6013. computeTangents: function () {
  6014. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  6015. },
  6016. computeLineDistances: function () {
  6017. var d = 0;
  6018. var vertices = this.vertices;
  6019. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6020. if ( i > 0 ) {
  6021. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  6022. }
  6023. this.lineDistances[ i ] = d;
  6024. }
  6025. },
  6026. computeBoundingBox: function () {
  6027. if ( this.boundingBox === null ) {
  6028. this.boundingBox = new THREE.Box3();
  6029. }
  6030. this.boundingBox.setFromPoints( this.vertices );
  6031. },
  6032. computeBoundingSphere: function () {
  6033. if ( this.boundingSphere === null ) {
  6034. this.boundingSphere = new THREE.Sphere();
  6035. }
  6036. this.boundingSphere.setFromPoints( this.vertices );
  6037. },
  6038. merge: function ( geometry, matrix, materialIndexOffset ) {
  6039. if ( geometry instanceof THREE.Geometry === false ) {
  6040. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  6041. return;
  6042. }
  6043. var normalMatrix,
  6044. vertexOffset = this.vertices.length,
  6045. vertices1 = this.vertices,
  6046. vertices2 = geometry.vertices,
  6047. faces1 = this.faces,
  6048. faces2 = geometry.faces,
  6049. uvs1 = this.faceVertexUvs[ 0 ],
  6050. uvs2 = geometry.faceVertexUvs[ 0 ];
  6051. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  6052. if ( matrix !== undefined ) {
  6053. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6054. }
  6055. // vertices
  6056. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  6057. var vertex = vertices2[ i ];
  6058. var vertexCopy = vertex.clone();
  6059. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  6060. vertices1.push( vertexCopy );
  6061. }
  6062. // faces
  6063. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  6064. var face = faces2[ i ], faceCopy, normal, color,
  6065. faceVertexNormals = face.vertexNormals,
  6066. faceVertexColors = face.vertexColors;
  6067. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  6068. faceCopy.normal.copy( face.normal );
  6069. if ( normalMatrix !== undefined ) {
  6070. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  6071. }
  6072. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  6073. normal = faceVertexNormals[ j ].clone();
  6074. if ( normalMatrix !== undefined ) {
  6075. normal.applyMatrix3( normalMatrix ).normalize();
  6076. }
  6077. faceCopy.vertexNormals.push( normal );
  6078. }
  6079. faceCopy.color.copy( face.color );
  6080. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  6081. color = faceVertexColors[ j ];
  6082. faceCopy.vertexColors.push( color.clone() );
  6083. }
  6084. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  6085. faces1.push( faceCopy );
  6086. }
  6087. // uvs
  6088. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  6089. var uv = uvs2[ i ], uvCopy = [];
  6090. if ( uv === undefined ) {
  6091. continue;
  6092. }
  6093. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  6094. uvCopy.push( uv[ j ].clone() );
  6095. }
  6096. uvs1.push( uvCopy );
  6097. }
  6098. },
  6099. mergeMesh: function ( mesh ) {
  6100. if ( mesh instanceof THREE.Mesh === false ) {
  6101. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  6102. return;
  6103. }
  6104. mesh.matrixAutoUpdate && mesh.updateMatrix();
  6105. this.merge( mesh.geometry, mesh.matrix );
  6106. },
  6107. /*
  6108. * Checks for duplicate vertices with hashmap.
  6109. * Duplicated vertices are removed
  6110. * and faces' vertices are updated.
  6111. */
  6112. mergeVertices: function () {
  6113. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  6114. var unique = [], changes = [];
  6115. var v, key;
  6116. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  6117. var precision = Math.pow( 10, precisionPoints );
  6118. var i, il, face;
  6119. var indices, j, jl;
  6120. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  6121. v = this.vertices[ i ];
  6122. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  6123. if ( verticesMap[ key ] === undefined ) {
  6124. verticesMap[ key ] = i;
  6125. unique.push( this.vertices[ i ] );
  6126. changes[ i ] = unique.length - 1;
  6127. } else {
  6128. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  6129. changes[ i ] = changes[ verticesMap[ key ] ];
  6130. }
  6131. }
  6132. // if faces are completely degenerate after merging vertices, we
  6133. // have to remove them from the geometry.
  6134. var faceIndicesToRemove = [];
  6135. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  6136. face = this.faces[ i ];
  6137. face.a = changes[ face.a ];
  6138. face.b = changes[ face.b ];
  6139. face.c = changes[ face.c ];
  6140. indices = [ face.a, face.b, face.c ];
  6141. var dupIndex = - 1;
  6142. // if any duplicate vertices are found in a Face3
  6143. // we have to remove the face as nothing can be saved
  6144. for ( var n = 0; n < 3; n ++ ) {
  6145. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  6146. dupIndex = n;
  6147. faceIndicesToRemove.push( i );
  6148. break;
  6149. }
  6150. }
  6151. }
  6152. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  6153. var idx = faceIndicesToRemove[ i ];
  6154. this.faces.splice( idx, 1 );
  6155. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  6156. this.faceVertexUvs[ j ].splice( idx, 1 );
  6157. }
  6158. }
  6159. // Use unique set of vertices
  6160. var diff = this.vertices.length - unique.length;
  6161. this.vertices = unique;
  6162. return diff;
  6163. },
  6164. sortFacesByMaterialIndex: function () {
  6165. var faces = this.faces;
  6166. var length = faces.length;
  6167. // tag faces
  6168. for ( var i = 0; i < length; i ++ ) {
  6169. faces[ i ]._id = i;
  6170. }
  6171. // sort faces
  6172. function materialIndexSort( a, b ) {
  6173. return a.materialIndex - b.materialIndex;
  6174. }
  6175. faces.sort( materialIndexSort );
  6176. // sort uvs
  6177. var uvs1 = this.faceVertexUvs[ 0 ];
  6178. var uvs2 = this.faceVertexUvs[ 1 ];
  6179. var newUvs1, newUvs2;
  6180. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  6181. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  6182. for ( var i = 0; i < length; i ++ ) {
  6183. var id = faces[ i ]._id;
  6184. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  6185. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  6186. }
  6187. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  6188. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  6189. },
  6190. toJSON: function () {
  6191. var data = {
  6192. metadata: {
  6193. version: 4.4,
  6194. type: 'Geometry',
  6195. generator: 'Geometry.toJSON'
  6196. }
  6197. };
  6198. // standard Geometry serialization
  6199. data.uuid = this.uuid;
  6200. data.type = this.type;
  6201. if ( this.name !== '' ) data.name = this.name;
  6202. if ( this.parameters !== undefined ) {
  6203. var parameters = this.parameters;
  6204. for ( var key in parameters ) {
  6205. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6206. }
  6207. return data;
  6208. }
  6209. var vertices = [];
  6210. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6211. var vertex = this.vertices[ i ];
  6212. vertices.push( vertex.x, vertex.y, vertex.z );
  6213. }
  6214. var faces = [];
  6215. var normals = [];
  6216. var normalsHash = {};
  6217. var colors = [];
  6218. var colorsHash = {};
  6219. var uvs = [];
  6220. var uvsHash = {};
  6221. for ( var i = 0; i < this.faces.length; i ++ ) {
  6222. var face = this.faces[ i ];
  6223. var hasMaterial = true;
  6224. var hasFaceUv = false; // deprecated
  6225. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6226. var hasFaceNormal = face.normal.length() > 0;
  6227. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6228. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6229. var hasFaceVertexColor = face.vertexColors.length > 0;
  6230. var faceType = 0;
  6231. faceType = setBit( faceType, 0, 0 ); // isQuad
  6232. faceType = setBit( faceType, 1, hasMaterial );
  6233. faceType = setBit( faceType, 2, hasFaceUv );
  6234. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6235. faceType = setBit( faceType, 4, hasFaceNormal );
  6236. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6237. faceType = setBit( faceType, 6, hasFaceColor );
  6238. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6239. faces.push( faceType );
  6240. faces.push( face.a, face.b, face.c );
  6241. faces.push( face.materialIndex );
  6242. if ( hasFaceVertexUv ) {
  6243. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6244. faces.push(
  6245. getUvIndex( faceVertexUvs[ 0 ] ),
  6246. getUvIndex( faceVertexUvs[ 1 ] ),
  6247. getUvIndex( faceVertexUvs[ 2 ] )
  6248. );
  6249. }
  6250. if ( hasFaceNormal ) {
  6251. faces.push( getNormalIndex( face.normal ) );
  6252. }
  6253. if ( hasFaceVertexNormal ) {
  6254. var vertexNormals = face.vertexNormals;
  6255. faces.push(
  6256. getNormalIndex( vertexNormals[ 0 ] ),
  6257. getNormalIndex( vertexNormals[ 1 ] ),
  6258. getNormalIndex( vertexNormals[ 2 ] )
  6259. );
  6260. }
  6261. if ( hasFaceColor ) {
  6262. faces.push( getColorIndex( face.color ) );
  6263. }
  6264. if ( hasFaceVertexColor ) {
  6265. var vertexColors = face.vertexColors;
  6266. faces.push(
  6267. getColorIndex( vertexColors[ 0 ] ),
  6268. getColorIndex( vertexColors[ 1 ] ),
  6269. getColorIndex( vertexColors[ 2 ] )
  6270. );
  6271. }
  6272. }
  6273. function setBit( value, position, enabled ) {
  6274. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6275. }
  6276. function getNormalIndex( normal ) {
  6277. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6278. if ( normalsHash[ hash ] !== undefined ) {
  6279. return normalsHash[ hash ];
  6280. }
  6281. normalsHash[ hash ] = normals.length / 3;
  6282. normals.push( normal.x, normal.y, normal.z );
  6283. return normalsHash[ hash ];
  6284. }
  6285. function getColorIndex( color ) {
  6286. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6287. if ( colorsHash[ hash ] !== undefined ) {
  6288. return colorsHash[ hash ];
  6289. }
  6290. colorsHash[ hash ] = colors.length;
  6291. colors.push( color.getHex() );
  6292. return colorsHash[ hash ];
  6293. }
  6294. function getUvIndex( uv ) {
  6295. var hash = uv.x.toString() + uv.y.toString();
  6296. if ( uvsHash[ hash ] !== undefined ) {
  6297. return uvsHash[ hash ];
  6298. }
  6299. uvsHash[ hash ] = uvs.length / 2;
  6300. uvs.push( uv.x, uv.y );
  6301. return uvsHash[ hash ];
  6302. }
  6303. data.data = {};
  6304. data.data.vertices = vertices;
  6305. data.data.normals = normals;
  6306. if ( colors.length > 0 ) data.data.colors = colors;
  6307. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6308. data.data.faces = faces;
  6309. return data;
  6310. },
  6311. clone: function () {
  6312. /*
  6313. // Handle primitives
  6314. var parameters = this.parameters;
  6315. if ( parameters !== undefined ) {
  6316. var values = [];
  6317. for ( var key in parameters ) {
  6318. values.push( parameters[ key ] );
  6319. }
  6320. var geometry = Object.create( this.constructor.prototype );
  6321. this.constructor.apply( geometry, values );
  6322. return geometry;
  6323. }
  6324. return new this.constructor().copy( this );
  6325. */
  6326. return new THREE.Geometry().copy( this );
  6327. },
  6328. copy: function ( source ) {
  6329. this.vertices = [];
  6330. this.faces = [];
  6331. this.faceVertexUvs = [ [] ];
  6332. var vertices = source.vertices;
  6333. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6334. this.vertices.push( vertices[ i ].clone() );
  6335. }
  6336. var faces = source.faces;
  6337. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6338. this.faces.push( faces[ i ].clone() );
  6339. }
  6340. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6341. var faceVertexUvs = source.faceVertexUvs[ i ];
  6342. if ( this.faceVertexUvs[ i ] === undefined ) {
  6343. this.faceVertexUvs[ i ] = [];
  6344. }
  6345. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6346. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6347. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6348. var uv = uvs[ k ];
  6349. uvsCopy.push( uv.clone() );
  6350. }
  6351. this.faceVertexUvs[ i ].push( uvsCopy );
  6352. }
  6353. }
  6354. return this;
  6355. },
  6356. dispose: function () {
  6357. this.dispatchEvent( { type: 'dispose' } );
  6358. }
  6359. };
  6360. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  6361. THREE.GeometryIdCount = 0;
  6362. // File:src/core/DirectGeometry.js
  6363. /**
  6364. * @author mrdoob / http://mrdoob.com/
  6365. */
  6366. THREE.DirectGeometry = function () {
  6367. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6368. this.uuid = THREE.Math.generateUUID();
  6369. this.name = '';
  6370. this.type = 'DirectGeometry';
  6371. this.indices = [];
  6372. this.vertices = [];
  6373. this.normals = [];
  6374. this.colors = [];
  6375. this.uvs = [];
  6376. this.uvs2 = [];
  6377. this.groups = [];
  6378. this.morphTargets = {};
  6379. this.skinWeights = [];
  6380. this.skinIndices = [];
  6381. // this.lineDistances = [];
  6382. this.boundingBox = null;
  6383. this.boundingSphere = null;
  6384. // update flags
  6385. this.verticesNeedUpdate = false;
  6386. this.normalsNeedUpdate = false;
  6387. this.colorsNeedUpdate = false;
  6388. this.uvsNeedUpdate = false;
  6389. this.groupsNeedUpdate = false;
  6390. };
  6391. THREE.DirectGeometry.prototype = {
  6392. constructor: THREE.DirectGeometry,
  6393. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6394. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6395. computeFaceNormals: function () {
  6396. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6397. },
  6398. computeVertexNormals: function () {
  6399. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6400. },
  6401. computeGroups: function ( geometry ) {
  6402. var group;
  6403. var groups = [];
  6404. var materialIndex;
  6405. var faces = geometry.faces;
  6406. for ( var i = 0; i < faces.length; i ++ ) {
  6407. var face = faces[ i ];
  6408. // materials
  6409. if ( face.materialIndex !== materialIndex ) {
  6410. materialIndex = face.materialIndex;
  6411. if ( group !== undefined ) {
  6412. group.count = ( i * 3 ) - group.start;
  6413. groups.push( group );
  6414. }
  6415. group = {
  6416. start: i * 3,
  6417. materialIndex: materialIndex
  6418. };
  6419. }
  6420. }
  6421. if ( group !== undefined ) {
  6422. group.count = ( i * 3 ) - group.start;
  6423. groups.push( group );
  6424. }
  6425. this.groups = groups;
  6426. },
  6427. fromGeometry: function ( geometry ) {
  6428. var faces = geometry.faces;
  6429. var vertices = geometry.vertices;
  6430. var faceVertexUvs = geometry.faceVertexUvs;
  6431. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6432. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6433. // morphs
  6434. var morphTargets = geometry.morphTargets;
  6435. var morphTargetsLength = morphTargets.length;
  6436. var morphTargetsPosition;
  6437. if ( morphTargetsLength > 0 ) {
  6438. morphTargetsPosition = [];
  6439. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6440. morphTargetsPosition[ i ] = [];
  6441. }
  6442. this.morphTargets.position = morphTargetsPosition;
  6443. }
  6444. var morphNormals = geometry.morphNormals;
  6445. var morphNormalsLength = morphNormals.length;
  6446. var morphTargetsNormal;
  6447. if ( morphNormalsLength > 0 ) {
  6448. morphTargetsNormal = [];
  6449. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6450. morphTargetsNormal[ i ] = [];
  6451. }
  6452. this.morphTargets.normal = morphTargetsNormal;
  6453. }
  6454. // skins
  6455. var skinIndices = geometry.skinIndices;
  6456. var skinWeights = geometry.skinWeights;
  6457. var hasSkinIndices = skinIndices.length === vertices.length;
  6458. var hasSkinWeights = skinWeights.length === vertices.length;
  6459. //
  6460. for ( var i = 0; i < faces.length; i ++ ) {
  6461. var face = faces[ i ];
  6462. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6463. var vertexNormals = face.vertexNormals;
  6464. if ( vertexNormals.length === 3 ) {
  6465. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6466. } else {
  6467. var normal = face.normal;
  6468. this.normals.push( normal, normal, normal );
  6469. }
  6470. var vertexColors = face.vertexColors;
  6471. if ( vertexColors.length === 3 ) {
  6472. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6473. } else {
  6474. var color = face.color;
  6475. this.colors.push( color, color, color );
  6476. }
  6477. if ( hasFaceVertexUv === true ) {
  6478. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6479. if ( vertexUvs !== undefined ) {
  6480. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6481. } else {
  6482. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6483. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6484. }
  6485. }
  6486. if ( hasFaceVertexUv2 === true ) {
  6487. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6488. if ( vertexUvs !== undefined ) {
  6489. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6490. } else {
  6491. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6492. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6493. }
  6494. }
  6495. // morphs
  6496. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6497. var morphTarget = morphTargets[ j ].vertices;
  6498. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6499. }
  6500. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6501. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6502. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6503. }
  6504. // skins
  6505. if ( hasSkinIndices ) {
  6506. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6507. }
  6508. if ( hasSkinWeights ) {
  6509. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6510. }
  6511. }
  6512. this.computeGroups( geometry );
  6513. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6514. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6515. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6516. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6517. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6518. return this;
  6519. },
  6520. dispose: function () {
  6521. this.dispatchEvent( { type: 'dispose' } );
  6522. }
  6523. };
  6524. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6525. // File:src/core/BufferGeometry.js
  6526. /**
  6527. * @author alteredq / http://alteredqualia.com/
  6528. * @author mrdoob / http://mrdoob.com/
  6529. */
  6530. THREE.BufferGeometry = function () {
  6531. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6532. this.uuid = THREE.Math.generateUUID();
  6533. this.name = '';
  6534. this.type = 'BufferGeometry';
  6535. this.index = null;
  6536. this.attributes = {};
  6537. this.morphAttributes = {};
  6538. this.groups = [];
  6539. this.boundingBox = null;
  6540. this.boundingSphere = null;
  6541. this.drawRange = { start: 0, count: Infinity };
  6542. };
  6543. THREE.BufferGeometry.prototype = {
  6544. constructor: THREE.BufferGeometry,
  6545. getIndex: function () {
  6546. return this.index;
  6547. },
  6548. setIndex: function ( index ) {
  6549. this.index = index;
  6550. },
  6551. addAttribute: function ( name, attribute ) {
  6552. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6553. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6554. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6555. return;
  6556. }
  6557. if ( name === 'index' ) {
  6558. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6559. this.setIndex( attribute );
  6560. return;
  6561. }
  6562. this.attributes[ name ] = attribute;
  6563. return this;
  6564. },
  6565. getAttribute: function ( name ) {
  6566. return this.attributes[ name ];
  6567. },
  6568. removeAttribute: function ( name ) {
  6569. delete this.attributes[ name ];
  6570. return this;
  6571. },
  6572. addGroup: function ( start, count, materialIndex ) {
  6573. this.groups.push( {
  6574. start: start,
  6575. count: count,
  6576. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6577. } );
  6578. },
  6579. clearGroups: function () {
  6580. this.groups = [];
  6581. },
  6582. setDrawRange: function ( start, count ) {
  6583. this.drawRange.start = start;
  6584. this.drawRange.count = count;
  6585. },
  6586. applyMatrix: function ( matrix ) {
  6587. var position = this.attributes.position;
  6588. if ( position !== undefined ) {
  6589. matrix.applyToVector3Array( position.array );
  6590. position.needsUpdate = true;
  6591. }
  6592. var normal = this.attributes.normal;
  6593. if ( normal !== undefined ) {
  6594. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6595. normalMatrix.applyToVector3Array( normal.array );
  6596. normal.needsUpdate = true;
  6597. }
  6598. if ( this.boundingBox !== null ) {
  6599. this.computeBoundingBox();
  6600. }
  6601. if ( this.boundingSphere !== null ) {
  6602. this.computeBoundingSphere();
  6603. }
  6604. },
  6605. rotateX: function () {
  6606. // rotate geometry around world x-axis
  6607. var m1;
  6608. return function rotateX( angle ) {
  6609. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6610. m1.makeRotationX( angle );
  6611. this.applyMatrix( m1 );
  6612. return this;
  6613. };
  6614. }(),
  6615. rotateY: function () {
  6616. // rotate geometry around world y-axis
  6617. var m1;
  6618. return function rotateY( angle ) {
  6619. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6620. m1.makeRotationY( angle );
  6621. this.applyMatrix( m1 );
  6622. return this;
  6623. };
  6624. }(),
  6625. rotateZ: function () {
  6626. // rotate geometry around world z-axis
  6627. var m1;
  6628. return function rotateZ( angle ) {
  6629. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6630. m1.makeRotationZ( angle );
  6631. this.applyMatrix( m1 );
  6632. return this;
  6633. };
  6634. }(),
  6635. translate: function () {
  6636. // translate geometry
  6637. var m1;
  6638. return function translate( x, y, z ) {
  6639. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6640. m1.makeTranslation( x, y, z );
  6641. this.applyMatrix( m1 );
  6642. return this;
  6643. };
  6644. }(),
  6645. scale: function () {
  6646. // scale geometry
  6647. var m1;
  6648. return function scale( x, y, z ) {
  6649. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6650. m1.makeScale( x, y, z );
  6651. this.applyMatrix( m1 );
  6652. return this;
  6653. };
  6654. }(),
  6655. lookAt: function () {
  6656. var obj;
  6657. return function lookAt( vector ) {
  6658. if ( obj === undefined ) obj = new THREE.Object3D();
  6659. obj.lookAt( vector );
  6660. obj.updateMatrix();
  6661. this.applyMatrix( obj.matrix );
  6662. };
  6663. }(),
  6664. center: function () {
  6665. this.computeBoundingBox();
  6666. var offset = this.boundingBox.center().negate();
  6667. this.translate( offset.x, offset.y, offset.z );
  6668. return offset;
  6669. },
  6670. setFromObject: function ( object ) {
  6671. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6672. var geometry = object.geometry;
  6673. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6674. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6675. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6676. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6677. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6678. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6679. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6680. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6681. }
  6682. if ( geometry.boundingSphere !== null ) {
  6683. this.boundingSphere = geometry.boundingSphere.clone();
  6684. }
  6685. if ( geometry.boundingBox !== null ) {
  6686. this.boundingBox = geometry.boundingBox.clone();
  6687. }
  6688. } else if ( object instanceof THREE.Mesh ) {
  6689. if ( geometry instanceof THREE.Geometry ) {
  6690. this.fromGeometry( geometry );
  6691. }
  6692. }
  6693. return this;
  6694. },
  6695. updateFromObject: function ( object ) {
  6696. var geometry = object.geometry;
  6697. if ( object instanceof THREE.Mesh ) {
  6698. var direct = geometry.__directGeometry;
  6699. if ( direct === undefined ) {
  6700. return this.fromGeometry( geometry );
  6701. }
  6702. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6703. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6704. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6705. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6706. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6707. geometry.verticesNeedUpdate = false;
  6708. geometry.normalsNeedUpdate = false;
  6709. geometry.colorsNeedUpdate = false;
  6710. geometry.uvsNeedUpdate = false;
  6711. geometry.groupsNeedUpdate = false;
  6712. geometry = direct;
  6713. }
  6714. if ( geometry.verticesNeedUpdate === true ) {
  6715. var attribute = this.attributes.position;
  6716. if ( attribute !== undefined ) {
  6717. attribute.copyVector3sArray( geometry.vertices );
  6718. attribute.needsUpdate = true;
  6719. }
  6720. geometry.verticesNeedUpdate = false;
  6721. }
  6722. if ( geometry.normalsNeedUpdate === true ) {
  6723. var attribute = this.attributes.normal;
  6724. if ( attribute !== undefined ) {
  6725. attribute.copyVector3sArray( geometry.normals );
  6726. attribute.needsUpdate = true;
  6727. }
  6728. geometry.normalsNeedUpdate = false;
  6729. }
  6730. if ( geometry.colorsNeedUpdate === true ) {
  6731. var attribute = this.attributes.color;
  6732. if ( attribute !== undefined ) {
  6733. attribute.copyColorsArray( geometry.colors );
  6734. attribute.needsUpdate = true;
  6735. }
  6736. geometry.colorsNeedUpdate = false;
  6737. }
  6738. if ( geometry.uvsNeedUpdate ) {
  6739. var attribute = this.attributes.uv;
  6740. if ( attribute !== undefined ) {
  6741. attribute.copyVector2sArray( geometry.uvs );
  6742. attribute.needsUpdate = true;
  6743. }
  6744. geometry.uvsNeedUpdate = false;
  6745. }
  6746. if ( geometry.lineDistancesNeedUpdate ) {
  6747. var attribute = this.attributes.lineDistance;
  6748. if ( attribute !== undefined ) {
  6749. attribute.copyArray( geometry.lineDistances );
  6750. attribute.needsUpdate = true;
  6751. }
  6752. geometry.lineDistancesNeedUpdate = false;
  6753. }
  6754. if ( geometry.groupsNeedUpdate ) {
  6755. geometry.computeGroups( object.geometry );
  6756. this.groups = geometry.groups;
  6757. geometry.groupsNeedUpdate = false;
  6758. }
  6759. return this;
  6760. },
  6761. fromGeometry: function ( geometry ) {
  6762. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6763. return this.fromDirectGeometry( geometry.__directGeometry );
  6764. },
  6765. fromDirectGeometry: function ( geometry ) {
  6766. var positions = new Float32Array( geometry.vertices.length * 3 );
  6767. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6768. if ( geometry.normals.length > 0 ) {
  6769. var normals = new Float32Array( geometry.normals.length * 3 );
  6770. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6771. }
  6772. if ( geometry.colors.length > 0 ) {
  6773. var colors = new Float32Array( geometry.colors.length * 3 );
  6774. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6775. }
  6776. if ( geometry.uvs.length > 0 ) {
  6777. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6778. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6779. }
  6780. if ( geometry.uvs2.length > 0 ) {
  6781. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6782. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6783. }
  6784. if ( geometry.indices.length > 0 ) {
  6785. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6786. var indices = new TypeArray( geometry.indices.length * 3 );
  6787. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6788. }
  6789. // groups
  6790. this.groups = geometry.groups;
  6791. // morphs
  6792. for ( var name in geometry.morphTargets ) {
  6793. var array = [];
  6794. var morphTargets = geometry.morphTargets[ name ];
  6795. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6796. var morphTarget = morphTargets[ i ];
  6797. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6798. array.push( attribute.copyVector3sArray( morphTarget ) );
  6799. }
  6800. this.morphAttributes[ name ] = array;
  6801. }
  6802. // skinning
  6803. if ( geometry.skinIndices.length > 0 ) {
  6804. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6805. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6806. }
  6807. if ( geometry.skinWeights.length > 0 ) {
  6808. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6809. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6810. }
  6811. //
  6812. if ( geometry.boundingSphere !== null ) {
  6813. this.boundingSphere = geometry.boundingSphere.clone();
  6814. }
  6815. if ( geometry.boundingBox !== null ) {
  6816. this.boundingBox = geometry.boundingBox.clone();
  6817. }
  6818. return this;
  6819. },
  6820. computeBoundingBox: function () {
  6821. var vector = new THREE.Vector3();
  6822. return function () {
  6823. if ( this.boundingBox === null ) {
  6824. this.boundingBox = new THREE.Box3();
  6825. }
  6826. var positions = this.attributes.position.array;
  6827. if ( positions ) {
  6828. this.boundingBox.setFromArray( positions );
  6829. }
  6830. if ( positions === undefined || positions.length === 0 ) {
  6831. this.boundingBox.min.set( 0, 0, 0 );
  6832. this.boundingBox.max.set( 0, 0, 0 );
  6833. }
  6834. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6835. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6836. }
  6837. };
  6838. }(),
  6839. computeBoundingSphere: function () {
  6840. var box = new THREE.Box3();
  6841. var vector = new THREE.Vector3();
  6842. return function () {
  6843. if ( this.boundingSphere === null ) {
  6844. this.boundingSphere = new THREE.Sphere();
  6845. }
  6846. var positions = this.attributes.position.array;
  6847. if ( positions ) {
  6848. var center = this.boundingSphere.center;
  6849. box.setFromArray( positions );
  6850. box.center( center );
  6851. // hoping to find a boundingSphere with a radius smaller than the
  6852. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6853. var maxRadiusSq = 0;
  6854. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6855. vector.fromArray( positions, i );
  6856. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6857. }
  6858. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6859. if ( isNaN( this.boundingSphere.radius ) ) {
  6860. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6861. }
  6862. }
  6863. };
  6864. }(),
  6865. computeFaceNormals: function () {
  6866. // backwards compatibility
  6867. },
  6868. computeVertexNormals: function () {
  6869. var index = this.index;
  6870. var attributes = this.attributes;
  6871. var groups = this.groups;
  6872. if ( attributes.position ) {
  6873. var positions = attributes.position.array;
  6874. if ( attributes.normal === undefined ) {
  6875. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6876. } else {
  6877. // reset existing normals to zero
  6878. var array = attributes.normal.array;
  6879. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6880. array[ i ] = 0;
  6881. }
  6882. }
  6883. var normals = attributes.normal.array;
  6884. var vA, vB, vC,
  6885. pA = new THREE.Vector3(),
  6886. pB = new THREE.Vector3(),
  6887. pC = new THREE.Vector3(),
  6888. cb = new THREE.Vector3(),
  6889. ab = new THREE.Vector3();
  6890. // indexed elements
  6891. if ( index ) {
  6892. var indices = index.array;
  6893. if ( groups.length === 0 ) {
  6894. this.addGroup( 0, indices.length );
  6895. }
  6896. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6897. var group = groups[ j ];
  6898. var start = group.start;
  6899. var count = group.count;
  6900. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6901. vA = indices[ i + 0 ] * 3;
  6902. vB = indices[ i + 1 ] * 3;
  6903. vC = indices[ i + 2 ] * 3;
  6904. pA.fromArray( positions, vA );
  6905. pB.fromArray( positions, vB );
  6906. pC.fromArray( positions, vC );
  6907. cb.subVectors( pC, pB );
  6908. ab.subVectors( pA, pB );
  6909. cb.cross( ab );
  6910. normals[ vA ] += cb.x;
  6911. normals[ vA + 1 ] += cb.y;
  6912. normals[ vA + 2 ] += cb.z;
  6913. normals[ vB ] += cb.x;
  6914. normals[ vB + 1 ] += cb.y;
  6915. normals[ vB + 2 ] += cb.z;
  6916. normals[ vC ] += cb.x;
  6917. normals[ vC + 1 ] += cb.y;
  6918. normals[ vC + 2 ] += cb.z;
  6919. }
  6920. }
  6921. } else {
  6922. // non-indexed elements (unconnected triangle soup)
  6923. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6924. pA.fromArray( positions, i );
  6925. pB.fromArray( positions, i + 3 );
  6926. pC.fromArray( positions, i + 6 );
  6927. cb.subVectors( pC, pB );
  6928. ab.subVectors( pA, pB );
  6929. cb.cross( ab );
  6930. normals[ i ] = cb.x;
  6931. normals[ i + 1 ] = cb.y;
  6932. normals[ i + 2 ] = cb.z;
  6933. normals[ i + 3 ] = cb.x;
  6934. normals[ i + 4 ] = cb.y;
  6935. normals[ i + 5 ] = cb.z;
  6936. normals[ i + 6 ] = cb.x;
  6937. normals[ i + 7 ] = cb.y;
  6938. normals[ i + 8 ] = cb.z;
  6939. }
  6940. }
  6941. this.normalizeNormals();
  6942. attributes.normal.needsUpdate = true;
  6943. }
  6944. },
  6945. merge: function ( geometry, offset ) {
  6946. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6947. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6948. return;
  6949. }
  6950. if ( offset === undefined ) offset = 0;
  6951. var attributes = this.attributes;
  6952. for ( var key in attributes ) {
  6953. if ( geometry.attributes[ key ] === undefined ) continue;
  6954. var attribute1 = attributes[ key ];
  6955. var attributeArray1 = attribute1.array;
  6956. var attribute2 = geometry.attributes[ key ];
  6957. var attributeArray2 = attribute2.array;
  6958. var attributeSize = attribute2.itemSize;
  6959. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6960. attributeArray1[ j ] = attributeArray2[ i ];
  6961. }
  6962. }
  6963. return this;
  6964. },
  6965. normalizeNormals: function () {
  6966. var normals = this.attributes.normal.array;
  6967. var x, y, z, n;
  6968. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6969. x = normals[ i ];
  6970. y = normals[ i + 1 ];
  6971. z = normals[ i + 2 ];
  6972. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6973. normals[ i ] *= n;
  6974. normals[ i + 1 ] *= n;
  6975. normals[ i + 2 ] *= n;
  6976. }
  6977. },
  6978. toNonIndexed: function () {
  6979. if ( this.index === null ) {
  6980. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  6981. return this;
  6982. }
  6983. var geometry2 = new THREE.BufferGeometry();
  6984. var indices = this.index.array;
  6985. var attributes = this.attributes;
  6986. for ( var name in attributes ) {
  6987. var attribute = attributes[ name ];
  6988. var array = attribute.array;
  6989. var itemSize = attribute.itemSize;
  6990. var array2 = new array.constructor( indices.length * itemSize );
  6991. var index = 0, index2 = 0;
  6992. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  6993. index = indices[ i ] * itemSize;
  6994. for ( var j = 0; j < itemSize; j ++ ) {
  6995. array2[ index2 ++ ] = array[ index ++ ];
  6996. }
  6997. }
  6998. geometry2.addAttribute( name, new THREE.BufferAttribute( array2, itemSize ) );
  6999. }
  7000. return geometry2;
  7001. },
  7002. toJSON: function () {
  7003. var data = {
  7004. metadata: {
  7005. version: 4.4,
  7006. type: 'BufferGeometry',
  7007. generator: 'BufferGeometry.toJSON'
  7008. }
  7009. };
  7010. // standard BufferGeometry serialization
  7011. data.uuid = this.uuid;
  7012. data.type = this.type;
  7013. if ( this.name !== '' ) data.name = this.name;
  7014. if ( this.parameters !== undefined ) {
  7015. var parameters = this.parameters;
  7016. for ( var key in parameters ) {
  7017. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7018. }
  7019. return data;
  7020. }
  7021. data.data = { attributes: {} };
  7022. var index = this.index;
  7023. if ( index !== null ) {
  7024. var array = Array.prototype.slice.call( index.array );
  7025. data.data.index = {
  7026. type: index.array.constructor.name,
  7027. array: array
  7028. };
  7029. }
  7030. var attributes = this.attributes;
  7031. for ( var key in attributes ) {
  7032. var attribute = attributes[ key ];
  7033. var array = Array.prototype.slice.call( attribute.array );
  7034. data.data.attributes[ key ] = {
  7035. itemSize: attribute.itemSize,
  7036. type: attribute.array.constructor.name,
  7037. array: array
  7038. };
  7039. }
  7040. var groups = this.groups;
  7041. if ( groups.length > 0 ) {
  7042. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7043. }
  7044. var boundingSphere = this.boundingSphere;
  7045. if ( boundingSphere !== null ) {
  7046. data.data.boundingSphere = {
  7047. center: boundingSphere.center.toArray(),
  7048. radius: boundingSphere.radius
  7049. };
  7050. }
  7051. return data;
  7052. },
  7053. clone: function () {
  7054. /*
  7055. // Handle primitives
  7056. var parameters = this.parameters;
  7057. if ( parameters !== undefined ) {
  7058. var values = [];
  7059. for ( var key in parameters ) {
  7060. values.push( parameters[ key ] );
  7061. }
  7062. var geometry = Object.create( this.constructor.prototype );
  7063. this.constructor.apply( geometry, values );
  7064. return geometry;
  7065. }
  7066. return new this.constructor().copy( this );
  7067. */
  7068. return new THREE.BufferGeometry().copy( this );
  7069. },
  7070. copy: function ( source ) {
  7071. var index = source.index;
  7072. if ( index !== null ) {
  7073. this.setIndex( index.clone() );
  7074. }
  7075. var attributes = source.attributes;
  7076. for ( var name in attributes ) {
  7077. var attribute = attributes[ name ];
  7078. this.addAttribute( name, attribute.clone() );
  7079. }
  7080. var groups = source.groups;
  7081. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7082. var group = groups[ i ];
  7083. this.addGroup( group.start, group.count );
  7084. }
  7085. return this;
  7086. },
  7087. dispose: function () {
  7088. this.dispatchEvent( { type: 'dispose' } );
  7089. }
  7090. };
  7091. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  7092. THREE.BufferGeometry.MaxIndex = 65535;
  7093. // File:src/core/InstancedBufferGeometry.js
  7094. /**
  7095. * @author benaadams / https://twitter.com/ben_a_adams
  7096. */
  7097. THREE.InstancedBufferGeometry = function () {
  7098. THREE.BufferGeometry.call( this );
  7099. this.type = 'InstancedBufferGeometry';
  7100. this.maxInstancedCount = undefined;
  7101. };
  7102. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  7103. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  7104. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  7105. this.groups.push( {
  7106. start: start,
  7107. count: count,
  7108. instances: instances
  7109. } );
  7110. };
  7111. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  7112. var index = source.index;
  7113. if ( index !== null ) {
  7114. this.setIndex( index.clone() );
  7115. }
  7116. var attributes = source.attributes;
  7117. for ( var name in attributes ) {
  7118. var attribute = attributes[ name ];
  7119. this.addAttribute( name, attribute.clone() );
  7120. }
  7121. var groups = source.groups;
  7122. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7123. var group = groups[ i ];
  7124. this.addGroup( group.start, group.count, group.instances );
  7125. }
  7126. return this;
  7127. };
  7128. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  7129. // File:src/core/Uniform.js
  7130. /**
  7131. * @author mrdoob / http://mrdoob.com/
  7132. */
  7133. THREE.Uniform = function ( type, value ) {
  7134. this.type = type;
  7135. this.value = value;
  7136. this.dynamic = false;
  7137. };
  7138. THREE.Uniform.prototype = {
  7139. constructor: THREE.Uniform,
  7140. onUpdate: function ( callback ) {
  7141. this.dynamic = true;
  7142. this.onUpdateCallback = callback;
  7143. return this;
  7144. }
  7145. };
  7146. // File:src/animation/AnimationClip.js
  7147. /**
  7148. *
  7149. * Reusable set of Tracks that represent an animation.
  7150. *
  7151. * @author Ben Houston / http://clara.io/
  7152. * @author David Sarno / http://lighthaus.us/
  7153. */
  7154. THREE.AnimationClip = function ( name, duration, tracks ) {
  7155. this.name = name || THREE.Math.generateUUID();
  7156. this.tracks = tracks;
  7157. this.duration = ( duration !== undefined ) ? duration : -1;
  7158. // this means it should figure out its duration by scanning the tracks
  7159. if ( this.duration < 0 ) {
  7160. this.resetDuration();
  7161. }
  7162. // maybe only do these on demand, as doing them here could potentially slow down loading
  7163. // but leaving these here during development as this ensures a lot of testing of these functions
  7164. this.trim();
  7165. this.optimize();
  7166. };
  7167. THREE.AnimationClip.prototype = {
  7168. constructor: THREE.AnimationClip,
  7169. resetDuration: function() {
  7170. var tracks = this.tracks,
  7171. duration = 0;
  7172. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  7173. var track = this.tracks[ i ];
  7174. duration = Math.max(
  7175. duration, track.times[ track.times.length - 1 ] );
  7176. }
  7177. this.duration = duration;
  7178. },
  7179. trim: function() {
  7180. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7181. this.tracks[ i ].trim( 0, this.duration );
  7182. }
  7183. return this;
  7184. },
  7185. optimize: function() {
  7186. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7187. this.tracks[ i ].optimize();
  7188. }
  7189. return this;
  7190. }
  7191. };
  7192. // Static methods:
  7193. Object.assign( THREE.AnimationClip, {
  7194. parse: function( json ) {
  7195. var tracks = [],
  7196. jsonTracks = json.tracks,
  7197. frameTime = 1.0 / ( json.fps || 1.0 );
  7198. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  7199. tracks.push( THREE.KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  7200. }
  7201. return new THREE.AnimationClip( json.name, json.duration, tracks );
  7202. },
  7203. toJSON: function( clip ) {
  7204. var tracks = [],
  7205. clipTracks = clip.tracks;
  7206. var json = {
  7207. 'name': clip.name,
  7208. 'duration': clip.duration,
  7209. 'tracks': tracks
  7210. };
  7211. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  7212. tracks.push( THREE.KeyframeTrack.toJSON( clipTracks[ i ] ) );
  7213. }
  7214. return json;
  7215. },
  7216. CreateFromMorphTargetSequence: function( name, morphTargetSequence, fps ) {
  7217. var numMorphTargets = morphTargetSequence.length;
  7218. var tracks = [];
  7219. for ( var i = 0; i < numMorphTargets; i ++ ) {
  7220. var times = [];
  7221. var values = [];
  7222. times.push(
  7223. ( i + numMorphTargets - 1 ) % numMorphTargets,
  7224. i,
  7225. ( i + 1 ) % numMorphTargets );
  7226. values.push( 0, 1, 0 );
  7227. var order = THREE.AnimationUtils.getKeyframeOrder( times );
  7228. times = THREE.AnimationUtils.sortedArray( times, 1, order );
  7229. values = THREE.AnimationUtils.sortedArray( values, 1, order );
  7230. // if there is a key at the first frame, duplicate it as the
  7231. // last frame as well for perfect loop.
  7232. if ( times[ 0 ] === 0 ) {
  7233. times.push( numMorphTargets );
  7234. values.push( values[ 0 ] );
  7235. }
  7236. tracks.push(
  7237. new THREE.NumberKeyframeTrack(
  7238. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  7239. times, values
  7240. ).scale( 1.0 / fps ) );
  7241. }
  7242. return new THREE.AnimationClip( name, -1, tracks );
  7243. },
  7244. findByName: function( clipArray, name ) {
  7245. for ( var i = 0; i < clipArray.length; i ++ ) {
  7246. if ( clipArray[ i ].name === name ) {
  7247. return clipArray[ i ];
  7248. }
  7249. }
  7250. return null;
  7251. },
  7252. CreateClipsFromMorphTargetSequences: function( morphTargets, fps ) {
  7253. var animationToMorphTargets = {};
  7254. // tested with https://regex101.com/ on trick sequences
  7255. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  7256. var pattern = /^([\w-]*?)([\d]+)$/;
  7257. // sort morph target names into animation groups based
  7258. // patterns like Walk_001, Walk_002, Run_001, Run_002
  7259. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  7260. var morphTarget = morphTargets[ i ];
  7261. var parts = morphTarget.name.match( pattern );
  7262. if ( parts && parts.length > 1 ) {
  7263. var name = parts[ 1 ];
  7264. var animationMorphTargets = animationToMorphTargets[ name ];
  7265. if ( ! animationMorphTargets ) {
  7266. animationToMorphTargets[ name ] = animationMorphTargets = [];
  7267. }
  7268. animationMorphTargets.push( morphTarget );
  7269. }
  7270. }
  7271. var clips = [];
  7272. for ( var name in animationToMorphTargets ) {
  7273. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps ) );
  7274. }
  7275. return clips;
  7276. },
  7277. // parse the animation.hierarchy format
  7278. parseAnimation: function( animation, bones, nodeName ) {
  7279. if ( ! animation ) {
  7280. console.error( " no animation in JSONLoader data" );
  7281. return null;
  7282. }
  7283. var addNonemptyTrack = function(
  7284. trackType, trackName, animationKeys, propertyName, destTracks ) {
  7285. // only return track if there are actually keys.
  7286. if ( animationKeys.length !== 0 ) {
  7287. var times = [];
  7288. var values = [];
  7289. THREE.AnimationUtils.flattenJSON(
  7290. animationKeys, times, values, propertyName );
  7291. // empty keys are filtered out, so check again
  7292. if ( times.length !== 0 ) {
  7293. destTracks.push( new trackType( trackName, times, values ) );
  7294. }
  7295. }
  7296. };
  7297. var tracks = [];
  7298. var clipName = animation.name || 'default';
  7299. // automatic length determination in AnimationClip.
  7300. var duration = animation.length || -1;
  7301. var fps = animation.fps || 30;
  7302. var hierarchyTracks = animation.hierarchy || [];
  7303. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7304. var animationKeys = hierarchyTracks[ h ].keys;
  7305. // skip empty tracks
  7306. if ( ! animationKeys || animationKeys.length == 0 ) continue;
  7307. // process morph targets in a way exactly compatible
  7308. // with AnimationHandler.init( animation )
  7309. if ( animationKeys[0].morphTargets ) {
  7310. // figure out all morph targets used in this track
  7311. var morphTargetNames = {};
  7312. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7313. if ( animationKeys[k].morphTargets ) {
  7314. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7315. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7316. }
  7317. }
  7318. }
  7319. // create a track for each morph target with all zero
  7320. // morphTargetInfluences except for the keys in which
  7321. // the morphTarget is named.
  7322. for ( var morphTargetName in morphTargetNames ) {
  7323. var times = [];
  7324. var values = [];
  7325. for ( var m = 0;
  7326. m !== animationKeys[k].morphTargets.length; ++ m ) {
  7327. var animationKey = animationKeys[k];
  7328. times.push( animationKey.time );
  7329. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 )
  7330. }
  7331. tracks.push( new THREE.NumberKeyframeTrack(
  7332. '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  7333. }
  7334. duration = morphTargetNames.length * ( fps || 1.0 );
  7335. } else {
  7336. // ...assume skeletal animation
  7337. var boneName = '.bones[' + bones[ h ].name + ']';
  7338. addNonemptyTrack(
  7339. THREE.VectorKeyframeTrack, boneName + '.position',
  7340. animationKeys, 'pos', tracks );
  7341. addNonemptyTrack(
  7342. THREE.QuaternionKeyframeTrack, boneName + '.quaternion',
  7343. animationKeys, 'rot', tracks );
  7344. addNonemptyTrack(
  7345. THREE.VectorKeyframeTrack, boneName + '.scale',
  7346. animationKeys, 'scl', tracks );
  7347. }
  7348. }
  7349. if ( tracks.length === 0 ) {
  7350. return null;
  7351. }
  7352. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7353. return clip;
  7354. }
  7355. } );
  7356. // File:src/animation/AnimationMixer.js
  7357. /**
  7358. *
  7359. * Player for AnimationClips.
  7360. *
  7361. *
  7362. * @author Ben Houston / http://clara.io/
  7363. * @author David Sarno / http://lighthaus.us/
  7364. * @author tschw
  7365. */
  7366. THREE.AnimationMixer = function( root ) {
  7367. this._root = root;
  7368. this._initMemoryManager();
  7369. this._accuIndex = 0;
  7370. this.time = 0;
  7371. this.timeScale = 1.0;
  7372. };
  7373. THREE.AnimationMixer.prototype = {
  7374. constructor: THREE.AnimationMixer,
  7375. // return an action for a clip optionally using a custom root target
  7376. // object (this method allocates a lot of dynamic memory in case a
  7377. // previously unknown clip/root combination is specified)
  7378. clipAction: function( clip, optionalRoot ) {
  7379. var root = optionalRoot || this._root,
  7380. rootUuid = root.uuid,
  7381. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7382. clipObject = ( clip !== clipName ) ? clip : null,
  7383. actionsForClip = this._actionsByClip[ clipName ],
  7384. prototypeAction;
  7385. if ( actionsForClip !== undefined ) {
  7386. var existingAction =
  7387. actionsForClip.actionByRoot[ rootUuid ];
  7388. if ( existingAction !== undefined ) {
  7389. return existingAction;
  7390. }
  7391. // we know the clip, so we don't have to parse all
  7392. // the bindings again but can just copy
  7393. prototypeAction = actionsForClip.knownActions[ 0 ];
  7394. // also, take the clip from the prototype action
  7395. clipObject = prototypeAction._clip;
  7396. if ( clip !== clipName && clip !== clipObject ) {
  7397. throw new Error(
  7398. "Different clips with the same name detected!" );
  7399. }
  7400. }
  7401. // clip must be known when specified via string
  7402. if ( clipObject === null ) return null;
  7403. // allocate all resources required to run it
  7404. var newAction = new THREE.
  7405. AnimationMixer._Action( this, clipObject, optionalRoot );
  7406. this._bindAction( newAction, prototypeAction );
  7407. // and make the action known to the memory manager
  7408. this._addInactiveAction( newAction, clipName, rootUuid );
  7409. return newAction;
  7410. },
  7411. // get an existing action
  7412. existingAction: function( clip, optionalRoot ) {
  7413. var root = optionalRoot || this._root,
  7414. rootUuid = root.uuid,
  7415. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7416. actionsForClip = this._actionsByClip[ clipName ];
  7417. if ( actionsForClip !== undefined ) {
  7418. return actionsForClip.actionByRoot[ rootUuid ] || null;
  7419. }
  7420. return null;
  7421. },
  7422. // deactivates all previously scheduled actions
  7423. stopAllAction: function() {
  7424. var actions = this._actions,
  7425. nActions = this._nActiveActions,
  7426. bindings = this._bindings,
  7427. nBindings = this._nActiveBindings;
  7428. this._nActiveActions = 0;
  7429. this._nActiveBindings = 0;
  7430. for ( var i = 0; i !== nActions; ++ i ) {
  7431. actions[ i ].reset();
  7432. }
  7433. for ( var i = 0; i !== nBindings; ++ i ) {
  7434. bindings[ i ].useCount = 0;
  7435. }
  7436. return this;
  7437. },
  7438. // advance the time and update apply the animation
  7439. update: function( deltaTime ) {
  7440. deltaTime *= this.timeScale;
  7441. var actions = this._actions,
  7442. nActions = this._nActiveActions,
  7443. time = this.time += deltaTime,
  7444. timeDirection = Math.sign( deltaTime ),
  7445. accuIndex = this._accuIndex ^= 1;
  7446. // run active actions
  7447. for ( var i = 0; i !== nActions; ++ i ) {
  7448. var action = actions[ i ];
  7449. if ( action.enabled ) {
  7450. action._update( time, deltaTime, timeDirection, accuIndex );
  7451. }
  7452. }
  7453. // update scene graph
  7454. var bindings = this._bindings,
  7455. nBindings = this._nActiveBindings;
  7456. for ( var i = 0; i !== nBindings; ++ i ) {
  7457. bindings[ i ].apply( accuIndex );
  7458. }
  7459. return this;
  7460. },
  7461. // return this mixer's root target object
  7462. getRoot: function() {
  7463. return this._root;
  7464. },
  7465. // free all resources specific to a particular clip
  7466. uncacheClip: function( clip ) {
  7467. var actions = this._actions,
  7468. clipName = clip.name,
  7469. actionsByClip = this._actionsByClip,
  7470. actionsForClip = actionsByClip[ clipName ];
  7471. if ( actionsForClip !== undefined ) {
  7472. // note: just calling _removeInactiveAction would mess up the
  7473. // iteration state and also require updating the state we can
  7474. // just throw away
  7475. var actionsToRemove = actionsForClip.knownActions;
  7476. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  7477. var action = actionsToRemove[ i ];
  7478. this._deactivateAction( action );
  7479. var cacheIndex = action._cacheIndex,
  7480. lastInactiveAction = actions[ actions.length - 1 ];
  7481. action._cacheIndex = null;
  7482. action._byClipCacheIndex = null;
  7483. lastInactiveAction._cacheIndex = cacheIndex;
  7484. actions[ cacheIndex ] = lastInactiveAction;
  7485. actions.pop();
  7486. this._removeInactiveBindingsForAction( action );
  7487. }
  7488. delete actionsByClip[ clipName ];
  7489. }
  7490. },
  7491. // free all resources specific to a particular root target object
  7492. uncacheRoot: function( root ) {
  7493. var rootUuid = root.uuid,
  7494. actionsByClip = this._actionsByClip;
  7495. for ( var clipName in actionsByClip ) {
  7496. var actionByRoot = actionsByClip[ clipName ].actionByRoot,
  7497. action = actionByRoot[ rootUuid ];
  7498. if ( action !== undefined ) {
  7499. this._deactivateAction( action );
  7500. this._removeInactiveAction( action );
  7501. }
  7502. }
  7503. var bindingsByRoot = this._bindingsByRootAndName,
  7504. bindingByName = bindingsByRoot[ rootUuid ];
  7505. if ( bindingByName !== undefined ) {
  7506. for ( var trackName in bindingByName ) {
  7507. var binding = bindingByName[ trackName ];
  7508. binding.restoreOriginalState();
  7509. this._removeInactiveBinding( binding );
  7510. }
  7511. }
  7512. },
  7513. // remove a targeted clip from the cache
  7514. uncacheAction: function( clip, optionalRoot ) {
  7515. var action = this.existingAction( clip, optionalRoot );
  7516. if ( action !== null ) {
  7517. this._deactivateAction( action );
  7518. this._removeInactiveAction( action );
  7519. }
  7520. }
  7521. };
  7522. THREE.EventDispatcher.prototype.apply( THREE.AnimationMixer.prototype );
  7523. THREE.AnimationMixer._Action =
  7524. function( mixer, clip, localRoot ) {
  7525. this._mixer = mixer;
  7526. this._clip = clip;
  7527. this._localRoot = localRoot || null;
  7528. var tracks = clip.tracks,
  7529. nTracks = tracks.length,
  7530. interpolants = new Array( nTracks );
  7531. var interpolantSettings = {
  7532. endingStart: THREE.ZeroCurvatureEnding,
  7533. endingEnd: THREE.ZeroCurvatureEnding
  7534. };
  7535. for ( var i = 0; i !== nTracks; ++ i ) {
  7536. var interpolant = tracks[ i ].createInterpolant( null );
  7537. interpolants[ i ] = interpolant;
  7538. interpolant.settings = interpolantSettings
  7539. }
  7540. this._interpolantSettings = interpolantSettings;
  7541. this._interpolants = interpolants; // bound by the mixer
  7542. // inside: PropertyMixer (managed by the mixer)
  7543. this._propertyBindings = new Array( nTracks );
  7544. this._cacheIndex = null; // for the memory manager
  7545. this._byClipCacheIndex = null; // for the memory manager
  7546. this._timeScaleInterpolant = null;
  7547. this._weightInterpolant = null;
  7548. this.loop = THREE.LoopRepeat;
  7549. this._loopCount = -1;
  7550. // global mixer time when the action is to be started
  7551. // it's set back to 'null' upon start of the action
  7552. this._startTime = null;
  7553. // scaled local time of the action
  7554. // gets clamped or wrapped to 0..clip.duration according to loop
  7555. this.time = 0;
  7556. this.timeScale = 1;
  7557. this._effectiveTimeScale = 1;
  7558. this.weight = 1;
  7559. this._effectiveWeight = 1;
  7560. this.repetitions = Infinity; // no. of repetitions when looping
  7561. this.paused = false; // false -> zero effective time scale
  7562. this.enabled = true; // true -> zero effective weight
  7563. this.clampWhenFinished = false; // keep feeding the last frame?
  7564. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  7565. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  7566. };
  7567. THREE.AnimationMixer._Action.prototype = {
  7568. constructor: THREE.AnimationMixer._Action,
  7569. // State & Scheduling
  7570. play: function() {
  7571. this._mixer._activateAction( this );
  7572. return this;
  7573. },
  7574. stop: function() {
  7575. this._mixer._deactivateAction( this );
  7576. return this.reset();
  7577. },
  7578. reset: function() {
  7579. this.paused = false;
  7580. this.enabled = true;
  7581. this.time = 0; // restart clip
  7582. this._loopCount = -1; // forget previous loops
  7583. this._startTime = null; // forget scheduling
  7584. return this.stopFading().stopWarping();
  7585. },
  7586. isRunning: function() {
  7587. var start = this._startTime;
  7588. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  7589. this._startTime === null && this._mixer._isActiveAction( this )
  7590. },
  7591. // return true when play has been called
  7592. isScheduled: function() {
  7593. return this._mixer._isActiveAction( this );
  7594. },
  7595. startAt: function( time ) {
  7596. this._startTime = time;
  7597. return this;
  7598. },
  7599. setLoop: function( mode, repetitions ) {
  7600. this.loop = mode;
  7601. this.repetitions = repetitions;
  7602. return this;
  7603. },
  7604. // Weight
  7605. // set the weight stopping any scheduled fading
  7606. // although .enabled = false yields an effective weight of zero, this
  7607. // method does *not* change .enabled, because it would be confusing
  7608. setEffectiveWeight: function( weight ) {
  7609. this.weight = weight;
  7610. // note: same logic as when updated at runtime
  7611. this._effectiveWeight = this.enabled ? weight : 0;
  7612. return this.stopFading();
  7613. },
  7614. // return the weight considering fading and .enabled
  7615. getEffectiveWeight: function() {
  7616. return this._effectiveWeight;
  7617. },
  7618. fadeIn: function( duration ) {
  7619. return this._scheduleFading( duration, 0, 1 );
  7620. },
  7621. fadeOut: function( duration ) {
  7622. return this._scheduleFading( duration, 1, 0 );
  7623. },
  7624. crossFadeFrom: function( fadeOutAction, duration, warp ) {
  7625. var mixer = this._mixer;
  7626. fadeOutAction.fadeOut( duration );
  7627. this.fadeIn( duration );
  7628. if( warp ) {
  7629. var fadeInDuration = this._clip.duration,
  7630. fadeOutDuration = fadeOutAction._clip.duration,
  7631. startEndRatio = fadeOutDuration / fadeInDuration,
  7632. endStartRatio = fadeInDuration / fadeOutDuration;
  7633. fadeOutAction.warp( 1.0, startEndRatio, duration );
  7634. this.warp( endStartRatio, 1.0, duration );
  7635. }
  7636. return this;
  7637. },
  7638. crossFadeTo: function( fadeInAction, duration, warp ) {
  7639. return fadeInAction.crossFadeFrom( this, duration, warp );
  7640. },
  7641. stopFading: function() {
  7642. var weightInterpolant = this._weightInterpolant;
  7643. if ( weightInterpolant !== null ) {
  7644. this._weightInterpolant = null;
  7645. this._mixer._takeBackControlInterpolant( weightInterpolant );
  7646. }
  7647. return this;
  7648. },
  7649. // Time Scale Control
  7650. // set the weight stopping any scheduled warping
  7651. // although .paused = true yields an effective time scale of zero, this
  7652. // method does *not* change .paused, because it would be confusing
  7653. setEffectiveTimeScale: function( timeScale ) {
  7654. this.timeScale = timeScale;
  7655. this._effectiveTimeScale = this.paused ? 0 :timeScale;
  7656. return this.stopWarping();
  7657. },
  7658. // return the time scale considering warping and .paused
  7659. getEffectiveTimeScale: function() {
  7660. return this._effectiveTimeScale;
  7661. },
  7662. setDuration: function( duration ) {
  7663. this.timeScale = this._clip.duration / duration;
  7664. return this.stopWarping();
  7665. },
  7666. syncWith: function( action ) {
  7667. this.time = action.time;
  7668. this.timeScale = action.timeScale;
  7669. return this.stopWarping();
  7670. },
  7671. halt: function( duration ) {
  7672. return this.warp( this._currentTimeScale, 0, duration );
  7673. },
  7674. warp: function( startTimeScale, endTimeScale, duration ) {
  7675. var mixer = this._mixer, now = mixer.time,
  7676. interpolant = this._timeScaleInterpolant,
  7677. timeScale = this.timeScale;
  7678. if ( interpolant === null ) {
  7679. interpolant = mixer._lendControlInterpolant(),
  7680. this._timeScaleInterpolant = interpolant;
  7681. }
  7682. var times = interpolant.parameterPositions,
  7683. values = interpolant.sampleValues;
  7684. times[ 0 ] = now;
  7685. times[ 1 ] = now + duration;
  7686. values[ 0 ] = startTimeScale / timeScale;
  7687. values[ 1 ] = endTimeScale / timeScale;
  7688. return this;
  7689. },
  7690. stopWarping: function() {
  7691. var timeScaleInterpolant = this._timeScaleInterpolant;
  7692. if ( timeScaleInterpolant !== null ) {
  7693. this._timeScaleInterpolant = null;
  7694. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  7695. }
  7696. return this;
  7697. },
  7698. // Object Accessors
  7699. getMixer: function() {
  7700. return this._mixer;
  7701. },
  7702. getClip: function() {
  7703. return this._clip;
  7704. },
  7705. getRoot: function() {
  7706. return this._localRoot || this._mixer._root;
  7707. },
  7708. // Interna
  7709. _update: function( time, deltaTime, timeDirection, accuIndex ) {
  7710. // called by the mixer
  7711. var startTime = this._startTime;
  7712. if ( startTime !== null ) {
  7713. // check for scheduled start of action
  7714. var timeRunning = ( time - startTime ) * timeDirection;
  7715. if ( timeRunning < 0 || timeDirection === 0 ) {
  7716. return; // yet to come / don't decide when delta = 0
  7717. }
  7718. // start
  7719. this._startTime = null; // unschedule
  7720. deltaTime = timeDirection * timeRunning;
  7721. }
  7722. // apply time scale and advance time
  7723. deltaTime *= this._updateTimeScale( time );
  7724. var clipTime = this._updateTime( deltaTime );
  7725. // note: _updateTime may disable the action resulting in
  7726. // an effective weight of 0
  7727. var weight = this._updateWeight( time );
  7728. if ( weight > 0 ) {
  7729. var interpolants = this._interpolants;
  7730. var propertyMixers = this._propertyBindings;
  7731. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  7732. interpolants[ j ].evaluate( clipTime );
  7733. propertyMixers[ j ].accumulate( accuIndex, weight );
  7734. }
  7735. }
  7736. },
  7737. _updateWeight: function( time ) {
  7738. var weight = 0;
  7739. if ( this.enabled ) {
  7740. weight = this.weight;
  7741. var interpolant = this._weightInterpolant;
  7742. if ( interpolant !== null ) {
  7743. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7744. weight *= interpolantValue;
  7745. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7746. this.stopFading();
  7747. if ( interpolantValue === 0 ) {
  7748. // faded out, disable
  7749. this.enabled = false;
  7750. }
  7751. }
  7752. }
  7753. }
  7754. this._effectiveWeight = weight;
  7755. return weight;
  7756. },
  7757. _updateTimeScale: function( time ) {
  7758. var timeScale = 0;
  7759. if ( ! this.paused ) {
  7760. timeScale = this.timeScale;
  7761. var interpolant = this._timeScaleInterpolant;
  7762. if ( interpolant !== null ) {
  7763. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7764. timeScale *= interpolantValue;
  7765. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7766. this.stopWarping();
  7767. if ( timeScale === 0 ) {
  7768. // motion has halted, pause
  7769. this.pause = true;
  7770. } else {
  7771. // warp done - apply final time scale
  7772. this.timeScale = timeScale;
  7773. }
  7774. }
  7775. }
  7776. }
  7777. this._effectiveTimeScale = timeScale;
  7778. return timeScale;
  7779. },
  7780. _updateTime: function( deltaTime ) {
  7781. var time = this.time + deltaTime;
  7782. if ( deltaTime === 0 ) return time;
  7783. var duration = this._clip.duration,
  7784. loop = this.loop,
  7785. loopCount = this._loopCount,
  7786. pingPong = false;
  7787. switch ( loop ) {
  7788. case THREE.LoopOnce:
  7789. if ( loopCount === -1 ) {
  7790. // just started
  7791. this.loopCount = 0;
  7792. this._setEndings( true, true, false );
  7793. }
  7794. if ( time >= duration ) {
  7795. time = duration;
  7796. } else if ( time < 0 ) {
  7797. time = 0;
  7798. } else break;
  7799. // reached the end
  7800. if ( this.clampWhenFinished ) this.pause = true;
  7801. else this.enabled = false;
  7802. this._mixer.dispatchEvent( {
  7803. type: 'finished', action: this,
  7804. direction: deltaTime < 0 ? -1 : 1
  7805. } );
  7806. break;
  7807. case THREE.LoopPingPong:
  7808. pingPong = true;
  7809. case THREE.LoopRepeat:
  7810. if ( loopCount === -1 ) {
  7811. // just started
  7812. if ( deltaTime > 0 ) {
  7813. loopCount = 0;
  7814. this._setEndings(
  7815. true, this.repetitions === 0, pingPong );
  7816. } else {
  7817. // when looping in reverse direction, the initial
  7818. // transition through zero counts as a repetition,
  7819. // so leave loopCount at -1
  7820. this._setEndings(
  7821. this.repetitions === 0, true, pingPong );
  7822. }
  7823. }
  7824. if ( time >= duration || time < 0 ) {
  7825. // wrap around
  7826. var loopDelta = Math.floor( time / duration ); // signed
  7827. time -= duration * loopDelta;
  7828. loopCount += Math.abs( loopDelta );
  7829. var pending = this.repetitions - loopCount;
  7830. if ( pending < 0 ) {
  7831. // stop (switch state, clamp time, fire event)
  7832. if ( this.clampWhenFinished ) this.paused = true;
  7833. else this.enabled = false;
  7834. time = deltaTime > 0 ? duration : 0;
  7835. this._mixer.dispatchEvent( {
  7836. type: 'finished', action: this,
  7837. direction: deltaTime > 0 ? 1 : -1
  7838. } );
  7839. break;
  7840. } else if ( pending === 0 ) {
  7841. // transition to last round
  7842. var atStart = deltaTime < 0;
  7843. this._setEndings( atStart, ! atStart, pingPong );
  7844. } else {
  7845. this._setEndings( false, false, pingPong );
  7846. }
  7847. this._loopCount = loopCount;
  7848. this._mixer.dispatchEvent( {
  7849. type: 'loop', action: this, loopDelta: loopDelta
  7850. } );
  7851. }
  7852. if ( loop === THREE.LoopPingPong && ( loopCount & 1 ) === 1 ) {
  7853. // invert time for the "pong round"
  7854. this.time = time;
  7855. return duration - time;
  7856. }
  7857. break;
  7858. }
  7859. this.time = time;
  7860. return time;
  7861. },
  7862. _setEndings: function( atStart, atEnd, pingPong ) {
  7863. var settings = this._interpolantSettings;
  7864. if ( pingPong ) {
  7865. settings.endingStart = THREE.ZeroSlopeEnding;
  7866. settings.endingEnd = THREE.ZeroSlopeEnding;
  7867. } else {
  7868. // assuming for LoopOnce atStart == atEnd == true
  7869. if ( atStart ) {
  7870. settings.endingStart = this.zeroSlopeAtStart ?
  7871. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7872. } else {
  7873. settings.endingStart = THREE.WrapAroundEnding;
  7874. }
  7875. if ( atEnd ) {
  7876. settings.endingEnd = this.zeroSlopeAtEnd ?
  7877. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7878. } else {
  7879. settings.endingEnd = THREE.WrapAroundEnding;
  7880. }
  7881. }
  7882. },
  7883. _scheduleFading: function( duration, weightNow, weightThen ) {
  7884. var mixer = this._mixer, now = mixer.time,
  7885. interpolant = this._weightInterpolant;
  7886. if ( interpolant === null ) {
  7887. interpolant = mixer._lendControlInterpolant(),
  7888. this._weightInterpolant = interpolant;
  7889. }
  7890. var times = interpolant.parameterPositions,
  7891. values = interpolant.sampleValues;
  7892. times[ 0 ] = now; values[ 0 ] = weightNow;
  7893. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  7894. return this;
  7895. }
  7896. };
  7897. // Implementation details:
  7898. Object.assign( THREE.AnimationMixer.prototype, {
  7899. _bindAction: function( action, prototypeAction ) {
  7900. var root = action._localRoot || this._root,
  7901. tracks = action._clip.tracks,
  7902. nTracks = tracks.length,
  7903. bindings = action._propertyBindings,
  7904. interpolants = action._interpolants,
  7905. rootUuid = root.uuid,
  7906. bindingsByRoot = this._bindingsByRootAndName,
  7907. bindingsByName = bindingsByRoot[ rootUuid ];
  7908. if ( bindingsByName === undefined ) {
  7909. bindingsByName = {};
  7910. bindingsByRoot[ rootUuid ] = bindingsByName;
  7911. }
  7912. for ( var i = 0; i !== nTracks; ++ i ) {
  7913. var track = tracks[ i ],
  7914. trackName = track.name,
  7915. binding = bindingsByName[ trackName ];
  7916. if ( binding !== undefined ) {
  7917. bindings[ i ] = binding;
  7918. } else {
  7919. binding = bindings[ i ];
  7920. if ( binding !== undefined ) {
  7921. // existing binding, make sure the cache knows
  7922. if ( binding._cacheIndex === null ) {
  7923. ++ binding.referenceCount;
  7924. this._addInactiveBinding( binding, rootUuid, trackName );
  7925. }
  7926. continue;
  7927. }
  7928. var path = prototypeAction && prototypeAction.
  7929. _propertyBindings[ i ].binding.parsedPath;
  7930. binding = new THREE.PropertyMixer(
  7931. THREE.PropertyBinding.create( root, trackName, path ),
  7932. track.ValueTypeName, track.getValueSize() );
  7933. ++ binding.referenceCount;
  7934. this._addInactiveBinding( binding, rootUuid, trackName );
  7935. bindings[ i ] = binding;
  7936. }
  7937. interpolants[ i ].resultBuffer = binding.buffer;
  7938. }
  7939. },
  7940. _activateAction: function( action ) {
  7941. if ( ! this._isActiveAction( action ) ) {
  7942. if ( action._cacheIndex === null ) {
  7943. // this action has been forgotten by the cache, but the user
  7944. // appears to be still using it -> rebind
  7945. var rootUuid = ( action._localRoot || this._root ).uuid,
  7946. clipName = action._clip.name,
  7947. actionsForClip = this._actionsByClip[ clipName ];
  7948. this._bindAction( action,
  7949. actionsForClip && actionsForClip.knownActions[ 0 ] );
  7950. this._addInactiveAction( action, clipName, rootUuid );
  7951. }
  7952. var bindings = action._propertyBindings;
  7953. // increment reference counts / sort out state
  7954. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  7955. var binding = bindings[ i ];
  7956. if ( binding.useCount ++ === 0 ) {
  7957. this._lendBinding( binding );
  7958. binding.saveOriginalState();
  7959. }
  7960. }
  7961. this._lendAction( action );
  7962. }
  7963. },
  7964. _deactivateAction: function( action ) {
  7965. if ( this._isActiveAction( action ) ) {
  7966. var bindings = action._propertyBindings;
  7967. // decrement reference counts / sort out state
  7968. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  7969. var binding = bindings[ i ];
  7970. if ( -- binding.useCount === 0 ) {
  7971. binding.restoreOriginalState();
  7972. this._takeBackBinding( binding );
  7973. }
  7974. }
  7975. this._takeBackAction( action );
  7976. }
  7977. },
  7978. // Memory manager
  7979. _initMemoryManager: function() {
  7980. this._actions = []; // 'nActiveActions' followed by inactive ones
  7981. this._nActiveActions = 0;
  7982. this._actionsByClip = {};
  7983. // inside:
  7984. // {
  7985. // knownActions: Array< _Action > - used as prototypes
  7986. // actionByRoot: _Action - lookup
  7987. // }
  7988. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  7989. this._nActiveBindings = 0;
  7990. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  7991. this._controlInterpolants = []; // same game as above
  7992. this._nActiveControlInterpolants = 0;
  7993. var scope = this;
  7994. this.stats = {
  7995. actions: {
  7996. get total() { return scope._actions.length; },
  7997. get inUse() { return scope._nActiveActions; }
  7998. },
  7999. bindings: {
  8000. get total() { return scope._bindings.length; },
  8001. get inUse() { return scope._nActiveBindings; }
  8002. },
  8003. controlInterpolants: {
  8004. get total() { return scope._controlInterpolants.length; },
  8005. get inUse() { return scope._nActiveControlInterpolants; }
  8006. }
  8007. };
  8008. },
  8009. // Memory management for _Action objects
  8010. _isActiveAction: function( action ) {
  8011. var index = action._cacheIndex;
  8012. return index !== null && index < this._nActiveActions;
  8013. },
  8014. _addInactiveAction: function( action, clipName, rootUuid ) {
  8015. var actions = this._actions,
  8016. actionsByClip = this._actionsByClip,
  8017. actionsForClip = actionsByClip[ clipName ];
  8018. if ( actionsForClip === undefined ) {
  8019. actionsForClip = {
  8020. knownActions: [ action ],
  8021. actionByRoot: {}
  8022. };
  8023. action._byClipCacheIndex = 0;
  8024. actionsByClip[ clipName ] = actionsForClip;
  8025. } else {
  8026. var knownActions = actionsForClip.knownActions;
  8027. action._byClipCacheIndex = knownActions.length;
  8028. knownActions.push( action );
  8029. }
  8030. action._cacheIndex = actions.length;
  8031. actions.push( action );
  8032. actionsForClip.actionByRoot[ rootUuid ] = action;
  8033. },
  8034. _removeInactiveAction: function( action ) {
  8035. var actions = this._actions,
  8036. lastInactiveAction = actions[ actions.length - 1 ],
  8037. cacheIndex = action._cacheIndex;
  8038. lastInactiveAction._cacheIndex = cacheIndex;
  8039. actions[ cacheIndex ] = lastInactiveAction;
  8040. actions.pop();
  8041. action._cacheIndex = null;
  8042. var clipName = action._clip.name,
  8043. actionsByClip = this._actionsByClip,
  8044. actionsForClip = actionsByClip[ clipName ],
  8045. knownActionsForClip = actionsForClip.knownActions,
  8046. lastKnownAction =
  8047. knownActionsForClip[ knownActionsForClip.length - 1 ],
  8048. byClipCacheIndex = action._byClipCacheIndex;
  8049. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  8050. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  8051. knownActionsForClip.pop();
  8052. action._byClipCacheIndex = null;
  8053. var actionByRoot = actionsForClip.actionByRoot,
  8054. rootUuid = ( actions._localRoot || this._root ).uuid;
  8055. delete actionByRoot[ rootUuid ];
  8056. if ( knownActionsForClip.length === 0 ) {
  8057. delete actionsByClip[ clipName ];
  8058. }
  8059. this._removeInactiveBindingsForAction( action );
  8060. },
  8061. _removeInactiveBindingsForAction: function( action ) {
  8062. var bindings = action._propertyBindings;
  8063. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8064. var binding = bindings[ i ];
  8065. if ( -- binding.referenceCount === 0 ) {
  8066. this._removeInactiveBinding( binding );
  8067. }
  8068. }
  8069. },
  8070. _lendAction: function( action ) {
  8071. // [ active actions | inactive actions ]
  8072. // [ active actions >| inactive actions ]
  8073. // s a
  8074. // <-swap->
  8075. // a s
  8076. var actions = this._actions,
  8077. prevIndex = action._cacheIndex,
  8078. lastActiveIndex = this._nActiveActions ++,
  8079. firstInactiveAction = actions[ lastActiveIndex ];
  8080. action._cacheIndex = lastActiveIndex;
  8081. actions[ lastActiveIndex ] = action;
  8082. firstInactiveAction._cacheIndex = prevIndex;
  8083. actions[ prevIndex ] = firstInactiveAction;
  8084. },
  8085. _takeBackAction: function( action ) {
  8086. // [ active actions | inactive actions ]
  8087. // [ active actions |< inactive actions ]
  8088. // a s
  8089. // <-swap->
  8090. // s a
  8091. var actions = this._actions,
  8092. prevIndex = action._cacheIndex,
  8093. firstInactiveIndex = -- this._nActiveActions,
  8094. lastActiveAction = actions[ firstInactiveIndex ];
  8095. action._cacheIndex = firstInactiveIndex;
  8096. actions[ firstInactiveIndex ] = action;
  8097. lastActiveAction._cacheIndex = prevIndex;
  8098. actions[ prevIndex ] = lastActiveAction;
  8099. },
  8100. // Memory management for PropertyMixer objects
  8101. _addInactiveBinding: function( binding, rootUuid, trackName ) {
  8102. var bindingsByRoot = this._bindingsByRootAndName,
  8103. bindingByName = bindingsByRoot[ rootUuid ],
  8104. bindings = this._bindings;
  8105. if ( bindingByName === undefined ) {
  8106. bindingByName = {};
  8107. bindingsByRoot[ rootUuid ] = bindingByName;
  8108. }
  8109. bindingByName[ trackName ] = binding;
  8110. binding._cacheIndex = bindings.length;
  8111. bindings.push( binding );
  8112. },
  8113. _removeInactiveBinding: function( binding ) {
  8114. var bindings = this._bindings,
  8115. propBinding = binding.binding,
  8116. rootUuid = propBinding.rootNode.uuid,
  8117. trackName = propBinding.path,
  8118. bindingsByRoot = this._bindingsByRootAndName,
  8119. bindingByName = bindingsByRoot[ rootUuid ],
  8120. lastInactiveBinding = bindings[ bindings.length - 1 ],
  8121. cacheIndex = binding._cacheIndex;
  8122. lastInactiveBinding._cacheIndex = cacheIndex;
  8123. bindings[ cacheIndex ] = lastInactiveBinding;
  8124. bindings.pop();
  8125. delete bindingByName[ trackName ];
  8126. remove_empty_map: {
  8127. for ( var _ in bindingByName ) break remove_empty_map;
  8128. delete bindingsByRoot[ rootUuid ];
  8129. }
  8130. },
  8131. _lendBinding: function( binding ) {
  8132. var bindings = this._bindings,
  8133. prevIndex = binding._cacheIndex,
  8134. lastActiveIndex = this._nActiveBindings ++,
  8135. firstInactiveBinding = bindings[ lastActiveIndex ];
  8136. binding._cacheIndex = lastActiveIndex;
  8137. bindings[ lastActiveIndex ] = binding;
  8138. firstInactiveBinding._cacheIndex = prevIndex;
  8139. bindings[ prevIndex ] = firstInactiveBinding;
  8140. },
  8141. _takeBackBinding: function( binding ) {
  8142. var bindings = this._bindings,
  8143. prevIndex = binding._cacheIndex,
  8144. firstInactiveIndex = -- this._nActiveBindings,
  8145. lastActiveBinding = bindings[ firstInactiveIndex ];
  8146. binding._cacheIndex = firstInactiveIndex;
  8147. bindings[ firstInactiveIndex ] = binding;
  8148. lastActiveBinding._cacheIndex = prevIndex;
  8149. bindings[ prevIndex ] = lastActiveBinding;
  8150. },
  8151. // Memory management of Interpolants for weight and time scale
  8152. _lendControlInterpolant: function() {
  8153. var interpolants = this._controlInterpolants,
  8154. lastActiveIndex = this._nActiveControlInterpolants ++,
  8155. interpolant = interpolants[ lastActiveIndex ];
  8156. if ( interpolant === undefined ) {
  8157. interpolant = new THREE.LinearInterpolant(
  8158. new Float32Array( 2 ), new Float32Array( 2 ),
  8159. 1, this._controlInterpolantsResultBuffer );
  8160. interpolant.__cacheIndex = lastActiveIndex;
  8161. interpolants[ lastActiveIndex ] = interpolant;
  8162. }
  8163. return interpolant;
  8164. },
  8165. _takeBackControlInterpolant: function( interpolant ) {
  8166. var interpolants = this._controlInterpolants,
  8167. prevIndex = interpolant.__cacheIndex,
  8168. firstInactiveIndex = -- this._nActiveControlInterpolants,
  8169. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  8170. interpolant.__cacheIndex = firstInactiveIndex;
  8171. interpolants[ firstInactiveIndex ] = interpolant;
  8172. lastActiveInterpolant.__cacheIndex = prevIndex;
  8173. interpolants[ prevIndex ] = lastActiveInterpolant;
  8174. },
  8175. _controlInterpolantsResultBuffer: new Float32Array( 1 )
  8176. } );
  8177. // File:src/animation/AnimationObjectGroup.js
  8178. /**
  8179. *
  8180. * A group of objects that receives a shared animation state.
  8181. *
  8182. * Usage:
  8183. *
  8184. * - Add objects you would otherwise pass as 'root' to the
  8185. * constructor or the .clipAction method of AnimationMixer.
  8186. *
  8187. * - Instead pass this object as 'root'.
  8188. *
  8189. * - You can also add and remove objects later when the mixer
  8190. * is running.
  8191. *
  8192. * Note:
  8193. *
  8194. * Objects of this class appear as one object to the mixer,
  8195. * so cache control of the individual objects must be done
  8196. * on the group.
  8197. *
  8198. * Limitation:
  8199. *
  8200. * - The animated properties must be compatible among the
  8201. * all objects in the group.
  8202. *
  8203. * - A single property can either be controlled through a
  8204. * target group or directly, but not both.
  8205. *
  8206. * @author tschw
  8207. */
  8208. THREE.AnimationObjectGroup = function( var_args ) {
  8209. this.uuid = THREE.Math.generateUUID();
  8210. // cached objects followed by the active ones
  8211. this._objects = Array.prototype.slice.call( arguments );
  8212. this.nCachedObjects_ = 0; // threshold
  8213. // note: read by PropertyBinding.Composite
  8214. var indices = {};
  8215. this._indicesByUUID = indices; // for bookkeeping
  8216. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8217. indices[ arguments[ i ].uuid ] = i;
  8218. }
  8219. this._paths = []; // inside: string
  8220. this._parsedPaths = []; // inside: { we don't care, here }
  8221. this._bindings = []; // inside: Array< PropertyBinding >
  8222. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  8223. var scope = this;
  8224. this.stats = {
  8225. objects: {
  8226. get total() { return scope._objects.length; },
  8227. get inUse() { return this.total - scope.nCachedObjects_; }
  8228. },
  8229. get bindingsPerObject() { return scope._bindings.length; }
  8230. };
  8231. };
  8232. THREE.AnimationObjectGroup.prototype = {
  8233. constructor: THREE.AnimationObjectGroup,
  8234. add: function( var_args ) {
  8235. var objects = this._objects,
  8236. nObjects = objects.length,
  8237. nCachedObjects = this.nCachedObjects_,
  8238. indicesByUUID = this._indicesByUUID,
  8239. paths = this._paths,
  8240. parsedPaths = this._parsedPaths,
  8241. bindings = this._bindings,
  8242. nBindings = bindings.length;
  8243. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8244. var object = arguments[ i ],
  8245. uuid = object.uuid,
  8246. index = indicesByUUID[ uuid ];
  8247. if ( index === undefined ) {
  8248. // unknown object -> add it to the ACTIVE region
  8249. index = nObjects ++;
  8250. indicesByUUID[ uuid ] = index;
  8251. objects.push( object );
  8252. // accounting is done, now do the same for all bindings
  8253. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8254. bindings[ j ].push(
  8255. new THREE.PropertyBinding(
  8256. object, paths[ j ], parsedPaths[ j ] ) );
  8257. }
  8258. } else if ( index < nCachedObjects ) {
  8259. var knownObject = objects[ index ];
  8260. // move existing object to the ACTIVE region
  8261. var firstActiveIndex = -- nCachedObjects,
  8262. lastCachedObject = objects[ firstActiveIndex ];
  8263. indicesByUUID[ lastCachedObject.uuid ] = index;
  8264. objects[ index ] = lastCachedObject;
  8265. indicesByUUID[ uuid ] = firstActiveIndex;
  8266. objects[ firstActiveIndex ] = object;
  8267. // accounting is done, now do the same for all bindings
  8268. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8269. var bindingsForPath = bindings[ j ],
  8270. lastCached = bindingsForPath[ firstActiveIndex ],
  8271. binding = bindingsForPath[ index ];
  8272. bindingsForPath[ index ] = lastCached;
  8273. if ( binding === undefined ) {
  8274. // since we do not bother to create new bindings
  8275. // for objects that are cached, the binding may
  8276. // or may not exist
  8277. binding = new THREE.PropertyBinding(
  8278. object, paths[ j ], parsedPaths[ j ] );
  8279. }
  8280. bindingsForPath[ firstActiveIndex ] = binding;
  8281. }
  8282. } else if ( objects[ index ] !== knownObject) {
  8283. console.error( "Different objects with the same UUID " +
  8284. "detected. Clean the caches or recreate your " +
  8285. "infrastructure when reloading scenes..." );
  8286. } // else the object is already where we want it to be
  8287. } // for arguments
  8288. this.nCachedObjects_ = nCachedObjects;
  8289. },
  8290. remove: function( var_args ) {
  8291. var objects = this._objects,
  8292. nObjects = objects.length,
  8293. nCachedObjects = this.nCachedObjects_,
  8294. indicesByUUID = this._indicesByUUID,
  8295. bindings = this._bindings,
  8296. nBindings = bindings.length;
  8297. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8298. var object = arguments[ i ],
  8299. uuid = object.uuid,
  8300. index = indicesByUUID[ uuid ];
  8301. if ( index !== undefined && index >= nCachedObjects ) {
  8302. // move existing object into the CACHED region
  8303. var lastCachedIndex = nCachedObjects ++,
  8304. firstActiveObject = objects[ lastCachedIndex ];
  8305. indicesByUUID[ firstActiveObject.uuid ] = index;
  8306. objects[ index ] = firstActiveObject;
  8307. indicesByUUID[ uuid ] = lastCachedIndex;
  8308. objects[ lastCachedIndex ] = object;
  8309. // accounting is done, now do the same for all bindings
  8310. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8311. var bindingsForPath = bindings[ j ],
  8312. firstActive = bindingsForPath[ lastCachedIndex ],
  8313. binding = bindingsForPath[ index ];
  8314. bindingsForPath[ index ] = firstActive;
  8315. bindingsForPath[ lastCachedIndex ] = binding;
  8316. }
  8317. }
  8318. } // for arguments
  8319. this.nCachedObjects_ = nCachedObjects;
  8320. },
  8321. // remove & forget
  8322. uncache: function( var_args ) {
  8323. var objects = this._objects,
  8324. nObjects = objects.length,
  8325. nCachedObjects = this.nCachedObjects_,
  8326. indicesByUUID = this._indicesByUUID,
  8327. bindings = this._bindings,
  8328. nBindings = bindings.length;
  8329. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8330. var object = arguments[ i ],
  8331. uuid = object.uuid,
  8332. index = indicesByUUID[ uuid ];
  8333. if ( index !== undefined ) {
  8334. delete indicesByUUID[ uuid ];
  8335. if ( index < nCachedObjects ) {
  8336. // object is cached, shrink the CACHED region
  8337. var firstActiveIndex = -- nCachedObjects,
  8338. lastCachedObject = objects[ firstActiveIndex ],
  8339. lastIndex = -- nObjects,
  8340. lastObject = objects[ lastIndex ];
  8341. // last cached object takes this object's place
  8342. indicesByUUID[ lastCachedObject.uuid ] = index;
  8343. objects[ index ] = lastCachedObject;
  8344. // last object goes to the activated slot and pop
  8345. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  8346. objects[ firstActiveIndex ] = lastObject;
  8347. objects.pop();
  8348. // accounting is done, now do the same for all bindings
  8349. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8350. var bindingsForPath = bindings[ j ],
  8351. lastCached = bindingsForPath[ firstActiveIndex ],
  8352. last = bindingsForPath[ lastIndex ];
  8353. bindingsForPath[ index ] = lastCached;
  8354. bindingsForPath[ firstActiveIndex ] = last;
  8355. bindingsForPath.pop();
  8356. }
  8357. } else {
  8358. // object is active, just swap with the last and pop
  8359. var lastIndex = -- nObjects,
  8360. lastObject = objects[ lastIndex ];
  8361. indicesByUUID[ lastObject.uuid ] = index;
  8362. objects[ index ] = lastObject;
  8363. objects.pop();
  8364. // accounting is done, now do the same for all bindings
  8365. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8366. var bindingsForPath = bindings[ j ];
  8367. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  8368. bindingsForPath.pop();
  8369. }
  8370. } // cached or active
  8371. } // if object is known
  8372. } // for arguments
  8373. this.nCachedObjects_ = nCachedObjects;
  8374. },
  8375. // Internal interface used by befriended PropertyBinding.Composite:
  8376. subscribe_: function( path, parsedPath ) {
  8377. // returns an array of bindings for the given path that is changed
  8378. // according to the contained objects in the group
  8379. var indicesByPath = this._bindingsIndicesByPath,
  8380. index = indicesByPath[ path ],
  8381. bindings = this._bindings;
  8382. if ( index !== undefined ) return bindings[ index ];
  8383. var paths = this._paths,
  8384. parsedPaths = this._parsedPaths,
  8385. objects = this._objects,
  8386. nObjects = objects.length,
  8387. nCachedObjects = this.nCachedObjects_,
  8388. bindingsForPath = new Array( nObjects );
  8389. index = bindings.length;
  8390. indicesByPath[ path ] = index;
  8391. paths.push( path );
  8392. parsedPaths.push( parsedPath );
  8393. bindings.push( bindingsForPath );
  8394. for ( var i = nCachedObjects,
  8395. n = objects.length; i !== n; ++ i ) {
  8396. var object = objects[ i ];
  8397. bindingsForPath[ i ] =
  8398. new THREE.PropertyBinding( object, path, parsedPath );
  8399. }
  8400. return bindingsForPath;
  8401. },
  8402. unsubscribe_: function( path ) {
  8403. // tells the group to forget about a property path and no longer
  8404. // update the array previously obtained with 'subscribe_'
  8405. var indicesByPath = this._bindingsIndicesByPath,
  8406. index = indicesByPath[ path ];
  8407. if ( index !== undefined ) {
  8408. var paths = this._paths,
  8409. parsedPaths = this._parsedPaths,
  8410. bindings = this._bindings,
  8411. lastBindingsIndex = bindings.length - 1,
  8412. lastBindings = bindings[ lastBindingsIndex ],
  8413. lastBindingsPath = path[ lastBindingsIndex ];
  8414. indicesByPath[ lastBindingsPath ] = index;
  8415. bindings[ index ] = lastBindings;
  8416. bindings.pop();
  8417. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  8418. parsedPaths.pop();
  8419. paths[ index ] = paths[ lastBindingsIndex ];
  8420. paths.pop();
  8421. }
  8422. }
  8423. };
  8424. // File:src/animation/AnimationUtils.js
  8425. /**
  8426. * @author tschw
  8427. * @author Ben Houston / http://clara.io/
  8428. * @author David Sarno / http://lighthaus.us/
  8429. */
  8430. THREE.AnimationUtils = {
  8431. // same as Array.prototype.slice, but also works on typed arrays
  8432. arraySlice: function( array, from, to ) {
  8433. if ( THREE.AnimationUtils.isTypedArray( array ) ) {
  8434. return new array.constructor( array.subarray( from, to ) );
  8435. }
  8436. return array.slice( from, to );
  8437. },
  8438. // converts an array to a specific type
  8439. convertArray: function( array, type, forceClone ) {
  8440. if ( ! array || // let 'undefined' and 'null' pass
  8441. ! forceClone && array.constructor === type ) return array;
  8442. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  8443. return new type( array ); // create typed array
  8444. }
  8445. return Array.prototype.slice.call( array ); // create Array
  8446. },
  8447. isTypedArray: function( object ) {
  8448. return ArrayBuffer.isView( object ) &&
  8449. ! ( object instanceof DataView );
  8450. },
  8451. // returns an array by which times and values can be sorted
  8452. getKeyframeOrder: function( times ) {
  8453. function compareTime( i, j ) {
  8454. return times[ i ] - times[ j ];
  8455. }
  8456. var n = times.length;
  8457. var result = new Array( n );
  8458. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  8459. result.sort( compareTime );
  8460. return result;
  8461. },
  8462. // uses the array previously returned by 'getKeyframeOrder' to sort data
  8463. sortedArray: function( values, stride, order ) {
  8464. var nValues = values.length;
  8465. var result = new values.constructor( nValues );
  8466. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  8467. var srcOffset = order[ i ] * stride;
  8468. for ( var j = 0; j !== stride; ++ j ) {
  8469. result[ dstOffset ++ ] = values[ srcOffset + j ];
  8470. }
  8471. }
  8472. return result;
  8473. },
  8474. // function for parsing AOS keyframe formats
  8475. flattenJSON: function( jsonKeys, times, values, valuePropertyName ) {
  8476. var i = 1, key = jsonKeys[ 0 ];
  8477. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  8478. key = jsonKeys[ i ++ ];
  8479. }
  8480. if ( key === undefined ) return; // no data
  8481. var value = key[ valuePropertyName ];
  8482. if ( value === undefined ) return; // no data
  8483. if ( Array.isArray( value ) ) {
  8484. do {
  8485. value = key[ valuePropertyName ];
  8486. if ( value !== undefined ) {
  8487. times.push( key.time );
  8488. values.push.apply( values, value ); // push all elements
  8489. }
  8490. key = jsonKeys[ i ++ ];
  8491. } while ( key !== undefined );
  8492. } else if ( value.toArray !== undefined ) {
  8493. // ...assume THREE.Math-ish
  8494. do {
  8495. value = key[ valuePropertyName ];
  8496. if ( value !== undefined ) {
  8497. times.push( key.time );
  8498. value.toArray( values, values.length );
  8499. }
  8500. key = jsonKeys[ i ++ ];
  8501. } while ( key !== undefined );
  8502. } else {
  8503. // otherwise push as-is
  8504. do {
  8505. value = key[ valuePropertyName ];
  8506. if ( value !== undefined ) {
  8507. times.push( key.time );
  8508. values.push( value );
  8509. }
  8510. key = jsonKeys[ i ++ ];
  8511. } while ( key !== undefined );
  8512. }
  8513. }
  8514. };
  8515. // File:src/animation/KeyframeTrack.js
  8516. /**
  8517. *
  8518. * A timed sequence of keyframes for a specific property.
  8519. *
  8520. *
  8521. * @author Ben Houston / http://clara.io/
  8522. * @author David Sarno / http://lighthaus.us/
  8523. * @author tschw
  8524. */
  8525. THREE.KeyframeTrack = function ( name, times, values, interpolation ) {
  8526. if( name === undefined ) throw new Error( "track name is undefined" );
  8527. if( times === undefined || times.length === 0 ) {
  8528. throw new Error( "no keyframes in track named " + name );
  8529. }
  8530. this.name = name;
  8531. this.times = THREE.AnimationUtils.convertArray( times, this.TimeBufferType );
  8532. this.values = THREE.AnimationUtils.convertArray( values, this.ValueBufferType );
  8533. this.setInterpolation( interpolation || this.DefaultInterpolation );
  8534. this.validate();
  8535. this.optimize();
  8536. };
  8537. THREE.KeyframeTrack.prototype = {
  8538. constructor: THREE.KeyframeTrack,
  8539. TimeBufferType: Float32Array,
  8540. ValueBufferType: Float32Array,
  8541. DefaultInterpolation: THREE.InterpolateLinear,
  8542. InterpolantFactoryMethodDiscrete: function( result ) {
  8543. return new THREE.DiscreteInterpolant(
  8544. this.times, this.values, this.getValueSize(), result );
  8545. },
  8546. InterpolantFactoryMethodLinear: function( result ) {
  8547. return new THREE.LinearInterpolant(
  8548. this.times, this.values, this.getValueSize(), result );
  8549. },
  8550. InterpolantFactoryMethodSmooth: function( result ) {
  8551. return new THREE.CubicInterpolant(
  8552. this.times, this.values, this.getValueSize(), result );
  8553. },
  8554. setInterpolation: function( interpolation ) {
  8555. var factoryMethod = undefined;
  8556. switch ( interpolation ) {
  8557. case THREE.InterpolateDiscrete:
  8558. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  8559. break;
  8560. case THREE.InterpolateLinear:
  8561. factoryMethod = this.InterpolantFactoryMethodLinear;
  8562. break;
  8563. case THREE.InterpolateSmooth:
  8564. factoryMethod = this.InterpolantFactoryMethodSmooth;
  8565. break;
  8566. }
  8567. if ( factoryMethod === undefined ) {
  8568. var message = "unsupported interpolation for " +
  8569. this.ValueTypeName + " keyframe track named " + this.name;
  8570. if ( this.createInterpolant === undefined ) {
  8571. // fall back to default, unless the default itself is messed up
  8572. if ( interpolation !== this.DefaultInterpolation ) {
  8573. this.setInterpolation( this.DefaultInterpolation );
  8574. } else {
  8575. throw new Error( message ); // fatal, in this case
  8576. }
  8577. }
  8578. console.warn( message );
  8579. return;
  8580. }
  8581. this.createInterpolant = factoryMethod;
  8582. },
  8583. getInterpolation: function() {
  8584. switch ( this.createInterpolant ) {
  8585. case this.InterpolantFactoryMethodDiscrete:
  8586. return THREE.InterpolateDiscrete;
  8587. case this.InterpolantFactoryMethodLinear:
  8588. return THREE.InterpolateLinear;
  8589. case this.InterpolantFactoryMethodSmooth:
  8590. return THREE.InterpolateSmooth;
  8591. }
  8592. },
  8593. getValueSize: function() {
  8594. return this.values.length / this.times.length;
  8595. },
  8596. // move all keyframes either forwards or backwards in time
  8597. shift: function( timeOffset ) {
  8598. if( timeOffset !== 0.0 ) {
  8599. var times = this.times;
  8600. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8601. times[ i ] += timeOffset;
  8602. }
  8603. }
  8604. return this;
  8605. },
  8606. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  8607. scale: function( timeScale ) {
  8608. if( timeScale !== 1.0 ) {
  8609. var times = this.times;
  8610. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8611. times[ i ] *= timeScale;
  8612. }
  8613. }
  8614. return this;
  8615. },
  8616. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  8617. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  8618. trim: function( startTime, endTime ) {
  8619. var times = this.times,
  8620. nKeys = times.length,
  8621. from = 0,
  8622. to = nKeys - 1;
  8623. while ( from !== nKeys && times[ from ] < startTime ) ++ from;
  8624. while ( to !== -1 && times[ to ] > endTime ) -- to;
  8625. ++ to; // inclusive -> exclusive bound
  8626. if( from !== 0 || to !== nKeys ) {
  8627. // empty tracks are forbidden, so keep at least one keyframe
  8628. if ( from >= to ) to = Math.max( to , 1 ), from = to - 1;
  8629. var stride = this.getValueSize();
  8630. this.times = THREE.AnimationUtils.arraySlice( times, from, to );
  8631. this.values = THREE.AnimationUtils.
  8632. arraySlice( this.values, from * stride, to * stride );
  8633. }
  8634. return this;
  8635. },
  8636. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  8637. validate: function() {
  8638. var valid = true;
  8639. var valueSize = this.getValueSize();
  8640. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  8641. console.error( "invalid value size in track", this );
  8642. valid = false;
  8643. }
  8644. var times = this.times,
  8645. values = this.values,
  8646. nKeys = times.length;
  8647. if( nKeys === 0 ) {
  8648. console.error( "track is empty", this );
  8649. valid = false;
  8650. }
  8651. var prevTime = null;
  8652. for( var i = 0; i !== nKeys; i ++ ) {
  8653. var currTime = times[ i ];
  8654. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  8655. console.error( "time is not a valid number", this, i, currTime );
  8656. valid = false;
  8657. break;
  8658. }
  8659. if( prevTime !== null && prevTime > currTime ) {
  8660. console.error( "out of order keys", this, i, currTime, prevTime );
  8661. valid = false;
  8662. break;
  8663. }
  8664. prevTime = currTime;
  8665. }
  8666. if ( values !== undefined ) {
  8667. if ( THREE.AnimationUtils.isTypedArray( values ) ) {
  8668. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  8669. var value = values[ i ];
  8670. if ( isNaN( value ) ) {
  8671. console.error( "value is not a valid number", this, i, value );
  8672. valid = false;
  8673. break;
  8674. }
  8675. }
  8676. }
  8677. }
  8678. return valid;
  8679. },
  8680. // removes equivalent sequential keys as common in morph target sequences
  8681. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  8682. optimize: function() {
  8683. var times = this.times,
  8684. values = this.values,
  8685. stride = this.getValueSize(),
  8686. writeIndex = 1;
  8687. for( var i = 1, n = times.length - 1; i <= n; ++ i ) {
  8688. var keep = false;
  8689. var time = times[ i ];
  8690. var timeNext = times[ i + 1 ];
  8691. // remove adjacent keyframes scheduled at the same time
  8692. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  8693. // remove unnecessary keyframes same as their neighbors
  8694. var offset = i * stride,
  8695. offsetP = offset - stride,
  8696. offsetN = offset + stride;
  8697. for ( var j = 0; j !== stride; ++ j ) {
  8698. var value = values[ offset + j ];
  8699. if ( value !== values[ offsetP + j ] ||
  8700. value !== values[ offsetN + j ] ) {
  8701. keep = true;
  8702. break;
  8703. }
  8704. }
  8705. }
  8706. // in-place compaction
  8707. if ( keep ) {
  8708. if ( i !== writeIndex ) {
  8709. times[ writeIndex ] = times[ i ];
  8710. var readOffset = i * stride,
  8711. writeOffset = writeIndex * stride;
  8712. for ( var j = 0; j !== stride; ++ j ) {
  8713. values[ writeOffset + j ] = values[ readOffset + j ];
  8714. }
  8715. }
  8716. ++ writeIndex;
  8717. }
  8718. }
  8719. if ( writeIndex !== times.length ) {
  8720. this.times = THREE.AnimationUtils.arraySlice( times, 0, writeIndex );
  8721. this.values = THREE.AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  8722. }
  8723. return this;
  8724. }
  8725. };
  8726. // Static methods:
  8727. Object.assign( THREE.KeyframeTrack, {
  8728. // Serialization (in static context, because of constructor invocation
  8729. // and automatic invocation of .toJSON):
  8730. parse: function( json ) {
  8731. if( json.type === undefined ) {
  8732. throw new Error( "track type undefined, can not parse" );
  8733. }
  8734. var trackType = THREE.KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  8735. if ( json.times === undefined ) {
  8736. console.warn( "legacy JSON format detected, converting" );
  8737. var times = [], values = [];
  8738. THREE.AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  8739. json.times = times;
  8740. json.values = values;
  8741. }
  8742. // derived classes can define a static parse method
  8743. if ( trackType.parse !== undefined ) {
  8744. return trackType.parse( json );
  8745. } else {
  8746. // by default, we asssume a constructor compatible with the base
  8747. return new trackType(
  8748. json.name, json.times, json.values, json.interpolation );
  8749. }
  8750. },
  8751. toJSON: function( track ) {
  8752. var trackType = track.constructor;
  8753. var json;
  8754. // derived classes can define a static toJSON method
  8755. if ( trackType.toJSON !== undefined ) {
  8756. json = trackType.toJSON( track );
  8757. } else {
  8758. // by default, we assume the data can be serialized as-is
  8759. json = {
  8760. 'name': track.name,
  8761. 'times': THREE.AnimationUtils.convertArray( track.times, Array ),
  8762. 'values': THREE.AnimationUtils.convertArray( track.values, Array )
  8763. };
  8764. var interpolation = track.getInterpolation();
  8765. if ( interpolation !== track.DefaultInterpolation ) {
  8766. json.interpolation = interpolation;
  8767. }
  8768. }
  8769. json.type = track.ValueTypeName; // mandatory
  8770. return json;
  8771. },
  8772. _getTrackTypeForValueTypeName: function( typeName ) {
  8773. switch( typeName.toLowerCase() ) {
  8774. case "scalar":
  8775. case "double":
  8776. case "float":
  8777. case "number":
  8778. case "integer":
  8779. return THREE.NumberKeyframeTrack;
  8780. case "vector":
  8781. case "vector2":
  8782. case "vector3":
  8783. case "vector4":
  8784. return THREE.VectorKeyframeTrack;
  8785. case "color":
  8786. return THREE.ColorKeyframeTrack;
  8787. case "quaternion":
  8788. return THREE.QuaternionKeyframeTrack;
  8789. case "bool":
  8790. case "boolean":
  8791. return THREE.BooleanKeyframeTrack;
  8792. case "string":
  8793. return THREE.StringKeyframeTrack;
  8794. };
  8795. throw new Error( "Unsupported typeName: " + typeName );
  8796. }
  8797. } );
  8798. // File:src/animation/PropertyBinding.js
  8799. /**
  8800. *
  8801. * A reference to a real property in the scene graph.
  8802. *
  8803. *
  8804. * @author Ben Houston / http://clara.io/
  8805. * @author David Sarno / http://lighthaus.us/
  8806. * @author tschw
  8807. */
  8808. THREE.PropertyBinding = function ( rootNode, path, parsedPath ) {
  8809. this.path = path;
  8810. this.parsedPath = parsedPath ||
  8811. THREE.PropertyBinding.parseTrackName( path );
  8812. this.node = THREE.PropertyBinding.findNode(
  8813. rootNode, this.parsedPath.nodeName ) || rootNode;
  8814. this.rootNode = rootNode;
  8815. };
  8816. THREE.PropertyBinding.prototype = {
  8817. constructor: THREE.PropertyBinding,
  8818. getValue: function getValue_unbound( targetArray, offset ) {
  8819. this.bind();
  8820. this.getValue( targetArray, offset );
  8821. // Note: This class uses a State pattern on a per-method basis:
  8822. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  8823. // prototype version of these methods with one that represents
  8824. // the bound state. When the property is not found, the methods
  8825. // become no-ops.
  8826. },
  8827. setValue: function getValue_unbound( sourceArray, offset ) {
  8828. this.bind();
  8829. this.setValue( sourceArray, offset );
  8830. },
  8831. // create getter / setter pair for a property in the scene graph
  8832. bind: function() {
  8833. var targetObject = this.node,
  8834. parsedPath = this.parsedPath,
  8835. objectName = parsedPath.objectName,
  8836. propertyName = parsedPath.propertyName,
  8837. propertyIndex = parsedPath.propertyIndex;
  8838. if ( ! targetObject ) {
  8839. targetObject = THREE.PropertyBinding.findNode(
  8840. this.rootNode, parsedPath.nodeName ) || this.rootNode;
  8841. this.node = targetObject;
  8842. }
  8843. // set fail state so we can just 'return' on error
  8844. this.getValue = this._getValue_unavailable;
  8845. this.setValue = this._setValue_unavailable;
  8846. // ensure there is a value node
  8847. if ( ! targetObject ) {
  8848. console.error( " trying to update node for track: " + this.path + " but it wasn't found." );
  8849. return;
  8850. }
  8851. if( objectName ) {
  8852. var objectIndex = parsedPath.objectIndex;
  8853. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  8854. switch ( objectName ) {
  8855. case 'materials':
  8856. if( ! targetObject.material ) {
  8857. console.error( ' can not bind to material as node does not have a material', this );
  8858. return;
  8859. }
  8860. if( ! targetObject.material.materials ) {
  8861. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  8862. return;
  8863. }
  8864. targetObject = targetObject.material.materials;
  8865. break;
  8866. case 'bones':
  8867. if( ! targetObject.skeleton ) {
  8868. console.error( ' can not bind to bones as node does not have a skeleton', this );
  8869. return;
  8870. }
  8871. // potential future optimization: skip this if propertyIndex is already an integer
  8872. // and convert the integer string to a true integer.
  8873. targetObject = targetObject.skeleton.bones;
  8874. // support resolving morphTarget names into indices.
  8875. for ( var i = 0; i < targetObject.length; i ++ ) {
  8876. if ( targetObject[i].name === objectIndex ) {
  8877. objectIndex = i;
  8878. break;
  8879. }
  8880. }
  8881. break;
  8882. default:
  8883. if ( targetObject[ objectName ] === undefined ) {
  8884. console.error( ' can not bind to objectName of node, undefined', this );
  8885. return;
  8886. }
  8887. targetObject = targetObject[ objectName ];
  8888. }
  8889. if ( objectIndex !== undefined ) {
  8890. if( targetObject[ objectIndex ] === undefined ) {
  8891. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  8892. return;
  8893. }
  8894. targetObject = targetObject[ objectIndex ];
  8895. }
  8896. }
  8897. // resolve property
  8898. var nodeProperty = targetObject[ propertyName ];
  8899. if ( ! nodeProperty ) {
  8900. var nodeName = parsedPath.nodeName;
  8901. console.error( " trying to update property for track: " + nodeName +
  8902. '.' + propertyName + " but it wasn't found.", targetObject );
  8903. return;
  8904. }
  8905. // determine versioning scheme
  8906. var versioning = this.Versioning.None;
  8907. if ( targetObject.needsUpdate !== undefined ) { // material
  8908. versioning = this.Versioning.NeedsUpdate;
  8909. this.targetObject = targetObject;
  8910. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  8911. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  8912. this.targetObject = targetObject;
  8913. }
  8914. // determine how the property gets bound
  8915. var bindingType = this.BindingType.Direct;
  8916. if ( propertyIndex !== undefined ) {
  8917. // access a sub element of the property array (only primitives are supported right now)
  8918. if ( propertyName === "morphTargetInfluences" ) {
  8919. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  8920. // support resolving morphTarget names into indices.
  8921. if ( ! targetObject.geometry ) {
  8922. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  8923. return;
  8924. }
  8925. if ( ! targetObject.geometry.morphTargets ) {
  8926. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  8927. return;
  8928. }
  8929. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  8930. if ( targetObject.geometry.morphTargets[i].name === propertyIndex ) {
  8931. propertyIndex = i;
  8932. break;
  8933. }
  8934. }
  8935. }
  8936. bindingType = this.BindingType.ArrayElement;
  8937. this.resolvedProperty = nodeProperty;
  8938. this.propertyIndex = propertyIndex;
  8939. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  8940. // must use copy for Object3D.Euler/Quaternion
  8941. bindingType = this.BindingType.HasFromToArray;
  8942. this.resolvedProperty = nodeProperty;
  8943. } else if ( nodeProperty.length !== undefined ) {
  8944. bindingType = this.BindingType.EntireArray;
  8945. this.resolvedProperty = nodeProperty;
  8946. } else {
  8947. this.propertyName = propertyName;
  8948. }
  8949. // select getter / setter
  8950. this.getValue = this.GetterByBindingType[ bindingType ];
  8951. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  8952. },
  8953. unbind: function() {
  8954. this.node = null;
  8955. // back to the prototype version of getValue / setValue
  8956. // note: avoiding to mutate the shape of 'this' via 'delete'
  8957. this.getValue = this._getValue_unbound;
  8958. this.setValue = this._setValue_unbound;
  8959. }
  8960. };
  8961. Object.assign( THREE.PropertyBinding.prototype, { // prototype, continued
  8962. // these are used to "bind" a nonexistent property
  8963. _getValue_unavailable: function() {},
  8964. _setValue_unavailable: function() {},
  8965. // initial state of these methods that calls 'bind'
  8966. _getValue_unbound: THREE.PropertyBinding.prototype.getValue,
  8967. _setValue_unbound: THREE.PropertyBinding.prototype.setValue,
  8968. BindingType: {
  8969. Direct: 0,
  8970. EntireArray: 1,
  8971. ArrayElement: 2,
  8972. HasFromToArray: 3
  8973. },
  8974. Versioning: {
  8975. None: 0,
  8976. NeedsUpdate: 1,
  8977. MatrixWorldNeedsUpdate: 2
  8978. },
  8979. GetterByBindingType: [
  8980. function getValue_direct( buffer, offset ) {
  8981. buffer[ offset ] = this.node[ this.propertyName ];
  8982. },
  8983. function getValue_array( buffer, offset ) {
  8984. var source = this.resolvedProperty;
  8985. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  8986. buffer[ offset ++ ] = source[ i ];
  8987. }
  8988. },
  8989. function getValue_arrayElement( buffer, offset ) {
  8990. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  8991. },
  8992. function getValue_toArray( buffer, offset ) {
  8993. this.resolvedProperty.toArray( buffer, offset );
  8994. }
  8995. ],
  8996. SetterByBindingTypeAndVersioning: [
  8997. [
  8998. // Direct
  8999. function setValue_direct( buffer, offset ) {
  9000. this.node[ this.propertyName ] = buffer[ offset ];
  9001. },
  9002. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  9003. this.node[ this.propertyName ] = buffer[ offset ];
  9004. this.targetObject.needsUpdate = true;
  9005. },
  9006. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9007. this.node[ this.propertyName ] = buffer[ offset ];
  9008. this.targetObject.matrixWorldNeedsUpdate = true;
  9009. }
  9010. ], [
  9011. // EntireArray
  9012. function setValue_array( buffer, offset ) {
  9013. var dest = this.resolvedProperty;
  9014. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9015. dest[ i ] = buffer[ offset ++ ];
  9016. }
  9017. },
  9018. function setValue_array_setNeedsUpdate( buffer, offset ) {
  9019. var dest = this.resolvedProperty;
  9020. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9021. dest[ i ] = buffer[ offset ++ ];
  9022. }
  9023. this.targetObject.needsUpdate = true;
  9024. },
  9025. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9026. var dest = this.resolvedProperty;
  9027. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9028. dest[ i ] = buffer[ offset ++ ];
  9029. }
  9030. this.targetObject.matrixWorldNeedsUpdate = true;
  9031. }
  9032. ], [
  9033. // ArrayElement
  9034. function setValue_arrayElement( buffer, offset ) {
  9035. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9036. },
  9037. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  9038. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9039. this.targetObject.needsUpdate = true;
  9040. },
  9041. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9042. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9043. this.targetObject.matrixWorldNeedsUpdate = true;
  9044. }
  9045. ], [
  9046. // HasToFromArray
  9047. function setValue_fromArray( buffer, offset ) {
  9048. this.resolvedProperty.fromArray( buffer, offset );
  9049. },
  9050. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  9051. this.resolvedProperty.fromArray( buffer, offset );
  9052. this.targetObject.needsUpdate = true;
  9053. },
  9054. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9055. this.resolvedProperty.fromArray( buffer, offset );
  9056. this.targetObject.matrixWorldNeedsUpdate = true;
  9057. }
  9058. ]
  9059. ]
  9060. } );
  9061. THREE.PropertyBinding.Composite =
  9062. function( targetGroup, path, optionalParsedPath ) {
  9063. var parsedPath = optionalParsedPath ||
  9064. THREE.PropertyBinding.parseTrackName( path );
  9065. this._targetGroup = targetGroup;
  9066. this._bindings = targetGroup.subscribe_( path, parsedPath );
  9067. };
  9068. THREE.PropertyBinding.Composite.prototype = {
  9069. constructor: THREE.PropertyBinding.Composite,
  9070. getValue: function( array, offset ) {
  9071. this.bind(); // bind all binding
  9072. var firstValidIndex = this._targetGroup.nCachedObjects_,
  9073. binding = this._bindings[ firstValidIndex ];
  9074. // and only call .getValue on the first
  9075. if ( binding !== undefined ) binding.getValue( array, offset );
  9076. },
  9077. setValue: function( array, offset ) {
  9078. var bindings = this._bindings;
  9079. for ( var i = this._targetGroup.nCachedObjects_,
  9080. n = bindings.length; i !== n; ++ i ) {
  9081. bindings[ i ].setValue( array, offset );
  9082. }
  9083. },
  9084. bind: function() {
  9085. var bindings = this._bindings;
  9086. for ( var i = this._targetGroup.nCachedObjects_,
  9087. n = bindings.length; i !== n; ++ i ) {
  9088. bindings[ i ].bind();
  9089. }
  9090. },
  9091. unbind: function() {
  9092. var bindings = this._bindings;
  9093. for ( var i = this._targetGroup.nCachedObjects_,
  9094. n = bindings.length; i !== n; ++ i ) {
  9095. bindings[ i ].unbind();
  9096. }
  9097. }
  9098. };
  9099. THREE.PropertyBinding.create = function( root, path, parsedPath ) {
  9100. if ( ! ( root instanceof THREE.AnimationObjectGroup ) ) {
  9101. return new THREE.PropertyBinding( root, path, parsedPath );
  9102. } else {
  9103. return new THREE.PropertyBinding.Composite( root, path, parsedPath );
  9104. }
  9105. };
  9106. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  9107. // matches strings in the form of:
  9108. // nodeName.property
  9109. // nodeName.property[accessor]
  9110. // nodeName.material.property[accessor]
  9111. // uuid.property[accessor]
  9112. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  9113. // parentName/nodeName.property
  9114. // parentName/parentName/nodeName.property[index]
  9115. // .bone[Armature.DEF_cog].position
  9116. // created and tested via https://regex101.com/#javascript
  9117. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_. ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  9118. var matches = re.exec(trackName);
  9119. if( ! matches ) {
  9120. throw new Error( "cannot parse trackName at all: " + trackName );
  9121. }
  9122. if (matches.index === re.lastIndex) {
  9123. re.lastIndex++;
  9124. }
  9125. var results = {
  9126. // directoryName: matches[1], // (tschw) currently unused
  9127. nodeName: matches[3], // allowed to be null, specified root node.
  9128. objectName: matches[5],
  9129. objectIndex: matches[7],
  9130. propertyName: matches[9],
  9131. propertyIndex: matches[11] // allowed to be null, specifies that the whole property is set.
  9132. };
  9133. if( results.propertyName === null || results.propertyName.length === 0 ) {
  9134. throw new Error( "can not parse propertyName from trackName: " + trackName );
  9135. }
  9136. return results;
  9137. };
  9138. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  9139. if( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  9140. return root;
  9141. }
  9142. // search into skeleton bones.
  9143. if( root.skeleton ) {
  9144. var searchSkeleton = function( skeleton ) {
  9145. for( var i = 0; i < skeleton.bones.length; i ++ ) {
  9146. var bone = skeleton.bones[i];
  9147. if( bone.name === nodeName ) {
  9148. return bone;
  9149. }
  9150. }
  9151. return null;
  9152. };
  9153. var bone = searchSkeleton( root.skeleton );
  9154. if( bone ) {
  9155. return bone;
  9156. }
  9157. }
  9158. // search into node subtree.
  9159. if( root.children ) {
  9160. var searchNodeSubtree = function( children ) {
  9161. for( var i = 0; i < children.length; i ++ ) {
  9162. var childNode = children[i];
  9163. if( childNode.name === nodeName || childNode.uuid === nodeName ) {
  9164. return childNode;
  9165. }
  9166. var result = searchNodeSubtree( childNode.children );
  9167. if( result ) return result;
  9168. }
  9169. return null;
  9170. };
  9171. var subTreeNode = searchNodeSubtree( root.children );
  9172. if( subTreeNode ) {
  9173. return subTreeNode;
  9174. }
  9175. }
  9176. return null;
  9177. }
  9178. // File:src/animation/PropertyMixer.js
  9179. /**
  9180. *
  9181. * Buffered scene graph property that allows weighted accumulation.
  9182. *
  9183. *
  9184. * @author Ben Houston / http://clara.io/
  9185. * @author David Sarno / http://lighthaus.us/
  9186. * @author tschw
  9187. */
  9188. THREE.PropertyMixer = function ( binding, typeName, valueSize ) {
  9189. this.binding = binding;
  9190. this.valueSize = valueSize;
  9191. var bufferType = Float64Array,
  9192. mixFunction;
  9193. switch ( typeName ) {
  9194. case 'quaternion': mixFunction = this._slerp; break;
  9195. case 'string':
  9196. case 'bool':
  9197. bufferType = Array, mixFunction = this._select; break;
  9198. default: mixFunction = this._lerp;
  9199. }
  9200. this.buffer = new bufferType( valueSize * 4 );
  9201. // layout: [ incoming | accu0 | accu1 | orig ]
  9202. //
  9203. // interpolators can use .buffer as their .result
  9204. // the data then goes to 'incoming'
  9205. //
  9206. // 'accu0' and 'accu1' are used frame-interleaved for
  9207. // the cumulative result and are compared to detect
  9208. // changes
  9209. //
  9210. // 'orig' stores the original state of the property
  9211. this._mixBufferRegion = mixFunction;
  9212. this.cumulativeWeight = 0;
  9213. this.useCount = 0;
  9214. this.referenceCount = 0;
  9215. };
  9216. THREE.PropertyMixer.prototype = {
  9217. constructor: THREE.PropertyMixer,
  9218. // accumulate data in the 'incoming' region into 'accu<i>'
  9219. accumulate: function( accuIndex, weight ) {
  9220. // note: happily accumulating nothing when weight = 0, the caller knows
  9221. // the weight and shouldn't have made the call in the first place
  9222. var buffer = this.buffer,
  9223. stride = this.valueSize,
  9224. offset = accuIndex * stride + stride,
  9225. currentWeight = this.cumulativeWeight;
  9226. if ( currentWeight === 0 ) {
  9227. // accuN := incoming * weight
  9228. for ( var i = 0; i !== stride; ++ i ) {
  9229. buffer[ offset + i ] = buffer[ i ];
  9230. }
  9231. currentWeight = weight;
  9232. } else {
  9233. // accuN := accuN + incoming * weight
  9234. currentWeight += weight;
  9235. var mix = weight / currentWeight;
  9236. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  9237. }
  9238. this.cumulativeWeight = currentWeight;
  9239. },
  9240. // apply the state of 'accu<i>' to the binding when accus differ
  9241. apply: function( accuIndex ) {
  9242. var stride = this.valueSize,
  9243. buffer = this.buffer,
  9244. offset = accuIndex * stride + stride,
  9245. weight = this.cumulativeWeight,
  9246. binding = this.binding;
  9247. this.cumulativeWeight = 0;
  9248. if ( weight < 1 ) {
  9249. // accuN := accuN + original * ( 1 - cumulativeWeight )
  9250. var originalValueOffset = stride * 3;
  9251. this._mixBufferRegion(
  9252. buffer, offset, originalValueOffset, 1 - weight, stride );
  9253. }
  9254. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  9255. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  9256. // value has changed -> update scene graph
  9257. binding.setValue( buffer, offset );
  9258. break;
  9259. }
  9260. }
  9261. },
  9262. // remember the state of the bound property and copy it to both accus
  9263. saveOriginalState: function() {
  9264. var binding = this.binding;
  9265. var buffer = this.buffer,
  9266. stride = this.valueSize,
  9267. originalValueOffset = stride * 3;
  9268. binding.getValue( buffer, originalValueOffset );
  9269. // accu[0..1] := orig -- initially detect changes against the original
  9270. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  9271. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  9272. }
  9273. this.cumulativeWeight = 0;
  9274. },
  9275. // apply the state previously taken via 'saveOriginalState' to the binding
  9276. restoreOriginalState: function() {
  9277. var originalValueOffset = this.valueSize * 3;
  9278. this.binding.setValue( this.buffer, originalValueOffset );
  9279. },
  9280. // mix functions
  9281. _select: function( buffer, dstOffset, srcOffset, t, stride ) {
  9282. if ( t >= 0.5 ) {
  9283. for ( var i = 0; i !== stride; ++ i ) {
  9284. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  9285. }
  9286. }
  9287. },
  9288. _slerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9289. THREE.Quaternion.slerpFlat( buffer, dstOffset,
  9290. buffer, dstOffset, buffer, srcOffset, t );
  9291. },
  9292. _lerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9293. var s = 1 - t;
  9294. for ( var i = 0; i !== stride; ++ i ) {
  9295. var j = dstOffset + i;
  9296. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  9297. }
  9298. }
  9299. };
  9300. // File:src/animation/tracks/BooleanKeyframeTrack.js
  9301. /**
  9302. *
  9303. * A Track of Boolean keyframe values.
  9304. *
  9305. *
  9306. * @author Ben Houston / http://clara.io/
  9307. * @author David Sarno / http://lighthaus.us/
  9308. * @author tschw
  9309. */
  9310. THREE.BooleanKeyframeTrack = function ( name, times, values ) {
  9311. THREE.KeyframeTrack.call( this, name, times, values );
  9312. };
  9313. THREE.BooleanKeyframeTrack.prototype =
  9314. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9315. constructor: THREE.BooleanKeyframeTrack,
  9316. ValueTypeName: 'bool',
  9317. ValueBufferType: Array,
  9318. DefaultInterpolation: THREE.IntepolateDiscrete,
  9319. InterpolantFactoryMethodLinear: undefined,
  9320. InterpolantFactoryMethodSmooth: undefined
  9321. // Note: Actually this track could have a optimized / compressed
  9322. // representation of a single value and a custom interpolant that
  9323. // computes "firstValue ^ isOdd( index )".
  9324. } );
  9325. // File:src/animation/tracks/NumberKeyframeTrack.js
  9326. /**
  9327. *
  9328. * A Track of numeric keyframe values.
  9329. *
  9330. * @author Ben Houston / http://clara.io/
  9331. * @author David Sarno / http://lighthaus.us/
  9332. * @author tschw
  9333. */
  9334. THREE.NumberKeyframeTrack = function ( name, times, values, interpolation ) {
  9335. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9336. };
  9337. THREE.NumberKeyframeTrack.prototype =
  9338. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9339. constructor: THREE.NumberKeyframeTrack,
  9340. ValueTypeName: 'number',
  9341. // ValueBufferType is inherited
  9342. // DefaultInterpolation is inherited
  9343. } );
  9344. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  9345. /**
  9346. *
  9347. * A Track of quaternion keyframe values.
  9348. *
  9349. * @author Ben Houston / http://clara.io/
  9350. * @author David Sarno / http://lighthaus.us/
  9351. * @author tschw
  9352. */
  9353. THREE.QuaternionKeyframeTrack = function ( name, times, values, interpolation ) {
  9354. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9355. };
  9356. THREE.QuaternionKeyframeTrack.prototype =
  9357. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9358. constructor: THREE.QuaternionKeyframeTrack,
  9359. ValueTypeName: 'quaternion',
  9360. // ValueBufferType is inherited
  9361. DefaultInterpolation: THREE.InterpolateLinear,
  9362. InterpolantFactoryMethodLinear: function( result ) {
  9363. return new THREE.QuaternionLinearInterpolant(
  9364. this.times, this.values, this.getValueSize(), result );
  9365. },
  9366. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  9367. } );
  9368. // File:src/animation/tracks/StringKeyframeTrack.js
  9369. /**
  9370. *
  9371. * A Track that interpolates Strings
  9372. *
  9373. *
  9374. * @author Ben Houston / http://clara.io/
  9375. * @author David Sarno / http://lighthaus.us/
  9376. * @author tschw
  9377. */
  9378. THREE.StringKeyframeTrack = function ( name, times, values, interpolation ) {
  9379. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9380. };
  9381. THREE.StringKeyframeTrack.prototype =
  9382. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9383. constructor: THREE.StringKeyframeTrack,
  9384. ValueTypeName: 'string',
  9385. ValueBufferType: Array,
  9386. DefaultInterpolation: THREE.IntepolateDiscrete,
  9387. InterpolantFactoryMethodLinear: undefined,
  9388. InterpolantFactoryMethodSmooth: undefined
  9389. } );
  9390. // File:src/animation/tracks/VectorKeyframeTrack.js
  9391. /**
  9392. *
  9393. * A Track of vectored keyframe values.
  9394. *
  9395. *
  9396. * @author Ben Houston / http://clara.io/
  9397. * @author David Sarno / http://lighthaus.us/
  9398. * @author tschw
  9399. */
  9400. THREE.VectorKeyframeTrack = function ( name, times, values, interpolation ) {
  9401. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9402. };
  9403. THREE.VectorKeyframeTrack.prototype =
  9404. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9405. constructor: THREE.VectorKeyframeTrack,
  9406. ValueTypeName: 'vector'
  9407. // ValueBufferType is inherited
  9408. // DefaultInterpolation is inherited
  9409. } );
  9410. // File:src/audio/Audio.js
  9411. /**
  9412. * @author mrdoob / http://mrdoob.com/
  9413. */
  9414. THREE.Audio = function ( listener ) {
  9415. THREE.Object3D.call( this );
  9416. this.type = 'Audio';
  9417. this.context = listener.context;
  9418. this.source = this.context.createBufferSource();
  9419. this.source.onended = this.onEnded.bind( this );
  9420. this.gain = this.context.createGain();
  9421. this.gain.connect( listener.getInput() );
  9422. this.autoplay = false;
  9423. this.startTime = 0;
  9424. this.playbackRate = 1;
  9425. this.isPlaying = false;
  9426. this.hasPlaybackControl = true;
  9427. this.sourceType = 'empty';
  9428. this.filter = null;
  9429. };
  9430. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  9431. THREE.Audio.prototype.constructor = THREE.Audio;
  9432. THREE.Audio.prototype.getOutput = function () {
  9433. return this.gain;
  9434. };
  9435. THREE.Audio.prototype.load = function ( file ) {
  9436. var buffer = new THREE.AudioBuffer( this.context );
  9437. buffer.load( file );
  9438. this.setBuffer( buffer );
  9439. return this;
  9440. };
  9441. THREE.Audio.prototype.setNodeSource = function ( audioNode ) {
  9442. this.hasPlaybackControl = false;
  9443. this.sourceType = 'audioNode';
  9444. this.source = audioNode;
  9445. this.connect();
  9446. return this;
  9447. };
  9448. THREE.Audio.prototype.setBuffer = function ( audioBuffer ) {
  9449. var scope = this;
  9450. audioBuffer.onReady( function( buffer ) {
  9451. scope.source.buffer = buffer;
  9452. scope.sourceType = 'buffer';
  9453. if ( scope.autoplay ) scope.play();
  9454. } );
  9455. return this;
  9456. };
  9457. THREE.Audio.prototype.play = function () {
  9458. if ( this.isPlaying === true ) {
  9459. console.warn( 'THREE.Audio: Audio is already playing.' );
  9460. return;
  9461. }
  9462. if ( this.hasPlaybackControl === false ) {
  9463. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9464. return;
  9465. }
  9466. var source = this.context.createBufferSource();
  9467. source.buffer = this.source.buffer;
  9468. source.loop = this.source.loop;
  9469. source.onended = this.source.onended;
  9470. source.start( 0, this.startTime );
  9471. source.playbackRate.value = this.playbackRate;
  9472. this.isPlaying = true;
  9473. this.source = source;
  9474. this.connect();
  9475. };
  9476. THREE.Audio.prototype.pause = function () {
  9477. if ( this.hasPlaybackControl === false ) {
  9478. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9479. return;
  9480. }
  9481. this.source.stop();
  9482. this.startTime = this.context.currentTime;
  9483. };
  9484. THREE.Audio.prototype.stop = function () {
  9485. if ( this.hasPlaybackControl === false ) {
  9486. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9487. return;
  9488. }
  9489. this.source.stop();
  9490. this.startTime = 0;
  9491. };
  9492. THREE.Audio.prototype.connect = function () {
  9493. if ( this.filter !== null ) {
  9494. this.source.connect( this.filter );
  9495. this.filter.connect( this.getOutput() );
  9496. } else {
  9497. this.source.connect( this.getOutput() );
  9498. }
  9499. };
  9500. THREE.Audio.prototype.disconnect = function () {
  9501. if ( this.filter !== null ) {
  9502. this.source.disconnect( this.filter );
  9503. this.filter.disconnect( this.getOutput() );
  9504. } else {
  9505. this.source.disconnect( this.getOutput() );
  9506. }
  9507. };
  9508. THREE.Audio.prototype.getFilter = function () {
  9509. return this.filter;
  9510. };
  9511. THREE.Audio.prototype.setFilter = function ( value ) {
  9512. if ( value === undefined ) value = null;
  9513. if ( this.isPlaying === true ) {
  9514. this.disconnect();
  9515. this.filter = value;
  9516. this.connect();
  9517. } else {
  9518. this.filter = value;
  9519. }
  9520. };
  9521. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  9522. if ( this.hasPlaybackControl === false ) {
  9523. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9524. return;
  9525. }
  9526. this.playbackRate = value;
  9527. if ( this.isPlaying === true ) {
  9528. this.source.playbackRate.value = this.playbackRate;
  9529. }
  9530. };
  9531. THREE.Audio.prototype.getPlaybackRate = function () {
  9532. return this.playbackRate;
  9533. };
  9534. THREE.Audio.prototype.onEnded = function() {
  9535. this.isPlaying = false;
  9536. };
  9537. THREE.Audio.prototype.setLoop = function ( value ) {
  9538. if ( this.hasPlaybackControl === false ) {
  9539. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9540. return;
  9541. }
  9542. this.source.loop = value;
  9543. };
  9544. THREE.Audio.prototype.getLoop = function () {
  9545. if ( this.hasPlaybackControl === false ) {
  9546. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9547. return false;
  9548. }
  9549. return this.source.loop;
  9550. };
  9551. THREE.Audio.prototype.setVolume = function ( value ) {
  9552. this.gain.gain.value = value;
  9553. };
  9554. THREE.Audio.prototype.getVolume = function () {
  9555. return this.gain.gain.value;
  9556. };
  9557. // File:src/audio/AudioAnalyser.js
  9558. /**
  9559. * @author mrdoob / http://mrdoob.com/
  9560. */
  9561. THREE.AudioAnalyser = function ( audio, fftSize ) {
  9562. this.analyser = audio.context.createAnalyser();
  9563. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  9564. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  9565. audio.getOutput().connect( this.analyser );
  9566. };
  9567. THREE.AudioAnalyser.prototype = {
  9568. constructor: THREE.AudioAnalyser,
  9569. getData: function () {
  9570. this.analyser.getByteFrequencyData( this.data );
  9571. return this.data;
  9572. }
  9573. };
  9574. // File:src/audio/AudioBuffer.js
  9575. /**
  9576. * @author mrdoob / http://mrdoob.com/
  9577. */
  9578. THREE.AudioBuffer = function ( context ) {
  9579. this.context = context;
  9580. this.ready = false;
  9581. this.readyCallbacks = [];
  9582. };
  9583. THREE.AudioBuffer.prototype.load = function ( file ) {
  9584. var scope = this;
  9585. var request = new XMLHttpRequest();
  9586. request.open( 'GET', file, true );
  9587. request.responseType = 'arraybuffer';
  9588. request.onload = function ( e ) {
  9589. scope.context.decodeAudioData( this.response, function ( buffer ) {
  9590. scope.buffer = buffer;
  9591. scope.ready = true;
  9592. for ( var i = 0; i < scope.readyCallbacks.length; i ++ ) {
  9593. scope.readyCallbacks[ i ]( scope.buffer );
  9594. }
  9595. scope.readyCallbacks = [];
  9596. } );
  9597. };
  9598. request.send();
  9599. return this;
  9600. };
  9601. THREE.AudioBuffer.prototype.onReady = function ( callback ) {
  9602. if ( this.ready ) {
  9603. callback( this.buffer );
  9604. } else {
  9605. this.readyCallbacks.push( callback );
  9606. }
  9607. };
  9608. // File:src/audio/PositionalAudio.js
  9609. /**
  9610. * @author mrdoob / http://mrdoob.com/
  9611. */
  9612. THREE.PositionalAudio = function ( listener ) {
  9613. THREE.Audio.call( this, listener );
  9614. this.panner = this.context.createPanner();
  9615. this.panner.connect( this.gain );
  9616. };
  9617. THREE.PositionalAudio.prototype = Object.create( THREE.Audio.prototype );
  9618. THREE.PositionalAudio.prototype.constructor = THREE.PositionalAudio;
  9619. THREE.PositionalAudio.prototype.getOutput = function () {
  9620. return this.panner;
  9621. };
  9622. THREE.PositionalAudio.prototype.setRefDistance = function ( value ) {
  9623. this.panner.refDistance = value;
  9624. };
  9625. THREE.PositionalAudio.prototype.getRefDistance = function () {
  9626. return this.panner.refDistance;
  9627. };
  9628. THREE.PositionalAudio.prototype.setRolloffFactor = function ( value ) {
  9629. this.panner.rolloffFactor = value;
  9630. };
  9631. THREE.PositionalAudio.prototype.getRolloffFactor = function () {
  9632. return this.panner.rolloffFactor;
  9633. };
  9634. THREE.PositionalAudio.prototype.setDistanceModel = function ( value ) {
  9635. this.panner.distanceModel = value;
  9636. };
  9637. THREE.PositionalAudio.prototype.getDistanceModel = function () {
  9638. return this.panner.distanceModel;
  9639. };
  9640. THREE.PositionalAudio.prototype.setMaxDistance = function ( value ) {
  9641. this.panner.maxDistance = value;
  9642. };
  9643. THREE.PositionalAudio.prototype.getMaxDistance = function () {
  9644. return this.panner.maxDistance;
  9645. };
  9646. THREE.PositionalAudio.prototype.updateMatrixWorld = ( function () {
  9647. var position = new THREE.Vector3();
  9648. return function updateMatrixWorld( force ) {
  9649. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9650. position.setFromMatrixPosition( this.matrixWorld );
  9651. this.panner.setPosition( position.x, position.y, position.z );
  9652. };
  9653. } )();
  9654. // File:src/audio/AudioListener.js
  9655. /**
  9656. * @author mrdoob / http://mrdoob.com/
  9657. */
  9658. THREE.AudioListener = function () {
  9659. THREE.Object3D.call( this );
  9660. this.type = 'AudioListener';
  9661. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  9662. this.gain = this.context.createGain();
  9663. this.gain.connect( this.context.destination );
  9664. this.filter = null;
  9665. };
  9666. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  9667. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  9668. THREE.AudioListener.prototype.getInput = function () {
  9669. return this.gain;
  9670. };
  9671. THREE.AudioListener.prototype.removeFilter = function ( ) {
  9672. if ( this.filter !== null ) {
  9673. this.gain.disconnect( this.filter );
  9674. this.filter.disconnect( this.context.destination );
  9675. this.gain.connect( this.context.destination );
  9676. this.filter = null;
  9677. }
  9678. };
  9679. THREE.AudioListener.prototype.setFilter = function ( value ) {
  9680. if ( this.filter !== null ) {
  9681. this.gain.disconnect( this.filter );
  9682. this.filter.disconnect( this.context.destination );
  9683. } else {
  9684. this.gain.disconnect( this.context.destination );
  9685. }
  9686. this.filter = value;
  9687. this.gain.connect( this.filter );
  9688. this.filter.connect( this.context.destination );
  9689. };
  9690. THREE.AudioListener.prototype.getFilter = function () {
  9691. return this.filter;
  9692. };
  9693. THREE.AudioListener.prototype.setMasterVolume = function ( value ) {
  9694. this.gain.gain.value = value;
  9695. };
  9696. THREE.AudioListener.prototype.getMasterVolume = function () {
  9697. return this.gain.gain.value;
  9698. };
  9699. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  9700. var position = new THREE.Vector3();
  9701. var quaternion = new THREE.Quaternion();
  9702. var scale = new THREE.Vector3();
  9703. var orientation = new THREE.Vector3();
  9704. return function updateMatrixWorld( force ) {
  9705. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9706. var listener = this.context.listener;
  9707. var up = this.up;
  9708. this.matrixWorld.decompose( position, quaternion, scale );
  9709. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9710. listener.setPosition( position.x, position.y, position.z );
  9711. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  9712. };
  9713. } )();
  9714. // File:src/cameras/Camera.js
  9715. /**
  9716. * @author mrdoob / http://mrdoob.com/
  9717. * @author mikael emtinger / http://gomo.se/
  9718. * @author WestLangley / http://github.com/WestLangley
  9719. */
  9720. THREE.Camera = function () {
  9721. THREE.Object3D.call( this );
  9722. this.type = 'Camera';
  9723. this.matrixWorldInverse = new THREE.Matrix4();
  9724. this.projectionMatrix = new THREE.Matrix4();
  9725. };
  9726. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  9727. THREE.Camera.prototype.constructor = THREE.Camera;
  9728. THREE.Camera.prototype.getWorldDirection = function () {
  9729. var quaternion = new THREE.Quaternion();
  9730. return function ( optionalTarget ) {
  9731. var result = optionalTarget || new THREE.Vector3();
  9732. this.getWorldQuaternion( quaternion );
  9733. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9734. };
  9735. }();
  9736. THREE.Camera.prototype.lookAt = function () {
  9737. // This routine does not support cameras with rotated and/or translated parent(s)
  9738. var m1 = new THREE.Matrix4();
  9739. return function ( vector ) {
  9740. m1.lookAt( this.position, vector, this.up );
  9741. this.quaternion.setFromRotationMatrix( m1 );
  9742. };
  9743. }();
  9744. THREE.Camera.prototype.clone = function () {
  9745. return new this.constructor().copy( this );
  9746. };
  9747. THREE.Camera.prototype.copy = function ( source ) {
  9748. THREE.Object3D.prototype.copy.call( this, source );
  9749. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  9750. this.projectionMatrix.copy( source.projectionMatrix );
  9751. return this;
  9752. };
  9753. // File:src/cameras/CubeCamera.js
  9754. /**
  9755. * Camera for rendering cube maps
  9756. * - renders scene into axis-aligned cube
  9757. *
  9758. * @author alteredq / http://alteredqualia.com/
  9759. */
  9760. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  9761. THREE.Object3D.call( this );
  9762. this.type = 'CubeCamera';
  9763. var fov = 90, aspect = 1;
  9764. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9765. cameraPX.up.set( 0, - 1, 0 );
  9766. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  9767. this.add( cameraPX );
  9768. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9769. cameraNX.up.set( 0, - 1, 0 );
  9770. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  9771. this.add( cameraNX );
  9772. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9773. cameraPY.up.set( 0, 0, 1 );
  9774. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  9775. this.add( cameraPY );
  9776. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9777. cameraNY.up.set( 0, 0, - 1 );
  9778. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  9779. this.add( cameraNY );
  9780. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9781. cameraPZ.up.set( 0, - 1, 0 );
  9782. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  9783. this.add( cameraPZ );
  9784. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9785. cameraNZ.up.set( 0, - 1, 0 );
  9786. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  9787. this.add( cameraNZ );
  9788. var options = { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter };
  9789. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  9790. this.updateCubeMap = function ( renderer, scene ) {
  9791. if ( this.parent === null ) this.updateMatrixWorld();
  9792. var renderTarget = this.renderTarget;
  9793. var generateMipmaps = renderTarget.texture.generateMipmaps;
  9794. renderTarget.texture.generateMipmaps = false;
  9795. renderTarget.activeCubeFace = 0;
  9796. renderer.render( scene, cameraPX, renderTarget );
  9797. renderTarget.activeCubeFace = 1;
  9798. renderer.render( scene, cameraNX, renderTarget );
  9799. renderTarget.activeCubeFace = 2;
  9800. renderer.render( scene, cameraPY, renderTarget );
  9801. renderTarget.activeCubeFace = 3;
  9802. renderer.render( scene, cameraNY, renderTarget );
  9803. renderTarget.activeCubeFace = 4;
  9804. renderer.render( scene, cameraPZ, renderTarget );
  9805. renderTarget.texture.generateMipmaps = generateMipmaps;
  9806. renderTarget.activeCubeFace = 5;
  9807. renderer.render( scene, cameraNZ, renderTarget );
  9808. renderer.setRenderTarget( null );
  9809. };
  9810. };
  9811. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  9812. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  9813. // File:src/cameras/OrthographicCamera.js
  9814. /**
  9815. * @author alteredq / http://alteredqualia.com/
  9816. */
  9817. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  9818. THREE.Camera.call( this );
  9819. this.type = 'OrthographicCamera';
  9820. this.zoom = 1;
  9821. this.left = left;
  9822. this.right = right;
  9823. this.top = top;
  9824. this.bottom = bottom;
  9825. this.near = ( near !== undefined ) ? near : 0.1;
  9826. this.far = ( far !== undefined ) ? far : 2000;
  9827. this.updateProjectionMatrix();
  9828. };
  9829. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  9830. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  9831. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  9832. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  9833. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  9834. var cx = ( this.right + this.left ) / 2;
  9835. var cy = ( this.top + this.bottom ) / 2;
  9836. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  9837. };
  9838. THREE.OrthographicCamera.prototype.copy = function ( source ) {
  9839. THREE.Camera.prototype.copy.call( this, source );
  9840. this.left = source.left;
  9841. this.right = source.right;
  9842. this.top = source.top;
  9843. this.bottom = source.bottom;
  9844. this.near = source.near;
  9845. this.far = source.far;
  9846. this.zoom = source.zoom;
  9847. return this;
  9848. };
  9849. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  9850. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9851. data.object.zoom = this.zoom;
  9852. data.object.left = this.left;
  9853. data.object.right = this.right;
  9854. data.object.top = this.top;
  9855. data.object.bottom = this.bottom;
  9856. data.object.near = this.near;
  9857. data.object.far = this.far;
  9858. return data;
  9859. };
  9860. // File:src/cameras/PerspectiveCamera.js
  9861. /**
  9862. * @author mrdoob / http://mrdoob.com/
  9863. * @author greggman / http://games.greggman.com/
  9864. * @author zz85 / http://www.lab4games.net/zz85/blog
  9865. */
  9866. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  9867. THREE.Camera.call( this );
  9868. this.type = 'PerspectiveCamera';
  9869. this.focalLength = 10;
  9870. this.zoom = 1;
  9871. this.fov = fov !== undefined ? fov : 50;
  9872. this.aspect = aspect !== undefined ? aspect : 1;
  9873. this.near = near !== undefined ? near : 0.1;
  9874. this.far = far !== undefined ? far : 2000;
  9875. this.updateProjectionMatrix();
  9876. };
  9877. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  9878. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  9879. /**
  9880. * Uses Focal Length (in mm) to estimate and set FOV
  9881. * 35mm (full-frame) camera is used if frame size is not specified;
  9882. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  9883. */
  9884. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  9885. if ( frameHeight === undefined ) frameHeight = 24;
  9886. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  9887. this.updateProjectionMatrix();
  9888. };
  9889. /**
  9890. * Sets an offset in a larger frustum. This is useful for multi-window or
  9891. * multi-monitor/multi-machine setups.
  9892. *
  9893. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  9894. * the monitors are in grid like this
  9895. *
  9896. * +---+---+---+
  9897. * | A | B | C |
  9898. * +---+---+---+
  9899. * | D | E | F |
  9900. * +---+---+---+
  9901. *
  9902. * then for each monitor you would call it like this
  9903. *
  9904. * var w = 1920;
  9905. * var h = 1080;
  9906. * var fullWidth = w * 3;
  9907. * var fullHeight = h * 2;
  9908. *
  9909. * --A--
  9910. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  9911. * --B--
  9912. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  9913. * --C--
  9914. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  9915. * --D--
  9916. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  9917. * --E--
  9918. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  9919. * --F--
  9920. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  9921. *
  9922. * Note there is no reason monitors have to be the same size or in a grid.
  9923. */
  9924. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  9925. this.fullWidth = fullWidth;
  9926. this.fullHeight = fullHeight;
  9927. this.x = x;
  9928. this.y = y;
  9929. this.width = width;
  9930. this.height = height;
  9931. this.updateProjectionMatrix();
  9932. };
  9933. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  9934. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  9935. if ( this.fullWidth ) {
  9936. var aspect = this.fullWidth / this.fullHeight;
  9937. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  9938. var bottom = - top;
  9939. var left = aspect * bottom;
  9940. var right = aspect * top;
  9941. var width = Math.abs( right - left );
  9942. var height = Math.abs( top - bottom );
  9943. this.projectionMatrix.makeFrustum(
  9944. left + this.x * width / this.fullWidth,
  9945. left + ( this.x + this.width ) * width / this.fullWidth,
  9946. top - ( this.y + this.height ) * height / this.fullHeight,
  9947. top - this.y * height / this.fullHeight,
  9948. this.near,
  9949. this.far
  9950. );
  9951. } else {
  9952. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  9953. }
  9954. };
  9955. THREE.PerspectiveCamera.prototype.copy = function ( source ) {
  9956. THREE.Camera.prototype.copy.call( this, source );
  9957. this.focalLength = source.focalLength;
  9958. this.zoom = source.zoom;
  9959. this.fov = source.fov;
  9960. this.aspect = source.aspect;
  9961. this.near = source.near;
  9962. this.far = source.far;
  9963. return this;
  9964. };
  9965. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  9966. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9967. data.object.focalLength = this.focalLength;
  9968. data.object.zoom = this.zoom;
  9969. data.object.fov = this.fov;
  9970. data.object.aspect = this.aspect;
  9971. data.object.near = this.near;
  9972. data.object.far = this.far;
  9973. return data;
  9974. };
  9975. // File:src/cameras/StereoCamera.js
  9976. /**
  9977. * @author mrdoob / http://mrdoob.com/
  9978. */
  9979. THREE.StereoCamera = function () {
  9980. this.type = 'StereoCamera';
  9981. this.aspect = 1;
  9982. this.cameraL = new THREE.PerspectiveCamera();
  9983. this.cameraL.layers.enable( 1 );
  9984. this.cameraL.matrixAutoUpdate = false;
  9985. this.cameraR = new THREE.PerspectiveCamera();
  9986. this.cameraR.layers.enable( 2 );
  9987. this.cameraR.matrixAutoUpdate = false;
  9988. };
  9989. THREE.StereoCamera.prototype = {
  9990. constructor: THREE.StereoCamera,
  9991. update: ( function () {
  9992. var focalLength, fov, aspect, near, far;
  9993. var eyeRight = new THREE.Matrix4();
  9994. var eyeLeft = new THREE.Matrix4();
  9995. return function update ( camera ) {
  9996. var needsUpdate = focalLength !== camera.focalLength || fov !== camera.fov ||
  9997. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  9998. far !== camera.far;
  9999. if ( needsUpdate ) {
  10000. focalLength = camera.focalLength;
  10001. fov = camera.fov;
  10002. aspect = camera.aspect * this.aspect;
  10003. near = camera.near;
  10004. far = camera.far;
  10005. // Off-axis stereoscopic effect based on
  10006. // http://paulbourke.net/stereographics/stereorender/
  10007. var projectionMatrix = camera.projectionMatrix.clone();
  10008. var eyeSep = 0.064 / 2;
  10009. var eyeSepOnProjection = eyeSep * near / focalLength;
  10010. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  10011. var xmin, xmax;
  10012. // translate xOffset
  10013. eyeLeft.elements[ 12 ] = - eyeSep;
  10014. eyeRight.elements[ 12 ] = eyeSep;
  10015. // for left eye
  10016. xmin = - ymax * aspect + eyeSepOnProjection;
  10017. xmax = ymax * aspect + eyeSepOnProjection;
  10018. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10019. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10020. this.cameraL.projectionMatrix.copy( projectionMatrix );
  10021. // for right eye
  10022. xmin = - ymax * aspect - eyeSepOnProjection;
  10023. xmax = ymax * aspect - eyeSepOnProjection;
  10024. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10025. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10026. this.cameraR.projectionMatrix.copy( projectionMatrix );
  10027. }
  10028. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  10029. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  10030. };
  10031. } )()
  10032. };
  10033. // File:src/lights/Light.js
  10034. /**
  10035. * @author mrdoob / http://mrdoob.com/
  10036. * @author alteredq / http://alteredqualia.com/
  10037. */
  10038. THREE.Light = function ( color, intensity ) {
  10039. THREE.Object3D.call( this );
  10040. this.type = 'Light';
  10041. this.color = new THREE.Color( color );
  10042. this.intensity = intensity !== undefined ? intensity : 1;
  10043. this.receiveShadow = undefined;
  10044. };
  10045. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  10046. THREE.Light.prototype.constructor = THREE.Light;
  10047. THREE.Light.prototype.copy = function ( source ) {
  10048. THREE.Object3D.prototype.copy.call( this, source );
  10049. this.color.copy( source.color );
  10050. this.intensity = source.intensity;
  10051. return this;
  10052. };
  10053. THREE.Light.prototype.toJSON = function ( meta ) {
  10054. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10055. data.object.color = this.color.getHex();
  10056. data.object.intensity = this.intensity;
  10057. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  10058. if ( this.distance !== undefined ) data.object.distance = this.distance;
  10059. if ( this.angle !== undefined ) data.object.angle = this.angle;
  10060. if ( this.decay !== undefined ) data.object.decay = this.decay;
  10061. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  10062. return data;
  10063. };
  10064. // File:src/lights/LightShadow.js
  10065. /**
  10066. * @author mrdoob / http://mrdoob.com/
  10067. */
  10068. THREE.LightShadow = function ( camera ) {
  10069. this.camera = camera;
  10070. this.bias = 0;
  10071. this.radius = 1;
  10072. this.mapSize = new THREE.Vector2( 512, 512 );
  10073. this.map = null;
  10074. this.matrix = new THREE.Matrix4();
  10075. };
  10076. THREE.LightShadow.prototype = {
  10077. constructor: THREE.LightShadow,
  10078. copy: function ( source ) {
  10079. this.camera = source.camera.clone();
  10080. this.bias = source.bias;
  10081. this.radius = source.radius;
  10082. this.mapSize.copy( source.mapSize );
  10083. return this;
  10084. },
  10085. clone: function () {
  10086. return new this.constructor().copy( this );
  10087. }
  10088. };
  10089. // File:src/lights/AmbientLight.js
  10090. /**
  10091. * @author mrdoob / http://mrdoob.com/
  10092. */
  10093. THREE.AmbientLight = function ( color, intensity ) {
  10094. THREE.Light.call( this, color, intensity );
  10095. this.type = 'AmbientLight';
  10096. this.castShadow = undefined;
  10097. };
  10098. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  10099. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  10100. // File:src/lights/DirectionalLight.js
  10101. /**
  10102. * @author mrdoob / http://mrdoob.com/
  10103. * @author alteredq / http://alteredqualia.com/
  10104. */
  10105. THREE.DirectionalLight = function ( color, intensity ) {
  10106. THREE.Light.call( this, color, intensity );
  10107. this.type = 'DirectionalLight';
  10108. this.position.set( 0, 1, 0 );
  10109. this.updateMatrix();
  10110. this.target = new THREE.Object3D();
  10111. this.shadow = new THREE.LightShadow( new THREE.OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  10112. };
  10113. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  10114. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  10115. THREE.DirectionalLight.prototype.copy = function ( source ) {
  10116. THREE.Light.prototype.copy.call( this, source );
  10117. this.target = source.target.clone();
  10118. this.shadow = source.shadow.clone();
  10119. return this;
  10120. };
  10121. // File:src/lights/HemisphereLight.js
  10122. /**
  10123. * @author alteredq / http://alteredqualia.com/
  10124. */
  10125. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  10126. THREE.Light.call( this, skyColor, intensity );
  10127. this.type = 'HemisphereLight';
  10128. this.castShadow = undefined;
  10129. this.position.set( 0, 1, 0 );
  10130. this.updateMatrix();
  10131. this.groundColor = new THREE.Color( groundColor );
  10132. };
  10133. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  10134. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  10135. THREE.HemisphereLight.prototype.copy = function ( source ) {
  10136. THREE.Light.prototype.copy.call( this, source );
  10137. this.groundColor.copy( source.groundColor );
  10138. return this;
  10139. };
  10140. // File:src/lights/PointLight.js
  10141. /**
  10142. * @author mrdoob / http://mrdoob.com/
  10143. */
  10144. THREE.PointLight = function ( color, intensity, distance, decay ) {
  10145. THREE.Light.call( this, color, intensity );
  10146. this.type = 'PointLight';
  10147. this.distance = ( distance !== undefined ) ? distance : 0;
  10148. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10149. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 90, 1, 0.5, 500 ) );
  10150. };
  10151. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  10152. THREE.PointLight.prototype.constructor = THREE.PointLight;
  10153. THREE.PointLight.prototype.copy = function ( source ) {
  10154. THREE.Light.prototype.copy.call( this, source );
  10155. this.distance = source.distance;
  10156. this.decay = source.decay;
  10157. this.shadow = source.shadow.clone();
  10158. return this;
  10159. };
  10160. // File:src/lights/SpotLight.js
  10161. /**
  10162. * @author alteredq / http://alteredqualia.com/
  10163. */
  10164. THREE.SpotLight = function ( color, intensity, distance, angle, penumbra, decay ) {
  10165. THREE.Light.call( this, color, intensity );
  10166. this.type = 'SpotLight';
  10167. this.position.set( 0, 1, 0 );
  10168. this.updateMatrix();
  10169. this.target = new THREE.Object3D();
  10170. this.distance = ( distance !== undefined ) ? distance : 0;
  10171. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  10172. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  10173. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10174. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 50, 1, 0.5, 500 ) );
  10175. };
  10176. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  10177. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  10178. THREE.SpotLight.prototype.copy = function ( source ) {
  10179. THREE.Light.prototype.copy.call( this, source );
  10180. this.distance = source.distance;
  10181. this.angle = source.angle;
  10182. this.penumbra = source.penumbra;
  10183. this.decay = source.decay;
  10184. this.target = source.target.clone();
  10185. this.shadow = source.shadow.clone();
  10186. return this;
  10187. };
  10188. // File:src/loaders/Cache.js
  10189. /**
  10190. * @author mrdoob / http://mrdoob.com/
  10191. */
  10192. THREE.Cache = {
  10193. enabled: false,
  10194. files: {},
  10195. add: function ( key, file ) {
  10196. if ( this.enabled === false ) return;
  10197. // console.log( 'THREE.Cache', 'Adding key:', key );
  10198. this.files[ key ] = file;
  10199. },
  10200. get: function ( key ) {
  10201. if ( this.enabled === false ) return;
  10202. // console.log( 'THREE.Cache', 'Checking key:', key );
  10203. return this.files[ key ];
  10204. },
  10205. remove: function ( key ) {
  10206. delete this.files[ key ];
  10207. },
  10208. clear: function () {
  10209. this.files = {};
  10210. }
  10211. };
  10212. // File:src/loaders/Loader.js
  10213. /**
  10214. * @author alteredq / http://alteredqualia.com/
  10215. */
  10216. THREE.Loader = function () {
  10217. this.onLoadStart = function () {};
  10218. this.onLoadProgress = function () {};
  10219. this.onLoadComplete = function () {};
  10220. };
  10221. THREE.Loader.prototype = {
  10222. constructor: THREE.Loader,
  10223. crossOrigin: undefined,
  10224. extractUrlBase: function ( url ) {
  10225. var parts = url.split( '/' );
  10226. if ( parts.length === 1 ) return './';
  10227. parts.pop();
  10228. return parts.join( '/' ) + '/';
  10229. },
  10230. initMaterials: function ( materials, texturePath, crossOrigin ) {
  10231. var array = [];
  10232. for ( var i = 0; i < materials.length; ++ i ) {
  10233. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  10234. }
  10235. return array;
  10236. },
  10237. createMaterial: ( function () {
  10238. var color, textureLoader, materialLoader;
  10239. return function ( m, texturePath, crossOrigin ) {
  10240. if ( color === undefined ) color = new THREE.Color();
  10241. if ( textureLoader === undefined ) textureLoader = new THREE.TextureLoader();
  10242. if ( materialLoader === undefined ) materialLoader = new THREE.MaterialLoader();
  10243. // convert from old material format
  10244. var textures = {};
  10245. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  10246. var fullPath = texturePath + path;
  10247. var loader = THREE.Loader.Handlers.get( fullPath );
  10248. var texture;
  10249. if ( loader !== null ) {
  10250. texture = loader.load( fullPath );
  10251. } else {
  10252. textureLoader.setCrossOrigin( crossOrigin );
  10253. texture = textureLoader.load( fullPath );
  10254. }
  10255. if ( repeat !== undefined ) {
  10256. texture.repeat.fromArray( repeat );
  10257. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  10258. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  10259. }
  10260. if ( offset !== undefined ) {
  10261. texture.offset.fromArray( offset );
  10262. }
  10263. if ( wrap !== undefined ) {
  10264. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = THREE.RepeatWrapping;
  10265. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = THREE.MirroredRepeatWrapping;
  10266. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = THREE.RepeatWrapping;
  10267. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = THREE.MirroredRepeatWrapping;
  10268. }
  10269. if ( anisotropy !== undefined ) {
  10270. texture.anisotropy = anisotropy;
  10271. }
  10272. var uuid = THREE.Math.generateUUID();
  10273. textures[ uuid ] = texture;
  10274. return uuid;
  10275. }
  10276. //
  10277. var json = {
  10278. uuid: THREE.Math.generateUUID(),
  10279. type: 'MeshLambertMaterial'
  10280. };
  10281. for ( var name in m ) {
  10282. var value = m[ name ];
  10283. switch ( name ) {
  10284. case 'DbgColor':
  10285. case 'DbgIndex':
  10286. case 'opticalDensity':
  10287. case 'illumination':
  10288. break;
  10289. case 'DbgName':
  10290. json.name = value;
  10291. break;
  10292. case 'blending':
  10293. json.blending = THREE[ value ];
  10294. break;
  10295. case 'colorAmbient':
  10296. case 'mapAmbient':
  10297. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  10298. break;
  10299. case 'colorDiffuse':
  10300. json.color = color.fromArray( value ).getHex();
  10301. break;
  10302. case 'colorSpecular':
  10303. json.specular = color.fromArray( value ).getHex();
  10304. break;
  10305. case 'colorEmissive':
  10306. json.emissive = color.fromArray( value ).getHex();
  10307. break;
  10308. case 'specularCoef':
  10309. json.shininess = value;
  10310. break;
  10311. case 'shading':
  10312. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  10313. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  10314. break;
  10315. case 'mapDiffuse':
  10316. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  10317. break;
  10318. case 'mapDiffuseRepeat':
  10319. case 'mapDiffuseOffset':
  10320. case 'mapDiffuseWrap':
  10321. case 'mapDiffuseAnisotropy':
  10322. break;
  10323. case 'mapLight':
  10324. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  10325. break;
  10326. case 'mapLightRepeat':
  10327. case 'mapLightOffset':
  10328. case 'mapLightWrap':
  10329. case 'mapLightAnisotropy':
  10330. break;
  10331. case 'mapAO':
  10332. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  10333. break;
  10334. case 'mapAORepeat':
  10335. case 'mapAOOffset':
  10336. case 'mapAOWrap':
  10337. case 'mapAOAnisotropy':
  10338. break;
  10339. case 'mapBump':
  10340. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  10341. break;
  10342. case 'mapBumpScale':
  10343. json.bumpScale = value;
  10344. break;
  10345. case 'mapBumpRepeat':
  10346. case 'mapBumpOffset':
  10347. case 'mapBumpWrap':
  10348. case 'mapBumpAnisotropy':
  10349. break;
  10350. case 'mapNormal':
  10351. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  10352. break;
  10353. case 'mapNormalFactor':
  10354. json.normalScale = [ value, value ];
  10355. break;
  10356. case 'mapNormalRepeat':
  10357. case 'mapNormalOffset':
  10358. case 'mapNormalWrap':
  10359. case 'mapNormalAnisotropy':
  10360. break;
  10361. case 'mapSpecular':
  10362. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  10363. break;
  10364. case 'mapSpecularRepeat':
  10365. case 'mapSpecularOffset':
  10366. case 'mapSpecularWrap':
  10367. case 'mapSpecularAnisotropy':
  10368. break;
  10369. case 'mapAlpha':
  10370. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  10371. break;
  10372. case 'mapAlphaRepeat':
  10373. case 'mapAlphaOffset':
  10374. case 'mapAlphaWrap':
  10375. case 'mapAlphaAnisotropy':
  10376. break;
  10377. case 'flipSided':
  10378. json.side = THREE.BackSide;
  10379. break;
  10380. case 'doubleSided':
  10381. json.side = THREE.DoubleSide;
  10382. break;
  10383. case 'transparency':
  10384. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  10385. json.opacity = value;
  10386. break;
  10387. case 'depthTest':
  10388. case 'depthWrite':
  10389. case 'colorWrite':
  10390. case 'opacity':
  10391. case 'reflectivity':
  10392. case 'transparent':
  10393. case 'visible':
  10394. case 'wireframe':
  10395. json[ name ] = value;
  10396. break;
  10397. case 'vertexColors':
  10398. if ( value === true ) json.vertexColors = THREE.VertexColors;
  10399. if ( value === 'face' ) json.vertexColors = THREE.FaceColors;
  10400. break;
  10401. default:
  10402. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  10403. break;
  10404. }
  10405. }
  10406. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  10407. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  10408. if ( json.opacity < 1 ) json.transparent = true;
  10409. materialLoader.setTextures( textures );
  10410. return materialLoader.parse( json );
  10411. };
  10412. } )()
  10413. };
  10414. THREE.Loader.Handlers = {
  10415. handlers: [],
  10416. add: function ( regex, loader ) {
  10417. this.handlers.push( regex, loader );
  10418. },
  10419. get: function ( file ) {
  10420. var handlers = this.handlers;
  10421. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  10422. var regex = handlers[ i ];
  10423. var loader = handlers[ i + 1 ];
  10424. if ( regex.test( file ) ) {
  10425. return loader;
  10426. }
  10427. }
  10428. return null;
  10429. }
  10430. };
  10431. // File:src/loaders/XHRLoader.js
  10432. /**
  10433. * @author mrdoob / http://mrdoob.com/
  10434. */
  10435. THREE.XHRLoader = function ( manager ) {
  10436. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10437. };
  10438. THREE.XHRLoader.prototype = {
  10439. constructor: THREE.XHRLoader,
  10440. load: function ( url, onLoad, onProgress, onError ) {
  10441. if ( this.path !== undefined ) url = this.path + url;
  10442. var scope = this;
  10443. var cached = THREE.Cache.get( url );
  10444. if ( cached !== undefined ) {
  10445. if ( onLoad ) {
  10446. setTimeout( function () {
  10447. onLoad( cached );
  10448. }, 0 );
  10449. }
  10450. return cached;
  10451. }
  10452. var request = new XMLHttpRequest();
  10453. request.overrideMimeType( 'text/plain' );
  10454. request.open( 'GET', url, true );
  10455. request.addEventListener( 'load', function ( event ) {
  10456. var response = event.target.response;
  10457. THREE.Cache.add( url, response );
  10458. if ( this.status === 200 ) {
  10459. if ( onLoad ) onLoad( response );
  10460. scope.manager.itemEnd( url );
  10461. } else if ( this.status === 0 ) {
  10462. // Some browsers return HTTP Status 0 when using non-http protocol
  10463. // e.g. 'file://' or 'data://'. Handle as success.
  10464. console.warn( 'THREE.XHRLoader: HTTP Status 0 received.' );
  10465. if ( onLoad ) onLoad( response );
  10466. scope.manager.itemEnd( url );
  10467. } else {
  10468. if ( onError ) onError( event );
  10469. scope.manager.itemError( url );
  10470. }
  10471. }, false );
  10472. if ( onProgress !== undefined ) {
  10473. request.addEventListener( 'progress', function ( event ) {
  10474. onProgress( event );
  10475. }, false );
  10476. }
  10477. request.addEventListener( 'error', function ( event ) {
  10478. if ( onError ) onError( event );
  10479. scope.manager.itemError( url );
  10480. }, false );
  10481. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  10482. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  10483. request.send( null );
  10484. scope.manager.itemStart( url );
  10485. return request;
  10486. },
  10487. setPath: function ( value ) {
  10488. this.path = value;
  10489. },
  10490. setResponseType: function ( value ) {
  10491. this.responseType = value;
  10492. },
  10493. setWithCredentials: function ( value ) {
  10494. this.withCredentials = value;
  10495. }
  10496. };
  10497. // File:src/loaders/FontLoader.js
  10498. /**
  10499. * @author mrdoob / http://mrdoob.com/
  10500. */
  10501. THREE.FontLoader = function ( manager ) {
  10502. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10503. };
  10504. THREE.FontLoader.prototype = {
  10505. constructor: THREE.FontLoader,
  10506. load: function ( url, onLoad, onProgress, onError ) {
  10507. var loader = new THREE.XHRLoader( this.manager );
  10508. loader.load( url, function ( text ) {
  10509. onLoad( new THREE.Font( JSON.parse( text.substring( 65, text.length - 2 ) ) ) );
  10510. }, onProgress, onError );
  10511. }
  10512. };
  10513. // File:src/loaders/ImageLoader.js
  10514. /**
  10515. * @author mrdoob / http://mrdoob.com/
  10516. */
  10517. THREE.ImageLoader = function ( manager ) {
  10518. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10519. };
  10520. THREE.ImageLoader.prototype = {
  10521. constructor: THREE.ImageLoader,
  10522. load: function ( url, onLoad, onProgress, onError ) {
  10523. if ( this.path !== undefined ) url = this.path + url;
  10524. var scope = this;
  10525. var cached = THREE.Cache.get( url );
  10526. if ( cached !== undefined ) {
  10527. scope.manager.itemStart( url );
  10528. if ( onLoad ) {
  10529. setTimeout( function () {
  10530. onLoad( cached );
  10531. scope.manager.itemEnd( url );
  10532. }, 0 );
  10533. } else {
  10534. scope.manager.itemEnd( url );
  10535. }
  10536. return cached;
  10537. }
  10538. var image = document.createElement( 'img' );
  10539. image.addEventListener( 'load', function ( event ) {
  10540. THREE.Cache.add( url, this );
  10541. if ( onLoad ) onLoad( this );
  10542. scope.manager.itemEnd( url );
  10543. }, false );
  10544. if ( onProgress !== undefined ) {
  10545. image.addEventListener( 'progress', function ( event ) {
  10546. onProgress( event );
  10547. }, false );
  10548. }
  10549. image.addEventListener( 'error', function ( event ) {
  10550. if ( onError ) onError( event );
  10551. scope.manager.itemError( url );
  10552. }, false );
  10553. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  10554. scope.manager.itemStart( url );
  10555. image.src = url;
  10556. return image;
  10557. },
  10558. setCrossOrigin: function ( value ) {
  10559. this.crossOrigin = value;
  10560. },
  10561. setPath: function ( value ) {
  10562. this.path = value;
  10563. }
  10564. };
  10565. // File:src/loaders/JSONLoader.js
  10566. /**
  10567. * @author mrdoob / http://mrdoob.com/
  10568. * @author alteredq / http://alteredqualia.com/
  10569. */
  10570. THREE.JSONLoader = function ( manager ) {
  10571. if ( typeof manager === 'boolean' ) {
  10572. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  10573. manager = undefined;
  10574. }
  10575. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10576. this.withCredentials = false;
  10577. };
  10578. THREE.JSONLoader.prototype = {
  10579. constructor: THREE.JSONLoader,
  10580. // Deprecated
  10581. get statusDomElement () {
  10582. if ( this._statusDomElement === undefined ) {
  10583. this._statusDomElement = document.createElement( 'div' );
  10584. }
  10585. console.warn( 'THREE.JSONLoader: .statusDomElement has been removed.' );
  10586. return this._statusDomElement;
  10587. },
  10588. load: function( url, onLoad, onProgress, onError ) {
  10589. var scope = this;
  10590. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  10591. var loader = new THREE.XHRLoader( this.manager );
  10592. loader.setWithCredentials( this.withCredentials );
  10593. loader.load( url, function ( text ) {
  10594. var json = JSON.parse( text );
  10595. var metadata = json.metadata;
  10596. if ( metadata !== undefined ) {
  10597. var type = metadata.type;
  10598. if ( type !== undefined ) {
  10599. if ( type.toLowerCase() === 'object' ) {
  10600. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  10601. return;
  10602. }
  10603. if ( type.toLowerCase() === 'scene' ) {
  10604. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  10605. return;
  10606. }
  10607. }
  10608. }
  10609. var object = scope.parse( json, texturePath );
  10610. onLoad( object.geometry, object.materials );
  10611. }, onProgress, onError );
  10612. },
  10613. setTexturePath: function ( value ) {
  10614. this.texturePath = value;
  10615. },
  10616. parse: function ( json, texturePath ) {
  10617. var geometry = new THREE.Geometry(),
  10618. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  10619. parseModel( scale );
  10620. parseSkin();
  10621. parseMorphing( scale );
  10622. parseAnimations();
  10623. geometry.computeFaceNormals();
  10624. geometry.computeBoundingSphere();
  10625. function parseModel( scale ) {
  10626. function isBitSet( value, position ) {
  10627. return value & ( 1 << position );
  10628. }
  10629. var i, j, fi,
  10630. offset, zLength,
  10631. colorIndex, normalIndex, uvIndex, materialIndex,
  10632. type,
  10633. isQuad,
  10634. hasMaterial,
  10635. hasFaceVertexUv,
  10636. hasFaceNormal, hasFaceVertexNormal,
  10637. hasFaceColor, hasFaceVertexColor,
  10638. vertex, face, faceA, faceB, hex, normal,
  10639. uvLayer, uv, u, v,
  10640. faces = json.faces,
  10641. vertices = json.vertices,
  10642. normals = json.normals,
  10643. colors = json.colors,
  10644. nUvLayers = 0;
  10645. if ( json.uvs !== undefined ) {
  10646. // disregard empty arrays
  10647. for ( i = 0; i < json.uvs.length; i ++ ) {
  10648. if ( json.uvs[ i ].length ) nUvLayers ++;
  10649. }
  10650. for ( i = 0; i < nUvLayers; i ++ ) {
  10651. geometry.faceVertexUvs[ i ] = [];
  10652. }
  10653. }
  10654. offset = 0;
  10655. zLength = vertices.length;
  10656. while ( offset < zLength ) {
  10657. vertex = new THREE.Vector3();
  10658. vertex.x = vertices[ offset ++ ] * scale;
  10659. vertex.y = vertices[ offset ++ ] * scale;
  10660. vertex.z = vertices[ offset ++ ] * scale;
  10661. geometry.vertices.push( vertex );
  10662. }
  10663. offset = 0;
  10664. zLength = faces.length;
  10665. while ( offset < zLength ) {
  10666. type = faces[ offset ++ ];
  10667. isQuad = isBitSet( type, 0 );
  10668. hasMaterial = isBitSet( type, 1 );
  10669. hasFaceVertexUv = isBitSet( type, 3 );
  10670. hasFaceNormal = isBitSet( type, 4 );
  10671. hasFaceVertexNormal = isBitSet( type, 5 );
  10672. hasFaceColor = isBitSet( type, 6 );
  10673. hasFaceVertexColor = isBitSet( type, 7 );
  10674. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  10675. if ( isQuad ) {
  10676. faceA = new THREE.Face3();
  10677. faceA.a = faces[ offset ];
  10678. faceA.b = faces[ offset + 1 ];
  10679. faceA.c = faces[ offset + 3 ];
  10680. faceB = new THREE.Face3();
  10681. faceB.a = faces[ offset + 1 ];
  10682. faceB.b = faces[ offset + 2 ];
  10683. faceB.c = faces[ offset + 3 ];
  10684. offset += 4;
  10685. if ( hasMaterial ) {
  10686. materialIndex = faces[ offset ++ ];
  10687. faceA.materialIndex = materialIndex;
  10688. faceB.materialIndex = materialIndex;
  10689. }
  10690. // to get face <=> uv index correspondence
  10691. fi = geometry.faces.length;
  10692. if ( hasFaceVertexUv ) {
  10693. for ( i = 0; i < nUvLayers; i ++ ) {
  10694. uvLayer = json.uvs[ i ];
  10695. geometry.faceVertexUvs[ i ][ fi ] = [];
  10696. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  10697. for ( j = 0; j < 4; j ++ ) {
  10698. uvIndex = faces[ offset ++ ];
  10699. u = uvLayer[ uvIndex * 2 ];
  10700. v = uvLayer[ uvIndex * 2 + 1 ];
  10701. uv = new THREE.Vector2( u, v );
  10702. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10703. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  10704. }
  10705. }
  10706. }
  10707. if ( hasFaceNormal ) {
  10708. normalIndex = faces[ offset ++ ] * 3;
  10709. faceA.normal.set(
  10710. normals[ normalIndex ++ ],
  10711. normals[ normalIndex ++ ],
  10712. normals[ normalIndex ]
  10713. );
  10714. faceB.normal.copy( faceA.normal );
  10715. }
  10716. if ( hasFaceVertexNormal ) {
  10717. for ( i = 0; i < 4; i ++ ) {
  10718. normalIndex = faces[ offset ++ ] * 3;
  10719. normal = new THREE.Vector3(
  10720. normals[ normalIndex ++ ],
  10721. normals[ normalIndex ++ ],
  10722. normals[ normalIndex ]
  10723. );
  10724. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  10725. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  10726. }
  10727. }
  10728. if ( hasFaceColor ) {
  10729. colorIndex = faces[ offset ++ ];
  10730. hex = colors[ colorIndex ];
  10731. faceA.color.setHex( hex );
  10732. faceB.color.setHex( hex );
  10733. }
  10734. if ( hasFaceVertexColor ) {
  10735. for ( i = 0; i < 4; i ++ ) {
  10736. colorIndex = faces[ offset ++ ];
  10737. hex = colors[ colorIndex ];
  10738. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  10739. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  10740. }
  10741. }
  10742. geometry.faces.push( faceA );
  10743. geometry.faces.push( faceB );
  10744. } else {
  10745. face = new THREE.Face3();
  10746. face.a = faces[ offset ++ ];
  10747. face.b = faces[ offset ++ ];
  10748. face.c = faces[ offset ++ ];
  10749. if ( hasMaterial ) {
  10750. materialIndex = faces[ offset ++ ];
  10751. face.materialIndex = materialIndex;
  10752. }
  10753. // to get face <=> uv index correspondence
  10754. fi = geometry.faces.length;
  10755. if ( hasFaceVertexUv ) {
  10756. for ( i = 0; i < nUvLayers; i ++ ) {
  10757. uvLayer = json.uvs[ i ];
  10758. geometry.faceVertexUvs[ i ][ fi ] = [];
  10759. for ( j = 0; j < 3; j ++ ) {
  10760. uvIndex = faces[ offset ++ ];
  10761. u = uvLayer[ uvIndex * 2 ];
  10762. v = uvLayer[ uvIndex * 2 + 1 ];
  10763. uv = new THREE.Vector2( u, v );
  10764. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10765. }
  10766. }
  10767. }
  10768. if ( hasFaceNormal ) {
  10769. normalIndex = faces[ offset ++ ] * 3;
  10770. face.normal.set(
  10771. normals[ normalIndex ++ ],
  10772. normals[ normalIndex ++ ],
  10773. normals[ normalIndex ]
  10774. );
  10775. }
  10776. if ( hasFaceVertexNormal ) {
  10777. for ( i = 0; i < 3; i ++ ) {
  10778. normalIndex = faces[ offset ++ ] * 3;
  10779. normal = new THREE.Vector3(
  10780. normals[ normalIndex ++ ],
  10781. normals[ normalIndex ++ ],
  10782. normals[ normalIndex ]
  10783. );
  10784. face.vertexNormals.push( normal );
  10785. }
  10786. }
  10787. if ( hasFaceColor ) {
  10788. colorIndex = faces[ offset ++ ];
  10789. face.color.setHex( colors[ colorIndex ] );
  10790. }
  10791. if ( hasFaceVertexColor ) {
  10792. for ( i = 0; i < 3; i ++ ) {
  10793. colorIndex = faces[ offset ++ ];
  10794. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  10795. }
  10796. }
  10797. geometry.faces.push( face );
  10798. }
  10799. }
  10800. };
  10801. function parseSkin() {
  10802. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  10803. if ( json.skinWeights ) {
  10804. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  10805. var x = json.skinWeights[ i ];
  10806. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  10807. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  10808. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  10809. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  10810. }
  10811. }
  10812. if ( json.skinIndices ) {
  10813. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  10814. var a = json.skinIndices[ i ];
  10815. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  10816. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  10817. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  10818. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  10819. }
  10820. }
  10821. geometry.bones = json.bones;
  10822. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  10823. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  10824. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  10825. }
  10826. };
  10827. function parseMorphing( scale ) {
  10828. if ( json.morphTargets !== undefined ) {
  10829. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  10830. geometry.morphTargets[ i ] = {};
  10831. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  10832. geometry.morphTargets[ i ].vertices = [];
  10833. var dstVertices = geometry.morphTargets[ i ].vertices;
  10834. var srcVertices = json.morphTargets[ i ].vertices;
  10835. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  10836. var vertex = new THREE.Vector3();
  10837. vertex.x = srcVertices[ v ] * scale;
  10838. vertex.y = srcVertices[ v + 1 ] * scale;
  10839. vertex.z = srcVertices[ v + 2 ] * scale;
  10840. dstVertices.push( vertex );
  10841. }
  10842. }
  10843. }
  10844. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  10845. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  10846. var faces = geometry.faces;
  10847. var morphColors = json.morphColors[ 0 ].colors;
  10848. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  10849. faces[ i ].color.fromArray( morphColors, i * 3 );
  10850. }
  10851. }
  10852. }
  10853. function parseAnimations() {
  10854. var outputAnimations = [];
  10855. // parse old style Bone/Hierarchy animations
  10856. var animations = [];
  10857. if ( json.animation !== undefined ) {
  10858. animations.push( json.animation );
  10859. }
  10860. if ( json.animations !== undefined ) {
  10861. if ( json.animations.length ) {
  10862. animations = animations.concat( json.animations );
  10863. } else {
  10864. animations.push( json.animations );
  10865. }
  10866. }
  10867. for ( var i = 0; i < animations.length; i ++ ) {
  10868. var clip = THREE.AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  10869. if ( clip ) outputAnimations.push( clip );
  10870. }
  10871. // parse implicit morph animations
  10872. if ( geometry.morphTargets ) {
  10873. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  10874. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  10875. outputAnimations = outputAnimations.concat( morphAnimationClips );
  10876. }
  10877. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  10878. };
  10879. if ( json.materials === undefined || json.materials.length === 0 ) {
  10880. return { geometry: geometry };
  10881. } else {
  10882. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  10883. return { geometry: geometry, materials: materials };
  10884. }
  10885. }
  10886. };
  10887. // File:src/loaders/LoadingManager.js
  10888. /**
  10889. * @author mrdoob / http://mrdoob.com/
  10890. */
  10891. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  10892. var scope = this;
  10893. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  10894. this.onStart = undefined;
  10895. this.onLoad = onLoad;
  10896. this.onProgress = onProgress;
  10897. this.onError = onError;
  10898. this.itemStart = function ( url ) {
  10899. itemsTotal ++;
  10900. if ( isLoading === false ) {
  10901. if ( scope.onStart !== undefined ) {
  10902. scope.onStart( url, itemsLoaded, itemsTotal );
  10903. }
  10904. }
  10905. isLoading = true;
  10906. };
  10907. this.itemEnd = function ( url ) {
  10908. itemsLoaded ++;
  10909. if ( scope.onProgress !== undefined ) {
  10910. scope.onProgress( url, itemsLoaded, itemsTotal );
  10911. }
  10912. if ( itemsLoaded === itemsTotal ) {
  10913. isLoading = false;
  10914. if ( scope.onLoad !== undefined ) {
  10915. scope.onLoad();
  10916. }
  10917. }
  10918. };
  10919. this.itemError = function ( url ) {
  10920. if ( scope.onError !== undefined ) {
  10921. scope.onError( url );
  10922. }
  10923. };
  10924. };
  10925. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  10926. // File:src/loaders/BufferGeometryLoader.js
  10927. /**
  10928. * @author mrdoob / http://mrdoob.com/
  10929. */
  10930. THREE.BufferGeometryLoader = function ( manager ) {
  10931. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10932. };
  10933. THREE.BufferGeometryLoader.prototype = {
  10934. constructor: THREE.BufferGeometryLoader,
  10935. load: function ( url, onLoad, onProgress, onError ) {
  10936. var scope = this;
  10937. var loader = new THREE.XHRLoader( scope.manager );
  10938. loader.load( url, function ( text ) {
  10939. onLoad( scope.parse( JSON.parse( text ) ) );
  10940. }, onProgress, onError );
  10941. },
  10942. parse: function ( json ) {
  10943. var geometry = new THREE.BufferGeometry();
  10944. var index = json.data.index;
  10945. var TYPED_ARRAYS = {
  10946. 'Int8Array': Int8Array,
  10947. 'Uint8Array': Uint8Array,
  10948. 'Uint8ClampedArray': Uint8ClampedArray,
  10949. 'Int16Array': Int16Array,
  10950. 'Uint16Array': Uint16Array,
  10951. 'Int32Array': Int32Array,
  10952. 'Uint32Array': Uint32Array,
  10953. 'Float32Array': Float32Array,
  10954. 'Float64Array': Float64Array
  10955. };
  10956. if ( index !== undefined ) {
  10957. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  10958. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  10959. }
  10960. var attributes = json.data.attributes;
  10961. for ( var key in attributes ) {
  10962. var attribute = attributes[ key ];
  10963. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  10964. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  10965. }
  10966. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  10967. if ( groups !== undefined ) {
  10968. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  10969. var group = groups[ i ];
  10970. geometry.addGroup( group.start, group.count, group.materialIndex );
  10971. }
  10972. }
  10973. var boundingSphere = json.data.boundingSphere;
  10974. if ( boundingSphere !== undefined ) {
  10975. var center = new THREE.Vector3();
  10976. if ( boundingSphere.center !== undefined ) {
  10977. center.fromArray( boundingSphere.center );
  10978. }
  10979. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  10980. }
  10981. return geometry;
  10982. }
  10983. };
  10984. // File:src/loaders/MaterialLoader.js
  10985. /**
  10986. * @author mrdoob / http://mrdoob.com/
  10987. */
  10988. THREE.MaterialLoader = function ( manager ) {
  10989. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10990. this.textures = {};
  10991. };
  10992. THREE.MaterialLoader.prototype = {
  10993. constructor: THREE.MaterialLoader,
  10994. load: function ( url, onLoad, onProgress, onError ) {
  10995. var scope = this;
  10996. var loader = new THREE.XHRLoader( scope.manager );
  10997. loader.load( url, function ( text ) {
  10998. onLoad( scope.parse( JSON.parse( text ) ) );
  10999. }, onProgress, onError );
  11000. },
  11001. setTextures: function ( value ) {
  11002. this.textures = value;
  11003. },
  11004. getTexture: function ( name ) {
  11005. var textures = this.textures;
  11006. if ( textures[ name ] === undefined ) {
  11007. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  11008. }
  11009. return textures[ name ];
  11010. },
  11011. parse: function ( json ) {
  11012. var material = new THREE[ json.type ];
  11013. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  11014. if ( json.name !== undefined ) material.name = json.name;
  11015. if ( json.color !== undefined ) material.color.setHex( json.color );
  11016. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  11017. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  11018. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  11019. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  11020. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  11021. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  11022. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  11023. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  11024. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  11025. if ( json.shading !== undefined ) material.shading = json.shading;
  11026. if ( json.blending !== undefined ) material.blending = json.blending;
  11027. if ( json.side !== undefined ) material.side = json.side;
  11028. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  11029. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  11030. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  11031. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  11032. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  11033. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  11034. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  11035. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  11036. // for PointsMaterial
  11037. if ( json.size !== undefined ) material.size = json.size;
  11038. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  11039. // maps
  11040. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  11041. if ( json.alphaMap !== undefined ) {
  11042. material.alphaMap = this.getTexture( json.alphaMap );
  11043. material.transparent = true;
  11044. }
  11045. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  11046. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  11047. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  11048. if ( json.normalScale !== undefined ) {
  11049. var normalScale = json.normalScale;
  11050. if ( Array.isArray( normalScale ) === false ) {
  11051. // Blender exporter used to export a scalar. See #7459
  11052. normalScale = [ normalScale, normalScale ];
  11053. }
  11054. material.normalScale = new THREE.Vector2().fromArray( normalScale );
  11055. }
  11056. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  11057. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  11058. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  11059. if ( json.roughnessMap !== undefined ) material.roughnessMap = this.getTexture( json.roughnessMap );
  11060. if ( json.metalnessMap !== undefined ) material.metalnessMap = this.getTexture( json.metalnessMap );
  11061. if ( json.emissiveMap !== undefined ) material.emissiveMap = this.getTexture( json.emissiveMap );
  11062. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  11063. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  11064. if ( json.envMap !== undefined ) {
  11065. material.envMap = this.getTexture( json.envMap );
  11066. material.combine = THREE.MultiplyOperation;
  11067. }
  11068. if ( json.reflectivity ) material.reflectivity = json.reflectivity;
  11069. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  11070. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  11071. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  11072. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  11073. // MultiMaterial
  11074. if ( json.materials !== undefined ) {
  11075. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  11076. material.materials.push( this.parse( json.materials[ i ] ) );
  11077. }
  11078. }
  11079. return material;
  11080. }
  11081. };
  11082. // File:src/loaders/ObjectLoader.js
  11083. /**
  11084. * @author mrdoob / http://mrdoob.com/
  11085. */
  11086. THREE.ObjectLoader = function ( manager ) {
  11087. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11088. this.texturePath = '';
  11089. };
  11090. THREE.ObjectLoader.prototype = {
  11091. constructor: THREE.ObjectLoader,
  11092. load: function ( url, onLoad, onProgress, onError ) {
  11093. if ( this.texturePath === '' ) {
  11094. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  11095. }
  11096. var scope = this;
  11097. var loader = new THREE.XHRLoader( scope.manager );
  11098. loader.load( url, function ( text ) {
  11099. scope.parse( JSON.parse( text ), onLoad );
  11100. }, onProgress, onError );
  11101. },
  11102. setTexturePath: function ( value ) {
  11103. this.texturePath = value;
  11104. },
  11105. setCrossOrigin: function ( value ) {
  11106. this.crossOrigin = value;
  11107. },
  11108. parse: function ( json, onLoad ) {
  11109. var geometries = this.parseGeometries( json.geometries );
  11110. var images = this.parseImages( json.images, function () {
  11111. if ( onLoad !== undefined ) onLoad( object );
  11112. } );
  11113. var textures = this.parseTextures( json.textures, images );
  11114. var materials = this.parseMaterials( json.materials, textures );
  11115. var object = this.parseObject( json.object, geometries, materials );
  11116. if ( json.animations ) {
  11117. object.animations = this.parseAnimations( json.animations );
  11118. }
  11119. if ( json.images === undefined || json.images.length === 0 ) {
  11120. if ( onLoad !== undefined ) onLoad( object );
  11121. }
  11122. return object;
  11123. },
  11124. parseGeometries: function ( json ) {
  11125. var geometries = {};
  11126. if ( json !== undefined ) {
  11127. var geometryLoader = new THREE.JSONLoader();
  11128. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  11129. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11130. var geometry;
  11131. var data = json[ i ];
  11132. switch ( data.type ) {
  11133. case 'PlaneGeometry':
  11134. case 'PlaneBufferGeometry':
  11135. geometry = new THREE[ data.type ](
  11136. data.width,
  11137. data.height,
  11138. data.widthSegments,
  11139. data.heightSegments
  11140. );
  11141. break;
  11142. case 'BoxGeometry':
  11143. case 'CubeGeometry': // backwards compatible
  11144. geometry = new THREE.BoxGeometry(
  11145. data.width,
  11146. data.height,
  11147. data.depth,
  11148. data.widthSegments,
  11149. data.heightSegments,
  11150. data.depthSegments
  11151. );
  11152. break;
  11153. case 'CircleBufferGeometry':
  11154. geometry = new THREE.CircleBufferGeometry(
  11155. data.radius,
  11156. data.segments,
  11157. data.thetaStart,
  11158. data.thetaLength
  11159. );
  11160. break;
  11161. case 'CircleGeometry':
  11162. geometry = new THREE.CircleGeometry(
  11163. data.radius,
  11164. data.segments,
  11165. data.thetaStart,
  11166. data.thetaLength
  11167. );
  11168. break;
  11169. case 'CylinderGeometry':
  11170. geometry = new THREE.CylinderGeometry(
  11171. data.radiusTop,
  11172. data.radiusBottom,
  11173. data.height,
  11174. data.radialSegments,
  11175. data.heightSegments,
  11176. data.openEnded,
  11177. data.thetaStart,
  11178. data.thetaLength
  11179. );
  11180. break;
  11181. case 'SphereGeometry':
  11182. geometry = new THREE.SphereGeometry(
  11183. data.radius,
  11184. data.widthSegments,
  11185. data.heightSegments,
  11186. data.phiStart,
  11187. data.phiLength,
  11188. data.thetaStart,
  11189. data.thetaLength
  11190. );
  11191. break;
  11192. case 'SphereBufferGeometry':
  11193. geometry = new THREE.SphereBufferGeometry(
  11194. data.radius,
  11195. data.widthSegments,
  11196. data.heightSegments,
  11197. data.phiStart,
  11198. data.phiLength,
  11199. data.thetaStart,
  11200. data.thetaLength
  11201. );
  11202. break;
  11203. case 'DodecahedronGeometry':
  11204. geometry = new THREE.DodecahedronGeometry(
  11205. data.radius,
  11206. data.detail
  11207. );
  11208. break;
  11209. case 'IcosahedronGeometry':
  11210. geometry = new THREE.IcosahedronGeometry(
  11211. data.radius,
  11212. data.detail
  11213. );
  11214. break;
  11215. case 'OctahedronGeometry':
  11216. geometry = new THREE.OctahedronGeometry(
  11217. data.radius,
  11218. data.detail
  11219. );
  11220. break;
  11221. case 'TetrahedronGeometry':
  11222. geometry = new THREE.TetrahedronGeometry(
  11223. data.radius,
  11224. data.detail
  11225. );
  11226. break;
  11227. case 'RingGeometry':
  11228. geometry = new THREE.RingGeometry(
  11229. data.innerRadius,
  11230. data.outerRadius,
  11231. data.thetaSegments,
  11232. data.phiSegments,
  11233. data.thetaStart,
  11234. data.thetaLength
  11235. );
  11236. break;
  11237. case 'TorusGeometry':
  11238. geometry = new THREE.TorusGeometry(
  11239. data.radius,
  11240. data.tube,
  11241. data.radialSegments,
  11242. data.tubularSegments,
  11243. data.arc
  11244. );
  11245. break;
  11246. case 'TorusKnotGeometry':
  11247. geometry = new THREE.TorusKnotGeometry(
  11248. data.radius,
  11249. data.tube,
  11250. data.radialSegments,
  11251. data.tubularSegments,
  11252. data.p,
  11253. data.q,
  11254. data.heightScale
  11255. );
  11256. break;
  11257. case 'LatheGeometry':
  11258. geometry = new THREE.LatheGeometry(
  11259. data.points,
  11260. data.segments,
  11261. data.phiStart,
  11262. data.phiLength
  11263. );
  11264. break;
  11265. case 'BufferGeometry':
  11266. geometry = bufferGeometryLoader.parse( data );
  11267. break;
  11268. case 'Geometry':
  11269. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  11270. break;
  11271. default:
  11272. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  11273. continue;
  11274. }
  11275. geometry.uuid = data.uuid;
  11276. if ( data.name !== undefined ) geometry.name = data.name;
  11277. geometries[ data.uuid ] = geometry;
  11278. }
  11279. }
  11280. return geometries;
  11281. },
  11282. parseMaterials: function ( json, textures ) {
  11283. var materials = {};
  11284. if ( json !== undefined ) {
  11285. var loader = new THREE.MaterialLoader();
  11286. loader.setTextures( textures );
  11287. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11288. var material = loader.parse( json[ i ] );
  11289. materials[ material.uuid ] = material;
  11290. }
  11291. }
  11292. return materials;
  11293. },
  11294. parseAnimations: function ( json ) {
  11295. var animations = [];
  11296. for ( var i = 0; i < json.length; i ++ ) {
  11297. var clip = THREE.AnimationClip.parse( json[ i ] );
  11298. animations.push( clip );
  11299. }
  11300. return animations;
  11301. },
  11302. parseImages: function ( json, onLoad ) {
  11303. var scope = this;
  11304. var images = {};
  11305. function loadImage( url ) {
  11306. scope.manager.itemStart( url );
  11307. return loader.load( url, function () {
  11308. scope.manager.itemEnd( url );
  11309. } );
  11310. }
  11311. if ( json !== undefined && json.length > 0 ) {
  11312. var manager = new THREE.LoadingManager( onLoad );
  11313. var loader = new THREE.ImageLoader( manager );
  11314. loader.setCrossOrigin( this.crossOrigin );
  11315. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11316. var image = json[ i ];
  11317. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  11318. images[ image.uuid ] = loadImage( path );
  11319. }
  11320. }
  11321. return images;
  11322. },
  11323. parseTextures: function ( json, images ) {
  11324. function parseConstant( value ) {
  11325. if ( typeof( value ) === 'number' ) return value;
  11326. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  11327. return THREE[ value ];
  11328. }
  11329. var textures = {};
  11330. if ( json !== undefined ) {
  11331. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11332. var data = json[ i ];
  11333. if ( data.image === undefined ) {
  11334. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  11335. }
  11336. if ( images[ data.image ] === undefined ) {
  11337. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  11338. }
  11339. var texture = new THREE.Texture( images[ data.image ] );
  11340. texture.needsUpdate = true;
  11341. texture.uuid = data.uuid;
  11342. if ( data.name !== undefined ) texture.name = data.name;
  11343. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  11344. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  11345. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  11346. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  11347. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  11348. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  11349. if ( Array.isArray( data.wrap ) ) {
  11350. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  11351. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  11352. }
  11353. textures[ data.uuid ] = texture;
  11354. }
  11355. }
  11356. return textures;
  11357. },
  11358. parseObject: function () {
  11359. var matrix = new THREE.Matrix4();
  11360. return function ( data, geometries, materials ) {
  11361. var object;
  11362. function getGeometry( name ) {
  11363. if ( geometries[ name ] === undefined ) {
  11364. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  11365. }
  11366. return geometries[ name ];
  11367. }
  11368. function getMaterial( name ) {
  11369. if ( name === undefined ) return undefined;
  11370. if ( materials[ name ] === undefined ) {
  11371. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  11372. }
  11373. return materials[ name ];
  11374. }
  11375. switch ( data.type ) {
  11376. case 'Scene':
  11377. object = new THREE.Scene();
  11378. break;
  11379. case 'PerspectiveCamera':
  11380. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  11381. break;
  11382. case 'OrthographicCamera':
  11383. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  11384. break;
  11385. case 'AmbientLight':
  11386. object = new THREE.AmbientLight( data.color, data.intensity );
  11387. break;
  11388. case 'DirectionalLight':
  11389. object = new THREE.DirectionalLight( data.color, data.intensity );
  11390. break;
  11391. case 'PointLight':
  11392. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  11393. break;
  11394. case 'SpotLight':
  11395. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  11396. break;
  11397. case 'HemisphereLight':
  11398. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  11399. break;
  11400. case 'Mesh':
  11401. var geometry = getGeometry( data.geometry );
  11402. var material = getMaterial( data.material );
  11403. if ( geometry.bones && geometry.bones.length > 0 ) {
  11404. object = new THREE.SkinnedMesh( geometry, material );
  11405. } else {
  11406. object = new THREE.Mesh( geometry, material );
  11407. }
  11408. break;
  11409. case 'LOD':
  11410. object = new THREE.LOD();
  11411. break;
  11412. case 'Line':
  11413. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  11414. break;
  11415. case 'PointCloud':
  11416. case 'Points':
  11417. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  11418. break;
  11419. case 'Sprite':
  11420. object = new THREE.Sprite( getMaterial( data.material ) );
  11421. break;
  11422. case 'Group':
  11423. object = new THREE.Group();
  11424. break;
  11425. default:
  11426. object = new THREE.Object3D();
  11427. }
  11428. object.uuid = data.uuid;
  11429. if ( data.name !== undefined ) object.name = data.name;
  11430. if ( data.matrix !== undefined ) {
  11431. matrix.fromArray( data.matrix );
  11432. matrix.decompose( object.position, object.quaternion, object.scale );
  11433. } else {
  11434. if ( data.position !== undefined ) object.position.fromArray( data.position );
  11435. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  11436. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  11437. }
  11438. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  11439. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  11440. if ( data.visible !== undefined ) object.visible = data.visible;
  11441. if ( data.userData !== undefined ) object.userData = data.userData;
  11442. if ( data.children !== undefined ) {
  11443. for ( var child in data.children ) {
  11444. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  11445. }
  11446. }
  11447. if ( data.type === 'LOD' ) {
  11448. var levels = data.levels;
  11449. for ( var l = 0; l < levels.length; l ++ ) {
  11450. var level = levels[ l ];
  11451. var child = object.getObjectByProperty( 'uuid', level.object );
  11452. if ( child !== undefined ) {
  11453. object.addLevel( child, level.distance );
  11454. }
  11455. }
  11456. }
  11457. return object;
  11458. }
  11459. }()
  11460. };
  11461. // File:src/loaders/TextureLoader.js
  11462. /**
  11463. * @author mrdoob / http://mrdoob.com/
  11464. */
  11465. THREE.TextureLoader = function ( manager ) {
  11466. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11467. };
  11468. THREE.TextureLoader.prototype = {
  11469. constructor: THREE.TextureLoader,
  11470. load: function ( url, onLoad, onProgress, onError ) {
  11471. var texture = new THREE.Texture();
  11472. var loader = new THREE.ImageLoader( this.manager );
  11473. loader.setCrossOrigin( this.crossOrigin );
  11474. loader.setPath( this.path );
  11475. loader.load( url, function ( image ) {
  11476. texture.image = image;
  11477. texture.needsUpdate = true;
  11478. if ( onLoad !== undefined ) {
  11479. onLoad( texture );
  11480. }
  11481. }, onProgress, onError );
  11482. return texture;
  11483. },
  11484. setCrossOrigin: function ( value ) {
  11485. this.crossOrigin = value;
  11486. },
  11487. setPath: function ( value ) {
  11488. this.path = value;
  11489. }
  11490. };
  11491. // File:src/loaders/CubeTextureLoader.js
  11492. /**
  11493. * @author mrdoob / http://mrdoob.com/
  11494. */
  11495. THREE.CubeTextureLoader = function ( manager ) {
  11496. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11497. };
  11498. THREE.CubeTextureLoader.prototype = {
  11499. constructor: THREE.CubeTextureLoader,
  11500. load: function ( urls, onLoad, onProgress, onError ) {
  11501. var texture = new THREE.CubeTexture( [] );
  11502. var loader = new THREE.ImageLoader( this.manager );
  11503. loader.setCrossOrigin( this.crossOrigin );
  11504. loader.setPath( this.path );
  11505. var loaded = 0;
  11506. function loadTexture( i ) {
  11507. loader.load( urls[ i ], function ( image ) {
  11508. texture.images[ i ] = image;
  11509. loaded ++;
  11510. if ( loaded === 6 ) {
  11511. texture.needsUpdate = true;
  11512. if ( onLoad ) onLoad( texture );
  11513. }
  11514. }, undefined, onError );
  11515. }
  11516. for ( var i = 0; i < urls.length; ++ i ) {
  11517. loadTexture( i );
  11518. }
  11519. return texture;
  11520. },
  11521. setCrossOrigin: function ( value ) {
  11522. this.crossOrigin = value;
  11523. },
  11524. setPath: function ( value ) {
  11525. this.path = value;
  11526. }
  11527. };
  11528. // File:src/loaders/BinaryTextureLoader.js
  11529. /**
  11530. * @author Nikos M. / https://github.com/foo123/
  11531. *
  11532. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  11533. */
  11534. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  11535. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11536. // override in sub classes
  11537. this._parser = null;
  11538. };
  11539. THREE.BinaryTextureLoader.prototype = {
  11540. constructor: THREE.BinaryTextureLoader,
  11541. load: function ( url, onLoad, onProgress, onError ) {
  11542. var scope = this;
  11543. var texture = new THREE.DataTexture();
  11544. var loader = new THREE.XHRLoader( this.manager );
  11545. loader.setResponseType( 'arraybuffer' );
  11546. loader.load( url, function ( buffer ) {
  11547. var texData = scope._parser( buffer );
  11548. if ( ! texData ) return;
  11549. if ( undefined !== texData.image ) {
  11550. texture.image = texData.image;
  11551. } else if ( undefined !== texData.data ) {
  11552. texture.image.width = texData.width;
  11553. texture.image.height = texData.height;
  11554. texture.image.data = texData.data;
  11555. }
  11556. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  11557. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  11558. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  11559. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  11560. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  11561. if ( undefined !== texData.format ) {
  11562. texture.format = texData.format;
  11563. }
  11564. if ( undefined !== texData.type ) {
  11565. texture.type = texData.type;
  11566. }
  11567. if ( undefined !== texData.mipmaps ) {
  11568. texture.mipmaps = texData.mipmaps;
  11569. }
  11570. if ( 1 === texData.mipmapCount ) {
  11571. texture.minFilter = THREE.LinearFilter;
  11572. }
  11573. texture.needsUpdate = true;
  11574. if ( onLoad ) onLoad( texture, texData );
  11575. }, onProgress, onError );
  11576. return texture;
  11577. }
  11578. };
  11579. // File:src/loaders/CompressedTextureLoader.js
  11580. /**
  11581. * @author mrdoob / http://mrdoob.com/
  11582. *
  11583. * Abstract Base class to block based textures loader (dds, pvr, ...)
  11584. */
  11585. THREE.CompressedTextureLoader = function ( manager ) {
  11586. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11587. // override in sub classes
  11588. this._parser = null;
  11589. };
  11590. THREE.CompressedTextureLoader.prototype = {
  11591. constructor: THREE.CompressedTextureLoader,
  11592. load: function ( url, onLoad, onProgress, onError ) {
  11593. var scope = this;
  11594. var images = [];
  11595. var texture = new THREE.CompressedTexture();
  11596. texture.image = images;
  11597. var loader = new THREE.XHRLoader( this.manager );
  11598. loader.setPath( this.path );
  11599. loader.setResponseType( 'arraybuffer' );
  11600. function loadTexture( i ) {
  11601. loader.load( url[ i ], function ( buffer ) {
  11602. var texDatas = scope._parser( buffer, true );
  11603. images[ i ] = {
  11604. width: texDatas.width,
  11605. height: texDatas.height,
  11606. format: texDatas.format,
  11607. mipmaps: texDatas.mipmaps
  11608. };
  11609. loaded += 1;
  11610. if ( loaded === 6 ) {
  11611. if ( texDatas.mipmapCount === 1 )
  11612. texture.minFilter = THREE.LinearFilter;
  11613. texture.format = texDatas.format;
  11614. texture.needsUpdate = true;
  11615. if ( onLoad ) onLoad( texture );
  11616. }
  11617. }, onProgress, onError );
  11618. }
  11619. if ( Array.isArray( url ) ) {
  11620. var loaded = 0;
  11621. for ( var i = 0, il = url.length; i < il; ++ i ) {
  11622. loadTexture( i );
  11623. }
  11624. } else {
  11625. // compressed cubemap texture stored in a single DDS file
  11626. loader.load( url, function ( buffer ) {
  11627. var texDatas = scope._parser( buffer, true );
  11628. if ( texDatas.isCubemap ) {
  11629. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  11630. for ( var f = 0; f < faces; f ++ ) {
  11631. images[ f ] = { mipmaps : [] };
  11632. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  11633. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  11634. images[ f ].format = texDatas.format;
  11635. images[ f ].width = texDatas.width;
  11636. images[ f ].height = texDatas.height;
  11637. }
  11638. }
  11639. } else {
  11640. texture.image.width = texDatas.width;
  11641. texture.image.height = texDatas.height;
  11642. texture.mipmaps = texDatas.mipmaps;
  11643. }
  11644. if ( texDatas.mipmapCount === 1 ) {
  11645. texture.minFilter = THREE.LinearFilter;
  11646. }
  11647. texture.format = texDatas.format;
  11648. texture.needsUpdate = true;
  11649. if ( onLoad ) onLoad( texture );
  11650. }, onProgress, onError );
  11651. }
  11652. return texture;
  11653. },
  11654. setPath: function ( value ) {
  11655. this.path = value;
  11656. }
  11657. };
  11658. // File:src/materials/Material.js
  11659. /**
  11660. * @author mrdoob / http://mrdoob.com/
  11661. * @author alteredq / http://alteredqualia.com/
  11662. */
  11663. THREE.Material = function () {
  11664. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  11665. this.uuid = THREE.Math.generateUUID();
  11666. this.name = '';
  11667. this.type = 'Material';
  11668. this.side = THREE.FrontSide;
  11669. this.opacity = 1;
  11670. this.transparent = false;
  11671. this.blending = THREE.NormalBlending;
  11672. this.blendSrc = THREE.SrcAlphaFactor;
  11673. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  11674. this.blendEquation = THREE.AddEquation;
  11675. this.blendSrcAlpha = null;
  11676. this.blendDstAlpha = null;
  11677. this.blendEquationAlpha = null;
  11678. this.depthFunc = THREE.LessEqualDepth;
  11679. this.depthTest = true;
  11680. this.depthWrite = true;
  11681. this.colorWrite = true;
  11682. this.precision = null; // override the renderer's default precision for this material
  11683. this.polygonOffset = false;
  11684. this.polygonOffsetFactor = 0;
  11685. this.polygonOffsetUnits = 0;
  11686. this.alphaTest = 0;
  11687. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  11688. this.visible = true;
  11689. this._needsUpdate = true;
  11690. };
  11691. THREE.Material.prototype = {
  11692. constructor: THREE.Material,
  11693. get needsUpdate () {
  11694. return this._needsUpdate;
  11695. },
  11696. set needsUpdate ( value ) {
  11697. if ( value === true ) this.update();
  11698. this._needsUpdate = value;
  11699. },
  11700. setValues: function ( values ) {
  11701. if ( values === undefined ) return;
  11702. for ( var key in values ) {
  11703. var newValue = values[ key ];
  11704. if ( newValue === undefined ) {
  11705. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  11706. continue;
  11707. }
  11708. var currentValue = this[ key ];
  11709. if ( currentValue === undefined ) {
  11710. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  11711. continue;
  11712. }
  11713. if ( currentValue instanceof THREE.Color ) {
  11714. currentValue.set( newValue );
  11715. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  11716. currentValue.copy( newValue );
  11717. } else if ( key === 'overdraw' ) {
  11718. // ensure overdraw is backwards-compatible with legacy boolean type
  11719. this[ key ] = Number( newValue );
  11720. } else {
  11721. this[ key ] = newValue;
  11722. }
  11723. }
  11724. },
  11725. toJSON: function ( meta ) {
  11726. var isRoot = meta === undefined;
  11727. if ( isRoot ) {
  11728. meta = {
  11729. textures: {},
  11730. images: {}
  11731. };
  11732. }
  11733. var data = {
  11734. metadata: {
  11735. version: 4.4,
  11736. type: 'Material',
  11737. generator: 'Material.toJSON'
  11738. }
  11739. };
  11740. // standard Material serialization
  11741. data.uuid = this.uuid;
  11742. data.type = this.type;
  11743. if ( this.name !== '' ) data.name = this.name;
  11744. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  11745. if ( this.roughness !== 0.5 ) data.roughness = this.roughness;
  11746. if ( this.metalness !== 0.5 ) data.metalness = this.metalness;
  11747. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  11748. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  11749. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  11750. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  11751. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  11752. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  11753. if ( this.bumpMap instanceof THREE.Texture ) {
  11754. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  11755. data.bumpScale = this.bumpScale;
  11756. }
  11757. if ( this.normalMap instanceof THREE.Texture ) {
  11758. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  11759. data.normalScale = this.normalScale.toArray();
  11760. }
  11761. if ( this.displacementMap instanceof THREE.Texture ) {
  11762. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  11763. data.displacementScale = this.displacementScale;
  11764. data.displacementBias = this.displacementBias;
  11765. }
  11766. if ( this.roughnessMap instanceof THREE.Texture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  11767. if ( this.metalnessMap instanceof THREE.Texture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  11768. if ( this.emissiveMap instanceof THREE.Texture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  11769. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  11770. if ( this.envMap instanceof THREE.Texture ) {
  11771. data.envMap = this.envMap.toJSON( meta ).uuid;
  11772. data.reflectivity = this.reflectivity; // Scale behind envMap
  11773. }
  11774. if ( this.size !== undefined ) data.size = this.size;
  11775. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  11776. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  11777. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  11778. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  11779. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  11780. if ( this.opacity < 1 ) data.opacity = this.opacity;
  11781. if ( this.transparent === true ) data.transparent = this.transparent;
  11782. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  11783. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  11784. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  11785. // TODO: Copied from Object3D.toJSON
  11786. function extractFromCache ( cache ) {
  11787. var values = [];
  11788. for ( var key in cache ) {
  11789. var data = cache[ key ];
  11790. delete data.metadata;
  11791. values.push( data );
  11792. }
  11793. return values;
  11794. }
  11795. if ( isRoot ) {
  11796. var textures = extractFromCache( meta.textures );
  11797. var images = extractFromCache( meta.images );
  11798. if ( textures.length > 0 ) data.textures = textures;
  11799. if ( images.length > 0 ) data.images = images;
  11800. }
  11801. return data;
  11802. },
  11803. clone: function () {
  11804. return new this.constructor().copy( this );
  11805. },
  11806. copy: function ( source ) {
  11807. this.name = source.name;
  11808. this.side = source.side;
  11809. this.opacity = source.opacity;
  11810. this.transparent = source.transparent;
  11811. this.blending = source.blending;
  11812. this.blendSrc = source.blendSrc;
  11813. this.blendDst = source.blendDst;
  11814. this.blendEquation = source.blendEquation;
  11815. this.blendSrcAlpha = source.blendSrcAlpha;
  11816. this.blendDstAlpha = source.blendDstAlpha;
  11817. this.blendEquationAlpha = source.blendEquationAlpha;
  11818. this.depthFunc = source.depthFunc;
  11819. this.depthTest = source.depthTest;
  11820. this.depthWrite = source.depthWrite;
  11821. this.colorWrite = source.colorWrite;
  11822. this.precision = source.precision;
  11823. this.polygonOffset = source.polygonOffset;
  11824. this.polygonOffsetFactor = source.polygonOffsetFactor;
  11825. this.polygonOffsetUnits = source.polygonOffsetUnits;
  11826. this.alphaTest = source.alphaTest;
  11827. this.overdraw = source.overdraw;
  11828. this.visible = source.visible;
  11829. return this;
  11830. },
  11831. update: function () {
  11832. this.dispatchEvent( { type: 'update' } );
  11833. },
  11834. dispose: function () {
  11835. this.dispatchEvent( { type: 'dispose' } );
  11836. }
  11837. };
  11838. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  11839. THREE.MaterialIdCount = 0;
  11840. // File:src/materials/LineBasicMaterial.js
  11841. /**
  11842. * @author mrdoob / http://mrdoob.com/
  11843. * @author alteredq / http://alteredqualia.com/
  11844. *
  11845. * parameters = {
  11846. * color: <hex>,
  11847. * opacity: <float>,
  11848. *
  11849. * blending: THREE.NormalBlending,
  11850. * depthTest: <bool>,
  11851. * depthWrite: <bool>,
  11852. *
  11853. * linewidth: <float>,
  11854. * linecap: "round",
  11855. * linejoin: "round",
  11856. *
  11857. * vertexColors: <bool>
  11858. *
  11859. * fog: <bool>
  11860. * }
  11861. */
  11862. THREE.LineBasicMaterial = function ( parameters ) {
  11863. THREE.Material.call( this );
  11864. this.type = 'LineBasicMaterial';
  11865. this.color = new THREE.Color( 0xffffff );
  11866. this.linewidth = 1;
  11867. this.linecap = 'round';
  11868. this.linejoin = 'round';
  11869. this.vertexColors = THREE.NoColors;
  11870. this.fog = true;
  11871. this.setValues( parameters );
  11872. };
  11873. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  11874. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  11875. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  11876. THREE.Material.prototype.copy.call( this, source );
  11877. this.color.copy( source.color );
  11878. this.linewidth = source.linewidth;
  11879. this.linecap = source.linecap;
  11880. this.linejoin = source.linejoin;
  11881. this.vertexColors = source.vertexColors;
  11882. this.fog = source.fog;
  11883. return this;
  11884. };
  11885. // File:src/materials/LineDashedMaterial.js
  11886. /**
  11887. * @author alteredq / http://alteredqualia.com/
  11888. *
  11889. * parameters = {
  11890. * color: <hex>,
  11891. * opacity: <float>,
  11892. *
  11893. * blending: THREE.NormalBlending,
  11894. * depthTest: <bool>,
  11895. * depthWrite: <bool>,
  11896. *
  11897. * linewidth: <float>,
  11898. *
  11899. * scale: <float>,
  11900. * dashSize: <float>,
  11901. * gapSize: <float>,
  11902. *
  11903. * vertexColors: THREE.NoColors / THREE.FaceColors / THREE.VertexColors
  11904. *
  11905. * fog: <bool>
  11906. * }
  11907. */
  11908. THREE.LineDashedMaterial = function ( parameters ) {
  11909. THREE.Material.call( this );
  11910. this.type = 'LineDashedMaterial';
  11911. this.color = new THREE.Color( 0xffffff );
  11912. this.linewidth = 1;
  11913. this.scale = 1;
  11914. this.dashSize = 3;
  11915. this.gapSize = 1;
  11916. this.vertexColors = THREE.NoColors;
  11917. this.fog = true;
  11918. this.setValues( parameters );
  11919. };
  11920. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  11921. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  11922. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  11923. THREE.Material.prototype.copy.call( this, source );
  11924. this.color.copy( source.color );
  11925. this.linewidth = source.linewidth;
  11926. this.scale = source.scale;
  11927. this.dashSize = source.dashSize;
  11928. this.gapSize = source.gapSize;
  11929. this.vertexColors = source.vertexColors;
  11930. this.fog = source.fog;
  11931. return this;
  11932. };
  11933. // File:src/materials/MeshBasicMaterial.js
  11934. /**
  11935. * @author mrdoob / http://mrdoob.com/
  11936. * @author alteredq / http://alteredqualia.com/
  11937. *
  11938. * parameters = {
  11939. * color: <hex>,
  11940. * opacity: <float>,
  11941. * map: new THREE.Texture( <Image> ),
  11942. *
  11943. * aoMap: new THREE.Texture( <Image> ),
  11944. * aoMapIntensity: <float>
  11945. *
  11946. * specularMap: new THREE.Texture( <Image> ),
  11947. *
  11948. * alphaMap: new THREE.Texture( <Image> ),
  11949. *
  11950. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  11951. * combine: THREE.Multiply,
  11952. * reflectivity: <float>,
  11953. * refractionRatio: <float>,
  11954. *
  11955. * shading: THREE.SmoothShading,
  11956. * blending: THREE.NormalBlending,
  11957. * depthTest: <bool>,
  11958. * depthWrite: <bool>,
  11959. *
  11960. * wireframe: <boolean>,
  11961. * wireframeLinewidth: <float>,
  11962. *
  11963. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  11964. *
  11965. * skinning: <bool>,
  11966. * morphTargets: <bool>,
  11967. *
  11968. * fog: <bool>
  11969. * }
  11970. */
  11971. THREE.MeshBasicMaterial = function ( parameters ) {
  11972. THREE.Material.call( this );
  11973. this.type = 'MeshBasicMaterial';
  11974. this.color = new THREE.Color( 0xffffff ); // emissive
  11975. this.map = null;
  11976. this.aoMap = null;
  11977. this.aoMapIntensity = 1.0;
  11978. this.specularMap = null;
  11979. this.alphaMap = null;
  11980. this.envMap = null;
  11981. this.combine = THREE.MultiplyOperation;
  11982. this.reflectivity = 1;
  11983. this.refractionRatio = 0.98;
  11984. this.fog = true;
  11985. this.shading = THREE.SmoothShading;
  11986. this.wireframe = false;
  11987. this.wireframeLinewidth = 1;
  11988. this.wireframeLinecap = 'round';
  11989. this.wireframeLinejoin = 'round';
  11990. this.vertexColors = THREE.NoColors;
  11991. this.skinning = false;
  11992. this.morphTargets = false;
  11993. this.setValues( parameters );
  11994. };
  11995. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  11996. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  11997. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  11998. THREE.Material.prototype.copy.call( this, source );
  11999. this.color.copy( source.color );
  12000. this.map = source.map;
  12001. this.aoMap = source.aoMap;
  12002. this.aoMapIntensity = source.aoMapIntensity;
  12003. this.specularMap = source.specularMap;
  12004. this.alphaMap = source.alphaMap;
  12005. this.envMap = source.envMap;
  12006. this.combine = source.combine;
  12007. this.reflectivity = source.reflectivity;
  12008. this.refractionRatio = source.refractionRatio;
  12009. this.fog = source.fog;
  12010. this.shading = source.shading;
  12011. this.wireframe = source.wireframe;
  12012. this.wireframeLinewidth = source.wireframeLinewidth;
  12013. this.wireframeLinecap = source.wireframeLinecap;
  12014. this.wireframeLinejoin = source.wireframeLinejoin;
  12015. this.vertexColors = source.vertexColors;
  12016. this.skinning = source.skinning;
  12017. this.morphTargets = source.morphTargets;
  12018. return this;
  12019. };
  12020. // File:src/materials/MeshLambertMaterial.js
  12021. /**
  12022. * @author mrdoob / http://mrdoob.com/
  12023. * @author alteredq / http://alteredqualia.com/
  12024. *
  12025. * parameters = {
  12026. * color: <hex>,
  12027. * opacity: <float>,
  12028. *
  12029. * map: new THREE.Texture( <Image> ),
  12030. *
  12031. * lightMap: new THREE.Texture( <Image> ),
  12032. * lightMapIntensity: <float>
  12033. *
  12034. * aoMap: new THREE.Texture( <Image> ),
  12035. * aoMapIntensity: <float>
  12036. *
  12037. * emissive: <hex>,
  12038. * emissiveIntensity: <float>
  12039. * emissiveMap: new THREE.Texture( <Image> ),
  12040. *
  12041. * specularMap: new THREE.Texture( <Image> ),
  12042. *
  12043. * alphaMap: new THREE.Texture( <Image> ),
  12044. *
  12045. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12046. * combine: THREE.Multiply,
  12047. * reflectivity: <float>,
  12048. * refractionRatio: <float>,
  12049. *
  12050. * blending: THREE.NormalBlending,
  12051. * depthTest: <bool>,
  12052. * depthWrite: <bool>,
  12053. *
  12054. * wireframe: <boolean>,
  12055. * wireframeLinewidth: <float>,
  12056. *
  12057. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12058. *
  12059. * skinning: <bool>,
  12060. * morphTargets: <bool>,
  12061. * morphNormals: <bool>,
  12062. *
  12063. * fog: <bool>
  12064. * }
  12065. */
  12066. THREE.MeshLambertMaterial = function ( parameters ) {
  12067. THREE.Material.call( this );
  12068. this.type = 'MeshLambertMaterial';
  12069. this.color = new THREE.Color( 0xffffff ); // diffuse
  12070. this.map = null;
  12071. this.lightMap = null;
  12072. this.lightMapIntensity = 1.0;
  12073. this.aoMap = null;
  12074. this.aoMapIntensity = 1.0;
  12075. this.emissive = new THREE.Color( 0x000000 );
  12076. this.emissiveIntensity = 1.0;
  12077. this.emissiveMap = null;
  12078. this.specularMap = null;
  12079. this.alphaMap = null;
  12080. this.envMap = null;
  12081. this.combine = THREE.MultiplyOperation;
  12082. this.reflectivity = 1;
  12083. this.refractionRatio = 0.98;
  12084. this.fog = true;
  12085. this.wireframe = false;
  12086. this.wireframeLinewidth = 1;
  12087. this.wireframeLinecap = 'round';
  12088. this.wireframeLinejoin = 'round';
  12089. this.vertexColors = THREE.NoColors;
  12090. this.skinning = false;
  12091. this.morphTargets = false;
  12092. this.morphNormals = false;
  12093. this.setValues( parameters );
  12094. };
  12095. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  12096. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  12097. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  12098. THREE.Material.prototype.copy.call( this, source );
  12099. this.color.copy( source.color );
  12100. this.map = source.map;
  12101. this.lightMap = source.lightMap;
  12102. this.lightMapIntensity = source.lightMapIntensity;
  12103. this.aoMap = source.aoMap;
  12104. this.aoMapIntensity = source.aoMapIntensity;
  12105. this.emissive.copy( source.emissive );
  12106. this.emissiveMap = source.emissiveMap;
  12107. this.emissiveIntensity = source.emissiveIntensity;
  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.wireframe = source.wireframe;
  12116. this.wireframeLinewidth = source.wireframeLinewidth;
  12117. this.wireframeLinecap = source.wireframeLinecap;
  12118. this.wireframeLinejoin = source.wireframeLinejoin;
  12119. this.vertexColors = source.vertexColors;
  12120. this.skinning = source.skinning;
  12121. this.morphTargets = source.morphTargets;
  12122. this.morphNormals = source.morphNormals;
  12123. return this;
  12124. };
  12125. // File:src/materials/MeshPhongMaterial.js
  12126. /**
  12127. * @author mrdoob / http://mrdoob.com/
  12128. * @author alteredq / http://alteredqualia.com/
  12129. *
  12130. * parameters = {
  12131. * color: <hex>,
  12132. * specular: <hex>,
  12133. * shininess: <float>,
  12134. * opacity: <float>,
  12135. *
  12136. * map: new THREE.Texture( <Image> ),
  12137. *
  12138. * lightMap: new THREE.Texture( <Image> ),
  12139. * lightMapIntensity: <float>
  12140. *
  12141. * aoMap: new THREE.Texture( <Image> ),
  12142. * aoMapIntensity: <float>
  12143. *
  12144. * emissive: <hex>,
  12145. * emissiveIntensity: <float>
  12146. * emissiveMap: new THREE.Texture( <Image> ),
  12147. *
  12148. * bumpMap: new THREE.Texture( <Image> ),
  12149. * bumpScale: <float>,
  12150. *
  12151. * normalMap: new THREE.Texture( <Image> ),
  12152. * normalScale: <Vector2>,
  12153. *
  12154. * displacementMap: new THREE.Texture( <Image> ),
  12155. * displacementScale: <float>,
  12156. * displacementBias: <float>,
  12157. *
  12158. * specularMap: new THREE.Texture( <Image> ),
  12159. *
  12160. * alphaMap: new THREE.Texture( <Image> ),
  12161. *
  12162. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12163. * combine: THREE.Multiply,
  12164. * reflectivity: <float>,
  12165. * refractionRatio: <float>,
  12166. *
  12167. * shading: THREE.SmoothShading,
  12168. * blending: THREE.NormalBlending,
  12169. * depthTest: <bool>,
  12170. * depthWrite: <bool>,
  12171. *
  12172. * wireframe: <boolean>,
  12173. * wireframeLinewidth: <float>,
  12174. *
  12175. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12176. *
  12177. * skinning: <bool>,
  12178. * morphTargets: <bool>,
  12179. * morphNormals: <bool>,
  12180. *
  12181. * fog: <bool>
  12182. * }
  12183. */
  12184. THREE.MeshPhongMaterial = function ( parameters ) {
  12185. THREE.Material.call( this );
  12186. this.type = 'MeshPhongMaterial';
  12187. this.color = new THREE.Color( 0xffffff ); // diffuse
  12188. this.specular = new THREE.Color( 0x111111 );
  12189. this.shininess = 30;
  12190. this.map = null;
  12191. this.lightMap = null;
  12192. this.lightMapIntensity = 1.0;
  12193. this.aoMap = null;
  12194. this.aoMapIntensity = 1.0;
  12195. this.emissive = new THREE.Color( 0x000000 );
  12196. this.emissiveIntensity = 1.0;
  12197. this.emissiveMap = null;
  12198. this.bumpMap = null;
  12199. this.bumpScale = 1;
  12200. this.normalMap = null;
  12201. this.normalScale = new THREE.Vector2( 1, 1 );
  12202. this.displacementMap = null;
  12203. this.displacementScale = 1;
  12204. this.displacementBias = 0;
  12205. this.specularMap = null;
  12206. this.alphaMap = null;
  12207. this.envMap = null;
  12208. this.combine = THREE.MultiplyOperation;
  12209. this.reflectivity = 1;
  12210. this.refractionRatio = 0.98;
  12211. this.fog = true;
  12212. this.shading = THREE.SmoothShading;
  12213. this.wireframe = false;
  12214. this.wireframeLinewidth = 1;
  12215. this.wireframeLinecap = 'round';
  12216. this.wireframeLinejoin = 'round';
  12217. this.vertexColors = THREE.NoColors;
  12218. this.skinning = false;
  12219. this.morphTargets = false;
  12220. this.morphNormals = false;
  12221. this.setValues( parameters );
  12222. };
  12223. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  12224. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  12225. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  12226. THREE.Material.prototype.copy.call( this, source );
  12227. this.color.copy( source.color );
  12228. this.specular.copy( source.specular );
  12229. this.shininess = source.shininess;
  12230. this.map = source.map;
  12231. this.lightMap = source.lightMap;
  12232. this.lightMapIntensity = source.lightMapIntensity;
  12233. this.aoMap = source.aoMap;
  12234. this.aoMapIntensity = source.aoMapIntensity;
  12235. this.emissive.copy( source.emissive );
  12236. this.emissiveMap = source.emissiveMap;
  12237. this.emissiveIntensity = source.emissiveIntensity;
  12238. this.bumpMap = source.bumpMap;
  12239. this.bumpScale = source.bumpScale;
  12240. this.normalMap = source.normalMap;
  12241. this.normalScale.copy( source.normalScale );
  12242. this.displacementMap = source.displacementMap;
  12243. this.displacementScale = source.displacementScale;
  12244. this.displacementBias = source.displacementBias;
  12245. this.specularMap = source.specularMap;
  12246. this.alphaMap = source.alphaMap;
  12247. this.envMap = source.envMap;
  12248. this.combine = source.combine;
  12249. this.reflectivity = source.reflectivity;
  12250. this.refractionRatio = source.refractionRatio;
  12251. this.fog = source.fog;
  12252. this.shading = source.shading;
  12253. this.wireframe = source.wireframe;
  12254. this.wireframeLinewidth = source.wireframeLinewidth;
  12255. this.wireframeLinecap = source.wireframeLinecap;
  12256. this.wireframeLinejoin = source.wireframeLinejoin;
  12257. this.vertexColors = source.vertexColors;
  12258. this.skinning = source.skinning;
  12259. this.morphTargets = source.morphTargets;
  12260. this.morphNormals = source.morphNormals;
  12261. return this;
  12262. };
  12263. // File:src/materials/MeshStandardMaterial.js
  12264. /**
  12265. * @author WestLangley / http://github.com/WestLangley
  12266. *
  12267. * parameters = {
  12268. * color: <hex>,
  12269. * roughness: <float>,
  12270. * metalness: <float>,
  12271. * opacity: <float>,
  12272. *
  12273. * map: new THREE.Texture( <Image> ),
  12274. *
  12275. * lightMap: new THREE.Texture( <Image> ),
  12276. * lightMapIntensity: <float>
  12277. *
  12278. * aoMap: new THREE.Texture( <Image> ),
  12279. * aoMapIntensity: <float>
  12280. *
  12281. * emissive: <hex>,
  12282. * emissiveIntensity: <float>
  12283. * emissiveMap: new THREE.Texture( <Image> ),
  12284. *
  12285. * bumpMap: new THREE.Texture( <Image> ),
  12286. * bumpScale: <float>,
  12287. *
  12288. * normalMap: new THREE.Texture( <Image> ),
  12289. * normalScale: <Vector2>,
  12290. *
  12291. * displacementMap: new THREE.Texture( <Image> ),
  12292. * displacementScale: <float>,
  12293. * displacementBias: <float>,
  12294. *
  12295. * roughnessMap: new THREE.Texture( <Image> ),
  12296. *
  12297. * metalnessMap: new THREE.Texture( <Image> ),
  12298. *
  12299. * alphaMap: new THREE.Texture( <Image> ),
  12300. *
  12301. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  12302. * envMapIntensity: <float>
  12303. *
  12304. * refractionRatio: <float>,
  12305. *
  12306. * shading: THREE.SmoothShading,
  12307. * blending: THREE.NormalBlending,
  12308. * depthTest: <bool>,
  12309. * depthWrite: <bool>,
  12310. *
  12311. * wireframe: <boolean>,
  12312. * wireframeLinewidth: <float>,
  12313. *
  12314. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12315. *
  12316. * skinning: <bool>,
  12317. * morphTargets: <bool>,
  12318. * morphNormals: <bool>,
  12319. *
  12320. * fog: <bool>
  12321. * }
  12322. */
  12323. THREE.MeshStandardMaterial = function ( parameters ) {
  12324. THREE.Material.call( this );
  12325. this.type = 'MeshStandardMaterial';
  12326. this.color = new THREE.Color( 0xffffff ); // diffuse
  12327. this.roughness = 0.5;
  12328. this.metalness = 0.5;
  12329. this.map = null;
  12330. this.lightMap = null;
  12331. this.lightMapIntensity = 1.0;
  12332. this.aoMap = null;
  12333. this.aoMapIntensity = 1.0;
  12334. this.emissive = new THREE.Color( 0x000000 );
  12335. this.emissiveIntensity = 1.0;
  12336. this.emissiveMap = null;
  12337. this.bumpMap = null;
  12338. this.bumpScale = 1;
  12339. this.normalMap = null;
  12340. this.normalScale = new THREE.Vector2( 1, 1 );
  12341. this.displacementMap = null;
  12342. this.displacementScale = 1;
  12343. this.displacementBias = 0;
  12344. this.roughnessMap = null;
  12345. this.metalnessMap = null;
  12346. this.alphaMap = null;
  12347. this.envMap = null;
  12348. this.envMapIntensity = 1.0;
  12349. this.refractionRatio = 0.98;
  12350. this.fog = true;
  12351. this.shading = THREE.SmoothShading;
  12352. this.wireframe = false;
  12353. this.wireframeLinewidth = 1;
  12354. this.wireframeLinecap = 'round';
  12355. this.wireframeLinejoin = 'round';
  12356. this.vertexColors = THREE.NoColors;
  12357. this.skinning = false;
  12358. this.morphTargets = false;
  12359. this.morphNormals = false;
  12360. this.setValues( parameters );
  12361. };
  12362. THREE.MeshStandardMaterial.prototype = Object.create( THREE.Material.prototype );
  12363. THREE.MeshStandardMaterial.prototype.constructor = THREE.MeshStandardMaterial;
  12364. THREE.MeshStandardMaterial.prototype.copy = function ( source ) {
  12365. THREE.Material.prototype.copy.call( this, source );
  12366. this.color.copy( source.color );
  12367. this.roughness = source.roughness;
  12368. this.metalness = source.metalness;
  12369. this.map = source.map;
  12370. this.lightMap = source.lightMap;
  12371. this.lightMapIntensity = source.lightMapIntensity;
  12372. this.aoMap = source.aoMap;
  12373. this.aoMapIntensity = source.aoMapIntensity;
  12374. this.emissive.copy( source.emissive );
  12375. this.emissiveMap = source.emissiveMap;
  12376. this.emissiveIntensity = source.emissiveIntensity;
  12377. this.bumpMap = source.bumpMap;
  12378. this.bumpScale = source.bumpScale;
  12379. this.normalMap = source.normalMap;
  12380. this.normalScale.copy( source.normalScale );
  12381. this.displacementMap = source.displacementMap;
  12382. this.displacementScale = source.displacementScale;
  12383. this.displacementBias = source.displacementBias;
  12384. this.roughnessMap = source.roughnessMap;
  12385. this.metalnessMap = source.metalnessMap;
  12386. this.alphaMap = source.alphaMap;
  12387. this.envMap = source.envMap;
  12388. this.envMapIntensity = source.envMapIntensity;
  12389. this.refractionRatio = source.refractionRatio;
  12390. this.fog = source.fog;
  12391. this.shading = source.shading;
  12392. this.wireframe = source.wireframe;
  12393. this.wireframeLinewidth = source.wireframeLinewidth;
  12394. this.wireframeLinecap = source.wireframeLinecap;
  12395. this.wireframeLinejoin = source.wireframeLinejoin;
  12396. this.vertexColors = source.vertexColors;
  12397. this.skinning = source.skinning;
  12398. this.morphTargets = source.morphTargets;
  12399. this.morphNormals = source.morphNormals;
  12400. return this;
  12401. };
  12402. // File:src/materials/MeshDepthMaterial.js
  12403. /**
  12404. * @author mrdoob / http://mrdoob.com/
  12405. * @author alteredq / http://alteredqualia.com/
  12406. *
  12407. * parameters = {
  12408. * opacity: <float>,
  12409. *
  12410. * blending: THREE.NormalBlending,
  12411. * depthTest: <bool>,
  12412. * depthWrite: <bool>,
  12413. *
  12414. * wireframe: <boolean>,
  12415. * wireframeLinewidth: <float>
  12416. * }
  12417. */
  12418. THREE.MeshDepthMaterial = function ( parameters ) {
  12419. THREE.Material.call( this );
  12420. this.type = 'MeshDepthMaterial';
  12421. this.morphTargets = false;
  12422. this.wireframe = false;
  12423. this.wireframeLinewidth = 1;
  12424. this.setValues( parameters );
  12425. };
  12426. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  12427. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  12428. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  12429. THREE.Material.prototype.copy.call( this, source );
  12430. this.wireframe = source.wireframe;
  12431. this.wireframeLinewidth = source.wireframeLinewidth;
  12432. return this;
  12433. };
  12434. // File:src/materials/MeshNormalMaterial.js
  12435. /**
  12436. * @author mrdoob / http://mrdoob.com/
  12437. *
  12438. * parameters = {
  12439. * opacity: <float>,
  12440. *
  12441. * blending: THREE.NormalBlending,
  12442. * depthTest: <bool>,
  12443. * depthWrite: <bool>,
  12444. *
  12445. * wireframe: <boolean>,
  12446. * wireframeLinewidth: <float>
  12447. * }
  12448. */
  12449. THREE.MeshNormalMaterial = function ( parameters ) {
  12450. THREE.Material.call( this, parameters );
  12451. this.type = 'MeshNormalMaterial';
  12452. this.wireframe = false;
  12453. this.wireframeLinewidth = 1;
  12454. this.morphTargets = false;
  12455. this.setValues( parameters );
  12456. };
  12457. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  12458. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  12459. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  12460. THREE.Material.prototype.copy.call( this, source );
  12461. this.wireframe = source.wireframe;
  12462. this.wireframeLinewidth = source.wireframeLinewidth;
  12463. return this;
  12464. };
  12465. // File:src/materials/MultiMaterial.js
  12466. /**
  12467. * @author mrdoob / http://mrdoob.com/
  12468. */
  12469. THREE.MultiMaterial = function ( materials ) {
  12470. this.uuid = THREE.Math.generateUUID();
  12471. this.type = 'MultiMaterial';
  12472. this.materials = materials instanceof Array ? materials : [];
  12473. this.visible = true;
  12474. };
  12475. THREE.MultiMaterial.prototype = {
  12476. constructor: THREE.MultiMaterial,
  12477. toJSON: function ( meta ) {
  12478. var output = {
  12479. metadata: {
  12480. version: 4.2,
  12481. type: 'material',
  12482. generator: 'MaterialExporter'
  12483. },
  12484. uuid: this.uuid,
  12485. type: this.type,
  12486. materials: []
  12487. };
  12488. var materials = this.materials;
  12489. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  12490. var material = materials[ i ].toJSON( meta );
  12491. delete material.metadata;
  12492. output.materials.push( material );
  12493. }
  12494. output.visible = this.visible;
  12495. return output;
  12496. },
  12497. clone: function () {
  12498. var material = new this.constructor();
  12499. for ( var i = 0; i < this.materials.length; i ++ ) {
  12500. material.materials.push( this.materials[ i ].clone() );
  12501. }
  12502. material.visible = this.visible;
  12503. return material;
  12504. }
  12505. };
  12506. // File:src/materials/PointsMaterial.js
  12507. /**
  12508. * @author mrdoob / http://mrdoob.com/
  12509. * @author alteredq / http://alteredqualia.com/
  12510. *
  12511. * parameters = {
  12512. * color: <hex>,
  12513. * opacity: <float>,
  12514. * map: new THREE.Texture( <Image> ),
  12515. *
  12516. * size: <float>,
  12517. * sizeAttenuation: <bool>,
  12518. *
  12519. * blending: THREE.NormalBlending,
  12520. * depthTest: <bool>,
  12521. * depthWrite: <bool>,
  12522. *
  12523. * vertexColors: <bool>,
  12524. *
  12525. * fog: <bool>
  12526. * }
  12527. */
  12528. THREE.PointsMaterial = function ( parameters ) {
  12529. THREE.Material.call( this );
  12530. this.type = 'PointsMaterial';
  12531. this.color = new THREE.Color( 0xffffff );
  12532. this.map = null;
  12533. this.size = 1;
  12534. this.sizeAttenuation = true;
  12535. this.vertexColors = THREE.NoColors;
  12536. this.fog = true;
  12537. this.setValues( parameters );
  12538. };
  12539. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  12540. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  12541. THREE.PointsMaterial.prototype.copy = function ( source ) {
  12542. THREE.Material.prototype.copy.call( this, source );
  12543. this.color.copy( source.color );
  12544. this.map = source.map;
  12545. this.size = source.size;
  12546. this.sizeAttenuation = source.sizeAttenuation;
  12547. this.vertexColors = source.vertexColors;
  12548. this.fog = source.fog;
  12549. return this;
  12550. };
  12551. // File:src/materials/ShaderMaterial.js
  12552. /**
  12553. * @author alteredq / http://alteredqualia.com/
  12554. *
  12555. * parameters = {
  12556. * defines: { "label" : "value" },
  12557. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  12558. *
  12559. * fragmentShader: <string>,
  12560. * vertexShader: <string>,
  12561. *
  12562. * shading: THREE.SmoothShading,
  12563. * blending: THREE.NormalBlending,
  12564. * depthTest: <bool>,
  12565. * depthWrite: <bool>,
  12566. *
  12567. * wireframe: <boolean>,
  12568. * wireframeLinewidth: <float>,
  12569. *
  12570. * lights: <bool>,
  12571. *
  12572. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12573. *
  12574. * skinning: <bool>,
  12575. * morphTargets: <bool>,
  12576. * morphNormals: <bool>,
  12577. *
  12578. * fog: <bool>
  12579. * }
  12580. */
  12581. THREE.ShaderMaterial = function ( parameters ) {
  12582. THREE.Material.call( this );
  12583. this.type = 'ShaderMaterial';
  12584. this.defines = {};
  12585. this.uniforms = {};
  12586. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12587. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12588. this.shading = THREE.SmoothShading;
  12589. this.linewidth = 1;
  12590. this.wireframe = false;
  12591. this.wireframeLinewidth = 1;
  12592. this.fog = false; // set to use scene fog
  12593. this.lights = false; // set to use scene lights
  12594. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  12595. this.skinning = false; // set to use skinning attribute streams
  12596. this.morphTargets = false; // set to use morph targets
  12597. this.morphNormals = false; // set to use morph normals
  12598. this.extensions = {
  12599. derivatives: false, // set to use derivatives
  12600. fragDepth: false, // set to use fragment depth values
  12601. drawBuffers: false, // set to use draw buffers
  12602. shaderTextureLOD: false // set to use shader texture LOD
  12603. };
  12604. // When rendered geometry doesn't include these attributes but the material does,
  12605. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12606. this.defaultAttributeValues = {
  12607. 'color': [ 1, 1, 1 ],
  12608. 'uv': [ 0, 0 ],
  12609. 'uv2': [ 0, 0 ]
  12610. };
  12611. this.index0AttributeName = undefined;
  12612. if ( parameters !== undefined ) {
  12613. if ( parameters.attributes !== undefined ) {
  12614. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12615. }
  12616. this.setValues( parameters );
  12617. }
  12618. };
  12619. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  12620. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  12621. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  12622. THREE.Material.prototype.copy.call( this, source );
  12623. this.fragmentShader = source.fragmentShader;
  12624. this.vertexShader = source.vertexShader;
  12625. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  12626. this.defines = source.defines;
  12627. this.shading = source.shading;
  12628. this.wireframe = source.wireframe;
  12629. this.wireframeLinewidth = source.wireframeLinewidth;
  12630. this.fog = source.fog;
  12631. this.lights = source.lights;
  12632. this.vertexColors = source.vertexColors;
  12633. this.skinning = source.skinning;
  12634. this.morphTargets = source.morphTargets;
  12635. this.morphNormals = source.morphNormals;
  12636. this.extensions = source.extensions;
  12637. return this;
  12638. };
  12639. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  12640. var data = THREE.Material.prototype.toJSON.call( this, meta );
  12641. data.uniforms = this.uniforms;
  12642. data.vertexShader = this.vertexShader;
  12643. data.fragmentShader = this.fragmentShader;
  12644. return data;
  12645. };
  12646. // File:src/materials/RawShaderMaterial.js
  12647. /**
  12648. * @author mrdoob / http://mrdoob.com/
  12649. */
  12650. THREE.RawShaderMaterial = function ( parameters ) {
  12651. THREE.ShaderMaterial.call( this, parameters );
  12652. this.type = 'RawShaderMaterial';
  12653. };
  12654. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  12655. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  12656. // File:src/materials/SpriteMaterial.js
  12657. /**
  12658. * @author alteredq / http://alteredqualia.com/
  12659. *
  12660. * parameters = {
  12661. * color: <hex>,
  12662. * opacity: <float>,
  12663. * map: new THREE.Texture( <Image> ),
  12664. *
  12665. * blending: THREE.NormalBlending,
  12666. * depthTest: <bool>,
  12667. * depthWrite: <bool>,
  12668. *
  12669. * uvOffset: new THREE.Vector2(),
  12670. * uvScale: new THREE.Vector2(),
  12671. *
  12672. * fog: <bool>
  12673. * }
  12674. */
  12675. THREE.SpriteMaterial = function ( parameters ) {
  12676. THREE.Material.call( this );
  12677. this.type = 'SpriteMaterial';
  12678. this.color = new THREE.Color( 0xffffff );
  12679. this.map = null;
  12680. this.rotation = 0;
  12681. this.fog = false;
  12682. // set parameters
  12683. this.setValues( parameters );
  12684. };
  12685. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  12686. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  12687. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  12688. THREE.Material.prototype.copy.call( this, source );
  12689. this.color.copy( source.color );
  12690. this.map = source.map;
  12691. this.rotation = source.rotation;
  12692. this.fog = source.fog;
  12693. return this;
  12694. };
  12695. // File:src/textures/Texture.js
  12696. /**
  12697. * @author mrdoob / http://mrdoob.com/
  12698. * @author alteredq / http://alteredqualia.com/
  12699. * @author szimek / https://github.com/szimek/
  12700. */
  12701. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12702. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  12703. this.uuid = THREE.Math.generateUUID();
  12704. this.name = '';
  12705. this.sourceFile = '';
  12706. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  12707. this.mipmaps = [];
  12708. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  12709. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  12710. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  12711. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  12712. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  12713. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  12714. this.format = format !== undefined ? format : THREE.RGBAFormat;
  12715. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  12716. this.offset = new THREE.Vector2( 0, 0 );
  12717. this.repeat = new THREE.Vector2( 1, 1 );
  12718. this.generateMipmaps = true;
  12719. this.premultiplyAlpha = false;
  12720. this.flipY = true;
  12721. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  12722. this.version = 0;
  12723. this.onUpdate = null;
  12724. };
  12725. THREE.Texture.DEFAULT_IMAGE = undefined;
  12726. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  12727. THREE.Texture.prototype = {
  12728. constructor: THREE.Texture,
  12729. set needsUpdate ( value ) {
  12730. if ( value === true ) this.version ++;
  12731. },
  12732. clone: function () {
  12733. return new this.constructor().copy( this );
  12734. },
  12735. copy: function ( source ) {
  12736. this.image = source.image;
  12737. this.mipmaps = source.mipmaps.slice( 0 );
  12738. this.mapping = source.mapping;
  12739. this.wrapS = source.wrapS;
  12740. this.wrapT = source.wrapT;
  12741. this.magFilter = source.magFilter;
  12742. this.minFilter = source.minFilter;
  12743. this.anisotropy = source.anisotropy;
  12744. this.format = source.format;
  12745. this.type = source.type;
  12746. this.offset.copy( source.offset );
  12747. this.repeat.copy( source.repeat );
  12748. this.generateMipmaps = source.generateMipmaps;
  12749. this.premultiplyAlpha = source.premultiplyAlpha;
  12750. this.flipY = source.flipY;
  12751. this.unpackAlignment = source.unpackAlignment;
  12752. return this;
  12753. },
  12754. toJSON: function ( meta ) {
  12755. if ( meta.textures[ this.uuid ] !== undefined ) {
  12756. return meta.textures[ this.uuid ];
  12757. }
  12758. function getDataURL( image ) {
  12759. var canvas;
  12760. if ( image.toDataURL !== undefined ) {
  12761. canvas = image;
  12762. } else {
  12763. canvas = document.createElement( 'canvas' );
  12764. canvas.width = image.width;
  12765. canvas.height = image.height;
  12766. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  12767. }
  12768. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  12769. return canvas.toDataURL( 'image/jpeg', 0.6 );
  12770. } else {
  12771. return canvas.toDataURL( 'image/png' );
  12772. }
  12773. }
  12774. var output = {
  12775. metadata: {
  12776. version: 4.4,
  12777. type: 'Texture',
  12778. generator: 'Texture.toJSON'
  12779. },
  12780. uuid: this.uuid,
  12781. name: this.name,
  12782. mapping: this.mapping,
  12783. repeat: [ this.repeat.x, this.repeat.y ],
  12784. offset: [ this.offset.x, this.offset.y ],
  12785. wrap: [ this.wrapS, this.wrapT ],
  12786. minFilter: this.minFilter,
  12787. magFilter: this.magFilter,
  12788. anisotropy: this.anisotropy
  12789. };
  12790. if ( this.image !== undefined ) {
  12791. // TODO: Move to THREE.Image
  12792. var image = this.image;
  12793. if ( image.uuid === undefined ) {
  12794. image.uuid = THREE.Math.generateUUID(); // UGH
  12795. }
  12796. if ( meta.images[ image.uuid ] === undefined ) {
  12797. meta.images[ image.uuid ] = {
  12798. uuid: image.uuid,
  12799. url: getDataURL( image )
  12800. };
  12801. }
  12802. output.image = image.uuid;
  12803. }
  12804. meta.textures[ this.uuid ] = output;
  12805. return output;
  12806. },
  12807. dispose: function () {
  12808. this.dispatchEvent( { type: 'dispose' } );
  12809. },
  12810. transformUv: function ( uv ) {
  12811. if ( this.mapping !== THREE.UVMapping ) return;
  12812. uv.multiply( this.repeat );
  12813. uv.add( this.offset );
  12814. if ( uv.x < 0 || uv.x > 1 ) {
  12815. switch ( this.wrapS ) {
  12816. case THREE.RepeatWrapping:
  12817. uv.x = uv.x - Math.floor( uv.x );
  12818. break;
  12819. case THREE.ClampToEdgeWrapping:
  12820. uv.x = uv.x < 0 ? 0 : 1;
  12821. break;
  12822. case THREE.MirroredRepeatWrapping:
  12823. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  12824. uv.x = Math.ceil( uv.x ) - uv.x;
  12825. } else {
  12826. uv.x = uv.x - Math.floor( uv.x );
  12827. }
  12828. break;
  12829. }
  12830. }
  12831. if ( uv.y < 0 || uv.y > 1 ) {
  12832. switch ( this.wrapT ) {
  12833. case THREE.RepeatWrapping:
  12834. uv.y = uv.y - Math.floor( uv.y );
  12835. break;
  12836. case THREE.ClampToEdgeWrapping:
  12837. uv.y = uv.y < 0 ? 0 : 1;
  12838. break;
  12839. case THREE.MirroredRepeatWrapping:
  12840. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  12841. uv.y = Math.ceil( uv.y ) - uv.y;
  12842. } else {
  12843. uv.y = uv.y - Math.floor( uv.y );
  12844. }
  12845. break;
  12846. }
  12847. }
  12848. if ( this.flipY ) {
  12849. uv.y = 1 - uv.y;
  12850. }
  12851. }
  12852. };
  12853. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  12854. THREE.TextureIdCount = 0;
  12855. // File:src/textures/CanvasTexture.js
  12856. /**
  12857. * @author mrdoob / http://mrdoob.com/
  12858. */
  12859. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12860. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12861. this.needsUpdate = true;
  12862. };
  12863. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  12864. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  12865. // File:src/textures/CubeTexture.js
  12866. /**
  12867. * @author mrdoob / http://mrdoob.com/
  12868. */
  12869. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12870. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  12871. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12872. this.images = images;
  12873. this.flipY = false;
  12874. };
  12875. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  12876. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  12877. THREE.CubeTexture.prototype.copy = function ( source ) {
  12878. THREE.Texture.prototype.copy.call( this, source );
  12879. this.images = source.images;
  12880. return this;
  12881. };
  12882. // File:src/textures/CompressedTexture.js
  12883. /**
  12884. * @author alteredq / http://alteredqualia.com/
  12885. */
  12886. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  12887. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12888. this.image = { width: width, height: height };
  12889. this.mipmaps = mipmaps;
  12890. // no flipping for cube textures
  12891. // (also flipping doesn't work for compressed textures )
  12892. this.flipY = false;
  12893. // can't generate mipmaps for compressed textures
  12894. // mips must be embedded in DDS files
  12895. this.generateMipmaps = false;
  12896. };
  12897. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  12898. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  12899. // File:src/textures/DataTexture.js
  12900. /**
  12901. * @author alteredq / http://alteredqualia.com/
  12902. */
  12903. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  12904. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12905. this.image = { data: data, width: width, height: height };
  12906. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  12907. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  12908. this.flipY = false;
  12909. this.generateMipmaps = false;
  12910. };
  12911. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  12912. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  12913. // File:src/textures/VideoTexture.js
  12914. /**
  12915. * @author mrdoob / http://mrdoob.com/
  12916. */
  12917. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12918. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12919. this.generateMipmaps = false;
  12920. var scope = this;
  12921. function update() {
  12922. requestAnimationFrame( update );
  12923. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  12924. scope.needsUpdate = true;
  12925. }
  12926. }
  12927. update();
  12928. };
  12929. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  12930. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  12931. // File:src/objects/Group.js
  12932. /**
  12933. * @author mrdoob / http://mrdoob.com/
  12934. */
  12935. THREE.Group = function () {
  12936. THREE.Object3D.call( this );
  12937. this.type = 'Group';
  12938. };
  12939. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  12940. THREE.Group.prototype.constructor = THREE.Group;
  12941. // File:src/objects/Points.js
  12942. /**
  12943. * @author alteredq / http://alteredqualia.com/
  12944. */
  12945. THREE.Points = function ( geometry, material ) {
  12946. THREE.Object3D.call( this );
  12947. this.type = 'Points';
  12948. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  12949. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  12950. };
  12951. THREE.Points.prototype = Object.create( THREE.Object3D.prototype );
  12952. THREE.Points.prototype.constructor = THREE.Points;
  12953. THREE.Points.prototype.raycast = ( function () {
  12954. var inverseMatrix = new THREE.Matrix4();
  12955. var ray = new THREE.Ray();
  12956. var sphere = new THREE.Sphere();
  12957. return function raycast( raycaster, intersects ) {
  12958. var object = this;
  12959. var geometry = this.geometry;
  12960. var matrixWorld = this.matrixWorld;
  12961. var threshold = raycaster.params.Points.threshold;
  12962. // Checking boundingSphere distance to ray
  12963. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  12964. sphere.copy( geometry.boundingSphere );
  12965. sphere.applyMatrix4( matrixWorld );
  12966. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  12967. //
  12968. inverseMatrix.getInverse( matrixWorld );
  12969. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  12970. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  12971. var localThresholdSq = localThreshold * localThreshold;
  12972. var position = new THREE.Vector3();
  12973. function testPoint( point, index ) {
  12974. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  12975. if ( rayPointDistanceSq < localThresholdSq ) {
  12976. var intersectPoint = ray.closestPointToPoint( point );
  12977. intersectPoint.applyMatrix4( matrixWorld );
  12978. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  12979. if ( distance < raycaster.near || distance > raycaster.far ) return;
  12980. intersects.push( {
  12981. distance: distance,
  12982. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  12983. point: intersectPoint.clone(),
  12984. index: index,
  12985. face: null,
  12986. object: object
  12987. } );
  12988. }
  12989. }
  12990. if ( geometry instanceof THREE.BufferGeometry ) {
  12991. var index = geometry.index;
  12992. var attributes = geometry.attributes;
  12993. var positions = attributes.position.array;
  12994. if ( index !== null ) {
  12995. var indices = index.array;
  12996. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  12997. var a = indices[ i ];
  12998. position.fromArray( positions, a * 3 );
  12999. testPoint( position, a );
  13000. }
  13001. } else {
  13002. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  13003. position.fromArray( positions, i * 3 );
  13004. testPoint( position, i );
  13005. }
  13006. }
  13007. } else {
  13008. var vertices = geometry.vertices;
  13009. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  13010. testPoint( vertices[ i ], i );
  13011. }
  13012. }
  13013. };
  13014. }() );
  13015. THREE.Points.prototype.clone = function () {
  13016. return new this.constructor( this.geometry, this.material ).copy( this );
  13017. };
  13018. // File:src/objects/Line.js
  13019. /**
  13020. * @author mrdoob / http://mrdoob.com/
  13021. */
  13022. THREE.Line = function ( geometry, material, mode ) {
  13023. if ( mode === 1 ) {
  13024. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  13025. return new THREE.LineSegments( geometry, material );
  13026. }
  13027. THREE.Object3D.call( this );
  13028. this.type = 'Line';
  13029. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  13030. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  13031. };
  13032. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  13033. THREE.Line.prototype.constructor = THREE.Line;
  13034. THREE.Line.prototype.raycast = ( function () {
  13035. var inverseMatrix = new THREE.Matrix4();
  13036. var ray = new THREE.Ray();
  13037. var sphere = new THREE.Sphere();
  13038. return function raycast( raycaster, intersects ) {
  13039. var precision = raycaster.linePrecision;
  13040. var precisionSq = precision * precision;
  13041. var geometry = this.geometry;
  13042. var matrixWorld = this.matrixWorld;
  13043. // Checking boundingSphere distance to ray
  13044. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13045. sphere.copy( geometry.boundingSphere );
  13046. sphere.applyMatrix4( matrixWorld );
  13047. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13048. //
  13049. inverseMatrix.getInverse( matrixWorld );
  13050. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13051. var vStart = new THREE.Vector3();
  13052. var vEnd = new THREE.Vector3();
  13053. var interSegment = new THREE.Vector3();
  13054. var interRay = new THREE.Vector3();
  13055. var step = this instanceof THREE.LineSegments ? 2 : 1;
  13056. if ( geometry instanceof THREE.BufferGeometry ) {
  13057. var index = geometry.index;
  13058. var attributes = geometry.attributes;
  13059. var positions = attributes.position.array;
  13060. if ( index !== null ) {
  13061. var indices = index.array;
  13062. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  13063. var a = indices[ i ];
  13064. var b = indices[ i + 1 ];
  13065. vStart.fromArray( positions, a * 3 );
  13066. vEnd.fromArray( positions, b * 3 );
  13067. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13068. if ( distSq > precisionSq ) continue;
  13069. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13070. var distance = raycaster.ray.origin.distanceTo( interRay );
  13071. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13072. intersects.push( {
  13073. distance: distance,
  13074. // What do we want? intersection point on the ray or on the segment??
  13075. // point: raycaster.ray.at( distance ),
  13076. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13077. index: i,
  13078. face: null,
  13079. faceIndex: null,
  13080. object: this
  13081. } );
  13082. }
  13083. } else {
  13084. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  13085. vStart.fromArray( positions, 3 * i );
  13086. vEnd.fromArray( positions, 3 * i + 3 );
  13087. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13088. if ( distSq > precisionSq ) continue;
  13089. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13090. var distance = raycaster.ray.origin.distanceTo( interRay );
  13091. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13092. intersects.push( {
  13093. distance: distance,
  13094. // What do we want? intersection point on the ray or on the segment??
  13095. // point: raycaster.ray.at( distance ),
  13096. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13097. index: i,
  13098. face: null,
  13099. faceIndex: null,
  13100. object: this
  13101. } );
  13102. }
  13103. }
  13104. } else if ( geometry instanceof THREE.Geometry ) {
  13105. var vertices = geometry.vertices;
  13106. var nbVertices = vertices.length;
  13107. for ( var i = 0; i < nbVertices - 1; i += step ) {
  13108. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  13109. if ( distSq > precisionSq ) continue;
  13110. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13111. var distance = raycaster.ray.origin.distanceTo( interRay );
  13112. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13113. intersects.push( {
  13114. distance: distance,
  13115. // What do we want? intersection point on the ray or on the segment??
  13116. // point: raycaster.ray.at( distance ),
  13117. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13118. index: i,
  13119. face: null,
  13120. faceIndex: null,
  13121. object: this
  13122. } );
  13123. }
  13124. }
  13125. };
  13126. }() );
  13127. THREE.Line.prototype.clone = function () {
  13128. return new this.constructor( this.geometry, this.material ).copy( this );
  13129. };
  13130. // DEPRECATED
  13131. THREE.LineStrip = 0;
  13132. THREE.LinePieces = 1;
  13133. // File:src/objects/LineSegments.js
  13134. /**
  13135. * @author mrdoob / http://mrdoob.com/
  13136. */
  13137. THREE.LineSegments = function ( geometry, material ) {
  13138. THREE.Line.call( this, geometry, material );
  13139. this.type = 'LineSegments';
  13140. };
  13141. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  13142. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  13143. // File:src/objects/Mesh.js
  13144. /**
  13145. * @author mrdoob / http://mrdoob.com/
  13146. * @author alteredq / http://alteredqualia.com/
  13147. * @author mikael emtinger / http://gomo.se/
  13148. * @author jonobr1 / http://jonobr1.com/
  13149. */
  13150. THREE.Mesh = function ( geometry, material ) {
  13151. THREE.Object3D.call( this );
  13152. this.type = 'Mesh';
  13153. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  13154. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  13155. this.drawMode = THREE.TrianglesDrawMode;
  13156. this.updateMorphTargets();
  13157. };
  13158. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  13159. THREE.Mesh.prototype.constructor = THREE.Mesh;
  13160. THREE.Mesh.prototype.setDrawMode = function ( value ) {
  13161. this.drawMode = value;
  13162. };
  13163. THREE.Mesh.prototype.updateMorphTargets = function () {
  13164. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  13165. this.morphTargetBase = - 1;
  13166. this.morphTargetInfluences = [];
  13167. this.morphTargetDictionary = {};
  13168. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  13169. this.morphTargetInfluences.push( 0 );
  13170. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  13171. }
  13172. }
  13173. };
  13174. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  13175. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  13176. return this.morphTargetDictionary[ name ];
  13177. }
  13178. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  13179. return 0;
  13180. };
  13181. THREE.Mesh.prototype.raycast = ( function () {
  13182. var inverseMatrix = new THREE.Matrix4();
  13183. var ray = new THREE.Ray();
  13184. var sphere = new THREE.Sphere();
  13185. var vA = new THREE.Vector3();
  13186. var vB = new THREE.Vector3();
  13187. var vC = new THREE.Vector3();
  13188. var tempA = new THREE.Vector3();
  13189. var tempB = new THREE.Vector3();
  13190. var tempC = new THREE.Vector3();
  13191. var uvA = new THREE.Vector2();
  13192. var uvB = new THREE.Vector2();
  13193. var uvC = new THREE.Vector2();
  13194. var barycoord = new THREE.Vector3();
  13195. var intersectionPoint = new THREE.Vector3();
  13196. var intersectionPointWorld = new THREE.Vector3();
  13197. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  13198. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  13199. uv1.multiplyScalar( barycoord.x );
  13200. uv2.multiplyScalar( barycoord.y );
  13201. uv3.multiplyScalar( barycoord.z );
  13202. uv1.add( uv2 ).add( uv3 );
  13203. return uv1.clone();
  13204. }
  13205. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ) {
  13206. var intersect;
  13207. var material = object.material;
  13208. if ( material.side === THREE.BackSide ) {
  13209. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  13210. } else {
  13211. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== THREE.DoubleSide, point );
  13212. }
  13213. if ( intersect === null ) return null;
  13214. intersectionPointWorld.copy( point );
  13215. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  13216. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  13217. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  13218. return {
  13219. distance: distance,
  13220. point: intersectionPointWorld.clone(),
  13221. object: object
  13222. };
  13223. }
  13224. function checkBufferGeometryIntersection( object, raycaster, ray, positions, uvs, a, b, c ) {
  13225. vA.fromArray( positions, a * 3 );
  13226. vB.fromArray( positions, b * 3 );
  13227. vC.fromArray( positions, c * 3 );
  13228. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  13229. if ( intersection ) {
  13230. if ( uvs ) {
  13231. uvA.fromArray( uvs, a * 2 );
  13232. uvB.fromArray( uvs, b * 2 );
  13233. uvC.fromArray( uvs, c * 2 );
  13234. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  13235. }
  13236. intersection.face = new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) );
  13237. intersection.faceIndex = a;
  13238. }
  13239. return intersection;
  13240. }
  13241. return function raycast( raycaster, intersects ) {
  13242. var geometry = this.geometry;
  13243. var material = this.material;
  13244. var matrixWorld = this.matrixWorld;
  13245. if ( material === undefined ) return;
  13246. // Checking boundingSphere distance to ray
  13247. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13248. sphere.copy( geometry.boundingSphere );
  13249. sphere.applyMatrix4( matrixWorld );
  13250. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13251. //
  13252. inverseMatrix.getInverse( matrixWorld );
  13253. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13254. // Check boundingBox before continuing
  13255. if ( geometry.boundingBox !== null ) {
  13256. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  13257. }
  13258. var uvs, intersection;
  13259. if ( geometry instanceof THREE.BufferGeometry ) {
  13260. var a, b, c;
  13261. var index = geometry.index;
  13262. var attributes = geometry.attributes;
  13263. var positions = attributes.position.array;
  13264. if ( attributes.uv !== undefined ) {
  13265. uvs = attributes.uv.array;
  13266. }
  13267. if ( index !== null ) {
  13268. var indices = index.array;
  13269. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  13270. a = indices[ i ];
  13271. b = indices[ i + 1 ];
  13272. c = indices[ i + 2 ];
  13273. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13274. if ( intersection ) {
  13275. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  13276. intersects.push( intersection );
  13277. }
  13278. }
  13279. } else {
  13280. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  13281. a = i / 3;
  13282. b = a + 1;
  13283. c = a + 2;
  13284. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13285. if ( intersection ) {
  13286. intersection.index = a; // triangle number in positions buffer semantics
  13287. intersects.push( intersection );
  13288. }
  13289. }
  13290. }
  13291. } else if ( geometry instanceof THREE.Geometry ) {
  13292. var fvA, fvB, fvC;
  13293. var isFaceMaterial = material instanceof THREE.MultiMaterial;
  13294. var materials = isFaceMaterial === true ? material.materials : null;
  13295. var vertices = geometry.vertices;
  13296. var faces = geometry.faces;
  13297. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  13298. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  13299. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  13300. var face = faces[ f ];
  13301. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  13302. if ( faceMaterial === undefined ) continue;
  13303. fvA = vertices[ face.a ];
  13304. fvB = vertices[ face.b ];
  13305. fvC = vertices[ face.c ];
  13306. if ( faceMaterial.morphTargets === true ) {
  13307. var morphTargets = geometry.morphTargets;
  13308. var morphInfluences = this.morphTargetInfluences;
  13309. vA.set( 0, 0, 0 );
  13310. vB.set( 0, 0, 0 );
  13311. vC.set( 0, 0, 0 );
  13312. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  13313. var influence = morphInfluences[ t ];
  13314. if ( influence === 0 ) continue;
  13315. var targets = morphTargets[ t ].vertices;
  13316. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  13317. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  13318. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  13319. }
  13320. vA.add( fvA );
  13321. vB.add( fvB );
  13322. vC.add( fvC );
  13323. fvA = vA;
  13324. fvB = vB;
  13325. fvC = vC;
  13326. }
  13327. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  13328. if ( intersection ) {
  13329. if ( uvs ) {
  13330. var uvs_f = uvs[ f ];
  13331. uvA.copy( uvs_f[ 0 ] );
  13332. uvB.copy( uvs_f[ 1 ] );
  13333. uvC.copy( uvs_f[ 2 ] );
  13334. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  13335. }
  13336. intersection.face = face;
  13337. intersection.faceIndex = f;
  13338. intersects.push( intersection );
  13339. }
  13340. }
  13341. }
  13342. };
  13343. }() );
  13344. THREE.Mesh.prototype.clone = function () {
  13345. return new this.constructor( this.geometry, this.material ).copy( this );
  13346. };
  13347. // File:src/objects/Bone.js
  13348. /**
  13349. * @author mikael emtinger / http://gomo.se/
  13350. * @author alteredq / http://alteredqualia.com/
  13351. * @author ikerr / http://verold.com
  13352. */
  13353. THREE.Bone = function ( skin ) {
  13354. THREE.Object3D.call( this );
  13355. this.type = 'Bone';
  13356. this.skin = skin;
  13357. };
  13358. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  13359. THREE.Bone.prototype.constructor = THREE.Bone;
  13360. THREE.Bone.prototype.copy = function ( source ) {
  13361. THREE.Object3D.prototype.copy.call( this, source );
  13362. this.skin = source.skin;
  13363. return this;
  13364. };
  13365. // File:src/objects/Skeleton.js
  13366. /**
  13367. * @author mikael emtinger / http://gomo.se/
  13368. * @author alteredq / http://alteredqualia.com/
  13369. * @author michael guerrero / http://realitymeltdown.com
  13370. * @author ikerr / http://verold.com
  13371. */
  13372. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  13373. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  13374. this.identityMatrix = new THREE.Matrix4();
  13375. // copy the bone array
  13376. bones = bones || [];
  13377. this.bones = bones.slice( 0 );
  13378. // create a bone texture or an array of floats
  13379. if ( this.useVertexTexture ) {
  13380. // layout (1 matrix = 4 pixels)
  13381. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13382. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13383. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13384. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13385. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13386. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  13387. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  13388. size = Math.max( size, 4 );
  13389. this.boneTextureWidth = size;
  13390. this.boneTextureHeight = size;
  13391. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  13392. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  13393. } else {
  13394. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  13395. }
  13396. // use the supplied bone inverses or calculate the inverses
  13397. if ( boneInverses === undefined ) {
  13398. this.calculateInverses();
  13399. } else {
  13400. if ( this.bones.length === boneInverses.length ) {
  13401. this.boneInverses = boneInverses.slice( 0 );
  13402. } else {
  13403. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  13404. this.boneInverses = [];
  13405. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13406. this.boneInverses.push( new THREE.Matrix4() );
  13407. }
  13408. }
  13409. }
  13410. };
  13411. THREE.Skeleton.prototype.calculateInverses = function () {
  13412. this.boneInverses = [];
  13413. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13414. var inverse = new THREE.Matrix4();
  13415. if ( this.bones[ b ] ) {
  13416. inverse.getInverse( this.bones[ b ].matrixWorld );
  13417. }
  13418. this.boneInverses.push( inverse );
  13419. }
  13420. };
  13421. THREE.Skeleton.prototype.pose = function () {
  13422. var bone;
  13423. // recover the bind-time world matrices
  13424. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13425. bone = this.bones[ b ];
  13426. if ( bone ) {
  13427. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  13428. }
  13429. }
  13430. // compute the local matrices, positions, rotations and scales
  13431. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13432. bone = this.bones[ b ];
  13433. if ( bone ) {
  13434. if ( bone.parent ) {
  13435. bone.matrix.getInverse( bone.parent.matrixWorld );
  13436. bone.matrix.multiply( bone.matrixWorld );
  13437. } else {
  13438. bone.matrix.copy( bone.matrixWorld );
  13439. }
  13440. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  13441. }
  13442. }
  13443. };
  13444. THREE.Skeleton.prototype.update = ( function () {
  13445. var offsetMatrix = new THREE.Matrix4();
  13446. return function update() {
  13447. // flatten bone matrices to array
  13448. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13449. // compute the offset between the current and the original transform
  13450. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  13451. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  13452. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  13453. }
  13454. if ( this.useVertexTexture ) {
  13455. this.boneTexture.needsUpdate = true;
  13456. }
  13457. };
  13458. } )();
  13459. THREE.Skeleton.prototype.clone = function () {
  13460. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  13461. };
  13462. // File:src/objects/SkinnedMesh.js
  13463. /**
  13464. * @author mikael emtinger / http://gomo.se/
  13465. * @author alteredq / http://alteredqualia.com/
  13466. * @author ikerr / http://verold.com
  13467. */
  13468. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  13469. THREE.Mesh.call( this, geometry, material );
  13470. this.type = 'SkinnedMesh';
  13471. this.bindMode = "attached";
  13472. this.bindMatrix = new THREE.Matrix4();
  13473. this.bindMatrixInverse = new THREE.Matrix4();
  13474. // init bones
  13475. // TODO: remove bone creation as there is no reason (other than
  13476. // convenience) for THREE.SkinnedMesh to do this.
  13477. var bones = [];
  13478. if ( this.geometry && this.geometry.bones !== undefined ) {
  13479. var bone, gbone;
  13480. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13481. gbone = this.geometry.bones[ b ];
  13482. bone = new THREE.Bone( this );
  13483. bones.push( bone );
  13484. bone.name = gbone.name;
  13485. bone.position.fromArray( gbone.pos );
  13486. bone.quaternion.fromArray( gbone.rotq );
  13487. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  13488. }
  13489. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13490. gbone = this.geometry.bones[ b ];
  13491. if ( gbone.parent !== - 1 && gbone.parent !== null ) {
  13492. bones[ gbone.parent ].add( bones[ b ] );
  13493. } else {
  13494. this.add( bones[ b ] );
  13495. }
  13496. }
  13497. }
  13498. this.normalizeSkinWeights();
  13499. this.updateMatrixWorld( true );
  13500. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  13501. };
  13502. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  13503. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  13504. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  13505. this.skeleton = skeleton;
  13506. if ( bindMatrix === undefined ) {
  13507. this.updateMatrixWorld( true );
  13508. this.skeleton.calculateInverses();
  13509. bindMatrix = this.matrixWorld;
  13510. }
  13511. this.bindMatrix.copy( bindMatrix );
  13512. this.bindMatrixInverse.getInverse( bindMatrix );
  13513. };
  13514. THREE.SkinnedMesh.prototype.pose = function () {
  13515. this.skeleton.pose();
  13516. };
  13517. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  13518. if ( this.geometry instanceof THREE.Geometry ) {
  13519. for ( var i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  13520. var sw = this.geometry.skinWeights[ i ];
  13521. var scale = 1.0 / sw.lengthManhattan();
  13522. if ( scale !== Infinity ) {
  13523. sw.multiplyScalar( scale );
  13524. } else {
  13525. sw.set( 1, 0, 0, 0 ); // do something reasonable
  13526. }
  13527. }
  13528. } else if ( this.geometry instanceof THREE.BufferGeometry ) {
  13529. var vec = new THREE.Vector4();
  13530. var skinWeight = this.geometry.attributes.skinWeight;
  13531. for ( var i = 0; i < skinWeight.count; i ++ ) {
  13532. vec.x = skinWeight.getX( i );
  13533. vec.y = skinWeight.getY( i );
  13534. vec.z = skinWeight.getZ( i );
  13535. vec.w = skinWeight.getW( i );
  13536. var scale = 1.0 / vec.lengthManhattan();
  13537. if ( scale !== Infinity ) {
  13538. vec.multiplyScalar( scale );
  13539. } else {
  13540. vec.set( 1, 0, 0, 0 ); // do something reasonable
  13541. }
  13542. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  13543. }
  13544. }
  13545. };
  13546. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  13547. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  13548. if ( this.bindMode === "attached" ) {
  13549. this.bindMatrixInverse.getInverse( this.matrixWorld );
  13550. } else if ( this.bindMode === "detached" ) {
  13551. this.bindMatrixInverse.getInverse( this.bindMatrix );
  13552. } else {
  13553. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  13554. }
  13555. };
  13556. THREE.SkinnedMesh.prototype.clone = function() {
  13557. return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this );
  13558. };
  13559. // File:src/objects/LOD.js
  13560. /**
  13561. * @author mikael emtinger / http://gomo.se/
  13562. * @author alteredq / http://alteredqualia.com/
  13563. * @author mrdoob / http://mrdoob.com/
  13564. */
  13565. THREE.LOD = function () {
  13566. THREE.Object3D.call( this );
  13567. this.type = 'LOD';
  13568. Object.defineProperties( this, {
  13569. levels: {
  13570. enumerable: true,
  13571. value: []
  13572. },
  13573. objects: {
  13574. get: function () {
  13575. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  13576. return this.levels;
  13577. }
  13578. }
  13579. } );
  13580. };
  13581. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  13582. THREE.LOD.prototype.constructor = THREE.LOD;
  13583. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  13584. if ( distance === undefined ) distance = 0;
  13585. distance = Math.abs( distance );
  13586. var levels = this.levels;
  13587. for ( var l = 0; l < levels.length; l ++ ) {
  13588. if ( distance < levels[ l ].distance ) {
  13589. break;
  13590. }
  13591. }
  13592. levels.splice( l, 0, { distance: distance, object: object } );
  13593. this.add( object );
  13594. };
  13595. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  13596. var levels = this.levels;
  13597. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13598. if ( distance < levels[ i ].distance ) {
  13599. break;
  13600. }
  13601. }
  13602. return levels[ i - 1 ].object;
  13603. };
  13604. THREE.LOD.prototype.raycast = ( function () {
  13605. var matrixPosition = new THREE.Vector3();
  13606. return function raycast( raycaster, intersects ) {
  13607. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13608. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  13609. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  13610. };
  13611. }() );
  13612. THREE.LOD.prototype.update = function () {
  13613. var v1 = new THREE.Vector3();
  13614. var v2 = new THREE.Vector3();
  13615. return function update( camera ) {
  13616. var levels = this.levels;
  13617. if ( levels.length > 1 ) {
  13618. v1.setFromMatrixPosition( camera.matrixWorld );
  13619. v2.setFromMatrixPosition( this.matrixWorld );
  13620. var distance = v1.distanceTo( v2 );
  13621. levels[ 0 ].object.visible = true;
  13622. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13623. if ( distance >= levels[ i ].distance ) {
  13624. levels[ i - 1 ].object.visible = false;
  13625. levels[ i ].object.visible = true;
  13626. } else {
  13627. break;
  13628. }
  13629. }
  13630. for ( ; i < l; i ++ ) {
  13631. levels[ i ].object.visible = false;
  13632. }
  13633. }
  13634. };
  13635. }();
  13636. THREE.LOD.prototype.copy = function ( source ) {
  13637. THREE.Object3D.prototype.copy.call( this, source, false );
  13638. var levels = source.levels;
  13639. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13640. var level = levels[ i ];
  13641. this.addLevel( level.object.clone(), level.distance );
  13642. }
  13643. return this;
  13644. };
  13645. THREE.LOD.prototype.toJSON = function ( meta ) {
  13646. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  13647. data.object.levels = [];
  13648. var levels = this.levels;
  13649. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13650. var level = levels[ i ];
  13651. data.object.levels.push( {
  13652. object: level.object.uuid,
  13653. distance: level.distance
  13654. } );
  13655. }
  13656. return data;
  13657. };
  13658. // File:src/objects/Sprite.js
  13659. /**
  13660. * @author mikael emtinger / http://gomo.se/
  13661. * @author alteredq / http://alteredqualia.com/
  13662. */
  13663. THREE.Sprite = ( function () {
  13664. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  13665. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  13666. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  13667. var geometry = new THREE.BufferGeometry();
  13668. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  13669. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  13670. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  13671. return function Sprite( material ) {
  13672. THREE.Object3D.call( this );
  13673. this.type = 'Sprite';
  13674. this.geometry = geometry;
  13675. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  13676. };
  13677. } )();
  13678. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  13679. THREE.Sprite.prototype.constructor = THREE.Sprite;
  13680. THREE.Sprite.prototype.raycast = ( function () {
  13681. var matrixPosition = new THREE.Vector3();
  13682. return function raycast( raycaster, intersects ) {
  13683. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13684. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  13685. var guessSizeSq = this.scale.x * this.scale.y;
  13686. if ( distanceSq > guessSizeSq ) {
  13687. return;
  13688. }
  13689. intersects.push( {
  13690. distance: Math.sqrt( distanceSq ),
  13691. point: this.position,
  13692. face: null,
  13693. object: this
  13694. } );
  13695. };
  13696. }() );
  13697. THREE.Sprite.prototype.clone = function () {
  13698. return new this.constructor( this.material ).copy( this );
  13699. };
  13700. // Backwards compatibility
  13701. THREE.Particle = THREE.Sprite;
  13702. // File:src/objects/LensFlare.js
  13703. /**
  13704. * @author mikael emtinger / http://gomo.se/
  13705. * @author alteredq / http://alteredqualia.com/
  13706. */
  13707. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  13708. THREE.Object3D.call( this );
  13709. this.lensFlares = [];
  13710. this.positionScreen = new THREE.Vector3();
  13711. this.customUpdateCallback = undefined;
  13712. if ( texture !== undefined ) {
  13713. this.add( texture, size, distance, blending, color );
  13714. }
  13715. };
  13716. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  13717. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  13718. /*
  13719. * Add: adds another flare
  13720. */
  13721. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  13722. if ( size === undefined ) size = - 1;
  13723. if ( distance === undefined ) distance = 0;
  13724. if ( opacity === undefined ) opacity = 1;
  13725. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  13726. if ( blending === undefined ) blending = THREE.NormalBlending;
  13727. distance = Math.min( distance, Math.max( 0, distance ) );
  13728. this.lensFlares.push( {
  13729. texture: texture, // THREE.Texture
  13730. size: size, // size in pixels (-1 = use texture.width)
  13731. distance: distance, // distance (0-1) from light source (0=at light source)
  13732. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  13733. scale: 1, // scale
  13734. rotation: 0, // rotation
  13735. opacity: opacity, // opacity
  13736. color: color, // color
  13737. blending: blending // blending
  13738. } );
  13739. };
  13740. /*
  13741. * Update lens flares update positions on all flares based on the screen position
  13742. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  13743. */
  13744. THREE.LensFlare.prototype.updateLensFlares = function () {
  13745. var f, fl = this.lensFlares.length;
  13746. var flare;
  13747. var vecX = - this.positionScreen.x * 2;
  13748. var vecY = - this.positionScreen.y * 2;
  13749. for ( f = 0; f < fl; f ++ ) {
  13750. flare = this.lensFlares[ f ];
  13751. flare.x = this.positionScreen.x + vecX * flare.distance;
  13752. flare.y = this.positionScreen.y + vecY * flare.distance;
  13753. flare.wantedRotation = flare.x * Math.PI * 0.25;
  13754. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  13755. }
  13756. };
  13757. THREE.LensFlare.prototype.copy = function ( source ) {
  13758. THREE.Object3D.prototype.copy.call( this, source );
  13759. this.positionScreen.copy( source.positionScreen );
  13760. this.customUpdateCallback = source.customUpdateCallback;
  13761. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  13762. this.lensFlares.push( source.lensFlares[ i ] );
  13763. }
  13764. return this;
  13765. };
  13766. // File:src/scenes/Scene.js
  13767. /**
  13768. * @author mrdoob / http://mrdoob.com/
  13769. */
  13770. THREE.Scene = function () {
  13771. THREE.Object3D.call( this );
  13772. this.type = 'Scene';
  13773. this.fog = null;
  13774. this.overrideMaterial = null;
  13775. this.autoUpdate = true; // checked by the renderer
  13776. };
  13777. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  13778. THREE.Scene.prototype.constructor = THREE.Scene;
  13779. THREE.Scene.prototype.copy = function ( source, recursive ) {
  13780. THREE.Object3D.prototype.copy.call( this, source, recursive );
  13781. if ( source.fog !== null ) this.fog = source.fog.clone();
  13782. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  13783. this.autoUpdate = source.autoUpdate;
  13784. this.matrixAutoUpdate = source.matrixAutoUpdate;
  13785. return this;
  13786. };
  13787. // File:src/scenes/Fog.js
  13788. /**
  13789. * @author mrdoob / http://mrdoob.com/
  13790. * @author alteredq / http://alteredqualia.com/
  13791. */
  13792. THREE.Fog = function ( color, near, far ) {
  13793. this.name = '';
  13794. this.color = new THREE.Color( color );
  13795. this.near = ( near !== undefined ) ? near : 1;
  13796. this.far = ( far !== undefined ) ? far : 1000;
  13797. };
  13798. THREE.Fog.prototype.clone = function () {
  13799. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  13800. };
  13801. // File:src/scenes/FogExp2.js
  13802. /**
  13803. * @author mrdoob / http://mrdoob.com/
  13804. * @author alteredq / http://alteredqualia.com/
  13805. */
  13806. THREE.FogExp2 = function ( color, density ) {
  13807. this.name = '';
  13808. this.color = new THREE.Color( color );
  13809. this.density = ( density !== undefined ) ? density : 0.00025;
  13810. };
  13811. THREE.FogExp2.prototype.clone = function () {
  13812. return new THREE.FogExp2( this.color.getHex(), this.density );
  13813. };
  13814. // File:src/renderers/shaders/ShaderChunk.js
  13815. THREE.ShaderChunk = {};
  13816. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  13817. THREE.ShaderChunk[ 'alphamap_fragment' ] = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  13818. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  13819. THREE.ShaderChunk[ 'alphamap_pars_fragment' ] = "#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif\n";
  13820. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  13821. THREE.ShaderChunk[ 'alphatest_fragment' ] = "#ifdef ALPHATEST\n if ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  13822. // File:src/renderers/shaders/ShaderChunk/ambient_pars.glsl
  13823. THREE.ShaderChunk[ 'ambient_pars' ] = "uniform vec3 ambientLightColor;\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n return PI * ambientLightColor;\n}\n";
  13824. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  13825. 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";
  13826. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  13827. THREE.ShaderChunk[ 'aomap_pars_fragment' ] = "#ifdef USE_AOMAP\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n#endif";
  13828. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  13829. THREE.ShaderChunk[ 'begin_vertex' ] = "\nvec3 transformed = vec3( position );\n";
  13830. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  13831. THREE.ShaderChunk[ 'beginnormal_vertex' ] = "\nvec3 objectNormal = vec3( normal );\n";
  13832. // File:src/renderers/shaders/ShaderChunk/bsdfs.glsl
  13833. THREE.ShaderChunk[ 'bsdfs' ] = "bool testLightInRange( const in float lightDistance, const in float cutoffDistance ) {\n return any( bvec2( cutoffDistance == 0.0, lightDistance < cutoffDistance ) );\n}\nfloat calcLightAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n if ( decayExponent > 0.0 ) {\n return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\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 = alpha * alpha;\n float gl = dotNL + pow( a2 + ( 1.0 - a2 ) * dotNL * dotNL, 0.5 );\n float gv = dotNV + pow( a2 + ( 1.0 - a2 ) * dotNV * dotNV, 0.5 );\n return 1.0 / ( gl * gv );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n float a2 = alpha * alpha;\n float denom = dotNH * dotNH * ( a2 - 1.0 ) + 1.0;\n return RECIPROCAL_PI * a2 / ( denom * 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 = roughness * 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 / square( ggxRoughness + 0.0001 ) - 2.0 );\n}\n";
  13834. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  13835. 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";
  13836. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  13837. THREE.ShaderChunk[ 'color_fragment' ] = "#ifdef USE_COLOR\n diffuseColor.rgb *= vColor;\n#endif";
  13838. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  13839. THREE.ShaderChunk[ 'color_pars_fragment' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif\n";
  13840. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  13841. THREE.ShaderChunk[ 'color_pars_vertex' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif";
  13842. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  13843. THREE.ShaderChunk[ 'color_vertex' ] = "#ifdef USE_COLOR\n vColor.xyz = color.xyz;\n#endif";
  13844. // File:src/renderers/shaders/ShaderChunk/common.glsl
  13845. 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 square( const in float x ) { return x*x; }\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}\nvec3 inputToLinear( in vec3 a ) {\n #ifdef GAMMA_INPUT\n return pow( a, vec3( float( GAMMA_FACTOR ) ) );\n #else\n return a;\n #endif\n}\nvec3 linearToOutput( in vec3 a ) {\n #ifdef GAMMA_OUTPUT\n return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );\n #else\n return a;\n #endif\n}\n";
  13846. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  13847. THREE.ShaderChunk[ 'defaultnormal_vertex' ] = "#ifdef FLIP_SIDED\n objectNormal = -objectNormal;\n#endif\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  13848. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  13849. THREE.ShaderChunk[ 'displacementmap_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  13850. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  13851. THREE.ShaderChunk[ 'displacementmap_pars_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n#endif\n";
  13852. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  13853. THREE.ShaderChunk[ 'emissivemap_fragment' ] = "#ifdef USE_EMISSIVEMAP\n vec4 emissiveColor = texture2D( emissiveMap, vUv );\n emissiveColor.rgb = inputToLinear( emissiveColor.rgb );\n totalEmissiveLight *= emissiveColor.rgb;\n#endif\n";
  13854. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  13855. THREE.ShaderChunk[ 'emissivemap_pars_fragment' ] = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif\n";
  13856. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  13857. 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.xyz = inputToLinear( envColor.xyz );\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";
  13858. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  13859. 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";
  13860. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  13861. 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";
  13862. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  13863. 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";
  13864. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  13865. 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 \n outgoingLight = mix( outgoingLight, fogColor, fogFactor );\n#endif";
  13866. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  13867. 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";
  13868. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  13869. THREE.ShaderChunk[ 'lightmap_fragment' ] = "#ifdef USE_LIGHTMAP\n reflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  13870. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  13871. THREE.ShaderChunk[ 'lightmap_pars_fragment' ] = "#ifdef USE_LIGHTMAP\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n#endif";
  13872. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  13873. 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 = getPointDirectLight( 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 = getSpotDirectLight( 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 = getDirectionalDirectLight( 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";
  13874. // File:src/renderers/shaders/ShaderChunk/lights_pars.glsl
  13875. THREE.ShaderChunk[ 'lights_pars' ] = "#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 getDirectionalDirectLight( 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 getPointDirectLight( 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 *= calcLightAttenuation( 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 getSpotDirectLight( 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 * calcLightAttenuation( 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 return PI * mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\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 #else\n vec3 envMapColor = vec3( 0.0 );\n #endif\n envMapColor.rgb = inputToLinear( 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( square( 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_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 = inputToLinear( envMapColor.rgb );\n return envMapColor.rgb * envMapIntensity;\n }\n#endif\n";
  13876. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  13877. THREE.ShaderChunk[ 'lights_phong_fragment' ] = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  13878. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  13879. 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 * PI * directLight.color;\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";
  13880. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  13881. THREE.ShaderChunk[ 'lights_phong_pars_vertex' ] = "#ifdef USE_ENVMAP\n varying vec3 vWorldPosition;\n#endif\n";
  13882. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  13883. THREE.ShaderChunk[ 'lights_phong_vertex' ] = "#ifdef USE_ENVMAP\n vWorldPosition = worldPosition.xyz;\n#endif\n";
  13884. // File:src/renderers/shaders/ShaderChunk/lights_standard_fragment.glsl
  13885. 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";
  13886. // File:src/renderers/shaders/ShaderChunk/lights_standard_pars_fragment.glsl
  13887. 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 * PI * directLight.color;\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";
  13888. // File:src/renderers/shaders/ShaderChunk/lights_template.glsl
  13889. 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 = getPointDirectLight( 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 = getSpotDirectLight( 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 = getDirectionalDirectLight( 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 irradiance += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\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 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";
  13890. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  13891. THREE.ShaderChunk[ 'linear_to_gamma_fragment' ] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  13892. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  13893. THREE.ShaderChunk[ 'logdepthbuf_fragment' ] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  13894. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  13895. 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";
  13896. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  13897. 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";
  13898. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  13899. 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";
  13900. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  13901. THREE.ShaderChunk[ 'map_fragment' ] = "#ifdef USE_MAP\n vec4 texelColor = texture2D( map, vUv );\n texelColor.xyz = inputToLinear( texelColor.xyz );\n diffuseColor *= texelColor;\n#endif\n";
  13902. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  13903. THREE.ShaderChunk[ 'map_pars_fragment' ] = "#ifdef USE_MAP\n uniform sampler2D map;\n#endif";
  13904. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  13905. THREE.ShaderChunk[ 'map_particle_fragment' ] = "#ifdef USE_MAP\n diffuseColor *= texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) * offsetRepeat.zw + offsetRepeat.xy );\n#endif\n";
  13906. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  13907. THREE.ShaderChunk[ 'map_particle_pars_fragment' ] = "#ifdef USE_MAP\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n#endif\n";
  13908. // File:src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl
  13909. THREE.ShaderChunk[ 'metalnessmap_fragment' ] = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, vUv );\n metalnessFactor *= texelMetalness.r;\n#endif\n";
  13910. // File:src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl
  13911. THREE.ShaderChunk[ 'metalnessmap_pars_fragment' ] = "#ifdef USE_METALNESSMAP\n uniform sampler2D metalnessMap;\n#endif";
  13912. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  13913. 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";
  13914. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  13915. 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";
  13916. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  13917. 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";
  13918. // File:src/renderers/shaders/ShaderChunk/normal_fragment.glsl
  13919. 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";
  13920. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  13921. 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";
  13922. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  13923. 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";
  13924. // File:src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl
  13925. THREE.ShaderChunk[ 'roughnessmap_fragment' ] = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, vUv );\n roughnessFactor *= texelRoughness.r;\n#endif\n";
  13926. // File:src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl
  13927. THREE.ShaderChunk[ 'roughnessmap_pars_fragment' ] = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif";
  13928. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  13929. 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";
  13930. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  13931. 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";
  13932. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  13933. 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";
  13934. // File:src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl
  13935. 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";
  13936. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  13937. 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";
  13938. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  13939. 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";
  13940. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  13941. 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";
  13942. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  13943. 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";
  13944. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  13945. 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";
  13946. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  13947. THREE.ShaderChunk[ 'specularmap_pars_fragment' ] = "#ifdef USE_SPECULARMAP\n uniform sampler2D specularMap;\n#endif";
  13948. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  13949. THREE.ShaderChunk[ 'uv2_pars_fragment' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n varying vec2 vUv2;\n#endif";
  13950. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  13951. THREE.ShaderChunk[ 'uv2_pars_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n attribute vec2 uv2;\n varying vec2 vUv2;\n#endif";
  13952. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  13953. THREE.ShaderChunk[ 'uv2_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = uv2;\n#endif";
  13954. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  13955. 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";
  13956. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  13957. 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";
  13958. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  13959. 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";
  13960. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  13961. 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";
  13962. // File:src/renderers/shaders/UniformsUtils.js
  13963. /**
  13964. * Uniform Utilities
  13965. */
  13966. THREE.UniformsUtils = {
  13967. merge: function ( uniforms ) {
  13968. var merged = {};
  13969. for ( var u = 0; u < uniforms.length; u ++ ) {
  13970. var tmp = this.clone( uniforms[ u ] );
  13971. for ( var p in tmp ) {
  13972. merged[ p ] = tmp[ p ];
  13973. }
  13974. }
  13975. return merged;
  13976. },
  13977. clone: function ( uniforms_src ) {
  13978. var uniforms_dst = {};
  13979. for ( var u in uniforms_src ) {
  13980. uniforms_dst[ u ] = {};
  13981. for ( var p in uniforms_src[ u ] ) {
  13982. var parameter_src = uniforms_src[ u ][ p ];
  13983. if ( parameter_src instanceof THREE.Color ||
  13984. parameter_src instanceof THREE.Vector2 ||
  13985. parameter_src instanceof THREE.Vector3 ||
  13986. parameter_src instanceof THREE.Vector4 ||
  13987. parameter_src instanceof THREE.Matrix3 ||
  13988. parameter_src instanceof THREE.Matrix4 ||
  13989. parameter_src instanceof THREE.Texture ) {
  13990. uniforms_dst[ u ][ p ] = parameter_src.clone();
  13991. } else if ( Array.isArray( parameter_src ) ) {
  13992. uniforms_dst[ u ][ p ] = parameter_src.slice();
  13993. } else {
  13994. uniforms_dst[ u ][ p ] = parameter_src;
  13995. }
  13996. }
  13997. }
  13998. return uniforms_dst;
  13999. }
  14000. };
  14001. // File:src/renderers/shaders/UniformsLib.js
  14002. /**
  14003. * Uniforms library for shared webgl shaders
  14004. */
  14005. THREE.UniformsLib = {
  14006. common: {
  14007. "diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
  14008. "opacity": { type: "f", value: 1.0 },
  14009. "map": { type: "t", value: null },
  14010. "offsetRepeat": { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  14011. "specularMap": { type: "t", value: null },
  14012. "alphaMap": { type: "t", value: null },
  14013. "envMap": { type: "t", value: null },
  14014. "flipEnvMap": { type: "f", value: - 1 },
  14015. "reflectivity": { type: "f", value: 1.0 },
  14016. "refractionRatio": { type: "f", value: 0.98 }
  14017. },
  14018. aomap: {
  14019. "aoMap": { type: "t", value: null },
  14020. "aoMapIntensity": { type: "f", value: 1 }
  14021. },
  14022. lightmap: {
  14023. "lightMap": { type: "t", value: null },
  14024. "lightMapIntensity": { type: "f", value: 1 }
  14025. },
  14026. emissivemap: {
  14027. "emissiveMap": { type: "t", value: null }
  14028. },
  14029. bumpmap: {
  14030. "bumpMap": { type: "t", value: null },
  14031. "bumpScale": { type: "f", value: 1 }
  14032. },
  14033. normalmap: {
  14034. "normalMap": { type: "t", value: null },
  14035. "normalScale": { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  14036. },
  14037. displacementmap: {
  14038. "displacementMap": { type: "t", value: null },
  14039. "displacementScale": { type: "f", value: 1 },
  14040. "displacementBias": { type: "f", value: 0 }
  14041. },
  14042. roughnessmap: {
  14043. "roughnessMap": { type: "t", value: null }
  14044. },
  14045. metalnessmap: {
  14046. "metalnessMap": { type: "t", value: null }
  14047. },
  14048. fog: {
  14049. "fogDensity": { type: "f", value: 0.00025 },
  14050. "fogNear": { type: "f", value: 1 },
  14051. "fogFar": { type: "f", value: 2000 },
  14052. "fogColor": { type: "c", value: new THREE.Color( 0xffffff ) }
  14053. },
  14054. ambient: {
  14055. "ambientLightColor": { type: "fv", value: [] }
  14056. },
  14057. lights: {
  14058. "directionalLights": { type: "sa", value: [], properties: {
  14059. "direction": { type: "v3" },
  14060. "color": { type: "c" },
  14061. "shadow": { type: "i" },
  14062. "shadowBias": { type: "f" },
  14063. "shadowRadius": { type: "f" },
  14064. "shadowMapSize": { type: "v2" }
  14065. } },
  14066. "directionalShadowMap": { type: "tv", value: [] },
  14067. "directionalShadowMatrix": { type: "m4v", value: [] },
  14068. "spotLights": { type: "sa", value: [], properties: {
  14069. "color": { type: "c" },
  14070. "position": { type: "v3" },
  14071. "direction": { type: "v3" },
  14072. "distance": { type: "f" },
  14073. "coneCos": { type: "f" },
  14074. "penumbraCos": { type: "f" },
  14075. "decay": { type: "f" },
  14076. "shadow": { type: "i" },
  14077. "shadowBias": { type: "f" },
  14078. "shadowRadius": { type: "f" },
  14079. "shadowMapSize": { type: "v2" }
  14080. } },
  14081. "spotShadowMap": { type: "tv", value: [] },
  14082. "spotShadowMatrix": { type: "m4v", value: [] },
  14083. "pointLights": { type: "sa", value: [], properties: {
  14084. "color": { type: "c" },
  14085. "position": { type: "v3" },
  14086. "decay": { type: "f" },
  14087. "distance": { type: "f" },
  14088. "shadow": { type: "i" },
  14089. "shadowBias": { type: "f" },
  14090. "shadowRadius": { type: "f" },
  14091. "shadowMapSize": { type: "v2" }
  14092. } },
  14093. "pointShadowMap": { type: "tv", value: [] },
  14094. "pointShadowMatrix": { type: "m4v", value: [] },
  14095. "hemisphereLights": { type: "sa", value: [], properties: {
  14096. "direction": { type: "v3" },
  14097. "skyColor": { type: "c" },
  14098. "groundColor": { type: "c" }
  14099. } }
  14100. },
  14101. points: {
  14102. "diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
  14103. "opacity": { type: "f", value: 1.0 },
  14104. "size": { type: "f", value: 1.0 },
  14105. "scale": { type: "f", value: 1.0 },
  14106. "map": { type: "t", value: null },
  14107. "offsetRepeat": { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) }
  14108. }
  14109. };
  14110. // File:src/renderers/shaders/ShaderLib.js
  14111. /**
  14112. * Webgl Shader Library for three.js
  14113. *
  14114. * @author alteredq / http://alteredqualia.com/
  14115. * @author mrdoob / http://mrdoob.com/
  14116. * @author mikael emtinger / http://gomo.se/
  14117. */
  14118. THREE.ShaderLib = {
  14119. 'basic': {
  14120. uniforms: THREE.UniformsUtils.merge( [
  14121. THREE.UniformsLib[ "common" ],
  14122. THREE.UniformsLib[ "aomap" ],
  14123. THREE.UniformsLib[ "fog" ]
  14124. ] ),
  14125. vertexShader: [
  14126. THREE.ShaderChunk[ "common" ],
  14127. THREE.ShaderChunk[ "uv_pars_vertex" ],
  14128. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  14129. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  14130. THREE.ShaderChunk[ "color_pars_vertex" ],
  14131. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14132. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14133. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14134. "void main() {",
  14135. THREE.ShaderChunk[ "uv_vertex" ],
  14136. THREE.ShaderChunk[ "uv2_vertex" ],
  14137. THREE.ShaderChunk[ "color_vertex" ],
  14138. THREE.ShaderChunk[ "skinbase_vertex" ],
  14139. " #ifdef USE_ENVMAP",
  14140. THREE.ShaderChunk[ "beginnormal_vertex" ],
  14141. THREE.ShaderChunk[ "morphnormal_vertex" ],
  14142. THREE.ShaderChunk[ "skinnormal_vertex" ],
  14143. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  14144. " #endif",
  14145. THREE.ShaderChunk[ "begin_vertex" ],
  14146. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14147. THREE.ShaderChunk[ "skinning_vertex" ],
  14148. THREE.ShaderChunk[ "project_vertex" ],
  14149. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14150. THREE.ShaderChunk[ "worldpos_vertex" ],
  14151. THREE.ShaderChunk[ "envmap_vertex" ],
  14152. "}"
  14153. ].join( "\n" ),
  14154. fragmentShader: [
  14155. "uniform vec3 diffuse;",
  14156. "uniform float opacity;",
  14157. "#ifndef FLAT_SHADED",
  14158. " varying vec3 vNormal;",
  14159. "#endif",
  14160. THREE.ShaderChunk[ "common" ],
  14161. THREE.ShaderChunk[ "color_pars_fragment" ],
  14162. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14163. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14164. THREE.ShaderChunk[ "map_pars_fragment" ],
  14165. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14166. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  14167. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14168. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14169. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14170. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14171. "void main() {",
  14172. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14173. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14174. THREE.ShaderChunk[ "map_fragment" ],
  14175. THREE.ShaderChunk[ "color_fragment" ],
  14176. THREE.ShaderChunk[ "alphamap_fragment" ],
  14177. THREE.ShaderChunk[ "alphatest_fragment" ],
  14178. THREE.ShaderChunk[ "specularmap_fragment" ],
  14179. " ReflectedLight reflectedLight;",
  14180. " reflectedLight.directDiffuse = vec3( 0.0 );",
  14181. " reflectedLight.directSpecular = vec3( 0.0 );",
  14182. " reflectedLight.indirectDiffuse = diffuseColor.rgb;",
  14183. " reflectedLight.indirectSpecular = vec3( 0.0 );",
  14184. THREE.ShaderChunk[ "aomap_fragment" ],
  14185. " vec3 outgoingLight = reflectedLight.indirectDiffuse;",
  14186. THREE.ShaderChunk[ "envmap_fragment" ],
  14187. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14188. THREE.ShaderChunk[ "fog_fragment" ],
  14189. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14190. "}"
  14191. ].join( "\n" )
  14192. },
  14193. 'lambert': {
  14194. uniforms: THREE.UniformsUtils.merge( [
  14195. THREE.UniformsLib[ "common" ],
  14196. THREE.UniformsLib[ "aomap" ],
  14197. THREE.UniformsLib[ "lightmap" ],
  14198. THREE.UniformsLib[ "emissivemap" ],
  14199. THREE.UniformsLib[ "fog" ],
  14200. THREE.UniformsLib[ "ambient" ],
  14201. THREE.UniformsLib[ "lights" ],
  14202. {
  14203. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  14204. }
  14205. ] ),
  14206. vertexShader: [
  14207. "#define LAMBERT",
  14208. "varying vec3 vLightFront;",
  14209. "#ifdef DOUBLE_SIDED",
  14210. " varying vec3 vLightBack;",
  14211. "#endif",
  14212. THREE.ShaderChunk[ "common" ],
  14213. THREE.ShaderChunk[ "uv_pars_vertex" ],
  14214. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  14215. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  14216. THREE.ShaderChunk[ "bsdfs" ],
  14217. THREE.ShaderChunk[ "lights_pars" ],
  14218. THREE.ShaderChunk[ "color_pars_vertex" ],
  14219. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14220. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14221. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14222. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14223. "void main() {",
  14224. THREE.ShaderChunk[ "uv_vertex" ],
  14225. THREE.ShaderChunk[ "uv2_vertex" ],
  14226. THREE.ShaderChunk[ "color_vertex" ],
  14227. THREE.ShaderChunk[ "beginnormal_vertex" ],
  14228. THREE.ShaderChunk[ "morphnormal_vertex" ],
  14229. THREE.ShaderChunk[ "skinbase_vertex" ],
  14230. THREE.ShaderChunk[ "skinnormal_vertex" ],
  14231. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  14232. THREE.ShaderChunk[ "begin_vertex" ],
  14233. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14234. THREE.ShaderChunk[ "skinning_vertex" ],
  14235. THREE.ShaderChunk[ "project_vertex" ],
  14236. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14237. THREE.ShaderChunk[ "worldpos_vertex" ],
  14238. THREE.ShaderChunk[ "envmap_vertex" ],
  14239. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  14240. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14241. "}"
  14242. ].join( "\n" ),
  14243. fragmentShader: [
  14244. "uniform vec3 diffuse;",
  14245. "uniform vec3 emissive;",
  14246. "uniform float opacity;",
  14247. "varying vec3 vLightFront;",
  14248. "#ifdef DOUBLE_SIDED",
  14249. " varying vec3 vLightBack;",
  14250. "#endif",
  14251. THREE.ShaderChunk[ "common" ],
  14252. THREE.ShaderChunk[ "color_pars_fragment" ],
  14253. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14254. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14255. THREE.ShaderChunk[ "map_pars_fragment" ],
  14256. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14257. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  14258. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  14259. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  14260. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14261. THREE.ShaderChunk[ "bsdfs" ],
  14262. THREE.ShaderChunk[ "ambient_pars" ],
  14263. THREE.ShaderChunk[ "lights_pars" ],
  14264. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14265. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14266. THREE.ShaderChunk[ "shadowmask_pars_fragment" ],
  14267. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14268. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14269. "void main() {",
  14270. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14271. " ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
  14272. " vec3 totalEmissiveLight = emissive;",
  14273. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14274. THREE.ShaderChunk[ "map_fragment" ],
  14275. THREE.ShaderChunk[ "color_fragment" ],
  14276. THREE.ShaderChunk[ "alphamap_fragment" ],
  14277. THREE.ShaderChunk[ "alphatest_fragment" ],
  14278. THREE.ShaderChunk[ "specularmap_fragment" ],
  14279. THREE.ShaderChunk[ "emissivemap_fragment" ],
  14280. // accumulation
  14281. " reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );",
  14282. THREE.ShaderChunk[ "lightmap_fragment" ],
  14283. " reflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );",
  14284. " #ifdef DOUBLE_SIDED",
  14285. " reflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;",
  14286. " #else",
  14287. " reflectedLight.directDiffuse = vLightFront;",
  14288. " #endif",
  14289. " reflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();",
  14290. // modulation
  14291. THREE.ShaderChunk[ "aomap_fragment" ],
  14292. " vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveLight;",
  14293. THREE.ShaderChunk[ "envmap_fragment" ],
  14294. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14295. THREE.ShaderChunk[ "fog_fragment" ],
  14296. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14297. "}"
  14298. ].join( "\n" )
  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[ "ambient" ],
  14311. THREE.UniformsLib[ "lights" ],
  14312. {
  14313. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14314. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  14315. "shininess": { type: "f", value: 30 }
  14316. }
  14317. ] ),
  14318. vertexShader: [
  14319. "#define PHONG",
  14320. "varying vec3 vViewPosition;",
  14321. "#ifndef FLAT_SHADED",
  14322. " varying vec3 vNormal;",
  14323. "#endif",
  14324. THREE.ShaderChunk[ "common" ],
  14325. THREE.ShaderChunk[ "uv_pars_vertex" ],
  14326. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  14327. THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
  14328. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  14329. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  14330. THREE.ShaderChunk[ "color_pars_vertex" ],
  14331. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14332. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14333. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14334. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14335. "void main() {",
  14336. THREE.ShaderChunk[ "uv_vertex" ],
  14337. THREE.ShaderChunk[ "uv2_vertex" ],
  14338. THREE.ShaderChunk[ "color_vertex" ],
  14339. THREE.ShaderChunk[ "beginnormal_vertex" ],
  14340. THREE.ShaderChunk[ "morphnormal_vertex" ],
  14341. THREE.ShaderChunk[ "skinbase_vertex" ],
  14342. THREE.ShaderChunk[ "skinnormal_vertex" ],
  14343. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  14344. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  14345. " vNormal = normalize( transformedNormal );",
  14346. "#endif",
  14347. THREE.ShaderChunk[ "begin_vertex" ],
  14348. THREE.ShaderChunk[ "displacementmap_vertex" ],
  14349. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14350. THREE.ShaderChunk[ "skinning_vertex" ],
  14351. THREE.ShaderChunk[ "project_vertex" ],
  14352. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14353. " vViewPosition = - mvPosition.xyz;",
  14354. THREE.ShaderChunk[ "worldpos_vertex" ],
  14355. THREE.ShaderChunk[ "envmap_vertex" ],
  14356. THREE.ShaderChunk[ "lights_phong_vertex" ],
  14357. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14358. "}"
  14359. ].join( "\n" ),
  14360. fragmentShader: [
  14361. "#define PHONG",
  14362. "uniform vec3 diffuse;",
  14363. "uniform vec3 emissive;",
  14364. "uniform vec3 specular;",
  14365. "uniform float shininess;",
  14366. "uniform float opacity;",
  14367. THREE.ShaderChunk[ "common" ],
  14368. THREE.ShaderChunk[ "color_pars_fragment" ],
  14369. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14370. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14371. THREE.ShaderChunk[ "map_pars_fragment" ],
  14372. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14373. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  14374. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  14375. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  14376. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14377. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14378. THREE.ShaderChunk[ "bsdfs" ],
  14379. THREE.ShaderChunk[ "ambient_pars" ],
  14380. THREE.ShaderChunk[ "lights_pars" ],
  14381. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  14382. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14383. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  14384. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  14385. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14386. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14387. "void main() {",
  14388. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14389. " ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
  14390. " vec3 totalEmissiveLight = emissive;",
  14391. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14392. THREE.ShaderChunk[ "map_fragment" ],
  14393. THREE.ShaderChunk[ "color_fragment" ],
  14394. THREE.ShaderChunk[ "alphamap_fragment" ],
  14395. THREE.ShaderChunk[ "alphatest_fragment" ],
  14396. THREE.ShaderChunk[ "specularmap_fragment" ],
  14397. THREE.ShaderChunk[ "normal_fragment" ],
  14398. THREE.ShaderChunk[ "emissivemap_fragment" ],
  14399. // accumulation
  14400. THREE.ShaderChunk[ "lights_phong_fragment" ],
  14401. THREE.ShaderChunk[ "lights_template" ],
  14402. // modulation
  14403. THREE.ShaderChunk[ "aomap_fragment" ],
  14404. "vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
  14405. THREE.ShaderChunk[ "envmap_fragment" ],
  14406. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14407. THREE.ShaderChunk[ "fog_fragment" ],
  14408. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14409. "}"
  14410. ].join( "\n" )
  14411. },
  14412. 'standard': {
  14413. uniforms: THREE.UniformsUtils.merge( [
  14414. THREE.UniformsLib[ "common" ],
  14415. THREE.UniformsLib[ "aomap" ],
  14416. THREE.UniformsLib[ "lightmap" ],
  14417. THREE.UniformsLib[ "emissivemap" ],
  14418. THREE.UniformsLib[ "bumpmap" ],
  14419. THREE.UniformsLib[ "normalmap" ],
  14420. THREE.UniformsLib[ "displacementmap" ],
  14421. THREE.UniformsLib[ "roughnessmap" ],
  14422. THREE.UniformsLib[ "metalnessmap" ],
  14423. THREE.UniformsLib[ "fog" ],
  14424. THREE.UniformsLib[ "ambient" ],
  14425. THREE.UniformsLib[ "lights" ],
  14426. {
  14427. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14428. "roughness": { type: "f", value: 0.5 },
  14429. "metalness": { type: "f", value: 0 },
  14430. "envMapIntensity" : { type: "f", value: 1 } // temporary
  14431. }
  14432. ] ),
  14433. vertexShader: [
  14434. "#define STANDARD",
  14435. "varying vec3 vViewPosition;",
  14436. "#ifndef FLAT_SHADED",
  14437. " varying vec3 vNormal;",
  14438. "#endif",
  14439. THREE.ShaderChunk[ "common" ],
  14440. THREE.ShaderChunk[ "uv_pars_vertex" ],
  14441. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  14442. THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
  14443. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  14444. THREE.ShaderChunk[ "color_pars_vertex" ],
  14445. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14446. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14447. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14448. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14449. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14450. "void main() {", // STANDARD
  14451. THREE.ShaderChunk[ "uv_vertex" ],
  14452. THREE.ShaderChunk[ "uv2_vertex" ],
  14453. THREE.ShaderChunk[ "color_vertex" ],
  14454. THREE.ShaderChunk[ "beginnormal_vertex" ],
  14455. THREE.ShaderChunk[ "morphnormal_vertex" ],
  14456. THREE.ShaderChunk[ "skinbase_vertex" ],
  14457. THREE.ShaderChunk[ "skinnormal_vertex" ],
  14458. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  14459. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  14460. " vNormal = normalize( transformedNormal );",
  14461. "#endif",
  14462. THREE.ShaderChunk[ "begin_vertex" ],
  14463. THREE.ShaderChunk[ "displacementmap_vertex" ],
  14464. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14465. THREE.ShaderChunk[ "skinning_vertex" ],
  14466. THREE.ShaderChunk[ "project_vertex" ],
  14467. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14468. " vViewPosition = - mvPosition.xyz;",
  14469. THREE.ShaderChunk[ "worldpos_vertex" ],
  14470. THREE.ShaderChunk[ "envmap_vertex" ],
  14471. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14472. "}"
  14473. ].join( "\n" ),
  14474. fragmentShader: [
  14475. "#define STANDARD",
  14476. "uniform vec3 diffuse;",
  14477. "uniform vec3 emissive;",
  14478. "uniform float roughness;",
  14479. "uniform float metalness;",
  14480. "uniform float opacity;",
  14481. "uniform float envMapIntensity;", // temporary
  14482. "varying vec3 vViewPosition;",
  14483. "#ifndef FLAT_SHADED",
  14484. " varying vec3 vNormal;",
  14485. "#endif",
  14486. THREE.ShaderChunk[ "common" ],
  14487. THREE.ShaderChunk[ "color_pars_fragment" ],
  14488. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14489. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14490. THREE.ShaderChunk[ "map_pars_fragment" ],
  14491. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14492. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  14493. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  14494. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  14495. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14496. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14497. THREE.ShaderChunk[ "bsdfs" ],
  14498. THREE.ShaderChunk[ "ambient_pars" ],
  14499. THREE.ShaderChunk[ "lights_pars" ],
  14500. THREE.ShaderChunk[ "lights_standard_pars_fragment" ],
  14501. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14502. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  14503. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  14504. THREE.ShaderChunk[ "roughnessmap_pars_fragment" ],
  14505. THREE.ShaderChunk[ "metalnessmap_pars_fragment" ],
  14506. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14507. "void main() {",
  14508. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14509. " ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
  14510. " vec3 totalEmissiveLight = emissive;",
  14511. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14512. THREE.ShaderChunk[ "map_fragment" ],
  14513. THREE.ShaderChunk[ "color_fragment" ],
  14514. THREE.ShaderChunk[ "alphamap_fragment" ],
  14515. THREE.ShaderChunk[ "alphatest_fragment" ],
  14516. THREE.ShaderChunk[ "specularmap_fragment" ],
  14517. THREE.ShaderChunk[ "roughnessmap_fragment" ],
  14518. THREE.ShaderChunk[ "metalnessmap_fragment" ],
  14519. THREE.ShaderChunk[ "normal_fragment" ],
  14520. THREE.ShaderChunk[ "emissivemap_fragment" ],
  14521. // accumulation
  14522. THREE.ShaderChunk[ "lights_standard_fragment" ],
  14523. THREE.ShaderChunk[ "lights_template" ],
  14524. // modulation
  14525. THREE.ShaderChunk[ "aomap_fragment" ],
  14526. "vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
  14527. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14528. THREE.ShaderChunk[ "fog_fragment" ],
  14529. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14530. "}"
  14531. ].join( "\n" )
  14532. },
  14533. 'points': {
  14534. uniforms: THREE.UniformsUtils.merge( [
  14535. THREE.UniformsLib[ "points" ],
  14536. THREE.UniformsLib[ "fog" ]
  14537. ] ),
  14538. vertexShader: [
  14539. "uniform float size;",
  14540. "uniform float scale;",
  14541. THREE.ShaderChunk[ "common" ],
  14542. THREE.ShaderChunk[ "color_pars_vertex" ],
  14543. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14544. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14545. "void main() {",
  14546. THREE.ShaderChunk[ "color_vertex" ],
  14547. THREE.ShaderChunk[ "begin_vertex" ],
  14548. THREE.ShaderChunk[ "project_vertex" ],
  14549. " #ifdef USE_SIZEATTENUATION",
  14550. " gl_PointSize = size * ( scale / - mvPosition.z );",
  14551. " #else",
  14552. " gl_PointSize = size;",
  14553. " #endif",
  14554. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14555. THREE.ShaderChunk[ "worldpos_vertex" ],
  14556. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14557. "}"
  14558. ].join( "\n" ),
  14559. fragmentShader: [
  14560. "uniform vec3 diffuse;",
  14561. "uniform float opacity;",
  14562. THREE.ShaderChunk[ "common" ],
  14563. THREE.ShaderChunk[ "color_pars_fragment" ],
  14564. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  14565. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14566. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14567. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14568. "void main() {",
  14569. " vec3 outgoingLight = vec3( 0.0 );",
  14570. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14571. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14572. THREE.ShaderChunk[ "map_particle_fragment" ],
  14573. THREE.ShaderChunk[ "color_fragment" ],
  14574. THREE.ShaderChunk[ "alphatest_fragment" ],
  14575. " outgoingLight = diffuseColor.rgb;",
  14576. THREE.ShaderChunk[ "fog_fragment" ],
  14577. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14578. "}"
  14579. ].join( "\n" )
  14580. },
  14581. 'dashed': {
  14582. uniforms: THREE.UniformsUtils.merge( [
  14583. THREE.UniformsLib[ "common" ],
  14584. THREE.UniformsLib[ "fog" ],
  14585. {
  14586. "scale" : { type: "f", value: 1 },
  14587. "dashSize" : { type: "f", value: 1 },
  14588. "totalSize": { type: "f", value: 2 }
  14589. }
  14590. ] ),
  14591. vertexShader: [
  14592. "uniform float scale;",
  14593. "attribute float lineDistance;",
  14594. "varying float vLineDistance;",
  14595. THREE.ShaderChunk[ "common" ],
  14596. THREE.ShaderChunk[ "color_pars_vertex" ],
  14597. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14598. "void main() {",
  14599. THREE.ShaderChunk[ "color_vertex" ],
  14600. " vLineDistance = scale * lineDistance;",
  14601. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  14602. " gl_Position = projectionMatrix * mvPosition;",
  14603. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14604. "}"
  14605. ].join( "\n" ),
  14606. fragmentShader: [
  14607. "uniform vec3 diffuse;",
  14608. "uniform float opacity;",
  14609. "uniform float dashSize;",
  14610. "uniform float totalSize;",
  14611. "varying float vLineDistance;",
  14612. THREE.ShaderChunk[ "common" ],
  14613. THREE.ShaderChunk[ "color_pars_fragment" ],
  14614. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14615. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14616. "void main() {",
  14617. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  14618. " discard;",
  14619. " }",
  14620. " vec3 outgoingLight = vec3( 0.0 );",
  14621. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14622. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14623. THREE.ShaderChunk[ "color_fragment" ],
  14624. " outgoingLight = diffuseColor.rgb;", // simple shader
  14625. THREE.ShaderChunk[ "fog_fragment" ],
  14626. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14627. "}"
  14628. ].join( "\n" )
  14629. },
  14630. 'depth': {
  14631. uniforms: {
  14632. "mNear": { type: "f", value: 1.0 },
  14633. "mFar" : { type: "f", value: 2000.0 },
  14634. "opacity" : { type: "f", value: 1.0 }
  14635. },
  14636. vertexShader: [
  14637. THREE.ShaderChunk[ "common" ],
  14638. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14639. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14640. "void main() {",
  14641. THREE.ShaderChunk[ "begin_vertex" ],
  14642. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14643. THREE.ShaderChunk[ "project_vertex" ],
  14644. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14645. "}"
  14646. ].join( "\n" ),
  14647. fragmentShader: [
  14648. "uniform float mNear;",
  14649. "uniform float mFar;",
  14650. "uniform float opacity;",
  14651. THREE.ShaderChunk[ "common" ],
  14652. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14653. "void main() {",
  14654. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14655. " #ifdef USE_LOGDEPTHBUF_EXT",
  14656. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  14657. " #else",
  14658. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  14659. " #endif",
  14660. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  14661. " gl_FragColor = vec4( vec3( color ), opacity );",
  14662. "}"
  14663. ].join( "\n" )
  14664. },
  14665. 'normal': {
  14666. uniforms: {
  14667. "opacity" : { type: "f", value: 1.0 }
  14668. },
  14669. vertexShader: [
  14670. "varying vec3 vNormal;",
  14671. THREE.ShaderChunk[ "common" ],
  14672. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14673. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14674. "void main() {",
  14675. " vNormal = normalize( normalMatrix * normal );",
  14676. THREE.ShaderChunk[ "begin_vertex" ],
  14677. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14678. THREE.ShaderChunk[ "project_vertex" ],
  14679. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14680. "}"
  14681. ].join( "\n" ),
  14682. fragmentShader: [
  14683. "uniform float opacity;",
  14684. "varying vec3 vNormal;",
  14685. THREE.ShaderChunk[ "common" ],
  14686. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14687. "void main() {",
  14688. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  14689. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14690. "}"
  14691. ].join( "\n" )
  14692. },
  14693. /* -------------------------------------------------------------------------
  14694. // Cube map shader
  14695. ------------------------------------------------------------------------- */
  14696. 'cube': {
  14697. uniforms: {
  14698. "tCube": { type: "t", value: null },
  14699. "tFlip": { type: "f", value: - 1 }
  14700. },
  14701. vertexShader: [
  14702. "varying vec3 vWorldPosition;",
  14703. THREE.ShaderChunk[ "common" ],
  14704. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14705. "void main() {",
  14706. " vWorldPosition = transformDirection( position, modelMatrix );",
  14707. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  14708. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14709. "}"
  14710. ].join( "\n" ),
  14711. fragmentShader: [
  14712. "uniform samplerCube tCube;",
  14713. "uniform float tFlip;",
  14714. "varying vec3 vWorldPosition;",
  14715. THREE.ShaderChunk[ "common" ],
  14716. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14717. "void main() {",
  14718. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  14719. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14720. "}"
  14721. ].join( "\n" )
  14722. },
  14723. /* -------------------------------------------------------------------------
  14724. // Cube map shader
  14725. ------------------------------------------------------------------------- */
  14726. 'equirect': {
  14727. uniforms: {
  14728. "tEquirect": { type: "t", value: null },
  14729. "tFlip": { type: "f", value: - 1 }
  14730. },
  14731. vertexShader: [
  14732. "varying vec3 vWorldPosition;",
  14733. THREE.ShaderChunk[ "common" ],
  14734. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14735. "void main() {",
  14736. " vWorldPosition = transformDirection( position, modelMatrix );",
  14737. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  14738. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14739. "}"
  14740. ].join( "\n" ),
  14741. fragmentShader: [
  14742. "uniform sampler2D tEquirect;",
  14743. "uniform float tFlip;",
  14744. "varying vec3 vWorldPosition;",
  14745. THREE.ShaderChunk[ "common" ],
  14746. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14747. "void main() {",
  14748. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  14749. "vec3 direction = normalize( vWorldPosition );",
  14750. "vec2 sampleUV;",
  14751. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  14752. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  14753. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  14754. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14755. "}"
  14756. ].join( "\n" )
  14757. },
  14758. /* Depth encoding into RGBA texture
  14759. *
  14760. * based on SpiderGL shadow map example
  14761. * http://spidergl.org/example.php?id=6
  14762. *
  14763. * originally from
  14764. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  14765. *
  14766. * see also
  14767. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  14768. */
  14769. 'depthRGBA': {
  14770. uniforms: {},
  14771. vertexShader: [
  14772. THREE.ShaderChunk[ "common" ],
  14773. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14774. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14775. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14776. "void main() {",
  14777. THREE.ShaderChunk[ "skinbase_vertex" ],
  14778. THREE.ShaderChunk[ "begin_vertex" ],
  14779. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14780. THREE.ShaderChunk[ "skinning_vertex" ],
  14781. THREE.ShaderChunk[ "project_vertex" ],
  14782. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14783. "}"
  14784. ].join( "\n" ),
  14785. fragmentShader: [
  14786. THREE.ShaderChunk[ "common" ],
  14787. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14788. "vec4 pack_depth( const in float depth ) {",
  14789. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  14790. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  14791. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );",
  14792. " res -= res.xxyz * bit_mask;",
  14793. " return res;",
  14794. "}",
  14795. "void main() {",
  14796. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14797. " #ifdef USE_LOGDEPTHBUF_EXT",
  14798. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  14799. " #else",
  14800. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  14801. " #endif",
  14802. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  14803. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  14804. //"gl_FragData[ 0 ] = pack_depth( z );",
  14805. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  14806. "}"
  14807. ].join( "\n" )
  14808. },
  14809. 'distanceRGBA': {
  14810. uniforms: {
  14811. "lightPos": { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) }
  14812. },
  14813. vertexShader: [
  14814. "varying vec4 vWorldPosition;",
  14815. THREE.ShaderChunk[ "common" ],
  14816. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14817. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14818. "void main() {",
  14819. THREE.ShaderChunk[ "skinbase_vertex" ],
  14820. THREE.ShaderChunk[ "begin_vertex" ],
  14821. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14822. THREE.ShaderChunk[ "skinning_vertex" ],
  14823. THREE.ShaderChunk[ "project_vertex" ],
  14824. THREE.ShaderChunk[ "worldpos_vertex" ],
  14825. "vWorldPosition = worldPosition;",
  14826. "}"
  14827. ].join( "\n" ),
  14828. fragmentShader: [
  14829. "uniform vec3 lightPos;",
  14830. "varying vec4 vWorldPosition;",
  14831. THREE.ShaderChunk[ "common" ],
  14832. "vec4 pack1K ( float depth ) {",
  14833. " depth /= 1000.0;",
  14834. " const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  14835. " const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  14836. " vec4 res = mod( depth * bitSh * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );",
  14837. " res -= res.xxyz * bitMsk;",
  14838. " return res; ",
  14839. "}",
  14840. "float unpack1K ( vec4 color ) {",
  14841. " const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
  14842. " return dot( color, bitSh ) * 1000.0;",
  14843. "}",
  14844. "void main () {",
  14845. " gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );",
  14846. "}"
  14847. ].join( "\n" )
  14848. }
  14849. };
  14850. // File:src/renderers/WebGLRenderer.js
  14851. /**
  14852. * @author supereggbert / http://www.paulbrunt.co.uk/
  14853. * @author mrdoob / http://mrdoob.com/
  14854. * @author alteredq / http://alteredqualia.com/
  14855. * @author szimek / https://github.com/szimek/
  14856. */
  14857. THREE.WebGLRenderer = function ( parameters ) {
  14858. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  14859. parameters = parameters || {};
  14860. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  14861. _context = parameters.context !== undefined ? parameters.context : null,
  14862. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14863. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14864. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14865. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14866. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14867. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
  14868. var lights = [];
  14869. var opaqueObjects = [];
  14870. var opaqueObjectsLastIndex = - 1;
  14871. var transparentObjects = [];
  14872. var transparentObjectsLastIndex = - 1;
  14873. var morphInfluences = new Float32Array( 8 );
  14874. var sprites = [];
  14875. var lensFlares = [];
  14876. // public properties
  14877. this.domElement = _canvas;
  14878. this.context = null;
  14879. // clearing
  14880. this.autoClear = true;
  14881. this.autoClearColor = true;
  14882. this.autoClearDepth = true;
  14883. this.autoClearStencil = true;
  14884. // scene graph
  14885. this.sortObjects = true;
  14886. // physically based shading
  14887. this.gammaFactor = 2.0; // for backwards compatibility
  14888. this.gammaInput = false;
  14889. this.gammaOutput = false;
  14890. // morphs
  14891. this.maxMorphTargets = 8;
  14892. this.maxMorphNormals = 4;
  14893. // flags
  14894. this.autoScaleCubemaps = true;
  14895. // internal properties
  14896. var _this = this,
  14897. // internal state cache
  14898. _currentProgram = null,
  14899. _currentRenderTarget = null,
  14900. _currentFramebuffer = null,
  14901. _currentMaterialId = - 1,
  14902. _currentGeometryProgram = '',
  14903. _currentCamera = null,
  14904. _currentScissor = new THREE.Vector4(),
  14905. _currentScissorTest = null,
  14906. _currentViewport = new THREE.Vector4(),
  14907. //
  14908. _usedTextureUnits = 0,
  14909. //
  14910. _clearColor = new THREE.Color( 0x000000 ),
  14911. _clearAlpha = 0,
  14912. _width = _canvas.width,
  14913. _height = _canvas.height,
  14914. _pixelRatio = 1,
  14915. _scissor = new THREE.Vector4( 0, 0, _width, _height ),
  14916. _scissorTest = false,
  14917. _viewport = new THREE.Vector4( 0, 0, _width, _height ),
  14918. // frustum
  14919. _frustum = new THREE.Frustum(),
  14920. // camera matrices cache
  14921. _projScreenMatrix = new THREE.Matrix4(),
  14922. _vector3 = new THREE.Vector3(),
  14923. // light arrays cache
  14924. _lights = {
  14925. hash: '',
  14926. ambient: [ 0, 0, 0 ],
  14927. directional: [],
  14928. directionalShadowMap: [],
  14929. directionalShadowMatrix: [],
  14930. spot: [],
  14931. spotShadowMap: [],
  14932. spotShadowMatrix: [],
  14933. point: [],
  14934. pointShadowMap: [],
  14935. pointShadowMatrix: [],
  14936. hemi: [],
  14937. shadows: [],
  14938. shadowsPointLight: 0
  14939. },
  14940. // info
  14941. _infoMemory = {
  14942. geometries: 0,
  14943. textures: 0
  14944. },
  14945. _infoRender = {
  14946. calls: 0,
  14947. vertices: 0,
  14948. faces: 0,
  14949. points: 0
  14950. };
  14951. this.info = {
  14952. render: _infoRender,
  14953. memory: _infoMemory,
  14954. programs: null
  14955. };
  14956. // initialize
  14957. var _gl;
  14958. try {
  14959. var attributes = {
  14960. alpha: _alpha,
  14961. depth: _depth,
  14962. stencil: _stencil,
  14963. antialias: _antialias,
  14964. premultipliedAlpha: _premultipliedAlpha,
  14965. preserveDrawingBuffer: _preserveDrawingBuffer
  14966. };
  14967. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  14968. if ( _gl === null ) {
  14969. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14970. throw 'Error creating WebGL context with your selected attributes.';
  14971. } else {
  14972. throw 'Error creating WebGL context.';
  14973. }
  14974. }
  14975. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14976. } catch ( error ) {
  14977. console.error( 'THREE.WebGLRenderer: ' + error );
  14978. }
  14979. var extensions = new THREE.WebGLExtensions( _gl );
  14980. extensions.get( 'OES_texture_float' );
  14981. extensions.get( 'OES_texture_float_linear' );
  14982. extensions.get( 'OES_texture_half_float' );
  14983. extensions.get( 'OES_texture_half_float_linear' );
  14984. extensions.get( 'OES_standard_derivatives' );
  14985. extensions.get( 'ANGLE_instanced_arrays' );
  14986. if ( extensions.get( 'OES_element_index_uint' ) ) {
  14987. THREE.BufferGeometry.MaxIndex = 4294967296;
  14988. }
  14989. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  14990. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  14991. var properties = new THREE.WebGLProperties();
  14992. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  14993. var programCache = new THREE.WebGLPrograms( this, capabilities );
  14994. var lightCache = new THREE.WebGLLights();
  14995. this.info.programs = programCache.programs;
  14996. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  14997. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  14998. //
  14999. function getTargetPixelRatio() {
  15000. return _currentRenderTarget === null ? _pixelRatio : 1;
  15001. }
  15002. function glClearColor( r, g, b, a ) {
  15003. if ( _premultipliedAlpha === true ) {
  15004. r *= a; g *= a; b *= a;
  15005. }
  15006. state.clearColor( r, g, b, a );
  15007. }
  15008. function setDefaultGLState() {
  15009. state.init();
  15010. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  15011. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  15012. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  15013. }
  15014. function resetGLState() {
  15015. _currentProgram = null;
  15016. _currentCamera = null;
  15017. _currentGeometryProgram = '';
  15018. _currentMaterialId = - 1;
  15019. state.reset();
  15020. }
  15021. setDefaultGLState();
  15022. this.context = _gl;
  15023. this.capabilities = capabilities;
  15024. this.extensions = extensions;
  15025. this.properties = properties;
  15026. this.state = state;
  15027. // shadow map
  15028. var shadowMap = new THREE.WebGLShadowMap( this, _lights, objects );
  15029. this.shadowMap = shadowMap;
  15030. // Plugins
  15031. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  15032. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  15033. // API
  15034. this.getContext = function () {
  15035. return _gl;
  15036. };
  15037. this.getContextAttributes = function () {
  15038. return _gl.getContextAttributes();
  15039. };
  15040. this.forceContextLoss = function () {
  15041. extensions.get( 'WEBGL_lose_context' ).loseContext();
  15042. };
  15043. this.getMaxAnisotropy = ( function () {
  15044. var value;
  15045. return function getMaxAnisotropy() {
  15046. if ( value !== undefined ) return value;
  15047. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  15048. if ( extension !== null ) {
  15049. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  15050. } else {
  15051. value = 0;
  15052. }
  15053. return value;
  15054. };
  15055. } )();
  15056. this.getPrecision = function () {
  15057. return capabilities.precision;
  15058. };
  15059. this.getPixelRatio = function () {
  15060. return _pixelRatio;
  15061. };
  15062. this.setPixelRatio = function ( value ) {
  15063. if ( value === undefined ) return;
  15064. _pixelRatio = value;
  15065. this.setSize( _viewport.z, _viewport.w, false );
  15066. };
  15067. this.getSize = function () {
  15068. return {
  15069. width: _width,
  15070. height: _height
  15071. };
  15072. };
  15073. this.setSize = function ( width, height, updateStyle ) {
  15074. _width = width;
  15075. _height = height;
  15076. _canvas.width = width * _pixelRatio;
  15077. _canvas.height = height * _pixelRatio;
  15078. if ( updateStyle !== false ) {
  15079. _canvas.style.width = width + 'px';
  15080. _canvas.style.height = height + 'px';
  15081. }
  15082. this.setViewport( 0, 0, width, height );
  15083. };
  15084. this.setViewport = function ( x, y, width, height ) {
  15085. state.viewport( _viewport.set( x, y, width, height ) );
  15086. };
  15087. this.setScissor = function ( x, y, width, height ) {
  15088. state.scissor( _scissor.set( x, y, width, height ) );
  15089. };
  15090. this.setScissorTest = function ( boolean ) {
  15091. state.setScissorTest( _scissorTest = boolean );
  15092. };
  15093. // Clearing
  15094. this.getClearColor = function () {
  15095. return _clearColor;
  15096. };
  15097. this.setClearColor = function ( color, alpha ) {
  15098. _clearColor.set( color );
  15099. _clearAlpha = alpha !== undefined ? alpha : 1;
  15100. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  15101. };
  15102. this.getClearAlpha = function () {
  15103. return _clearAlpha;
  15104. };
  15105. this.setClearAlpha = function ( alpha ) {
  15106. _clearAlpha = alpha;
  15107. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  15108. };
  15109. this.clear = function ( color, depth, stencil ) {
  15110. var bits = 0;
  15111. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  15112. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  15113. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  15114. _gl.clear( bits );
  15115. };
  15116. this.clearColor = function () {
  15117. this.clear( true, false, false );
  15118. };
  15119. this.clearDepth = function () {
  15120. this.clear( false, true, false );
  15121. };
  15122. this.clearStencil = function () {
  15123. this.clear( false, false, true );
  15124. };
  15125. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  15126. this.setRenderTarget( renderTarget );
  15127. this.clear( color, depth, stencil );
  15128. };
  15129. // Reset
  15130. this.resetGLState = resetGLState;
  15131. this.dispose = function() {
  15132. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  15133. };
  15134. // Events
  15135. function onContextLost( event ) {
  15136. event.preventDefault();
  15137. resetGLState();
  15138. setDefaultGLState();
  15139. properties.clear();
  15140. }
  15141. function onTextureDispose( event ) {
  15142. var texture = event.target;
  15143. texture.removeEventListener( 'dispose', onTextureDispose );
  15144. deallocateTexture( texture );
  15145. _infoMemory.textures --;
  15146. }
  15147. function onRenderTargetDispose( event ) {
  15148. var renderTarget = event.target;
  15149. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  15150. deallocateRenderTarget( renderTarget );
  15151. _infoMemory.textures --;
  15152. }
  15153. function onMaterialDispose( event ) {
  15154. var material = event.target;
  15155. material.removeEventListener( 'dispose', onMaterialDispose );
  15156. deallocateMaterial( material );
  15157. }
  15158. // Buffer deallocation
  15159. function deallocateTexture( texture ) {
  15160. var textureProperties = properties.get( texture );
  15161. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  15162. // cube texture
  15163. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  15164. } else {
  15165. // 2D texture
  15166. if ( textureProperties.__webglInit === undefined ) return;
  15167. _gl.deleteTexture( textureProperties.__webglTexture );
  15168. }
  15169. // remove all webgl properties
  15170. properties.delete( texture );
  15171. }
  15172. function deallocateRenderTarget( renderTarget ) {
  15173. var renderTargetProperties = properties.get( renderTarget );
  15174. var textureProperties = properties.get( renderTarget.texture );
  15175. if ( ! renderTarget || textureProperties.__webglTexture === undefined ) return;
  15176. _gl.deleteTexture( textureProperties.__webglTexture );
  15177. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  15178. for ( var i = 0; i < 6; i ++ ) {
  15179. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  15180. _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  15181. }
  15182. } else {
  15183. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  15184. _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  15185. }
  15186. properties.delete( renderTarget.texture );
  15187. properties.delete( renderTarget );
  15188. }
  15189. function deallocateMaterial( material ) {
  15190. releaseMaterialProgramReference( material );
  15191. properties.delete( material );
  15192. }
  15193. function releaseMaterialProgramReference( material ) {
  15194. var programInfo = properties.get( material ).program;
  15195. material.program = undefined;
  15196. if ( programInfo !== undefined ) {
  15197. programCache.releaseProgram( programInfo );
  15198. }
  15199. }
  15200. // Buffer rendering
  15201. this.renderBufferImmediate = function ( object, program, material ) {
  15202. state.initAttributes();
  15203. var buffers = properties.get( object );
  15204. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  15205. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  15206. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  15207. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  15208. var attributes = program.getAttributes();
  15209. if ( object.hasPositions ) {
  15210. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  15211. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  15212. state.enableAttribute( attributes.position );
  15213. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  15214. }
  15215. if ( object.hasNormals ) {
  15216. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  15217. if ( material.type !== 'MeshPhongMaterial' && material.type !== 'MeshStandardMaterial' && material.shading === THREE.FlatShading ) {
  15218. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  15219. var array = object.normalArray;
  15220. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  15221. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  15222. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  15223. array[ i + 0 ] = nx;
  15224. array[ i + 1 ] = ny;
  15225. array[ i + 2 ] = nz;
  15226. array[ i + 3 ] = nx;
  15227. array[ i + 4 ] = ny;
  15228. array[ i + 5 ] = nz;
  15229. array[ i + 6 ] = nx;
  15230. array[ i + 7 ] = ny;
  15231. array[ i + 8 ] = nz;
  15232. }
  15233. }
  15234. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  15235. state.enableAttribute( attributes.normal );
  15236. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  15237. }
  15238. if ( object.hasUvs && material.map ) {
  15239. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  15240. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  15241. state.enableAttribute( attributes.uv );
  15242. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  15243. }
  15244. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  15245. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  15246. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  15247. state.enableAttribute( attributes.color );
  15248. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  15249. }
  15250. state.disableUnusedAttributes();
  15251. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  15252. object.count = 0;
  15253. };
  15254. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  15255. setMaterial( material );
  15256. var program = setProgram( camera, fog, material, object );
  15257. var updateBuffers = false;
  15258. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  15259. if ( geometryProgram !== _currentGeometryProgram ) {
  15260. _currentGeometryProgram = geometryProgram;
  15261. updateBuffers = true;
  15262. }
  15263. // morph targets
  15264. var morphTargetInfluences = object.morphTargetInfluences;
  15265. if ( morphTargetInfluences !== undefined ) {
  15266. var activeInfluences = [];
  15267. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  15268. var influence = morphTargetInfluences[ i ];
  15269. activeInfluences.push( [ influence, i ] );
  15270. }
  15271. activeInfluences.sort( absNumericalSort );
  15272. if ( activeInfluences.length > 8 ) {
  15273. activeInfluences.length = 8;
  15274. }
  15275. var morphAttributes = geometry.morphAttributes;
  15276. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  15277. var influence = activeInfluences[ i ];
  15278. morphInfluences[ i ] = influence[ 0 ];
  15279. if ( influence[ 0 ] !== 0 ) {
  15280. var index = influence[ 1 ];
  15281. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  15282. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  15283. } else {
  15284. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  15285. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  15286. }
  15287. }
  15288. var uniforms = program.getUniforms();
  15289. if ( uniforms.morphTargetInfluences !== null ) {
  15290. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  15291. }
  15292. updateBuffers = true;
  15293. }
  15294. //
  15295. var index = geometry.index;
  15296. var position = geometry.attributes.position;
  15297. if ( material.wireframe === true ) {
  15298. index = objects.getWireframeAttribute( geometry );
  15299. }
  15300. var renderer;
  15301. if ( index !== null ) {
  15302. renderer = indexedBufferRenderer;
  15303. renderer.setIndex( index );
  15304. } else {
  15305. renderer = bufferRenderer;
  15306. }
  15307. if ( updateBuffers ) {
  15308. setupVertexAttributes( material, program, geometry );
  15309. if ( index !== null ) {
  15310. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  15311. }
  15312. }
  15313. //
  15314. var dataStart = 0;
  15315. var dataCount = Infinity;
  15316. if ( index !== null ) {
  15317. dataCount = index.count;
  15318. } else if ( position !== undefined ) {
  15319. dataCount = position.count;
  15320. }
  15321. var rangeStart = geometry.drawRange.start;
  15322. var rangeCount = geometry.drawRange.count;
  15323. var groupStart = group !== null ? group.start : 0;
  15324. var groupCount = group !== null ? group.count : Infinity;
  15325. var drawStart = Math.max( dataStart, rangeStart, groupStart );
  15326. var drawEnd = Math.min( dataStart + dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  15327. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  15328. //
  15329. if ( object instanceof THREE.Mesh ) {
  15330. if ( material.wireframe === true ) {
  15331. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  15332. renderer.setMode( _gl.LINES );
  15333. } else {
  15334. switch ( object.drawMode ) {
  15335. case THREE.TrianglesDrawMode:
  15336. renderer.setMode( _gl.TRIANGLES );
  15337. break;
  15338. case THREE.TriangleStripDrawMode:
  15339. renderer.setMode( _gl.TRIANGLE_STRIP );
  15340. break;
  15341. case THREE.TriangleFanDrawMode:
  15342. renderer.setMode( _gl.TRIANGLE_FAN );
  15343. break;
  15344. }
  15345. }
  15346. } else if ( object instanceof THREE.Line ) {
  15347. var lineWidth = material.linewidth;
  15348. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  15349. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  15350. if ( object instanceof THREE.LineSegments ) {
  15351. renderer.setMode( _gl.LINES );
  15352. } else {
  15353. renderer.setMode( _gl.LINE_STRIP );
  15354. }
  15355. } else if ( object instanceof THREE.Points ) {
  15356. renderer.setMode( _gl.POINTS );
  15357. }
  15358. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  15359. renderer.renderInstances( geometry, drawStart, drawCount );
  15360. } else {
  15361. renderer.render( drawStart, drawCount );
  15362. }
  15363. };
  15364. function setupVertexAttributes( material, program, geometry, startIndex ) {
  15365. var extension;
  15366. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15367. extension = extensions.get( 'ANGLE_instanced_arrays' );
  15368. if ( extension === null ) {
  15369. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  15370. return;
  15371. }
  15372. }
  15373. if ( startIndex === undefined ) startIndex = 0;
  15374. state.initAttributes();
  15375. var geometryAttributes = geometry.attributes;
  15376. var programAttributes = program.getAttributes();
  15377. var materialDefaultAttributeValues = material.defaultAttributeValues;
  15378. for ( var name in programAttributes ) {
  15379. var programAttribute = programAttributes[ name ];
  15380. if ( programAttribute >= 0 ) {
  15381. var geometryAttribute = geometryAttributes[ name ];
  15382. if ( geometryAttribute !== undefined ) {
  15383. var size = geometryAttribute.itemSize;
  15384. var buffer = objects.getAttributeBuffer( geometryAttribute );
  15385. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  15386. var data = geometryAttribute.data;
  15387. var stride = data.stride;
  15388. var offset = geometryAttribute.offset;
  15389. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  15390. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  15391. if ( geometry.maxInstancedCount === undefined ) {
  15392. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  15393. }
  15394. } else {
  15395. state.enableAttribute( programAttribute );
  15396. }
  15397. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15398. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  15399. } else {
  15400. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  15401. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  15402. if ( geometry.maxInstancedCount === undefined ) {
  15403. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  15404. }
  15405. } else {
  15406. state.enableAttribute( programAttribute );
  15407. }
  15408. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15409. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  15410. }
  15411. } else if ( materialDefaultAttributeValues !== undefined ) {
  15412. var value = materialDefaultAttributeValues[ name ];
  15413. if ( value !== undefined ) {
  15414. switch ( value.length ) {
  15415. case 2:
  15416. _gl.vertexAttrib2fv( programAttribute, value );
  15417. break;
  15418. case 3:
  15419. _gl.vertexAttrib3fv( programAttribute, value );
  15420. break;
  15421. case 4:
  15422. _gl.vertexAttrib4fv( programAttribute, value );
  15423. break;
  15424. default:
  15425. _gl.vertexAttrib1fv( programAttribute, value );
  15426. }
  15427. }
  15428. }
  15429. }
  15430. }
  15431. state.disableUnusedAttributes();
  15432. }
  15433. // Sorting
  15434. function absNumericalSort( a, b ) {
  15435. return Math.abs( b[ 0 ] ) - Math.abs( a[ 0 ] );
  15436. }
  15437. function painterSortStable ( a, b ) {
  15438. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15439. return a.object.renderOrder - b.object.renderOrder;
  15440. } else if ( a.material.id !== b.material.id ) {
  15441. return a.material.id - b.material.id;
  15442. } else if ( a.z !== b.z ) {
  15443. return a.z - b.z;
  15444. } else {
  15445. return a.id - b.id;
  15446. }
  15447. }
  15448. function reversePainterSortStable ( a, b ) {
  15449. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15450. return a.object.renderOrder - b.object.renderOrder;
  15451. } if ( a.z !== b.z ) {
  15452. return b.z - a.z;
  15453. } else {
  15454. return a.id - b.id;
  15455. }
  15456. }
  15457. // Rendering
  15458. this.render = function ( scene, camera, renderTarget, forceClear ) {
  15459. if ( camera instanceof THREE.Camera === false ) {
  15460. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15461. return;
  15462. }
  15463. var fog = scene.fog;
  15464. // reset caching for this frame
  15465. _currentGeometryProgram = '';
  15466. _currentMaterialId = - 1;
  15467. _currentCamera = null;
  15468. // update scene graph
  15469. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15470. // update camera matrices and frustum
  15471. if ( camera.parent === null ) camera.updateMatrixWorld();
  15472. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  15473. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15474. _frustum.setFromMatrix( _projScreenMatrix );
  15475. lights.length = 0;
  15476. opaqueObjectsLastIndex = - 1;
  15477. transparentObjectsLastIndex = - 1;
  15478. sprites.length = 0;
  15479. lensFlares.length = 0;
  15480. projectObject( scene, camera );
  15481. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  15482. transparentObjects.length = transparentObjectsLastIndex + 1;
  15483. if ( _this.sortObjects === true ) {
  15484. opaqueObjects.sort( painterSortStable );
  15485. transparentObjects.sort( reversePainterSortStable );
  15486. }
  15487. setupLights( lights, camera );
  15488. //
  15489. shadowMap.render( scene, camera );
  15490. //
  15491. _infoRender.calls = 0;
  15492. _infoRender.vertices = 0;
  15493. _infoRender.faces = 0;
  15494. _infoRender.points = 0;
  15495. if ( renderTarget === undefined ) {
  15496. renderTarget = null;
  15497. }
  15498. this.setRenderTarget( renderTarget );
  15499. if ( this.autoClear || forceClear ) {
  15500. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  15501. }
  15502. //
  15503. if ( scene.overrideMaterial ) {
  15504. var overrideMaterial = scene.overrideMaterial;
  15505. renderObjects( opaqueObjects, camera, fog, overrideMaterial );
  15506. renderObjects( transparentObjects, camera, fog, overrideMaterial );
  15507. } else {
  15508. // opaque pass (front-to-back order)
  15509. state.setBlending( THREE.NoBlending );
  15510. renderObjects( opaqueObjects, camera, fog );
  15511. // transparent pass (back-to-front order)
  15512. renderObjects( transparentObjects, camera, fog );
  15513. }
  15514. // custom render plugins (post pass)
  15515. spritePlugin.render( scene, camera );
  15516. lensFlarePlugin.render( scene, camera, _currentViewport );
  15517. // Generate mipmap if we're using any kind of mipmap filtering
  15518. if ( renderTarget ) {
  15519. var texture = renderTarget.texture;
  15520. if ( texture.generateMipmaps && isPowerOfTwo( renderTarget ) &&
  15521. texture.minFilter !== THREE.NearestFilter &&
  15522. texture.minFilter !== THREE.LinearFilter ) {
  15523. updateRenderTargetMipmap( renderTarget );
  15524. }
  15525. }
  15526. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15527. state.setDepthTest( true );
  15528. state.setDepthWrite( true );
  15529. state.setColorWrite( true );
  15530. // _gl.finish();
  15531. };
  15532. function pushRenderItem( object, geometry, material, z, group ) {
  15533. var array, index;
  15534. // allocate the next position in the appropriate array
  15535. if ( material.transparent ) {
  15536. array = transparentObjects;
  15537. index = ++ transparentObjectsLastIndex;
  15538. } else {
  15539. array = opaqueObjects;
  15540. index = ++ opaqueObjectsLastIndex;
  15541. }
  15542. // recycle existing render item or grow the array
  15543. var renderItem = array[ index ];
  15544. if ( renderItem !== undefined ) {
  15545. renderItem.id = object.id;
  15546. renderItem.object = object;
  15547. renderItem.geometry = geometry;
  15548. renderItem.material = material;
  15549. renderItem.z = _vector3.z;
  15550. renderItem.group = group;
  15551. } else {
  15552. renderItem = {
  15553. id: object.id,
  15554. object: object,
  15555. geometry: geometry,
  15556. material: material,
  15557. z: _vector3.z,
  15558. group: group
  15559. };
  15560. // assert( index === array.length );
  15561. array.push( renderItem );
  15562. }
  15563. }
  15564. function projectObject( object, camera ) {
  15565. if ( object.visible === false ) return;
  15566. if ( object.layers.test( camera.layers ) ) {
  15567. if ( object instanceof THREE.Light ) {
  15568. lights.push( object );
  15569. } else if ( object instanceof THREE.Sprite ) {
  15570. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15571. sprites.push( object );
  15572. }
  15573. } else if ( object instanceof THREE.LensFlare ) {
  15574. lensFlares.push( object );
  15575. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  15576. if ( _this.sortObjects === true ) {
  15577. _vector3.setFromMatrixPosition( object.matrixWorld );
  15578. _vector3.applyProjection( _projScreenMatrix );
  15579. }
  15580. pushRenderItem( object, null, object.material, _vector3.z, null );
  15581. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15582. if ( object instanceof THREE.SkinnedMesh ) {
  15583. object.skeleton.update();
  15584. }
  15585. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15586. var material = object.material;
  15587. if ( material.visible === true ) {
  15588. if ( _this.sortObjects === true ) {
  15589. _vector3.setFromMatrixPosition( object.matrixWorld );
  15590. _vector3.applyProjection( _projScreenMatrix );
  15591. }
  15592. var geometry = objects.update( object );
  15593. if ( material instanceof THREE.MultiMaterial ) {
  15594. var groups = geometry.groups;
  15595. var materials = material.materials;
  15596. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15597. var group = groups[ i ];
  15598. var groupMaterial = materials[ group.materialIndex ];
  15599. if ( groupMaterial.visible === true ) {
  15600. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  15601. }
  15602. }
  15603. } else {
  15604. pushRenderItem( object, geometry, material, _vector3.z, null );
  15605. }
  15606. }
  15607. }
  15608. }
  15609. }
  15610. var children = object.children;
  15611. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15612. projectObject( children[ i ], camera );
  15613. }
  15614. }
  15615. function renderObjects( renderList, camera, fog, overrideMaterial ) {
  15616. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15617. var renderItem = renderList[ i ];
  15618. var object = renderItem.object;
  15619. var geometry = renderItem.geometry;
  15620. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  15621. var group = renderItem.group;
  15622. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15623. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15624. if ( object instanceof THREE.ImmediateRenderObject ) {
  15625. setMaterial( material );
  15626. var program = setProgram( camera, fog, material, object );
  15627. _currentGeometryProgram = '';
  15628. object.render( function ( object ) {
  15629. _this.renderBufferImmediate( object, program, material );
  15630. } );
  15631. } else {
  15632. _this.renderBufferDirect( camera, fog, geometry, material, object, group );
  15633. }
  15634. }
  15635. }
  15636. function initMaterial( material, fog, object ) {
  15637. var materialProperties = properties.get( material );
  15638. var parameters = programCache.getParameters( material, _lights, fog, object );
  15639. var code = programCache.getProgramCode( material, parameters );
  15640. var program = materialProperties.program;
  15641. var programChange = true;
  15642. if ( program === undefined ) {
  15643. // new material
  15644. material.addEventListener( 'dispose', onMaterialDispose );
  15645. } else if ( program.code !== code ) {
  15646. // changed glsl or parameters
  15647. releaseMaterialProgramReference( material );
  15648. } else if ( parameters.shaderID !== undefined ) {
  15649. // same glsl and uniform list
  15650. return;
  15651. } else {
  15652. // only rebuild uniform list
  15653. programChange = false;
  15654. }
  15655. if ( programChange ) {
  15656. if ( parameters.shaderID ) {
  15657. var shader = THREE.ShaderLib[ parameters.shaderID ];
  15658. materialProperties.__webglShader = {
  15659. name: material.type,
  15660. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  15661. vertexShader: shader.vertexShader,
  15662. fragmentShader: shader.fragmentShader
  15663. };
  15664. } else {
  15665. materialProperties.__webglShader = {
  15666. name: material.type,
  15667. uniforms: material.uniforms,
  15668. vertexShader: material.vertexShader,
  15669. fragmentShader: material.fragmentShader
  15670. };
  15671. }
  15672. material.__webglShader = materialProperties.__webglShader;
  15673. program = programCache.acquireProgram( material, parameters, code );
  15674. materialProperties.program = program;
  15675. material.program = program;
  15676. }
  15677. var attributes = program.getAttributes();
  15678. if ( material.morphTargets ) {
  15679. material.numSupportedMorphTargets = 0;
  15680. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15681. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  15682. material.numSupportedMorphTargets ++;
  15683. }
  15684. }
  15685. }
  15686. if ( material.morphNormals ) {
  15687. material.numSupportedMorphNormals = 0;
  15688. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  15689. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  15690. material.numSupportedMorphNormals ++;
  15691. }
  15692. }
  15693. }
  15694. materialProperties.uniformsList = [];
  15695. var uniforms = materialProperties.__webglShader.uniforms,
  15696. uniformLocations = materialProperties.program.getUniforms();
  15697. for ( var u in uniforms ) {
  15698. var location = uniformLocations[ u ];
  15699. if ( location ) {
  15700. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  15701. }
  15702. }
  15703. if ( material instanceof THREE.MeshPhongMaterial ||
  15704. material instanceof THREE.MeshLambertMaterial ||
  15705. material instanceof THREE.MeshStandardMaterial ||
  15706. material.lights ) {
  15707. // store the light setup it was created for
  15708. materialProperties.lightsHash = _lights.hash;
  15709. // wire up the material to this renderer's lighting state
  15710. uniforms.ambientLightColor.value = _lights.ambient;
  15711. uniforms.directionalLights.value = _lights.directional;
  15712. uniforms.spotLights.value = _lights.spot;
  15713. uniforms.pointLights.value = _lights.point;
  15714. uniforms.hemisphereLights.value = _lights.hemi;
  15715. uniforms.directionalShadowMap.value = _lights.directionalShadowMap;
  15716. uniforms.directionalShadowMatrix.value = _lights.directionalShadowMatrix;
  15717. uniforms.spotShadowMap.value = _lights.spotShadowMap;
  15718. uniforms.spotShadowMatrix.value = _lights.spotShadowMatrix;
  15719. uniforms.pointShadowMap.value = _lights.pointShadowMap;
  15720. uniforms.pointShadowMatrix.value = _lights.pointShadowMatrix;
  15721. }
  15722. // detect dynamic uniforms
  15723. materialProperties.hasDynamicUniforms = false;
  15724. for ( var j = 0, jl = materialProperties.uniformsList.length; j < jl; j ++ ) {
  15725. var uniform = materialProperties.uniformsList[ j ][ 0 ];
  15726. if ( uniform.dynamic === true ) {
  15727. materialProperties.hasDynamicUniforms = true;
  15728. break;
  15729. }
  15730. }
  15731. }
  15732. function setMaterial( material ) {
  15733. setMaterialFaces( material );
  15734. if ( material.transparent === true ) {
  15735. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  15736. } else {
  15737. state.setBlending( THREE.NoBlending );
  15738. }
  15739. state.setDepthFunc( material.depthFunc );
  15740. state.setDepthTest( material.depthTest );
  15741. state.setDepthWrite( material.depthWrite );
  15742. state.setColorWrite( material.colorWrite );
  15743. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  15744. }
  15745. function setMaterialFaces( material ) {
  15746. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  15747. state.setFlipSided( material.side === THREE.BackSide );
  15748. }
  15749. function setProgram( camera, fog, material, object ) {
  15750. _usedTextureUnits = 0;
  15751. var materialProperties = properties.get( material );
  15752. if ( materialProperties.program === undefined ) {
  15753. material.needsUpdate = true;
  15754. }
  15755. if ( materialProperties.lightsHash !== undefined &&
  15756. materialProperties.lightsHash !== _lights.hash ) {
  15757. material.needsUpdate = true;
  15758. }
  15759. if ( material.needsUpdate ) {
  15760. initMaterial( material, fog, object );
  15761. material.needsUpdate = false;
  15762. }
  15763. var refreshProgram = false;
  15764. var refreshMaterial = false;
  15765. var refreshLights = false;
  15766. var program = materialProperties.program,
  15767. p_uniforms = program.getUniforms(),
  15768. m_uniforms = materialProperties.__webglShader.uniforms;
  15769. if ( program.id !== _currentProgram ) {
  15770. _gl.useProgram( program.program );
  15771. _currentProgram = program.id;
  15772. refreshProgram = true;
  15773. refreshMaterial = true;
  15774. refreshLights = true;
  15775. }
  15776. if ( material.id !== _currentMaterialId ) {
  15777. _currentMaterialId = material.id;
  15778. refreshMaterial = true;
  15779. }
  15780. if ( refreshProgram || camera !== _currentCamera ) {
  15781. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  15782. if ( capabilities.logarithmicDepthBuffer ) {
  15783. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15784. }
  15785. if ( camera !== _currentCamera ) {
  15786. _currentCamera = camera;
  15787. // lighting uniforms depend on the camera so enforce an update
  15788. // now, in case this material supports lights - or later, when
  15789. // the next material that does gets activated:
  15790. refreshMaterial = true; // set to true on material change
  15791. refreshLights = true; // remains set until update done
  15792. }
  15793. // load material specific uniforms
  15794. // (shader material also gets them for the sake of genericity)
  15795. if ( material instanceof THREE.ShaderMaterial ||
  15796. material instanceof THREE.MeshPhongMaterial ||
  15797. material instanceof THREE.MeshStandardMaterial ||
  15798. material.envMap ) {
  15799. if ( p_uniforms.cameraPosition !== undefined ) {
  15800. _vector3.setFromMatrixPosition( camera.matrixWorld );
  15801. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  15802. }
  15803. }
  15804. if ( material instanceof THREE.MeshPhongMaterial ||
  15805. material instanceof THREE.MeshLambertMaterial ||
  15806. material instanceof THREE.MeshBasicMaterial ||
  15807. material instanceof THREE.MeshStandardMaterial ||
  15808. material instanceof THREE.ShaderMaterial ||
  15809. material.skinning ) {
  15810. if ( p_uniforms.viewMatrix !== undefined ) {
  15811. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  15812. }
  15813. }
  15814. }
  15815. // skinning uniforms must be set even if material didn't change
  15816. // auto-setting of texture unit for bone texture must go before other textures
  15817. // not sure why, but otherwise weird things happen
  15818. if ( material.skinning ) {
  15819. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  15820. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  15821. }
  15822. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  15823. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  15824. }
  15825. if ( capabilities.floatVertexTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  15826. if ( p_uniforms.boneTexture !== undefined ) {
  15827. var textureUnit = getTextureUnit();
  15828. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  15829. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  15830. }
  15831. if ( p_uniforms.boneTextureWidth !== undefined ) {
  15832. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  15833. }
  15834. if ( p_uniforms.boneTextureHeight !== undefined ) {
  15835. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  15836. }
  15837. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  15838. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  15839. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  15840. }
  15841. }
  15842. }
  15843. if ( refreshMaterial ) {
  15844. if ( material instanceof THREE.MeshPhongMaterial ||
  15845. material instanceof THREE.MeshLambertMaterial ||
  15846. material instanceof THREE.MeshStandardMaterial ||
  15847. material.lights ) {
  15848. // the current material requires lighting info
  15849. // note: all lighting uniforms are always set correctly
  15850. // they simply reference the renderer's state for their
  15851. // values
  15852. //
  15853. // use the current material's .needsUpdate flags to set
  15854. // the GL state when required
  15855. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15856. }
  15857. // refresh uniforms common to several materials
  15858. if ( fog && material.fog ) {
  15859. refreshUniformsFog( m_uniforms, fog );
  15860. }
  15861. if ( material instanceof THREE.MeshBasicMaterial ||
  15862. material instanceof THREE.MeshLambertMaterial ||
  15863. material instanceof THREE.MeshPhongMaterial ||
  15864. material instanceof THREE.MeshStandardMaterial ) {
  15865. refreshUniformsCommon( m_uniforms, material );
  15866. }
  15867. // refresh single material specific uniforms
  15868. if ( material instanceof THREE.LineBasicMaterial ) {
  15869. refreshUniformsLine( m_uniforms, material );
  15870. } else if ( material instanceof THREE.LineDashedMaterial ) {
  15871. refreshUniformsLine( m_uniforms, material );
  15872. refreshUniformsDash( m_uniforms, material );
  15873. } else if ( material instanceof THREE.PointsMaterial ) {
  15874. refreshUniformsPoints( m_uniforms, material );
  15875. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  15876. refreshUniformsLambert( m_uniforms, material );
  15877. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  15878. refreshUniformsPhong( m_uniforms, material );
  15879. } else if ( material instanceof THREE.MeshStandardMaterial ) {
  15880. refreshUniformsStandard( m_uniforms, material );
  15881. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  15882. m_uniforms.mNear.value = camera.near;
  15883. m_uniforms.mFar.value = camera.far;
  15884. m_uniforms.opacity.value = material.opacity;
  15885. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  15886. m_uniforms.opacity.value = material.opacity;
  15887. }
  15888. // load common uniforms
  15889. loadUniformsGeneric( materialProperties.uniformsList );
  15890. }
  15891. loadUniformsMatrices( p_uniforms, object );
  15892. if ( p_uniforms.modelMatrix !== undefined ) {
  15893. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  15894. }
  15895. if ( materialProperties.hasDynamicUniforms === true ) {
  15896. updateDynamicUniforms( materialProperties.uniformsList, object, camera );
  15897. }
  15898. return program;
  15899. }
  15900. function updateDynamicUniforms ( uniforms, object, camera ) {
  15901. var dynamicUniforms = [];
  15902. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  15903. var uniform = uniforms[ j ][ 0 ];
  15904. var onUpdateCallback = uniform.onUpdateCallback;
  15905. if ( onUpdateCallback !== undefined ) {
  15906. onUpdateCallback.bind( uniform )( object, camera );
  15907. dynamicUniforms.push( uniforms[ j ] );
  15908. }
  15909. }
  15910. loadUniformsGeneric( dynamicUniforms );
  15911. }
  15912. // Uniforms (refresh uniforms objects)
  15913. function refreshUniformsCommon ( uniforms, material ) {
  15914. uniforms.opacity.value = material.opacity;
  15915. uniforms.diffuse.value = material.color;
  15916. if ( material.emissive ) {
  15917. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  15918. }
  15919. uniforms.map.value = material.map;
  15920. uniforms.specularMap.value = material.specularMap;
  15921. uniforms.alphaMap.value = material.alphaMap;
  15922. if ( material.aoMap ) {
  15923. uniforms.aoMap.value = material.aoMap;
  15924. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  15925. }
  15926. // uv repeat and offset setting priorities
  15927. // 1. color map
  15928. // 2. specular map
  15929. // 3. normal map
  15930. // 4. bump map
  15931. // 5. alpha map
  15932. // 6. emissive map
  15933. var uvScaleMap;
  15934. if ( material.map ) {
  15935. uvScaleMap = material.map;
  15936. } else if ( material.specularMap ) {
  15937. uvScaleMap = material.specularMap;
  15938. } else if ( material.displacementMap ) {
  15939. uvScaleMap = material.displacementMap;
  15940. } else if ( material.normalMap ) {
  15941. uvScaleMap = material.normalMap;
  15942. } else if ( material.bumpMap ) {
  15943. uvScaleMap = material.bumpMap;
  15944. } else if ( material.roughnessMap ) {
  15945. uvScaleMap = material.roughnessMap;
  15946. } else if ( material.metalnessMap ) {
  15947. uvScaleMap = material.metalnessMap;
  15948. } else if ( material.alphaMap ) {
  15949. uvScaleMap = material.alphaMap;
  15950. } else if ( material.emissiveMap ) {
  15951. uvScaleMap = material.emissiveMap;
  15952. }
  15953. if ( uvScaleMap !== undefined ) {
  15954. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) {
  15955. uvScaleMap = uvScaleMap.texture;
  15956. }
  15957. var offset = uvScaleMap.offset;
  15958. var repeat = uvScaleMap.repeat;
  15959. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15960. }
  15961. uniforms.envMap.value = material.envMap;
  15962. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  15963. uniforms.reflectivity.value = material.reflectivity;
  15964. uniforms.refractionRatio.value = material.refractionRatio;
  15965. }
  15966. function refreshUniformsLine ( uniforms, material ) {
  15967. uniforms.diffuse.value = material.color;
  15968. uniforms.opacity.value = material.opacity;
  15969. }
  15970. function refreshUniformsDash ( uniforms, material ) {
  15971. uniforms.dashSize.value = material.dashSize;
  15972. uniforms.totalSize.value = material.dashSize + material.gapSize;
  15973. uniforms.scale.value = material.scale;
  15974. }
  15975. function refreshUniformsPoints ( uniforms, material ) {
  15976. uniforms.diffuse.value = material.color;
  15977. uniforms.opacity.value = material.opacity;
  15978. uniforms.size.value = material.size * _pixelRatio;
  15979. uniforms.scale.value = _canvas.clientHeight / 2.0; // TODO: Cache this.
  15980. uniforms.map.value = material.map;
  15981. if ( material.map !== null ) {
  15982. var offset = material.map.offset;
  15983. var repeat = material.map.repeat;
  15984. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15985. }
  15986. }
  15987. function refreshUniformsFog ( uniforms, fog ) {
  15988. uniforms.fogColor.value = fog.color;
  15989. if ( fog instanceof THREE.Fog ) {
  15990. uniforms.fogNear.value = fog.near;
  15991. uniforms.fogFar.value = fog.far;
  15992. } else if ( fog instanceof THREE.FogExp2 ) {
  15993. uniforms.fogDensity.value = fog.density;
  15994. }
  15995. }
  15996. function refreshUniformsLambert ( uniforms, material ) {
  15997. if ( material.lightMap ) {
  15998. uniforms.lightMap.value = material.lightMap;
  15999. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  16000. }
  16001. if ( material.emissiveMap ) {
  16002. uniforms.emissiveMap.value = material.emissiveMap;
  16003. }
  16004. }
  16005. function refreshUniformsPhong ( uniforms, material ) {
  16006. uniforms.specular.value = material.specular;
  16007. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  16008. if ( material.lightMap ) {
  16009. uniforms.lightMap.value = material.lightMap;
  16010. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  16011. }
  16012. if ( material.emissiveMap ) {
  16013. uniforms.emissiveMap.value = material.emissiveMap;
  16014. }
  16015. if ( material.bumpMap ) {
  16016. uniforms.bumpMap.value = material.bumpMap;
  16017. uniforms.bumpScale.value = material.bumpScale;
  16018. }
  16019. if ( material.normalMap ) {
  16020. uniforms.normalMap.value = material.normalMap;
  16021. uniforms.normalScale.value.copy( material.normalScale );
  16022. }
  16023. if ( material.displacementMap ) {
  16024. uniforms.displacementMap.value = material.displacementMap;
  16025. uniforms.displacementScale.value = material.displacementScale;
  16026. uniforms.displacementBias.value = material.displacementBias;
  16027. }
  16028. }
  16029. function refreshUniformsStandard ( uniforms, material ) {
  16030. uniforms.roughness.value = material.roughness;
  16031. uniforms.metalness.value = material.metalness;
  16032. if ( material.roughnessMap ) {
  16033. uniforms.roughnessMap.value = material.roughnessMap;
  16034. }
  16035. if ( material.metalnessMap ) {
  16036. uniforms.metalnessMap.value = material.metalnessMap;
  16037. }
  16038. if ( material.lightMap ) {
  16039. uniforms.lightMap.value = material.lightMap;
  16040. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  16041. }
  16042. if ( material.emissiveMap ) {
  16043. uniforms.emissiveMap.value = material.emissiveMap;
  16044. }
  16045. if ( material.bumpMap ) {
  16046. uniforms.bumpMap.value = material.bumpMap;
  16047. uniforms.bumpScale.value = material.bumpScale;
  16048. }
  16049. if ( material.normalMap ) {
  16050. uniforms.normalMap.value = material.normalMap;
  16051. uniforms.normalScale.value.copy( material.normalScale );
  16052. }
  16053. if ( material.displacementMap ) {
  16054. uniforms.displacementMap.value = material.displacementMap;
  16055. uniforms.displacementScale.value = material.displacementScale;
  16056. uniforms.displacementBias.value = material.displacementBias;
  16057. }
  16058. if ( material.envMap ) {
  16059. //uniforms.envMap.value = material.envMap; // part of uniforms common
  16060. uniforms.envMapIntensity.value = material.envMapIntensity;
  16061. }
  16062. }
  16063. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  16064. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  16065. uniforms.ambientLightColor.needsUpdate = value;
  16066. uniforms.directionalLights.needsUpdate = value;
  16067. uniforms.pointLights.needsUpdate = value;
  16068. uniforms.spotLights.needsUpdate = value;
  16069. uniforms.hemisphereLights.needsUpdate = value;
  16070. }
  16071. // Uniforms (load to GPU)
  16072. function loadUniformsMatrices ( uniforms, object ) {
  16073. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object.modelViewMatrix.elements );
  16074. if ( uniforms.normalMatrix ) {
  16075. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object.normalMatrix.elements );
  16076. }
  16077. }
  16078. function getTextureUnit() {
  16079. var textureUnit = _usedTextureUnits;
  16080. if ( textureUnit >= capabilities.maxTextures ) {
  16081. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  16082. }
  16083. _usedTextureUnits += 1;
  16084. return textureUnit;
  16085. }
  16086. function loadUniformsGeneric ( uniforms ) {
  16087. var texture, textureUnit;
  16088. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  16089. var uniform = uniforms[ j ][ 0 ];
  16090. // needsUpdate property is not added to all uniforms.
  16091. if ( uniform.needsUpdate === false ) continue;
  16092. var type = uniform.type;
  16093. var value = uniform.value;
  16094. var location = uniforms[ j ][ 1 ];
  16095. switch ( type ) {
  16096. case '1i':
  16097. _gl.uniform1i( location, value );
  16098. break;
  16099. case '1f':
  16100. _gl.uniform1f( location, value );
  16101. break;
  16102. case '2f':
  16103. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  16104. break;
  16105. case '3f':
  16106. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  16107. break;
  16108. case '4f':
  16109. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  16110. break;
  16111. case '1iv':
  16112. _gl.uniform1iv( location, value );
  16113. break;
  16114. case '3iv':
  16115. _gl.uniform3iv( location, value );
  16116. break;
  16117. case '1fv':
  16118. _gl.uniform1fv( location, value );
  16119. break;
  16120. case '2fv':
  16121. _gl.uniform2fv( location, value );
  16122. break;
  16123. case '3fv':
  16124. _gl.uniform3fv( location, value );
  16125. break;
  16126. case '4fv':
  16127. _gl.uniform4fv( location, value );
  16128. break;
  16129. case 'Matrix2fv':
  16130. _gl.uniformMatrix2fv( location, false, value );
  16131. break;
  16132. case 'Matrix3fv':
  16133. _gl.uniformMatrix3fv( location, false, value );
  16134. break;
  16135. case 'Matrix4fv':
  16136. _gl.uniformMatrix4fv( location, false, value );
  16137. break;
  16138. //
  16139. case 'i':
  16140. // single integer
  16141. _gl.uniform1i( location, value );
  16142. break;
  16143. case 'f':
  16144. // single float
  16145. _gl.uniform1f( location, value );
  16146. break;
  16147. case 'v2':
  16148. // single THREE.Vector2
  16149. _gl.uniform2f( location, value.x, value.y );
  16150. break;
  16151. case 'v3':
  16152. // single THREE.Vector3
  16153. _gl.uniform3f( location, value.x, value.y, value.z );
  16154. break;
  16155. case 'v4':
  16156. // single THREE.Vector4
  16157. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  16158. break;
  16159. case 'c':
  16160. // single THREE.Color
  16161. _gl.uniform3f( location, value.r, value.g, value.b );
  16162. break;
  16163. /*
  16164. case 's':
  16165. // TODO: Optimize this.
  16166. for( var propertyName in uniform.properties ) {
  16167. var property = uniform.properties[ propertyName ];
  16168. var locationProperty = location[ propertyName ];
  16169. var valueProperty = value[ propertyName ];
  16170. switch( property.type ) {
  16171. case 'i':
  16172. _gl.uniform1i( locationProperty, valueProperty );
  16173. break;
  16174. case 'f':
  16175. _gl.uniform1f( locationProperty, valueProperty );
  16176. break;
  16177. case 'v2':
  16178. _gl.uniform2f( locationProperty, valueProperty.x, valueProperty.y );
  16179. break;
  16180. case 'v3':
  16181. _gl.uniform3f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z );
  16182. break;
  16183. case 'v4':
  16184. _gl.uniform4f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z, valueProperty.w );
  16185. break;
  16186. case 'c':
  16187. _gl.uniform3f( locationProperty, valueProperty.r, valueProperty.g, valueProperty.b );
  16188. break;
  16189. };
  16190. }
  16191. break;
  16192. */
  16193. case 'sa':
  16194. // TODO: Optimize this.
  16195. for ( var i = 0; i < value.length; i ++ ) {
  16196. for ( var propertyName in uniform.properties ) {
  16197. var property = uniform.properties[ propertyName ];
  16198. var locationProperty = location[ i ][ propertyName ];
  16199. var valueProperty = value[ i ][ propertyName ];
  16200. switch ( property.type ) {
  16201. case 'i':
  16202. _gl.uniform1i( locationProperty, valueProperty );
  16203. break;
  16204. case 'f':
  16205. _gl.uniform1f( locationProperty, valueProperty );
  16206. break;
  16207. case 'v2':
  16208. _gl.uniform2f( locationProperty, valueProperty.x, valueProperty.y );
  16209. break;
  16210. case 'v3':
  16211. _gl.uniform3f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z );
  16212. break;
  16213. case 'v4':
  16214. _gl.uniform4f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z, valueProperty.w );
  16215. break;
  16216. case 'c':
  16217. _gl.uniform3f( locationProperty, valueProperty.r, valueProperty.g, valueProperty.b );
  16218. break;
  16219. case 'm4':
  16220. _gl.uniformMatrix4fv( locationProperty, false, valueProperty.elements );
  16221. break;
  16222. }
  16223. }
  16224. }
  16225. break;
  16226. case 'iv1':
  16227. // flat array of integers (JS or typed array)
  16228. _gl.uniform1iv( location, value );
  16229. break;
  16230. case 'iv':
  16231. // flat array of integers with 3 x N size (JS or typed array)
  16232. _gl.uniform3iv( location, value );
  16233. break;
  16234. case 'fv1':
  16235. // flat array of floats (JS or typed array)
  16236. _gl.uniform1fv( location, value );
  16237. break;
  16238. case 'fv':
  16239. // flat array of floats with 3 x N size (JS or typed array)
  16240. _gl.uniform3fv( location, value );
  16241. break;
  16242. case 'v2v':
  16243. // array of THREE.Vector2
  16244. if ( uniform._array === undefined ) {
  16245. uniform._array = new Float32Array( 2 * value.length );
  16246. }
  16247. for ( var i = 0, i2 = 0, il = value.length; i < il; i ++, i2 += 2 ) {
  16248. uniform._array[ i2 + 0 ] = value[ i ].x;
  16249. uniform._array[ i2 + 1 ] = value[ i ].y;
  16250. }
  16251. _gl.uniform2fv( location, uniform._array );
  16252. break;
  16253. case 'v3v':
  16254. // array of THREE.Vector3
  16255. if ( uniform._array === undefined ) {
  16256. uniform._array = new Float32Array( 3 * value.length );
  16257. }
  16258. for ( var i = 0, i3 = 0, il = value.length; i < il; i ++, i3 += 3 ) {
  16259. uniform._array[ i3 + 0 ] = value[ i ].x;
  16260. uniform._array[ i3 + 1 ] = value[ i ].y;
  16261. uniform._array[ i3 + 2 ] = value[ i ].z;
  16262. }
  16263. _gl.uniform3fv( location, uniform._array );
  16264. break;
  16265. case 'v4v':
  16266. // array of THREE.Vector4
  16267. if ( uniform._array === undefined ) {
  16268. uniform._array = new Float32Array( 4 * value.length );
  16269. }
  16270. for ( var i = 0, i4 = 0, il = value.length; i < il; i ++, i4 += 4 ) {
  16271. uniform._array[ i4 + 0 ] = value[ i ].x;
  16272. uniform._array[ i4 + 1 ] = value[ i ].y;
  16273. uniform._array[ i4 + 2 ] = value[ i ].z;
  16274. uniform._array[ i4 + 3 ] = value[ i ].w;
  16275. }
  16276. _gl.uniform4fv( location, uniform._array );
  16277. break;
  16278. case 'm2':
  16279. // single THREE.Matrix2
  16280. _gl.uniformMatrix2fv( location, false, value.elements );
  16281. break;
  16282. case 'm3':
  16283. // single THREE.Matrix3
  16284. _gl.uniformMatrix3fv( location, false, value.elements );
  16285. break;
  16286. case 'm3v':
  16287. // array of THREE.Matrix3
  16288. if ( uniform._array === undefined ) {
  16289. uniform._array = new Float32Array( 9 * value.length );
  16290. }
  16291. for ( var i = 0, il = value.length; i < il; i ++ ) {
  16292. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  16293. }
  16294. _gl.uniformMatrix3fv( location, false, uniform._array );
  16295. break;
  16296. case 'm4':
  16297. // single THREE.Matrix4
  16298. _gl.uniformMatrix4fv( location, false, value.elements );
  16299. break;
  16300. case 'm4v':
  16301. // array of THREE.Matrix4
  16302. if ( uniform._array === undefined ) {
  16303. uniform._array = new Float32Array( 16 * value.length );
  16304. }
  16305. for ( var i = 0, il = value.length; i < il; i ++ ) {
  16306. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  16307. }
  16308. _gl.uniformMatrix4fv( location, false, uniform._array );
  16309. break;
  16310. case 't':
  16311. // single THREE.Texture (2d or cube)
  16312. texture = value;
  16313. textureUnit = getTextureUnit();
  16314. _gl.uniform1i( location, textureUnit );
  16315. if ( ! texture ) continue;
  16316. if ( texture instanceof THREE.CubeTexture ||
  16317. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  16318. // CompressedTexture can have Array in image :/
  16319. setCubeTexture( texture, textureUnit );
  16320. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  16321. setCubeTextureDynamic( texture.texture, textureUnit );
  16322. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  16323. _this.setTexture( texture.texture, textureUnit );
  16324. } else {
  16325. _this.setTexture( texture, textureUnit );
  16326. }
  16327. break;
  16328. case 'tv':
  16329. // array of THREE.Texture (2d or cube)
  16330. if ( uniform._array === undefined ) {
  16331. uniform._array = [];
  16332. }
  16333. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  16334. uniform._array[ i ] = getTextureUnit();
  16335. }
  16336. _gl.uniform1iv( location, uniform._array );
  16337. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  16338. texture = uniform.value[ i ];
  16339. textureUnit = uniform._array[ i ];
  16340. if ( ! texture ) continue;
  16341. if ( texture instanceof THREE.CubeTexture ||
  16342. ( texture.image instanceof Array && texture.image.length === 6 ) ) {
  16343. // CompressedTexture can have Array in image :/
  16344. setCubeTexture( texture, textureUnit );
  16345. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  16346. _this.setTexture( texture.texture, textureUnit );
  16347. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  16348. setCubeTextureDynamic( texture.texture, textureUnit );
  16349. } else {
  16350. _this.setTexture( texture, textureUnit );
  16351. }
  16352. }
  16353. break;
  16354. default:
  16355. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  16356. }
  16357. }
  16358. }
  16359. function setupLights ( lights, camera ) {
  16360. var l, ll, light,
  16361. r = 0, g = 0, b = 0,
  16362. color,
  16363. intensity,
  16364. distance,
  16365. viewMatrix = camera.matrixWorldInverse,
  16366. directionalLength = 0,
  16367. pointLength = 0,
  16368. spotLength = 0,
  16369. hemiLength = 0,
  16370. shadowsLength = 0;
  16371. _lights.shadowsPointLight = 0;
  16372. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  16373. light = lights[ l ];
  16374. color = light.color;
  16375. intensity = light.intensity;
  16376. distance = light.distance;
  16377. if ( light instanceof THREE.AmbientLight ) {
  16378. r += color.r * intensity;
  16379. g += color.g * intensity;
  16380. b += color.b * intensity;
  16381. } else if ( light instanceof THREE.DirectionalLight ) {
  16382. var uniforms = lightCache.get( light );
  16383. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  16384. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16385. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  16386. uniforms.direction.sub( _vector3 );
  16387. uniforms.direction.transformDirection( viewMatrix );
  16388. uniforms.shadow = light.castShadow;
  16389. if ( light.castShadow ) {
  16390. uniforms.shadowBias = light.shadow.bias;
  16391. uniforms.shadowRadius = light.shadow.radius;
  16392. uniforms.shadowMapSize = light.shadow.mapSize;
  16393. _lights.shadows[ shadowsLength ++ ] = light;
  16394. }
  16395. _lights.directionalShadowMap[ directionalLength ] = light.shadow.map;
  16396. _lights.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  16397. _lights.directional[ directionalLength ++ ] = uniforms;
  16398. } else if ( light instanceof THREE.SpotLight ) {
  16399. var uniforms = lightCache.get( light );
  16400. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  16401. uniforms.position.applyMatrix4( viewMatrix );
  16402. uniforms.color.copy( color ).multiplyScalar( intensity );
  16403. uniforms.distance = distance;
  16404. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16405. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  16406. uniforms.direction.sub( _vector3 );
  16407. uniforms.direction.transformDirection( viewMatrix );
  16408. uniforms.coneCos = Math.cos( light.angle );
  16409. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  16410. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16411. uniforms.shadow = light.castShadow;
  16412. if ( light.castShadow ) {
  16413. uniforms.shadowBias = light.shadow.bias;
  16414. uniforms.shadowRadius = light.shadow.radius;
  16415. uniforms.shadowMapSize = light.shadow.mapSize;
  16416. _lights.shadows[ shadowsLength ++ ] = light;
  16417. }
  16418. _lights.spotShadowMap[ spotLength ] = light.shadow.map;
  16419. _lights.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  16420. _lights.spot[ spotLength ++ ] = uniforms;
  16421. } else if ( light instanceof THREE.PointLight ) {
  16422. var uniforms = lightCache.get( light );
  16423. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  16424. uniforms.position.applyMatrix4( viewMatrix );
  16425. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  16426. uniforms.distance = light.distance;
  16427. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16428. uniforms.shadow = light.castShadow;
  16429. if ( light.castShadow ) {
  16430. uniforms.shadowBias = light.shadow.bias;
  16431. uniforms.shadowRadius = light.shadow.radius;
  16432. uniforms.shadowMapSize = light.shadow.mapSize;
  16433. _lights.shadows[ shadowsLength ++ ] = light;
  16434. }
  16435. _lights.pointShadowMap[ pointLength ] = light.shadow.map;
  16436. if ( _lights.pointShadowMatrix[ pointLength ] === undefined ) {
  16437. _lights.pointShadowMatrix[ pointLength ] = new THREE.Matrix4();
  16438. }
  16439. // for point lights we set the shadow matrix to be a translation-only matrix
  16440. // equal to inverse of the light's position
  16441. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  16442. _lights.pointShadowMatrix[ pointLength ].identity().setPosition( _vector3 );
  16443. _lights.point[ pointLength ++ ] = uniforms;
  16444. } else if ( light instanceof THREE.HemisphereLight ) {
  16445. var uniforms = lightCache.get( light );
  16446. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16447. uniforms.direction.transformDirection( viewMatrix );
  16448. uniforms.direction.normalize();
  16449. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  16450. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  16451. _lights.hemi[ hemiLength ++ ] = uniforms;
  16452. }
  16453. }
  16454. _lights.ambient[ 0 ] = r;
  16455. _lights.ambient[ 1 ] = g;
  16456. _lights.ambient[ 2 ] = b;
  16457. _lights.directional.length = directionalLength;
  16458. _lights.spot.length = spotLength;
  16459. _lights.point.length = pointLength;
  16460. _lights.hemi.length = hemiLength;
  16461. _lights.shadows.length = shadowsLength;
  16462. _lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + hemiLength + ',' + shadowsLength;
  16463. }
  16464. // GL state setting
  16465. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  16466. if ( cullFace === THREE.CullFaceNone ) {
  16467. state.disable( _gl.CULL_FACE );
  16468. } else {
  16469. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  16470. _gl.frontFace( _gl.CW );
  16471. } else {
  16472. _gl.frontFace( _gl.CCW );
  16473. }
  16474. if ( cullFace === THREE.CullFaceBack ) {
  16475. _gl.cullFace( _gl.BACK );
  16476. } else if ( cullFace === THREE.CullFaceFront ) {
  16477. _gl.cullFace( _gl.FRONT );
  16478. } else {
  16479. _gl.cullFace( _gl.FRONT_AND_BACK );
  16480. }
  16481. state.enable( _gl.CULL_FACE );
  16482. }
  16483. };
  16484. // Textures
  16485. function setTextureParameters ( textureType, texture, isPowerOfTwoImage ) {
  16486. var extension;
  16487. if ( isPowerOfTwoImage ) {
  16488. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  16489. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  16490. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  16491. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  16492. } else {
  16493. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  16494. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  16495. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  16496. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  16497. }
  16498. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  16499. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  16500. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  16501. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  16502. }
  16503. }
  16504. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  16505. if ( extension ) {
  16506. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  16507. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  16508. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  16509. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  16510. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  16511. }
  16512. }
  16513. }
  16514. function uploadTexture( textureProperties, texture, slot ) {
  16515. if ( textureProperties.__webglInit === undefined ) {
  16516. textureProperties.__webglInit = true;
  16517. texture.addEventListener( 'dispose', onTextureDispose );
  16518. textureProperties.__webglTexture = _gl.createTexture();
  16519. _infoMemory.textures ++;
  16520. }
  16521. state.activeTexture( _gl.TEXTURE0 + slot );
  16522. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16523. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16524. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  16525. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  16526. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  16527. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  16528. image = makePowerOfTwo( image );
  16529. }
  16530. var isPowerOfTwoImage = isPowerOfTwo( image ),
  16531. glFormat = paramThreeToGL( texture.format ),
  16532. glType = paramThreeToGL( texture.type );
  16533. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  16534. var mipmap, mipmaps = texture.mipmaps;
  16535. if ( texture instanceof THREE.DataTexture ) {
  16536. // use manually created mipmaps if available
  16537. // if there are no manual mipmaps
  16538. // set 0 level mipmap and then use GL to generate other mipmap levels
  16539. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  16540. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16541. mipmap = mipmaps[ i ];
  16542. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16543. }
  16544. texture.generateMipmaps = false;
  16545. } else {
  16546. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  16547. }
  16548. } else if ( texture instanceof THREE.CompressedTexture ) {
  16549. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16550. mipmap = mipmaps[ i ];
  16551. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16552. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16553. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16554. } else {
  16555. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  16556. }
  16557. } else {
  16558. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16559. }
  16560. }
  16561. } else {
  16562. // regular Texture (image, video, canvas)
  16563. // use manually created mipmaps if available
  16564. // if there are no manual mipmaps
  16565. // set 0 level mipmap and then use GL to generate other mipmap levels
  16566. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  16567. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16568. mipmap = mipmaps[ i ];
  16569. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  16570. }
  16571. texture.generateMipmaps = false;
  16572. } else {
  16573. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  16574. }
  16575. }
  16576. if ( texture.generateMipmaps && isPowerOfTwoImage ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16577. textureProperties.__version = texture.version;
  16578. if ( texture.onUpdate ) texture.onUpdate( texture );
  16579. }
  16580. this.setTexture = function ( texture, slot ) {
  16581. var textureProperties = properties.get( texture );
  16582. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16583. var image = texture.image;
  16584. if ( image === undefined ) {
  16585. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  16586. return;
  16587. }
  16588. if ( image.complete === false ) {
  16589. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  16590. return;
  16591. }
  16592. uploadTexture( textureProperties, texture, slot );
  16593. return;
  16594. }
  16595. state.activeTexture( _gl.TEXTURE0 + slot );
  16596. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16597. };
  16598. function clampToMaxSize ( image, maxSize ) {
  16599. if ( image.width > maxSize || image.height > maxSize ) {
  16600. // Warning: Scaling through the canvas will only work with images that use
  16601. // premultiplied alpha.
  16602. var scale = maxSize / Math.max( image.width, image.height );
  16603. var canvas = document.createElement( 'canvas' );
  16604. canvas.width = Math.floor( image.width * scale );
  16605. canvas.height = Math.floor( image.height * scale );
  16606. var context = canvas.getContext( '2d' );
  16607. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  16608. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16609. return canvas;
  16610. }
  16611. return image;
  16612. }
  16613. function isPowerOfTwo( image ) {
  16614. return THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height );
  16615. }
  16616. function textureNeedsPowerOfTwo( texture ) {
  16617. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) return true;
  16618. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) return true;
  16619. return false;
  16620. }
  16621. function makePowerOfTwo( image ) {
  16622. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  16623. var canvas = document.createElement( 'canvas' );
  16624. canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
  16625. canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
  16626. var context = canvas.getContext( '2d' );
  16627. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  16628. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16629. return canvas;
  16630. }
  16631. return image;
  16632. }
  16633. function setCubeTexture ( texture, slot ) {
  16634. var textureProperties = properties.get( texture );
  16635. if ( texture.image.length === 6 ) {
  16636. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16637. if ( ! textureProperties.__image__webglTextureCube ) {
  16638. texture.addEventListener( 'dispose', onTextureDispose );
  16639. textureProperties.__image__webglTextureCube = _gl.createTexture();
  16640. _infoMemory.textures ++;
  16641. }
  16642. state.activeTexture( _gl.TEXTURE0 + slot );
  16643. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16644. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16645. var isCompressed = texture instanceof THREE.CompressedTexture;
  16646. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  16647. var cubeImage = [];
  16648. for ( var i = 0; i < 6; i ++ ) {
  16649. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  16650. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  16651. } else {
  16652. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  16653. }
  16654. }
  16655. var image = cubeImage[ 0 ],
  16656. isPowerOfTwoImage = isPowerOfTwo( image ),
  16657. glFormat = paramThreeToGL( texture.format ),
  16658. glType = paramThreeToGL( texture.type );
  16659. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  16660. for ( var i = 0; i < 6; i ++ ) {
  16661. if ( ! isCompressed ) {
  16662. if ( isDataTexture ) {
  16663. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  16664. } else {
  16665. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  16666. }
  16667. } else {
  16668. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  16669. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  16670. mipmap = mipmaps[ j ];
  16671. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16672. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16673. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16674. } else {
  16675. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  16676. }
  16677. } else {
  16678. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16679. }
  16680. }
  16681. }
  16682. }
  16683. if ( texture.generateMipmaps && isPowerOfTwoImage ) {
  16684. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16685. }
  16686. textureProperties.__version = texture.version;
  16687. if ( texture.onUpdate ) texture.onUpdate( texture );
  16688. } else {
  16689. state.activeTexture( _gl.TEXTURE0 + slot );
  16690. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16691. }
  16692. }
  16693. }
  16694. function setCubeTextureDynamic ( texture, slot ) {
  16695. state.activeTexture( _gl.TEXTURE0 + slot );
  16696. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  16697. }
  16698. // Render targets
  16699. // Setup storage for target texture and bind it to correct framebuffer
  16700. function setupFrameBufferTexture ( framebuffer, renderTarget, attachment, textureTarget ) {
  16701. var glFormat = paramThreeToGL( renderTarget.texture.format );
  16702. var glType = paramThreeToGL( renderTarget.texture.type );
  16703. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  16704. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16705. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  16706. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16707. }
  16708. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  16709. function setupRenderBufferStorage ( renderbuffer, renderTarget ) {
  16710. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  16711. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  16712. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  16713. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16714. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  16715. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  16716. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16717. } else {
  16718. // FIXME: We don't support !depth !stencil
  16719. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  16720. }
  16721. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  16722. }
  16723. // Setup GL resources for a non-texture depth buffer
  16724. function setupDepthRenderbuffer( renderTarget ) {
  16725. var renderTargetProperties = properties.get( renderTarget );
  16726. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16727. if ( isCube ) {
  16728. renderTargetProperties.__webglDepthbuffer = [];
  16729. for ( var i = 0; i < 6; i ++ ) {
  16730. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  16731. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  16732. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  16733. }
  16734. } else {
  16735. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  16736. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  16737. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  16738. }
  16739. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16740. }
  16741. // Set up GL resources for the render target
  16742. function setupRenderTarget( renderTarget ) {
  16743. var renderTargetProperties = properties.get( renderTarget );
  16744. var textureProperties = properties.get( renderTarget.texture );
  16745. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  16746. textureProperties.__webglTexture = _gl.createTexture();
  16747. _infoMemory.textures ++;
  16748. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16749. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height );
  16750. // Setup framebuffer
  16751. if ( isCube ) {
  16752. renderTargetProperties.__webglFramebuffer = [];
  16753. for ( var i = 0; i < 6; i ++ ) {
  16754. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  16755. }
  16756. } else {
  16757. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  16758. }
  16759. // Setup color buffer
  16760. if ( isCube ) {
  16761. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  16762. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  16763. for ( var i = 0; i < 6; i ++ ) {
  16764. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  16765. }
  16766. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16767. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  16768. } else {
  16769. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16770. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  16771. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  16772. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16773. state.bindTexture( _gl.TEXTURE_2D, null );
  16774. }
  16775. // Setup depth and stencil buffers
  16776. if ( renderTarget.depthBuffer ) {
  16777. setupDepthRenderbuffer( renderTarget );
  16778. }
  16779. }
  16780. this.setRenderTarget = function ( renderTarget ) {
  16781. _currentRenderTarget = renderTarget;
  16782. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  16783. setupRenderTarget( renderTarget );
  16784. }
  16785. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16786. var framebuffer;
  16787. if ( renderTarget ) {
  16788. var renderTargetProperties = properties.get( renderTarget );
  16789. if ( isCube ) {
  16790. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  16791. } else {
  16792. framebuffer = renderTargetProperties.__webglFramebuffer;
  16793. }
  16794. _currentScissor.copy( renderTarget.scissor );
  16795. _currentScissorTest = renderTarget.scissorTest;
  16796. _currentViewport.copy( renderTarget.viewport );
  16797. } else {
  16798. framebuffer = null;
  16799. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  16800. _currentScissorTest = _scissorTest;
  16801. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  16802. }
  16803. if ( _currentFramebuffer !== framebuffer ) {
  16804. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16805. _currentFramebuffer = framebuffer;
  16806. }
  16807. state.scissor( _currentScissor );
  16808. state.setScissorTest( _currentScissorTest );
  16809. state.viewport( _currentViewport );
  16810. if ( isCube ) {
  16811. var textureProperties = properties.get( renderTarget.texture );
  16812. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, 0 );
  16813. }
  16814. };
  16815. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  16816. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  16817. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  16818. return;
  16819. }
  16820. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16821. if ( framebuffer ) {
  16822. var restore = false;
  16823. if ( framebuffer !== _currentFramebuffer ) {
  16824. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16825. restore = true;
  16826. }
  16827. try {
  16828. var texture = renderTarget.texture;
  16829. if ( texture.format !== THREE.RGBAFormat
  16830. && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  16831. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  16832. return;
  16833. }
  16834. if ( texture.type !== THREE.UnsignedByteType
  16835. && paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE )
  16836. && ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) )
  16837. && ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  16838. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  16839. return;
  16840. }
  16841. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  16842. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  16843. } else {
  16844. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  16845. }
  16846. } finally {
  16847. if ( restore ) {
  16848. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  16849. }
  16850. }
  16851. }
  16852. };
  16853. function updateRenderTargetMipmap( renderTarget ) {
  16854. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  16855. var texture = properties.get( renderTarget.texture ).__webglTexture;
  16856. state.bindTexture( target, texture );
  16857. _gl.generateMipmap( target );
  16858. state.bindTexture( target, null );
  16859. }
  16860. // Fallback filters for non-power-of-2 textures
  16861. function filterFallback ( f ) {
  16862. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  16863. return _gl.NEAREST;
  16864. }
  16865. return _gl.LINEAR;
  16866. }
  16867. // Map three.js constants to WebGL constants
  16868. function paramThreeToGL ( p ) {
  16869. var extension;
  16870. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  16871. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  16872. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  16873. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  16874. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  16875. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  16876. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  16877. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  16878. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  16879. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  16880. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  16881. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  16882. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  16883. if ( p === THREE.ByteType ) return _gl.BYTE;
  16884. if ( p === THREE.ShortType ) return _gl.SHORT;
  16885. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  16886. if ( p === THREE.IntType ) return _gl.INT;
  16887. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  16888. if ( p === THREE.FloatType ) return _gl.FLOAT;
  16889. extension = extensions.get( 'OES_texture_half_float' );
  16890. if ( extension !== null ) {
  16891. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  16892. }
  16893. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  16894. if ( p === THREE.RGBFormat ) return _gl.RGB;
  16895. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  16896. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  16897. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  16898. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  16899. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  16900. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  16901. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  16902. if ( p === THREE.OneFactor ) return _gl.ONE;
  16903. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  16904. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  16905. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  16906. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  16907. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  16908. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  16909. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  16910. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  16911. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  16912. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  16913. if ( extension !== null ) {
  16914. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  16915. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  16916. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  16917. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  16918. }
  16919. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  16920. if ( extension !== null ) {
  16921. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  16922. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  16923. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  16924. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  16925. }
  16926. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  16927. if ( extension !== null ) {
  16928. if ( p === THREE.RGB_ETC1_Format ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  16929. }
  16930. extension = extensions.get( 'EXT_blend_minmax' );
  16931. if ( extension !== null ) {
  16932. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  16933. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  16934. }
  16935. return 0;
  16936. }
  16937. };
  16938. // File:src/renderers/WebGLRenderTarget.js
  16939. /**
  16940. * @author szimek / https://github.com/szimek/
  16941. * @author alteredq / http://alteredqualia.com/
  16942. * @author Marius Kintel / https://github.com/kintel
  16943. */
  16944. /*
  16945. In options, we can specify:
  16946. * Texture parameters for an auto-generated target texture
  16947. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  16948. */
  16949. THREE.WebGLRenderTarget = function ( width, height, options ) {
  16950. this.uuid = THREE.Math.generateUUID();
  16951. this.width = width;
  16952. this.height = height;
  16953. this.scissor = new THREE.Vector4( 0, 0, width, height );
  16954. this.scissorTest = false;
  16955. this.viewport = new THREE.Vector4( 0, 0, width, height );
  16956. options = options || {};
  16957. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  16958. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy );
  16959. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  16960. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  16961. };
  16962. THREE.WebGLRenderTarget.prototype = {
  16963. constructor: THREE.WebGLRenderTarget,
  16964. setSize: function ( width, height ) {
  16965. if ( this.width !== width || this.height !== height ) {
  16966. this.width = width;
  16967. this.height = height;
  16968. this.dispose();
  16969. }
  16970. this.viewport.set( 0, 0, width, height );
  16971. this.scissor.set( 0, 0, width, height );
  16972. },
  16973. clone: function () {
  16974. return new this.constructor().copy( this );
  16975. },
  16976. copy: function ( source ) {
  16977. this.width = source.width;
  16978. this.height = source.height;
  16979. this.viewport.copy( source.viewport );
  16980. this.texture = source.texture.clone();
  16981. this.depthBuffer = source.depthBuffer;
  16982. this.stencilBuffer = source.stencilBuffer;
  16983. this.shareDepthFrom = source.shareDepthFrom;
  16984. return this;
  16985. },
  16986. dispose: function () {
  16987. this.dispatchEvent( { type: 'dispose' } );
  16988. }
  16989. };
  16990. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  16991. // File:src/renderers/WebGLRenderTargetCube.js
  16992. /**
  16993. * @author alteredq / http://alteredqualia.com
  16994. */
  16995. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  16996. THREE.WebGLRenderTarget.call( this, width, height, options );
  16997. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  16998. };
  16999. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  17000. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  17001. // File:src/renderers/webgl/WebGLBufferRenderer.js
  17002. /**
  17003. * @author mrdoob / http://mrdoob.com/
  17004. */
  17005. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  17006. var mode;
  17007. function setMode( value ) {
  17008. mode = value;
  17009. }
  17010. function render( start, count ) {
  17011. _gl.drawArrays( mode, start, count );
  17012. _infoRender.calls ++;
  17013. _infoRender.vertices += count;
  17014. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  17015. }
  17016. function renderInstances( geometry ) {
  17017. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  17018. if ( extension === null ) {
  17019. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  17020. return;
  17021. }
  17022. var position = geometry.attributes.position;
  17023. var count = 0;
  17024. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  17025. count = position.data.count;
  17026. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  17027. } else {
  17028. count = position.count;
  17029. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  17030. }
  17031. _infoRender.calls ++;
  17032. _infoRender.vertices += count * geometry.maxInstancedCount;
  17033. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  17034. }
  17035. this.setMode = setMode;
  17036. this.render = render;
  17037. this.renderInstances = renderInstances;
  17038. };
  17039. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  17040. /**
  17041. * @author mrdoob / http://mrdoob.com/
  17042. */
  17043. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  17044. var mode;
  17045. function setMode( value ) {
  17046. mode = value;
  17047. }
  17048. var type, size;
  17049. function setIndex( index ) {
  17050. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  17051. type = _gl.UNSIGNED_INT;
  17052. size = 4;
  17053. } else {
  17054. type = _gl.UNSIGNED_SHORT;
  17055. size = 2;
  17056. }
  17057. }
  17058. function render( start, count ) {
  17059. _gl.drawElements( mode, count, type, start * size );
  17060. _infoRender.calls ++;
  17061. _infoRender.vertices += count;
  17062. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  17063. }
  17064. function renderInstances( geometry, start, count ) {
  17065. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  17066. if ( extension === null ) {
  17067. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  17068. return;
  17069. }
  17070. extension.drawElementsInstancedANGLE( mode, count, type, start * size, geometry.maxInstancedCount );
  17071. _infoRender.calls ++;
  17072. _infoRender.vertices += count * geometry.maxInstancedCount;
  17073. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  17074. }
  17075. this.setMode = setMode;
  17076. this.setIndex = setIndex;
  17077. this.render = render;
  17078. this.renderInstances = renderInstances;
  17079. };
  17080. // File:src/renderers/webgl/WebGLExtensions.js
  17081. /**
  17082. * @author mrdoob / http://mrdoob.com/
  17083. */
  17084. THREE.WebGLExtensions = function ( gl ) {
  17085. var extensions = {};
  17086. this.get = function ( name ) {
  17087. if ( extensions[ name ] !== undefined ) {
  17088. return extensions[ name ];
  17089. }
  17090. var extension;
  17091. switch ( name ) {
  17092. case 'EXT_texture_filter_anisotropic':
  17093. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  17094. break;
  17095. case 'WEBGL_compressed_texture_s3tc':
  17096. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  17097. break;
  17098. case 'WEBGL_compressed_texture_pvrtc':
  17099. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  17100. break;
  17101. case 'WEBGL_compressed_texture_etc1':
  17102. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  17103. break;
  17104. default:
  17105. extension = gl.getExtension( name );
  17106. }
  17107. if ( extension === null ) {
  17108. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  17109. }
  17110. extensions[ name ] = extension;
  17111. return extension;
  17112. };
  17113. };
  17114. // File:src/renderers/webgl/WebGLCapabilities.js
  17115. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  17116. function getMaxPrecision( precision ) {
  17117. if ( precision === 'highp' ) {
  17118. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  17119. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  17120. return 'highp';
  17121. }
  17122. precision = 'mediump';
  17123. }
  17124. if ( precision === 'mediump' ) {
  17125. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  17126. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  17127. return 'mediump';
  17128. }
  17129. }
  17130. return 'lowp';
  17131. }
  17132. this.getMaxPrecision = getMaxPrecision;
  17133. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  17134. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  17135. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  17136. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  17137. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  17138. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  17139. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  17140. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  17141. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  17142. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  17143. this.vertexTextures = this.maxVertexTextures > 0;
  17144. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  17145. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  17146. var _maxPrecision = getMaxPrecision( this.precision );
  17147. if ( _maxPrecision !== this.precision ) {
  17148. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  17149. this.precision = _maxPrecision;
  17150. }
  17151. if ( this.logarithmicDepthBuffer ) {
  17152. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  17153. }
  17154. };
  17155. // File:src/renderers/webgl/WebGLGeometries.js
  17156. /**
  17157. * @author mrdoob / http://mrdoob.com/
  17158. */
  17159. THREE.WebGLGeometries = function ( gl, properties, info ) {
  17160. var geometries = {};
  17161. function get( object ) {
  17162. var geometry = object.geometry;
  17163. if ( geometries[ geometry.id ] !== undefined ) {
  17164. return geometries[ geometry.id ];
  17165. }
  17166. geometry.addEventListener( 'dispose', onGeometryDispose );
  17167. var buffergeometry;
  17168. if ( geometry instanceof THREE.BufferGeometry ) {
  17169. buffergeometry = geometry;
  17170. } else if ( geometry instanceof THREE.Geometry ) {
  17171. if ( geometry._bufferGeometry === undefined ) {
  17172. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  17173. }
  17174. buffergeometry = geometry._bufferGeometry;
  17175. }
  17176. geometries[ geometry.id ] = buffergeometry;
  17177. info.memory.geometries ++;
  17178. return buffergeometry;
  17179. }
  17180. function onGeometryDispose( event ) {
  17181. var geometry = event.target;
  17182. var buffergeometry = geometries[ geometry.id ];
  17183. if ( buffergeometry.index !== null ) {
  17184. deleteAttribute( buffergeometry.index );
  17185. }
  17186. deleteAttributes( buffergeometry.attributes );
  17187. geometry.removeEventListener( 'dispose', onGeometryDispose );
  17188. delete geometries[ geometry.id ];
  17189. // TODO
  17190. var property = properties.get( geometry );
  17191. if ( property.wireframe ) {
  17192. deleteAttribute( property.wireframe );
  17193. }
  17194. properties.delete( geometry );
  17195. var bufferproperty = properties.get( buffergeometry );
  17196. if ( bufferproperty.wireframe ) {
  17197. deleteAttribute( bufferproperty.wireframe );
  17198. }
  17199. properties.delete( buffergeometry );
  17200. //
  17201. info.memory.geometries --;
  17202. }
  17203. function getAttributeBuffer( attribute ) {
  17204. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  17205. return properties.get( attribute.data ).__webglBuffer;
  17206. }
  17207. return properties.get( attribute ).__webglBuffer;
  17208. }
  17209. function deleteAttribute( attribute ) {
  17210. var buffer = getAttributeBuffer( attribute );
  17211. if ( buffer !== undefined ) {
  17212. gl.deleteBuffer( buffer );
  17213. removeAttributeBuffer( attribute );
  17214. }
  17215. }
  17216. function deleteAttributes( attributes ) {
  17217. for ( var name in attributes ) {
  17218. deleteAttribute( attributes[ name ] );
  17219. }
  17220. }
  17221. function removeAttributeBuffer( attribute ) {
  17222. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  17223. properties.delete( attribute.data );
  17224. } else {
  17225. properties.delete( attribute );
  17226. }
  17227. }
  17228. this.get = get;
  17229. };
  17230. // File:src/renderers/webgl/WebGLLights.js
  17231. /**
  17232. * @author mrdoob / http://mrdoob.com/
  17233. */
  17234. THREE.WebGLLights = function () {
  17235. var lights = {};
  17236. this.get = function ( light ) {
  17237. if ( lights[ light.id ] !== undefined ) {
  17238. return lights[ light.id ];
  17239. }
  17240. var uniforms;
  17241. switch ( light.type ) {
  17242. case 'DirectionalLight':
  17243. uniforms = {
  17244. direction: new THREE.Vector3(),
  17245. color: new THREE.Color(),
  17246. shadow: false,
  17247. shadowBias: 0,
  17248. shadowRadius: 1,
  17249. shadowMapSize: new THREE.Vector2()
  17250. };
  17251. break;
  17252. case 'SpotLight':
  17253. uniforms = {
  17254. position: new THREE.Vector3(),
  17255. direction: new THREE.Vector3(),
  17256. color: new THREE.Color(),
  17257. distance: 0,
  17258. coneCos: 0,
  17259. penumbraCos: 0,
  17260. decay: 0,
  17261. shadow: false,
  17262. shadowBias: 0,
  17263. shadowRadius: 1,
  17264. shadowMapSize: new THREE.Vector2()
  17265. };
  17266. break;
  17267. case 'PointLight':
  17268. uniforms = {
  17269. position: new THREE.Vector3(),
  17270. color: new THREE.Color(),
  17271. distance: 0,
  17272. decay: 0,
  17273. shadow: false,
  17274. shadowBias: 0,
  17275. shadowRadius: 1,
  17276. shadowMapSize: new THREE.Vector2()
  17277. };
  17278. break;
  17279. case 'HemisphereLight':
  17280. uniforms = {
  17281. direction: new THREE.Vector3(),
  17282. skyColor: new THREE.Color(),
  17283. groundColor: new THREE.Color()
  17284. };
  17285. break;
  17286. }
  17287. lights[ light.id ] = uniforms;
  17288. return uniforms;
  17289. };
  17290. };
  17291. // File:src/renderers/webgl/WebGLObjects.js
  17292. /**
  17293. * @author mrdoob / http://mrdoob.com/
  17294. */
  17295. THREE.WebGLObjects = function ( gl, properties, info ) {
  17296. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  17297. //
  17298. function update( object ) {
  17299. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  17300. var geometry = geometries.get( object );
  17301. if ( object.geometry instanceof THREE.Geometry ) {
  17302. geometry.updateFromObject( object );
  17303. }
  17304. var index = geometry.index;
  17305. var attributes = geometry.attributes;
  17306. if ( index !== null ) {
  17307. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  17308. }
  17309. for ( var name in attributes ) {
  17310. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  17311. }
  17312. // morph targets
  17313. var morphAttributes = geometry.morphAttributes;
  17314. for ( var name in morphAttributes ) {
  17315. var array = morphAttributes[ name ];
  17316. for ( var i = 0, l = array.length; i < l; i ++ ) {
  17317. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  17318. }
  17319. }
  17320. return geometry;
  17321. }
  17322. function updateAttribute( attribute, bufferType ) {
  17323. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  17324. var attributeProperties = properties.get( data );
  17325. if ( attributeProperties.__webglBuffer === undefined ) {
  17326. createBuffer( attributeProperties, data, bufferType );
  17327. } else if ( attributeProperties.version !== data.version ) {
  17328. updateBuffer( attributeProperties, data, bufferType );
  17329. }
  17330. }
  17331. function createBuffer( attributeProperties, data, bufferType ) {
  17332. attributeProperties.__webglBuffer = gl.createBuffer();
  17333. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  17334. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  17335. gl.bufferData( bufferType, data.array, usage );
  17336. attributeProperties.version = data.version;
  17337. }
  17338. function updateBuffer( attributeProperties, data, bufferType ) {
  17339. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  17340. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  17341. // Not using update ranges
  17342. gl.bufferSubData( bufferType, 0, data.array );
  17343. } else if ( data.updateRange.count === 0 ) {
  17344. 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.' );
  17345. } else {
  17346. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  17347. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  17348. data.updateRange.count = 0; // reset range
  17349. }
  17350. attributeProperties.version = data.version;
  17351. }
  17352. function getAttributeBuffer( attribute ) {
  17353. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  17354. return properties.get( attribute.data ).__webglBuffer;
  17355. }
  17356. return properties.get( attribute ).__webglBuffer;
  17357. }
  17358. function getWireframeAttribute( geometry ) {
  17359. var property = properties.get( geometry );
  17360. if ( property.wireframe !== undefined ) {
  17361. return property.wireframe;
  17362. }
  17363. var indices = [];
  17364. var index = geometry.index;
  17365. var attributes = geometry.attributes;
  17366. var position = attributes.position;
  17367. // console.time( 'wireframe' );
  17368. if ( index !== null ) {
  17369. var edges = {};
  17370. var array = index.array;
  17371. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  17372. var a = array[ i + 0 ];
  17373. var b = array[ i + 1 ];
  17374. var c = array[ i + 2 ];
  17375. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  17376. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  17377. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  17378. }
  17379. } else {
  17380. var array = attributes.position.array;
  17381. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  17382. var a = i + 0;
  17383. var b = i + 1;
  17384. var c = i + 2;
  17385. indices.push( a, b, b, c, c, a );
  17386. }
  17387. }
  17388. // console.timeEnd( 'wireframe' );
  17389. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  17390. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  17391. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  17392. property.wireframe = attribute;
  17393. return attribute;
  17394. }
  17395. function checkEdge( edges, a, b ) {
  17396. if ( a > b ) {
  17397. var tmp = a;
  17398. a = b;
  17399. b = tmp;
  17400. }
  17401. var list = edges[ a ];
  17402. if ( list === undefined ) {
  17403. edges[ a ] = [ b ];
  17404. return true;
  17405. } else if ( list.indexOf( b ) === -1 ) {
  17406. list.push( b );
  17407. return true;
  17408. }
  17409. return false;
  17410. }
  17411. this.getAttributeBuffer = getAttributeBuffer;
  17412. this.getWireframeAttribute = getWireframeAttribute;
  17413. this.update = update;
  17414. };
  17415. // File:src/renderers/webgl/WebGLProgram.js
  17416. THREE.WebGLProgram = ( function () {
  17417. var programIdCount = 0;
  17418. // TODO: Combine the regex
  17419. var structRe = /^([\w\d_]+)\.([\w\d_]+)$/;
  17420. var arrayStructRe = /^([\w\d_]+)\[(\d+)\]\.([\w\d_]+)$/;
  17421. var arrayRe = /^([\w\d_]+)\[0\]$/;
  17422. function generateExtensions( extensions, parameters, rendererExtensions ) {
  17423. extensions = extensions || {};
  17424. var chunks = [
  17425. ( extensions.derivatives || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  17426. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  17427. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  17428. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : '',
  17429. ];
  17430. return chunks.filter( filterEmptyLine ).join( '\n' );
  17431. }
  17432. function generateDefines( defines ) {
  17433. var chunks = [];
  17434. for ( var name in defines ) {
  17435. var value = defines[ name ];
  17436. if ( value === false ) continue;
  17437. chunks.push( '#define ' + name + ' ' + value );
  17438. }
  17439. return chunks.join( '\n' );
  17440. }
  17441. function fetchUniformLocations( gl, program, identifiers ) {
  17442. var uniforms = {};
  17443. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  17444. for ( var i = 0; i < n; i ++ ) {
  17445. var info = gl.getActiveUniform( program, i );
  17446. var name = info.name;
  17447. var location = gl.getUniformLocation( program, name );
  17448. //console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  17449. var matches = structRe.exec( name );
  17450. if ( matches ) {
  17451. var structName = matches[ 1 ];
  17452. var structProperty = matches[ 2 ];
  17453. var uniformsStruct = uniforms[ structName ];
  17454. if ( ! uniformsStruct ) {
  17455. uniformsStruct = uniforms[ structName ] = {};
  17456. }
  17457. uniformsStruct[ structProperty ] = location;
  17458. continue;
  17459. }
  17460. matches = arrayStructRe.exec( name );
  17461. if ( matches ) {
  17462. var arrayName = matches[ 1 ];
  17463. var arrayIndex = matches[ 2 ];
  17464. var arrayProperty = matches[ 3 ];
  17465. var uniformsArray = uniforms[ arrayName ];
  17466. if ( ! uniformsArray ) {
  17467. uniformsArray = uniforms[ arrayName ] = [];
  17468. }
  17469. var uniformsArrayIndex = uniformsArray[ arrayIndex ];
  17470. if ( ! uniformsArrayIndex ) {
  17471. uniformsArrayIndex = uniformsArray[ arrayIndex ] = {};
  17472. }
  17473. uniformsArrayIndex[ arrayProperty ] = location;
  17474. continue;
  17475. }
  17476. matches = arrayRe.exec( name );
  17477. if ( matches ) {
  17478. var arrayName = matches[ 1 ];
  17479. uniforms[ arrayName ] = location;
  17480. continue;
  17481. }
  17482. uniforms[ name ] = location;
  17483. }
  17484. return uniforms;
  17485. }
  17486. function fetchAttributeLocations( gl, program, identifiers ) {
  17487. var attributes = {};
  17488. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  17489. for ( var i = 0; i < n; i ++ ) {
  17490. var info = gl.getActiveAttrib( program, i );
  17491. var name = info.name;
  17492. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  17493. attributes[ name ] = gl.getAttribLocation( program, name );
  17494. }
  17495. return attributes;
  17496. }
  17497. function filterEmptyLine( string ) {
  17498. return string !== '';
  17499. }
  17500. function replaceLightNums( string, parameters ) {
  17501. return string
  17502. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  17503. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  17504. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  17505. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  17506. }
  17507. function unrollLoops( string ) {
  17508. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  17509. function replace( match, start, end, snippet ) {
  17510. var unroll = '';
  17511. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  17512. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  17513. }
  17514. return unroll;
  17515. }
  17516. return string.replace( pattern, replace );
  17517. }
  17518. return function WebGLProgram( renderer, code, material, parameters ) {
  17519. var gl = renderer.context;
  17520. var extensions = material.extensions;
  17521. var defines = material.defines;
  17522. var vertexShader = material.__webglShader.vertexShader;
  17523. var fragmentShader = material.__webglShader.fragmentShader;
  17524. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  17525. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  17526. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  17527. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  17528. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  17529. }
  17530. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17531. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  17532. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17533. if ( parameters.envMap ) {
  17534. switch ( material.envMap.mapping ) {
  17535. case THREE.CubeReflectionMapping:
  17536. case THREE.CubeRefractionMapping:
  17537. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17538. break;
  17539. case THREE.EquirectangularReflectionMapping:
  17540. case THREE.EquirectangularRefractionMapping:
  17541. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  17542. break;
  17543. case THREE.SphericalReflectionMapping:
  17544. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  17545. break;
  17546. }
  17547. switch ( material.envMap.mapping ) {
  17548. case THREE.CubeRefractionMapping:
  17549. case THREE.EquirectangularRefractionMapping:
  17550. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  17551. break;
  17552. }
  17553. switch ( material.combine ) {
  17554. case THREE.MultiplyOperation:
  17555. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17556. break;
  17557. case THREE.MixOperation:
  17558. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  17559. break;
  17560. case THREE.AddOperation:
  17561. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  17562. break;
  17563. }
  17564. }
  17565. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  17566. // console.log( 'building new program ' );
  17567. //
  17568. var customExtensions = generateExtensions( extensions, parameters, renderer.extensions );
  17569. var customDefines = generateDefines( defines );
  17570. //
  17571. var program = gl.createProgram();
  17572. var prefixVertex, prefixFragment;
  17573. if ( material instanceof THREE.RawShaderMaterial ) {
  17574. prefixVertex = '';
  17575. prefixFragment = '';
  17576. } else {
  17577. prefixVertex = [
  17578. 'precision ' + parameters.precision + ' float;',
  17579. 'precision ' + parameters.precision + ' int;',
  17580. '#define SHADER_NAME ' + material.__webglShader.name,
  17581. customDefines,
  17582. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  17583. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  17584. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  17585. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17586. '#define MAX_BONES ' + parameters.maxBones,
  17587. parameters.map ? '#define USE_MAP' : '',
  17588. parameters.envMap ? '#define USE_ENVMAP' : '',
  17589. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17590. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17591. parameters.aoMap ? '#define USE_AOMAP' : '',
  17592. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17593. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17594. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17595. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  17596. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17597. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17598. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17599. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17600. parameters.vertexColors ? '#define USE_COLOR' : '',
  17601. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17602. parameters.skinning ? '#define USE_SKINNING' : '',
  17603. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  17604. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  17605. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  17606. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17607. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17608. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17609. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17610. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  17611. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  17612. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17613. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17614. 'uniform mat4 modelMatrix;',
  17615. 'uniform mat4 modelViewMatrix;',
  17616. 'uniform mat4 projectionMatrix;',
  17617. 'uniform mat4 viewMatrix;',
  17618. 'uniform mat3 normalMatrix;',
  17619. 'uniform vec3 cameraPosition;',
  17620. 'attribute vec3 position;',
  17621. 'attribute vec3 normal;',
  17622. 'attribute vec2 uv;',
  17623. '#ifdef USE_COLOR',
  17624. ' attribute vec3 color;',
  17625. '#endif',
  17626. '#ifdef USE_MORPHTARGETS',
  17627. ' attribute vec3 morphTarget0;',
  17628. ' attribute vec3 morphTarget1;',
  17629. ' attribute vec3 morphTarget2;',
  17630. ' attribute vec3 morphTarget3;',
  17631. ' #ifdef USE_MORPHNORMALS',
  17632. ' attribute vec3 morphNormal0;',
  17633. ' attribute vec3 morphNormal1;',
  17634. ' attribute vec3 morphNormal2;',
  17635. ' attribute vec3 morphNormal3;',
  17636. ' #else',
  17637. ' attribute vec3 morphTarget4;',
  17638. ' attribute vec3 morphTarget5;',
  17639. ' attribute vec3 morphTarget6;',
  17640. ' attribute vec3 morphTarget7;',
  17641. ' #endif',
  17642. '#endif',
  17643. '#ifdef USE_SKINNING',
  17644. ' attribute vec4 skinIndex;',
  17645. ' attribute vec4 skinWeight;',
  17646. '#endif',
  17647. '\n'
  17648. ].filter( filterEmptyLine ).join( '\n' );
  17649. prefixFragment = [
  17650. customExtensions,
  17651. 'precision ' + parameters.precision + ' float;',
  17652. 'precision ' + parameters.precision + ' int;',
  17653. '#define SHADER_NAME ' + material.__webglShader.name,
  17654. customDefines,
  17655. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  17656. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  17657. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  17658. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17659. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  17660. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  17661. parameters.map ? '#define USE_MAP' : '',
  17662. parameters.envMap ? '#define USE_ENVMAP' : '',
  17663. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  17664. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17665. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  17666. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17667. parameters.aoMap ? '#define USE_AOMAP' : '',
  17668. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17669. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17670. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17671. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17672. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17673. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17674. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17675. parameters.vertexColors ? '#define USE_COLOR' : '',
  17676. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17677. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17678. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17679. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17680. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17681. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  17682. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17683. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17684. parameters.envMap && renderer.extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  17685. 'uniform mat4 viewMatrix;',
  17686. 'uniform vec3 cameraPosition;',
  17687. '\n'
  17688. ].filter( filterEmptyLine ).join( '\n' );
  17689. }
  17690. vertexShader = replaceLightNums( vertexShader, parameters );
  17691. fragmentShader = replaceLightNums( fragmentShader, parameters );
  17692. if ( material instanceof THREE.ShaderMaterial === false ) {
  17693. vertexShader = unrollLoops( vertexShader );
  17694. fragmentShader = unrollLoops( fragmentShader );
  17695. }
  17696. var vertexGlsl = prefixVertex + vertexShader;
  17697. var fragmentGlsl = prefixFragment + fragmentShader;
  17698. // console.log( '*VERTEX*', vertexGlsl );
  17699. // console.log( '*FRAGMENT*', fragmentGlsl );
  17700. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  17701. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  17702. gl.attachShader( program, glVertexShader );
  17703. gl.attachShader( program, glFragmentShader );
  17704. // Force a particular attribute to index 0.
  17705. if ( material.index0AttributeName !== undefined ) {
  17706. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  17707. } else if ( parameters.morphTargets === true ) {
  17708. // programs with morphTargets displace position out of attribute 0
  17709. gl.bindAttribLocation( program, 0, 'position' );
  17710. }
  17711. gl.linkProgram( program );
  17712. var programLog = gl.getProgramInfoLog( program );
  17713. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  17714. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  17715. var runnable = true;
  17716. var haveDiagnostics = true;
  17717. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  17718. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  17719. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  17720. runnable = false;
  17721. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  17722. } else if ( programLog !== '' ) {
  17723. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  17724. } else if ( vertexLog === '' || fragmentLog === '' ) {
  17725. haveDiagnostics = false;
  17726. }
  17727. if ( haveDiagnostics ) {
  17728. this.diagnostics = {
  17729. runnable: runnable,
  17730. material: material,
  17731. programLog: programLog,
  17732. vertexShader: {
  17733. log: vertexLog,
  17734. prefix: prefixVertex
  17735. },
  17736. fragmentShader: {
  17737. log: fragmentLog,
  17738. prefix: prefixFragment
  17739. }
  17740. };
  17741. }
  17742. // clean up
  17743. gl.deleteShader( glVertexShader );
  17744. gl.deleteShader( glFragmentShader );
  17745. // set up caching for uniform locations
  17746. var cachedUniforms;
  17747. this.getUniforms = function() {
  17748. if ( cachedUniforms === undefined ) {
  17749. cachedUniforms = fetchUniformLocations( gl, program );
  17750. }
  17751. return cachedUniforms;
  17752. };
  17753. // set up caching for attribute locations
  17754. var cachedAttributes;
  17755. this.getAttributes = function() {
  17756. if ( cachedAttributes === undefined ) {
  17757. cachedAttributes = fetchAttributeLocations( gl, program );
  17758. }
  17759. return cachedAttributes;
  17760. };
  17761. // free resource
  17762. this.destroy = function() {
  17763. gl.deleteProgram( program );
  17764. this.program = undefined;
  17765. };
  17766. // DEPRECATED
  17767. Object.defineProperties( this, {
  17768. uniforms: {
  17769. get: function() {
  17770. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  17771. return this.getUniforms();
  17772. }
  17773. },
  17774. attributes: {
  17775. get: function() {
  17776. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  17777. return this.getAttributes();
  17778. }
  17779. }
  17780. } );
  17781. //
  17782. this.id = programIdCount ++;
  17783. this.code = code;
  17784. this.usedTimes = 1;
  17785. this.program = program;
  17786. this.vertexShader = glVertexShader;
  17787. this.fragmentShader = glFragmentShader;
  17788. return this;
  17789. };
  17790. } )();
  17791. // File:src/renderers/webgl/WebGLPrograms.js
  17792. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  17793. var programs = [];
  17794. var shaderIDs = {
  17795. MeshDepthMaterial: 'depth',
  17796. MeshNormalMaterial: 'normal',
  17797. MeshBasicMaterial: 'basic',
  17798. MeshLambertMaterial: 'lambert',
  17799. MeshPhongMaterial: 'phong',
  17800. MeshStandardMaterial: 'standard',
  17801. LineBasicMaterial: 'basic',
  17802. LineDashedMaterial: 'dashed',
  17803. PointsMaterial: 'points'
  17804. };
  17805. var parameterNames = [
  17806. "precision", "supportsVertexTextures", "map", "envMap", "envMapMode",
  17807. "lightMap", "aoMap", "emissiveMap", "bumpMap", "normalMap", "displacementMap", "specularMap",
  17808. "roughnessMap", "metalnessMap",
  17809. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  17810. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  17811. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  17812. "maxMorphTargets", "maxMorphNormals",
  17813. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights",
  17814. "shadowMapEnabled", "pointLightShadows",
  17815. "shadowMapType",
  17816. "alphaTest", "doubleSided", "flipSided"
  17817. ];
  17818. function allocateBones ( object ) {
  17819. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  17820. return 1024;
  17821. } else {
  17822. // default for when object is not specified
  17823. // ( for example when prebuilding shader to be used with multiple objects )
  17824. //
  17825. // - leave some extra space for other uniforms
  17826. // - limit here is ANGLE's 254 max uniform vectors
  17827. // (up to 54 should be safe)
  17828. var nVertexUniforms = capabilities.maxVertexUniforms;
  17829. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  17830. var maxBones = nVertexMatrices;
  17831. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  17832. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  17833. if ( maxBones < object.skeleton.bones.length ) {
  17834. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  17835. }
  17836. }
  17837. return maxBones;
  17838. }
  17839. }
  17840. this.getParameters = function ( material, lights, fog, object ) {
  17841. var shaderID = shaderIDs[ material.type ];
  17842. // heuristics to create shader parameters according to lights in the scene
  17843. // (not to blow over maxLights budget)
  17844. var maxBones = allocateBones( object );
  17845. var precision = renderer.getPrecision();
  17846. if ( material.precision !== null ) {
  17847. precision = capabilities.getMaxPrecision( material.precision );
  17848. if ( precision !== material.precision ) {
  17849. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  17850. }
  17851. }
  17852. var parameters = {
  17853. shaderID: shaderID,
  17854. precision: precision,
  17855. supportsVertexTextures: capabilities.vertexTextures,
  17856. map: !! material.map,
  17857. envMap: !! material.envMap,
  17858. envMapMode: material.envMap && material.envMap.mapping,
  17859. lightMap: !! material.lightMap,
  17860. aoMap: !! material.aoMap,
  17861. emissiveMap: !! material.emissiveMap,
  17862. bumpMap: !! material.bumpMap,
  17863. normalMap: !! material.normalMap,
  17864. displacementMap: !! material.displacementMap,
  17865. roughnessMap: !! material.roughnessMap,
  17866. metalnessMap: !! material.metalnessMap,
  17867. specularMap: !! material.specularMap,
  17868. alphaMap: !! material.alphaMap,
  17869. combine: material.combine,
  17870. vertexColors: material.vertexColors,
  17871. fog: fog,
  17872. useFog: material.fog,
  17873. fogExp: fog instanceof THREE.FogExp2,
  17874. flatShading: material.shading === THREE.FlatShading,
  17875. sizeAttenuation: material.sizeAttenuation,
  17876. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  17877. skinning: material.skinning,
  17878. maxBones: maxBones,
  17879. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  17880. morphTargets: material.morphTargets,
  17881. morphNormals: material.morphNormals,
  17882. maxMorphTargets: renderer.maxMorphTargets,
  17883. maxMorphNormals: renderer.maxMorphNormals,
  17884. numDirLights: lights.directional.length,
  17885. numPointLights: lights.point.length,
  17886. numSpotLights: lights.spot.length,
  17887. numHemiLights: lights.hemi.length,
  17888. pointLightShadows: lights.shadowsPointLight,
  17889. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows.length > 0,
  17890. shadowMapType: renderer.shadowMap.type,
  17891. alphaTest: material.alphaTest,
  17892. doubleSided: material.side === THREE.DoubleSide,
  17893. flipSided: material.side === THREE.BackSide
  17894. };
  17895. return parameters;
  17896. };
  17897. this.getProgramCode = function ( material, parameters ) {
  17898. var chunks = [];
  17899. if ( parameters.shaderID ) {
  17900. chunks.push( parameters.shaderID );
  17901. } else {
  17902. chunks.push( material.fragmentShader );
  17903. chunks.push( material.vertexShader );
  17904. }
  17905. if ( material.defines !== undefined ) {
  17906. for ( var name in material.defines ) {
  17907. chunks.push( name );
  17908. chunks.push( material.defines[ name ] );
  17909. }
  17910. }
  17911. for ( var i = 0; i < parameterNames.length; i ++ ) {
  17912. var parameterName = parameterNames[ i ];
  17913. chunks.push( parameterName );
  17914. chunks.push( parameters[ parameterName ] );
  17915. }
  17916. return chunks.join();
  17917. };
  17918. this.acquireProgram = function ( material, parameters, code ) {
  17919. var program;
  17920. // Check if code has been already compiled
  17921. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  17922. var programInfo = programs[ p ];
  17923. if ( programInfo.code === code ) {
  17924. program = programInfo;
  17925. ++ program.usedTimes;
  17926. break;
  17927. }
  17928. }
  17929. if ( program === undefined ) {
  17930. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  17931. programs.push( program );
  17932. }
  17933. return program;
  17934. };
  17935. this.releaseProgram = function( program ) {
  17936. if ( -- program.usedTimes === 0 ) {
  17937. // Remove from unordered set
  17938. var i = programs.indexOf( program );
  17939. programs[ i ] = programs[ programs.length - 1 ];
  17940. programs.pop();
  17941. // Free WebGL resources
  17942. program.destroy();
  17943. }
  17944. };
  17945. // Exposed for resource monitoring & error feedback via renderer.info:
  17946. this.programs = programs;
  17947. };
  17948. // File:src/renderers/webgl/WebGLProperties.js
  17949. /**
  17950. * @author fordacious / fordacious.github.io
  17951. */
  17952. THREE.WebGLProperties = function () {
  17953. var properties = {};
  17954. this.get = function ( object ) {
  17955. var uuid = object.uuid;
  17956. var map = properties[ uuid ];
  17957. if ( map === undefined ) {
  17958. map = {};
  17959. properties[ uuid ] = map;
  17960. }
  17961. return map;
  17962. };
  17963. this.delete = function ( object ) {
  17964. delete properties[ object.uuid ];
  17965. };
  17966. this.clear = function () {
  17967. properties = {};
  17968. };
  17969. };
  17970. // File:src/renderers/webgl/WebGLShader.js
  17971. THREE.WebGLShader = ( function () {
  17972. function addLineNumbers( string ) {
  17973. var lines = string.split( '\n' );
  17974. for ( var i = 0; i < lines.length; i ++ ) {
  17975. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  17976. }
  17977. return lines.join( '\n' );
  17978. }
  17979. return function WebGLShader( gl, type, string ) {
  17980. var shader = gl.createShader( type );
  17981. gl.shaderSource( shader, string );
  17982. gl.compileShader( shader );
  17983. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  17984. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  17985. }
  17986. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  17987. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  17988. }
  17989. // --enable-privileged-webgl-extension
  17990. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  17991. return shader;
  17992. };
  17993. } )();
  17994. // File:src/renderers/webgl/WebGLShadowMap.js
  17995. /**
  17996. * @author alteredq / http://alteredqualia.com/
  17997. * @author mrdoob / http://mrdoob.com/
  17998. */
  17999. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  18000. var _gl = _renderer.context,
  18001. _state = _renderer.state,
  18002. _frustum = new THREE.Frustum(),
  18003. _projScreenMatrix = new THREE.Matrix4(),
  18004. _shadowMapSize = new THREE.Vector2(),
  18005. _lookTarget = new THREE.Vector3(),
  18006. _lightPositionWorld = new THREE.Vector3(),
  18007. _renderList = [],
  18008. _MorphingFlag = 1,
  18009. _SkinningFlag = 2,
  18010. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  18011. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  18012. _distanceMaterials = new Array( _NumberOfMaterialVariants );
  18013. var cubeDirections = [
  18014. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  18015. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  18016. ];
  18017. var cubeUps = [
  18018. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  18019. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  18020. ];
  18021. var cube2DViewPorts = [
  18022. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  18023. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  18024. ];
  18025. // init
  18026. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  18027. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  18028. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  18029. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  18030. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  18031. var useMorphing = ( i & _MorphingFlag ) !== 0;
  18032. var useSkinning = ( i & _SkinningFlag ) !== 0;
  18033. var depthMaterial = new THREE.ShaderMaterial( {
  18034. uniforms: depthUniforms,
  18035. vertexShader: depthShader.vertexShader,
  18036. fragmentShader: depthShader.fragmentShader,
  18037. morphTargets: useMorphing,
  18038. skinning: useSkinning
  18039. } );
  18040. _depthMaterials[ i ] = depthMaterial;
  18041. var distanceMaterial = new THREE.ShaderMaterial( {
  18042. defines: {
  18043. 'USE_SHADOWMAP': ''
  18044. },
  18045. uniforms: distanceUniforms,
  18046. vertexShader: distanceShader.vertexShader,
  18047. fragmentShader: distanceShader.fragmentShader,
  18048. morphTargets: useMorphing,
  18049. skinning: useSkinning
  18050. } );
  18051. _distanceMaterials[ i ] = distanceMaterial;
  18052. }
  18053. //
  18054. var scope = this;
  18055. this.enabled = false;
  18056. this.autoUpdate = true;
  18057. this.needsUpdate = false;
  18058. this.type = THREE.PCFShadowMap;
  18059. this.cullFace = THREE.CullFaceFront;
  18060. this.render = function ( scene, camera ) {
  18061. var faceCount, isPointLight;
  18062. if ( scope.enabled === false ) return;
  18063. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  18064. // Set GL state for depth map.
  18065. _state.clearColor( 1, 1, 1, 1 );
  18066. _state.disable( _gl.BLEND );
  18067. _state.enable( _gl.CULL_FACE );
  18068. _gl.frontFace( _gl.CCW );
  18069. _gl.cullFace( scope.cullFace === THREE.CullFaceFront ? _gl.FRONT : _gl.BACK );
  18070. _state.setDepthTest( true );
  18071. _state.setScissorTest( false );
  18072. // render depth map
  18073. var shadows = _lights.shadows;
  18074. for ( var i = 0, il = shadows.length; i < il; i ++ ) {
  18075. var light = shadows[ i ];
  18076. var shadow = light.shadow;
  18077. var shadowCamera = shadow.camera;
  18078. _shadowMapSize.copy( shadow.mapSize );
  18079. if ( light instanceof THREE.PointLight ) {
  18080. faceCount = 6;
  18081. isPointLight = true;
  18082. var vpWidth = _shadowMapSize.x;
  18083. var vpHeight = _shadowMapSize.y;
  18084. // These viewports map a cube-map onto a 2D texture with the
  18085. // following orientation:
  18086. //
  18087. // xzXZ
  18088. // y Y
  18089. //
  18090. // X - Positive x direction
  18091. // x - Negative x direction
  18092. // Y - Positive y direction
  18093. // y - Negative y direction
  18094. // Z - Positive z direction
  18095. // z - Negative z direction
  18096. // positive X
  18097. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  18098. // negative X
  18099. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  18100. // positive Z
  18101. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  18102. // negative Z
  18103. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  18104. // positive Y
  18105. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  18106. // negative Y
  18107. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  18108. _shadowMapSize.x *= 4.0;
  18109. _shadowMapSize.y *= 2.0;
  18110. } else {
  18111. faceCount = 1;
  18112. isPointLight = false;
  18113. }
  18114. if ( shadow.map === null ) {
  18115. var pars = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
  18116. shadow.map = new THREE.WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  18117. //
  18118. if ( light instanceof THREE.SpotLight ) {
  18119. shadowCamera.aspect = _shadowMapSize.x / _shadowMapSize.y;
  18120. }
  18121. shadowCamera.updateProjectionMatrix();
  18122. }
  18123. var shadowMap = shadow.map;
  18124. var shadowMatrix = shadow.matrix;
  18125. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  18126. shadowCamera.position.copy( _lightPositionWorld );
  18127. _renderer.setRenderTarget( shadowMap );
  18128. _renderer.clear();
  18129. // render shadow map for each cube face (if omni-directional) or
  18130. // run a single pass if not
  18131. for ( var face = 0; face < faceCount; face ++ ) {
  18132. if ( isPointLight ) {
  18133. _lookTarget.copy( shadowCamera.position );
  18134. _lookTarget.add( cubeDirections[ face ] );
  18135. shadowCamera.up.copy( cubeUps[ face ] );
  18136. shadowCamera.lookAt( _lookTarget );
  18137. var vpDimensions = cube2DViewPorts[ face ];
  18138. _state.viewport( vpDimensions );
  18139. } else {
  18140. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  18141. shadowCamera.lookAt( _lookTarget );
  18142. }
  18143. shadowCamera.updateMatrixWorld();
  18144. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  18145. // compute shadow matrix
  18146. shadowMatrix.set(
  18147. 0.5, 0.0, 0.0, 0.5,
  18148. 0.0, 0.5, 0.0, 0.5,
  18149. 0.0, 0.0, 0.5, 0.5,
  18150. 0.0, 0.0, 0.0, 1.0
  18151. );
  18152. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  18153. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  18154. // update camera matrices and frustum
  18155. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  18156. _frustum.setFromMatrix( _projScreenMatrix );
  18157. // set object matrices & frustum culling
  18158. _renderList.length = 0;
  18159. projectObject( scene, camera, shadowCamera );
  18160. // render shadow map
  18161. // render regular objects
  18162. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  18163. var object = _renderList[ j ];
  18164. var geometry = _objects.update( object );
  18165. var material = object.material;
  18166. if ( material instanceof THREE.MultiMaterial ) {
  18167. var groups = geometry.groups;
  18168. var materials = material.materials;
  18169. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  18170. var group = groups[ k ];
  18171. var groupMaterial = materials[ group.materialIndex ];
  18172. if ( groupMaterial.visible === true ) {
  18173. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  18174. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  18175. }
  18176. }
  18177. } else {
  18178. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  18179. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  18180. }
  18181. }
  18182. }
  18183. // We must call _renderer.resetGLState() at the end of each iteration of
  18184. // the light loop in order to force material updates for each light.
  18185. _renderer.resetGLState();
  18186. }
  18187. // Restore GL state.
  18188. var clearColor = _renderer.getClearColor(),
  18189. clearAlpha = _renderer.getClearAlpha();
  18190. _renderer.setClearColor( clearColor, clearAlpha );
  18191. _state.enable( _gl.BLEND );
  18192. if ( scope.cullFace === THREE.CullFaceFront ) {
  18193. _gl.cullFace( _gl.BACK );
  18194. }
  18195. _renderer.resetGLState();
  18196. scope.needsUpdate = false;
  18197. };
  18198. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  18199. var geometry = object.geometry;
  18200. var newMaterial = null;
  18201. var materialVariants = _depthMaterials;
  18202. var customMaterial = object.customDepthMaterial;
  18203. if ( isPointLight ) {
  18204. materialVariants = _distanceMaterials;
  18205. customMaterial = object.customDistanceMaterial;
  18206. }
  18207. if ( ! customMaterial ) {
  18208. var useMorphing = geometry.morphTargets !== undefined &&
  18209. geometry.morphTargets.length > 0 && material.morphTargets;
  18210. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  18211. var variantIndex = 0;
  18212. if ( useMorphing ) variantIndex |= _MorphingFlag;
  18213. if ( useSkinning ) variantIndex |= _SkinningFlag;
  18214. newMaterial = materialVariants[ variantIndex ];
  18215. } else {
  18216. newMaterial = customMaterial;
  18217. }
  18218. newMaterial.visible = material.visible;
  18219. newMaterial.wireframe = material.wireframe;
  18220. newMaterial.wireframeLinewidth = material.wireframeLinewidth;
  18221. if ( isPointLight && newMaterial.uniforms.lightPos !== undefined ) {
  18222. newMaterial.uniforms.lightPos.value.copy( lightPositionWorld );
  18223. }
  18224. return newMaterial;
  18225. }
  18226. function projectObject( object, camera, shadowCamera ) {
  18227. if ( object.visible === false ) return;
  18228. if ( object.layers.test( camera.layers ) && ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) ) {
  18229. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  18230. var material = object.material;
  18231. if ( material.visible === true ) {
  18232. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  18233. _renderList.push( object );
  18234. }
  18235. }
  18236. }
  18237. var children = object.children;
  18238. for ( var i = 0, l = children.length; i < l; i ++ ) {
  18239. projectObject( children[ i ], camera, shadowCamera );
  18240. }
  18241. }
  18242. };
  18243. // File:src/renderers/webgl/WebGLState.js
  18244. /**
  18245. * @author mrdoob / http://mrdoob.com/
  18246. */
  18247. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  18248. var _this = this;
  18249. var color = new THREE.Vector4();
  18250. var newAttributes = new Uint8Array( 16 );
  18251. var enabledAttributes = new Uint8Array( 16 );
  18252. var attributeDivisors = new Uint8Array( 16 );
  18253. var capabilities = {};
  18254. var compressedTextureFormats = null;
  18255. var currentBlending = null;
  18256. var currentBlendEquation = null;
  18257. var currentBlendSrc = null;
  18258. var currentBlendDst = null;
  18259. var currentBlendEquationAlpha = null;
  18260. var currentBlendSrcAlpha = null;
  18261. var currentBlendDstAlpha = null;
  18262. var currentDepthFunc = null;
  18263. var currentDepthWrite = null;
  18264. var currentColorWrite = null;
  18265. var currentStencilWrite = null;
  18266. var currentStencilFunc = null;
  18267. var currentStencilRef = null;
  18268. var currentStencilMask = null;
  18269. var currentStencilFail = null;
  18270. var currentStencilZFail = null;
  18271. var currentStencilZPass = null;
  18272. var currentFlipSided = null;
  18273. var currentLineWidth = null;
  18274. var currentPolygonOffsetFactor = null;
  18275. var currentPolygonOffsetUnits = null;
  18276. var currentScissorTest = null;
  18277. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  18278. var currentTextureSlot = undefined;
  18279. var currentBoundTextures = {};
  18280. var currentClearColor = new THREE.Vector4();
  18281. var currentClearDepth = null;
  18282. var currentClearStencil = null;
  18283. var currentScissor = new THREE.Vector4();
  18284. var currentViewport = new THREE.Vector4();
  18285. var emptyTexture = gl.createTexture();
  18286. gl.bindTexture( gl.TEXTURE_2D, emptyTexture );
  18287. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR );
  18288. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 1, 1, 0, gl.RGB, gl.UNSIGNED_BYTE, new Uint8Array( 3 ) );
  18289. this.init = function () {
  18290. this.clearColor( 0, 0, 0, 1 );
  18291. this.clearDepth( 1 );
  18292. this.clearStencil( 0 );
  18293. this.enable( gl.DEPTH_TEST );
  18294. gl.depthFunc( gl.LEQUAL );
  18295. gl.frontFace( gl.CCW );
  18296. gl.cullFace( gl.BACK );
  18297. this.enable( gl.CULL_FACE );
  18298. this.enable( gl.BLEND );
  18299. gl.blendEquation( gl.FUNC_ADD );
  18300. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  18301. };
  18302. this.initAttributes = function () {
  18303. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  18304. newAttributes[ i ] = 0;
  18305. }
  18306. };
  18307. this.enableAttribute = function ( attribute ) {
  18308. newAttributes[ attribute ] = 1;
  18309. if ( enabledAttributes[ attribute ] === 0 ) {
  18310. gl.enableVertexAttribArray( attribute );
  18311. enabledAttributes[ attribute ] = 1;
  18312. }
  18313. if ( attributeDivisors[ attribute ] !== 0 ) {
  18314. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  18315. extension.vertexAttribDivisorANGLE( attribute, 0 );
  18316. attributeDivisors[ attribute ] = 0;
  18317. }
  18318. };
  18319. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  18320. newAttributes[ attribute ] = 1;
  18321. if ( enabledAttributes[ attribute ] === 0 ) {
  18322. gl.enableVertexAttribArray( attribute );
  18323. enabledAttributes[ attribute ] = 1;
  18324. }
  18325. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  18326. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  18327. attributeDivisors[ attribute ] = meshPerAttribute;
  18328. }
  18329. };
  18330. this.disableUnusedAttributes = function () {
  18331. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  18332. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  18333. gl.disableVertexAttribArray( i );
  18334. enabledAttributes[ i ] = 0;
  18335. }
  18336. }
  18337. };
  18338. this.enable = function ( id ) {
  18339. if ( capabilities[ id ] !== true ) {
  18340. gl.enable( id );
  18341. capabilities[ id ] = true;
  18342. }
  18343. };
  18344. this.disable = function ( id ) {
  18345. if ( capabilities[ id ] !== false ) {
  18346. gl.disable( id );
  18347. capabilities[ id ] = false;
  18348. }
  18349. };
  18350. this.getCompressedTextureFormats = function () {
  18351. if ( compressedTextureFormats === null ) {
  18352. compressedTextureFormats = [];
  18353. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  18354. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  18355. extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
  18356. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  18357. for ( var i = 0; i < formats.length; i ++ ) {
  18358. compressedTextureFormats.push( formats[ i ] );
  18359. }
  18360. }
  18361. }
  18362. return compressedTextureFormats;
  18363. };
  18364. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  18365. if ( blending === THREE.NoBlending ) {
  18366. this.disable( gl.BLEND );
  18367. } else {
  18368. this.enable( gl.BLEND );
  18369. }
  18370. if ( blending !== currentBlending ) {
  18371. if ( blending === THREE.AdditiveBlending ) {
  18372. gl.blendEquation( gl.FUNC_ADD );
  18373. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  18374. } else if ( blending === THREE.SubtractiveBlending ) {
  18375. // TODO: Find blendFuncSeparate() combination
  18376. gl.blendEquation( gl.FUNC_ADD );
  18377. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  18378. } else if ( blending === THREE.MultiplyBlending ) {
  18379. // TODO: Find blendFuncSeparate() combination
  18380. gl.blendEquation( gl.FUNC_ADD );
  18381. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  18382. } else {
  18383. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18384. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  18385. }
  18386. currentBlending = blending;
  18387. }
  18388. if ( blending === THREE.CustomBlending ) {
  18389. blendEquationAlpha = blendEquationAlpha || blendEquation;
  18390. blendSrcAlpha = blendSrcAlpha || blendSrc;
  18391. blendDstAlpha = blendDstAlpha || blendDst;
  18392. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  18393. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  18394. currentBlendEquation = blendEquation;
  18395. currentBlendEquationAlpha = blendEquationAlpha;
  18396. }
  18397. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  18398. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  18399. currentBlendSrc = blendSrc;
  18400. currentBlendDst = blendDst;
  18401. currentBlendSrcAlpha = blendSrcAlpha;
  18402. currentBlendDstAlpha = blendDstAlpha;
  18403. }
  18404. } else {
  18405. currentBlendEquation = null;
  18406. currentBlendSrc = null;
  18407. currentBlendDst = null;
  18408. currentBlendEquationAlpha = null;
  18409. currentBlendSrcAlpha = null;
  18410. currentBlendDstAlpha = null;
  18411. }
  18412. };
  18413. this.setDepthFunc = function ( depthFunc ) {
  18414. if ( currentDepthFunc !== depthFunc ) {
  18415. if ( depthFunc ) {
  18416. switch ( depthFunc ) {
  18417. case THREE.NeverDepth:
  18418. gl.depthFunc( gl.NEVER );
  18419. break;
  18420. case THREE.AlwaysDepth:
  18421. gl.depthFunc( gl.ALWAYS );
  18422. break;
  18423. case THREE.LessDepth:
  18424. gl.depthFunc( gl.LESS );
  18425. break;
  18426. case THREE.LessEqualDepth:
  18427. gl.depthFunc( gl.LEQUAL );
  18428. break;
  18429. case THREE.EqualDepth:
  18430. gl.depthFunc( gl.EQUAL );
  18431. break;
  18432. case THREE.GreaterEqualDepth:
  18433. gl.depthFunc( gl.GEQUAL );
  18434. break;
  18435. case THREE.GreaterDepth:
  18436. gl.depthFunc( gl.GREATER );
  18437. break;
  18438. case THREE.NotEqualDepth:
  18439. gl.depthFunc( gl.NOTEQUAL );
  18440. break;
  18441. default:
  18442. gl.depthFunc( gl.LEQUAL );
  18443. }
  18444. } else {
  18445. gl.depthFunc( gl.LEQUAL );
  18446. }
  18447. currentDepthFunc = depthFunc;
  18448. }
  18449. };
  18450. this.setDepthTest = function ( depthTest ) {
  18451. if ( depthTest ) {
  18452. this.enable( gl.DEPTH_TEST );
  18453. } else {
  18454. this.disable( gl.DEPTH_TEST );
  18455. }
  18456. };
  18457. this.setDepthWrite = function ( depthWrite ) {
  18458. // TODO: Rename to setDepthMask
  18459. if ( currentDepthWrite !== depthWrite ) {
  18460. gl.depthMask( depthWrite );
  18461. currentDepthWrite = depthWrite;
  18462. }
  18463. };
  18464. this.setColorWrite = function ( colorWrite ) {
  18465. // TODO: Rename to setColorMask
  18466. if ( currentColorWrite !== colorWrite ) {
  18467. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  18468. currentColorWrite = colorWrite;
  18469. }
  18470. };
  18471. this.setStencilFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  18472. if ( currentStencilFunc !== stencilFunc ||
  18473. currentStencilRef !== stencilRef ||
  18474. currentStencilMask !== stencilMask ) {
  18475. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  18476. currentStencilFunc = stencilFunc;
  18477. currentStencilRef = stencilRef;
  18478. currentStencilMask = stencilMask;
  18479. }
  18480. };
  18481. this.setStencilOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  18482. if ( currentStencilFail !== stencilFail ||
  18483. currentStencilZFail !== stencilZFail ||
  18484. currentStencilZPass !== stencilZPass ) {
  18485. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  18486. currentStencilFail = stencilFail;
  18487. currentStencilZFail = stencilZFail;
  18488. currentStencilZPass = stencilZPass;
  18489. }
  18490. };
  18491. this.setStencilTest = function ( stencilTest ) {
  18492. if ( stencilTest ) {
  18493. this.enable( gl.STENCIL_TEST );
  18494. } else {
  18495. this.disable( gl.STENCIL_TEST );
  18496. }
  18497. };
  18498. this.setStencilWrite = function ( stencilWrite ) {
  18499. // TODO: Rename to setStencilMask
  18500. if ( currentStencilWrite !== stencilWrite ) {
  18501. gl.stencilMask( stencilWrite );
  18502. currentStencilWrite = stencilWrite;
  18503. }
  18504. };
  18505. this.setFlipSided = function ( flipSided ) {
  18506. if ( currentFlipSided !== flipSided ) {
  18507. if ( flipSided ) {
  18508. gl.frontFace( gl.CW );
  18509. } else {
  18510. gl.frontFace( gl.CCW );
  18511. }
  18512. currentFlipSided = flipSided;
  18513. }
  18514. };
  18515. this.setLineWidth = function ( width ) {
  18516. if ( width !== currentLineWidth ) {
  18517. gl.lineWidth( width );
  18518. currentLineWidth = width;
  18519. }
  18520. };
  18521. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  18522. if ( polygonOffset ) {
  18523. this.enable( gl.POLYGON_OFFSET_FILL );
  18524. } else {
  18525. this.disable( gl.POLYGON_OFFSET_FILL );
  18526. }
  18527. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  18528. gl.polygonOffset( factor, units );
  18529. currentPolygonOffsetFactor = factor;
  18530. currentPolygonOffsetUnits = units;
  18531. }
  18532. };
  18533. this.getScissorTest = function () {
  18534. return currentScissorTest;
  18535. };
  18536. this.setScissorTest = function ( scissorTest ) {
  18537. currentScissorTest = scissorTest;
  18538. if ( scissorTest ) {
  18539. this.enable( gl.SCISSOR_TEST );
  18540. } else {
  18541. this.disable( gl.SCISSOR_TEST );
  18542. }
  18543. };
  18544. // texture
  18545. this.activeTexture = function ( webglSlot ) {
  18546. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  18547. if ( currentTextureSlot !== webglSlot ) {
  18548. gl.activeTexture( webglSlot );
  18549. currentTextureSlot = webglSlot;
  18550. }
  18551. };
  18552. this.bindTexture = function ( webglType, webglTexture ) {
  18553. if ( currentTextureSlot === undefined ) {
  18554. _this.activeTexture();
  18555. }
  18556. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  18557. if ( boundTexture === undefined ) {
  18558. boundTexture = { type: undefined, texture: undefined };
  18559. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  18560. }
  18561. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  18562. gl.bindTexture( webglType, webglTexture || emptyTexture );
  18563. boundTexture.type = webglType;
  18564. boundTexture.texture = webglTexture;
  18565. }
  18566. };
  18567. this.compressedTexImage2D = function () {
  18568. try {
  18569. gl.compressedTexImage2D.apply( gl, arguments );
  18570. } catch ( error ) {
  18571. console.error( error );
  18572. }
  18573. };
  18574. this.texImage2D = function () {
  18575. try {
  18576. gl.texImage2D.apply( gl, arguments );
  18577. } catch ( error ) {
  18578. console.error( error );
  18579. }
  18580. };
  18581. // clear values
  18582. this.clearColor = function ( r, g, b, a ) {
  18583. color.set( r, g, b, a );
  18584. if ( currentClearColor.equals( color ) === false ) {
  18585. gl.clearColor( r, g, b, a );
  18586. currentClearColor.copy( color );
  18587. }
  18588. };
  18589. this.clearDepth = function ( depth ) {
  18590. if ( currentClearDepth !== depth ) {
  18591. gl.clearDepth( depth );
  18592. currentClearDepth = depth;
  18593. }
  18594. };
  18595. this.clearStencil = function ( stencil ) {
  18596. if ( currentClearStencil !== stencil ) {
  18597. gl.clearStencil( stencil );
  18598. currentClearStencil = stencil;
  18599. }
  18600. };
  18601. //
  18602. this.scissor = function ( scissor ) {
  18603. if ( currentScissor.equals( scissor ) === false ) {
  18604. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  18605. currentScissor.copy( scissor );
  18606. }
  18607. };
  18608. this.viewport = function ( viewport ) {
  18609. if ( currentViewport.equals( viewport ) === false ) {
  18610. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  18611. currentViewport.copy( viewport );
  18612. }
  18613. };
  18614. //
  18615. this.reset = function () {
  18616. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  18617. if ( enabledAttributes[ i ] === 1 ) {
  18618. gl.disableVertexAttribArray( i );
  18619. enabledAttributes[ i ] = 0;
  18620. }
  18621. }
  18622. capabilities = {};
  18623. compressedTextureFormats = null;
  18624. currentBlending = null;
  18625. currentColorWrite = null;
  18626. currentDepthWrite = null;
  18627. currentStencilWrite = null;
  18628. currentFlipSided = null;
  18629. };
  18630. };
  18631. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  18632. /**
  18633. * @author mikael emtinger / http://gomo.se/
  18634. * @author alteredq / http://alteredqualia.com/
  18635. */
  18636. THREE.LensFlarePlugin = function ( renderer, flares ) {
  18637. var gl = renderer.context;
  18638. var state = renderer.state;
  18639. var vertexBuffer, elementBuffer;
  18640. var program, attributes, uniforms;
  18641. var hasVertexTexture;
  18642. var tempTexture, occlusionTexture;
  18643. function init() {
  18644. var vertices = new Float32Array( [
  18645. - 1, - 1, 0, 0,
  18646. 1, - 1, 1, 0,
  18647. 1, 1, 1, 1,
  18648. - 1, 1, 0, 1
  18649. ] );
  18650. var faces = new Uint16Array( [
  18651. 0, 1, 2,
  18652. 0, 2, 3
  18653. ] );
  18654. // buffers
  18655. vertexBuffer = gl.createBuffer();
  18656. elementBuffer = gl.createBuffer();
  18657. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18658. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18659. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18660. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18661. // textures
  18662. tempTexture = gl.createTexture();
  18663. occlusionTexture = gl.createTexture();
  18664. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18665. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  18666. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18667. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18668. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18669. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18670. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18671. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  18672. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18673. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18674. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18675. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18676. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  18677. var shader;
  18678. if ( hasVertexTexture ) {
  18679. shader = {
  18680. vertexShader: [
  18681. "uniform lowp int renderType;",
  18682. "uniform vec3 screenPosition;",
  18683. "uniform vec2 scale;",
  18684. "uniform float rotation;",
  18685. "uniform sampler2D occlusionMap;",
  18686. "attribute vec2 position;",
  18687. "attribute vec2 uv;",
  18688. "varying vec2 vUV;",
  18689. "varying float vVisibility;",
  18690. "void main() {",
  18691. "vUV = uv;",
  18692. "vec2 pos = position;",
  18693. "if ( renderType == 2 ) {",
  18694. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  18695. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  18696. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  18697. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  18698. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  18699. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  18700. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  18701. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  18702. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  18703. "vVisibility = visibility.r / 9.0;",
  18704. "vVisibility *= 1.0 - visibility.g / 9.0;",
  18705. "vVisibility *= visibility.b / 9.0;",
  18706. "vVisibility *= 1.0 - visibility.a / 9.0;",
  18707. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18708. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18709. "}",
  18710. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18711. "}"
  18712. ].join( "\n" ),
  18713. fragmentShader: [
  18714. "uniform lowp int renderType;",
  18715. "uniform sampler2D map;",
  18716. "uniform float opacity;",
  18717. "uniform vec3 color;",
  18718. "varying vec2 vUV;",
  18719. "varying float vVisibility;",
  18720. "void main() {",
  18721. // pink square
  18722. "if ( renderType == 0 ) {",
  18723. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  18724. // restore
  18725. "} else if ( renderType == 1 ) {",
  18726. "gl_FragColor = texture2D( map, vUV );",
  18727. // flare
  18728. "} else {",
  18729. "vec4 texture = texture2D( map, vUV );",
  18730. "texture.a *= opacity * vVisibility;",
  18731. "gl_FragColor = texture;",
  18732. "gl_FragColor.rgb *= color;",
  18733. "}",
  18734. "}"
  18735. ].join( "\n" )
  18736. };
  18737. } else {
  18738. shader = {
  18739. vertexShader: [
  18740. "uniform lowp int renderType;",
  18741. "uniform vec3 screenPosition;",
  18742. "uniform vec2 scale;",
  18743. "uniform float rotation;",
  18744. "attribute vec2 position;",
  18745. "attribute vec2 uv;",
  18746. "varying vec2 vUV;",
  18747. "void main() {",
  18748. "vUV = uv;",
  18749. "vec2 pos = position;",
  18750. "if ( renderType == 2 ) {",
  18751. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18752. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18753. "}",
  18754. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18755. "}"
  18756. ].join( "\n" ),
  18757. fragmentShader: [
  18758. "precision mediump float;",
  18759. "uniform lowp int renderType;",
  18760. "uniform sampler2D map;",
  18761. "uniform sampler2D occlusionMap;",
  18762. "uniform float opacity;",
  18763. "uniform vec3 color;",
  18764. "varying vec2 vUV;",
  18765. "void main() {",
  18766. // pink square
  18767. "if ( renderType == 0 ) {",
  18768. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  18769. // restore
  18770. "} else if ( renderType == 1 ) {",
  18771. "gl_FragColor = texture2D( map, vUV );",
  18772. // flare
  18773. "} else {",
  18774. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  18775. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  18776. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  18777. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  18778. "visibility = ( 1.0 - visibility / 4.0 );",
  18779. "vec4 texture = texture2D( map, vUV );",
  18780. "texture.a *= opacity * visibility;",
  18781. "gl_FragColor = texture;",
  18782. "gl_FragColor.rgb *= color;",
  18783. "}",
  18784. "}"
  18785. ].join( "\n" )
  18786. };
  18787. }
  18788. program = createProgram( shader );
  18789. attributes = {
  18790. vertex: gl.getAttribLocation ( program, "position" ),
  18791. uv: gl.getAttribLocation ( program, "uv" )
  18792. };
  18793. uniforms = {
  18794. renderType: gl.getUniformLocation( program, "renderType" ),
  18795. map: gl.getUniformLocation( program, "map" ),
  18796. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  18797. opacity: gl.getUniformLocation( program, "opacity" ),
  18798. color: gl.getUniformLocation( program, "color" ),
  18799. scale: gl.getUniformLocation( program, "scale" ),
  18800. rotation: gl.getUniformLocation( program, "rotation" ),
  18801. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  18802. };
  18803. }
  18804. /*
  18805. * Render lens flares
  18806. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  18807. * reads these back and calculates occlusion.
  18808. */
  18809. this.render = function ( scene, camera, viewport ) {
  18810. if ( flares.length === 0 ) return;
  18811. var tempPosition = new THREE.Vector3();
  18812. var invAspect = viewport.w / viewport.z,
  18813. halfViewportWidth = viewport.z * 0.5,
  18814. halfViewportHeight = viewport.w * 0.5;
  18815. var size = 16 / viewport.w,
  18816. scale = new THREE.Vector2( size * invAspect, size );
  18817. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  18818. screenPositionPixels = new THREE.Vector2( 1, 1 );
  18819. if ( program === undefined ) {
  18820. init();
  18821. }
  18822. gl.useProgram( program );
  18823. state.initAttributes();
  18824. state.enableAttribute( attributes.vertex );
  18825. state.enableAttribute( attributes.uv );
  18826. state.disableUnusedAttributes();
  18827. // loop through all lens flares to update their occlusion and positions
  18828. // setup gl and common used attribs/uniforms
  18829. gl.uniform1i( uniforms.occlusionMap, 0 );
  18830. gl.uniform1i( uniforms.map, 1 );
  18831. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18832. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  18833. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  18834. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18835. state.disable( gl.CULL_FACE );
  18836. state.setDepthWrite( false );
  18837. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  18838. size = 16 / viewport.w;
  18839. scale.set( size * invAspect, size );
  18840. // calc object screen position
  18841. var flare = flares[ i ];
  18842. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  18843. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  18844. tempPosition.applyProjection( camera.projectionMatrix );
  18845. // setup arrays for gl programs
  18846. screenPosition.copy( tempPosition );
  18847. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  18848. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  18849. // screen cull
  18850. if ( hasVertexTexture || (
  18851. screenPositionPixels.x > 0 &&
  18852. screenPositionPixels.x < viewport.z &&
  18853. screenPositionPixels.y > 0 &&
  18854. screenPositionPixels.y < viewport.w ) ) {
  18855. // save current RGB to temp texture
  18856. state.activeTexture( gl.TEXTURE0 );
  18857. state.bindTexture( gl.TEXTURE_2D, null );
  18858. state.activeTexture( gl.TEXTURE1 );
  18859. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18860. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, viewport.x + screenPositionPixels.x - 8, viewport.y + screenPositionPixels.y - 8, 16, 16, 0 );
  18861. // render pink quad
  18862. gl.uniform1i( uniforms.renderType, 0 );
  18863. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18864. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18865. state.disable( gl.BLEND );
  18866. state.enable( gl.DEPTH_TEST );
  18867. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18868. // copy result to occlusionMap
  18869. state.activeTexture( gl.TEXTURE0 );
  18870. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18871. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, viewport.x + screenPositionPixels.x - 8, viewport.y + screenPositionPixels.y - 8, 16, 16, 0 );
  18872. // restore graphics
  18873. gl.uniform1i( uniforms.renderType, 1 );
  18874. state.disable( gl.DEPTH_TEST );
  18875. state.activeTexture( gl.TEXTURE1 );
  18876. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18877. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18878. // update object positions
  18879. flare.positionScreen.copy( screenPosition );
  18880. if ( flare.customUpdateCallback ) {
  18881. flare.customUpdateCallback( flare );
  18882. } else {
  18883. flare.updateLensFlares();
  18884. }
  18885. // render flares
  18886. gl.uniform1i( uniforms.renderType, 2 );
  18887. state.enable( gl.BLEND );
  18888. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  18889. var sprite = flare.lensFlares[ j ];
  18890. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  18891. screenPosition.x = sprite.x;
  18892. screenPosition.y = sprite.y;
  18893. screenPosition.z = sprite.z;
  18894. size = sprite.size * sprite.scale / viewport.w;
  18895. scale.x = size * invAspect;
  18896. scale.y = size;
  18897. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18898. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18899. gl.uniform1f( uniforms.rotation, sprite.rotation );
  18900. gl.uniform1f( uniforms.opacity, sprite.opacity );
  18901. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  18902. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  18903. renderer.setTexture( sprite.texture, 1 );
  18904. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18905. }
  18906. }
  18907. }
  18908. }
  18909. // restore gl
  18910. state.enable( gl.CULL_FACE );
  18911. state.enable( gl.DEPTH_TEST );
  18912. state.setDepthWrite( true );
  18913. renderer.resetGLState();
  18914. };
  18915. function createProgram ( shader ) {
  18916. var program = gl.createProgram();
  18917. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  18918. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  18919. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  18920. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  18921. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  18922. gl.compileShader( fragmentShader );
  18923. gl.compileShader( vertexShader );
  18924. gl.attachShader( program, fragmentShader );
  18925. gl.attachShader( program, vertexShader );
  18926. gl.linkProgram( program );
  18927. return program;
  18928. }
  18929. };
  18930. // File:src/renderers/webgl/plugins/SpritePlugin.js
  18931. /**
  18932. * @author mikael emtinger / http://gomo.se/
  18933. * @author alteredq / http://alteredqualia.com/
  18934. */
  18935. THREE.SpritePlugin = function ( renderer, sprites ) {
  18936. var gl = renderer.context;
  18937. var state = renderer.state;
  18938. var vertexBuffer, elementBuffer;
  18939. var program, attributes, uniforms;
  18940. var texture;
  18941. // decompose matrixWorld
  18942. var spritePosition = new THREE.Vector3();
  18943. var spriteRotation = new THREE.Quaternion();
  18944. var spriteScale = new THREE.Vector3();
  18945. function init() {
  18946. var vertices = new Float32Array( [
  18947. - 0.5, - 0.5, 0, 0,
  18948. 0.5, - 0.5, 1, 0,
  18949. 0.5, 0.5, 1, 1,
  18950. - 0.5, 0.5, 0, 1
  18951. ] );
  18952. var faces = new Uint16Array( [
  18953. 0, 1, 2,
  18954. 0, 2, 3
  18955. ] );
  18956. vertexBuffer = gl.createBuffer();
  18957. elementBuffer = gl.createBuffer();
  18958. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18959. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18960. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18961. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18962. program = createProgram();
  18963. attributes = {
  18964. position: gl.getAttribLocation ( program, 'position' ),
  18965. uv: gl.getAttribLocation ( program, 'uv' )
  18966. };
  18967. uniforms = {
  18968. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  18969. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  18970. rotation: gl.getUniformLocation( program, 'rotation' ),
  18971. scale: gl.getUniformLocation( program, 'scale' ),
  18972. color: gl.getUniformLocation( program, 'color' ),
  18973. map: gl.getUniformLocation( program, 'map' ),
  18974. opacity: gl.getUniformLocation( program, 'opacity' ),
  18975. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  18976. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  18977. fogType: gl.getUniformLocation( program, 'fogType' ),
  18978. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  18979. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  18980. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  18981. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  18982. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  18983. };
  18984. var canvas = document.createElement( 'canvas' );
  18985. canvas.width = 8;
  18986. canvas.height = 8;
  18987. var context = canvas.getContext( '2d' );
  18988. context.fillStyle = 'white';
  18989. context.fillRect( 0, 0, 8, 8 );
  18990. texture = new THREE.Texture( canvas );
  18991. texture.needsUpdate = true;
  18992. }
  18993. this.render = function ( scene, camera ) {
  18994. if ( sprites.length === 0 ) return;
  18995. // setup gl
  18996. if ( program === undefined ) {
  18997. init();
  18998. }
  18999. gl.useProgram( program );
  19000. state.initAttributes();
  19001. state.enableAttribute( attributes.position );
  19002. state.enableAttribute( attributes.uv );
  19003. state.disableUnusedAttributes();
  19004. state.disable( gl.CULL_FACE );
  19005. state.enable( gl.BLEND );
  19006. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19007. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  19008. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  19009. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19010. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  19011. state.activeTexture( gl.TEXTURE0 );
  19012. gl.uniform1i( uniforms.map, 0 );
  19013. var oldFogType = 0;
  19014. var sceneFogType = 0;
  19015. var fog = scene.fog;
  19016. if ( fog ) {
  19017. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  19018. if ( fog instanceof THREE.Fog ) {
  19019. gl.uniform1f( uniforms.fogNear, fog.near );
  19020. gl.uniform1f( uniforms.fogFar, fog.far );
  19021. gl.uniform1i( uniforms.fogType, 1 );
  19022. oldFogType = 1;
  19023. sceneFogType = 1;
  19024. } else if ( fog instanceof THREE.FogExp2 ) {
  19025. gl.uniform1f( uniforms.fogDensity, fog.density );
  19026. gl.uniform1i( uniforms.fogType, 2 );
  19027. oldFogType = 2;
  19028. sceneFogType = 2;
  19029. }
  19030. } else {
  19031. gl.uniform1i( uniforms.fogType, 0 );
  19032. oldFogType = 0;
  19033. sceneFogType = 0;
  19034. }
  19035. // update positions and sort
  19036. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  19037. var sprite = sprites[ i ];
  19038. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  19039. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  19040. }
  19041. sprites.sort( painterSortStable );
  19042. // render all sprites
  19043. var scale = [];
  19044. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  19045. var sprite = sprites[ i ];
  19046. var material = sprite.material;
  19047. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  19048. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  19049. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  19050. scale[ 0 ] = spriteScale.x;
  19051. scale[ 1 ] = spriteScale.y;
  19052. var fogType = 0;
  19053. if ( scene.fog && material.fog ) {
  19054. fogType = sceneFogType;
  19055. }
  19056. if ( oldFogType !== fogType ) {
  19057. gl.uniform1i( uniforms.fogType, fogType );
  19058. oldFogType = fogType;
  19059. }
  19060. if ( material.map !== null ) {
  19061. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  19062. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  19063. } else {
  19064. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  19065. gl.uniform2f( uniforms.uvScale, 1, 1 );
  19066. }
  19067. gl.uniform1f( uniforms.opacity, material.opacity );
  19068. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  19069. gl.uniform1f( uniforms.rotation, material.rotation );
  19070. gl.uniform2fv( uniforms.scale, scale );
  19071. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  19072. state.setDepthTest( material.depthTest );
  19073. state.setDepthWrite( material.depthWrite );
  19074. if ( material.map && material.map.image && material.map.image.width ) {
  19075. renderer.setTexture( material.map, 0 );
  19076. } else {
  19077. renderer.setTexture( texture, 0 );
  19078. }
  19079. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19080. }
  19081. // restore gl
  19082. state.enable( gl.CULL_FACE );
  19083. renderer.resetGLState();
  19084. };
  19085. function createProgram () {
  19086. var program = gl.createProgram();
  19087. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  19088. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  19089. gl.shaderSource( vertexShader, [
  19090. 'precision ' + renderer.getPrecision() + ' float;',
  19091. 'uniform mat4 modelViewMatrix;',
  19092. 'uniform mat4 projectionMatrix;',
  19093. 'uniform float rotation;',
  19094. 'uniform vec2 scale;',
  19095. 'uniform vec2 uvOffset;',
  19096. 'uniform vec2 uvScale;',
  19097. 'attribute vec2 position;',
  19098. 'attribute vec2 uv;',
  19099. 'varying vec2 vUV;',
  19100. 'void main() {',
  19101. 'vUV = uvOffset + uv * uvScale;',
  19102. 'vec2 alignedPosition = position * scale;',
  19103. 'vec2 rotatedPosition;',
  19104. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  19105. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  19106. 'vec4 finalPosition;',
  19107. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  19108. 'finalPosition.xy += rotatedPosition;',
  19109. 'finalPosition = projectionMatrix * finalPosition;',
  19110. 'gl_Position = finalPosition;',
  19111. '}'
  19112. ].join( '\n' ) );
  19113. gl.shaderSource( fragmentShader, [
  19114. 'precision ' + renderer.getPrecision() + ' float;',
  19115. 'uniform vec3 color;',
  19116. 'uniform sampler2D map;',
  19117. 'uniform float opacity;',
  19118. 'uniform int fogType;',
  19119. 'uniform vec3 fogColor;',
  19120. 'uniform float fogDensity;',
  19121. 'uniform float fogNear;',
  19122. 'uniform float fogFar;',
  19123. 'uniform float alphaTest;',
  19124. 'varying vec2 vUV;',
  19125. 'void main() {',
  19126. 'vec4 texture = texture2D( map, vUV );',
  19127. 'if ( texture.a < alphaTest ) discard;',
  19128. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  19129. 'if ( fogType > 0 ) {',
  19130. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  19131. 'float fogFactor = 0.0;',
  19132. 'if ( fogType == 1 ) {',
  19133. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  19134. '} else {',
  19135. 'const float LOG2 = 1.442695;',
  19136. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  19137. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  19138. '}',
  19139. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  19140. '}',
  19141. '}'
  19142. ].join( '\n' ) );
  19143. gl.compileShader( vertexShader );
  19144. gl.compileShader( fragmentShader );
  19145. gl.attachShader( program, vertexShader );
  19146. gl.attachShader( program, fragmentShader );
  19147. gl.linkProgram( program );
  19148. return program;
  19149. }
  19150. function painterSortStable ( a, b ) {
  19151. if ( a.renderOrder !== b.renderOrder ) {
  19152. return a.renderOrder - b.renderOrder;
  19153. } else if ( a.z !== b.z ) {
  19154. return b.z - a.z;
  19155. } else {
  19156. return b.id - a.id;
  19157. }
  19158. }
  19159. };
  19160. // File:src/Three.Legacy.js
  19161. /**
  19162. * @author mrdoob / http://mrdoob.com/
  19163. */
  19164. Object.defineProperties( THREE.Box2.prototype, {
  19165. empty: {
  19166. value: function () {
  19167. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  19168. return this.isEmpty();
  19169. }
  19170. },
  19171. isIntersectionBox: {
  19172. value: function ( box ) {
  19173. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19174. return this.intersectsBox( box );
  19175. }
  19176. }
  19177. } );
  19178. Object.defineProperties( THREE.Box3.prototype, {
  19179. empty: {
  19180. value: function () {
  19181. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  19182. return this.isEmpty();
  19183. }
  19184. },
  19185. isIntersectionBox: {
  19186. value: function ( box ) {
  19187. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19188. return this.intersectsBox( box );
  19189. }
  19190. },
  19191. isIntersectionSphere: {
  19192. value: function ( sphere ) {
  19193. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  19194. return this.intersectsSphere( sphere );
  19195. }
  19196. }
  19197. } );
  19198. Object.defineProperties( THREE.Matrix3.prototype, {
  19199. multiplyVector3: {
  19200. value: function ( vector ) {
  19201. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  19202. return vector.applyMatrix3( this );
  19203. }
  19204. },
  19205. multiplyVector3Array: {
  19206. value: function ( a ) {
  19207. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  19208. return this.applyToVector3Array( a );
  19209. }
  19210. }
  19211. } );
  19212. Object.defineProperties( THREE.Matrix4.prototype, {
  19213. extractPosition: {
  19214. value: function ( m ) {
  19215. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  19216. return this.copyPosition( m );
  19217. }
  19218. },
  19219. setRotationFromQuaternion: {
  19220. value: function ( q ) {
  19221. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  19222. return this.makeRotationFromQuaternion( q );
  19223. }
  19224. },
  19225. multiplyVector3: {
  19226. value: function ( vector ) {
  19227. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  19228. return vector.applyProjection( this );
  19229. }
  19230. },
  19231. multiplyVector4: {
  19232. value: function ( vector ) {
  19233. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  19234. return vector.applyMatrix4( this );
  19235. }
  19236. },
  19237. multiplyVector3Array: {
  19238. value: function ( a ) {
  19239. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  19240. return this.applyToVector3Array( a );
  19241. }
  19242. },
  19243. rotateAxis: {
  19244. value: function ( v ) {
  19245. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  19246. v.transformDirection( this );
  19247. }
  19248. },
  19249. crossVector: {
  19250. value: function ( vector ) {
  19251. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  19252. return vector.applyMatrix4( this );
  19253. }
  19254. },
  19255. translate: {
  19256. value: function ( v ) {
  19257. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  19258. }
  19259. },
  19260. rotateX: {
  19261. value: function ( angle ) {
  19262. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  19263. }
  19264. },
  19265. rotateY: {
  19266. value: function ( angle ) {
  19267. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  19268. }
  19269. },
  19270. rotateZ: {
  19271. value: function ( angle ) {
  19272. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  19273. }
  19274. },
  19275. rotateByAxis: {
  19276. value: function ( axis, angle ) {
  19277. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  19278. }
  19279. }
  19280. } );
  19281. Object.defineProperties( THREE.Plane.prototype, {
  19282. isIntersectionLine: {
  19283. value: function ( line ) {
  19284. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  19285. return this.intersectsLine( line );
  19286. }
  19287. }
  19288. } );
  19289. Object.defineProperties( THREE.Quaternion.prototype, {
  19290. multiplyVector3: {
  19291. value: function ( vector ) {
  19292. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  19293. return vector.applyQuaternion( this );
  19294. }
  19295. }
  19296. } );
  19297. Object.defineProperties( THREE.Ray.prototype, {
  19298. isIntersectionBox: {
  19299. value: function ( box ) {
  19300. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19301. return this.intersectsBox( box );
  19302. }
  19303. },
  19304. isIntersectionPlane: {
  19305. value: function ( plane ) {
  19306. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  19307. return this.intersectsPlane( plane );
  19308. }
  19309. },
  19310. isIntersectionSphere: {
  19311. value: function ( sphere ) {
  19312. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  19313. return this.intersectsSphere( sphere );
  19314. }
  19315. }
  19316. } );
  19317. Object.defineProperties( THREE.Vector3.prototype, {
  19318. setEulerFromRotationMatrix: {
  19319. value: function () {
  19320. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  19321. }
  19322. },
  19323. setEulerFromQuaternion: {
  19324. value: function () {
  19325. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  19326. }
  19327. },
  19328. getPositionFromMatrix: {
  19329. value: function ( m ) {
  19330. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  19331. return this.setFromMatrixPosition( m );
  19332. }
  19333. },
  19334. getScaleFromMatrix: {
  19335. value: function ( m ) {
  19336. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  19337. return this.setFromMatrixScale( m );
  19338. }
  19339. },
  19340. getColumnFromMatrix: {
  19341. value: function ( index, matrix ) {
  19342. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  19343. return this.setFromMatrixColumn( index, matrix );
  19344. }
  19345. }
  19346. } );
  19347. //
  19348. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  19349. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  19350. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  19351. };
  19352. THREE.Vertex = function ( x, y, z ) {
  19353. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  19354. return new THREE.Vector3( x, y, z );
  19355. };
  19356. //
  19357. Object.defineProperties( THREE.Object3D.prototype, {
  19358. eulerOrder: {
  19359. get: function () {
  19360. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19361. return this.rotation.order;
  19362. },
  19363. set: function ( value ) {
  19364. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19365. this.rotation.order = value;
  19366. }
  19367. },
  19368. getChildByName: {
  19369. value: function ( name ) {
  19370. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  19371. return this.getObjectByName( name );
  19372. }
  19373. },
  19374. renderDepth: {
  19375. set: function ( value ) {
  19376. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  19377. }
  19378. },
  19379. translate: {
  19380. value: function ( distance, axis ) {
  19381. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  19382. return this.translateOnAxis( axis, distance );
  19383. }
  19384. },
  19385. useQuaternion: {
  19386. get: function () {
  19387. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19388. },
  19389. set: function ( value ) {
  19390. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19391. }
  19392. }
  19393. } );
  19394. //
  19395. Object.defineProperties( THREE, {
  19396. PointCloud: {
  19397. value: function ( geometry, material ) {
  19398. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  19399. return new THREE.Points( geometry, material );
  19400. }
  19401. },
  19402. ParticleSystem: {
  19403. value: function ( geometry, material ) {
  19404. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  19405. return new THREE.Points( geometry, material );
  19406. }
  19407. }
  19408. } );
  19409. //
  19410. Object.defineProperties( THREE.Light.prototype, {
  19411. onlyShadow: {
  19412. set: function ( value ) {
  19413. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  19414. }
  19415. },
  19416. shadowCameraFov: {
  19417. set: function ( value ) {
  19418. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  19419. this.shadow.camera.fov = value;
  19420. }
  19421. },
  19422. shadowCameraLeft: {
  19423. set: function ( value ) {
  19424. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  19425. this.shadow.camera.left = value;
  19426. }
  19427. },
  19428. shadowCameraRight: {
  19429. set: function ( value ) {
  19430. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  19431. this.shadow.camera.right = value;
  19432. }
  19433. },
  19434. shadowCameraTop: {
  19435. set: function ( value ) {
  19436. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  19437. this.shadow.camera.top = value;
  19438. }
  19439. },
  19440. shadowCameraBottom: {
  19441. set: function ( value ) {
  19442. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  19443. this.shadow.camera.bottom = value;
  19444. }
  19445. },
  19446. shadowCameraNear: {
  19447. set: function ( value ) {
  19448. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  19449. this.shadow.camera.near = value;
  19450. }
  19451. },
  19452. shadowCameraFar: {
  19453. set: function ( value ) {
  19454. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  19455. this.shadow.camera.far = value;
  19456. }
  19457. },
  19458. shadowCameraVisible: {
  19459. set: function ( value ) {
  19460. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  19461. }
  19462. },
  19463. shadowBias: {
  19464. set: function ( value ) {
  19465. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  19466. this.shadow.bias = value;
  19467. }
  19468. },
  19469. shadowDarkness: {
  19470. set: function ( value ) {
  19471. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  19472. }
  19473. },
  19474. shadowMapWidth: {
  19475. set: function ( value ) {
  19476. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  19477. this.shadow.mapSize.width = value;
  19478. }
  19479. },
  19480. shadowMapHeight: {
  19481. set: function ( value ) {
  19482. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  19483. this.shadow.mapSize.height = value;
  19484. }
  19485. }
  19486. } );
  19487. //
  19488. Object.defineProperties( THREE.BufferAttribute.prototype, {
  19489. length: {
  19490. get: function () {
  19491. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  19492. return this.array.length;
  19493. }
  19494. }
  19495. } );
  19496. Object.defineProperties( THREE.BufferGeometry.prototype, {
  19497. drawcalls: {
  19498. get: function () {
  19499. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  19500. return this.groups;
  19501. }
  19502. },
  19503. offsets: {
  19504. get: function () {
  19505. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  19506. return this.groups;
  19507. }
  19508. },
  19509. addIndex: {
  19510. value: function ( index ) {
  19511. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  19512. this.setIndex( index );
  19513. }
  19514. },
  19515. addDrawCall: {
  19516. value: function ( start, count, indexOffset ) {
  19517. if ( indexOffset !== undefined ) {
  19518. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  19519. }
  19520. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  19521. this.addGroup( start, count );
  19522. }
  19523. },
  19524. clearDrawCalls: {
  19525. value: function () {
  19526. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  19527. this.clearGroups();
  19528. }
  19529. },
  19530. computeTangents: {
  19531. value: function () {
  19532. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  19533. }
  19534. },
  19535. computeOffsets: {
  19536. value: function () {
  19537. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  19538. }
  19539. }
  19540. } );
  19541. //
  19542. Object.defineProperties( THREE.Material.prototype, {
  19543. wrapAround: {
  19544. get: function () {
  19545. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19546. },
  19547. set: function ( value ) {
  19548. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19549. }
  19550. },
  19551. wrapRGB: {
  19552. get: function () {
  19553. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  19554. return new THREE.Color();
  19555. }
  19556. }
  19557. } );
  19558. Object.defineProperties( THREE, {
  19559. PointCloudMaterial: {
  19560. value: function ( parameters ) {
  19561. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  19562. return new THREE.PointsMaterial( parameters );
  19563. }
  19564. },
  19565. ParticleBasicMaterial: {
  19566. value: function ( parameters ) {
  19567. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  19568. return new THREE.PointsMaterial( parameters );
  19569. }
  19570. },
  19571. ParticleSystemMaterial:{
  19572. value: function ( parameters ) {
  19573. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  19574. return new THREE.PointsMaterial( parameters );
  19575. }
  19576. }
  19577. } );
  19578. Object.defineProperties( THREE.MeshPhongMaterial.prototype, {
  19579. metal: {
  19580. get: function () {
  19581. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  19582. return false;
  19583. },
  19584. set: function ( value ) {
  19585. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  19586. }
  19587. }
  19588. } );
  19589. Object.defineProperties( THREE.ShaderMaterial.prototype, {
  19590. derivatives: {
  19591. get: function () {
  19592. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19593. return this.extensions.derivatives;
  19594. },
  19595. set: function ( value ) {
  19596. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19597. this.extensions.derivatives = value;
  19598. }
  19599. }
  19600. } );
  19601. //
  19602. Object.defineProperties( THREE.WebGLRenderer.prototype, {
  19603. supportsFloatTextures: {
  19604. value: function () {
  19605. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  19606. return this.extensions.get( 'OES_texture_float' );
  19607. }
  19608. },
  19609. supportsHalfFloatTextures: {
  19610. value: function () {
  19611. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  19612. return this.extensions.get( 'OES_texture_half_float' );
  19613. }
  19614. },
  19615. supportsStandardDerivatives: {
  19616. value: function () {
  19617. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  19618. return this.extensions.get( 'OES_standard_derivatives' );
  19619. }
  19620. },
  19621. supportsCompressedTextureS3TC: {
  19622. value: function () {
  19623. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  19624. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  19625. }
  19626. },
  19627. supportsCompressedTexturePVRTC: {
  19628. value: function () {
  19629. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  19630. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  19631. }
  19632. },
  19633. supportsBlendMinMax: {
  19634. value: function () {
  19635. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  19636. return this.extensions.get( 'EXT_blend_minmax' );
  19637. }
  19638. },
  19639. supportsVertexTextures: {
  19640. value: function () {
  19641. return this.capabilities.vertexTextures;
  19642. }
  19643. },
  19644. supportsInstancedArrays: {
  19645. value: function () {
  19646. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  19647. return this.extensions.get( 'ANGLE_instanced_arrays' );
  19648. }
  19649. },
  19650. enableScissorTest: {
  19651. value: function ( boolean ) {
  19652. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  19653. this.setScissorTest( boolean );
  19654. }
  19655. },
  19656. initMaterial: {
  19657. value: function () {
  19658. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  19659. }
  19660. },
  19661. addPrePlugin: {
  19662. value: function () {
  19663. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  19664. }
  19665. },
  19666. addPostPlugin: {
  19667. value: function () {
  19668. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  19669. }
  19670. },
  19671. updateShadowMap: {
  19672. value: function () {
  19673. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  19674. }
  19675. },
  19676. shadowMapEnabled: {
  19677. get: function () {
  19678. return this.shadowMap.enabled;
  19679. },
  19680. set: function ( value ) {
  19681. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  19682. this.shadowMap.enabled = value;
  19683. }
  19684. },
  19685. shadowMapType: {
  19686. get: function () {
  19687. return this.shadowMap.type;
  19688. },
  19689. set: function ( value ) {
  19690. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  19691. this.shadowMap.type = value;
  19692. }
  19693. },
  19694. shadowMapCullFace: {
  19695. get: function () {
  19696. return this.shadowMap.cullFace;
  19697. },
  19698. set: function ( value ) {
  19699. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  19700. this.shadowMap.cullFace = value;
  19701. }
  19702. }
  19703. } );
  19704. //
  19705. Object.defineProperties( THREE.WebGLRenderTarget.prototype, {
  19706. wrapS: {
  19707. get: function () {
  19708. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19709. return this.texture.wrapS;
  19710. },
  19711. set: function ( value ) {
  19712. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19713. this.texture.wrapS = value;
  19714. }
  19715. },
  19716. wrapT: {
  19717. get: function () {
  19718. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19719. return this.texture.wrapT;
  19720. },
  19721. set: function ( value ) {
  19722. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19723. this.texture.wrapT = value;
  19724. }
  19725. },
  19726. magFilter: {
  19727. get: function () {
  19728. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19729. return this.texture.magFilter;
  19730. },
  19731. set: function ( value ) {
  19732. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19733. this.texture.magFilter = value;
  19734. }
  19735. },
  19736. minFilter: {
  19737. get: function () {
  19738. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19739. return this.texture.minFilter;
  19740. },
  19741. set: function ( value ) {
  19742. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19743. this.texture.minFilter = value;
  19744. }
  19745. },
  19746. anisotropy: {
  19747. get: function () {
  19748. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19749. return this.texture.anisotropy;
  19750. },
  19751. set: function ( value ) {
  19752. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19753. this.texture.anisotropy = value;
  19754. }
  19755. },
  19756. offset: {
  19757. get: function () {
  19758. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19759. return this.texture.offset;
  19760. },
  19761. set: function ( value ) {
  19762. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19763. this.texture.offset = value;
  19764. }
  19765. },
  19766. repeat: {
  19767. get: function () {
  19768. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19769. return this.texture.repeat;
  19770. },
  19771. set: function ( value ) {
  19772. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19773. this.texture.repeat = value;
  19774. }
  19775. },
  19776. format: {
  19777. get: function () {
  19778. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19779. return this.texture.format;
  19780. },
  19781. set: function ( value ) {
  19782. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19783. this.texture.format = value;
  19784. }
  19785. },
  19786. type: {
  19787. get: function () {
  19788. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19789. return this.texture.type;
  19790. },
  19791. set: function ( value ) {
  19792. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19793. this.texture.type = value;
  19794. }
  19795. },
  19796. generateMipmaps: {
  19797. get: function () {
  19798. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19799. return this.texture.generateMipmaps;
  19800. },
  19801. set: function ( value ) {
  19802. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19803. this.texture.generateMipmaps = value;
  19804. }
  19805. }
  19806. } );
  19807. //
  19808. THREE.GeometryUtils = {
  19809. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  19810. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  19811. var matrix;
  19812. if ( geometry2 instanceof THREE.Mesh ) {
  19813. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  19814. matrix = geometry2.matrix;
  19815. geometry2 = geometry2.geometry;
  19816. }
  19817. geometry1.merge( geometry2, matrix, materialIndexOffset );
  19818. },
  19819. center: function ( geometry ) {
  19820. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  19821. return geometry.center();
  19822. }
  19823. };
  19824. THREE.ImageUtils = {
  19825. crossOrigin: undefined,
  19826. loadTexture: function ( url, mapping, onLoad, onError ) {
  19827. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  19828. var loader = new THREE.TextureLoader();
  19829. loader.setCrossOrigin( this.crossOrigin );
  19830. var texture = loader.load( url, onLoad, undefined, onError );
  19831. if ( mapping ) texture.mapping = mapping;
  19832. return texture;
  19833. },
  19834. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  19835. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  19836. var loader = new THREE.CubeTextureLoader();
  19837. loader.setCrossOrigin( this.crossOrigin );
  19838. var texture = loader.load( urls, onLoad, undefined, onError );
  19839. if ( mapping ) texture.mapping = mapping;
  19840. return texture;
  19841. },
  19842. loadCompressedTexture: function () {
  19843. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  19844. },
  19845. loadCompressedTextureCube: function () {
  19846. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  19847. }
  19848. };
  19849. //
  19850. THREE.Projector = function () {
  19851. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  19852. this.projectVector = function ( vector, camera ) {
  19853. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  19854. vector.project( camera );
  19855. };
  19856. this.unprojectVector = function ( vector, camera ) {
  19857. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  19858. vector.unproject( camera );
  19859. };
  19860. this.pickingRay = function ( vector, camera ) {
  19861. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  19862. };
  19863. };
  19864. //
  19865. THREE.CanvasRenderer = function () {
  19866. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  19867. this.domElement = document.createElement( 'canvas' );
  19868. this.clear = function () {};
  19869. this.render = function () {};
  19870. this.setClearColor = function () {};
  19871. this.setSize = function () {};
  19872. };
  19873. //
  19874. THREE.MeshFaceMaterial = THREE.MultiMaterial;
  19875. // File:src/extras/CurveUtils.js
  19876. /**
  19877. * @author zz85 / http://www.lab4games.net/zz85/blog
  19878. */
  19879. THREE.CurveUtils = {
  19880. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  19881. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  19882. },
  19883. // Puay Bing, thanks for helping with this derivative!
  19884. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  19885. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  19886. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  19887. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  19888. 3 * t * t * p3;
  19889. },
  19890. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  19891. // To check if my formulas are correct
  19892. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  19893. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  19894. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  19895. var h11 = 3 * t * t - 2 * t; // t3 − t2
  19896. return h00 + h10 + h01 + h11;
  19897. },
  19898. // Catmull-Rom
  19899. interpolate: function( p0, p1, p2, p3, t ) {
  19900. var v0 = ( p2 - p0 ) * 0.5;
  19901. var v1 = ( p3 - p1 ) * 0.5;
  19902. var t2 = t * t;
  19903. var t3 = t * t2;
  19904. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  19905. }
  19906. };
  19907. // File:src/extras/SceneUtils.js
  19908. /**
  19909. * @author alteredq / http://alteredqualia.com/
  19910. */
  19911. THREE.SceneUtils = {
  19912. createMultiMaterialObject: function ( geometry, materials ) {
  19913. var group = new THREE.Group();
  19914. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  19915. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  19916. }
  19917. return group;
  19918. },
  19919. detach: function ( child, parent, scene ) {
  19920. child.applyMatrix( parent.matrixWorld );
  19921. parent.remove( child );
  19922. scene.add( child );
  19923. },
  19924. attach: function ( child, scene, parent ) {
  19925. var matrixWorldInverse = new THREE.Matrix4();
  19926. matrixWorldInverse.getInverse( parent.matrixWorld );
  19927. child.applyMatrix( matrixWorldInverse );
  19928. scene.remove( child );
  19929. parent.add( child );
  19930. }
  19931. };
  19932. // File:src/extras/ShapeUtils.js
  19933. /**
  19934. * @author zz85 / http://www.lab4games.net/zz85/blog
  19935. */
  19936. THREE.ShapeUtils = {
  19937. // calculate area of the contour polygon
  19938. area: function ( contour ) {
  19939. var n = contour.length;
  19940. var a = 0.0;
  19941. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  19942. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  19943. }
  19944. return a * 0.5;
  19945. },
  19946. triangulate: ( function () {
  19947. /**
  19948. * This code is a quick port of code written in C++ which was submitted to
  19949. * flipcode.com by John W. Ratcliff // July 22, 2000
  19950. * See original code and more information here:
  19951. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  19952. *
  19953. * ported to actionscript by Zevan Rosser
  19954. * www.actionsnippet.com
  19955. *
  19956. * ported to javascript by Joshua Koo
  19957. * http://www.lab4games.net/zz85/blog
  19958. *
  19959. */
  19960. function snip( contour, u, v, w, n, verts ) {
  19961. var p;
  19962. var ax, ay, bx, by;
  19963. var cx, cy, px, py;
  19964. ax = contour[ verts[ u ] ].x;
  19965. ay = contour[ verts[ u ] ].y;
  19966. bx = contour[ verts[ v ] ].x;
  19967. by = contour[ verts[ v ] ].y;
  19968. cx = contour[ verts[ w ] ].x;
  19969. cy = contour[ verts[ w ] ].y;
  19970. if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  19971. var aX, aY, bX, bY, cX, cY;
  19972. var apx, apy, bpx, bpy, cpx, cpy;
  19973. var cCROSSap, bCROSScp, aCROSSbp;
  19974. aX = cx - bx; aY = cy - by;
  19975. bX = ax - cx; bY = ay - cy;
  19976. cX = bx - ax; cY = by - ay;
  19977. for ( p = 0; p < n; p ++ ) {
  19978. px = contour[ verts[ p ] ].x;
  19979. py = contour[ verts[ p ] ].y;
  19980. if ( ( ( px === ax ) && ( py === ay ) ) ||
  19981. ( ( px === bx ) && ( py === by ) ) ||
  19982. ( ( px === cx ) && ( py === cy ) ) ) continue;
  19983. apx = px - ax; apy = py - ay;
  19984. bpx = px - bx; bpy = py - by;
  19985. cpx = px - cx; cpy = py - cy;
  19986. // see if p is inside triangle abc
  19987. aCROSSbp = aX * bpy - aY * bpx;
  19988. cCROSSap = cX * apy - cY * apx;
  19989. bCROSScp = bX * cpy - bY * cpx;
  19990. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  19991. }
  19992. return true;
  19993. }
  19994. // takes in an contour array and returns
  19995. return function ( contour, indices ) {
  19996. var n = contour.length;
  19997. if ( n < 3 ) return null;
  19998. var result = [],
  19999. verts = [],
  20000. vertIndices = [];
  20001. /* we want a counter-clockwise polygon in verts */
  20002. var u, v, w;
  20003. if ( THREE.ShapeUtils.area( contour ) > 0.0 ) {
  20004. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  20005. } else {
  20006. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  20007. }
  20008. var nv = n;
  20009. /* remove nv - 2 vertices, creating 1 triangle every time */
  20010. var count = 2 * nv; /* error detection */
  20011. for ( v = nv - 1; nv > 2; ) {
  20012. /* if we loop, it is probably a non-simple polygon */
  20013. if ( ( count -- ) <= 0 ) {
  20014. //** Triangulate: ERROR - probable bad polygon!
  20015. //throw ( "Warning, unable to triangulate polygon!" );
  20016. //return null;
  20017. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  20018. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  20019. if ( indices ) return vertIndices;
  20020. return result;
  20021. }
  20022. /* three consecutive vertices in current polygon, <u,v,w> */
  20023. u = v; if ( nv <= u ) u = 0; /* previous */
  20024. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  20025. w = v + 1; if ( nv <= w ) w = 0; /* next */
  20026. if ( snip( contour, u, v, w, nv, verts ) ) {
  20027. var a, b, c, s, t;
  20028. /* true names of the vertices */
  20029. a = verts[ u ];
  20030. b = verts[ v ];
  20031. c = verts[ w ];
  20032. /* output Triangle */
  20033. result.push( [ contour[ a ],
  20034. contour[ b ],
  20035. contour[ c ] ] );
  20036. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  20037. /* remove v from the remaining polygon */
  20038. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  20039. verts[ s ] = verts[ t ];
  20040. }
  20041. nv --;
  20042. /* reset error detection counter */
  20043. count = 2 * nv;
  20044. }
  20045. }
  20046. if ( indices ) return vertIndices;
  20047. return result;
  20048. }
  20049. } )(),
  20050. triangulateShape: function ( contour, holes ) {
  20051. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  20052. // inOtherPt needs to be collinear to the inSegment
  20053. if ( inSegPt1.x !== inSegPt2.x ) {
  20054. if ( inSegPt1.x < inSegPt2.x ) {
  20055. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  20056. } else {
  20057. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  20058. }
  20059. } else {
  20060. if ( inSegPt1.y < inSegPt2.y ) {
  20061. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  20062. } else {
  20063. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  20064. }
  20065. }
  20066. }
  20067. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  20068. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  20069. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  20070. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  20071. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  20072. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  20073. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  20074. if ( Math.abs( limit ) > Number.EPSILON ) {
  20075. // not parallel
  20076. var perpSeg2;
  20077. if ( limit > 0 ) {
  20078. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  20079. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  20080. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  20081. } else {
  20082. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  20083. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  20084. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  20085. }
  20086. // i.e. to reduce rounding errors
  20087. // intersection at endpoint of segment#1?
  20088. if ( perpSeg2 === 0 ) {
  20089. if ( ( inExcludeAdjacentSegs ) &&
  20090. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  20091. return [ inSeg1Pt1 ];
  20092. }
  20093. if ( perpSeg2 === limit ) {
  20094. if ( ( inExcludeAdjacentSegs ) &&
  20095. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  20096. return [ inSeg1Pt2 ];
  20097. }
  20098. // intersection at endpoint of segment#2?
  20099. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  20100. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  20101. // return real intersection point
  20102. var factorSeg1 = perpSeg2 / limit;
  20103. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  20104. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  20105. } else {
  20106. // parallel or collinear
  20107. if ( ( perpSeg1 !== 0 ) ||
  20108. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  20109. // they are collinear or degenerate
  20110. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  20111. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  20112. // both segments are points
  20113. if ( seg1Pt && seg2Pt ) {
  20114. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  20115. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  20116. return [ inSeg1Pt1 ]; // they are the same point
  20117. }
  20118. // segment#1 is a single point
  20119. if ( seg1Pt ) {
  20120. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  20121. return [ inSeg1Pt1 ];
  20122. }
  20123. // segment#2 is a single point
  20124. if ( seg2Pt ) {
  20125. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  20126. return [ inSeg2Pt1 ];
  20127. }
  20128. // they are collinear segments, which might overlap
  20129. var seg1min, seg1max, seg1minVal, seg1maxVal;
  20130. var seg2min, seg2max, seg2minVal, seg2maxVal;
  20131. if ( seg1dx !== 0 ) {
  20132. // the segments are NOT on a vertical line
  20133. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  20134. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  20135. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  20136. } else {
  20137. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  20138. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  20139. }
  20140. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  20141. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  20142. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  20143. } else {
  20144. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  20145. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  20146. }
  20147. } else {
  20148. // the segments are on a vertical line
  20149. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  20150. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  20151. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  20152. } else {
  20153. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  20154. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  20155. }
  20156. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  20157. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  20158. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  20159. } else {
  20160. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  20161. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  20162. }
  20163. }
  20164. if ( seg1minVal <= seg2minVal ) {
  20165. if ( seg1maxVal < seg2minVal ) return [];
  20166. if ( seg1maxVal === seg2minVal ) {
  20167. if ( inExcludeAdjacentSegs ) return [];
  20168. return [ seg2min ];
  20169. }
  20170. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  20171. return [ seg2min, seg2max ];
  20172. } else {
  20173. if ( seg1minVal > seg2maxVal ) return [];
  20174. if ( seg1minVal === seg2maxVal ) {
  20175. if ( inExcludeAdjacentSegs ) return [];
  20176. return [ seg1min ];
  20177. }
  20178. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  20179. return [ seg1min, seg2max ];
  20180. }
  20181. }
  20182. }
  20183. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  20184. // The order of legs is important
  20185. // translation of all points, so that Vertex is at (0,0)
  20186. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  20187. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  20188. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  20189. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  20190. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  20191. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  20192. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  20193. // angle != 180 deg.
  20194. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  20195. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  20196. if ( from2toAngle > 0 ) {
  20197. // main angle < 180 deg.
  20198. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  20199. } else {
  20200. // main angle > 180 deg.
  20201. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  20202. }
  20203. } else {
  20204. // angle == 180 deg.
  20205. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  20206. return ( from2otherAngle > 0 );
  20207. }
  20208. }
  20209. function removeHoles( contour, holes ) {
  20210. var shape = contour.concat(); // work on this shape
  20211. var hole;
  20212. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  20213. // Check if hole point lies within angle around shape point
  20214. var lastShapeIdx = shape.length - 1;
  20215. var prevShapeIdx = inShapeIdx - 1;
  20216. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  20217. var nextShapeIdx = inShapeIdx + 1;
  20218. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  20219. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  20220. if ( ! insideAngle ) {
  20221. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  20222. return false;
  20223. }
  20224. // Check if shape point lies within angle around hole point
  20225. var lastHoleIdx = hole.length - 1;
  20226. var prevHoleIdx = inHoleIdx - 1;
  20227. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  20228. var nextHoleIdx = inHoleIdx + 1;
  20229. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  20230. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  20231. if ( ! insideAngle ) {
  20232. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  20233. return false;
  20234. }
  20235. return true;
  20236. }
  20237. function intersectsShapeEdge( inShapePt, inHolePt ) {
  20238. // checks for intersections with shape edges
  20239. var sIdx, nextIdx, intersection;
  20240. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  20241. nextIdx = sIdx + 1; nextIdx %= shape.length;
  20242. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  20243. if ( intersection.length > 0 ) return true;
  20244. }
  20245. return false;
  20246. }
  20247. var indepHoles = [];
  20248. function intersectsHoleEdge( inShapePt, inHolePt ) {
  20249. // checks for intersections with hole edges
  20250. var ihIdx, chkHole,
  20251. hIdx, nextIdx, intersection;
  20252. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  20253. chkHole = holes[ indepHoles[ ihIdx ]];
  20254. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  20255. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  20256. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  20257. if ( intersection.length > 0 ) return true;
  20258. }
  20259. }
  20260. return false;
  20261. }
  20262. var holeIndex, shapeIndex,
  20263. shapePt, holePt,
  20264. holeIdx, cutKey, failedCuts = [],
  20265. tmpShape1, tmpShape2,
  20266. tmpHole1, tmpHole2;
  20267. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  20268. indepHoles.push( h );
  20269. }
  20270. var minShapeIndex = 0;
  20271. var counter = indepHoles.length * 2;
  20272. while ( indepHoles.length > 0 ) {
  20273. counter --;
  20274. if ( counter < 0 ) {
  20275. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  20276. break;
  20277. }
  20278. // search for shape-vertex and hole-vertex,
  20279. // which can be connected without intersections
  20280. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  20281. shapePt = shape[ shapeIndex ];
  20282. holeIndex = - 1;
  20283. // search for hole which can be reached without intersections
  20284. for ( var h = 0; h < indepHoles.length; h ++ ) {
  20285. holeIdx = indepHoles[ h ];
  20286. // prevent multiple checks
  20287. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  20288. if ( failedCuts[ cutKey ] !== undefined ) continue;
  20289. hole = holes[ holeIdx ];
  20290. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  20291. holePt = hole[ h2 ];
  20292. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  20293. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  20294. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  20295. holeIndex = h2;
  20296. indepHoles.splice( h, 1 );
  20297. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  20298. tmpShape2 = shape.slice( shapeIndex );
  20299. tmpHole1 = hole.slice( holeIndex );
  20300. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  20301. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  20302. minShapeIndex = shapeIndex;
  20303. // Debug only, to show the selected cuts
  20304. // glob_CutLines.push( [ shapePt, holePt ] );
  20305. break;
  20306. }
  20307. if ( holeIndex >= 0 ) break; // hole-vertex found
  20308. failedCuts[ cutKey ] = true; // remember failure
  20309. }
  20310. if ( holeIndex >= 0 ) break; // hole-vertex found
  20311. }
  20312. }
  20313. return shape; /* shape with no holes */
  20314. }
  20315. var i, il, f, face,
  20316. key, index,
  20317. allPointsMap = {};
  20318. // 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.
  20319. var allpoints = contour.concat();
  20320. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  20321. Array.prototype.push.apply( allpoints, holes[ h ] );
  20322. }
  20323. //console.log( "allpoints",allpoints, allpoints.length );
  20324. // prepare all points map
  20325. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  20326. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  20327. if ( allPointsMap[ key ] !== undefined ) {
  20328. console.warn( "THREE.Shape: Duplicate point", key );
  20329. }
  20330. allPointsMap[ key ] = i;
  20331. }
  20332. // remove holes by cutting paths to holes and adding them to the shape
  20333. var shapeWithoutHoles = removeHoles( contour, holes );
  20334. var triangles = THREE.ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  20335. //console.log( "triangles",triangles, triangles.length );
  20336. // check all face vertices against all points map
  20337. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  20338. face = triangles[ i ];
  20339. for ( f = 0; f < 3; f ++ ) {
  20340. key = face[ f ].x + ":" + face[ f ].y;
  20341. index = allPointsMap[ key ];
  20342. if ( index !== undefined ) {
  20343. face[ f ] = index;
  20344. }
  20345. }
  20346. }
  20347. return triangles.concat();
  20348. },
  20349. isClockWise: function ( pts ) {
  20350. return THREE.ShapeUtils.area( pts ) < 0;
  20351. },
  20352. // Bezier Curves formulas obtained from
  20353. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  20354. // Quad Bezier Functions
  20355. b2: ( function () {
  20356. function b2p0( t, p ) {
  20357. var k = 1 - t;
  20358. return k * k * p;
  20359. }
  20360. function b2p1( t, p ) {
  20361. return 2 * ( 1 - t ) * t * p;
  20362. }
  20363. function b2p2( t, p ) {
  20364. return t * t * p;
  20365. }
  20366. return function ( t, p0, p1, p2 ) {
  20367. return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
  20368. };
  20369. } )(),
  20370. // Cubic Bezier Functions
  20371. b3: ( function () {
  20372. function b3p0( t, p ) {
  20373. var k = 1 - t;
  20374. return k * k * k * p;
  20375. }
  20376. function b3p1( t, p ) {
  20377. var k = 1 - t;
  20378. return 3 * k * k * t * p;
  20379. }
  20380. function b3p2( t, p ) {
  20381. var k = 1 - t;
  20382. return 3 * k * t * t * p;
  20383. }
  20384. function b3p3( t, p ) {
  20385. return t * t * t * p;
  20386. }
  20387. return function ( t, p0, p1, p2, p3 ) {
  20388. return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
  20389. };
  20390. } )()
  20391. };
  20392. // File:src/extras/core/Curve.js
  20393. /**
  20394. * @author zz85 / http://www.lab4games.net/zz85/blog
  20395. * Extensible curve object
  20396. *
  20397. * Some common of Curve methods
  20398. * .getPoint(t), getTangent(t)
  20399. * .getPointAt(u), getTagentAt(u)
  20400. * .getPoints(), .getSpacedPoints()
  20401. * .getLength()
  20402. * .updateArcLengths()
  20403. *
  20404. * This following classes subclasses THREE.Curve:
  20405. *
  20406. * -- 2d classes --
  20407. * THREE.LineCurve
  20408. * THREE.QuadraticBezierCurve
  20409. * THREE.CubicBezierCurve
  20410. * THREE.SplineCurve
  20411. * THREE.ArcCurve
  20412. * THREE.EllipseCurve
  20413. *
  20414. * -- 3d classes --
  20415. * THREE.LineCurve3
  20416. * THREE.QuadraticBezierCurve3
  20417. * THREE.CubicBezierCurve3
  20418. * THREE.SplineCurve3
  20419. * THREE.ClosedSplineCurve3
  20420. *
  20421. * A series of curves can be represented as a THREE.CurvePath
  20422. *
  20423. **/
  20424. /**************************************************************
  20425. * Abstract Curve base class
  20426. **************************************************************/
  20427. THREE.Curve = function () {
  20428. };
  20429. THREE.Curve.prototype = {
  20430. constructor: THREE.Curve,
  20431. // Virtual base class method to overwrite and implement in subclasses
  20432. // - t [0 .. 1]
  20433. getPoint: function ( t ) {
  20434. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  20435. return null;
  20436. },
  20437. // Get point at relative position in curve according to arc length
  20438. // - u [0 .. 1]
  20439. getPointAt: function ( u ) {
  20440. var t = this.getUtoTmapping( u );
  20441. return this.getPoint( t );
  20442. },
  20443. // Get sequence of points using getPoint( t )
  20444. getPoints: function ( divisions ) {
  20445. if ( ! divisions ) divisions = 5;
  20446. var d, pts = [];
  20447. for ( d = 0; d <= divisions; d ++ ) {
  20448. pts.push( this.getPoint( d / divisions ) );
  20449. }
  20450. return pts;
  20451. },
  20452. // Get sequence of points using getPointAt( u )
  20453. getSpacedPoints: function ( divisions ) {
  20454. if ( ! divisions ) divisions = 5;
  20455. var d, pts = [];
  20456. for ( d = 0; d <= divisions; d ++ ) {
  20457. pts.push( this.getPointAt( d / divisions ) );
  20458. }
  20459. return pts;
  20460. },
  20461. // Get total curve arc length
  20462. getLength: function () {
  20463. var lengths = this.getLengths();
  20464. return lengths[ lengths.length - 1 ];
  20465. },
  20466. // Get list of cumulative segment lengths
  20467. getLengths: function ( divisions ) {
  20468. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  20469. if ( this.cacheArcLengths
  20470. && ( this.cacheArcLengths.length === divisions + 1 )
  20471. && ! this.needsUpdate ) {
  20472. //console.log( "cached", this.cacheArcLengths );
  20473. return this.cacheArcLengths;
  20474. }
  20475. this.needsUpdate = false;
  20476. var cache = [];
  20477. var current, last = this.getPoint( 0 );
  20478. var p, sum = 0;
  20479. cache.push( 0 );
  20480. for ( p = 1; p <= divisions; p ++ ) {
  20481. current = this.getPoint ( p / divisions );
  20482. sum += current.distanceTo( last );
  20483. cache.push( sum );
  20484. last = current;
  20485. }
  20486. this.cacheArcLengths = cache;
  20487. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  20488. },
  20489. updateArcLengths: function() {
  20490. this.needsUpdate = true;
  20491. this.getLengths();
  20492. },
  20493. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  20494. getUtoTmapping: function ( u, distance ) {
  20495. var arcLengths = this.getLengths();
  20496. var i = 0, il = arcLengths.length;
  20497. var targetArcLength; // The targeted u distance value to get
  20498. if ( distance ) {
  20499. targetArcLength = distance;
  20500. } else {
  20501. targetArcLength = u * arcLengths[ il - 1 ];
  20502. }
  20503. //var time = Date.now();
  20504. // binary search for the index with largest value smaller than target u distance
  20505. var low = 0, high = il - 1, comparison;
  20506. while ( low <= high ) {
  20507. 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
  20508. comparison = arcLengths[ i ] - targetArcLength;
  20509. if ( comparison < 0 ) {
  20510. low = i + 1;
  20511. } else if ( comparison > 0 ) {
  20512. high = i - 1;
  20513. } else {
  20514. high = i;
  20515. break;
  20516. // DONE
  20517. }
  20518. }
  20519. i = high;
  20520. //console.log('b' , i, low, high, Date.now()- time);
  20521. if ( arcLengths[ i ] === targetArcLength ) {
  20522. var t = i / ( il - 1 );
  20523. return t;
  20524. }
  20525. // we could get finer grain at lengths, or use simple interpolation between two points
  20526. var lengthBefore = arcLengths[ i ];
  20527. var lengthAfter = arcLengths[ i + 1 ];
  20528. var segmentLength = lengthAfter - lengthBefore;
  20529. // determine where we are between the 'before' and 'after' points
  20530. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  20531. // add that fractional amount to t
  20532. var t = ( i + segmentFraction ) / ( il - 1 );
  20533. return t;
  20534. },
  20535. // Returns a unit vector tangent at t
  20536. // In case any sub curve does not implement its tangent derivation,
  20537. // 2 points a small delta apart will be used to find its gradient
  20538. // which seems to give a reasonable approximation
  20539. getTangent: function( t ) {
  20540. var delta = 0.0001;
  20541. var t1 = t - delta;
  20542. var t2 = t + delta;
  20543. // Capping in case of danger
  20544. if ( t1 < 0 ) t1 = 0;
  20545. if ( t2 > 1 ) t2 = 1;
  20546. var pt1 = this.getPoint( t1 );
  20547. var pt2 = this.getPoint( t2 );
  20548. var vec = pt2.clone().sub( pt1 );
  20549. return vec.normalize();
  20550. },
  20551. getTangentAt: function ( u ) {
  20552. var t = this.getUtoTmapping( u );
  20553. return this.getTangent( t );
  20554. }
  20555. };
  20556. // TODO: Transformation for Curves?
  20557. /**************************************************************
  20558. * 3D Curves
  20559. **************************************************************/
  20560. // A Factory method for creating new curve subclasses
  20561. THREE.Curve.create = function ( constructor, getPointFunc ) {
  20562. constructor.prototype = Object.create( THREE.Curve.prototype );
  20563. constructor.prototype.constructor = constructor;
  20564. constructor.prototype.getPoint = getPointFunc;
  20565. return constructor;
  20566. };
  20567. // File:src/extras/core/CurvePath.js
  20568. /**
  20569. * @author zz85 / http://www.lab4games.net/zz85/blog
  20570. *
  20571. **/
  20572. /**************************************************************
  20573. * Curved Path - a curve path is simply a array of connected
  20574. * curves, but retains the api of a curve
  20575. **************************************************************/
  20576. THREE.CurvePath = function () {
  20577. this.curves = [];
  20578. this.autoClose = false; // Automatically closes the path
  20579. };
  20580. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  20581. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  20582. THREE.CurvePath.prototype.add = function ( curve ) {
  20583. this.curves.push( curve );
  20584. };
  20585. /*
  20586. THREE.CurvePath.prototype.checkConnection = function() {
  20587. // TODO
  20588. // If the ending of curve is not connected to the starting
  20589. // or the next curve, then, this is not a real path
  20590. };
  20591. */
  20592. THREE.CurvePath.prototype.closePath = function() {
  20593. // TODO Test
  20594. // and verify for vector3 (needs to implement equals)
  20595. // Add a line curve if start and end of lines are not connected
  20596. var startPoint = this.curves[ 0 ].getPoint( 0 );
  20597. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  20598. if ( ! startPoint.equals( endPoint ) ) {
  20599. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  20600. }
  20601. };
  20602. // To get accurate point with reference to
  20603. // entire path distance at time t,
  20604. // following has to be done:
  20605. // 1. Length of each sub path have to be known
  20606. // 2. Locate and identify type of curve
  20607. // 3. Get t for the curve
  20608. // 4. Return curve.getPointAt(t')
  20609. THREE.CurvePath.prototype.getPoint = function( t ) {
  20610. var d = t * this.getLength();
  20611. var curveLengths = this.getCurveLengths();
  20612. var i = 0;
  20613. // To think about boundaries points.
  20614. while ( i < curveLengths.length ) {
  20615. if ( curveLengths[ i ] >= d ) {
  20616. var diff = curveLengths[ i ] - d;
  20617. var curve = this.curves[ i ];
  20618. var u = 1 - diff / curve.getLength();
  20619. return curve.getPointAt( u );
  20620. }
  20621. i ++;
  20622. }
  20623. return null;
  20624. // loop where sum != 0, sum > d , sum+1 <d
  20625. };
  20626. /*
  20627. THREE.CurvePath.prototype.getTangent = function( t ) {
  20628. };
  20629. */
  20630. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  20631. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  20632. // getPoint() depends on getLength
  20633. THREE.CurvePath.prototype.getLength = function() {
  20634. var lens = this.getCurveLengths();
  20635. return lens[ lens.length - 1 ];
  20636. };
  20637. // Compute lengths and cache them
  20638. // We cannot overwrite getLengths() because UtoT mapping uses it.
  20639. THREE.CurvePath.prototype.getCurveLengths = function() {
  20640. // We use cache values if curves and cache array are same length
  20641. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  20642. return this.cacheLengths;
  20643. }
  20644. // Get length of sub-curve
  20645. // Push sums into cached array
  20646. var lengths = [], sums = 0;
  20647. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  20648. sums += this.curves[ i ].getLength();
  20649. lengths.push( sums );
  20650. }
  20651. this.cacheLengths = lengths;
  20652. return lengths;
  20653. };
  20654. /**************************************************************
  20655. * Create Geometries Helpers
  20656. **************************************************************/
  20657. /// Generate geometry from path points (for Line or Points objects)
  20658. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  20659. var pts = this.getPoints( divisions );
  20660. return this.createGeometry( pts );
  20661. };
  20662. // Generate geometry from equidistant sampling along the path
  20663. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  20664. var pts = this.getSpacedPoints( divisions );
  20665. return this.createGeometry( pts );
  20666. };
  20667. THREE.CurvePath.prototype.createGeometry = function( points ) {
  20668. var geometry = new THREE.Geometry();
  20669. for ( var i = 0, l = points.length; i < l; i ++ ) {
  20670. var point = points[ i ];
  20671. geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
  20672. }
  20673. return geometry;
  20674. };
  20675. // File:src/extras/core/Font.js
  20676. /**
  20677. * @author zz85 / http://www.lab4games.net/zz85/blog
  20678. * @author mrdoob / http://mrdoob.com/
  20679. */
  20680. THREE.Font = function ( data ) {
  20681. this.data = data;
  20682. };
  20683. THREE.Font.prototype = {
  20684. constructor: THREE.Font,
  20685. generateShapes: function ( text, size, divisions ) {
  20686. function createPaths( text ) {
  20687. var chars = String( text ).split( '' );
  20688. var scale = size / data.resolution;
  20689. var offset = 0;
  20690. var paths = [];
  20691. for ( var i = 0; i < chars.length; i ++ ) {
  20692. var ret = createPath( chars[ i ], scale, offset );
  20693. offset += ret.offset;
  20694. paths.push( ret.path );
  20695. }
  20696. return paths;
  20697. }
  20698. function createPath( c, scale, offset ) {
  20699. var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
  20700. if ( ! glyph ) return;
  20701. var path = new THREE.Path();
  20702. var pts = [], b2 = THREE.ShapeUtils.b2, b3 = THREE.ShapeUtils.b3;
  20703. var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
  20704. if ( glyph.o ) {
  20705. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  20706. for ( var i = 0, l = outline.length; i < l; ) {
  20707. var action = outline[ i ++ ];
  20708. switch ( action ) {
  20709. case 'm': // moveTo
  20710. x = outline[ i ++ ] * scale + offset;
  20711. y = outline[ i ++ ] * scale;
  20712. path.moveTo( x, y );
  20713. break;
  20714. case 'l': // lineTo
  20715. x = outline[ i ++ ] * scale + offset;
  20716. y = outline[ i ++ ] * scale;
  20717. path.lineTo( x, y );
  20718. break;
  20719. case 'q': // quadraticCurveTo
  20720. cpx = outline[ i ++ ] * scale + offset;
  20721. cpy = outline[ i ++ ] * scale;
  20722. cpx1 = outline[ i ++ ] * scale + offset;
  20723. cpy1 = outline[ i ++ ] * scale;
  20724. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  20725. laste = pts[ pts.length - 1 ];
  20726. if ( laste ) {
  20727. cpx0 = laste.x;
  20728. cpy0 = laste.y;
  20729. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  20730. var t = i2 / divisions;
  20731. b2( t, cpx0, cpx1, cpx );
  20732. b2( t, cpy0, cpy1, cpy );
  20733. }
  20734. }
  20735. break;
  20736. case 'b': // bezierCurveTo
  20737. cpx = outline[ i ++ ] * scale + offset;
  20738. cpy = outline[ i ++ ] * scale;
  20739. cpx1 = outline[ i ++ ] * scale + offset;
  20740. cpy1 = outline[ i ++ ] * scale;
  20741. cpx2 = outline[ i ++ ] * scale + offset;
  20742. cpy2 = outline[ i ++ ] * scale;
  20743. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  20744. laste = pts[ pts.length - 1 ];
  20745. if ( laste ) {
  20746. cpx0 = laste.x;
  20747. cpy0 = laste.y;
  20748. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  20749. var t = i2 / divisions;
  20750. b3( t, cpx0, cpx1, cpx2, cpx );
  20751. b3( t, cpy0, cpy1, cpy2, cpy );
  20752. }
  20753. }
  20754. break;
  20755. }
  20756. }
  20757. }
  20758. return { offset: glyph.ha * scale, path: path };
  20759. }
  20760. //
  20761. if ( size === undefined ) size = 100;
  20762. if ( divisions === undefined ) divisions = 4;
  20763. var data = this.data;
  20764. var paths = createPaths( text );
  20765. var shapes = [];
  20766. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  20767. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  20768. }
  20769. return shapes;
  20770. }
  20771. };
  20772. // File:src/extras/core/Path.js
  20773. /**
  20774. * @author zz85 / http://www.lab4games.net/zz85/blog
  20775. * Creates free form 2d path using series of points, lines or curves.
  20776. *
  20777. **/
  20778. THREE.Path = function ( points ) {
  20779. THREE.CurvePath.call( this );
  20780. this.actions = [];
  20781. if ( points ) {
  20782. this.fromPoints( points );
  20783. }
  20784. };
  20785. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  20786. THREE.Path.prototype.constructor = THREE.Path;
  20787. // TODO Clean up PATH API
  20788. // Create path using straight lines to connect all points
  20789. // - vectors: array of Vector2
  20790. THREE.Path.prototype.fromPoints = function ( vectors ) {
  20791. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  20792. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  20793. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  20794. }
  20795. };
  20796. // startPath() endPath()?
  20797. THREE.Path.prototype.moveTo = function ( x, y ) {
  20798. this.actions.push( { action: 'moveTo', args: [ x, y ] } );
  20799. };
  20800. THREE.Path.prototype.lineTo = function ( x, y ) {
  20801. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20802. var x0 = lastargs[ lastargs.length - 2 ];
  20803. var y0 = lastargs[ lastargs.length - 1 ];
  20804. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  20805. this.curves.push( curve );
  20806. this.actions.push( { action: 'lineTo', args: [ x, y ] } );
  20807. };
  20808. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  20809. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20810. var x0 = lastargs[ lastargs.length - 2 ];
  20811. var y0 = lastargs[ lastargs.length - 1 ];
  20812. var curve = new THREE.QuadraticBezierCurve(
  20813. new THREE.Vector2( x0, y0 ),
  20814. new THREE.Vector2( aCPx, aCPy ),
  20815. new THREE.Vector2( aX, aY )
  20816. );
  20817. this.curves.push( curve );
  20818. this.actions.push( { action: 'quadraticCurveTo', args: [ aCPx, aCPy, aX, aY ] } );
  20819. };
  20820. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  20821. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20822. var x0 = lastargs[ lastargs.length - 2 ];
  20823. var y0 = lastargs[ lastargs.length - 1 ];
  20824. var curve = new THREE.CubicBezierCurve(
  20825. new THREE.Vector2( x0, y0 ),
  20826. new THREE.Vector2( aCP1x, aCP1y ),
  20827. new THREE.Vector2( aCP2x, aCP2y ),
  20828. new THREE.Vector2( aX, aY )
  20829. );
  20830. this.curves.push( curve );
  20831. this.actions.push( { action: 'bezierCurveTo', args: [ aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ] } );
  20832. };
  20833. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  20834. var args = Array.prototype.slice.call( arguments );
  20835. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20836. var x0 = lastargs[ lastargs.length - 2 ];
  20837. var y0 = lastargs[ lastargs.length - 1 ];
  20838. var npts = [ new THREE.Vector2( x0, y0 ) ];
  20839. Array.prototype.push.apply( npts, pts );
  20840. var curve = new THREE.SplineCurve( npts );
  20841. this.curves.push( curve );
  20842. this.actions.push( { action: 'splineThru', args: args } );
  20843. };
  20844. // FUTURE: Change the API or follow canvas API?
  20845. THREE.Path.prototype.arc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20846. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20847. var x0 = lastargs[ lastargs.length - 2 ];
  20848. var y0 = lastargs[ lastargs.length - 1 ];
  20849. this.absarc( aX + x0, aY + y0, aRadius,
  20850. aStartAngle, aEndAngle, aClockwise );
  20851. };
  20852. THREE.Path.prototype.absarc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20853. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  20854. };
  20855. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20856. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20857. var x0 = lastargs[ lastargs.length - 2 ];
  20858. var y0 = lastargs[ lastargs.length - 1 ];
  20859. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20860. };
  20861. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20862. var args = [
  20863. aX, aY,
  20864. xRadius, yRadius,
  20865. aStartAngle, aEndAngle,
  20866. aClockwise,
  20867. aRotation || 0 // aRotation is optional.
  20868. ];
  20869. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20870. this.curves.push( curve );
  20871. var lastPoint = curve.getPoint( 1 );
  20872. args.push( lastPoint.x );
  20873. args.push( lastPoint.y );
  20874. this.actions.push( { action: 'ellipse', args: args } );
  20875. };
  20876. THREE.Path.prototype.getSpacedPoints = function ( divisions ) {
  20877. if ( ! divisions ) divisions = 40;
  20878. var points = [];
  20879. for ( var i = 0; i < divisions; i ++ ) {
  20880. points.push( this.getPoint( i / divisions ) );
  20881. //if ( !this.getPoint( i / divisions ) ) throw "DIE";
  20882. }
  20883. if ( this.autoClose ) {
  20884. points.push( points[ 0 ] );
  20885. }
  20886. return points;
  20887. };
  20888. /* Return an array of vectors based on contour of the path */
  20889. THREE.Path.prototype.getPoints = function( divisions ) {
  20890. divisions = divisions || 12;
  20891. var b2 = THREE.ShapeUtils.b2;
  20892. var b3 = THREE.ShapeUtils.b3;
  20893. var points = [];
  20894. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  20895. laste, tx, ty;
  20896. for ( var i = 0, l = this.actions.length; i < l; i ++ ) {
  20897. var item = this.actions[ i ];
  20898. var action = item.action;
  20899. var args = item.args;
  20900. switch ( action ) {
  20901. case 'moveTo':
  20902. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20903. break;
  20904. case 'lineTo':
  20905. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20906. break;
  20907. case 'quadraticCurveTo':
  20908. cpx = args[ 2 ];
  20909. cpy = args[ 3 ];
  20910. cpx1 = args[ 0 ];
  20911. cpy1 = args[ 1 ];
  20912. if ( points.length > 0 ) {
  20913. laste = points[ points.length - 1 ];
  20914. cpx0 = laste.x;
  20915. cpy0 = laste.y;
  20916. } else {
  20917. laste = this.actions[ i - 1 ].args;
  20918. cpx0 = laste[ laste.length - 2 ];
  20919. cpy0 = laste[ laste.length - 1 ];
  20920. }
  20921. for ( var j = 1; j <= divisions; j ++ ) {
  20922. var t = j / divisions;
  20923. tx = b2( t, cpx0, cpx1, cpx );
  20924. ty = b2( t, cpy0, cpy1, cpy );
  20925. points.push( new THREE.Vector2( tx, ty ) );
  20926. }
  20927. break;
  20928. case 'bezierCurveTo':
  20929. cpx = args[ 4 ];
  20930. cpy = args[ 5 ];
  20931. cpx1 = args[ 0 ];
  20932. cpy1 = args[ 1 ];
  20933. cpx2 = args[ 2 ];
  20934. cpy2 = args[ 3 ];
  20935. if ( points.length > 0 ) {
  20936. laste = points[ points.length - 1 ];
  20937. cpx0 = laste.x;
  20938. cpy0 = laste.y;
  20939. } else {
  20940. laste = this.actions[ i - 1 ].args;
  20941. cpx0 = laste[ laste.length - 2 ];
  20942. cpy0 = laste[ laste.length - 1 ];
  20943. }
  20944. for ( var j = 1; j <= divisions; j ++ ) {
  20945. var t = j / divisions;
  20946. tx = b3( t, cpx0, cpx1, cpx2, cpx );
  20947. ty = b3( t, cpy0, cpy1, cpy2, cpy );
  20948. points.push( new THREE.Vector2( tx, ty ) );
  20949. }
  20950. break;
  20951. case 'splineThru':
  20952. laste = this.actions[ i - 1 ].args;
  20953. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  20954. var spts = [ last ];
  20955. var n = divisions * args[ 0 ].length;
  20956. spts = spts.concat( args[ 0 ] );
  20957. var spline = new THREE.SplineCurve( spts );
  20958. for ( var j = 1; j <= n; j ++ ) {
  20959. points.push( spline.getPointAt( j / n ) );
  20960. }
  20961. break;
  20962. case 'arc':
  20963. var aX = args[ 0 ], aY = args[ 1 ],
  20964. aRadius = args[ 2 ],
  20965. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  20966. aClockwise = !! args[ 5 ];
  20967. var deltaAngle = aEndAngle - aStartAngle;
  20968. var angle;
  20969. var tdivisions = divisions * 2;
  20970. for ( var j = 1; j <= tdivisions; j ++ ) {
  20971. var t = j / tdivisions;
  20972. if ( ! aClockwise ) {
  20973. t = 1 - t;
  20974. }
  20975. angle = aStartAngle + t * deltaAngle;
  20976. tx = aX + aRadius * Math.cos( angle );
  20977. ty = aY + aRadius * Math.sin( angle );
  20978. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  20979. points.push( new THREE.Vector2( tx, ty ) );
  20980. }
  20981. //console.log(points);
  20982. break;
  20983. case 'ellipse':
  20984. var aX = args[ 0 ], aY = args[ 1 ],
  20985. xRadius = args[ 2 ],
  20986. yRadius = args[ 3 ],
  20987. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  20988. aClockwise = !! args[ 6 ],
  20989. aRotation = args[ 7 ];
  20990. var deltaAngle = aEndAngle - aStartAngle;
  20991. var angle;
  20992. var tdivisions = divisions * 2;
  20993. var cos, sin;
  20994. if ( aRotation !== 0 ) {
  20995. cos = Math.cos( aRotation );
  20996. sin = Math.sin( aRotation );
  20997. }
  20998. for ( var j = 1; j <= tdivisions; j ++ ) {
  20999. var t = j / tdivisions;
  21000. if ( ! aClockwise ) {
  21001. t = 1 - t;
  21002. }
  21003. angle = aStartAngle + t * deltaAngle;
  21004. tx = aX + xRadius * Math.cos( angle );
  21005. ty = aY + yRadius * Math.sin( angle );
  21006. if ( aRotation !== 0 ) {
  21007. var x = tx, y = ty;
  21008. // Rotate the point about the center of the ellipse.
  21009. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  21010. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  21011. }
  21012. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  21013. points.push( new THREE.Vector2( tx, ty ) );
  21014. }
  21015. //console.log(points);
  21016. break;
  21017. } // end switch
  21018. }
  21019. // Normalize to remove the closing point by default.
  21020. var lastPoint = points[ points.length - 1 ];
  21021. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < Number.EPSILON &&
  21022. Math.abs( lastPoint.y - points[ 0 ].y ) < Number.EPSILON )
  21023. points.splice( points.length - 1, 1 );
  21024. if ( this.autoClose ) {
  21025. points.push( points[ 0 ] );
  21026. }
  21027. return points;
  21028. };
  21029. //
  21030. // Breaks path into shapes
  21031. //
  21032. // Assumptions (if parameter isCCW==true the opposite holds):
  21033. // - solid shapes are defined clockwise (CW)
  21034. // - holes are defined counterclockwise (CCW)
  21035. //
  21036. // If parameter noHoles==true:
  21037. // - all subPaths are regarded as solid shapes
  21038. // - definition order CW/CCW has no relevance
  21039. //
  21040. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  21041. function extractSubpaths( inActions ) {
  21042. var subPaths = [], lastPath = new THREE.Path();
  21043. for ( var i = 0, l = inActions.length; i < l; i ++ ) {
  21044. var item = inActions[ i ];
  21045. var args = item.args;
  21046. var action = item.action;
  21047. if ( action === 'moveTo' ) {
  21048. if ( lastPath.actions.length !== 0 ) {
  21049. subPaths.push( lastPath );
  21050. lastPath = new THREE.Path();
  21051. }
  21052. }
  21053. lastPath[ action ].apply( lastPath, args );
  21054. }
  21055. if ( lastPath.actions.length !== 0 ) {
  21056. subPaths.push( lastPath );
  21057. }
  21058. // console.log(subPaths);
  21059. return subPaths;
  21060. }
  21061. function toShapesNoHoles( inSubpaths ) {
  21062. var shapes = [];
  21063. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  21064. var tmpPath = inSubpaths[ i ];
  21065. var tmpShape = new THREE.Shape();
  21066. tmpShape.actions = tmpPath.actions;
  21067. tmpShape.curves = tmpPath.curves;
  21068. shapes.push( tmpShape );
  21069. }
  21070. //console.log("shape", shapes);
  21071. return shapes;
  21072. }
  21073. function isPointInsidePolygon( inPt, inPolygon ) {
  21074. var polyLen = inPolygon.length;
  21075. // inPt on polygon contour => immediate success or
  21076. // toggling of inside/outside at every single! intersection point of an edge
  21077. // with the horizontal line through inPt, left of inPt
  21078. // not counting lowerY endpoints of edges and whole edges on that line
  21079. var inside = false;
  21080. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  21081. var edgeLowPt = inPolygon[ p ];
  21082. var edgeHighPt = inPolygon[ q ];
  21083. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  21084. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  21085. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  21086. // not parallel
  21087. if ( edgeDy < 0 ) {
  21088. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  21089. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  21090. }
  21091. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  21092. if ( inPt.y === edgeLowPt.y ) {
  21093. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  21094. // continue; // no intersection or edgeLowPt => doesn't count !!!
  21095. } else {
  21096. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  21097. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  21098. if ( perpEdge < 0 ) continue;
  21099. inside = ! inside; // true intersection left of inPt
  21100. }
  21101. } else {
  21102. // parallel or collinear
  21103. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  21104. // edge lies on the same horizontal line as inPt
  21105. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  21106. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  21107. // continue;
  21108. }
  21109. }
  21110. return inside;
  21111. }
  21112. var isClockWise = THREE.ShapeUtils.isClockWise;
  21113. var subPaths = extractSubpaths( this.actions );
  21114. if ( subPaths.length === 0 ) return [];
  21115. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  21116. var solid, tmpPath, tmpShape, shapes = [];
  21117. if ( subPaths.length === 1 ) {
  21118. tmpPath = subPaths[ 0 ];
  21119. tmpShape = new THREE.Shape();
  21120. tmpShape.actions = tmpPath.actions;
  21121. tmpShape.curves = tmpPath.curves;
  21122. shapes.push( tmpShape );
  21123. return shapes;
  21124. }
  21125. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  21126. holesFirst = isCCW ? ! holesFirst : holesFirst;
  21127. // console.log("Holes first", holesFirst);
  21128. var betterShapeHoles = [];
  21129. var newShapes = [];
  21130. var newShapeHoles = [];
  21131. var mainIdx = 0;
  21132. var tmpPoints;
  21133. newShapes[ mainIdx ] = undefined;
  21134. newShapeHoles[ mainIdx ] = [];
  21135. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  21136. tmpPath = subPaths[ i ];
  21137. tmpPoints = tmpPath.getPoints();
  21138. solid = isClockWise( tmpPoints );
  21139. solid = isCCW ? ! solid : solid;
  21140. if ( solid ) {
  21141. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  21142. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  21143. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  21144. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  21145. if ( holesFirst ) mainIdx ++;
  21146. newShapeHoles[ mainIdx ] = [];
  21147. //console.log('cw', i);
  21148. } else {
  21149. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  21150. //console.log('ccw', i);
  21151. }
  21152. }
  21153. // only Holes? -> probably all Shapes with wrong orientation
  21154. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  21155. if ( newShapes.length > 1 ) {
  21156. var ambiguous = false;
  21157. var toChange = [];
  21158. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21159. betterShapeHoles[ sIdx ] = [];
  21160. }
  21161. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21162. var sho = newShapeHoles[ sIdx ];
  21163. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  21164. var ho = sho[ hIdx ];
  21165. var hole_unassigned = true;
  21166. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  21167. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  21168. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  21169. if ( hole_unassigned ) {
  21170. hole_unassigned = false;
  21171. betterShapeHoles[ s2Idx ].push( ho );
  21172. } else {
  21173. ambiguous = true;
  21174. }
  21175. }
  21176. }
  21177. if ( hole_unassigned ) {
  21178. betterShapeHoles[ sIdx ].push( ho );
  21179. }
  21180. }
  21181. }
  21182. // console.log("ambiguous: ", ambiguous);
  21183. if ( toChange.length > 0 ) {
  21184. // console.log("to change: ", toChange);
  21185. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  21186. }
  21187. }
  21188. var tmpHoles;
  21189. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  21190. tmpShape = newShapes[ i ].s;
  21191. shapes.push( tmpShape );
  21192. tmpHoles = newShapeHoles[ i ];
  21193. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  21194. tmpShape.holes.push( tmpHoles[ j ].h );
  21195. }
  21196. }
  21197. //console.log("shape", shapes);
  21198. return shapes;
  21199. };
  21200. // File:src/extras/core/Shape.js
  21201. /**
  21202. * @author zz85 / http://www.lab4games.net/zz85/blog
  21203. * Defines a 2d shape plane using paths.
  21204. **/
  21205. // STEP 1 Create a path.
  21206. // STEP 2 Turn path into shape.
  21207. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  21208. // STEP 3a - Extract points from each shape, turn to vertices
  21209. // STEP 3b - Triangulate each shape, add faces.
  21210. THREE.Shape = function () {
  21211. THREE.Path.apply( this, arguments );
  21212. this.holes = [];
  21213. };
  21214. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  21215. THREE.Shape.prototype.constructor = THREE.Shape;
  21216. // Convenience method to return ExtrudeGeometry
  21217. THREE.Shape.prototype.extrude = function ( options ) {
  21218. return new THREE.ExtrudeGeometry( this, options );
  21219. };
  21220. // Convenience method to return ShapeGeometry
  21221. THREE.Shape.prototype.makeGeometry = function ( options ) {
  21222. return new THREE.ShapeGeometry( this, options );
  21223. };
  21224. // Get points of holes
  21225. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  21226. var holesPts = [];
  21227. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  21228. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  21229. }
  21230. return holesPts;
  21231. };
  21232. // Get points of shape and holes (keypoints based on segments parameter)
  21233. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  21234. return {
  21235. shape: this.getPoints( divisions ),
  21236. holes: this.getPointsHoles( divisions )
  21237. };
  21238. };
  21239. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  21240. return this.extractAllPoints( divisions );
  21241. };
  21242. // File:src/extras/curves/LineCurve.js
  21243. /**************************************************************
  21244. * Line
  21245. **************************************************************/
  21246. THREE.LineCurve = function ( v1, v2 ) {
  21247. this.v1 = v1;
  21248. this.v2 = v2;
  21249. };
  21250. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  21251. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  21252. THREE.LineCurve.prototype.getPoint = function ( t ) {
  21253. var point = this.v2.clone().sub( this.v1 );
  21254. point.multiplyScalar( t ).add( this.v1 );
  21255. return point;
  21256. };
  21257. // Line curve is linear, so we can overwrite default getPointAt
  21258. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  21259. return this.getPoint( u );
  21260. };
  21261. THREE.LineCurve.prototype.getTangent = function( t ) {
  21262. var tangent = this.v2.clone().sub( this.v1 );
  21263. return tangent.normalize();
  21264. };
  21265. // File:src/extras/curves/QuadraticBezierCurve.js
  21266. /**************************************************************
  21267. * Quadratic Bezier curve
  21268. **************************************************************/
  21269. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  21270. this.v0 = v0;
  21271. this.v1 = v1;
  21272. this.v2 = v2;
  21273. };
  21274. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  21275. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  21276. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  21277. var b2 = THREE.ShapeUtils.b2;
  21278. return new THREE.Vector2(
  21279. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21280. b2( t, this.v0.y, this.v1.y, this.v2.y )
  21281. );
  21282. };
  21283. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  21284. var tangentQuadraticBezier = THREE.CurveUtils.tangentQuadraticBezier;
  21285. return new THREE.Vector2(
  21286. tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x ),
  21287. tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y )
  21288. ).normalize();
  21289. };
  21290. // File:src/extras/curves/CubicBezierCurve.js
  21291. /**************************************************************
  21292. * Cubic Bezier curve
  21293. **************************************************************/
  21294. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  21295. this.v0 = v0;
  21296. this.v1 = v1;
  21297. this.v2 = v2;
  21298. this.v3 = v3;
  21299. };
  21300. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  21301. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  21302. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  21303. var b3 = THREE.ShapeUtils.b3;
  21304. return new THREE.Vector2(
  21305. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21306. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  21307. );
  21308. };
  21309. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  21310. var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
  21311. return new THREE.Vector2(
  21312. tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21313. tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  21314. ).normalize();
  21315. };
  21316. // File:src/extras/curves/SplineCurve.js
  21317. /**************************************************************
  21318. * Spline curve
  21319. **************************************************************/
  21320. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  21321. this.points = ( points == undefined ) ? [] : points;
  21322. };
  21323. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  21324. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  21325. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  21326. var points = this.points;
  21327. var point = ( points.length - 1 ) * t;
  21328. var intPoint = Math.floor( point );
  21329. var weight = point - intPoint;
  21330. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21331. var point1 = points[ intPoint ];
  21332. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21333. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21334. var interpolate = THREE.CurveUtils.interpolate;
  21335. return new THREE.Vector2(
  21336. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21337. interpolate( point0.y, point1.y, point2.y, point3.y, weight )
  21338. );
  21339. };
  21340. // File:src/extras/curves/EllipseCurve.js
  21341. /**************************************************************
  21342. * Ellipse curve
  21343. **************************************************************/
  21344. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21345. this.aX = aX;
  21346. this.aY = aY;
  21347. this.xRadius = xRadius;
  21348. this.yRadius = yRadius;
  21349. this.aStartAngle = aStartAngle;
  21350. this.aEndAngle = aEndAngle;
  21351. this.aClockwise = aClockwise;
  21352. this.aRotation = aRotation || 0;
  21353. };
  21354. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  21355. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  21356. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  21357. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21358. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  21359. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  21360. var angle;
  21361. if ( this.aClockwise === true ) {
  21362. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  21363. } else {
  21364. angle = this.aStartAngle + t * deltaAngle;
  21365. }
  21366. var x = this.aX + this.xRadius * Math.cos( angle );
  21367. var y = this.aY + this.yRadius * Math.sin( angle );
  21368. if ( this.aRotation !== 0 ) {
  21369. var cos = Math.cos( this.aRotation );
  21370. var sin = Math.sin( this.aRotation );
  21371. var tx = x, ty = y;
  21372. // Rotate the point about the center of the ellipse.
  21373. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  21374. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  21375. }
  21376. return new THREE.Vector2( x, y );
  21377. };
  21378. // File:src/extras/curves/ArcCurve.js
  21379. /**************************************************************
  21380. * Arc curve
  21381. **************************************************************/
  21382. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21383. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21384. };
  21385. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  21386. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  21387. // File:src/extras/curves/LineCurve3.js
  21388. /**************************************************************
  21389. * Line3D
  21390. **************************************************************/
  21391. THREE.LineCurve3 = THREE.Curve.create(
  21392. function ( v1, v2 ) {
  21393. this.v1 = v1;
  21394. this.v2 = v2;
  21395. },
  21396. function ( t ) {
  21397. var vector = new THREE.Vector3();
  21398. vector.subVectors( this.v2, this.v1 ); // diff
  21399. vector.multiplyScalar( t );
  21400. vector.add( this.v1 );
  21401. return vector;
  21402. }
  21403. );
  21404. // File:src/extras/curves/QuadraticBezierCurve3.js
  21405. /**************************************************************
  21406. * Quadratic Bezier 3D curve
  21407. **************************************************************/
  21408. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  21409. function ( v0, v1, v2 ) {
  21410. this.v0 = v0;
  21411. this.v1 = v1;
  21412. this.v2 = v2;
  21413. },
  21414. function ( t ) {
  21415. var b2 = THREE.ShapeUtils.b2;
  21416. return new THREE.Vector3(
  21417. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21418. b2( t, this.v0.y, this.v1.y, this.v2.y ),
  21419. b2( t, this.v0.z, this.v1.z, this.v2.z )
  21420. );
  21421. }
  21422. );
  21423. // File:src/extras/curves/CubicBezierCurve3.js
  21424. /**************************************************************
  21425. * Cubic Bezier 3D curve
  21426. **************************************************************/
  21427. THREE.CubicBezierCurve3 = THREE.Curve.create(
  21428. function ( v0, v1, v2, v3 ) {
  21429. this.v0 = v0;
  21430. this.v1 = v1;
  21431. this.v2 = v2;
  21432. this.v3 = v3;
  21433. },
  21434. function ( t ) {
  21435. var b3 = THREE.ShapeUtils.b3;
  21436. return new THREE.Vector3(
  21437. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21438. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
  21439. b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z )
  21440. );
  21441. }
  21442. );
  21443. // File:src/extras/curves/SplineCurve3.js
  21444. /**************************************************************
  21445. * Spline 3D curve
  21446. **************************************************************/
  21447. THREE.SplineCurve3 = THREE.Curve.create(
  21448. function ( points /* array of Vector3 */ ) {
  21449. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  21450. this.points = ( points == undefined ) ? [] : points;
  21451. },
  21452. function ( t ) {
  21453. var points = this.points;
  21454. var point = ( points.length - 1 ) * t;
  21455. var intPoint = Math.floor( point );
  21456. var weight = point - intPoint;
  21457. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  21458. var point1 = points[ intPoint ];
  21459. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21460. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21461. var interpolate = THREE.CurveUtils.interpolate;
  21462. return new THREE.Vector3(
  21463. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21464. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  21465. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  21466. );
  21467. }
  21468. );
  21469. // File:src/extras/curves/CatmullRomCurve3.js
  21470. /**
  21471. * @author zz85 https://github.com/zz85
  21472. *
  21473. * Centripetal CatmullRom Curve - which is useful for avoiding
  21474. * cusps and self-intersections in non-uniform catmull rom curves.
  21475. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21476. *
  21477. * curve.type accepts centripetal(default), chordal and catmullrom
  21478. * curve.tension is used for catmullrom which defaults to 0.5
  21479. */
  21480. THREE.CatmullRomCurve3 = ( function() {
  21481. var
  21482. tmp = new THREE.Vector3(),
  21483. px = new CubicPoly(),
  21484. py = new CubicPoly(),
  21485. pz = new CubicPoly();
  21486. /*
  21487. Based on an optimized c++ solution in
  21488. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21489. - http://ideone.com/NoEbVM
  21490. This CubicPoly class could be used for reusing some variables and calculations,
  21491. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21492. which can be placed in CurveUtils.
  21493. */
  21494. function CubicPoly() {
  21495. }
  21496. /*
  21497. * Compute coefficients for a cubic polynomial
  21498. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21499. * such that
  21500. * p(0) = x0, p(1) = x1
  21501. * and
  21502. * p'(0) = t0, p'(1) = t1.
  21503. */
  21504. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  21505. this.c0 = x0;
  21506. this.c1 = t0;
  21507. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21508. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21509. };
  21510. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21511. // compute tangents when parameterized in [t1,t2]
  21512. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21513. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21514. // rescale tangents for parametrization in [0,1]
  21515. t1 *= dt1;
  21516. t2 *= dt1;
  21517. // initCubicPoly
  21518. this.init( x1, x2, t1, t2 );
  21519. };
  21520. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  21521. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  21522. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21523. };
  21524. CubicPoly.prototype.calc = function( t ) {
  21525. var t2 = t * t;
  21526. var t3 = t2 * t;
  21527. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  21528. };
  21529. // Subclass Three.js curve
  21530. return THREE.Curve.create(
  21531. function ( p /* array of Vector3 */ ) {
  21532. this.points = p || [];
  21533. this.closed = false;
  21534. },
  21535. function ( t ) {
  21536. var points = this.points,
  21537. point, intPoint, weight, l;
  21538. l = points.length;
  21539. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  21540. point = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21541. intPoint = Math.floor( point );
  21542. weight = point - intPoint;
  21543. if ( this.closed ) {
  21544. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  21545. } else if ( weight === 0 && intPoint === l - 1 ) {
  21546. intPoint = l - 2;
  21547. weight = 1;
  21548. }
  21549. var p0, p1, p2, p3; // 4 points
  21550. if ( this.closed || intPoint > 0 ) {
  21551. p0 = points[ ( intPoint - 1 ) % l ];
  21552. } else {
  21553. // extrapolate first point
  21554. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21555. p0 = tmp;
  21556. }
  21557. p1 = points[ intPoint % l ];
  21558. p2 = points[ ( intPoint + 1 ) % l ];
  21559. if ( this.closed || intPoint + 2 < l ) {
  21560. p3 = points[ ( intPoint + 2 ) % l ];
  21561. } else {
  21562. // extrapolate last point
  21563. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21564. p3 = tmp;
  21565. }
  21566. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  21567. // init Centripetal / Chordal Catmull-Rom
  21568. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  21569. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21570. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21571. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21572. // safety check for repeated points
  21573. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21574. if ( dt0 < 1e-4 ) dt0 = dt1;
  21575. if ( dt2 < 1e-4 ) dt2 = dt1;
  21576. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21577. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21578. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21579. } else if ( this.type === 'catmullrom' ) {
  21580. var tension = this.tension !== undefined ? this.tension : 0.5;
  21581. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  21582. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  21583. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  21584. }
  21585. var v = new THREE.Vector3(
  21586. px.calc( weight ),
  21587. py.calc( weight ),
  21588. pz.calc( weight )
  21589. );
  21590. return v;
  21591. }
  21592. );
  21593. } )();
  21594. // File:src/extras/curves/ClosedSplineCurve3.js
  21595. /**************************************************************
  21596. * Closed Spline 3D curve
  21597. **************************************************************/
  21598. THREE.ClosedSplineCurve3 = function ( points ) {
  21599. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Please use THREE.CatmullRomCurve3.' );
  21600. THREE.CatmullRomCurve3.call( this, points );
  21601. this.type = 'catmullrom';
  21602. this.closed = true;
  21603. };
  21604. THREE.ClosedSplineCurve3.prototype = Object.create( THREE.CatmullRomCurve3.prototype );
  21605. // File:src/extras/geometries/BoxGeometry.js
  21606. /**
  21607. * @author mrdoob / http://mrdoob.com/
  21608. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  21609. */
  21610. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21611. THREE.Geometry.call( this );
  21612. this.type = 'BoxGeometry';
  21613. this.parameters = {
  21614. width: width,
  21615. height: height,
  21616. depth: depth,
  21617. widthSegments: widthSegments,
  21618. heightSegments: heightSegments,
  21619. depthSegments: depthSegments
  21620. };
  21621. this.widthSegments = widthSegments || 1;
  21622. this.heightSegments = heightSegments || 1;
  21623. this.depthSegments = depthSegments || 1;
  21624. var scope = this;
  21625. var width_half = width / 2;
  21626. var height_half = height / 2;
  21627. var depth_half = depth / 2;
  21628. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
  21629. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, 1 ); // nx
  21630. buildPlane( 'x', 'z', 1, 1, width, depth, height_half, 2 ); // py
  21631. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, 3 ); // ny
  21632. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, 4 ); // pz
  21633. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
  21634. function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
  21635. var w, ix, iy,
  21636. gridX = scope.widthSegments,
  21637. gridY = scope.heightSegments,
  21638. width_half = width / 2,
  21639. height_half = height / 2,
  21640. offset = scope.vertices.length;
  21641. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  21642. w = 'z';
  21643. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  21644. w = 'y';
  21645. gridY = scope.depthSegments;
  21646. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  21647. w = 'x';
  21648. gridX = scope.depthSegments;
  21649. }
  21650. var gridX1 = gridX + 1,
  21651. gridY1 = gridY + 1,
  21652. segment_width = width / gridX,
  21653. segment_height = height / gridY,
  21654. normal = new THREE.Vector3();
  21655. normal[ w ] = depth > 0 ? 1 : - 1;
  21656. for ( iy = 0; iy < gridY1; iy ++ ) {
  21657. for ( ix = 0; ix < gridX1; ix ++ ) {
  21658. var vector = new THREE.Vector3();
  21659. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  21660. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  21661. vector[ w ] = depth;
  21662. scope.vertices.push( vector );
  21663. }
  21664. }
  21665. for ( iy = 0; iy < gridY; iy ++ ) {
  21666. for ( ix = 0; ix < gridX; ix ++ ) {
  21667. var a = ix + gridX1 * iy;
  21668. var b = ix + gridX1 * ( iy + 1 );
  21669. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  21670. var d = ( ix + 1 ) + gridX1 * iy;
  21671. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  21672. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  21673. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  21674. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  21675. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  21676. face.normal.copy( normal );
  21677. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  21678. face.materialIndex = materialIndex;
  21679. scope.faces.push( face );
  21680. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  21681. face = new THREE.Face3( b + offset, c + offset, d + offset );
  21682. face.normal.copy( normal );
  21683. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  21684. face.materialIndex = materialIndex;
  21685. scope.faces.push( face );
  21686. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  21687. }
  21688. }
  21689. }
  21690. this.mergeVertices();
  21691. };
  21692. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21693. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  21694. THREE.CubeGeometry = THREE.BoxGeometry;
  21695. // File:src/extras/geometries/CircleGeometry.js
  21696. /**
  21697. * @author hughes
  21698. */
  21699. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21700. THREE.Geometry.call( this );
  21701. this.type = 'CircleGeometry';
  21702. this.parameters = {
  21703. radius: radius,
  21704. segments: segments,
  21705. thetaStart: thetaStart,
  21706. thetaLength: thetaLength
  21707. };
  21708. this.fromBufferGeometry( new THREE.CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  21709. };
  21710. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21711. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  21712. // File:src/extras/geometries/CircleBufferGeometry.js
  21713. /**
  21714. * @author benaadams / https://twitter.com/ben_a_adams
  21715. */
  21716. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21717. THREE.BufferGeometry.call( this );
  21718. this.type = 'CircleBufferGeometry';
  21719. this.parameters = {
  21720. radius: radius,
  21721. segments: segments,
  21722. thetaStart: thetaStart,
  21723. thetaLength: thetaLength
  21724. };
  21725. radius = radius || 50;
  21726. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  21727. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21728. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  21729. var vertices = segments + 2;
  21730. var positions = new Float32Array( vertices * 3 );
  21731. var normals = new Float32Array( vertices * 3 );
  21732. var uvs = new Float32Array( vertices * 2 );
  21733. // center data is already zero, but need to set a few extras
  21734. normals[ 2 ] = 1.0;
  21735. uvs[ 0 ] = 0.5;
  21736. uvs[ 1 ] = 0.5;
  21737. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  21738. var segment = thetaStart + s / segments * thetaLength;
  21739. positions[ i ] = radius * Math.cos( segment );
  21740. positions[ i + 1 ] = radius * Math.sin( segment );
  21741. normals[ i + 2 ] = 1; // normal z
  21742. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  21743. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  21744. }
  21745. var indices = [];
  21746. for ( var i = 1; i <= segments; i ++ ) {
  21747. indices.push( i, i + 1, 0 );
  21748. }
  21749. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  21750. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  21751. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21752. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21753. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  21754. };
  21755. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21756. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  21757. // File:src/extras/geometries/CylinderGeometry.js
  21758. /**
  21759. * @author mrdoob / http://mrdoob.com/
  21760. */
  21761. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  21762. THREE.Geometry.call( this );
  21763. this.type = 'CylinderGeometry';
  21764. this.parameters = {
  21765. radiusTop: radiusTop,
  21766. radiusBottom: radiusBottom,
  21767. height: height,
  21768. radialSegments: radialSegments,
  21769. heightSegments: heightSegments,
  21770. openEnded: openEnded,
  21771. thetaStart: thetaStart,
  21772. thetaLength: thetaLength
  21773. };
  21774. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  21775. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  21776. height = height !== undefined ? height : 100;
  21777. radialSegments = radialSegments || 8;
  21778. heightSegments = heightSegments || 1;
  21779. openEnded = openEnded !== undefined ? openEnded : false;
  21780. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21781. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  21782. var heightHalf = height / 2;
  21783. var x, y, vertices = [], uvs = [];
  21784. for ( y = 0; y <= heightSegments; y ++ ) {
  21785. var verticesRow = [];
  21786. var uvsRow = [];
  21787. var v = y / heightSegments;
  21788. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  21789. for ( x = 0; x <= radialSegments; x ++ ) {
  21790. var u = x / radialSegments;
  21791. var vertex = new THREE.Vector3();
  21792. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  21793. vertex.y = - v * height + heightHalf;
  21794. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  21795. this.vertices.push( vertex );
  21796. verticesRow.push( this.vertices.length - 1 );
  21797. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  21798. }
  21799. vertices.push( verticesRow );
  21800. uvs.push( uvsRow );
  21801. }
  21802. var tanTheta = ( radiusBottom - radiusTop ) / height;
  21803. var na, nb;
  21804. for ( x = 0; x < radialSegments; x ++ ) {
  21805. if ( radiusTop !== 0 ) {
  21806. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  21807. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  21808. } else {
  21809. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  21810. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  21811. }
  21812. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  21813. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  21814. for ( y = 0; y < heightSegments; y ++ ) {
  21815. var v1 = vertices[ y ][ x ];
  21816. var v2 = vertices[ y + 1 ][ x ];
  21817. var v3 = vertices[ y + 1 ][ x + 1 ];
  21818. var v4 = vertices[ y ][ x + 1 ];
  21819. var n1 = na.clone();
  21820. var n2 = na.clone();
  21821. var n3 = nb.clone();
  21822. var n4 = nb.clone();
  21823. var uv1 = uvs[ y ][ x ].clone();
  21824. var uv2 = uvs[ y + 1 ][ x ].clone();
  21825. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  21826. var uv4 = uvs[ y ][ x + 1 ].clone();
  21827. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  21828. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  21829. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  21830. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  21831. }
  21832. }
  21833. // top cap
  21834. if ( openEnded === false && radiusTop > 0 ) {
  21835. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  21836. for ( x = 0; x < radialSegments; x ++ ) {
  21837. var v1 = vertices[ 0 ][ x ];
  21838. var v2 = vertices[ 0 ][ x + 1 ];
  21839. var v3 = this.vertices.length - 1;
  21840. var n1 = new THREE.Vector3( 0, 1, 0 );
  21841. var n2 = new THREE.Vector3( 0, 1, 0 );
  21842. var n3 = new THREE.Vector3( 0, 1, 0 );
  21843. var uv1 = uvs[ 0 ][ x ].clone();
  21844. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  21845. var uv3 = new THREE.Vector2( uv2.x, 0 );
  21846. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 1 ) );
  21847. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  21848. }
  21849. }
  21850. // bottom cap
  21851. if ( openEnded === false && radiusBottom > 0 ) {
  21852. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  21853. for ( x = 0; x < radialSegments; x ++ ) {
  21854. var v1 = vertices[ heightSegments ][ x + 1 ];
  21855. var v2 = vertices[ heightSegments ][ x ];
  21856. var v3 = this.vertices.length - 1;
  21857. var n1 = new THREE.Vector3( 0, - 1, 0 );
  21858. var n2 = new THREE.Vector3( 0, - 1, 0 );
  21859. var n3 = new THREE.Vector3( 0, - 1, 0 );
  21860. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  21861. var uv2 = uvs[ heightSegments ][ x ].clone();
  21862. var uv3 = new THREE.Vector2( uv2.x, 1 );
  21863. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 2 ) );
  21864. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  21865. }
  21866. }
  21867. this.computeFaceNormals();
  21868. };
  21869. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21870. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  21871. // File:src/extras/geometries/EdgesGeometry.js
  21872. /**
  21873. * @author WestLangley / http://github.com/WestLangley
  21874. */
  21875. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  21876. THREE.BufferGeometry.call( this );
  21877. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  21878. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  21879. var edge = [ 0, 0 ], hash = {};
  21880. function sortFunction( a, b ) {
  21881. return a - b;
  21882. }
  21883. var keys = [ 'a', 'b', 'c' ];
  21884. var geometry2;
  21885. if ( geometry instanceof THREE.BufferGeometry ) {
  21886. geometry2 = new THREE.Geometry();
  21887. geometry2.fromBufferGeometry( geometry );
  21888. } else {
  21889. geometry2 = geometry.clone();
  21890. }
  21891. geometry2.mergeVertices();
  21892. geometry2.computeFaceNormals();
  21893. var vertices = geometry2.vertices;
  21894. var faces = geometry2.faces;
  21895. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21896. var face = faces[ i ];
  21897. for ( var j = 0; j < 3; j ++ ) {
  21898. edge[ 0 ] = face[ keys[ j ] ];
  21899. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  21900. edge.sort( sortFunction );
  21901. var key = edge.toString();
  21902. if ( hash[ key ] === undefined ) {
  21903. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  21904. } else {
  21905. hash[ key ].face2 = i;
  21906. }
  21907. }
  21908. }
  21909. var coords = [];
  21910. for ( var key in hash ) {
  21911. var h = hash[ key ];
  21912. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  21913. var vertex = vertices[ h.vert1 ];
  21914. coords.push( vertex.x );
  21915. coords.push( vertex.y );
  21916. coords.push( vertex.z );
  21917. vertex = vertices[ h.vert2 ];
  21918. coords.push( vertex.x );
  21919. coords.push( vertex.y );
  21920. coords.push( vertex.z );
  21921. }
  21922. }
  21923. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  21924. };
  21925. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21926. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  21927. // File:src/extras/geometries/ExtrudeGeometry.js
  21928. /**
  21929. * @author zz85 / http://www.lab4games.net/zz85/blog
  21930. *
  21931. * Creates extruded geometry from a path shape.
  21932. *
  21933. * parameters = {
  21934. *
  21935. * curveSegments: <int>, // number of points on the curves
  21936. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  21937. * amount: <int>, // Depth to extrude the shape
  21938. *
  21939. * bevelEnabled: <bool>, // turn on bevel
  21940. * bevelThickness: <float>, // how deep into the original shape bevel goes
  21941. * bevelSize: <float>, // how far from shape outline is bevel
  21942. * bevelSegments: <int>, // number of bevel layers
  21943. *
  21944. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  21945. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  21946. *
  21947. * uvGenerator: <Object> // object that provides UV generator functions
  21948. *
  21949. * }
  21950. **/
  21951. THREE.ExtrudeGeometry = function ( shapes, options ) {
  21952. if ( typeof( shapes ) === "undefined" ) {
  21953. shapes = [];
  21954. return;
  21955. }
  21956. THREE.Geometry.call( this );
  21957. this.type = 'ExtrudeGeometry';
  21958. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  21959. this.addShapeList( shapes, options );
  21960. this.computeFaceNormals();
  21961. // can't really use automatic vertex normals
  21962. // as then front and back sides get smoothed too
  21963. // should do separate smoothing just for sides
  21964. //this.computeVertexNormals();
  21965. //console.log( "took", ( Date.now() - startTime ) );
  21966. };
  21967. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21968. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  21969. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  21970. var sl = shapes.length;
  21971. for ( var s = 0; s < sl; s ++ ) {
  21972. var shape = shapes[ s ];
  21973. this.addShape( shape, options );
  21974. }
  21975. };
  21976. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  21977. var amount = options.amount !== undefined ? options.amount : 100;
  21978. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  21979. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  21980. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  21981. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  21982. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  21983. var steps = options.steps !== undefined ? options.steps : 1;
  21984. var extrudePath = options.extrudePath;
  21985. var extrudePts, extrudeByPath = false;
  21986. // Use default WorldUVGenerator if no UV generators are specified.
  21987. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  21988. var splineTube, binormal, normal, position2;
  21989. if ( extrudePath ) {
  21990. extrudePts = extrudePath.getSpacedPoints( steps );
  21991. extrudeByPath = true;
  21992. bevelEnabled = false; // bevels not supported for path extrusion
  21993. // SETUP TNB variables
  21994. // Reuse TNB from TubeGeomtry for now.
  21995. // TODO1 - have a .isClosed in spline?
  21996. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  21997. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  21998. binormal = new THREE.Vector3();
  21999. normal = new THREE.Vector3();
  22000. position2 = new THREE.Vector3();
  22001. }
  22002. // Safeguards if bevels are not enabled
  22003. if ( ! bevelEnabled ) {
  22004. bevelSegments = 0;
  22005. bevelThickness = 0;
  22006. bevelSize = 0;
  22007. }
  22008. // Variables initialization
  22009. var ahole, h, hl; // looping of holes
  22010. var scope = this;
  22011. var shapesOffset = this.vertices.length;
  22012. var shapePoints = shape.extractPoints( curveSegments );
  22013. var vertices = shapePoints.shape;
  22014. var holes = shapePoints.holes;
  22015. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22016. if ( reverse ) {
  22017. vertices = vertices.reverse();
  22018. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  22019. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22020. ahole = holes[ h ];
  22021. if ( THREE.ShapeUtils.isClockWise( ahole ) ) {
  22022. holes[ h ] = ahole.reverse();
  22023. }
  22024. }
  22025. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  22026. }
  22027. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22028. /* Vertices */
  22029. var contour = vertices; // vertices has all points but contour has only points of circumference
  22030. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22031. ahole = holes[ h ];
  22032. vertices = vertices.concat( ahole );
  22033. }
  22034. function scalePt2 ( pt, vec, size ) {
  22035. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  22036. return vec.clone().multiplyScalar( size ).add( pt );
  22037. }
  22038. var b, bs, t, z,
  22039. vert, vlen = vertices.length,
  22040. face, flen = faces.length;
  22041. // Find directions for point movement
  22042. function getBevelVec( inPt, inPrev, inNext ) {
  22043. // computes for inPt the corresponding point inPt' on a new contour
  22044. // shifted by 1 unit (length of normalized vector) to the left
  22045. // if we walk along contour clockwise, this new contour is outside the old one
  22046. //
  22047. // inPt' is the intersection of the two lines parallel to the two
  22048. // adjacent edges of inPt at a distance of 1 unit on the left side.
  22049. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  22050. // good reading for geometry algorithms (here: line-line intersection)
  22051. // http://geomalgorithms.com/a05-_intersect-1.html
  22052. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  22053. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  22054. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  22055. // check for collinear edges
  22056. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  22057. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  22058. // not collinear
  22059. // length of vectors for normalizing
  22060. var v_prev_len = Math.sqrt( v_prev_lensq );
  22061. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  22062. // shift adjacent points by unit vectors to the left
  22063. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  22064. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  22065. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  22066. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  22067. // scaling factor for v_prev to intersection point
  22068. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  22069. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  22070. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  22071. // vector from inPt to intersection point
  22072. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  22073. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  22074. // Don't normalize!, otherwise sharp corners become ugly
  22075. // but prevent crazy spikes
  22076. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  22077. if ( v_trans_lensq <= 2 ) {
  22078. return new THREE.Vector2( v_trans_x, v_trans_y );
  22079. } else {
  22080. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  22081. }
  22082. } else {
  22083. // handle special case of collinear edges
  22084. var direction_eq = false; // assumes: opposite
  22085. if ( v_prev_x > Number.EPSILON ) {
  22086. if ( v_next_x > Number.EPSILON ) {
  22087. direction_eq = true;
  22088. }
  22089. } else {
  22090. if ( v_prev_x < - Number.EPSILON ) {
  22091. if ( v_next_x < - Number.EPSILON ) {
  22092. direction_eq = true;
  22093. }
  22094. } else {
  22095. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  22096. direction_eq = true;
  22097. }
  22098. }
  22099. }
  22100. if ( direction_eq ) {
  22101. // console.log("Warning: lines are a straight sequence");
  22102. v_trans_x = - v_prev_y;
  22103. v_trans_y = v_prev_x;
  22104. shrink_by = Math.sqrt( v_prev_lensq );
  22105. } else {
  22106. // console.log("Warning: lines are a straight spike");
  22107. v_trans_x = v_prev_x;
  22108. v_trans_y = v_prev_y;
  22109. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  22110. }
  22111. }
  22112. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  22113. }
  22114. var contourMovements = [];
  22115. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  22116. if ( j === il ) j = 0;
  22117. if ( k === il ) k = 0;
  22118. // (j)---(i)---(k)
  22119. // console.log('i,j,k', i, j , k)
  22120. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  22121. }
  22122. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  22123. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22124. ahole = holes[ h ];
  22125. oneHoleMovements = [];
  22126. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  22127. if ( j === il ) j = 0;
  22128. if ( k === il ) k = 0;
  22129. // (j)---(i)---(k)
  22130. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  22131. }
  22132. holesMovements.push( oneHoleMovements );
  22133. verticesMovements = verticesMovements.concat( oneHoleMovements );
  22134. }
  22135. // Loop bevelSegments, 1 for the front, 1 for the back
  22136. for ( b = 0; b < bevelSegments; b ++ ) {
  22137. //for ( b = bevelSegments; b > 0; b -- ) {
  22138. t = b / bevelSegments;
  22139. z = bevelThickness * ( 1 - t );
  22140. //z = bevelThickness * t;
  22141. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  22142. //bs = bevelSize * t; // linear
  22143. // contract shape
  22144. for ( i = 0, il = contour.length; i < il; i ++ ) {
  22145. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  22146. v( vert.x, vert.y, - z );
  22147. }
  22148. // expand holes
  22149. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22150. ahole = holes[ h ];
  22151. oneHoleMovements = holesMovements[ h ];
  22152. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22153. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22154. v( vert.x, vert.y, - z );
  22155. }
  22156. }
  22157. }
  22158. bs = bevelSize;
  22159. // Back facing vertices
  22160. for ( i = 0; i < vlen; i ++ ) {
  22161. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  22162. if ( ! extrudeByPath ) {
  22163. v( vert.x, vert.y, 0 );
  22164. } else {
  22165. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  22166. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  22167. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  22168. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  22169. v( position2.x, position2.y, position2.z );
  22170. }
  22171. }
  22172. // Add stepped vertices...
  22173. // Including front facing vertices
  22174. var s;
  22175. for ( s = 1; s <= steps; s ++ ) {
  22176. for ( i = 0; i < vlen; i ++ ) {
  22177. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  22178. if ( ! extrudeByPath ) {
  22179. v( vert.x, vert.y, amount / steps * s );
  22180. } else {
  22181. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  22182. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  22183. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  22184. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  22185. v( position2.x, position2.y, position2.z );
  22186. }
  22187. }
  22188. }
  22189. // Add bevel segments planes
  22190. //for ( b = 1; b <= bevelSegments; b ++ ) {
  22191. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  22192. t = b / bevelSegments;
  22193. z = bevelThickness * ( 1 - t );
  22194. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  22195. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  22196. // contract shape
  22197. for ( i = 0, il = contour.length; i < il; i ++ ) {
  22198. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  22199. v( vert.x, vert.y, amount + z );
  22200. }
  22201. // expand holes
  22202. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22203. ahole = holes[ h ];
  22204. oneHoleMovements = holesMovements[ h ];
  22205. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22206. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22207. if ( ! extrudeByPath ) {
  22208. v( vert.x, vert.y, amount + z );
  22209. } else {
  22210. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  22211. }
  22212. }
  22213. }
  22214. }
  22215. /* Faces */
  22216. // Top and bottom faces
  22217. buildLidFaces();
  22218. // Sides faces
  22219. buildSideFaces();
  22220. ///// Internal functions
  22221. function buildLidFaces() {
  22222. if ( bevelEnabled ) {
  22223. var layer = 0; // steps + 1
  22224. var offset = vlen * layer;
  22225. // Bottom faces
  22226. for ( i = 0; i < flen; i ++ ) {
  22227. face = faces[ i ];
  22228. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  22229. }
  22230. layer = steps + bevelSegments * 2;
  22231. offset = vlen * layer;
  22232. // Top faces
  22233. for ( i = 0; i < flen; i ++ ) {
  22234. face = faces[ i ];
  22235. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  22236. }
  22237. } else {
  22238. // Bottom faces
  22239. for ( i = 0; i < flen; i ++ ) {
  22240. face = faces[ i ];
  22241. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  22242. }
  22243. // Top faces
  22244. for ( i = 0; i < flen; i ++ ) {
  22245. face = faces[ i ];
  22246. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  22247. }
  22248. }
  22249. }
  22250. // Create faces for the z-sides of the shape
  22251. function buildSideFaces() {
  22252. var layeroffset = 0;
  22253. sidewalls( contour, layeroffset );
  22254. layeroffset += contour.length;
  22255. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22256. ahole = holes[ h ];
  22257. sidewalls( ahole, layeroffset );
  22258. //, true
  22259. layeroffset += ahole.length;
  22260. }
  22261. }
  22262. function sidewalls( contour, layeroffset ) {
  22263. var j, k;
  22264. i = contour.length;
  22265. while ( -- i >= 0 ) {
  22266. j = i;
  22267. k = i - 1;
  22268. if ( k < 0 ) k = contour.length - 1;
  22269. //console.log('b', i,j, i-1, k,vertices.length);
  22270. var s = 0, sl = steps + bevelSegments * 2;
  22271. for ( s = 0; s < sl; s ++ ) {
  22272. var slen1 = vlen * s;
  22273. var slen2 = vlen * ( s + 1 );
  22274. var a = layeroffset + j + slen1,
  22275. b = layeroffset + k + slen1,
  22276. c = layeroffset + k + slen2,
  22277. d = layeroffset + j + slen2;
  22278. f4( a, b, c, d, contour, s, sl, j, k );
  22279. }
  22280. }
  22281. }
  22282. function v( x, y, z ) {
  22283. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  22284. }
  22285. function f3( a, b, c ) {
  22286. a += shapesOffset;
  22287. b += shapesOffset;
  22288. c += shapesOffset;
  22289. scope.faces.push( new THREE.Face3( a, b, c, null, null, 0 ) );
  22290. var uvs = uvgen.generateTopUV( scope, a, b, c );
  22291. scope.faceVertexUvs[ 0 ].push( uvs );
  22292. }
  22293. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  22294. a += shapesOffset;
  22295. b += shapesOffset;
  22296. c += shapesOffset;
  22297. d += shapesOffset;
  22298. scope.faces.push( new THREE.Face3( a, b, d, null, null, 1 ) );
  22299. scope.faces.push( new THREE.Face3( b, c, d, null, null, 1 ) );
  22300. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  22301. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  22302. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  22303. }
  22304. };
  22305. THREE.ExtrudeGeometry.WorldUVGenerator = {
  22306. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  22307. var vertices = geometry.vertices;
  22308. var a = vertices[ indexA ];
  22309. var b = vertices[ indexB ];
  22310. var c = vertices[ indexC ];
  22311. return [
  22312. new THREE.Vector2( a.x, a.y ),
  22313. new THREE.Vector2( b.x, b.y ),
  22314. new THREE.Vector2( c.x, c.y )
  22315. ];
  22316. },
  22317. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  22318. var vertices = geometry.vertices;
  22319. var a = vertices[ indexA ];
  22320. var b = vertices[ indexB ];
  22321. var c = vertices[ indexC ];
  22322. var d = vertices[ indexD ];
  22323. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  22324. return [
  22325. new THREE.Vector2( a.x, 1 - a.z ),
  22326. new THREE.Vector2( b.x, 1 - b.z ),
  22327. new THREE.Vector2( c.x, 1 - c.z ),
  22328. new THREE.Vector2( d.x, 1 - d.z )
  22329. ];
  22330. } else {
  22331. return [
  22332. new THREE.Vector2( a.y, 1 - a.z ),
  22333. new THREE.Vector2( b.y, 1 - b.z ),
  22334. new THREE.Vector2( c.y, 1 - c.z ),
  22335. new THREE.Vector2( d.y, 1 - d.z )
  22336. ];
  22337. }
  22338. }
  22339. };
  22340. // File:src/extras/geometries/ShapeGeometry.js
  22341. /**
  22342. * @author jonobr1 / http://jonobr1.com
  22343. *
  22344. * Creates a one-sided polygonal geometry from a path shape. Similar to
  22345. * ExtrudeGeometry.
  22346. *
  22347. * parameters = {
  22348. *
  22349. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  22350. *
  22351. * material: <int> // material index for front and back faces
  22352. * uvGenerator: <Object> // object that provides UV generator functions
  22353. *
  22354. * }
  22355. **/
  22356. THREE.ShapeGeometry = function ( shapes, options ) {
  22357. THREE.Geometry.call( this );
  22358. this.type = 'ShapeGeometry';
  22359. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  22360. this.addShapeList( shapes, options );
  22361. this.computeFaceNormals();
  22362. };
  22363. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22364. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  22365. /**
  22366. * Add an array of shapes to THREE.ShapeGeometry.
  22367. */
  22368. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  22369. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  22370. this.addShape( shapes[ i ], options );
  22371. }
  22372. return this;
  22373. };
  22374. /**
  22375. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  22376. */
  22377. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  22378. if ( options === undefined ) options = {};
  22379. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  22380. var material = options.material;
  22381. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  22382. //
  22383. var i, l, hole;
  22384. var shapesOffset = this.vertices.length;
  22385. var shapePoints = shape.extractPoints( curveSegments );
  22386. var vertices = shapePoints.shape;
  22387. var holes = shapePoints.holes;
  22388. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22389. if ( reverse ) {
  22390. vertices = vertices.reverse();
  22391. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  22392. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22393. hole = holes[ i ];
  22394. if ( THREE.ShapeUtils.isClockWise( hole ) ) {
  22395. holes[ i ] = hole.reverse();
  22396. }
  22397. }
  22398. reverse = false;
  22399. }
  22400. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22401. // Vertices
  22402. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22403. hole = holes[ i ];
  22404. vertices = vertices.concat( hole );
  22405. }
  22406. //
  22407. var vert, vlen = vertices.length;
  22408. var face, flen = faces.length;
  22409. for ( i = 0; i < vlen; i ++ ) {
  22410. vert = vertices[ i ];
  22411. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  22412. }
  22413. for ( i = 0; i < flen; i ++ ) {
  22414. face = faces[ i ];
  22415. var a = face[ 0 ] + shapesOffset;
  22416. var b = face[ 1 ] + shapesOffset;
  22417. var c = face[ 2 ] + shapesOffset;
  22418. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  22419. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  22420. }
  22421. };
  22422. // File:src/extras/geometries/LatheGeometry.js
  22423. /**
  22424. * @author astrodud / http://astrodud.isgreat.org/
  22425. * @author zz85 / https://github.com/zz85
  22426. * @author bhouston / http://clara.io
  22427. */
  22428. // points - to create a closed torus, one must use a set of points
  22429. // like so: [ a, b, c, d, a ], see first is the same as last.
  22430. // segments - the number of circumference segments to create
  22431. // phiStart - the starting radian
  22432. // phiLength - the radian (0 to 2*PI) range of the lathed section
  22433. // 2*pi is a closed lathe, less than 2PI is a portion.
  22434. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  22435. THREE.Geometry.call( this );
  22436. this.type = 'LatheGeometry';
  22437. this.parameters = {
  22438. points: points,
  22439. segments: segments,
  22440. phiStart: phiStart,
  22441. phiLength: phiLength
  22442. };
  22443. segments = segments || 12;
  22444. phiStart = phiStart || 0;
  22445. phiLength = phiLength || 2 * Math.PI;
  22446. var inversePointLength = 1.0 / ( points.length - 1 );
  22447. var inverseSegments = 1.0 / segments;
  22448. for ( var i = 0, il = segments; i <= il; i ++ ) {
  22449. var phi = phiStart + i * inverseSegments * phiLength;
  22450. var sin = Math.sin( phi );
  22451. var cos = Math.cos( phi );
  22452. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  22453. var point = points[ j ];
  22454. var vertex = new THREE.Vector3();
  22455. vertex.x = point.x * sin;
  22456. vertex.y = point.y;
  22457. vertex.z = point.x * cos;
  22458. this.vertices.push( vertex );
  22459. }
  22460. }
  22461. var np = points.length;
  22462. for ( var i = 0, il = segments; i < il; i ++ ) {
  22463. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  22464. var base = j + np * i;
  22465. var a = base;
  22466. var b = base + np;
  22467. var c = base + 1 + np;
  22468. var d = base + 1;
  22469. var u0 = i * inverseSegments;
  22470. var v0 = j * inversePointLength;
  22471. var u1 = u0 + inverseSegments;
  22472. var v1 = v0 + inversePointLength;
  22473. this.faces.push( new THREE.Face3( a, b, d ) );
  22474. this.faceVertexUvs[ 0 ].push( [
  22475. new THREE.Vector2( u0, v0 ),
  22476. new THREE.Vector2( u1, v0 ),
  22477. new THREE.Vector2( u0, v1 )
  22478. ] );
  22479. this.faces.push( new THREE.Face3( b, c, d ) );
  22480. this.faceVertexUvs[ 0 ].push( [
  22481. new THREE.Vector2( u1, v0 ),
  22482. new THREE.Vector2( u1, v1 ),
  22483. new THREE.Vector2( u0, v1 )
  22484. ] );
  22485. }
  22486. }
  22487. this.mergeVertices();
  22488. this.computeFaceNormals();
  22489. this.computeVertexNormals();
  22490. };
  22491. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22492. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  22493. // File:src/extras/geometries/PlaneGeometry.js
  22494. /**
  22495. * @author mrdoob / http://mrdoob.com/
  22496. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22497. */
  22498. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  22499. THREE.Geometry.call( this );
  22500. this.type = 'PlaneGeometry';
  22501. this.parameters = {
  22502. width: width,
  22503. height: height,
  22504. widthSegments: widthSegments,
  22505. heightSegments: heightSegments
  22506. };
  22507. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  22508. };
  22509. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22510. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  22511. // File:src/extras/geometries/PlaneBufferGeometry.js
  22512. /**
  22513. * @author mrdoob / http://mrdoob.com/
  22514. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22515. */
  22516. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  22517. THREE.BufferGeometry.call( this );
  22518. this.type = 'PlaneBufferGeometry';
  22519. this.parameters = {
  22520. width: width,
  22521. height: height,
  22522. widthSegments: widthSegments,
  22523. heightSegments: heightSegments
  22524. };
  22525. var width_half = width / 2;
  22526. var height_half = height / 2;
  22527. var gridX = Math.floor( widthSegments ) || 1;
  22528. var gridY = Math.floor( heightSegments ) || 1;
  22529. var gridX1 = gridX + 1;
  22530. var gridY1 = gridY + 1;
  22531. var segment_width = width / gridX;
  22532. var segment_height = height / gridY;
  22533. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  22534. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  22535. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  22536. var offset = 0;
  22537. var offset2 = 0;
  22538. for ( var iy = 0; iy < gridY1; iy ++ ) {
  22539. var y = iy * segment_height - height_half;
  22540. for ( var ix = 0; ix < gridX1; ix ++ ) {
  22541. var x = ix * segment_width - width_half;
  22542. vertices[ offset ] = x;
  22543. vertices[ offset + 1 ] = - y;
  22544. normals[ offset + 2 ] = 1;
  22545. uvs[ offset2 ] = ix / gridX;
  22546. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  22547. offset += 3;
  22548. offset2 += 2;
  22549. }
  22550. }
  22551. offset = 0;
  22552. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  22553. for ( var iy = 0; iy < gridY; iy ++ ) {
  22554. for ( var ix = 0; ix < gridX; ix ++ ) {
  22555. var a = ix + gridX1 * iy;
  22556. var b = ix + gridX1 * ( iy + 1 );
  22557. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  22558. var d = ( ix + 1 ) + gridX1 * iy;
  22559. indices[ offset ] = a;
  22560. indices[ offset + 1 ] = b;
  22561. indices[ offset + 2 ] = d;
  22562. indices[ offset + 3 ] = b;
  22563. indices[ offset + 4 ] = c;
  22564. indices[ offset + 5 ] = d;
  22565. offset += 6;
  22566. }
  22567. }
  22568. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  22569. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  22570. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  22571. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  22572. };
  22573. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22574. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  22575. // File:src/extras/geometries/RingGeometry.js
  22576. /**
  22577. * @author Kaleb Murphy
  22578. */
  22579. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  22580. THREE.Geometry.call( this );
  22581. this.type = 'RingGeometry';
  22582. this.parameters = {
  22583. innerRadius: innerRadius,
  22584. outerRadius: outerRadius,
  22585. thetaSegments: thetaSegments,
  22586. phiSegments: phiSegments,
  22587. thetaStart: thetaStart,
  22588. thetaLength: thetaLength
  22589. };
  22590. innerRadius = innerRadius || 0;
  22591. outerRadius = outerRadius || 50;
  22592. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  22593. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  22594. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  22595. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  22596. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  22597. for ( i = 0; i < phiSegments + 1; i ++ ) {
  22598. // concentric circles inside ring
  22599. for ( o = 0; o < thetaSegments + 1; o ++ ) {
  22600. // number of segments per circle
  22601. var vertex = new THREE.Vector3();
  22602. var segment = thetaStart + o / thetaSegments * thetaLength;
  22603. vertex.x = radius * Math.cos( segment );
  22604. vertex.y = radius * Math.sin( segment );
  22605. this.vertices.push( vertex );
  22606. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  22607. }
  22608. radius += radiusStep;
  22609. }
  22610. var n = new THREE.Vector3( 0, 0, 1 );
  22611. for ( i = 0; i < phiSegments; i ++ ) {
  22612. // concentric circles inside ring
  22613. var thetaSegment = i * ( thetaSegments + 1 );
  22614. for ( o = 0; o < thetaSegments ; o ++ ) {
  22615. // number of segments per circle
  22616. var segment = o + thetaSegment;
  22617. var v1 = segment;
  22618. var v2 = segment + thetaSegments + 1;
  22619. var v3 = segment + thetaSegments + 2;
  22620. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  22621. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  22622. v1 = segment;
  22623. v2 = segment + thetaSegments + 2;
  22624. v3 = segment + 1;
  22625. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  22626. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  22627. }
  22628. }
  22629. this.computeFaceNormals();
  22630. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22631. };
  22632. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22633. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  22634. // File:src/extras/geometries/SphereGeometry.js
  22635. /**
  22636. * @author mrdoob / http://mrdoob.com/
  22637. */
  22638. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  22639. THREE.Geometry.call( this );
  22640. this.type = 'SphereGeometry';
  22641. this.parameters = {
  22642. radius: radius,
  22643. widthSegments: widthSegments,
  22644. heightSegments: heightSegments,
  22645. phiStart: phiStart,
  22646. phiLength: phiLength,
  22647. thetaStart: thetaStart,
  22648. thetaLength: thetaLength
  22649. };
  22650. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  22651. };
  22652. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22653. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  22654. // File:src/extras/geometries/SphereBufferGeometry.js
  22655. /**
  22656. * @author benaadams / https://twitter.com/ben_a_adams
  22657. * based on THREE.SphereGeometry
  22658. */
  22659. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  22660. THREE.BufferGeometry.call( this );
  22661. this.type = 'SphereBufferGeometry';
  22662. this.parameters = {
  22663. radius: radius,
  22664. widthSegments: widthSegments,
  22665. heightSegments: heightSegments,
  22666. phiStart: phiStart,
  22667. phiLength: phiLength,
  22668. thetaStart: thetaStart,
  22669. thetaLength: thetaLength
  22670. };
  22671. radius = radius || 50;
  22672. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  22673. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  22674. phiStart = phiStart !== undefined ? phiStart : 0;
  22675. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  22676. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  22677. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  22678. var thetaEnd = thetaStart + thetaLength;
  22679. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  22680. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22681. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22682. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22683. var index = 0, vertices = [], normal = new THREE.Vector3();
  22684. for ( var y = 0; y <= heightSegments; y ++ ) {
  22685. var verticesRow = [];
  22686. var v = y / heightSegments;
  22687. for ( var x = 0; x <= widthSegments; x ++ ) {
  22688. var u = x / widthSegments;
  22689. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  22690. var py = radius * Math.cos( thetaStart + v * thetaLength );
  22691. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  22692. normal.set( px, py, pz ).normalize();
  22693. positions.setXYZ( index, px, py, pz );
  22694. normals.setXYZ( index, normal.x, normal.y, normal.z );
  22695. uvs.setXY( index, u, 1 - v );
  22696. verticesRow.push( index );
  22697. index ++;
  22698. }
  22699. vertices.push( verticesRow );
  22700. }
  22701. var indices = [];
  22702. for ( var y = 0; y < heightSegments; y ++ ) {
  22703. for ( var x = 0; x < widthSegments; x ++ ) {
  22704. var v1 = vertices[ y ][ x + 1 ];
  22705. var v2 = vertices[ y ][ x ];
  22706. var v3 = vertices[ y + 1 ][ x ];
  22707. var v4 = vertices[ y + 1 ][ x + 1 ];
  22708. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  22709. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  22710. }
  22711. }
  22712. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  22713. this.addAttribute( 'position', positions );
  22714. this.addAttribute( 'normal', normals );
  22715. this.addAttribute( 'uv', uvs );
  22716. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22717. };
  22718. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22719. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  22720. // File:src/extras/geometries/TextGeometry.js
  22721. /**
  22722. * @author zz85 / http://www.lab4games.net/zz85/blog
  22723. * @author alteredq / http://alteredqualia.com/
  22724. *
  22725. * Text = 3D Text
  22726. *
  22727. * parameters = {
  22728. * font: <THREE.Font>, // font
  22729. *
  22730. * size: <float>, // size of the text
  22731. * height: <float>, // thickness to extrude text
  22732. * curveSegments: <int>, // number of points on the curves
  22733. *
  22734. * bevelEnabled: <bool>, // turn on bevel
  22735. * bevelThickness: <float>, // how deep into text bevel goes
  22736. * bevelSize: <float> // how far from text outline is bevel
  22737. * }
  22738. */
  22739. THREE.TextGeometry = function ( text, parameters ) {
  22740. parameters = parameters || {};
  22741. var font = parameters.font;
  22742. if ( font instanceof THREE.Font === false ) {
  22743. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  22744. return new THREE.Geometry();
  22745. }
  22746. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  22747. // translate parameters to ExtrudeGeometry API
  22748. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  22749. // defaults
  22750. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  22751. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  22752. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  22753. THREE.ExtrudeGeometry.call( this, shapes, parameters );
  22754. this.type = 'TextGeometry';
  22755. };
  22756. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  22757. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  22758. // File:src/extras/geometries/TorusGeometry.js
  22759. /**
  22760. * @author oosmoxiecode
  22761. * @author mrdoob / http://mrdoob.com/
  22762. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  22763. */
  22764. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  22765. THREE.Geometry.call( this );
  22766. this.type = 'TorusGeometry';
  22767. this.parameters = {
  22768. radius: radius,
  22769. tube: tube,
  22770. radialSegments: radialSegments,
  22771. tubularSegments: tubularSegments,
  22772. arc: arc
  22773. };
  22774. radius = radius || 100;
  22775. tube = tube || 40;
  22776. radialSegments = radialSegments || 8;
  22777. tubularSegments = tubularSegments || 6;
  22778. arc = arc || Math.PI * 2;
  22779. var center = new THREE.Vector3(), uvs = [], normals = [];
  22780. for ( var j = 0; j <= radialSegments; j ++ ) {
  22781. for ( var i = 0; i <= tubularSegments; i ++ ) {
  22782. var u = i / tubularSegments * arc;
  22783. var v = j / radialSegments * Math.PI * 2;
  22784. center.x = radius * Math.cos( u );
  22785. center.y = radius * Math.sin( u );
  22786. var vertex = new THREE.Vector3();
  22787. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  22788. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  22789. vertex.z = tube * Math.sin( v );
  22790. this.vertices.push( vertex );
  22791. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  22792. normals.push( vertex.clone().sub( center ).normalize() );
  22793. }
  22794. }
  22795. for ( var j = 1; j <= radialSegments; j ++ ) {
  22796. for ( var i = 1; i <= tubularSegments; i ++ ) {
  22797. var a = ( tubularSegments + 1 ) * j + i - 1;
  22798. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  22799. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  22800. var d = ( tubularSegments + 1 ) * j + i;
  22801. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  22802. this.faces.push( face );
  22803. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  22804. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  22805. this.faces.push( face );
  22806. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  22807. }
  22808. }
  22809. this.computeFaceNormals();
  22810. };
  22811. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22812. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  22813. // File:src/extras/geometries/TorusKnotGeometry.js
  22814. /**
  22815. * @author oosmoxiecode
  22816. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  22817. */
  22818. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  22819. THREE.Geometry.call( this );
  22820. this.type = 'TorusKnotGeometry';
  22821. this.parameters = {
  22822. radius: radius,
  22823. tube: tube,
  22824. radialSegments: radialSegments,
  22825. tubularSegments: tubularSegments,
  22826. p: p,
  22827. q: q,
  22828. heightScale: heightScale
  22829. };
  22830. radius = radius || 100;
  22831. tube = tube || 40;
  22832. radialSegments = radialSegments || 64;
  22833. tubularSegments = tubularSegments || 8;
  22834. p = p || 2;
  22835. q = q || 3;
  22836. heightScale = heightScale || 1;
  22837. var grid = new Array( radialSegments );
  22838. var tang = new THREE.Vector3();
  22839. var n = new THREE.Vector3();
  22840. var bitan = new THREE.Vector3();
  22841. for ( var i = 0; i < radialSegments; ++ i ) {
  22842. grid[ i ] = new Array( tubularSegments );
  22843. var u = i / radialSegments * 2 * p * Math.PI;
  22844. var p1 = getPos( u, q, p, radius, heightScale );
  22845. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  22846. tang.subVectors( p2, p1 );
  22847. n.addVectors( p2, p1 );
  22848. bitan.crossVectors( tang, n );
  22849. n.crossVectors( bitan, tang );
  22850. bitan.normalize();
  22851. n.normalize();
  22852. for ( var j = 0; j < tubularSegments; ++ j ) {
  22853. var v = j / tubularSegments * 2 * Math.PI;
  22854. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  22855. var cy = tube * Math.sin( v );
  22856. var pos = new THREE.Vector3();
  22857. pos.x = p1.x + cx * n.x + cy * bitan.x;
  22858. pos.y = p1.y + cx * n.y + cy * bitan.y;
  22859. pos.z = p1.z + cx * n.z + cy * bitan.z;
  22860. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  22861. }
  22862. }
  22863. for ( var i = 0; i < radialSegments; ++ i ) {
  22864. for ( var j = 0; j < tubularSegments; ++ j ) {
  22865. var ip = ( i + 1 ) % radialSegments;
  22866. var jp = ( j + 1 ) % tubularSegments;
  22867. var a = grid[ i ][ j ];
  22868. var b = grid[ ip ][ j ];
  22869. var c = grid[ ip ][ jp ];
  22870. var d = grid[ i ][ jp ];
  22871. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  22872. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  22873. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  22874. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  22875. this.faces.push( new THREE.Face3( a, b, d ) );
  22876. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  22877. this.faces.push( new THREE.Face3( b, c, d ) );
  22878. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  22879. }
  22880. }
  22881. this.computeFaceNormals();
  22882. this.computeVertexNormals();
  22883. function getPos( u, in_q, in_p, radius, heightScale ) {
  22884. var cu = Math.cos( u );
  22885. var su = Math.sin( u );
  22886. var quOverP = in_q / in_p * u;
  22887. var cs = Math.cos( quOverP );
  22888. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  22889. var ty = radius * ( 2 + cs ) * su * 0.5;
  22890. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  22891. return new THREE.Vector3( tx, ty, tz );
  22892. }
  22893. };
  22894. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22895. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  22896. // File:src/extras/geometries/TubeGeometry.js
  22897. /**
  22898. * @author WestLangley / https://github.com/WestLangley
  22899. * @author zz85 / https://github.com/zz85
  22900. * @author miningold / https://github.com/miningold
  22901. * @author jonobr1 / https://github.com/jonobr1
  22902. *
  22903. * Modified from the TorusKnotGeometry by @oosmoxiecode
  22904. *
  22905. * Creates a tube which extrudes along a 3d spline
  22906. *
  22907. * Uses parallel transport frames as described in
  22908. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22909. */
  22910. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  22911. THREE.Geometry.call( this );
  22912. this.type = 'TubeGeometry';
  22913. this.parameters = {
  22914. path: path,
  22915. segments: segments,
  22916. radius: radius,
  22917. radialSegments: radialSegments,
  22918. closed: closed,
  22919. taper: taper
  22920. };
  22921. segments = segments || 64;
  22922. radius = radius || 1;
  22923. radialSegments = radialSegments || 8;
  22924. closed = closed || false;
  22925. taper = taper || THREE.TubeGeometry.NoTaper;
  22926. var grid = [];
  22927. var scope = this,
  22928. tangent,
  22929. normal,
  22930. binormal,
  22931. numpoints = segments + 1,
  22932. u, v, r,
  22933. cx, cy,
  22934. pos, pos2 = new THREE.Vector3(),
  22935. i, j,
  22936. ip, jp,
  22937. a, b, c, d,
  22938. uva, uvb, uvc, uvd;
  22939. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  22940. tangents = frames.tangents,
  22941. normals = frames.normals,
  22942. binormals = frames.binormals;
  22943. // proxy internals
  22944. this.tangents = tangents;
  22945. this.normals = normals;
  22946. this.binormals = binormals;
  22947. function vert( x, y, z ) {
  22948. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  22949. }
  22950. // construct the grid
  22951. for ( i = 0; i < numpoints; i ++ ) {
  22952. grid[ i ] = [];
  22953. u = i / ( numpoints - 1 );
  22954. pos = path.getPointAt( u );
  22955. tangent = tangents[ i ];
  22956. normal = normals[ i ];
  22957. binormal = binormals[ i ];
  22958. r = radius * taper( u );
  22959. for ( j = 0; j < radialSegments; j ++ ) {
  22960. v = j / radialSegments * 2 * Math.PI;
  22961. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  22962. cy = r * Math.sin( v );
  22963. pos2.copy( pos );
  22964. pos2.x += cx * normal.x + cy * binormal.x;
  22965. pos2.y += cx * normal.y + cy * binormal.y;
  22966. pos2.z += cx * normal.z + cy * binormal.z;
  22967. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  22968. }
  22969. }
  22970. // construct the mesh
  22971. for ( i = 0; i < segments; i ++ ) {
  22972. for ( j = 0; j < radialSegments; j ++ ) {
  22973. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  22974. jp = ( j + 1 ) % radialSegments;
  22975. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  22976. b = grid[ ip ][ j ];
  22977. c = grid[ ip ][ jp ];
  22978. d = grid[ i ][ jp ];
  22979. uva = new THREE.Vector2( i / segments, j / radialSegments );
  22980. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  22981. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  22982. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  22983. this.faces.push( new THREE.Face3( a, b, d ) );
  22984. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  22985. this.faces.push( new THREE.Face3( b, c, d ) );
  22986. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  22987. }
  22988. }
  22989. this.computeFaceNormals();
  22990. this.computeVertexNormals();
  22991. };
  22992. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22993. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  22994. THREE.TubeGeometry.NoTaper = function ( u ) {
  22995. return 1;
  22996. };
  22997. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  22998. return Math.sin( Math.PI * u );
  22999. };
  23000. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  23001. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  23002. var normal = new THREE.Vector3(),
  23003. tangents = [],
  23004. normals = [],
  23005. binormals = [],
  23006. vec = new THREE.Vector3(),
  23007. mat = new THREE.Matrix4(),
  23008. numpoints = segments + 1,
  23009. theta,
  23010. smallest,
  23011. tx, ty, tz,
  23012. i, u;
  23013. // expose internals
  23014. this.tangents = tangents;
  23015. this.normals = normals;
  23016. this.binormals = binormals;
  23017. // compute the tangent vectors for each segment on the path
  23018. for ( i = 0; i < numpoints; i ++ ) {
  23019. u = i / ( numpoints - 1 );
  23020. tangents[ i ] = path.getTangentAt( u );
  23021. tangents[ i ].normalize();
  23022. }
  23023. initialNormal3();
  23024. /*
  23025. function initialNormal1(lastBinormal) {
  23026. // fixed start binormal. Has dangers of 0 vectors
  23027. normals[ 0 ] = new THREE.Vector3();
  23028. binormals[ 0 ] = new THREE.Vector3();
  23029. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  23030. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  23031. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23032. }
  23033. function initialNormal2() {
  23034. // This uses the Frenet-Serret formula for deriving binormal
  23035. var t2 = path.getTangentAt( epsilon );
  23036. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  23037. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  23038. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  23039. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23040. }
  23041. */
  23042. function initialNormal3() {
  23043. // select an initial normal vector perpendicular to the first tangent vector,
  23044. // and in the direction of the smallest tangent xyz component
  23045. normals[ 0 ] = new THREE.Vector3();
  23046. binormals[ 0 ] = new THREE.Vector3();
  23047. smallest = Number.MAX_VALUE;
  23048. tx = Math.abs( tangents[ 0 ].x );
  23049. ty = Math.abs( tangents[ 0 ].y );
  23050. tz = Math.abs( tangents[ 0 ].z );
  23051. if ( tx <= smallest ) {
  23052. smallest = tx;
  23053. normal.set( 1, 0, 0 );
  23054. }
  23055. if ( ty <= smallest ) {
  23056. smallest = ty;
  23057. normal.set( 0, 1, 0 );
  23058. }
  23059. if ( tz <= smallest ) {
  23060. normal.set( 0, 0, 1 );
  23061. }
  23062. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  23063. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  23064. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  23065. }
  23066. // compute the slowly-varying normal and binormal vectors for each segment on the path
  23067. for ( i = 1; i < numpoints; i ++ ) {
  23068. normals[ i ] = normals[ i - 1 ].clone();
  23069. binormals[ i ] = binormals[ i - 1 ].clone();
  23070. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  23071. if ( vec.length() > Number.EPSILON ) {
  23072. vec.normalize();
  23073. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  23074. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  23075. }
  23076. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23077. }
  23078. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  23079. if ( closed ) {
  23080. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  23081. theta /= ( numpoints - 1 );
  23082. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  23083. theta = - theta;
  23084. }
  23085. for ( i = 1; i < numpoints; i ++ ) {
  23086. // twist a little...
  23087. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  23088. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23089. }
  23090. }
  23091. };
  23092. // File:src/extras/geometries/PolyhedronGeometry.js
  23093. /**
  23094. * @author clockworkgeek / https://github.com/clockworkgeek
  23095. * @author timothypratley / https://github.com/timothypratley
  23096. * @author WestLangley / http://github.com/WestLangley
  23097. */
  23098. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  23099. THREE.Geometry.call( this );
  23100. this.type = 'PolyhedronGeometry';
  23101. this.parameters = {
  23102. vertices: vertices,
  23103. indices: indices,
  23104. radius: radius,
  23105. detail: detail
  23106. };
  23107. radius = radius || 1;
  23108. detail = detail || 0;
  23109. var that = this;
  23110. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  23111. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  23112. }
  23113. var p = this.vertices;
  23114. var faces = [];
  23115. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  23116. var v1 = p[ indices[ i ] ];
  23117. var v2 = p[ indices[ i + 1 ] ];
  23118. var v3 = p[ indices[ i + 2 ] ];
  23119. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, j );
  23120. }
  23121. var centroid = new THREE.Vector3();
  23122. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23123. subdivide( faces[ i ], detail );
  23124. }
  23125. // Handle case when face straddles the seam
  23126. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  23127. var uvs = this.faceVertexUvs[ 0 ][ i ];
  23128. var x0 = uvs[ 0 ].x;
  23129. var x1 = uvs[ 1 ].x;
  23130. var x2 = uvs[ 2 ].x;
  23131. var max = Math.max( x0, x1, x2 );
  23132. var min = Math.min( x0, x1, x2 );
  23133. if ( max > 0.9 && min < 0.1 ) {
  23134. // 0.9 is somewhat arbitrary
  23135. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  23136. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  23137. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  23138. }
  23139. }
  23140. // Apply radius
  23141. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  23142. this.vertices[ i ].multiplyScalar( radius );
  23143. }
  23144. // Merge vertices
  23145. this.mergeVertices();
  23146. this.computeFaceNormals();
  23147. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  23148. // Project vector onto sphere's surface
  23149. function prepare( vector ) {
  23150. var vertex = vector.normalize().clone();
  23151. vertex.index = that.vertices.push( vertex ) - 1;
  23152. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  23153. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  23154. var v = inclination( vector ) / Math.PI + 0.5;
  23155. vertex.uv = new THREE.Vector2( u, 1 - v );
  23156. return vertex;
  23157. }
  23158. // Approximate a curved face with recursively sub-divided triangles.
  23159. function make( v1, v2, v3, materialIndex ) {
  23160. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, materialIndex );
  23161. that.faces.push( face );
  23162. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  23163. var azi = azimuth( centroid );
  23164. that.faceVertexUvs[ 0 ].push( [
  23165. correctUV( v1.uv, v1, azi ),
  23166. correctUV( v2.uv, v2, azi ),
  23167. correctUV( v3.uv, v3, azi )
  23168. ] );
  23169. }
  23170. // Analytically subdivide a face to the required detail level.
  23171. function subdivide( face, detail ) {
  23172. var cols = Math.pow( 2, detail );
  23173. var a = prepare( that.vertices[ face.a ] );
  23174. var b = prepare( that.vertices[ face.b ] );
  23175. var c = prepare( that.vertices[ face.c ] );
  23176. var v = [];
  23177. var materialIndex = face.materialIndex;
  23178. // Construct all of the vertices for this subdivision.
  23179. for ( var i = 0 ; i <= cols; i ++ ) {
  23180. v[ i ] = [];
  23181. var aj = prepare( a.clone().lerp( c, i / cols ) );
  23182. var bj = prepare( b.clone().lerp( c, i / cols ) );
  23183. var rows = cols - i;
  23184. for ( var j = 0; j <= rows; j ++ ) {
  23185. if ( j === 0 && i === cols ) {
  23186. v[ i ][ j ] = aj;
  23187. } else {
  23188. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  23189. }
  23190. }
  23191. }
  23192. // Construct all of the faces.
  23193. for ( var i = 0; i < cols ; i ++ ) {
  23194. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  23195. var k = Math.floor( j / 2 );
  23196. if ( j % 2 === 0 ) {
  23197. make(
  23198. v[ i ][ k + 1 ],
  23199. v[ i + 1 ][ k ],
  23200. v[ i ][ k ],
  23201. materialIndex
  23202. );
  23203. } else {
  23204. make(
  23205. v[ i ][ k + 1 ],
  23206. v[ i + 1 ][ k + 1 ],
  23207. v[ i + 1 ][ k ],
  23208. materialIndex
  23209. );
  23210. }
  23211. }
  23212. }
  23213. }
  23214. // Angle around the Y axis, counter-clockwise when looking from above.
  23215. function azimuth( vector ) {
  23216. return Math.atan2( vector.z, - vector.x );
  23217. }
  23218. // Angle above the XZ plane.
  23219. function inclination( vector ) {
  23220. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  23221. }
  23222. // Texture fixing helper. Spheres have some odd behaviours.
  23223. function correctUV( uv, vector, azimuth ) {
  23224. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  23225. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  23226. return uv.clone();
  23227. }
  23228. };
  23229. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23230. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  23231. // File:src/extras/geometries/DodecahedronGeometry.js
  23232. /**
  23233. * @author Abe Pazos / https://hamoid.com
  23234. */
  23235. THREE.DodecahedronGeometry = function ( radius, detail ) {
  23236. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23237. var r = 1 / t;
  23238. var vertices = [
  23239. // (±1, ±1, ±1)
  23240. - 1, - 1, - 1, - 1, - 1, 1,
  23241. - 1, 1, - 1, - 1, 1, 1,
  23242. 1, - 1, - 1, 1, - 1, 1,
  23243. 1, 1, - 1, 1, 1, 1,
  23244. // (0, ±1/φ, ±φ)
  23245. 0, - r, - t, 0, - r, t,
  23246. 0, r, - t, 0, r, t,
  23247. // (±1/φ, ±φ, 0)
  23248. - r, - t, 0, - r, t, 0,
  23249. r, - t, 0, r, t, 0,
  23250. // (±φ, 0, ±1/φ)
  23251. - t, 0, - r, t, 0, - r,
  23252. - t, 0, r, t, 0, r
  23253. ];
  23254. var indices = [
  23255. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  23256. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  23257. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  23258. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  23259. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  23260. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  23261. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  23262. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  23263. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  23264. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  23265. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  23266. 1, 12, 14, 1, 14, 5, 1, 5, 9
  23267. ];
  23268. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23269. this.type = 'DodecahedronGeometry';
  23270. this.parameters = {
  23271. radius: radius,
  23272. detail: detail
  23273. };
  23274. };
  23275. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23276. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  23277. // File:src/extras/geometries/IcosahedronGeometry.js
  23278. /**
  23279. * @author timothypratley / https://github.com/timothypratley
  23280. */
  23281. THREE.IcosahedronGeometry = function ( radius, detail ) {
  23282. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23283. var vertices = [
  23284. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  23285. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  23286. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  23287. ];
  23288. var indices = [
  23289. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  23290. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  23291. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  23292. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  23293. ];
  23294. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23295. this.type = 'IcosahedronGeometry';
  23296. this.parameters = {
  23297. radius: radius,
  23298. detail: detail
  23299. };
  23300. };
  23301. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23302. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  23303. // File:src/extras/geometries/OctahedronGeometry.js
  23304. /**
  23305. * @author timothypratley / https://github.com/timothypratley
  23306. */
  23307. THREE.OctahedronGeometry = function ( radius, detail ) {
  23308. var vertices = [
  23309. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  23310. ];
  23311. var indices = [
  23312. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  23313. ];
  23314. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23315. this.type = 'OctahedronGeometry';
  23316. this.parameters = {
  23317. radius: radius,
  23318. detail: detail
  23319. };
  23320. };
  23321. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23322. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  23323. // File:src/extras/geometries/TetrahedronGeometry.js
  23324. /**
  23325. * @author timothypratley / https://github.com/timothypratley
  23326. */
  23327. THREE.TetrahedronGeometry = function ( radius, detail ) {
  23328. var vertices = [
  23329. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  23330. ];
  23331. var indices = [
  23332. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  23333. ];
  23334. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23335. this.type = 'TetrahedronGeometry';
  23336. this.parameters = {
  23337. radius: radius,
  23338. detail: detail
  23339. };
  23340. };
  23341. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23342. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  23343. // File:src/extras/geometries/ParametricGeometry.js
  23344. /**
  23345. * @author zz85 / https://github.com/zz85
  23346. * Parametric Surfaces Geometry
  23347. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  23348. *
  23349. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  23350. *
  23351. */
  23352. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  23353. THREE.Geometry.call( this );
  23354. this.type = 'ParametricGeometry';
  23355. this.parameters = {
  23356. func: func,
  23357. slices: slices,
  23358. stacks: stacks
  23359. };
  23360. var verts = this.vertices;
  23361. var faces = this.faces;
  23362. var uvs = this.faceVertexUvs[ 0 ];
  23363. var i, j, p;
  23364. var u, v;
  23365. var sliceCount = slices + 1;
  23366. for ( i = 0; i <= stacks; i ++ ) {
  23367. v = i / stacks;
  23368. for ( j = 0; j <= slices; j ++ ) {
  23369. u = j / slices;
  23370. p = func( u, v );
  23371. verts.push( p );
  23372. }
  23373. }
  23374. var a, b, c, d;
  23375. var uva, uvb, uvc, uvd;
  23376. for ( i = 0; i < stacks; i ++ ) {
  23377. for ( j = 0; j < slices; j ++ ) {
  23378. a = i * sliceCount + j;
  23379. b = i * sliceCount + j + 1;
  23380. c = ( i + 1 ) * sliceCount + j + 1;
  23381. d = ( i + 1 ) * sliceCount + j;
  23382. uva = new THREE.Vector2( j / slices, i / stacks );
  23383. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  23384. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  23385. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  23386. faces.push( new THREE.Face3( a, b, d ) );
  23387. uvs.push( [ uva, uvb, uvd ] );
  23388. faces.push( new THREE.Face3( b, c, d ) );
  23389. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  23390. }
  23391. }
  23392. // console.log(this);
  23393. // magic bullet
  23394. // var diff = this.mergeVertices();
  23395. // console.log('removed ', diff, ' vertices by merging');
  23396. this.computeFaceNormals();
  23397. this.computeVertexNormals();
  23398. };
  23399. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23400. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  23401. // File:src/extras/geometries/WireframeGeometry.js
  23402. /**
  23403. * @author mrdoob / http://mrdoob.com/
  23404. */
  23405. THREE.WireframeGeometry = function ( geometry ) {
  23406. THREE.BufferGeometry.call( this );
  23407. var edge = [ 0, 0 ], hash = {};
  23408. function sortFunction( a, b ) {
  23409. return a - b;
  23410. }
  23411. var keys = [ 'a', 'b', 'c' ];
  23412. if ( geometry instanceof THREE.Geometry ) {
  23413. var vertices = geometry.vertices;
  23414. var faces = geometry.faces;
  23415. var numEdges = 0;
  23416. // allocate maximal size
  23417. var edges = new Uint32Array( 6 * faces.length );
  23418. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23419. var face = faces[ i ];
  23420. for ( var j = 0; j < 3; j ++ ) {
  23421. edge[ 0 ] = face[ keys[ j ] ];
  23422. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  23423. edge.sort( sortFunction );
  23424. var key = edge.toString();
  23425. if ( hash[ key ] === undefined ) {
  23426. edges[ 2 * numEdges ] = edge[ 0 ];
  23427. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  23428. hash[ key ] = true;
  23429. numEdges ++;
  23430. }
  23431. }
  23432. }
  23433. var coords = new Float32Array( numEdges * 2 * 3 );
  23434. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  23435. for ( var j = 0; j < 2; j ++ ) {
  23436. var vertex = vertices[ edges [ 2 * i + j ] ];
  23437. var index = 6 * i + 3 * j;
  23438. coords[ index + 0 ] = vertex.x;
  23439. coords[ index + 1 ] = vertex.y;
  23440. coords[ index + 2 ] = vertex.z;
  23441. }
  23442. }
  23443. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23444. } else if ( geometry instanceof THREE.BufferGeometry ) {
  23445. if ( geometry.index !== null ) {
  23446. // Indexed BufferGeometry
  23447. var indices = geometry.index.array;
  23448. var vertices = geometry.attributes.position;
  23449. var groups = geometry.groups;
  23450. var numEdges = 0;
  23451. if ( groups.length === 0 ) {
  23452. geometry.addGroup( 0, indices.length );
  23453. }
  23454. // allocate maximal size
  23455. var edges = new Uint32Array( 2 * indices.length );
  23456. for ( var o = 0, ol = groups.length; o < ol; ++ o ) {
  23457. var group = groups[ o ];
  23458. var start = group.start;
  23459. var count = group.count;
  23460. for ( var i = start, il = start + count; i < il; i += 3 ) {
  23461. for ( var j = 0; j < 3; j ++ ) {
  23462. edge[ 0 ] = indices[ i + j ];
  23463. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  23464. edge.sort( sortFunction );
  23465. var key = edge.toString();
  23466. if ( hash[ key ] === undefined ) {
  23467. edges[ 2 * numEdges ] = edge[ 0 ];
  23468. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  23469. hash[ key ] = true;
  23470. numEdges ++;
  23471. }
  23472. }
  23473. }
  23474. }
  23475. var coords = new Float32Array( numEdges * 2 * 3 );
  23476. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  23477. for ( var j = 0; j < 2; j ++ ) {
  23478. var index = 6 * i + 3 * j;
  23479. var index2 = edges[ 2 * i + j ];
  23480. coords[ index + 0 ] = vertices.getX( index2 );
  23481. coords[ index + 1 ] = vertices.getY( index2 );
  23482. coords[ index + 2 ] = vertices.getZ( index2 );
  23483. }
  23484. }
  23485. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23486. } else {
  23487. // non-indexed BufferGeometry
  23488. var vertices = geometry.attributes.position.array;
  23489. var numEdges = vertices.length / 3;
  23490. var numTris = numEdges / 3;
  23491. var coords = new Float32Array( numEdges * 2 * 3 );
  23492. for ( var i = 0, l = numTris; i < l; i ++ ) {
  23493. for ( var j = 0; j < 3; j ++ ) {
  23494. var index = 18 * i + 6 * j;
  23495. var index1 = 9 * i + 3 * j;
  23496. coords[ index + 0 ] = vertices[ index1 ];
  23497. coords[ index + 1 ] = vertices[ index1 + 1 ];
  23498. coords[ index + 2 ] = vertices[ index1 + 2 ];
  23499. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  23500. coords[ index + 3 ] = vertices[ index2 ];
  23501. coords[ index + 4 ] = vertices[ index2 + 1 ];
  23502. coords[ index + 5 ] = vertices[ index2 + 2 ];
  23503. }
  23504. }
  23505. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23506. }
  23507. }
  23508. };
  23509. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23510. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  23511. // File:src/extras/helpers/AxisHelper.js
  23512. /**
  23513. * @author sroucheray / http://sroucheray.org/
  23514. * @author mrdoob / http://mrdoob.com/
  23515. */
  23516. THREE.AxisHelper = function ( size ) {
  23517. size = size || 1;
  23518. var vertices = new Float32Array( [
  23519. 0, 0, 0, size, 0, 0,
  23520. 0, 0, 0, 0, size, 0,
  23521. 0, 0, 0, 0, 0, size
  23522. ] );
  23523. var colors = new Float32Array( [
  23524. 1, 0, 0, 1, 0.6, 0,
  23525. 0, 1, 0, 0.6, 1, 0,
  23526. 0, 0, 1, 0, 0.6, 1
  23527. ] );
  23528. var geometry = new THREE.BufferGeometry();
  23529. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  23530. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  23531. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  23532. THREE.LineSegments.call( this, geometry, material );
  23533. };
  23534. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23535. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  23536. // File:src/extras/helpers/ArrowHelper.js
  23537. /**
  23538. * @author WestLangley / http://github.com/WestLangley
  23539. * @author zz85 / http://github.com/zz85
  23540. * @author bhouston / http://clara.io
  23541. *
  23542. * Creates an arrow for visualizing directions
  23543. *
  23544. * Parameters:
  23545. * dir - Vector3
  23546. * origin - Vector3
  23547. * length - Number
  23548. * color - color in hex value
  23549. * headLength - Number
  23550. * headWidth - Number
  23551. */
  23552. THREE.ArrowHelper = ( function () {
  23553. var lineGeometry = new THREE.Geometry();
  23554. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  23555. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  23556. coneGeometry.translate( 0, - 0.5, 0 );
  23557. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  23558. // dir is assumed to be normalized
  23559. THREE.Object3D.call( this );
  23560. if ( color === undefined ) color = 0xffff00;
  23561. if ( length === undefined ) length = 1;
  23562. if ( headLength === undefined ) headLength = 0.2 * length;
  23563. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  23564. this.position.copy( origin );
  23565. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  23566. this.line.matrixAutoUpdate = false;
  23567. this.add( this.line );
  23568. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  23569. this.cone.matrixAutoUpdate = false;
  23570. this.add( this.cone );
  23571. this.setDirection( dir );
  23572. this.setLength( length, headLength, headWidth );
  23573. }
  23574. }() );
  23575. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  23576. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  23577. THREE.ArrowHelper.prototype.setDirection = ( function () {
  23578. var axis = new THREE.Vector3();
  23579. var radians;
  23580. return function setDirection( dir ) {
  23581. // dir is assumed to be normalized
  23582. if ( dir.y > 0.99999 ) {
  23583. this.quaternion.set( 0, 0, 0, 1 );
  23584. } else if ( dir.y < - 0.99999 ) {
  23585. this.quaternion.set( 1, 0, 0, 0 );
  23586. } else {
  23587. axis.set( dir.z, 0, - dir.x ).normalize();
  23588. radians = Math.acos( dir.y );
  23589. this.quaternion.setFromAxisAngle( axis, radians );
  23590. }
  23591. };
  23592. }() );
  23593. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  23594. if ( headLength === undefined ) headLength = 0.2 * length;
  23595. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  23596. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  23597. this.line.updateMatrix();
  23598. this.cone.scale.set( headWidth, headLength, headWidth );
  23599. this.cone.position.y = length;
  23600. this.cone.updateMatrix();
  23601. };
  23602. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  23603. this.line.material.color.set( color );
  23604. this.cone.material.color.set( color );
  23605. };
  23606. // File:src/extras/helpers/BoxHelper.js
  23607. /**
  23608. * @author mrdoob / http://mrdoob.com/
  23609. */
  23610. THREE.BoxHelper = function ( object ) {
  23611. 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 ] );
  23612. var positions = new Float32Array( 8 * 3 );
  23613. var geometry = new THREE.BufferGeometry();
  23614. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  23615. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  23616. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  23617. if ( object !== undefined ) {
  23618. this.update( object );
  23619. }
  23620. };
  23621. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23622. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  23623. THREE.BoxHelper.prototype.update = ( function () {
  23624. var box = new THREE.Box3();
  23625. return function ( object ) {
  23626. box.setFromObject( object );
  23627. if ( box.isEmpty() ) return;
  23628. var min = box.min;
  23629. var max = box.max;
  23630. /*
  23631. 5____4
  23632. 1/___0/|
  23633. | 6__|_7
  23634. 2/___3/
  23635. 0: max.x, max.y, max.z
  23636. 1: min.x, max.y, max.z
  23637. 2: min.x, min.y, max.z
  23638. 3: max.x, min.y, max.z
  23639. 4: max.x, max.y, min.z
  23640. 5: min.x, max.y, min.z
  23641. 6: min.x, min.y, min.z
  23642. 7: max.x, min.y, min.z
  23643. */
  23644. var position = this.geometry.attributes.position;
  23645. var array = position.array;
  23646. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  23647. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  23648. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  23649. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  23650. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  23651. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  23652. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  23653. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  23654. position.needsUpdate = true;
  23655. this.geometry.computeBoundingSphere();
  23656. };
  23657. } )();
  23658. // File:src/extras/helpers/BoundingBoxHelper.js
  23659. /**
  23660. * @author WestLangley / http://github.com/WestLangley
  23661. */
  23662. // a helper to show the world-axis-aligned bounding box for an object
  23663. THREE.BoundingBoxHelper = function ( object, hex ) {
  23664. var color = ( hex !== undefined ) ? hex : 0x888888;
  23665. this.object = object;
  23666. this.box = new THREE.Box3();
  23667. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  23668. };
  23669. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  23670. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  23671. THREE.BoundingBoxHelper.prototype.update = function () {
  23672. this.box.setFromObject( this.object );
  23673. this.box.size( this.scale );
  23674. this.box.center( this.position );
  23675. };
  23676. // File:src/extras/helpers/CameraHelper.js
  23677. /**
  23678. * @author alteredq / http://alteredqualia.com/
  23679. *
  23680. * - shows frustum, line of sight and up of the camera
  23681. * - suitable for fast updates
  23682. * - based on frustum visualization in lightgl.js shadowmap example
  23683. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  23684. */
  23685. THREE.CameraHelper = function ( camera ) {
  23686. var geometry = new THREE.Geometry();
  23687. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  23688. var pointMap = {};
  23689. // colors
  23690. var hexFrustum = 0xffaa00;
  23691. var hexCone = 0xff0000;
  23692. var hexUp = 0x00aaff;
  23693. var hexTarget = 0xffffff;
  23694. var hexCross = 0x333333;
  23695. // near
  23696. addLine( "n1", "n2", hexFrustum );
  23697. addLine( "n2", "n4", hexFrustum );
  23698. addLine( "n4", "n3", hexFrustum );
  23699. addLine( "n3", "n1", hexFrustum );
  23700. // far
  23701. addLine( "f1", "f2", hexFrustum );
  23702. addLine( "f2", "f4", hexFrustum );
  23703. addLine( "f4", "f3", hexFrustum );
  23704. addLine( "f3", "f1", hexFrustum );
  23705. // sides
  23706. addLine( "n1", "f1", hexFrustum );
  23707. addLine( "n2", "f2", hexFrustum );
  23708. addLine( "n3", "f3", hexFrustum );
  23709. addLine( "n4", "f4", hexFrustum );
  23710. // cone
  23711. addLine( "p", "n1", hexCone );
  23712. addLine( "p", "n2", hexCone );
  23713. addLine( "p", "n3", hexCone );
  23714. addLine( "p", "n4", hexCone );
  23715. // up
  23716. addLine( "u1", "u2", hexUp );
  23717. addLine( "u2", "u3", hexUp );
  23718. addLine( "u3", "u1", hexUp );
  23719. // target
  23720. addLine( "c", "t", hexTarget );
  23721. addLine( "p", "c", hexCross );
  23722. // cross
  23723. addLine( "cn1", "cn2", hexCross );
  23724. addLine( "cn3", "cn4", hexCross );
  23725. addLine( "cf1", "cf2", hexCross );
  23726. addLine( "cf3", "cf4", hexCross );
  23727. function addLine( a, b, hex ) {
  23728. addPoint( a, hex );
  23729. addPoint( b, hex );
  23730. }
  23731. function addPoint( id, hex ) {
  23732. geometry.vertices.push( new THREE.Vector3() );
  23733. geometry.colors.push( new THREE.Color( hex ) );
  23734. if ( pointMap[ id ] === undefined ) {
  23735. pointMap[ id ] = [];
  23736. }
  23737. pointMap[ id ].push( geometry.vertices.length - 1 );
  23738. }
  23739. THREE.LineSegments.call( this, geometry, material );
  23740. this.camera = camera;
  23741. this.camera.updateProjectionMatrix();
  23742. this.matrix = camera.matrixWorld;
  23743. this.matrixAutoUpdate = false;
  23744. this.pointMap = pointMap;
  23745. this.update();
  23746. };
  23747. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23748. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  23749. THREE.CameraHelper.prototype.update = function () {
  23750. var geometry, pointMap;
  23751. var vector = new THREE.Vector3();
  23752. var camera = new THREE.Camera();
  23753. function setPoint( point, x, y, z ) {
  23754. vector.set( x, y, z ).unproject( camera );
  23755. var points = pointMap[ point ];
  23756. if ( points !== undefined ) {
  23757. for ( var i = 0, il = points.length; i < il; i ++ ) {
  23758. geometry.vertices[ points[ i ] ].copy( vector );
  23759. }
  23760. }
  23761. }
  23762. return function () {
  23763. geometry = this.geometry;
  23764. pointMap = this.pointMap;
  23765. var w = 1, h = 1;
  23766. // we need just camera projection matrix
  23767. // world matrix must be identity
  23768. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  23769. // center / target
  23770. setPoint( "c", 0, 0, - 1 );
  23771. setPoint( "t", 0, 0, 1 );
  23772. // near
  23773. setPoint( "n1", - w, - h, - 1 );
  23774. setPoint( "n2", w, - h, - 1 );
  23775. setPoint( "n3", - w, h, - 1 );
  23776. setPoint( "n4", w, h, - 1 );
  23777. // far
  23778. setPoint( "f1", - w, - h, 1 );
  23779. setPoint( "f2", w, - h, 1 );
  23780. setPoint( "f3", - w, h, 1 );
  23781. setPoint( "f4", w, h, 1 );
  23782. // up
  23783. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  23784. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  23785. setPoint( "u3", 0, h * 2, - 1 );
  23786. // cross
  23787. setPoint( "cf1", - w, 0, 1 );
  23788. setPoint( "cf2", w, 0, 1 );
  23789. setPoint( "cf3", 0, - h, 1 );
  23790. setPoint( "cf4", 0, h, 1 );
  23791. setPoint( "cn1", - w, 0, - 1 );
  23792. setPoint( "cn2", w, 0, - 1 );
  23793. setPoint( "cn3", 0, - h, - 1 );
  23794. setPoint( "cn4", 0, h, - 1 );
  23795. geometry.verticesNeedUpdate = true;
  23796. };
  23797. }();
  23798. // File:src/extras/helpers/DirectionalLightHelper.js
  23799. /**
  23800. * @author alteredq / http://alteredqualia.com/
  23801. * @author mrdoob / http://mrdoob.com/
  23802. * @author WestLangley / http://github.com/WestLangley
  23803. */
  23804. THREE.DirectionalLightHelper = function ( light, size ) {
  23805. THREE.Object3D.call( this );
  23806. this.light = light;
  23807. this.light.updateMatrixWorld();
  23808. this.matrix = light.matrixWorld;
  23809. this.matrixAutoUpdate = false;
  23810. size = size || 1;
  23811. var geometry = new THREE.Geometry();
  23812. geometry.vertices.push(
  23813. new THREE.Vector3( - size, size, 0 ),
  23814. new THREE.Vector3( size, size, 0 ),
  23815. new THREE.Vector3( size, - size, 0 ),
  23816. new THREE.Vector3( - size, - size, 0 ),
  23817. new THREE.Vector3( - size, size, 0 )
  23818. );
  23819. var material = new THREE.LineBasicMaterial( { fog: false } );
  23820. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23821. this.lightPlane = new THREE.Line( geometry, material );
  23822. this.add( this.lightPlane );
  23823. geometry = new THREE.Geometry();
  23824. geometry.vertices.push(
  23825. new THREE.Vector3(),
  23826. new THREE.Vector3()
  23827. );
  23828. material = new THREE.LineBasicMaterial( { fog: false } );
  23829. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23830. this.targetLine = new THREE.Line( geometry, material );
  23831. this.add( this.targetLine );
  23832. this.update();
  23833. };
  23834. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23835. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  23836. THREE.DirectionalLightHelper.prototype.dispose = function () {
  23837. this.lightPlane.geometry.dispose();
  23838. this.lightPlane.material.dispose();
  23839. this.targetLine.geometry.dispose();
  23840. this.targetLine.material.dispose();
  23841. };
  23842. THREE.DirectionalLightHelper.prototype.update = function () {
  23843. var v1 = new THREE.Vector3();
  23844. var v2 = new THREE.Vector3();
  23845. var v3 = new THREE.Vector3();
  23846. return function () {
  23847. v1.setFromMatrixPosition( this.light.matrixWorld );
  23848. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  23849. v3.subVectors( v2, v1 );
  23850. this.lightPlane.lookAt( v3 );
  23851. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23852. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  23853. this.targetLine.geometry.verticesNeedUpdate = true;
  23854. this.targetLine.material.color.copy( this.lightPlane.material.color );
  23855. };
  23856. }();
  23857. // File:src/extras/helpers/EdgesHelper.js
  23858. /**
  23859. * @author WestLangley / http://github.com/WestLangley
  23860. * @param object THREE.Mesh whose geometry will be used
  23861. * @param hex line color
  23862. * @param thresholdAngle the minimum angle (in degrees),
  23863. * between the face normals of adjacent faces,
  23864. * that is required to render an edge. A value of 10 means
  23865. * an edge is only rendered if the angle is at least 10 degrees.
  23866. */
  23867. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  23868. var color = ( hex !== undefined ) ? hex : 0xffffff;
  23869. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  23870. this.matrix = object.matrixWorld;
  23871. this.matrixAutoUpdate = false;
  23872. };
  23873. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23874. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  23875. // File:src/extras/helpers/FaceNormalsHelper.js
  23876. /**
  23877. * @author mrdoob / http://mrdoob.com/
  23878. * @author WestLangley / http://github.com/WestLangley
  23879. */
  23880. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  23881. // FaceNormalsHelper only supports THREE.Geometry
  23882. this.object = object;
  23883. this.size = ( size !== undefined ) ? size : 1;
  23884. var color = ( hex !== undefined ) ? hex : 0xffff00;
  23885. var width = ( linewidth !== undefined ) ? linewidth : 1;
  23886. //
  23887. var nNormals = 0;
  23888. var objGeometry = this.object.geometry;
  23889. if ( objGeometry instanceof THREE.Geometry ) {
  23890. nNormals = objGeometry.faces.length;
  23891. } else {
  23892. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  23893. }
  23894. //
  23895. var geometry = new THREE.BufferGeometry();
  23896. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  23897. geometry.addAttribute( 'position', positions );
  23898. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  23899. //
  23900. this.matrixAutoUpdate = false;
  23901. this.update();
  23902. };
  23903. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23904. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  23905. THREE.FaceNormalsHelper.prototype.update = ( function () {
  23906. var v1 = new THREE.Vector3();
  23907. var v2 = new THREE.Vector3();
  23908. var normalMatrix = new THREE.Matrix3();
  23909. return function update() {
  23910. this.object.updateMatrixWorld( true );
  23911. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  23912. var matrixWorld = this.object.matrixWorld;
  23913. var position = this.geometry.attributes.position;
  23914. //
  23915. var objGeometry = this.object.geometry;
  23916. var vertices = objGeometry.vertices;
  23917. var faces = objGeometry.faces;
  23918. var idx = 0;
  23919. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23920. var face = faces[ i ];
  23921. var normal = face.normal;
  23922. v1.copy( vertices[ face.a ] )
  23923. .add( vertices[ face.b ] )
  23924. .add( vertices[ face.c ] )
  23925. .divideScalar( 3 )
  23926. .applyMatrix4( matrixWorld );
  23927. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  23928. position.setXYZ( idx, v1.x, v1.y, v1.z );
  23929. idx = idx + 1;
  23930. position.setXYZ( idx, v2.x, v2.y, v2.z );
  23931. idx = idx + 1;
  23932. }
  23933. position.needsUpdate = true;
  23934. return this;
  23935. }
  23936. }() );
  23937. // File:src/extras/helpers/GridHelper.js
  23938. /**
  23939. * @author mrdoob / http://mrdoob.com/
  23940. */
  23941. THREE.GridHelper = function ( size, step ) {
  23942. var geometry = new THREE.Geometry();
  23943. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  23944. this.color1 = new THREE.Color( 0x444444 );
  23945. this.color2 = new THREE.Color( 0x888888 );
  23946. for ( var i = - size; i <= size; i += step ) {
  23947. geometry.vertices.push(
  23948. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  23949. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  23950. );
  23951. var color = i === 0 ? this.color1 : this.color2;
  23952. geometry.colors.push( color, color, color, color );
  23953. }
  23954. THREE.LineSegments.call( this, geometry, material );
  23955. };
  23956. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23957. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  23958. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  23959. this.color1.set( colorCenterLine );
  23960. this.color2.set( colorGrid );
  23961. this.geometry.colorsNeedUpdate = true;
  23962. };
  23963. // File:src/extras/helpers/HemisphereLightHelper.js
  23964. /**
  23965. * @author alteredq / http://alteredqualia.com/
  23966. * @author mrdoob / http://mrdoob.com/
  23967. */
  23968. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  23969. THREE.Object3D.call( this );
  23970. this.light = light;
  23971. this.light.updateMatrixWorld();
  23972. this.matrix = light.matrixWorld;
  23973. this.matrixAutoUpdate = false;
  23974. this.colors = [ new THREE.Color(), new THREE.Color() ];
  23975. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  23976. geometry.rotateX( - Math.PI / 2 );
  23977. for ( var i = 0, il = 8; i < il; i ++ ) {
  23978. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  23979. }
  23980. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  23981. this.lightSphere = new THREE.Mesh( geometry, material );
  23982. this.add( this.lightSphere );
  23983. this.update();
  23984. };
  23985. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23986. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  23987. THREE.HemisphereLightHelper.prototype.dispose = function () {
  23988. this.lightSphere.geometry.dispose();
  23989. this.lightSphere.material.dispose();
  23990. };
  23991. THREE.HemisphereLightHelper.prototype.update = function () {
  23992. var vector = new THREE.Vector3();
  23993. return function () {
  23994. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  23995. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  23996. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  23997. this.lightSphere.geometry.colorsNeedUpdate = true;
  23998. }
  23999. }();
  24000. // File:src/extras/helpers/PointLightHelper.js
  24001. /**
  24002. * @author alteredq / http://alteredqualia.com/
  24003. * @author mrdoob / http://mrdoob.com/
  24004. */
  24005. THREE.PointLightHelper = function ( light, sphereSize ) {
  24006. this.light = light;
  24007. this.light.updateMatrixWorld();
  24008. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  24009. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  24010. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24011. THREE.Mesh.call( this, geometry, material );
  24012. this.matrix = this.light.matrixWorld;
  24013. this.matrixAutoUpdate = false;
  24014. /*
  24015. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  24016. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  24017. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  24018. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  24019. var d = light.distance;
  24020. if ( d === 0.0 ) {
  24021. this.lightDistance.visible = false;
  24022. } else {
  24023. this.lightDistance.scale.set( d, d, d );
  24024. }
  24025. this.add( this.lightDistance );
  24026. */
  24027. };
  24028. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  24029. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  24030. THREE.PointLightHelper.prototype.dispose = function () {
  24031. this.geometry.dispose();
  24032. this.material.dispose();
  24033. };
  24034. THREE.PointLightHelper.prototype.update = function () {
  24035. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24036. /*
  24037. var d = this.light.distance;
  24038. if ( d === 0.0 ) {
  24039. this.lightDistance.visible = false;
  24040. } else {
  24041. this.lightDistance.visible = true;
  24042. this.lightDistance.scale.set( d, d, d );
  24043. }
  24044. */
  24045. };
  24046. // File:src/extras/helpers/SkeletonHelper.js
  24047. /**
  24048. * @author Sean Griffin / http://twitter.com/sgrif
  24049. * @author Michael Guerrero / http://realitymeltdown.com
  24050. * @author mrdoob / http://mrdoob.com/
  24051. * @author ikerr / http://verold.com
  24052. */
  24053. THREE.SkeletonHelper = function ( object ) {
  24054. this.bones = this.getBoneList( object );
  24055. var geometry = new THREE.Geometry();
  24056. for ( var i = 0; i < this.bones.length; i ++ ) {
  24057. var bone = this.bones[ i ];
  24058. if ( bone.parent instanceof THREE.Bone ) {
  24059. geometry.vertices.push( new THREE.Vector3() );
  24060. geometry.vertices.push( new THREE.Vector3() );
  24061. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  24062. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  24063. }
  24064. }
  24065. geometry.dynamic = true;
  24066. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  24067. THREE.LineSegments.call( this, geometry, material );
  24068. this.root = object;
  24069. this.matrix = object.matrixWorld;
  24070. this.matrixAutoUpdate = false;
  24071. this.update();
  24072. };
  24073. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24074. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  24075. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  24076. var boneList = [];
  24077. if ( object instanceof THREE.Bone ) {
  24078. boneList.push( object );
  24079. }
  24080. for ( var i = 0; i < object.children.length; i ++ ) {
  24081. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  24082. }
  24083. return boneList;
  24084. };
  24085. THREE.SkeletonHelper.prototype.update = function () {
  24086. var geometry = this.geometry;
  24087. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  24088. var boneMatrix = new THREE.Matrix4();
  24089. var j = 0;
  24090. for ( var i = 0; i < this.bones.length; i ++ ) {
  24091. var bone = this.bones[ i ];
  24092. if ( bone.parent instanceof THREE.Bone ) {
  24093. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  24094. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  24095. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  24096. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  24097. j += 2;
  24098. }
  24099. }
  24100. geometry.verticesNeedUpdate = true;
  24101. geometry.computeBoundingSphere();
  24102. };
  24103. // File:src/extras/helpers/SpotLightHelper.js
  24104. /**
  24105. * @author alteredq / http://alteredqualia.com/
  24106. * @author mrdoob / http://mrdoob.com/
  24107. * @author WestLangley / http://github.com/WestLangley
  24108. */
  24109. THREE.SpotLightHelper = function ( light ) {
  24110. THREE.Object3D.call( this );
  24111. this.light = light;
  24112. this.light.updateMatrixWorld();
  24113. this.matrix = light.matrixWorld;
  24114. this.matrixAutoUpdate = false;
  24115. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  24116. geometry.translate( 0, - 0.5, 0 );
  24117. geometry.rotateX( - Math.PI / 2 );
  24118. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  24119. this.cone = new THREE.Mesh( geometry, material );
  24120. this.add( this.cone );
  24121. this.update();
  24122. };
  24123. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24124. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  24125. THREE.SpotLightHelper.prototype.dispose = function () {
  24126. this.cone.geometry.dispose();
  24127. this.cone.material.dispose();
  24128. };
  24129. THREE.SpotLightHelper.prototype.update = function () {
  24130. var vector = new THREE.Vector3();
  24131. var vector2 = new THREE.Vector3();
  24132. return function () {
  24133. var coneLength = this.light.distance ? this.light.distance : 10000;
  24134. var coneWidth = coneLength * Math.tan( this.light.angle );
  24135. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  24136. vector.setFromMatrixPosition( this.light.matrixWorld );
  24137. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  24138. this.cone.lookAt( vector2.sub( vector ) );
  24139. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24140. };
  24141. }();
  24142. // File:src/extras/helpers/VertexNormalsHelper.js
  24143. /**
  24144. * @author mrdoob / http://mrdoob.com/
  24145. * @author WestLangley / http://github.com/WestLangley
  24146. */
  24147. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  24148. this.object = object;
  24149. this.size = ( size !== undefined ) ? size : 1;
  24150. var color = ( hex !== undefined ) ? hex : 0xff0000;
  24151. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24152. //
  24153. var nNormals = 0;
  24154. var objGeometry = this.object.geometry;
  24155. if ( objGeometry instanceof THREE.Geometry ) {
  24156. nNormals = objGeometry.faces.length * 3;
  24157. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24158. nNormals = objGeometry.attributes.normal.count
  24159. }
  24160. //
  24161. var geometry = new THREE.BufferGeometry();
  24162. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  24163. geometry.addAttribute( 'position', positions );
  24164. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  24165. //
  24166. this.matrixAutoUpdate = false;
  24167. this.update();
  24168. };
  24169. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24170. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  24171. THREE.VertexNormalsHelper.prototype.update = ( function () {
  24172. var v1 = new THREE.Vector3();
  24173. var v2 = new THREE.Vector3();
  24174. var normalMatrix = new THREE.Matrix3();
  24175. return function update() {
  24176. var keys = [ 'a', 'b', 'c' ];
  24177. this.object.updateMatrixWorld( true );
  24178. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24179. var matrixWorld = this.object.matrixWorld;
  24180. var position = this.geometry.attributes.position;
  24181. //
  24182. var objGeometry = this.object.geometry;
  24183. if ( objGeometry instanceof THREE.Geometry ) {
  24184. var vertices = objGeometry.vertices;
  24185. var faces = objGeometry.faces;
  24186. var idx = 0;
  24187. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24188. var face = faces[ i ];
  24189. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  24190. var vertex = vertices[ face[ keys[ j ] ] ];
  24191. var normal = face.vertexNormals[ j ];
  24192. v1.copy( vertex ).applyMatrix4( matrixWorld );
  24193. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24194. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24195. idx = idx + 1;
  24196. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24197. idx = idx + 1;
  24198. }
  24199. }
  24200. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24201. var objPos = objGeometry.attributes.position;
  24202. var objNorm = objGeometry.attributes.normal;
  24203. var idx = 0;
  24204. // for simplicity, ignore index and drawcalls, and render every normal
  24205. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  24206. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  24207. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  24208. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24209. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24210. idx = idx + 1;
  24211. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24212. idx = idx + 1;
  24213. }
  24214. }
  24215. position.needsUpdate = true;
  24216. return this;
  24217. }
  24218. }() );
  24219. // File:src/extras/helpers/WireframeHelper.js
  24220. /**
  24221. * @author mrdoob / http://mrdoob.com/
  24222. */
  24223. THREE.WireframeHelper = function ( object, hex ) {
  24224. var color = ( hex !== undefined ) ? hex : 0xffffff;
  24225. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  24226. this.matrix = object.matrixWorld;
  24227. this.matrixAutoUpdate = false;
  24228. };
  24229. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24230. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  24231. // File:src/extras/objects/ImmediateRenderObject.js
  24232. /**
  24233. * @author alteredq / http://alteredqualia.com/
  24234. */
  24235. THREE.ImmediateRenderObject = function ( material ) {
  24236. THREE.Object3D.call( this );
  24237. this.material = material;
  24238. this.render = function ( renderCallback ) {};
  24239. };
  24240. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  24241. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  24242. // File:src/extras/objects/MorphBlendMesh.js
  24243. /**
  24244. * @author alteredq / http://alteredqualia.com/
  24245. */
  24246. THREE.MorphBlendMesh = function( geometry, material ) {
  24247. THREE.Mesh.call( this, geometry, material );
  24248. this.animationsMap = {};
  24249. this.animationsList = [];
  24250. // prepare default animation
  24251. // (all frames played together in 1 second)
  24252. var numFrames = this.geometry.morphTargets.length;
  24253. var name = "__default";
  24254. var startFrame = 0;
  24255. var endFrame = numFrames - 1;
  24256. var fps = numFrames / 1;
  24257. this.createAnimation( name, startFrame, endFrame, fps );
  24258. this.setAnimationWeight( name, 1 );
  24259. };
  24260. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  24261. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  24262. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  24263. var animation = {
  24264. start: start,
  24265. end: end,
  24266. length: end - start + 1,
  24267. fps: fps,
  24268. duration: ( end - start ) / fps,
  24269. lastFrame: 0,
  24270. currentFrame: 0,
  24271. active: false,
  24272. time: 0,
  24273. direction: 1,
  24274. weight: 1,
  24275. directionBackwards: false,
  24276. mirroredLoop: false
  24277. };
  24278. this.animationsMap[ name ] = animation;
  24279. this.animationsList.push( animation );
  24280. };
  24281. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  24282. var pattern = /([a-z]+)_?(\d+)/i;
  24283. var firstAnimation, frameRanges = {};
  24284. var geometry = this.geometry;
  24285. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  24286. var morph = geometry.morphTargets[ i ];
  24287. var chunks = morph.name.match( pattern );
  24288. if ( chunks && chunks.length > 1 ) {
  24289. var name = chunks[ 1 ];
  24290. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  24291. var range = frameRanges[ name ];
  24292. if ( i < range.start ) range.start = i;
  24293. if ( i > range.end ) range.end = i;
  24294. if ( ! firstAnimation ) firstAnimation = name;
  24295. }
  24296. }
  24297. for ( var name in frameRanges ) {
  24298. var range = frameRanges[ name ];
  24299. this.createAnimation( name, range.start, range.end, fps );
  24300. }
  24301. this.firstAnimation = firstAnimation;
  24302. };
  24303. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  24304. var animation = this.animationsMap[ name ];
  24305. if ( animation ) {
  24306. animation.direction = 1;
  24307. animation.directionBackwards = false;
  24308. }
  24309. };
  24310. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  24311. var animation = this.animationsMap[ name ];
  24312. if ( animation ) {
  24313. animation.direction = - 1;
  24314. animation.directionBackwards = true;
  24315. }
  24316. };
  24317. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  24318. var animation = this.animationsMap[ name ];
  24319. if ( animation ) {
  24320. animation.fps = fps;
  24321. animation.duration = ( animation.end - animation.start ) / animation.fps;
  24322. }
  24323. };
  24324. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  24325. var animation = this.animationsMap[ name ];
  24326. if ( animation ) {
  24327. animation.duration = duration;
  24328. animation.fps = ( animation.end - animation.start ) / animation.duration;
  24329. }
  24330. };
  24331. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  24332. var animation = this.animationsMap[ name ];
  24333. if ( animation ) {
  24334. animation.weight = weight;
  24335. }
  24336. };
  24337. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  24338. var animation = this.animationsMap[ name ];
  24339. if ( animation ) {
  24340. animation.time = time;
  24341. }
  24342. };
  24343. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  24344. var time = 0;
  24345. var animation = this.animationsMap[ name ];
  24346. if ( animation ) {
  24347. time = animation.time;
  24348. }
  24349. return time;
  24350. };
  24351. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  24352. var duration = - 1;
  24353. var animation = this.animationsMap[ name ];
  24354. if ( animation ) {
  24355. duration = animation.duration;
  24356. }
  24357. return duration;
  24358. };
  24359. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  24360. var animation = this.animationsMap[ name ];
  24361. if ( animation ) {
  24362. animation.time = 0;
  24363. animation.active = true;
  24364. } else {
  24365. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  24366. }
  24367. };
  24368. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  24369. var animation = this.animationsMap[ name ];
  24370. if ( animation ) {
  24371. animation.active = false;
  24372. }
  24373. };
  24374. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  24375. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  24376. var animation = this.animationsList[ i ];
  24377. if ( ! animation.active ) continue;
  24378. var frameTime = animation.duration / animation.length;
  24379. animation.time += animation.direction * delta;
  24380. if ( animation.mirroredLoop ) {
  24381. if ( animation.time > animation.duration || animation.time < 0 ) {
  24382. animation.direction *= - 1;
  24383. if ( animation.time > animation.duration ) {
  24384. animation.time = animation.duration;
  24385. animation.directionBackwards = true;
  24386. }
  24387. if ( animation.time < 0 ) {
  24388. animation.time = 0;
  24389. animation.directionBackwards = false;
  24390. }
  24391. }
  24392. } else {
  24393. animation.time = animation.time % animation.duration;
  24394. if ( animation.time < 0 ) animation.time += animation.duration;
  24395. }
  24396. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  24397. var weight = animation.weight;
  24398. if ( keyframe !== animation.currentFrame ) {
  24399. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  24400. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  24401. this.morphTargetInfluences[ keyframe ] = 0;
  24402. animation.lastFrame = animation.currentFrame;
  24403. animation.currentFrame = keyframe;
  24404. }
  24405. var mix = ( animation.time % frameTime ) / frameTime;
  24406. if ( animation.directionBackwards ) mix = 1 - mix;
  24407. if ( animation.currentFrame !== animation.lastFrame ) {
  24408. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  24409. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  24410. } else {
  24411. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  24412. }
  24413. }
  24414. };